hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/testing/selftests/x86/syscall_nt.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * syscall_nt.c - checks syscalls with NT set
34 * 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.
135 *
146 * Some obscure user-space code requires the ability to make system calls
157 * with FLAGS.NT set. Make sure it works.
....@@ -21,28 +13,10 @@
2113 #include <signal.h>
2214 #include <err.h>
2315 #include <sys/syscall.h>
24
-#include <asm/processor-flags.h>
2516
26
-#ifdef __x86_64__
27
-# define WIDTH "q"
28
-#else
29
-# define WIDTH "l"
30
-#endif
17
+#include "helpers.h"
3118
3219 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
-}
4620
4721 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
4822 int flags)
....@@ -82,6 +56,12 @@
8256 printf("[RUN]\tSet NT and issue a syscall\n");
8357 do_it(X86_EFLAGS_NT);
8458
59
+ printf("[RUN]\tSet AC and issue a syscall\n");
60
+ do_it(X86_EFLAGS_AC);
61
+
62
+ printf("[RUN]\tSet NT|AC and issue a syscall\n");
63
+ do_it(X86_EFLAGS_NT | X86_EFLAGS_AC);
64
+
8565 /*
8666 * Now try it again with TF set -- TF forces returns via IRET in all
8767 * cases except non-ptregs-using 64-bit full fast path syscalls.
....@@ -89,8 +69,28 @@
8969
9070 sethandler(SIGTRAP, sigtrap, 0);
9171
72
+ printf("[RUN]\tSet TF and issue a syscall\n");
73
+ do_it(X86_EFLAGS_TF);
74
+
9275 printf("[RUN]\tSet NT|TF and issue a syscall\n");
9376 do_it(X86_EFLAGS_NT | X86_EFLAGS_TF);
9477
78
+ printf("[RUN]\tSet AC|TF and issue a syscall\n");
79
+ do_it(X86_EFLAGS_AC | X86_EFLAGS_TF);
80
+
81
+ printf("[RUN]\tSet NT|AC|TF and issue a syscall\n");
82
+ do_it(X86_EFLAGS_NT | X86_EFLAGS_AC | X86_EFLAGS_TF);
83
+
84
+ /*
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
87
+ * for this to happen.
88
+ */
89
+ printf("[RUN]\tSet DF and issue a syscall\n");
90
+ do_it(X86_EFLAGS_DF);
91
+
92
+ printf("[RUN]\tSet TF|DF and issue a syscall\n");
93
+ do_it(X86_EFLAGS_TF | X86_EFLAGS_DF);
94
+
9595 return nerrs == 0 ? 0 : 1;
9696 }