Add a very simple exit handler and use it as a third variant of the SGX selftest to verify that the vDSO invokes then user's handler when one is supplied. Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> --- tools/testing/selftests/sgx/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c index 158ea9e2b6d3a..44acb3c720675 100644 --- a/tools/testing/selftests/sgx/main.c +++ b/tools/testing/selftests/sgx/main.c @@ -137,10 +137,21 @@ int check_result(struct sgx_enclave_run *run, int ret, uint64_t result, printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n", test, MAGIC, result); return -EIO; + } else if (run->user_data) { + printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n", + test, run->user_data); + return -EIO; } return 0; } +static int exit_handler(long rdi, long rsi, long rdx, long ursp, long r8, long r9, + struct sgx_enclave_run *run) +{ + run->user_data = 0; + return 0; +} + int main(int argc, char *argv[], char *envp[]) { struct sgx_enclave_run run; @@ -203,6 +214,14 @@ int main(int argc, char *argv[], char *envp[]) if (check_result(&run, ret, result, "eenter")) goto err; + /* And with an exit handler. */ + run.user_handler = exit_handler; + run.user_data = 0xdeadbeef; + ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, + 0, 0, &run); + if (check_result(&run, ret, result, "exit_handler")) + goto err; + printf("SUCCESS\n"); encl_delete(&encl); exit(0); -- 2.28.0