~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/x86/syscall_nt.c

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * syscall_nt.c - checks syscalls with NT set
  3  * Copyright (c) 2014-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.
 13  *
 14  * Some obscure user-space code requires the ability to make system calls
 15  * with FLAGS.NT set.  Make sure it works.
 16  */
 17 
 18 #include <stdio.h>
 19 #include <unistd.h>
 20 #include <string.h>
 21 #include <signal.h>
 22 #include <err.h>
 23 #include <sys/syscall.h>
 24 #include <asm/processor-flags.h>
 25 
 26 #ifdef __x86_64__
 27 # define WIDTH "q"
 28 #else
 29 # define WIDTH "l"
 30 #endif
 31 
 32 static unsigned int nerrs;
 33 
 34 static unsigned long get_eflags(void)
 35 {
 36         unsigned long eflags;
 37         asm volatile ("pushf" WIDTH "\n\tpop" WIDTH " %0" : "=rm" (eflags));
 38         return eflags;
 39 }
 40 
 41 static void set_eflags(unsigned long eflags)
 42 {
 43         asm volatile ("push" WIDTH " %0\n\tpopf" WIDTH
 44                       : : "rm" (eflags) : "flags");
 45 }
 46 
 47 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
 48                        int flags)
 49 {
 50         struct sigaction sa;
 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);
 68         syscall(SYS_getpid);
 69         flags = get_eflags();
 70         if ((flags & extraflags) == extraflags) {
 71                 printf("[OK]\tThe syscall worked and flags are still set\n");
 72         } else {
 73                 printf("[FAIL]\tThe syscall worked but flags were cleared (flags = 0x%lx but expected 0x%lx set)\n",
 74                        flags, extraflags);
 75                 nerrs++;
 76         }
 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 }
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp