2 * vdso_restorer.c - tests vDSO-based signal restore
3 * Copyright (c) 2015 Andrew Lutomirski
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * This makes sure that sa_restorer == NULL keeps working on 32-bit
15 * configurations. Modern glibc doesn't use it under any circumstances,
16 * so it's easy to overlook breakage.
18 * 64-bit userspace has never supported sa_restorer == NULL, so this is
30 #include <sys/syscall.h>
32 /* Open-code this -- the headers are too messy to easily use them. */
33 struct real_sigaction {
40 static volatile sig_atomic_t handler_called;
42 static void handler_with_siginfo(int sig, siginfo_t *info, void *ctx_void)
47 static void handler_without_siginfo(int sig)
55 struct real_sigaction sa;
57 memset(&sa, 0, sizeof(sa));
58 sa.handler = handler_with_siginfo;
59 sa.flags = SA_SIGINFO;
60 sa.restorer = NULL; /* request kernel-provided restorer */
62 if (syscall(SYS_rt_sigaction, SIGUSR1, &sa, NULL, 8) != 0)
63 err(1, "raw rt_sigaction syscall");
68 printf("[OK]\tSA_SIGINFO handler returned successfully\n");
70 printf("[FAIL]\tSA_SIGINFO handler was not called\n");
75 sa.handler = handler_without_siginfo;
76 if (syscall(SYS_sigaction, SIGUSR1, &sa, 0) != 0)
77 err(1, "raw sigaction syscall");
83 printf("[OK]\t!SA_SIGINFO handler returned successfully\n");
85 printf("[FAIL]\t!SA_SIGINFO handler was not called\n");