@@ -329,6 +329,31 @@ static void test_vdso_no_exit_handler(struct sgx_secs *secs)
ASSERT_EQ(exception.leaf, ENCLU_EENTER);
}
+static int basic_exit_handler(long rdi, long rsi, long rdx, int ret,
+ long r8, long r9, void *tcs, long ursp,
+ struct sgx_enclave_exception *e)
+{
+ ASSERT_EQ(ret, 0);
+ return 0;
+}
+
+/*
+ * Test the vDSO API, __vdso_sgx_enter_enclave(), with an exit handler.
+ */
+static void test_vdso_with_exit_handler(struct sgx_secs *secs)
+{
+ struct sgx_enclave_exception exception;
+ uint64_t result = 0;
+ long ret;
+
+ memset(&exception, 0, sizeof(exception));
+
+ ret = sgx_call((void *)&MAGIC, &result, 0, 0, 0, 0, (void *)secs->base,
+ &exception, basic_exit_handler);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(result, MAGIC);
+}
+
int main(int argc, char *argv[], char *envp[])
{
struct sgx_sigstruct sigstruct;
@@ -356,6 +381,7 @@ int main(int argc, char *argv[], char *envp[])
encl_build(&secs, bin, bin_size, &sigstruct);
test_vdso_no_exit_handler(&secs);
+ test_vdso_with_exit_handler(&secs);
printf("All tests passed!\n");
exit(0);
Add a test to verify that nothing explodes when using an exit handler to control the flow of the vDSO. Suggested-by: Suggested-by: Cedric Xing <cedric.xing@intel.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> --- tools/testing/selftests/x86/sgx/main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)