summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/x86/sysret_rip.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/x86/sysret_rip.c')
-rw-r--r--tools/testing/selftests/x86/sysret_rip.c36
1 files changed, 7 insertions, 29 deletions
diff --git a/tools/testing/selftests/x86/sysret_rip.c b/tools/testing/selftests/x86/sysret_rip.c
index b30de9aaa6d4..2e423a335e1c 100644
--- a/tools/testing/selftests/x86/sysret_rip.c
+++ b/tools/testing/selftests/x86/sysret_rip.c
@@ -22,6 +22,8 @@
#include <sys/mman.h>
#include <assert.h>
+#include "helpers.h"
+
/*
* These items are in clang_helpers_64.S, in order to avoid clang inline asm
* limitations:
@@ -29,29 +31,7 @@
void test_syscall_ins(void);
extern const char test_page[];
-static void const *current_test_page_addr = test_page;
-
-static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
- int flags)
-{
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_sigaction = handler;
- sa.sa_flags = SA_SIGINFO | flags;
- sigemptyset(&sa.sa_mask);
- if (sigaction(sig, &sa, 0))
- err(1, "sigaction");
-}
-
-static void clearhandler(int sig)
-{
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_DFL;
- sigemptyset(&sa.sa_mask);
- if (sigaction(sig, &sa, 0))
- err(1, "sigaction");
-}
+static const void *current_test_page_addr = test_page;
/* State used by our signal handlers. */
static gregset_t initial_regs;
@@ -60,7 +40,7 @@ static volatile unsigned long rip;
static void sigsegv_for_sigreturn_test(int sig, siginfo_t *info, void *ctx_void)
{
- ucontext_t *ctx = (ucontext_t*)ctx_void;
+ ucontext_t *ctx = (ucontext_t *)ctx_void;
if (rip != ctx->uc_mcontext.gregs[REG_RIP]) {
printf("[FAIL]\tRequested RIP=0x%lx but got RIP=0x%lx\n",
@@ -76,7 +56,7 @@ static void sigsegv_for_sigreturn_test(int sig, siginfo_t *info, void *ctx_void)
static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
{
- ucontext_t *ctx = (ucontext_t*)ctx_void;
+ ucontext_t *ctx = (ucontext_t *)ctx_void;
memcpy(&initial_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
@@ -89,8 +69,6 @@ static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
ctx->uc_mcontext.gregs[REG_R11]);
sethandler(SIGSEGV, sigsegv_for_sigreturn_test, SA_RESETHAND);
-
- return;
}
static void test_sigreturn_to(unsigned long ip)
@@ -104,7 +82,7 @@ static jmp_buf jmpbuf;
static void sigsegv_for_fallthrough(int sig, siginfo_t *info, void *ctx_void)
{
- ucontext_t *ctx = (ucontext_t*)ctx_void;
+ ucontext_t *ctx = (ucontext_t *)ctx_void;
if (rip != ctx->uc_mcontext.gregs[REG_RIP]) {
printf("[FAIL]\tExpected SIGSEGV at 0x%lx but got RIP=0x%lx\n",
@@ -150,7 +128,7 @@ static void test_syscall_fallthrough_to(unsigned long ip)
printf("[OK]\tWe survived\n");
}
-int main()
+int main(void)
{
/*
* When the kernel returns from a slow-path syscall, it will