~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/x86/vdso_restorer.c

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * vdso_restorer.c - tests vDSO-based signal restore
  4  * Copyright (c) 2015 Andrew Lutomirski
  5  *
  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.
  9  *
 10  * 64-bit userspace has never supported sa_restorer == NULL, so this is
 11  * 32-bit only.
 12  */
 13 
 14 #define _GNU_SOURCE
 15 
 16 #include <err.h>
 17 #include <stdio.h>
 18 #include <dlfcn.h>
 19 #include <string.h>
 20 #include <signal.h>
 21 #include <unistd.h>
 22 #include <syscall.h>
 23 #include <sys/syscall.h>
 24 
 25 /* Open-code this -- the headers are too messy to easily use them. */
 26 struct real_sigaction {
 27         void *handler;
 28         unsigned long flags;
 29         void *restorer;
 30         unsigned int mask[2];
 31 };
 32 
 33 static volatile sig_atomic_t handler_called;
 34 
 35 static void handler_with_siginfo(int sig, siginfo_t *info, void *ctx_void)
 36 {
 37         handler_called = 1;
 38 }
 39 
 40 static void handler_without_siginfo(int sig)
 41 {
 42         handler_called = 1;
 43 }
 44 
 45 int main()
 46 {
 47         int nerrs = 0;
 48         struct real_sigaction sa;
 49 
 50         void *vdso = dlopen("linux-vdso.so.1",
 51                             RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
 52         if (!vdso)
 53                 vdso = dlopen("linux-gate.so.1",
 54                               RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
 55         if (!vdso) {
 56                 printf("[SKIP]\tFailed to find vDSO.  Tests are not expected to work.\n");
 57                 return 0;
 58         }
 59 
 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 */
 64 
 65         printf("[RUN]\tRaise a signal, SA_SIGINFO, sa.restorer == NULL\n");
 66 
 67         if (syscall(SYS_rt_sigaction, SIGUSR1, &sa, NULL, 8) != 0)
 68                 err(1, "raw rt_sigaction syscall");
 69 
 70         raise(SIGUSR1);
 71 
 72         if (handler_called) {
 73                 printf("[OK]\tSA_SIGINFO handler returned successfully\n");
 74         } else {
 75                 printf("[FAIL]\tSA_SIGINFO handler was not called\n");
 76                 nerrs++;
 77         }
 78 
 79         printf("[RUN]\tRaise a signal, !SA_SIGINFO, sa.restorer == NULL\n");
 80 
 81         sa.flags = 0;
 82         sa.handler = handler_without_siginfo;
 83         if (syscall(SYS_sigaction, SIGUSR1, &sa, 0) != 0)
 84                 err(1, "raw sigaction syscall");
 85         handler_called = 0;
 86 
 87         raise(SIGUSR1);
 88 
 89         if (handler_called) {
 90                 printf("[OK]\t!SA_SIGINFO handler returned successfully\n");
 91         } else {
 92                 printf("[FAIL]\t!SA_SIGINFO handler was not called\n");
 93                 nerrs++;
 94         }
 95 }
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp