xref: /netbsd-src/tests/lib/libc/sys/t_ptrace_wait.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: t_ptrace_wait.h,v 1.11 2018/05/30 17:48:13 kamil Exp $	*/
2 
3 /*-
4  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* Detect plain wait(2) use-case */
30 #if !defined(TWAIT_WAITPID) && \
31     !defined(TWAIT_WAITID) && \
32     !defined(TWAIT_WAIT3) && \
33     !defined(TWAIT_WAIT4) && \
34     !defined(TWAIT_WAIT6)
35 #define TWAIT_WAIT
36 #endif
37 
38 /*
39  * There are two classes of wait(2)-like functions:
40  * - wait4(2)-like accepting pid_t, optional options parameter, struct rusage*
41  * - wait6(2)-like accepting idtype_t, id_t, struct wrusage, mandatory options
42  *
43  * The TWAIT_FNAME value is to be used for convenience in debug messages.
44  *
45  * The TWAIT_GENERIC() macro is designed to reuse the same unmodified
46  * code with as many wait(2)-like functions as possible.
47  *
48  * In a common use-case wait4(2) and wait6(2)-like function can work the almost
49  * the same way, however there are few important differences:
50  * wait6(2) must specify P_PID for idtype to match wpid from wait4(2).
51  * To behave like wait4(2), wait6(2) the 'options' to wait must include
52  * WEXITED|WTRUNCATED.
53  *
54  * There are two helper macros (they purpose it to mach more than one
55  * wait(2)-like function):
56  * The TWAIT_HAVE_STATUS - specifies whether a function can retrieve
57  *                         status (as integer value).
58  * The TWAIT_HAVE_PID    - specifies whether a function can request
59  *                         exact process identifier
60  * The TWAIT_HAVE_RUSAGE - specifies whether a function can request
61  *                         the struct rusage value
62  *
63  */
64 
65 #if defined(TWAIT_WAIT)
66 #	define TWAIT_FNAME			"wait"
67 #	define TWAIT_WAIT4TYPE(a,b,c,d)		wait((b))
68 #	define TWAIT_GENERIC(a,b,c)		wait((b))
69 #	define TWAIT_HAVE_STATUS		1
70 #elif defined(TWAIT_WAITPID)
71 #	define TWAIT_FNAME			"waitpid"
72 #	define TWAIT_WAIT4TYPE(a,b,c,d)		waitpid((a),(b),(c))
73 #	define TWAIT_GENERIC(a,b,c)		waitpid((a),(b),(c))
74 #	define TWAIT_HAVE_PID			1
75 #	define TWAIT_HAVE_STATUS		1
76 #elif defined(TWAIT_WAITID)
77 #	define TWAIT_FNAME			"waitid"
78 #	define TWAIT_GENERIC(a,b,c)		\
79 		waitid(P_PID,(a),NULL,(c)|WEXITED|WTRAPPED)
80 #	define TWAIT_WAIT6TYPE(a,b,c,d,e,f)	waitid((a),(b),(f),(d))
81 #	define TWAIT_HAVE_PID			1
82 #elif defined(TWAIT_WAIT3)
83 #	define TWAIT_FNAME			"wait3"
84 #	define TWAIT_WAIT4TYPE(a,b,c,d)		wait3((b),(c),(d))
85 #	define TWAIT_GENERIC(a,b,c)		wait3((b),(c),NULL)
86 #	define TWAIT_HAVE_STATUS		1
87 #	define TWAIT_HAVE_RUSAGE		1
88 #elif defined(TWAIT_WAIT4)
89 #	define TWAIT_FNAME			"wait4"
90 #	define TWAIT_WAIT4TYPE(a,b,c,d)		wait4((a),(b),(c),(d))
91 #	define TWAIT_GENERIC(a,b,c)		wait4((a),(b),(c),NULL)
92 #	define TWAIT_HAVE_PID			1
93 #	define TWAIT_HAVE_STATUS		1
94 #	define TWAIT_HAVE_RUSAGE		1
95 #elif defined(TWAIT_WAIT6)
96 #	define TWAIT_FNAME			"wait6"
97 #	define TWAIT_WAIT6TYPE(a,b,c,d,e,f)	wait6((a),(b),(c),(d),(e),(f))
98 #	define TWAIT_GENERIC(a,b,c)		\
99 		wait6(P_PID,(a),(b),(c)|WEXITED|WTRAPPED,NULL,NULL)
100 #	define TWAIT_HAVE_PID			1
101 #	define TWAIT_HAVE_STATUS		1
102 #endif
103 
104 /*
105  * There are 3 groups of tests:
106  * - TWAIT_GENERIC()	(wait, wait2, waitpid, wait3, wait4, wait6)
107  * - TWAIT_WAIT4TYPE()	(wait2, waitpid, wait3, wait4)
108  * - TWAIT_WAIT6TYPE()	(waitid, wait6)
109  *
110  * Tests only in the above categories are allowed. However some tests are not
111  * possible in the context requested functionality to be verified, therefore
112  * there are helper macros:
113  * - TWAIT_HAVE_PID	(wait2, waitpid, waitid, wait4, wait6)
114  * - TWAIT_HAVE_STATUS	(wait, wait2, waitpid, wait3, wait4, wait6)
115  * - TWAIT_HAVE_RUSAGE	(wait3, wait4)
116  * - TWAIT_HAVE_RETPID	(wait, wait2, waitpid, wait3, wait4, wait6)
117  *
118  * If there is an intention to test e.g. wait6(2) specific features in the
119  * ptrace(2) context, find the most matching group and with #ifdefs reduce
120  * functionality of less featured than wait6(2) interface (TWAIT_WAIT6TYPE).
121  *
122  * For clarity never use negative preprocessor checks, like:
123  *     #if !defined(TWAIT_WAIT4)
124  * always refer to checks for positive values.
125  */
126 
127 #define TEST_REQUIRE_EQ(x, y)						\
128 do {									\
129 	uintmax_t vx = (x);						\
130 	uintmax_t vy = (y);						\
131 	int ret = vx == vy;						\
132 	if (!ret)							\
133 		ATF_REQUIRE_EQ_MSG(vx, vy, "%s(%ju) == %s(%ju)", 	\
134 		    #x, vx, #y, vy);					\
135 } while (/*CONSTCOND*/0)
136 
137 /*
138  * A child process cannot call atf functions and expect them to magically
139  * work like in the parent.
140  * The printf(3) messaging from a child will not work out of the box as well
141  * without estabilishing a communication protocol with its parent. To not
142  * overcomplicate the tests - do not log from a child and use err(3)/errx(3)
143  * wrapped with FORKEE_ASSERT()/FORKEE_ASSERTX() as that is guaranteed to work.
144  */
145 #define FORKEE_ASSERT_EQ(x, y)						\
146 do {									\
147 	uintmax_t vx = (x);						\
148 	uintmax_t vy = (y);						\
149 	int ret = vx == vy;						\
150 	if (!ret)							\
151 		errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: "	\
152 		    "%s(%ju) == %s(%ju)", __FILE__, __LINE__, __func__,	\
153 		    #x, vx, #y, vy);					\
154 } while (/*CONSTCOND*/0)
155 
156 #define FORKEE_ASSERT_NEQ(x, y)						\
157 do {									\
158 	uintmax_t vx = (x);						\
159 	uintmax_t vy = (y);						\
160 	int ret = vx != vy;						\
161 	if (!ret)							\
162 		errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: "	\
163 		    "%s(%ju) != %s(%ju)", __FILE__, __LINE__, __func__,	\
164 		    #x, vx, #y, vy);					\
165 } while (/*CONSTCOND*/0)
166 
167 #define FORKEE_ASSERTX(x)						\
168 do {									\
169 	int ret = (x);							\
170 	if (!ret)							\
171 		errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s",\
172 		     __FILE__, __LINE__, __func__, #x);			\
173 } while (/*CONSTCOND*/0)
174 
175 #define FORKEE_ASSERT(x)						\
176 do {									\
177 	int ret = (x);							\
178 	if (!ret)							\
179 		err(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s",\
180 		     __FILE__, __LINE__, __func__, #x);			\
181 } while (/*CONSTCOND*/0)
182 
183 /*
184  * Simplify logic for functions using general purpose registers add HAVE_GPREGS
185  *
186  * For platforms that do not implement all needed calls for simplicity assume
187  * that they are unsupported at all.
188  */
189 #if defined(PT_GETREGS)			\
190     && defined(PT_SETREGS)		\
191     && defined(PTRACE_REG_PC)		\
192     && defined(PTRACE_REG_SET_PC)	\
193     && defined(PTRACE_REG_SP)		\
194     && defined(PTRACE_REG_INTRV)
195 #define HAVE_GPREGS
196 #endif
197 
198 /* Add guards for floating point registers */
199 #if defined(PT_GETFPREGS)		\
200     && defined(PT_SETFPREGS)
201 #define HAVE_FPREGS
202 #endif
203 
204 /* Add guards for cpu debug registers */
205 #if defined(PT_GETDBREGS)		\
206     && defined(PT_SETDBREGS)
207 #define HAVE_DBREGS
208 #endif
209 
210 /*
211  * If waitid(2) returns because one or more processes have a state change to
212  * report, 0 is returned.  If an error is detected, a value of -1 is returned
213  * and errno is set to indicate the error. If WNOHANG is specified and there
214  * are no stopped, continued or exited children, 0 is returned.
215  */
216 #if defined(TWAIT_WAITID)
217 #define TWAIT_REQUIRE_SUCCESS(a,b)	TEST_REQUIRE_EQ((a), 0)
218 #define TWAIT_REQUIRE_FAILURE(a,b)	ATF_REQUIRE_ERRNO((a),(b) == -1)
219 #define FORKEE_REQUIRE_SUCCESS(a,b)	FORKEE_ASSERT_EQ(a, 0)
220 #define FORKEE_REQUIRE_FAILURE(a,b)	\
221 	FORKEE_ASSERTX(((a) == errno) && ((b) == -1))
222 #else
223 #define TWAIT_REQUIRE_SUCCESS(a,b)	TEST_REQUIRE_EQ((a), (b))
224 #define TWAIT_REQUIRE_FAILURE(a,b)	ATF_REQUIRE_ERRNO((a),(b) == -1)
225 #define FORKEE_REQUIRE_SUCCESS(a,b)	FORKEE_ASSERT_EQ(a, b)
226 #define FORKEE_REQUIRE_FAILURE(a,b)	\
227 	FORKEE_ASSERTX(((a) == errno) && ((b) == -1))
228 #endif
229 
230 /*
231  * Helper tools to verify whether status reports exited value
232  */
233 #if TWAIT_HAVE_STATUS
234 static void __used
235 validate_status_exited(int status, int expected)
236 {
237         ATF_REQUIRE_MSG(WIFEXITED(status), "Reported !exited process");
238         ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process");
239         ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process");
240         ATF_REQUIRE_MSG(!WIFSTOPPED(status), "Reported stopped process");
241 
242 	ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), expected,
243 	    "The process has exited with invalid value %d != %d",
244 	    WEXITSTATUS(status), expected);
245 }
246 
247 static void __used
248 forkee_status_exited(int status, int expected)
249 {
250 	FORKEE_ASSERTX(WIFEXITED(status));
251 	FORKEE_ASSERTX(!WIFCONTINUED(status));
252 	FORKEE_ASSERTX(!WIFSIGNALED(status));
253 	FORKEE_ASSERTX(!WIFSTOPPED(status));
254 
255 	FORKEE_ASSERT_EQ(WEXITSTATUS(status), expected);
256 }
257 
258 static void __used
259 validate_status_continued(int status)
260 {
261 	ATF_REQUIRE_MSG(!WIFEXITED(status), "Reported exited process");
262 	ATF_REQUIRE_MSG(WIFCONTINUED(status), "Reported !continued process");
263 	ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process");
264 	ATF_REQUIRE_MSG(!WIFSTOPPED(status), "Reported stopped process");
265 }
266 
267 static void __used
268 forkee_status_continued(int status)
269 {
270 	FORKEE_ASSERTX(!WIFEXITED(status));
271 	FORKEE_ASSERTX(WIFCONTINUED(status));
272 	FORKEE_ASSERTX(!WIFSIGNALED(status));
273 	FORKEE_ASSERTX(!WIFSTOPPED(status));
274 }
275 
276 static void __used
277 validate_status_signaled(int status, int expected_termsig, int expected_core)
278 {
279 	ATF_REQUIRE_MSG(!WIFEXITED(status), "Reported exited process");
280 	ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process");
281 	ATF_REQUIRE_MSG(WIFSIGNALED(status), "Reported !signaled process");
282 	ATF_REQUIRE_MSG(!WIFSTOPPED(status), "Reported stopped process");
283 
284 	ATF_REQUIRE_EQ_MSG(WTERMSIG(status), expected_termsig,
285 	    "Unexpected signal received");
286 
287 	ATF_REQUIRE_EQ_MSG(!!WCOREDUMP(status), expected_core,
288 	    "Unexpectedly core file %s generated", expected_core ? "not" : "");
289 }
290 
291 static void __used
292 forkee_status_signaled(int status, int expected_termsig, int expected_core)
293 {
294 	FORKEE_ASSERTX(!WIFEXITED(status));
295 	FORKEE_ASSERTX(!WIFCONTINUED(status));
296 	FORKEE_ASSERTX(WIFSIGNALED(status));
297 	FORKEE_ASSERTX(!WIFSTOPPED(status));
298 
299 	FORKEE_ASSERT_EQ(WTERMSIG(status), expected_termsig);
300 	FORKEE_ASSERT_EQ(!!WCOREDUMP(status), expected_core);
301 }
302 
303 static void __used
304 validate_status_stopped(int status, int expected)
305 {
306 	ATF_REQUIRE_MSG(!WIFEXITED(status), "Reported exited process");
307 	ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process");
308 	ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process");
309 	ATF_REQUIRE_MSG(WIFSTOPPED(status), "Reported !stopped process");
310 
311 	char st[128], ex[128];
312 	strlcpy(st, strsignal(WSTOPSIG(status)), sizeof(st));
313 	strlcpy(ex, strsignal(expected), sizeof(ex));
314 
315 	ATF_REQUIRE_EQ_MSG(WSTOPSIG(status), expected,
316 	    "Unexpected stop signal received [%s] != [%s]", st, ex);
317 }
318 
319 static void __used
320 forkee_status_stopped(int status, int expected)
321 {
322 	FORKEE_ASSERTX(!WIFEXITED(status));
323 	FORKEE_ASSERTX(!WIFCONTINUED(status));
324 	FORKEE_ASSERTX(!WIFSIGNALED(status));
325 	FORKEE_ASSERTX(WIFSTOPPED(status));
326 
327 	FORKEE_ASSERT_EQ(WSTOPSIG(status), expected);
328 }
329 #else
330 #define validate_status_exited(a,b)
331 #define forkee_status_exited(a,b)
332 #define validate_status_continued(a,b)
333 #define forkee_status_continued(a,b)
334 #define validate_status_signaled(a,b,c)
335 #define forkee_status_signaled(a,b,c)
336 #define validate_status_stopped(a,b)
337 #define forkee_status_stopped(a,b)
338 #endif
339 
340 /* This function is currently designed to be run in the main/parent process */
341 static void __used
342 await_zombie_raw(pid_t process, useconds_t ms)
343 {
344 	struct kinfo_proc2 p;
345 	size_t len = sizeof(p);
346 
347 	const int name[] = {
348 		[0] = CTL_KERN,
349 		[1] = KERN_PROC2,
350 		[2] = KERN_PROC_PID,
351 		[3] = process,
352 		[4] = sizeof(p),
353 		[5] = 1
354 	};
355 
356 	const size_t namelen = __arraycount(name);
357 
358 	/* Await the process becoming a zombie */
359 	while(1) {
360 		ATF_REQUIRE(sysctl(name, namelen, &p, &len, NULL, 0) == 0);
361 
362 		if (p.p_stat == LSZOMB)
363 			break;
364 
365 		if (ms > 0) {
366 			ATF_REQUIRE(usleep(ms) == 0);
367 		}
368 	}
369 }
370 
371 static void __used
372 await_zombie(pid_t process)
373 {
374 
375 	await_zombie_raw(process, 1000);
376 }
377 
378 static pid_t __used
379 await_stopped_child(pid_t process)
380 {
381 	struct kinfo_proc2 *p = NULL;
382 	size_t i, len;
383 	pid_t child = -1;
384 
385 	int name[] = {
386 		[0] = CTL_KERN,
387 		[1] = KERN_PROC2,
388 		[2] = KERN_PROC_ALL,
389 		[3] = 0,
390 		[4] = sizeof(struct kinfo_proc2),
391 		[5] = 0
392 	};
393 
394 	const size_t namelen = __arraycount(name);
395 
396 	/* Await the process becoming a zombie */
397 	while(1) {
398 		name[5] = 0;
399 
400 		FORKEE_ASSERT_EQ(sysctl(name, namelen, 0, &len, NULL, 0), 0);
401 
402 		FORKEE_ASSERT_EQ(reallocarr(&p,
403 		                            len,
404 		                            sizeof(struct kinfo_proc2)), 0);
405 
406 		name[5] = len;
407 
408 		FORKEE_ASSERT_EQ(sysctl(name, namelen, p, &len, NULL, 0), 0);
409 
410 		for (i = 0; i < len/sizeof(struct kinfo_proc2); i++) {
411 			if (p[i].p_pid == getpid())
412 				continue;
413 			if (p[i].p_ppid != process)
414 				continue;
415 			if (p[i].p_stat != LSSTOP)
416 				continue;
417 			child = p[i].p_pid;
418 			break;
419 		}
420 
421 		if (child != -1)
422 			break;
423 
424 		FORKEE_ASSERT_EQ(usleep(1000), 0);
425 	}
426 
427 	/* Free the buffer */
428 	FORKEE_ASSERT_EQ(reallocarr(&p, 0, sizeof(struct kinfo_proc2)), 0);
429 
430 	return child;
431 }
432 
433 /* Happy number sequence -- this function is used to just consume cpu cycles */
434 #define	HAPPY_NUMBER	1
435 
436 /* If n is not happy then its sequence ends in the cycle:
437  * 4, 16, 37, 58, 89, 145, 42, 20, 4, ... */
438 #define	SAD_NUMBER	4
439 
440 /* Calculate the sum of the squares of the digits of n */
441 static unsigned __used
442 dsum(unsigned n)
443 {
444 	unsigned sum, x;
445 	for (sum = 0; n; n /= 10) {
446 		x = n % 10;
447 		sum += x * x;
448 	}
449 	return sum;
450 }
451 
452 /*
453  * XXX: Disabled optimization is required to make tests for hardware assisted
454  * traps in .text functional
455  *
456  * Tested with GCC 5.4 on NetBSD 7.99.47 amd64
457  */
458 static int __used
459 #ifdef __clang__
460 __attribute__((__optnone__))
461 #else
462 __attribute__((__optimize__("O0")))
463 #endif
464 check_happy(unsigned n)
465 {
466 	for (;;) {
467 		unsigned total = dsum(n);
468 
469 		if (total == HAPPY_NUMBER)
470 			return 1;
471 		if (total == SAD_NUMBER)
472 			return 0;
473 
474 		n = total;
475 	}
476 }
477 
478 #if defined(HAVE_DBREGS)
479 static bool __used
480 can_we_set_dbregs(void)
481 {
482 	static long euid = -1;
483 	static int user_set_dbregs  = -1;
484 	size_t user_set_dbregs_len = sizeof(user_set_dbregs);
485 
486 	if (euid == -1)
487 		euid = geteuid();
488 
489 	if (euid == 0)
490 		return true;
491 
492 	if (user_set_dbregs == -1) {
493 		if (sysctlbyname("security.models.extensions.user_set_dbregs",
494 			&user_set_dbregs, &user_set_dbregs_len, NULL, 0)
495 			== -1) {
496 			return false;
497 		}
498 	}
499 
500 	if (user_set_dbregs > 0)
501 		return true;
502 	else
503 		return false;
504 }
505 #endif
506 
507 static bool __used
508 can_we_write_to_text(pid_t pid)
509 {
510 	int mib[3];
511 	int paxflags;
512 	size_t len = sizeof(int);
513 
514 	mib[0] = CTL_PROC;
515 	mib[1] = pid;
516 	mib[2] = PROC_PID_PAXFLAGS;
517 
518 	if (sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)
519 		return false;
520 
521 	return !(paxflags & CTL_PROC_PAXFLAGS_MPROTECT);
522 }
523 
524 static void __used
525 trigger_trap(void)
526 {
527 
528 	/* Software breakpoint causes CPU trap, translated to SIGTRAP */
529 #ifdef PTRACE_BREAKPOINT_ASM
530 	PTRACE_BREAKPOINT_ASM;
531 #else
532 	/* port me */
533 #endif
534 }
535 
536 static void __used
537 trigger_segv(void)
538 {
539 	static volatile char *ptr = NULL;
540 
541 	/* Access to unmapped memory causes CPU trap, translated to SIGSEGV */
542 	*ptr = 1;
543 }
544 
545 static void __used
546 trigger_ill(void)
547 {
548 
549 	/* Illegal instruction causes CPU trap, translated to SIGILL */
550 #ifdef PTRACE_ILLEGAL_ASM
551 	PTRACE_ILLEGAL_ASM;
552 #else
553 	/* port me */
554 #endif
555 }
556 
557 static void __used
558 trigger_fpe(void)
559 {
560 	volatile int a = getpid();
561 	volatile int b = atoi("0");
562 
563 	/* Division by zero causes CPU trap, translated to SIGFPE */
564 	usleep(a / b);
565 }
566 
567 static void __used
568 trigger_bus(void)
569 {
570 	FILE *fp;
571 	char *p;
572 
573 	/* Open an empty file for writing. */
574 	fp = tmpfile();
575 	FORKEE_ASSERT_NEQ((uintptr_t)fp, (uintptr_t)NULL);
576 
577 	/*
578 	 * Map an empty file with mmap(2) to a pointer.
579 	 *
580 	 * PROT_READ handles read-modify-write sequences emitted for
581 	 * certain combinations of CPUs and compilers (e.g. Alpha AXP).
582 	 */
583 	p = mmap(0, 1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
584 	FORKEE_ASSERT_NEQ((uintptr_t)p, (uintptr_t)MAP_FAILED);
585 
586 	/* Invalid memory access causes CPU trap, translated to SIGBUS */
587 	*p = 'a';
588 }
589 
590 #if defined(TWAIT_HAVE_PID)
591 #define ATF_TP_ADD_TC_HAVE_PID(a,b)	ATF_TP_ADD_TC(a,b)
592 #else
593 #define ATF_TP_ADD_TC_HAVE_PID(a,b)
594 #endif
595 
596 #if defined(HAVE_GPREGS)
597 #define ATF_TP_ADD_TC_HAVE_GPREGS(a,b)	ATF_TP_ADD_TC(a,b)
598 #else
599 #define ATF_TP_ADD_TC_HAVE_GPREGS(a,b)
600 #endif
601 
602 #if defined(HAVE_FPREGS)
603 #define ATF_TP_ADD_TC_HAVE_FPREGS(a,b)	ATF_TP_ADD_TC(a,b)
604 #else
605 #define ATF_TP_ADD_TC_HAVE_FPREGS(a,b)
606 #endif
607 
608 #if defined(HAVE_DBREGS)
609 #define ATF_TP_ADD_TC_HAVE_DBREGS(a,b) ATF_TP_ADD_TC(a,b)
610 #else
611 #define ATF_TP_ADD_TC_HAVE_DBREGS(a,b)
612 #endif
613 
614 #if defined(PT_STEP)
615 #define ATF_TP_ADD_TC_PT_STEP(a,b)	ATF_TP_ADD_TC(a,b)
616 #else
617 #define ATF_TP_ADD_TC_PT_STEP(a,b)
618 #endif
619