Print this page
10076 make usr/src/test smatch clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/os-tests/tests/i386/badseg.c
+++ new/usr/src/test/os-tests/tests/i386/badseg.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2018 Joyent, Inc.
14 14 */
15 15
16 16 #include <stdlib.h>
17 17 #include <ucontext.h>
18 18 #include <sys/wait.h>
19 19 #include <unistd.h>
20 20 #include <sys/regset.h>
21 21
22 22 /*
23 23 * Load a bunch of bad selectors into the seg regs: this will typically cause
24 24 * the child process to core dump, but it shouldn't panic the kernel...
25 25 *
26 26 * It's especially interesting to run this on CPU0.
27 27 */
28 28
29 29 unsigned short selector;
30 30
31 31 static void badds(void)
32 32 {
33 33 __asm__ volatile("movw %0, %%ds" : : "r" (selector));
34 34 }
35 35
36 36 static void bades(void)
37 37 {
38 38 __asm__ volatile("movw %0, %%es" : : "r" (selector));
39 39 }
40 40
41 41 static void badfs(void)
42 42 {
43 43 __asm__ volatile("movw %0, %%fs" : : "r" (selector));
44 44 }
45 45
46 46 static void badgs(void)
47 47 {
48 48 __asm__ volatile("movw %0, %%gs" : : "r" (selector));
49 49 }
50 50
51 51 static void badss(void)
52 52 {
53 53 __asm__ volatile("movw %0, %%ss" : : "r" (selector));
54 54 }
55 55
56 56 static void
57 57 resetseg(uint_t seg)
58 58 {
59 59 ucontext_t ucp;
60 60 volatile int done = 0;
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
61 61
62 62 int rc = getcontext(&ucp);
63 63 if (done) {
64 64 (void) getcontext(&ucp);
65 65 return;
66 66 }
67 67
68 68 if (rc == 0) {
69 69 done = 1;
70 70 ucp.uc_mcontext.gregs[seg] = selector;
71 - setcontext(&ucp);
71 + (void) setcontext(&ucp);
72 72 }
73 73 abort();
74 74 }
75 75
76 76 static void
77 77 resetcs(void)
78 78 {
79 79 return (resetseg(CS));
80 80 }
81 81
82 82 static void
83 83 resetds(void)
84 84 {
85 85 return (resetseg(DS));
86 86 }
87 87
88 88 static void
89 89 resetes(void)
90 90 {
91 91 return (resetseg(ES));
92 92 }
93 93
94 94 static void
95 95 resetfs(void)
96 96 {
97 97 return (resetseg(FS));
98 98 }
99 99
100 100 static void
101 101 resetgs(void)
102 102 {
103 103 return (resetseg(GS));
104 104 }
105 105
106 106 static void
107 107 resetss(void)
108 108 {
109 109 return (resetseg(SS));
110 110 }
111 111
112 112 static void
113 113 inchild(void (*func)())
114 114 {
115 115 pid_t pid;
116 116
117 117 switch ((pid = fork())) {
118 118 case 0:
119 119 func();
120 120 exit(0);
121 121 case -1:
122 122 exit(1);
123 123 default:
124 124 (void) waitpid(pid, NULL, 0);
125 125 return;
126 126 }
127 127
128 128 }
129 129
130 130 int
131 131 main(int argc, char *argv[])
132 132 {
133 133 for (selector = 0; selector < 8194; selector++) {
134 134 inchild(resetcs);
135 135 inchild(resetds);
136 136 inchild(resetes);
137 137 inchild(resetfs);
138 138 inchild(resetgs);
139 139 inchild(resetss);
140 140 inchild(badds);
141 141 inchild(bades);
142 142 inchild(badfs);
143 143 inchild(badgs);
144 144 inchild(badss);
145 145 }
146 146
147 147 exit(0);
148 148 }
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX