forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/tools/testing/selftests/x86/vdso_restorer.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * vdso_restorer.c - tests vDSO-based signal restore
34 * Copyright (c) 2015 Andrew Lutomirski
4
- *
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.
8
- *
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.
135 *
146 * This makes sure that sa_restorer == NULL keeps working on 32-bit
157 * configurations. Modern glibc doesn't use it under any circumstances,
....@@ -23,6 +15,7 @@
2315
2416 #include <err.h>
2517 #include <stdio.h>
18
+#include <dlfcn.h>
2619 #include <string.h>
2720 #include <signal.h>
2821 #include <unistd.h>
....@@ -54,10 +47,22 @@
5447 int nerrs = 0;
5548 struct real_sigaction sa;
5649
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
+
5760 memset(&sa, 0, sizeof(sa));
5861 sa.handler = handler_with_siginfo;
5962 sa.flags = SA_SIGINFO;
6063 sa.restorer = NULL; /* request kernel-provided restorer */
64
+
65
+ printf("[RUN]\tRaise a signal, SA_SIGINFO, sa.restorer == NULL\n");
6166
6267 if (syscall(SYS_rt_sigaction, SIGUSR1, &sa, NULL, 8) != 0)
6368 err(1, "raw rt_sigaction syscall");
....@@ -71,6 +76,8 @@
7176 nerrs++;
7277 }
7378
79
+ printf("[RUN]\tRaise a signal, !SA_SIGINFO, sa.restorer == NULL\n");
80
+
7481 sa.flags = 0;
7582 sa.handler = handler_without_siginfo;
7683 if (syscall(SYS_sigaction, SIGUSR1, &sa, 0) != 0)