1 // SPDX-License-Identifier: GPL-2.0-only
3 * syscall_nt.c - checks syscalls with NT set
4 * Copyright (c) 2014-2015 Andrew Lutomirski
6 * Some obscure user-space code requires the ability to make system calls
7 * with FLAGS.NT set. Make sure it works.
15 #include <sys/syscall.h>
19 static unsigned int nerrs
;
21 static void sethandler(int sig
, void (*handler
)(int, siginfo_t
*, void *),
25 memset(&sa
, 0, sizeof(sa
));
26 sa
.sa_sigaction
= handler
;
27 sa
.sa_flags
= SA_SIGINFO
| flags
;
28 sigemptyset(&sa
.sa_mask
);
29 if (sigaction(sig
, &sa
, 0))
33 static void sigtrap(int sig
, siginfo_t
*si
, void *ctx_void
)
37 static void do_it(unsigned long extraflags
)
41 set_eflags(get_eflags() | extraflags
);
44 set_eflags(X86_EFLAGS_IF
| X86_EFLAGS_FIXED
);
45 if ((flags
& extraflags
) == extraflags
) {
46 printf("[OK]\tThe syscall worked and flags are still set\n");
48 printf("[FAIL]\tThe syscall worked but flags were cleared (flags = 0x%lx but expected 0x%lx set)\n",
56 printf("[RUN]\tSet NT and issue a syscall\n");
59 printf("[RUN]\tSet AC and issue a syscall\n");
62 printf("[RUN]\tSet NT|AC and issue a syscall\n");
63 do_it(X86_EFLAGS_NT
| X86_EFLAGS_AC
);
66 * Now try it again with TF set -- TF forces returns via IRET in all
67 * cases except non-ptregs-using 64-bit full fast path syscalls.
70 sethandler(SIGTRAP
, sigtrap
, 0);
72 printf("[RUN]\tSet TF and issue a syscall\n");
75 printf("[RUN]\tSet NT|TF and issue a syscall\n");
76 do_it(X86_EFLAGS_NT
| X86_EFLAGS_TF
);
78 printf("[RUN]\tSet AC|TF and issue a syscall\n");
79 do_it(X86_EFLAGS_AC
| X86_EFLAGS_TF
);
81 printf("[RUN]\tSet NT|AC|TF and issue a syscall\n");
82 do_it(X86_EFLAGS_NT
| X86_EFLAGS_AC
| X86_EFLAGS_TF
);
85 * Now try DF. This is evil and it's plausible that we will crash
86 * glibc, but glibc would have to do something rather surprising
89 printf("[RUN]\tSet DF and issue a syscall\n");
92 printf("[RUN]\tSet TF|DF and issue a syscall\n");
93 do_it(X86_EFLAGS_TF
| X86_EFLAGS_DF
);
95 return nerrs
== 0 ? 0 : 1;