@@ -342,6 +342,31 @@ static void test_sgx_vdso(struct sgx_secs *secs)
EXPECT_EQ(exception.leaf, ENCLU_EENTER);
}
+static int basic_exit_handler(long rdi, long rsi, long rdx, long ursp,
+ long r8, long r9, void *tcs, int ret,
+ 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_sgx_vdso_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_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,
+ (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;
@@ -350,7 +375,7 @@ int main(int argc, char *argv[], char *envp[])
void *bin;
ksft_print_header();
- ksft_set_plan(2);
+ ksft_set_plan(3);
bin = encl_data_map("encl.bin", &bin_size);
@@ -363,6 +388,7 @@ int main(int argc, char *argv[], char *envp[])
setup_vdso();
RUN_TEST(test_sgx_vdso);
+ RUN_TEST(test_sgx_vdso_exit_handler);
return ksft_exit_pass();
}
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 | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)