Debian Codegraph @

testsuite/systemtap.syscall/prctl.c

raw
1 /* COVERAGE: prctl */
2 #include <string.h>
3 #include <sys/prctl.h>
4 #include <linux/prctl.h>
5 #include <linux/capability.h>
6 #include <linux/version.h>
7
8 #if defined(PR_SET_SECUREBITS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
9 // PR_SET_SECUREBITS has existed since Linux 2.6.26. However, RHEL6
10 // doesn't have the associated /usr/include/linux/securebits.h include
11 // file. So, let's require at least a 3.0 kernel and hope that's
12 // reasonable to assume a /usr/include/linux/securebits.h file exists there.
13 #include <linux/securebits.h>
14 #endif
15
16 int main()
17 {
18 char buffer[1024];
19 int int_buffer;
20 int *int_ptr;
21
22 // PR_CAPBSET_READ (since Linux 2.6.25)
23 #ifdef PR_CAPBSET_READ
24 prctl(PR_CAPBSET_READ, CAP_CHOWN, 0L, 0L, 0L);
25 //staptest// prctl (PR_CAPBSET_READ, CAP_CHOWN) = NNNN
26 #endif
27
28 // PR_CAPBSET_DROP (since Linux 2.6.25)
29 #ifdef PR_CAPBSET_DROP
30 prctl(PR_CAPBSET_DROP, CAP_SETGID, 0L, 0L, 0L);
31 //staptest// prctl (PR_CAPBSET_DROP, CAP_SETGID) = NNNN
32 #endif
33
34 // PR_SET_CHILD_SUBREAPER (since Linux 3.4)
35 #ifdef PR_SET_CHILD_SUBREAPER
36 prctl(PR_SET_CHILD_SUBREAPER, 1L, 0L, 0L, 0L);
37 //staptest// prctl (PR_SET_CHILD_SUBREAPER, 1) = NNNN
38 #endif
39
40 // PR_GET_CHILD_SUBREAPER (since Linux 3.4)
41 #ifdef PR_GET_CHILD_SUBREAPER
42 prctl(PR_GET_CHILD_SUBREAPER, &int_buffer, 0L, 0L, 0L);
43 //staptest// prctl (PR_GET_CHILD_SUBREAPER, XXXX) = NNNN
44 #endif
45
46 // PR_SET_DUMPABLE (since Linux 2.3.20)
47 prctl(PR_SET_DUMPABLE, 0L, 0L, 0L, 0L);
48 //staptest// prctl (PR_SET_DUMPABLE, 0) = NNNN
49
50 // PR_GET_DUMPABLE (since Linux 2.3.20)
51 prctl(PR_GET_DUMPABLE, 0L, 0L, 0L, 0L);
52 //staptest// prctl (PR_GET_DUMPABLE) = NNNN
53
54 // PR_SET_ENDIAN (since Linux 2.6.18, PowerPC only)
55 // Since PR_SET_ENDIAN actually does something on PowerPC,
56 // don't run it there.
57 #if defined(PR_SET_ENDIAN) && !(defined(__powerpc64__) || defined(__powerpc__))
58 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
59 prctl(PR_SET_ENDIAN, PR_ENDIAN_LITTLE, 0L, 0L, 0L);
60 //staptest// prctl (PR_SET_ENDIAN, PR_ENDIAN_LITTLE) = NNNN
61 #else
62 prctl(PR_SET_ENDIAN, PR_ENDIAN_BIG, 0L, 0L, 0L);
63 //staptest// prctl (PR_SET_ENDIAN, PR_ENDIAN_BIG) = NNNN
64 #endif
65 #endif
66
67 // PR_GET_ENDIAN (since Linux 2.6.18, PowerPC only)
68 #ifdef PR_GET_ENDIAN
69 prctl(PR_GET_ENDIAN, &int_buffer, 0L, 0L, 0L);
70 //staptest// prctl (PR_GET_ENDIAN, XXXX) = NNNN
71 #endif
72
73 // PR_SET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
74 #ifdef PR_SET_FPEMU
75 prctl(PR_SET_FPEMU, PR_FPEMU_NOPRINT, 0L, 0L, 0L);
76 //staptest// prctl (PR_SET_FPEMU, PR_FPEMU_NOPRINT) = NNNN
77 #endif
78
79 // PR_GET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
80 #ifdef PR_GET_FPEMU
81 prctl(PR_GET_FPEMU, &int_buffer, 0L, 0L, 0L);
82 //staptest// prctl (PR_GET_FPEMU, XXXX) = NNNN
83 #endif
84
85 // PR_SET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
86 prctl(PR_SET_FPEXC, PR_FP_EXC_DISABLED, 0L, 0L, 0L);
87 //staptest// prctl (PR_SET_FPEXC, PR_FP_EXC_DISABLED) = NNNN
88
89 // PR_GET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
90 prctl(PR_GET_FPEXC, &int_buffer, 0L, 0L, 0L);
91 //staptest// prctl (PR_GET_FPEXC, XXXX) = NNNN
92
93 // PR_SET_KEEPCAPS (since Linux 2.2.18)
94 prctl(PR_SET_KEEPCAPS, 1L, 0L, 0L, 0L);
95 //staptest// prctl (PR_SET_KEEPCAPS, 1) = NNNN
96
97 // PR_GET_KEEPCAPS (since Linux 2.2.18)
98 prctl(PR_GET_KEEPCAPS, 0L, 0L, 0L, 0L);
99 //staptest// prctl (PR_GET_KEEPCAPS) = NNNN
100
101 // PR_GET_NAME (since Linux 2.6.11)
102 prctl(PR_GET_NAME, &buffer, 0L, 0L, 0L);
103 //staptest// prctl (PR_GET_NAME, XXXX) = 0
104
105 // PR_SET_NAME (since Linux 2.6.9)
106 // Notice we're setting the name to the same name we got from
107 // PR_GET_NAME.
108 prctl(PR_SET_NAME, &buffer, 0L, 0L, 0L);
109 //staptest// prctl (PR_SET_NAME, XXXX) = NNNN
110
111 // PR_SET_NO_NEW_PRIVS (since Linux 3.5)
112 #ifdef PR_SET_NO_NEW_PRIVS
113 prctl(PR_SET_NO_NEW_PRIVS, 1L, 0L, 0L, 0L);
114 //staptest// prctl (PR_SET_NO_NEW_PRIVS, 1) = NNNN
115 #endif
116
117 // PR_GET_NO_NEW_PRIVS (since Linux 3.5)
118 #ifdef PR_GET_NO_NEW_PRIVS
119 prctl(PR_GET_NO_NEW_PRIVS, 0L, 0L, 0L, 0L);
120 //staptest// prctl (PR_GET_NO_NEW_PRIVS) = NNNN
121 #endif
122
123 // PR_SET_PDEATHSIG (since Linux 2.1.57)
124 prctl(PR_GET_PDEATHSIG, &int_buffer, 0L, 0L, 0L);
125 //staptest// prctl (PR_GET_PDEATHSIG, XXXX) = 0
126
127 // PR_SET_PTRACER (since Linux 3.4)
128 #ifdef PR_SET_PTRACER
129 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0L, 0L, 0L);
130 //staptest// prctl (PR_SET_PTRACER, PR_SET_PTRACER_ANY) = NNNN
131
132 prctl(PR_SET_PTRACER, 0L, 0L, 0L, 0L);
133 //staptest// prctl (PR_SET_PTRACER, 0) = NNNN
134 #endif
135
136 // PR_SET_SECCOMP (since Linux 2.6.23)
137 // Note that PR_GET_SECCOMP causes a SIGKILL signal to be sent if
138 // we're in strict secure computing mode.
139 #ifdef PR_GET_SECCOMP
140 prctl(PR_GET_SECCOMP, 0L, 0L, 0L, 0L);
141 //staptest// prctl (PR_GET_SECCOMP) = NNNN
142 #endif
143
144 // PR_SET_SECUREBITS (since Linux 2.6.26). However, RHEL6 doesn't
145 // have the SECBIT stuff available to userspace (no
146 // linux/securebits.h header exists). So, we require a 3.0 kernel.
147 #if defined(PR_SET_SECUREBITS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
148 prctl(PR_SET_SECUREBITS, SECBIT_KEEP_CAPS | SECBIT_NO_SETUID_FIXUP,
149 0L, 0L, 0L);
150 //staptest// prctl (PR_SET_SECUREBITS, SECBIT_NO_SETUID_FIXUP|SECBIT_KEEP_CAPS) = NNNN
151 #endif
152
153 // PR_GET_SECUREBITS (since Linux 2.6.26)
154 #ifdef PR_GET_SECUREBITS
155 prctl(PR_GET_SECUREBITS, 0L, 0L, 0L, 0L);
156 //staptest// prctl (PR_GET_SECUREBITS) = NNNN
157 #endif
158
159 // PR_GET_TID_ADDRESS (since Linux 3.5)
160 #ifdef PR_GET_TID_ADDRESS
161 prctl(PR_GET_TID_ADDRESS, &int_ptr, 0L, 0L, 0L);
162 //staptest// prctl (PR_GET_TID_ADDRESS, XXXX) = NNNN
163 #endif
164
165 // PR_SET_TIMERSLACK (since Linux 2.6.28)
166 #ifdef PR_SET_TIMERSLACK
167 prctl(PR_SET_TIMERSLACK, 10L, 0L, 0L, 0L);
168 //staptest// prctl (PR_SET_TIMERSLACK, 10) = NNNN
169
170 prctl(PR_SET_TIMERSLACK, 0L, 0L, 0L, 0L);
171 //staptest// prctl (PR_SET_TIMERSLACK, 0) = NNNN
172 #endif
173
174 // PR_GET_TIMERSLACK (since Linux 2.6.28)
175 #ifdef PR_GET_TIMERSLACK
176 prctl(PR_GET_TIMERSLACK, 0L, 0L, 0L, 0L);
177 //staptest// prctl (PR_GET_TIMERSLACK) = NNNN
178 #endif
179
180 // PR_SET_TIMING (since Linux 2.6.0-test4)
181 #ifdef PR_SET_TIMING
182 prctl(PR_SET_TIMING, PR_TIMING_TIMESTAMP, 0L, 0L, 0L);
183 //staptest// prctl (PR_SET_TIMING, PR_TIMING_TIMESTAMP) = NNNN
184 #endif
185
186 // PR_GET_TIMING (since Linux 2.6.0-test4)
187 #ifdef PR_GET_TIMING
188 prctl(PR_GET_TIMING, 0L, 0L, 0L, 0L);
189 //staptest// prctl (PR_GET_TIMING) = NNNN
190 #endif
191
192 // PR_TASK_PERF_EVENTS_ENABLE (since Linux 2.6.31)
193 #ifdef PR_TASK_PERF_EVENTS_ENABLE
194 prctl(PR_TASK_PERF_EVENTS_ENABLE, 0L, 0L, 0L, 0L);
195 //staptest// prctl (PR_TASK_PERF_EVENTS_ENABLE) = NNNN
196 #endif
197
198 // PR_TASK_PERF_EVENTS_DISABLE (since Linux 2.6.31)
199 #ifdef PR_TASK_PERF_EVENTS_DISABLE
200 prctl(PR_TASK_PERF_EVENTS_DISABLE, 0L, 0L, 0L, 0L);
201 //staptest// prctl (PR_TASK_PERF_EVENTS_DISABLE) = NNNN
202 #endif
203
204 // PR_SET_TSC (since Linux 2.6.26, x86 only)
205 #ifdef PR_SET_TSC
206 prctl(PR_SET_TSC, PR_TSC_ENABLE, 0L, 0L, 0L);
207 //staptest// prctl (PR_SET_TSC, PR_TSC_ENABLE) = NNNN
208 #endif
209
210 // PR_GET_TSC (since Linux 2.6.26, x86 only)
211 #ifdef PR_GET_TSC
212 prctl(PR_GET_TSC, &int_buffer, 0L, 0L, 0L);
213 //staptest// prctl (PR_GET_TSC, XXXX) = NNNN
214 #endif
215
216 // PR_SET_UNALIGN
217 prctl(PR_SET_UNALIGN, PR_UNALIGN_NOPRINT, 0L, 0L, 0L);
218 //staptest// prctl (PR_SET_UNALIGN, PR_UNALIGN_NOPRINT) = NNNN
219
220 // PR_GET_UNALIGN
221 prctl(PR_GET_UNALIGN, &int_buffer, 0L, 0L, 0L);
222 //staptest// prctl (PR_GET_UNALIGN, XXXX) = NNNN
223
224 // PR_MCE_KILL (since Linux 2.6.32)
225 #ifdef PR_MCE_KILL
226 prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0L, 0L);
227 //staptest// prctl (PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY) = NNNN
228
229 prctl(PR_MCE_KILL, PR_MCE_KILL_CLEAR, 0L, 0L, 0L);
230 //staptest// prctl (PR_MCE_KILL, PR_MCE_KILL_CLEAR) = NNNN
231 #endif
232
233 // PR_MCE_KILL_GET (since Linux 2.6.32)
234 #ifdef PR_MCE_KILL
235 prctl(PR_MCE_KILL_GET, 0L, 0L, 0L, 0L);
236 //staptest// prctl (PR_MCE_KILL_GET) = NNNN
237 #endif
238
239 // PR_SET_MM (since Linux 3.3)
240 #ifdef PR_SET_MM
241 // PR_SET_MM_START_BRK
242 prctl(PR_SET_MM, PR_SET_MM_START_BRK, 0L, 0L, 0L);
243 //staptest// prctl (PR_SET_MM, PR_SET_MM_START_BRK, 0x0) = NNNN
244
245 // PR_SET_MM_BRK
246 prctl(PR_SET_MM, PR_SET_MM_BRK, 0L, 0L, 0L);
247 //staptest// prctl (PR_SET_MM, PR_SET_MM_BRK, 0x0) = NNNN
248 #endif
249
250 /* Limit testing. */
251 prctl(-1, 0L, 0L, 0L, 0L);
252 //staptest// prctl (0xffffffff, 0x0, 0x0, 0x0, 0x0) = -NNNN
253
254 prctl(-1, -1L, 0L, 0L, 0L);
255 //staptest// prctl (0xffffffff, 0x[f]+, 0x0, 0x0, 0x0) = -NNNN
256
257 prctl(-1, 0L, -1L, 0L, 0L);
258 //staptest// prctl (0xffffffff, 0x0, 0x[f]+, 0x0, 0x0) = -NNNN
259
260 prctl(-1, 0L, 0L, -1L, 0L);
261 //staptest// prctl (0xffffffff, 0x0, 0x0, 0x[f]+, 0x0) = -NNNN
262
263 prctl(-1, 0L, 0L, 0L, -1L);
264 //staptest// prctl (0xffffffff, 0x0, 0x0, 0x0, 0x[f]+) = -NNNN
265
266 return 0;
267 }