1 // SPDX-License-Identifier: GPL-2.0-only
3 * vdso_restorer.c - tests vDSO-based signal restore
4 * Copyright (c) 2015 Andrew Lutomirski
6 * This makes sure that sa_restorer == NULL keeps working on 32-bit
7 * configurations. Modern glibc doesn't use it under any circumstances,
8 * so it's easy to overlook breakage.
10 * 64-bit userspace has never supported sa_restorer == NULL, so this is
23 #include <sys/syscall.h>
25 /* Open-code this -- the headers are too messy to easily use them. */
26 struct real_sigaction
{
33 static volatile sig_atomic_t handler_called
;
35 static void handler_with_siginfo(int sig
, siginfo_t
*info
, void *ctx_void
)
40 static void handler_without_siginfo(int sig
)
48 struct real_sigaction sa
;
50 void *vdso
= dlopen("linux-vdso.so.1",
51 RTLD_LAZY
| RTLD_LOCAL
| RTLD_NOLOAD
);
53 vdso
= dlopen("linux-gate.so.1",
54 RTLD_LAZY
| RTLD_LOCAL
| RTLD_NOLOAD
);
56 printf("[SKIP]\tFailed to find vDSO. Tests are not expected to work.\n");
60 memset(&sa
, 0, sizeof(sa
));
61 sa
.handler
= handler_with_siginfo
;
62 sa
.flags
= SA_SIGINFO
;
63 sa
.restorer
= NULL
; /* request kernel-provided restorer */
65 printf("[RUN]\tRaise a signal, SA_SIGINFO, sa.restorer == NULL\n");
67 if (syscall(SYS_rt_sigaction
, SIGUSR1
, &sa
, NULL
, 8) != 0)
68 err(1, "raw rt_sigaction syscall");
73 printf("[OK]\tSA_SIGINFO handler returned successfully\n");
75 printf("[FAIL]\tSA_SIGINFO handler was not called\n");
79 printf("[RUN]\tRaise a signal, !SA_SIGINFO, sa.restorer == NULL\n");
82 sa
.handler
= handler_without_siginfo
;
83 if (syscall(SYS_sigaction
, SIGUSR1
, &sa
, 0) != 0)
84 err(1, "raw sigaction syscall");
90 printf("[OK]\t!SA_SIGINFO handler returned successfully\n");
92 printf("[FAIL]\t!SA_SIGINFO handler was not called\n");