2 * syscall_nt.c - checks syscalls with NT set
3 * Copyright (c) 2014-2015 Andrew Lutomirski
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.
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.
14 * Some obscure user-space code requires the ability to make system calls
15 * with FLAGS.NT set. Make sure it works.
20 #include <sys/syscall.h>
21 #include <asm/processor-flags.h>
29 static unsigned long get_eflags(void)
32 asm volatile ("pushf" WIDTH "\n\tpop" WIDTH " %0" : "=rm" (eflags));
36 static void set_eflags(unsigned long eflags)
38 asm volatile ("push" WIDTH " %0\n\tpopf" WIDTH
39 : : "rm" (eflags) : "flags");
44 printf("[RUN]\tSet NT and issue a syscall\n");
45 set_eflags(get_eflags() | X86_EFLAGS_NT);
47 if (get_eflags() & X86_EFLAGS_NT) {
48 printf("[OK]\tThe syscall worked and NT is still set\n");
51 printf("[FAIL]\tThe syscall worked but NT was cleared\n");