diff options
Diffstat (limited to 'tools/testing/selftests/x86/syscall_nt.c')
-rw-r--r-- | tools/testing/selftests/x86/syscall_nt.c | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/tools/testing/selftests/x86/syscall_nt.c b/tools/testing/selftests/x86/syscall_nt.c index 60c06af4646a..43fcab367fb0 100644 --- a/tools/testing/selftests/x86/syscall_nt.c +++ b/tools/testing/selftests/x86/syscall_nt.c | |||
@@ -17,6 +17,9 @@ | |||
17 | 17 | ||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include <unistd.h> | 19 | #include <unistd.h> |
20 | #include <string.h> | ||
21 | #include <signal.h> | ||
22 | #include <err.h> | ||
20 | #include <sys/syscall.h> | 23 | #include <sys/syscall.h> |
21 | #include <asm/processor-flags.h> | 24 | #include <asm/processor-flags.h> |
22 | 25 | ||
@@ -26,6 +29,8 @@ | |||
26 | # define WIDTH "l" | 29 | # define WIDTH "l" |
27 | #endif | 30 | #endif |
28 | 31 | ||
32 | static unsigned int nerrs; | ||
33 | |||
29 | static unsigned long get_eflags(void) | 34 | static unsigned long get_eflags(void) |
30 | { | 35 | { |
31 | unsigned long eflags; | 36 | unsigned long eflags; |
@@ -39,16 +44,52 @@ static void set_eflags(unsigned long eflags) | |||
39 | : : "rm" (eflags) : "flags"); | 44 | : : "rm" (eflags) : "flags"); |
40 | } | 45 | } |
41 | 46 | ||
42 | int main() | 47 | static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), |
48 | int flags) | ||
43 | { | 49 | { |
44 | printf("[RUN]\tSet NT and issue a syscall\n"); | 50 | struct sigaction sa; |
45 | set_eflags(get_eflags() | X86_EFLAGS_NT); | 51 | memset(&sa, 0, sizeof(sa)); |
52 | sa.sa_sigaction = handler; | ||
53 | sa.sa_flags = SA_SIGINFO | flags; | ||
54 | sigemptyset(&sa.sa_mask); | ||
55 | if (sigaction(sig, &sa, 0)) | ||
56 | err(1, "sigaction"); | ||
57 | } | ||
58 | |||
59 | static void sigtrap(int sig, siginfo_t *si, void *ctx_void) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | static void do_it(unsigned long extraflags) | ||
64 | { | ||
65 | unsigned long flags; | ||
66 | |||
67 | set_eflags(get_eflags() | extraflags); | ||
46 | syscall(SYS_getpid); | 68 | syscall(SYS_getpid); |
47 | if (get_eflags() & X86_EFLAGS_NT) { | 69 | flags = get_eflags(); |
48 | printf("[OK]\tThe syscall worked and NT is still set\n"); | 70 | if ((flags & extraflags) == extraflags) { |
49 | return 0; | 71 | printf("[OK]\tThe syscall worked and flags are still set\n"); |
50 | } else { | 72 | } else { |
51 | printf("[FAIL]\tThe syscall worked but NT was cleared\n"); | 73 | printf("[FAIL]\tThe syscall worked but flags were cleared (flags = 0x%lx but expected 0x%lx set)\n", |
52 | return 1; | 74 | flags, extraflags); |
75 | nerrs++; | ||
53 | } | 76 | } |
54 | } | 77 | } |
78 | |||
79 | int main(void) | ||
80 | { | ||
81 | printf("[RUN]\tSet NT and issue a syscall\n"); | ||
82 | do_it(X86_EFLAGS_NT); | ||
83 | |||
84 | /* | ||
85 | * Now try it again with TF set -- TF forces returns via IRET in all | ||
86 | * cases except non-ptregs-using 64-bit full fast path syscalls. | ||
87 | */ | ||
88 | |||
89 | sethandler(SIGTRAP, sigtrap, 0); | ||
90 | |||
91 | printf("[RUN]\tSet NT|TF and issue a syscall\n"); | ||
92 | do_it(X86_EFLAGS_NT | X86_EFLAGS_TF); | ||
93 | |||
94 | return nerrs == 0 ? 0 : 1; | ||
95 | } | ||