Print this page
11841 badseg test times out
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/os-tests/tests/i386/badseg_exec.c
+++ new/usr/src/test/os-tests/tests/i386/badseg_exec.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 2019 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 #include <sys/resource.h>
22 22 #include <err.h>
23 23
24 24 /*
25 25 * Load a bunch of bad selectors into the seg regs: this will typically cause
26 26 * the child process to core dump, but it shouldn't panic the kernel...
27 27 *
28 28 * It's especially interesting to run this on CPU0.
29 29 */
30 30
31 31 unsigned short selector;
32 32
33 33 static void badds(void)
34 34 {
35 35 __asm__ volatile("movw %0, %%ds" : : "r" (selector));
36 36 }
37 37
38 38 static void bades(void)
39 39 {
40 40 __asm__ volatile("movw %0, %%es" : : "r" (selector));
41 41 }
42 42
43 43 static void badfs(void)
44 44 {
45 45 __asm__ volatile("movw %0, %%fs" : : "r" (selector));
46 46 }
47 47
48 48 static void badgs(void)
49 49 {
50 50 __asm__ volatile("movw %0, %%gs" : : "r" (selector));
51 51 }
52 52
53 53 static void badss(void)
54 54 {
55 55 __asm__ volatile("movw %0, %%ss" : : "r" (selector));
56 56 }
57 57
58 58 static void
59 59 resetseg(uint_t seg)
60 60 {
61 61 ucontext_t ucp;
62 62 volatile int done = 0;
63 63
64 64 int rc = getcontext(&ucp);
65 65 if (done) {
66 66 (void) getcontext(&ucp);
67 67 return;
68 68 }
69 69
70 70 if (rc == 0) {
71 71 done = 1;
72 72 ucp.uc_mcontext.gregs[seg] = selector;
73 73 (void) setcontext(&ucp);
74 74 }
75 75 abort();
76 76 }
77 77
78 78 static void
79 79 resetcs(void)
80 80 {
81 81 return (resetseg(CS));
82 82 }
83 83
84 84 static void
85 85 resetds(void)
86 86 {
87 87 return (resetseg(DS));
88 88 }
89 89
90 90 static void
91 91 resetes(void)
92 92 {
93 93 return (resetseg(ES));
94 94 }
95 95
96 96 static void
97 97 resetfs(void)
98 98 {
99 99 return (resetseg(FS));
100 100 }
101 101
102 102 static void
103 103 resetgs(void)
104 104 {
105 105 return (resetseg(GS));
106 106 }
107 107
108 108 static void
109 109 resetss(void)
110 110 {
111 111 return (resetseg(SS));
112 112 }
113 113
114 114 static void
115 115 inchild(void (*func)())
116 116 {
117 117 pid_t pid;
118 118
119 119 switch ((pid = fork())) {
120 120 case 0:
121 121 func();
122 122 exit(EXIT_SUCCESS);
123 123 case -1:
124 124 exit(EXIT_FAILURE);
125 125 default:
126 126 (void) waitpid(pid, NULL, 0);
127 127 return;
128 128 }
129 129
130 130 }
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
131 131
132 132 int
133 133 main(int argc, char *argv[])
134 134 {
135 135 struct rlimit rl = { 0, };
136 136
137 137 if (setrlimit(RLIMIT_CORE, &rl) != 0) {
138 138 err(EXIT_FAILURE, "failed to disable cores");
139 139 }
140 140
141 - for (selector = 0; selector < 8194; selector++) {
141 + for (selector = 0; selector < 512; selector++) {
142 142 inchild(resetcs);
143 143 inchild(resetds);
144 144 inchild(resetes);
145 145 inchild(resetfs);
146 146 inchild(resetgs);
147 147 inchild(resetss);
148 148 inchild(badds);
149 149 inchild(bades);
150 150 inchild(badfs);
151 151 inchild(badgs);
152 152 inchild(badss);
153 153 }
154 154
155 155 exit(EXIT_SUCCESS);
156 156 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX