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>
16 #include <asm/processor-flags.h>
24 static unsigned int nerrs
;
26 static unsigned long get_eflags(void)
29 asm volatile ("pushf" WIDTH
"\n\tpop" WIDTH
" %0" : "=rm" (eflags
));
33 static void set_eflags(unsigned long eflags
)
35 asm volatile ("push" WIDTH
" %0\n\tpopf" WIDTH
36 : : "rm" (eflags
) : "flags");
39 static void sethandler(int sig
, void (*handler
)(int, siginfo_t
*, void *),
43 memset(&sa
, 0, sizeof(sa
));
44 sa
.sa_sigaction
= handler
;
45 sa
.sa_flags
= SA_SIGINFO
| flags
;
46 sigemptyset(&sa
.sa_mask
);
47 if (sigaction(sig
, &sa
, 0))
51 static void sigtrap(int sig
, siginfo_t
*si
, void *ctx_void
)
55 static void do_it(unsigned long extraflags
)
59 set_eflags(get_eflags() | extraflags
);
62 if ((flags
& extraflags
) == extraflags
) {
63 printf("[OK]\tThe syscall worked and flags are still set\n");
65 printf("[FAIL]\tThe syscall worked but flags were cleared (flags = 0x%lx but expected 0x%lx set)\n",
73 printf("[RUN]\tSet NT and issue a syscall\n");
77 * Now try it again with TF set -- TF forces returns via IRET in all
78 * cases except non-ptregs-using 64-bit full fast path syscalls.
81 sethandler(SIGTRAP
, sigtrap
, 0);
83 printf("[RUN]\tSet NT|TF and issue a syscall\n");
84 do_it(X86_EFLAGS_NT
| X86_EFLAGS_TF
);
86 return nerrs
== 0 ? 0 : 1;