Ptrace.xs

filter: Statementstmt 70.5% 91 / 129 Branchbran 50.0% 32 / 64 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.7% 123 / 193 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Sys/Ptrace.pm ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include <sys/ptrace.h>
5  
6 static int
7 0 not_here(char *s)
8 {
9 0 croak("%s not implemented on this architecture", s);
10 return -1;
11 }
12  
13 static double
14 6 constant_PT_W(char *name, int len, int arg)
15 {
16 6 ▶ if (4 + 5 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (4 + 5 >= len ) { 0 6 6
17 0 errno = EINVAL;
18 0 return 0;
19 }
20 6 switch (name[4 + 5]) {
21 2 case 'D':
22 2 ▶ if (strEQ(name + 4, "RITE_D")) { /* PT_W removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "RITE_D")) { /* PT_W removed */ 2 0 2
23 #ifdef PT_WRITE_D
24 2 return PT_WRITE_D;
25 #else
26 goto not_there;
27 #endif
28 }
29 case 'I':
30 2 ▶ if (strEQ(name + 4, "RITE_I")) { /* PT_W removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "RITE_I")) { /* PT_W removed */ 2 0 2
31 #ifdef PT_WRITE_I
32 2 return PT_WRITE_I;
33 #else
34 goto not_there;
35 #endif
36 }
37 case 'U':
38 2 ▶ if (strEQ(name + 4, "RITE_U")) { /* PT_W removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "RITE_U")) { /* PT_W removed */ 2 0 2
39 #ifdef PT_WRITE_U
40 2 return PT_WRITE_U;
41 #else
42 goto not_there;
43 #endif
44 }
45 }
46 0 errno = EINVAL;
47 0 return 0;
48  
49 not_there:
50 errno = ENOENT;
51 return 0;
52 }
53  
54 static double
55 4 constant_PT_GETF(char *name, int len, int arg)
56 {
57 4 ▶ if (7 + 1 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (7 + 1 >= len ) { 0 4 4
58 0 errno = EINVAL;
59 0 return 0;
60 }
61 4 switch (name[7 + 1]) {
62 2 case 'R':
63 2 ▶ if (strEQ(name + 7, "PREGS")) { /* PT_GETF removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 7, "PREGS")) { /* PT_GETF removed */ 2 0 2
64 #ifdef PT_GETFPREGS
65 2 return PT_GETFPREGS;
66 #else
67 goto not_there;
68 #endif
69 }
70 case 'X':
71 2 ▶ if (strEQ(name + 7, "PXREGS")) { /* PT_GETF removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 7, "PXREGS")) { /* PT_GETF removed */ 2 0 2
72 #ifdef PT_GETFPXREGS
73 2 return PT_GETFPXREGS;
74 #else
75 goto not_there;
76 #endif
77 }
78 }
79 0 errno = EINVAL;
80 0 return 0;
81  
82 not_there:
83 errno = ENOENT;
84 return 0;
85 }
86  
87 static double
88 6 constant_PT_G(char *name, int len, int arg)
89 {
90 6 ▶ if (4 + 2 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (4 + 2 >= len ) { 0 6 6
91 0 errno = EINVAL;
92 0 return 0;
93 }
94 6 switch (name[4 + 2]) {
95 4 case 'F':
96 4 ▶ if (!strnEQ(name + 4,"ET", 2))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 4,"ET", 2)) 0 4 4
97 0 break;
98 4 return constant_PT_GETF(name, len, arg);
99 2 case 'R':
100 2 ▶ if (strEQ(name + 4, "ETREGS")) { /* PT_G removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "ETREGS")) { /* PT_G removed */ 2 0 2
101 #ifdef PT_GETREGS
102 2 return PT_GETREGS;
103 #else
104 goto not_there;
105 #endif
106 }
107 }
108 0 errno = EINVAL;
109 0 return 0;
110  
111 not_there:
112 errno = ENOENT;
113 return 0;
114 }
115  
116 static double
117 9 constant_PT_R(char *name, int len, int arg)
118 {
119 9 ▶ if (4 + 4 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (4 + 4 >= len ) { 0 9 9
120 0 errno = EINVAL;
121 0 return 0;
122 }
123 9 switch (name[4 + 4]) {
124 3 case 'D':
125 3 ▶ if (strEQ(name + 4, "EAD_D")) { /* PT_R removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "EAD_D")) { /* PT_R removed */ 3 0 3
126 #ifdef PT_READ_D
127 3 return PT_READ_D;
128 #else
129 goto not_there;
130 #endif
131 }
132 case 'I':
133 3 ▶ if (strEQ(name + 4, "EAD_I")) { /* PT_R removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "EAD_I")) { /* PT_R removed */ 3 0 3
134 #ifdef PT_READ_I
135 3 return PT_READ_I;
136 #else
137 goto not_there;
138 #endif
139 }
140 case 'U':
141 3 ▶ if (strEQ(name + 4, "EAD_U")) { /* PT_R removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "EAD_U")) { /* PT_R removed */ 3 0 3
142 #ifdef PT_READ_U
143 3 return PT_READ_U;
144 #else
145 goto not_there;
146 #endif
147 }
148 }
149 0 errno = EINVAL;
150 0 return 0;
151  
152 not_there:
153 errno = ENOENT;
154 return 0;
155 }
156  
157 static double
158 4 constant_PT_SETF(char *name, int len, int arg)
159 {
160 4 ▶ if (7 + 1 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (7 + 1 >= len ) { 0 4 4
161 0 errno = EINVAL;
162 0 return 0;
163 }
164 4 switch (name[7 + 1]) {
165 2 case 'R':
166 2 ▶ if (strEQ(name + 7, "PREGS")) { /* PT_SETF removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 7, "PREGS")) { /* PT_SETF removed */ 2 0 2
167 #ifdef PT_SETFPREGS
168 2 return PT_SETFPREGS;
169 #else
170 goto not_there;
171 #endif
172 }
173 case 'X':
174 2 ▶ if (strEQ(name + 7, "PXREGS")) { /* PT_SETF removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 7, "PXREGS")) { /* PT_SETF removed */ 2 0 2
175 #ifdef PT_SETFPXREGS
176 2 return PT_SETFPXREGS;
177 #else
178 goto not_there;
179 #endif
180 }
181 }
182 0 errno = EINVAL;
183 0 return 0;
184  
185 not_there:
186 errno = ENOENT;
187 return 0;
188 }
189  
190 static double
191 6 constant_PT_SE(char *name, int len, int arg)
192 {
193 6 ▶ if (5 + 1 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (5 + 1 >= len ) { 0 6 6
194 0 errno = EINVAL;
195 0 return 0;
196 }
197 6 switch (name[5 + 1]) {
198 4 case 'F':
199 4 ▶ if (!strnEQ(name + 5,"T", 1))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 5,"T", 1)) 0 4 4
200 0 break;
201 4 return constant_PT_SETF(name, len, arg);
202 2 case 'R':
203 2 ▶ if (strEQ(name + 5, "TREGS")) { /* PT_SE removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 5, "TREGS")) { /* PT_SE removed */ 2 0 2
204 #ifdef PT_SETREGS
205 2 return PT_SETREGS;
206 #else
207 goto not_there;
208 #endif
209 }
210 }
211 0 errno = EINVAL;
212 0 return 0;
213  
214 not_there:
215 errno = ENOENT;
216 return 0;
217 }
218  
219 static double
220 11 constant_PT_S(char *name, int len, int arg)
221 {
222 11 switch (name[4 + 0]) {
223 6 case 'E':
224 6 return constant_PT_SE(name, len, arg);
225 2 case 'T':
226 2 ▶ if (strEQ(name + 4, "TEP")) { /* PT_S removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "TEP")) { /* PT_S removed */ 2 0 2
227 #ifdef PT_STEP
228 2 return PT_STEP;
229 #else
230 goto not_there;
231 #endif
232 }
233 case 'Y':
234 3 ▶ if (strEQ(name + 4, "YSCALL")) { /* PT_S removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 4, "YSCALL")) { /* PT_S removed */ 3 0 3
235 #ifdef PT_SYSCALL
236 3 return PT_SYSCALL;
237 #else
238 goto not_there;
239 #endif
240 }
241 }
242 0 errno = EINVAL;
243 0 return 0;
244  
245 not_there:
246 errno = ENOENT;
247 return 0;
248 }
249  
250 static double
251 42 constant(char *name, int len, int arg)
252 {
253 42 errno = 0;
254 42 ▶ if (0 + 3 >= len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 + 3 >= len ) { 0 42 42
255 0 errno = EINVAL;
256 0 return 0;
257 }
258 42 switch (name[0 + 3]) {
259 2 case 'A':
260 2 ▶ if (strEQ(name + 0, "PT_ATTACH")) { /* removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 0, "PT_ATTACH")) { /* removed */ 2 0 2
261 #ifdef PT_ATTACH
262 2 return PT_ATTACH;
263 #else
264 goto not_there;
265 #endif
266 }
267 case 'C':
268 2 ▶ if (strEQ(name + 0, "PT_CONTINUE")) { /* removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 0, "PT_CONTINUE")) { /* removed */ 2 0 2
269 #ifdef PT_CONTINUE
270 2 return PT_CONTINUE;
271 #else
272 goto not_there;
273 #endif
274 }
275 case 'D':
276 2 ▶ if (strEQ(name + 0, "PT_DETACH")) { /* removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 0, "PT_DETACH")) { /* removed */ 2 0 2
277 #ifdef PT_DETACH
278 2 return PT_DETACH;
279 #else
280 goto not_there;
281 #endif
282 }
283 case 'G':
284 6 ▶ if (!strnEQ(name + 0,"PT_", 3))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 0,"PT_", 3)) 0 6 6
285 0 break;
286 6 return constant_PT_G(name, len, arg);
287 2 case 'K':
288 2 ▶ if (strEQ(name + 0, "PT_KILL")) { /* removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 0, "PT_KILL")) { /* removed */ 2 0 2
289 #ifdef PT_KILL
290 2 return PT_KILL;
291 #else
292 goto not_there;
293 #endif
294 }
295 case 'R':
296 9 ▶ if (!strnEQ(name + 0,"PT_", 3))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 0,"PT_", 3)) 0 9 9
297 0 break;
298 9 return constant_PT_R(name, len, arg);
299 11 case 'S':
300 11 ▶ if (!strnEQ(name + 0,"PT_", 3))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 0,"PT_", 3)) 0 11 11
301 0 break;
302 11 return constant_PT_S(name, len, arg);
303 2 case 'T':
304 2 ▶ if (strEQ(name + 0, "PT_TRACE_ME")) { /* removed */
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name + 0, "PT_TRACE_ME")) { /* removed */ 2 0 2
305 #ifdef PT_TRACE_ME
306 2 return PT_TRACE_ME;
307 #else
308 goto not_there;
309 #endif
310 }
311 case 'W':
312 6 ▶ if (!strnEQ(name + 0,"PT_", 3))
Branch: 1 branch
BranchTrueFalseTotal
if (!strnEQ(name + 0,"PT_", 3)) 0 6 6
313 0 break;
314 6 return constant_PT_W(name, len, arg);
315 }
316 0 errno = EINVAL;
317 0 return 0;
318  
319 not_there:
320 errno = ENOENT;
321 return 0;
322 }
323  
324  
325 MODULE = Sys::Ptrace PACKAGE = Sys::Ptrace
326  
327 double
328 constant(sv,arg)
329 PREINIT:
330 STRLEN len;
331 INPUT:
332 SV * sv
333 char * s = SvPV(sv, len);
334 int arg
335 CODE:
336 42 RETVAL = constant(s,len,arg);
337 OUTPUT:
338 RETVAL
339  
340 long
341 _ptrace(request, pid, addr, data)
342 INPUT:
343 double request
344 int pid
345 size_t addr
346 size_t data
347 CODE:
348 1 RETVAL = ptrace(request, pid, (void*) addr, (void*) data);
349 OUTPUT:
350 RETVAL
351  
« blib/lib/Sys/Ptrace.pm ↑ Summary