Home | History | Annotate | Line # | Download | only in sys
t_ptrace_signal_wait.h revision 1.9
      1 /*	$NetBSD: t_ptrace_signal_wait.h,v 1.9 2025/05/10 00:23:28 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2016, 2017, 2018, 2019, 2020 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 #ifdef __SOFTFP__
     30 static void
     31 softfloat_fudge_sigs(const ki_sigset_t *kbefore, ki_sigset_t *kafter)
     32 {
     33 	sigset_t before, after;
     34 
     35 	/*
     36 	 * XXX Would be nice if the layout of ki_sigset_t were publicly
     37 	 * documented!
     38 	 */
     39 	__CTASSERT(sizeof(before) == sizeof(*kbefore));
     40 	__CTASSERT(sizeof(after) == sizeof(*kafter));
     41 	memcpy(&before, kbefore, sizeof(before));
     42 	memcpy(&after, kafter, sizeof(after));
     43 	if (sigismember(&before, SIGFPE)) {
     44 		fprintf(stderr, "%s: add SIGFPE\n", __func__);
     45 		sigaddset(&after, SIGFPE);
     46 	} else {
     47 		fprintf(stderr, "%s: del SIGFPE\n", __func__);
     48 		sigdelset(&after, SIGFPE);
     49 	}
     50 	memcpy(kafter, &after, sizeof(after));
     51 }
     52 #endif
     53 
     54 static void
     55 traceme_raise(int sigval)
     56 {
     57 	const int exitval = 5;
     58 	pid_t child, wpid;
     59 #if defined(TWAIT_HAVE_STATUS)
     60 	int status;
     61 #endif
     62 
     63 	ptrace_state_t state, zero_state;
     64 	const int slen = sizeof(state);
     65 	struct ptrace_siginfo info;
     66 	memset(&zero_state, 0, sizeof(zero_state));
     67 	memset(&info, 0, sizeof(info));
     68 
     69 	DPRINTF("Before forking process PID=%d\n", getpid());
     70 	RL(child = fork());
     71 	if (child == 0) {
     72 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
     73 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
     74 
     75 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
     76 		FORKEE_ASSERT(raise(sigval) == 0);
     77 
     78 		switch (sigval) {
     79 		case SIGKILL:
     80 			/* NOTREACHED */
     81 			FORKEE_ASSERTX(0 && "This shall not be reached");
     82 			__unreachable();
     83 		default:
     84 			DPRINTF("Before exiting of the child process\n");
     85 			_exit(exitval);
     86 		}
     87 	}
     88 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
     89 
     90 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
     91 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
     92 
     93 	switch (sigval) {
     94 	case SIGKILL:
     95 		validate_status_signaled(status, sigval, 0);
     96 		SYSCALL_REQUIRE(
     97 		    ptrace(PT_GET_PROCESS_STATE, child, &state, slen) == -1);
     98 
     99 		break;
    100 	default:
    101 		validate_status_stopped(status, sigval);
    102 
    103 		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for "
    104 			"child\n");
    105 		SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info,
    106 			sizeof(info)) != -1);
    107 
    108 		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    109 		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
    110 			"si_errno=%#x\n",
    111 			info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    112 			info.psi_siginfo.si_errno);
    113 
    114 		TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    115 		TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    116 
    117 		DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error\n");
    118 		SYSCALL_REQUIRE(
    119 		    ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
    120 		TEST_CHECK_MEMEQ(&state, &zero_state, slen);
    121 
    122 		DPRINTF("Before resuming the child process where it left off "
    123 		    "and without signal to be sent\n");
    124 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    125 
    126 		DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    127 		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
    128 		    child);
    129 		break;
    130 	}
    131 
    132 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    133 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    134 }
    135 
    136 #define TRACEME_RAISE(test, sig)					\
    137 ATF_TC(test);								\
    138 ATF_TC_HEAD(test, tc)							\
    139 {									\
    140 	atf_tc_set_md_var(tc, "descr",					\
    141 	    "Verify " #sig " followed by _exit(2) in a child");		\
    142 }									\
    143 									\
    144 ATF_TC_BODY(test, tc)							\
    145 {									\
    146 									\
    147 	traceme_raise(sig);						\
    148 }
    149 
    150 TRACEME_RAISE(traceme_raise1, SIGKILL) /* non-maskable */
    151 TRACEME_RAISE(traceme_raise2, SIGSTOP) /* non-maskable */
    152 TRACEME_RAISE(traceme_raise3, SIGABRT) /* regular abort trap */
    153 TRACEME_RAISE(traceme_raise4, SIGHUP)  /* hangup */
    154 TRACEME_RAISE(traceme_raise5, SIGCONT) /* continued? */
    155 TRACEME_RAISE(traceme_raise6, SIGTRAP) /* crash signal */
    156 TRACEME_RAISE(traceme_raise7, SIGBUS) /* crash signal */
    157 TRACEME_RAISE(traceme_raise8, SIGILL) /* crash signal */
    158 TRACEME_RAISE(traceme_raise9, SIGFPE) /* crash signal */
    159 TRACEME_RAISE(traceme_raise10, SIGSEGV) /* crash signal */
    160 
    161 /// ----------------------------------------------------------------------------
    162 
    163 static void
    164 traceme_raisesignal_ignored(int sigignored)
    165 {
    166 	const int exitval = 5;
    167 	const int sigval = SIGSTOP;
    168 	pid_t child, wpid;
    169 	struct sigaction sa;
    170 #if defined(TWAIT_HAVE_STATUS)
    171 	int status;
    172 #endif
    173 	struct ptrace_siginfo info;
    174 
    175 	memset(&info, 0, sizeof(info));
    176 
    177 	DPRINTF("Before forking process PID=%d\n", getpid());
    178 	RL(child = fork());
    179 	if (child == 0) {
    180 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    181 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    182 
    183 		memset(&sa, 0, sizeof(sa));
    184 		sa.sa_handler = SIG_IGN;
    185 		sigemptyset(&sa.sa_mask);
    186 		FORKEE_ASSERT(sigaction(sigignored, &sa, NULL) != -1);
    187 
    188 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
    189 		FORKEE_ASSERT(raise(sigval) == 0);
    190 
    191 		DPRINTF("Before raising %s from child\n",
    192 		    strsignal(sigignored));
    193 		FORKEE_ASSERT(raise(sigignored) == 0);
    194 
    195 		DPRINTF("Before exiting of the child process\n");
    196 		_exit(exitval);
    197 	}
    198 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    199 
    200 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    201 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    202 
    203 	validate_status_stopped(status, sigval);
    204 
    205 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    206 	SYSCALL_REQUIRE(
    207 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    208 
    209 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    210 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    211 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    212 	    info.psi_siginfo.si_errno);
    213 
    214 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    215 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    216 
    217 	DPRINTF("Before resuming the child process where it left off and "
    218 	    "without signal to be sent\n");
    219 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    220 
    221 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    222 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    223 
    224 	validate_status_stopped(status, sigignored);
    225 
    226 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    227 	SYSCALL_REQUIRE(
    228 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    229 
    230 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    231 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    232 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    233 	    info.psi_siginfo.si_errno);
    234 
    235 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigignored);
    236 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    237 
    238 	DPRINTF("Before resuming the child process where it left off and "
    239 	    "without signal to be sent\n");
    240 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    241 
    242 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    243 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    244 
    245 	validate_status_exited(status, exitval);
    246 
    247 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    248 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    249 }
    250 
    251 #define TRACEME_RAISESIGNAL_IGNORED(test, sig)				\
    252 ATF_TC(test);								\
    253 ATF_TC_HEAD(test, tc)							\
    254 {									\
    255 	atf_tc_set_md_var(tc, "descr",					\
    256 	    "Verify that ignoring (with SIG_IGN) " #sig " in tracee "	\
    257 	    "does not stop tracer from catching this raised signal");	\
    258 }									\
    259 									\
    260 ATF_TC_BODY(test, tc)							\
    261 {									\
    262 									\
    263 	traceme_raisesignal_ignored(sig);				\
    264 }
    265 
    266 // A signal handler for SIGKILL and SIGSTOP cannot be ignored.
    267 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored1, SIGABRT) /* abort */
    268 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored2, SIGHUP)  /* hangup */
    269 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored3, SIGCONT) /* cont. */
    270 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored4, SIGTRAP) /* crash */
    271 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored5, SIGBUS) /* crash */
    272 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored6, SIGILL) /* crash */
    273 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored7, SIGFPE) /* crash */
    274 TRACEME_RAISESIGNAL_IGNORED(traceme_raisesignal_ignored8, SIGSEGV) /* crash */
    275 
    276 /// ----------------------------------------------------------------------------
    277 
    278 static void
    279 traceme_raisesignal_masked(int sigmasked)
    280 {
    281 	const int exitval = 5;
    282 	const int sigval = SIGSTOP;
    283 	pid_t child, wpid;
    284 #if defined(TWAIT_HAVE_STATUS)
    285 	int status;
    286 #endif
    287 	sigset_t intmask;
    288 	struct ptrace_siginfo info;
    289 
    290 	memset(&info, 0, sizeof(info));
    291 
    292 	DPRINTF("Before forking process PID=%d\n", getpid());
    293 	RL(child = fork());
    294 	if (child == 0) {
    295 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    296 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    297 
    298 		sigemptyset(&intmask);
    299 		sigaddset(&intmask, sigmasked);
    300 		sigprocmask(SIG_BLOCK, &intmask, NULL);
    301 
    302 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
    303 		FORKEE_ASSERT(raise(sigval) == 0);
    304 
    305 		DPRINTF("Before raising %s breakpoint from child\n",
    306 		    strsignal(sigmasked));
    307 		FORKEE_ASSERT(raise(sigmasked) == 0);
    308 
    309 		DPRINTF("Before exiting of the child process\n");
    310 		_exit(exitval);
    311 	}
    312 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    313 
    314 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    315 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    316 
    317 	validate_status_stopped(status, sigval);
    318 
    319 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    320 	SYSCALL_REQUIRE(
    321 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    322 
    323 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    324 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    325 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    326 	    info.psi_siginfo.si_errno);
    327 
    328 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    329 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    330 
    331 	DPRINTF("Before resuming the child process where it left off and "
    332 	    "without signal to be sent\n");
    333 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    334 
    335 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    336 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    337 
    338 	validate_status_exited(status, exitval);
    339 
    340 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    341 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    342 }
    343 
    344 #define TRACEME_RAISESIGNAL_MASKED(test, sig)				\
    345 ATF_TC(test);								\
    346 ATF_TC_HEAD(test, tc)							\
    347 {									\
    348 	atf_tc_set_md_var(tc, "descr",					\
    349 	    "Verify that masking (with SIG_BLOCK) " #sig " in tracee "	\
    350 	    "stops tracer from catching this raised signal");		\
    351 }									\
    352 									\
    353 ATF_TC_BODY(test, tc)							\
    354 {									\
    355 									\
    356 	traceme_raisesignal_masked(sig);				\
    357 }
    358 
    359 // A signal handler for SIGKILL and SIGSTOP cannot be masked.
    360 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked1, SIGABRT) /* abort trap */
    361 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked2, SIGHUP)  /* hangup */
    362 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked3, SIGCONT) /* continued? */
    363 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked4, SIGTRAP) /* crash sig. */
    364 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked5, SIGBUS) /* crash sig. */
    365 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked6, SIGILL) /* crash sig. */
    366 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked7, SIGFPE) /* crash sig. */
    367 TRACEME_RAISESIGNAL_MASKED(traceme_raisesignal_masked8, SIGSEGV) /* crash sig. */
    368 
    369 /// ----------------------------------------------------------------------------
    370 
    371 static void
    372 traceme_crash(int sig)
    373 {
    374 	pid_t child, wpid;
    375 #if defined(TWAIT_HAVE_STATUS)
    376 	int status;
    377 #endif
    378 	struct ptrace_siginfo info;
    379 
    380 #ifndef PTRACE_ILLEGAL_ASM
    381 	if (sig == SIGILL)
    382 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
    383 #endif
    384 
    385 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
    386 		atf_tc_skip("FP exceptions are not supported");
    387 
    388 	memset(&info, 0, sizeof(info));
    389 
    390 	DPRINTF("Before forking process PID=%d\n", getpid());
    391 	RL(child = fork());
    392 	if (child == 0) {
    393 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    394 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    395 
    396 		DPRINTF("Before executing a trap\n");
    397 		switch (sig) {
    398 		case SIGTRAP:
    399 			trigger_trap();
    400 			break;
    401 		case SIGSEGV:
    402 			trigger_segv();
    403 			break;
    404 		case SIGILL:
    405 			trigger_ill();
    406 			break;
    407 		case SIGFPE:
    408 			trigger_fpe();
    409 			break;
    410 		case SIGBUS:
    411 			trigger_bus();
    412 			break;
    413 		default:
    414 			/* NOTREACHED */
    415 			FORKEE_ASSERTX(0 && "This shall not be reached");
    416 		}
    417 
    418 		/* NOTREACHED */
    419 		FORKEE_ASSERTX(0 && "This shall not be reached");
    420 	}
    421 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    422 
    423 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    424 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    425 
    426 	validate_status_stopped(status, sig);
    427 
    428 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    429 	SYSCALL_REQUIRE(
    430 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    431 
    432 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    433 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    434 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    435 	    info.psi_siginfo.si_errno);
    436 
    437 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sig);
    438 	switch (sig) {
    439 	case SIGTRAP:
    440 		TEST_CHECK_EQ(info.psi_siginfo.si_code, TRAP_BRKPT);
    441 		break;
    442 	case SIGSEGV:
    443 		TEST_CHECK_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
    444 		break;
    445 	case SIGILL:
    446 		ATF_CHECK_MSG((info.psi_siginfo.si_code >= ILL_ILLOPC &&
    447 			info.psi_siginfo.si_code <= ILL_BADSTK),
    448 		    "info.psi_siginfo.si_code=%d ILL_ILLOPC=%d ILL_BADSTK=%d",
    449 		    info.psi_siginfo.si_code, ILL_ILLOPC, ILL_BADSTK);
    450 		break;
    451 	case SIGFPE:
    452 // XXXQEMU	TEST_CHECK_EQ(info.psi_siginfo.si_code, FPE_FLTDIV);
    453 		break;
    454 	case SIGBUS:
    455 		TEST_CHECK_EQ(info.psi_siginfo.si_code, BUS_ADRERR);
    456 		break;
    457 	}
    458 
    459 	SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1);
    460 
    461 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    462 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    463 
    464 	validate_status_signaled(status, SIGKILL, 0);
    465 
    466 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    467 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    468 }
    469 
    470 #define TRACEME_CRASH(test, sig)					\
    471 ATF_TC(test);								\
    472 ATF_TC_HEAD(test, tc)							\
    473 {									\
    474 	atf_tc_set_md_var(tc, "descr",					\
    475 	    "Verify crash signal " #sig " in a child after PT_TRACE_ME"); \
    476 }									\
    477 									\
    478 ATF_TC_BODY(test, tc)							\
    479 {									\
    480 									\
    481 	traceme_crash(sig);						\
    482 }
    483 
    484 TRACEME_CRASH(traceme_crash_trap, SIGTRAP)
    485 TRACEME_CRASH(traceme_crash_segv, SIGSEGV)
    486 TRACEME_CRASH(traceme_crash_ill, SIGILL)
    487 TRACEME_CRASH(traceme_crash_fpe, SIGFPE)
    488 TRACEME_CRASH(traceme_crash_bus, SIGBUS)
    489 
    490 /// ----------------------------------------------------------------------------
    491 
    492 static void
    493 traceme_signalmasked_crash(int sig)
    494 {
    495 	const int sigval = SIGSTOP;
    496 	pid_t child, wpid;
    497 #if defined(TWAIT_HAVE_STATUS)
    498 	int status;
    499 #endif
    500 	struct ptrace_siginfo info;
    501 	sigset_t intmask;
    502 	struct kinfo_proc2 kp;
    503 	size_t len = sizeof(kp);
    504 
    505 	int name[6];
    506 	const size_t namelen = __arraycount(name);
    507 	ki_sigset_t kp_sigmask;
    508 
    509 #ifndef PTRACE_ILLEGAL_ASM
    510 	if (sig == SIGILL)
    511 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
    512 #endif
    513 
    514 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
    515 		atf_tc_skip("FP exceptions are not supported");
    516 
    517 #ifdef __SOFTFP__
    518 	/*
    519 	 * Let's try to track down the dregs of PR misc/56820: Many FPE
    520 	 * related tests fail on softfloat machines.
    521 	 */
    522 	if (sig == SIGFPE)
    523 		debug = 1;
    524 #endif
    525 
    526 	memset(&info, 0, sizeof(info));
    527 
    528 	DPRINTF("Before forking process PID=%d\n", getpid());
    529 	RL(child = fork());
    530 	if (child == 0) {
    531 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    532 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    533 
    534 		sigemptyset(&intmask);
    535 		sigaddset(&intmask, sig);
    536 		sigprocmask(SIG_BLOCK, &intmask, NULL);
    537 
    538 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
    539 		FORKEE_ASSERT(raise(sigval) == 0);
    540 
    541 		DPRINTF("Before executing a trap\n");
    542 		switch (sig) {
    543 		case SIGTRAP:
    544 			trigger_trap();
    545 			break;
    546 		case SIGSEGV:
    547 			trigger_segv();
    548 			break;
    549 		case SIGILL:
    550 			trigger_ill();
    551 			break;
    552 		case SIGFPE:
    553 			trigger_fpe();
    554 			break;
    555 		case SIGBUS:
    556 			trigger_bus();
    557 			break;
    558 		default:
    559 			/* NOTREACHED */
    560 			FORKEE_ASSERTX(0 && "This shall not be reached");
    561 		}
    562 
    563 		/* NOTREACHED */
    564 		FORKEE_ASSERTX(0 && "This shall not be reached");
    565 	}
    566 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    567 
    568 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    569 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    570 
    571 	validate_status_stopped(status, sigval);
    572 
    573 	name[0] = CTL_KERN,
    574 	name[1] = KERN_PROC2,
    575 	name[2] = KERN_PROC_PID;
    576 	name[3] = child;
    577 	name[4] = sizeof(kp);
    578 	name[5] = 1;
    579 
    580 	RL(sysctl(name, namelen, &kp, &len, NULL, 0));
    581 
    582 	kp_sigmask = kp.p_sigmask;
    583 
    584 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    585 	SYSCALL_REQUIRE(
    586 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    587 
    588 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    589 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    590 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    591 	    info.psi_siginfo.si_errno);
    592 
    593 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    594 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    595 
    596 	DPRINTF("Before resuming the child process where it left off and "
    597 	    "without signal to be sent\n");
    598 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    599 
    600 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    601 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    602 
    603 	validate_status_stopped(status, sig);
    604 
    605 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    606 	SYSCALL_REQUIRE(
    607 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    608 
    609 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    610 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    611 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    612 	    info.psi_siginfo.si_errno);
    613 
    614 	RL(sysctl(name, namelen, &kp, &len, NULL, 0));
    615 
    616 	DPRINTF("kp_sigmask="
    617 	    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n",
    618 	    kp_sigmask.__bits[0], kp_sigmask.__bits[1], kp_sigmask.__bits[2],
    619 	    kp_sigmask.__bits[3]);
    620 
    621 	DPRINTF("kp.p_sigmask="
    622 	    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n",
    623 	    kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
    624 	    kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
    625 
    626 #ifdef __SOFTFP__
    627 	/*
    628 	 * Hardfloat floating-point exception traps raise SIGFPE even
    629 	 * if the process has masked SIGFPE.  As a side effect,
    630 	 * delivery of the signal on trap unmasks it -- but as a
    631 	 * special case, if the process is traced, it first stops and
    632 	 * notifies the tracer _before_ unmasking SIGFPE and removing
    633 	 * it from p_sigmask.
    634 	 *
    635 	 * Softfloat floating-point exception traps try to mimic this
    636 	 * behaviour by sigprocmask and sigqueueinfo in userland, but
    637 	 * it is difficult -- and likely not worthwhile -- to emulate
    638 	 * the special case of a traced process.  So when the tracer is
    639 	 * notified of the child's signal, the child has _already_
    640 	 * unmasked SIGFPE so it is no longer in p_sigmask.  (See
    641 	 * float_raise in lib/libc/softfloat/softfloat-specialize for
    642 	 * details.)
    643 	 *
    644 	 * Since this is probably not worthwhile to address (it only
    645 	 * affects an obscure detail of how the process state manifests
    646 	 * to a debugger), we just pretend that SIGFPE didn't change in
    647 	 * p_sigmask.
    648 	 */
    649 	if (sig == SIGFPE)
    650 		softfloat_fudge_sigs(&kp_sigmask, &kp.p_sigmask);
    651 #endif
    652 
    653 	TEST_CHECK_MEMEQ(&kp_sigmask, &kp.p_sigmask, sizeof(kp_sigmask));
    654 
    655 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sig);
    656 	switch (sig) {
    657 	case SIGTRAP:
    658 		TEST_CHECK_EQ(info.psi_siginfo.si_code, TRAP_BRKPT);
    659 		break;
    660 	case SIGSEGV:
    661 		TEST_CHECK_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
    662 		break;
    663 	case SIGILL:
    664 		ATF_CHECK_MSG((info.psi_siginfo.si_code >= ILL_ILLOPC &&
    665 			info.psi_siginfo.si_code <= ILL_BADSTK),
    666 		    "info.psi_siginfo.si_code=%d ILL_ILLOPC=%d ILL_BADSTK=%d",
    667 		    info.psi_siginfo.si_code, ILL_ILLOPC, ILL_BADSTK);
    668 		break;
    669 	case SIGFPE:
    670 // XXXQEMU	TEST_CHECK_EQ(info.psi_siginfo.si_code, FPE_FLTDIV);
    671 		break;
    672 	case SIGBUS:
    673 		TEST_CHECK_EQ(info.psi_siginfo.si_code, BUS_ADRERR);
    674 		break;
    675 	}
    676 
    677 	SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1);
    678 
    679 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    680 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    681 
    682 	validate_status_signaled(status, SIGKILL, 0);
    683 
    684 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    685 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    686 }
    687 
    688 #define TRACEME_SIGNALMASKED_CRASH(test, sig)				\
    689 ATF_TC(test);								\
    690 ATF_TC_HEAD(test, tc)							\
    691 {									\
    692 	atf_tc_set_md_var(tc, "descr",					\
    693 	    "Verify masked crash signal " #sig " in a child after "	\
    694 	    "PT_TRACE_ME is delivered to its tracer");			\
    695 }									\
    696 									\
    697 ATF_TC_BODY(test, tc)							\
    698 {									\
    699 									\
    700 	traceme_signalmasked_crash(sig);				\
    701 }
    702 
    703 TRACEME_SIGNALMASKED_CRASH(traceme_signalmasked_crash_trap, SIGTRAP)
    704 TRACEME_SIGNALMASKED_CRASH(traceme_signalmasked_crash_segv, SIGSEGV)
    705 TRACEME_SIGNALMASKED_CRASH(traceme_signalmasked_crash_ill, SIGILL)
    706 TRACEME_SIGNALMASKED_CRASH(traceme_signalmasked_crash_fpe, SIGFPE)
    707 TRACEME_SIGNALMASKED_CRASH(traceme_signalmasked_crash_bus, SIGBUS)
    708 
    709 /// ----------------------------------------------------------------------------
    710 
    711 static void
    712 traceme_signalignored_crash(int sig)
    713 {
    714 	const int sigval = SIGSTOP;
    715 	pid_t child, wpid;
    716 #if defined(TWAIT_HAVE_STATUS)
    717 	int status;
    718 #endif
    719 	struct sigaction sa;
    720 	struct ptrace_siginfo info;
    721 	struct kinfo_proc2 kp;
    722 	size_t len = sizeof(kp);
    723 
    724 	int name[6];
    725 	const size_t namelen = __arraycount(name);
    726 	ki_sigset_t kp_sigignore;
    727 
    728 #ifndef PTRACE_ILLEGAL_ASM
    729 	if (sig == SIGILL)
    730 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
    731 #endif
    732 
    733 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
    734 		atf_tc_skip("FP exceptions are not supported");
    735 
    736 #ifdef __SOFTFP__
    737 	/*
    738 	 * Let's try to track down the dregs of PR misc/56820: Many FPE
    739 	 * related tests fail on softfloat machines.
    740 	 */
    741 	if (sig == SIGFPE)
    742 		debug = 1;
    743 #endif
    744 
    745 	memset(&info, 0, sizeof(info));
    746 
    747 	DPRINTF("Before forking process PID=%d\n", getpid());
    748 	RL(child = fork());
    749 	if (child == 0) {
    750 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    751 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    752 
    753 		memset(&sa, 0, sizeof(sa));
    754 		sa.sa_handler = SIG_IGN;
    755 		sigemptyset(&sa.sa_mask);
    756 
    757 		FORKEE_ASSERT(sigaction(sig, &sa, NULL) != -1);
    758 
    759 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
    760 		FORKEE_ASSERT(raise(sigval) == 0);
    761 
    762 		DPRINTF("Before executing a trap\n");
    763 		switch (sig) {
    764 		case SIGTRAP:
    765 			trigger_trap();
    766 			break;
    767 		case SIGSEGV:
    768 			trigger_segv();
    769 			break;
    770 		case SIGILL:
    771 			trigger_ill();
    772 			break;
    773 		case SIGFPE:
    774 			trigger_fpe();
    775 			break;
    776 		case SIGBUS:
    777 			trigger_bus();
    778 			break;
    779 		default:
    780 			/* NOTREACHED */
    781 			FORKEE_ASSERTX(0 && "This shall not be reached");
    782 		}
    783 
    784 		/* NOTREACHED */
    785 		FORKEE_ASSERTX(0 && "This shall not be reached");
    786 	}
    787 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    788 
    789 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    790 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    791 
    792 	validate_status_stopped(status, sigval);
    793 
    794 	name[0] = CTL_KERN,
    795 	name[1] = KERN_PROC2,
    796 	name[2] = KERN_PROC_PID;
    797 	name[3] = child;
    798 	name[4] = sizeof(kp);
    799 	name[5] = 1;
    800 
    801 	RL(sysctl(name, namelen, &kp, &len, NULL, 0));
    802 
    803 	kp_sigignore = kp.p_sigignore;
    804 
    805 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    806 	SYSCALL_REQUIRE(
    807 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    808 
    809 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    810 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    811 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    812 	    info.psi_siginfo.si_errno);
    813 
    814 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    815 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    816 
    817 	DPRINTF("Before resuming the child process where it left off and "
    818 	    "without signal to be sent\n");
    819 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    820 
    821 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    822 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    823 
    824 	validate_status_stopped(status, sig);
    825 
    826 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    827 	SYSCALL_REQUIRE(
    828 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    829 
    830 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    831 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    832 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    833 	    info.psi_siginfo.si_errno);
    834 
    835 	RL(sysctl(name, namelen, &kp, &len, NULL, 0));
    836 
    837 	DPRINTF("kp_sigignore="
    838 	    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n",
    839 	    kp_sigignore.__bits[0], kp_sigignore.__bits[1],
    840 	    kp_sigignore.__bits[2], kp_sigignore.__bits[3]);
    841 
    842 	DPRINTF("kp.p_sigignore="
    843 	    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n",
    844 	    kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
    845 	    kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
    846 
    847 #ifdef __SOFTFP__
    848 	/*
    849 	 * Hardfloat floating-point exception traps raise SIGFPE even
    850 	 * if the process has set the signal disposition of SIGFPE to
    851 	 * SIG_IGN.  As a side effect, delivery of the signal on trap
    852 	 * changes the disposition from SIG_IGN to SIG_DFL -- but as a
    853 	 * special case, if the process is traced, it first stops and
    854 	 * notifies the tracer _before_ changing the disposition and
    855 	 * removing SIGFPE from p_sigignore.
    856 	 *
    857 	 * Softfloat floating-point exception traps try to mimic this
    858 	 * behaviour by sigaction and sigqueueinfo in userland, but it
    859 	 * is difficult -- and likely not worthwhile -- to emulate the
    860 	 * special case of a traced process.  So when the tracer is
    861 	 * notified of the child's signal, its disposition has
    862 	 * _already_ been changed to SIG_DFL and so SIGFPE is no longer
    863 	 * in p_sigignore.  (See float_raise in
    864 	 * lib/libc/softfloat/softfloat-specialize for details.)
    865 	 *
    866 	 * Since this is probably not worthwhile to address (it only
    867 	 * affects an obscure detail of how the process state manifests
    868 	 * to a debugger), we just pretend that nothing changeed in
    869 	 * whether SIGFPE is ignored or not.
    870 	 */
    871 	if (sig == SIGFPE)
    872 		softfloat_fudge_sigs(&kp_sigignore, &kp.p_sigignore);
    873 #endif
    874 
    875 	TEST_CHECK_MEMEQ(&kp_sigignore, &kp.p_sigignore, sizeof(kp_sigignore));
    876 
    877 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sig);
    878 	switch (sig) {
    879 	case SIGTRAP:
    880 		TEST_CHECK_EQ(info.psi_siginfo.si_code, TRAP_BRKPT);
    881 		break;
    882 	case SIGSEGV:
    883 		TEST_CHECK_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
    884 		break;
    885 	case SIGILL:
    886 		ATF_CHECK_MSG((info.psi_siginfo.si_code >= ILL_ILLOPC &&
    887 			info.psi_siginfo.si_code <= ILL_BADSTK),
    888 		    "info.psi_siginfo.si_code=%d ILL_ILLOPC=%d ILL_BADSTK=%d",
    889 		    info.psi_siginfo.si_code, ILL_ILLOPC, ILL_BADSTK);
    890 		break;
    891 	case SIGFPE:
    892 // XXXQEMU	TEST_CHECK_EQ(info.psi_siginfo.si_code, FPE_FLTDIV);
    893 		break;
    894 	case SIGBUS:
    895 		TEST_CHECK_EQ(info.psi_siginfo.si_code, BUS_ADRERR);
    896 		break;
    897 	}
    898 
    899 	SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1);
    900 
    901 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    902 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    903 
    904 	validate_status_signaled(status, SIGKILL, 0);
    905 
    906 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    907 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    908 }
    909 
    910 #define TRACEME_SIGNALIGNORED_CRASH(test, sig)				\
    911 ATF_TC(test);								\
    912 ATF_TC_HEAD(test, tc)							\
    913 {									\
    914 	atf_tc_set_md_var(tc, "descr",					\
    915 	    "Verify ignored crash signal " #sig " in a child after "	\
    916 	    "PT_TRACE_ME is delivered to its tracer"); 			\
    917 }									\
    918 									\
    919 ATF_TC_BODY(test, tc)							\
    920 {									\
    921 									\
    922 	traceme_signalignored_crash(sig);				\
    923 }
    924 
    925 TRACEME_SIGNALIGNORED_CRASH(traceme_signalignored_crash_trap, SIGTRAP)
    926 TRACEME_SIGNALIGNORED_CRASH(traceme_signalignored_crash_segv, SIGSEGV)
    927 TRACEME_SIGNALIGNORED_CRASH(traceme_signalignored_crash_ill, SIGILL)
    928 TRACEME_SIGNALIGNORED_CRASH(traceme_signalignored_crash_fpe, SIGFPE)
    929 TRACEME_SIGNALIGNORED_CRASH(traceme_signalignored_crash_bus, SIGBUS)
    930 
    931 /// ----------------------------------------------------------------------------
    932 
    933 static void
    934 traceme_sendsignal_handle(int sigsent, void (*sah)(int a), int *traceme_caught)
    935 {
    936 	const int exitval = 5;
    937 	const int sigval = SIGSTOP;
    938 	pid_t child, wpid;
    939 	struct sigaction sa;
    940 #if defined(TWAIT_HAVE_STATUS)
    941 	int status;
    942 #endif
    943 	struct ptrace_siginfo info;
    944 
    945 	memset(&info, 0, sizeof(info));
    946 
    947 	DPRINTF("Before forking process PID=%d\n", getpid());
    948 	RL(child = fork());
    949 	if (child == 0) {
    950 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
    951 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
    952 
    953 		sa.sa_handler = sah;
    954 		sa.sa_flags = SA_SIGINFO;
    955 		sigemptyset(&sa.sa_mask);
    956 
    957 		FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1);
    958 
    959 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
    960 		FORKEE_ASSERT(raise(sigval) == 0);
    961 
    962 		FORKEE_ASSERT_EQ(*traceme_caught, 1);
    963 
    964 		DPRINTF("Before exiting of the child process\n");
    965 		_exit(exitval);
    966 	}
    967 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
    968 
    969 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    970 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    971 
    972 	validate_status_stopped(status, sigval);
    973 
    974 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
    975 	SYSCALL_REQUIRE(
    976 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
    977 
    978 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
    979 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
    980 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
    981 	    info.psi_siginfo.si_errno);
    982 
    983 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
    984 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
    985 
    986 	DPRINTF("Before resuming the child process where it left off and with "
    987 	    "signal %s to be sent\n", strsignal(sigsent));
    988 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
    989 
    990 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    991 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    992 
    993 	validate_status_exited(status, exitval);
    994 
    995 	DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME);
    996 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    997 }
    998 
    999 #define TRACEME_SENDSIGNAL_HANDLE(test, sig)				\
   1000 ATF_TC(test);								\
   1001 ATF_TC_HEAD(test, tc)							\
   1002 {									\
   1003 	atf_tc_set_md_var(tc, "descr",					\
   1004 	    "Verify that a signal " #sig " emitted by a tracer to a child is " \
   1005 	    "handled correctly and caught by a signal handler");	\
   1006 }									\
   1007 									\
   1008 static int test##_caught = 0;						\
   1009 									\
   1010 static void								\
   1011 test##_sighandler(int arg)						\
   1012 {									\
   1013 	FORKEE_ASSERT_EQ(arg, sig);					\
   1014 									\
   1015 	++ test##_caught;						\
   1016 }									\
   1017 									\
   1018 ATF_TC_BODY(test, tc)							\
   1019 {									\
   1020 									\
   1021 	traceme_sendsignal_handle(sig, test##_sighandler, & test##_caught); \
   1022 }
   1023 
   1024 // A signal handler for SIGKILL and SIGSTOP cannot be registered.
   1025 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle1, SIGABRT) /* abort trap */
   1026 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle2, SIGHUP)  /* hangup */
   1027 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle3, SIGCONT) /* continued? */
   1028 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle4, SIGTRAP) /* crash sig. */
   1029 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle5, SIGBUS) /* crash sig. */
   1030 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle6, SIGILL) /* crash sig. */
   1031 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle7, SIGFPE) /* crash sig. */
   1032 TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle8, SIGSEGV) /* crash sig. */
   1033 
   1034 /// ----------------------------------------------------------------------------
   1035 
   1036 static void
   1037 traceme_sendsignal_masked(int sigsent)
   1038 {
   1039 	const int exitval = 5;
   1040 	const int sigval = SIGSTOP;
   1041 	pid_t child, wpid;
   1042 	sigset_t set;
   1043 #if defined(TWAIT_HAVE_STATUS)
   1044 	int status;
   1045 #endif
   1046 	struct ptrace_siginfo info;
   1047 
   1048 	memset(&info, 0, sizeof(info));
   1049 
   1050 	DPRINTF("Before forking process PID=%d\n", getpid());
   1051 	RL(child = fork());
   1052 	if (child == 0) {
   1053 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1054 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1055 
   1056 		sigemptyset(&set);
   1057 		sigaddset(&set, sigsent);
   1058 		FORKEE_ASSERT(sigprocmask(SIG_BLOCK, &set, NULL) != -1);
   1059 
   1060 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   1061 		FORKEE_ASSERT(raise(sigval) == 0);
   1062 
   1063 		_exit(exitval);
   1064 	}
   1065 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1066 
   1067 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1068 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1069 
   1070 	validate_status_stopped(status, sigval);
   1071 
   1072 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
   1073 	SYSCALL_REQUIRE(
   1074 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
   1075 
   1076 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1077 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
   1078 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
   1079 	    info.psi_siginfo.si_errno);
   1080 
   1081 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
   1082 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
   1083 
   1084 	DPRINTF("Before resuming the child process where it left off and with "
   1085 	    "signal %s to be sent\n", strsignal(sigsent));
   1086 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
   1087 
   1088 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1089 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1090 
   1091 	validate_status_exited(status, exitval);
   1092 
   1093 	DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME);
   1094 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1095 }
   1096 
   1097 #define TRACEME_SENDSIGNAL_MASKED(test, sig)				\
   1098 ATF_TC(test);								\
   1099 ATF_TC_HEAD(test, tc)							\
   1100 {									\
   1101 	atf_tc_set_md_var(tc, "descr",					\
   1102 	    "Verify that a signal " #sig " emitted by a tracer to a child is " \
   1103 	    "handled correctly and the signal is masked by SIG_BLOCK");	\
   1104 }									\
   1105 									\
   1106 ATF_TC_BODY(test, tc)							\
   1107 {									\
   1108 									\
   1109 	traceme_sendsignal_masked(sig);					\
   1110 }
   1111 
   1112 // A signal handler for SIGKILL and SIGSTOP cannot be masked.
   1113 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked1, SIGABRT) /* abort trap */
   1114 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked2, SIGHUP)  /* hangup */
   1115 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked3, SIGCONT) /* continued? */
   1116 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked4, SIGTRAP) /* crash sig. */
   1117 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked5, SIGBUS) /* crash sig. */
   1118 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked6, SIGILL) /* crash sig. */
   1119 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked7, SIGFPE) /* crash sig. */
   1120 TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked8, SIGSEGV) /* crash sig. */
   1121 
   1122 /// ----------------------------------------------------------------------------
   1123 
   1124 static void
   1125 traceme_sendsignal_ignored(int sigsent)
   1126 {
   1127 	const int exitval = 5;
   1128 	const int sigval = SIGSTOP;
   1129 	pid_t child, wpid;
   1130 	struct sigaction sa;
   1131 #if defined(TWAIT_HAVE_STATUS)
   1132 	int status;
   1133 #endif
   1134 	struct ptrace_siginfo info;
   1135 
   1136 	memset(&info, 0, sizeof(info));
   1137 
   1138 	DPRINTF("Before forking process PID=%d\n", getpid());
   1139 	RL(child = fork());
   1140 	if (child == 0) {
   1141 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1142 
   1143 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1144 
   1145 		memset(&sa, 0, sizeof(sa));
   1146 		sa.sa_handler = SIG_IGN;
   1147 		sigemptyset(&sa.sa_mask);
   1148 		FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1);
   1149 
   1150 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   1151 		FORKEE_ASSERT(raise(sigval) == 0);
   1152 
   1153 		_exit(exitval);
   1154 	}
   1155 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1156 
   1157 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1158 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1159 
   1160 	validate_status_stopped(status, sigval);
   1161 
   1162 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
   1163 	SYSCALL_REQUIRE(
   1164 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
   1165 
   1166 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1167 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
   1168 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
   1169 	    info.psi_siginfo.si_errno);
   1170 
   1171 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
   1172 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
   1173 
   1174 	DPRINTF("Before resuming the child process where it left off and with "
   1175 	    "signal %s to be sent\n", strsignal(sigsent));
   1176 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
   1177 
   1178 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1179 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1180 
   1181 	validate_status_exited(status, exitval);
   1182 
   1183 	DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME);
   1184 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1185 }
   1186 
   1187 #define TRACEME_SENDSIGNAL_IGNORED(test, sig)				\
   1188 ATF_TC(test);								\
   1189 ATF_TC_HEAD(test, tc)							\
   1190 {									\
   1191 	atf_tc_set_md_var(tc, "descr",					\
   1192 	    "Verify that a signal " #sig " emitted by a tracer to a child is " \
   1193 	    "handled correctly and the signal is masked by SIG_IGN");	\
   1194 }									\
   1195 									\
   1196 ATF_TC_BODY(test, tc)							\
   1197 {									\
   1198 									\
   1199 	traceme_sendsignal_ignored(sig);				\
   1200 }
   1201 
   1202 // A signal handler for SIGKILL and SIGSTOP cannot be ignored.
   1203 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored1, SIGABRT) /* abort */
   1204 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored2, SIGHUP)  /* hangup */
   1205 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored3, SIGCONT) /* continued */
   1206 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored4, SIGTRAP) /* crash s. */
   1207 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored5, SIGBUS) /* crash s. */
   1208 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored6, SIGILL) /* crash s. */
   1209 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored7, SIGFPE) /* crash s. */
   1210 TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored8, SIGSEGV) /* crash s. */
   1211 
   1212 /// ----------------------------------------------------------------------------
   1213 
   1214 static void
   1215 traceme_sendsignal_simple(int sigsent)
   1216 {
   1217 	const int sigval = SIGSTOP;
   1218 	int exitval = 0;
   1219 	pid_t child, wpid;
   1220 #if defined(TWAIT_HAVE_STATUS)
   1221 	int status;
   1222 	int expect_core;
   1223 
   1224 	switch (sigsent) {
   1225 	case SIGABRT:
   1226 	case SIGTRAP:
   1227 	case SIGBUS:
   1228 	case SIGILL:
   1229 	case SIGFPE:
   1230 	case SIGSEGV:
   1231 		expect_core = 1;
   1232 		break;
   1233 	default:
   1234 		expect_core = 0;
   1235 		break;
   1236 	}
   1237 #endif
   1238 	struct ptrace_siginfo info;
   1239 
   1240 	memset(&info, 0, sizeof(info));
   1241 
   1242 	DPRINTF("Before forking process PID=%d\n", getpid());
   1243 	RL(child = fork());
   1244 	if (child == 0) {
   1245 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1246 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1247 
   1248 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   1249 		FORKEE_ASSERT(raise(sigval) == 0);
   1250 
   1251 		switch (sigsent) {
   1252 		case SIGCONT:
   1253 		case SIGSTOP:
   1254 			_exit(exitval);
   1255 		default:
   1256 			/* NOTREACHED */
   1257 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1258 		}
   1259 	}
   1260 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1261 
   1262 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1263 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1264 
   1265 	validate_status_stopped(status, sigval);
   1266 
   1267 	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
   1268 	SYSCALL_REQUIRE(
   1269 	    ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
   1270 
   1271 	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1272 	DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
   1273 	    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
   1274 	    info.psi_siginfo.si_errno);
   1275 
   1276 	TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
   1277 	TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
   1278 
   1279 	DPRINTF("Before resuming the child process where it left off and with "
   1280 	    "signal %s to be sent\n", strsignal(sigsent));
   1281 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
   1282 
   1283 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1284 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1285 
   1286 	switch (sigsent) {
   1287 	case SIGSTOP:
   1288 		validate_status_stopped(status, sigsent);
   1289 		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for "
   1290 		    "child\n");
   1291 		SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info,
   1292 		    sizeof(info)) != -1);
   1293 
   1294 		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1295 		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
   1296 		    "si_errno=%#x\n",
   1297 		    info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
   1298 		    info.psi_siginfo.si_errno);
   1299 
   1300 		TEST_CHECK_EQ(info.psi_siginfo.si_signo, sigval);
   1301 		TEST_CHECK_EQ(info.psi_siginfo.si_code, SI_LWP);
   1302 
   1303 		DPRINTF("Before resuming the child process where it left off "
   1304 		    "and with signal %s to be sent\n", strsignal(sigsent));
   1305 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
   1306 
   1307 		DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1308 		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
   1309 		    child);
   1310 		/* FALLTHROUGH */
   1311 	case SIGCONT:
   1312 		validate_status_exited(status, exitval);
   1313 		break;
   1314 	default:
   1315 		validate_status_signaled(status, sigsent, expect_core);
   1316 		break;
   1317 	}
   1318 
   1319 	DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME);
   1320 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1321 }
   1322 
   1323 #define TRACEME_SENDSIGNAL_SIMPLE(test, sig)				\
   1324 ATF_TC(test);								\
   1325 ATF_TC_HEAD(test, tc)							\
   1326 {									\
   1327 	atf_tc_set_md_var(tc, "descr",					\
   1328 	    "Verify that a signal " #sig " emitted by a tracer to a child is " \
   1329 	    "handled correctly in a child without a signal handler");	\
   1330 }									\
   1331 									\
   1332 ATF_TC_BODY(test, tc)							\
   1333 {									\
   1334 									\
   1335 	traceme_sendsignal_simple(sig);					\
   1336 }
   1337 
   1338 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple1, SIGKILL) /* non-maskable*/
   1339 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple2, SIGSTOP) /* non-maskable*/
   1340 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple3, SIGABRT) /* abort trap */
   1341 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple4, SIGHUP)  /* hangup */
   1342 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple5, SIGCONT) /* continued? */
   1343 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple6, SIGTRAP) /* crash sig. */
   1344 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple7, SIGBUS) /* crash sig. */
   1345 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple8, SIGILL) /* crash sig. */
   1346 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple9, SIGFPE) /* crash sig. */
   1347 TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple10, SIGSEGV) /* crash sig. */
   1348 
   1349 /// ----------------------------------------------------------------------------
   1350 
   1351 static void
   1352 traceme_vfork_raise(int sigval)
   1353 {
   1354 	const int exitval = 5, exitval_watcher = 10;
   1355 	pid_t child, parent, watcher, wpid;
   1356 	int rv;
   1357 #if defined(TWAIT_HAVE_STATUS)
   1358 	int status;
   1359 
   1360 	/* volatile workarounds GCC -Werror=clobbered */
   1361 	volatile int expect_core;
   1362 
   1363 	switch (sigval) {
   1364 	case SIGABRT:
   1365 	case SIGTRAP:
   1366 	case SIGBUS:
   1367 	case SIGILL:
   1368 	case SIGFPE:
   1369 	case SIGSEGV:
   1370 		expect_core = 1;
   1371 		break;
   1372 	default:
   1373 		expect_core = 0;
   1374 		break;
   1375 	}
   1376 #endif
   1377 
   1378 	/*
   1379 	 * Spawn a dedicated thread to watch for a stopped child and emit
   1380 	 * the SIGKILL signal to it.
   1381 	 *
   1382 	 * vfork(2) might clobber watcher, this means that it's safer and
   1383 	 * simpler to reparent this process to initproc and forget about it.
   1384 	 */
   1385 	if (sigval == SIGSTOP) {
   1386 		parent = getpid();
   1387 
   1388 		RL(watcher = fork());
   1389 		ATF_REQUIRE(watcher != 1);
   1390 		if (watcher == 0) {
   1391 			/* Double fork(2) trick to reparent to initproc */
   1392 			watcher = fork();
   1393 			FORKEE_ASSERT_NEQ(watcher, -1);
   1394 			if (watcher != 0)
   1395 				_exit(exitval_watcher);
   1396 
   1397 			child = await_stopped_child(parent);
   1398 
   1399 			errno = 0;
   1400 			rv = kill(child, SIGKILL);
   1401 			FORKEE_ASSERT_EQ(rv, 0);
   1402 			FORKEE_ASSERT_EQ(errno, 0);
   1403 
   1404 			/* This exit value will be collected by initproc */
   1405 			_exit(0);
   1406 		}
   1407 		DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1408 		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(watcher, &status, 0),
   1409 		    watcher);
   1410 
   1411 		validate_status_exited(status, exitval_watcher);
   1412 
   1413 		DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1414 		TWAIT_REQUIRE_FAILURE(ECHILD,
   1415 		    wpid = TWAIT_GENERIC(watcher, &status, 0));
   1416 	}
   1417 
   1418 	DPRINTF("Before forking process PID=%d\n", getpid());
   1419 	RL(child = vfork());
   1420 	if (child == 0) {
   1421 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1422 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1423 
   1424 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   1425 		FORKEE_ASSERT(raise(sigval) == 0);
   1426 
   1427 		switch (sigval) {
   1428 		case SIGSTOP:
   1429 		case SIGKILL:
   1430 		case SIGABRT:
   1431 		case SIGHUP:
   1432 		case SIGTRAP:
   1433 		case SIGBUS:
   1434 		case SIGILL:
   1435 		case SIGFPE:
   1436 		case SIGSEGV:
   1437 			/* NOTREACHED */
   1438 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1439 			__unreachable();
   1440 		default:
   1441 			DPRINTF("Before exiting of the child process\n");
   1442 			_exit(exitval);
   1443 		}
   1444 	}
   1445 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1446 
   1447 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1448 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1449 
   1450 	switch (sigval) {
   1451 	case SIGKILL:
   1452 	case SIGABRT:
   1453 	case SIGHUP:
   1454 	case SIGTRAP:
   1455 	case SIGBUS:
   1456 	case SIGILL:
   1457 	case SIGFPE:
   1458 	case SIGSEGV:
   1459 		validate_status_signaled(status, sigval, expect_core);
   1460 		break;
   1461 	case SIGSTOP:
   1462 		validate_status_signaled(status, SIGKILL, 0);
   1463 		break;
   1464 	case SIGCONT:
   1465 	case SIGTSTP:
   1466 	case SIGTTIN:
   1467 	case SIGTTOU:
   1468 		validate_status_exited(status, exitval);
   1469 		break;
   1470 	default:
   1471 		/* NOTREACHED */
   1472 		ATF_REQUIRE(0 && "NOT IMPLEMENTED");
   1473 		break;
   1474 	}
   1475 
   1476 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1477 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1478 }
   1479 
   1480 #define TRACEME_VFORK_RAISE(test, sig)					\
   1481 ATF_TC(test);								\
   1482 ATF_TC_HEAD(test, tc)							\
   1483 {									\
   1484 	atf_tc_set_md_var(tc, "descr",					\
   1485 	    "Verify PT_TRACE_ME followed by raise of " #sig " in a "	\
   1486 	    "vfork(2)ed child");					\
   1487 }									\
   1488 									\
   1489 ATF_TC_BODY(test, tc)							\
   1490 {									\
   1491 									\
   1492 	traceme_vfork_raise(sig);					\
   1493 }
   1494 
   1495 TRACEME_VFORK_RAISE(traceme_vfork_raise1, SIGKILL) /* non-maskable */
   1496 TRACEME_VFORK_RAISE(traceme_vfork_raise2, SIGSTOP) /* non-maskable */
   1497 TRACEME_VFORK_RAISE(traceme_vfork_raise3, SIGTSTP) /* ignored in vfork(2) */
   1498 TRACEME_VFORK_RAISE(traceme_vfork_raise4, SIGTTIN) /* ignored in vfork(2) */
   1499 TRACEME_VFORK_RAISE(traceme_vfork_raise5, SIGTTOU) /* ignored in vfork(2) */
   1500 TRACEME_VFORK_RAISE(traceme_vfork_raise6, SIGABRT) /* regular abort trap */
   1501 TRACEME_VFORK_RAISE(traceme_vfork_raise7, SIGHUP)  /* hangup */
   1502 TRACEME_VFORK_RAISE(traceme_vfork_raise8, SIGCONT) /* continued? */
   1503 TRACEME_VFORK_RAISE(traceme_vfork_raise9, SIGTRAP) /* crash signal */
   1504 TRACEME_VFORK_RAISE(traceme_vfork_raise10, SIGBUS) /* crash signal */
   1505 TRACEME_VFORK_RAISE(traceme_vfork_raise11, SIGILL) /* crash signal */
   1506 TRACEME_VFORK_RAISE(traceme_vfork_raise12, SIGFPE) /* crash signal */
   1507 TRACEME_VFORK_RAISE(traceme_vfork_raise13, SIGSEGV) /* crash signal */
   1508 
   1509 /// ----------------------------------------------------------------------------
   1510 
   1511 static void
   1512 traceme_vfork_crash(int sig)
   1513 {
   1514 	pid_t child, wpid;
   1515 #if defined(TWAIT_HAVE_STATUS)
   1516 	int status;
   1517 #endif
   1518 
   1519 #ifndef PTRACE_ILLEGAL_ASM
   1520 	if (sig == SIGILL)
   1521 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
   1522 #endif
   1523 
   1524 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
   1525 		atf_tc_skip("FP exceptions are not supported");
   1526 
   1527 	DPRINTF("Before forking process PID=%d\n", getpid());
   1528 	RL(child = vfork());
   1529 	if (child == 0) {
   1530 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1531 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1532 
   1533 		DPRINTF("Before executing a trap\n");
   1534 		switch (sig) {
   1535 		case SIGTRAP:
   1536 			trigger_trap();
   1537 			break;
   1538 		case SIGSEGV:
   1539 			trigger_segv();
   1540 			break;
   1541 		case SIGILL:
   1542 			trigger_ill();
   1543 			break;
   1544 		case SIGFPE:
   1545 			trigger_fpe();
   1546 			break;
   1547 		case SIGBUS:
   1548 			trigger_bus();
   1549 			break;
   1550 		default:
   1551 			/* NOTREACHED */
   1552 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1553 		}
   1554 
   1555 		/* NOTREACHED */
   1556 		FORKEE_ASSERTX(0 && "This shall not be reached");
   1557 	}
   1558 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1559 
   1560 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1561 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1562 
   1563 	validate_status_signaled(status, sig, 1);
   1564 
   1565 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1566 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1567 }
   1568 
   1569 #define TRACEME_VFORK_CRASH(test, sig)					\
   1570 ATF_TC(test);								\
   1571 ATF_TC_HEAD(test, tc)							\
   1572 {									\
   1573 	atf_tc_set_md_var(tc, "descr",					\
   1574 	    "Verify PT_TRACE_ME followed by a crash signal " #sig " in a " \
   1575 	    "vfork(2)ed child");					\
   1576 }									\
   1577 									\
   1578 ATF_TC_BODY(test, tc)							\
   1579 {									\
   1580 									\
   1581 	traceme_vfork_crash(sig);					\
   1582 }
   1583 
   1584 TRACEME_VFORK_CRASH(traceme_vfork_crash_trap, SIGTRAP)
   1585 TRACEME_VFORK_CRASH(traceme_vfork_crash_segv, SIGSEGV)
   1586 TRACEME_VFORK_CRASH(traceme_vfork_crash_ill, SIGILL)
   1587 TRACEME_VFORK_CRASH(traceme_vfork_crash_fpe, SIGFPE)
   1588 TRACEME_VFORK_CRASH(traceme_vfork_crash_bus, SIGBUS)
   1589 
   1590 /// ----------------------------------------------------------------------------
   1591 
   1592 static void
   1593 traceme_vfork_signalmasked_crash(int sig)
   1594 {
   1595 	pid_t child, wpid;
   1596 #if defined(TWAIT_HAVE_STATUS)
   1597 	int status;
   1598 #endif
   1599 	sigset_t intmask;
   1600 
   1601 #ifndef PTRACE_ILLEGAL_ASM
   1602 	if (sig == SIGILL)
   1603 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
   1604 #endif
   1605 
   1606 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
   1607 		atf_tc_skip("FP exceptions are not supported");
   1608 
   1609 	DPRINTF("Before forking process PID=%d\n", getpid());
   1610 	RL(child = vfork());
   1611 	if (child == 0) {
   1612 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1613 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1614 
   1615 		sigemptyset(&intmask);
   1616 		sigaddset(&intmask, sig);
   1617 		sigprocmask(SIG_BLOCK, &intmask, NULL);
   1618 
   1619 		DPRINTF("Before executing a trap\n");
   1620 		switch (sig) {
   1621 		case SIGTRAP:
   1622 			trigger_trap();
   1623 			break;
   1624 		case SIGSEGV:
   1625 			trigger_segv();
   1626 			break;
   1627 		case SIGILL:
   1628 			trigger_ill();
   1629 			break;
   1630 		case SIGFPE:
   1631 			trigger_fpe();
   1632 			break;
   1633 		case SIGBUS:
   1634 			trigger_bus();
   1635 			break;
   1636 		default:
   1637 			/* NOTREACHED */
   1638 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1639 		}
   1640 
   1641 		/* NOTREACHED */
   1642 		FORKEE_ASSERTX(0 && "This shall not be reached");
   1643 	}
   1644 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1645 
   1646 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1647 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1648 
   1649 	validate_status_signaled(status, sig, 1);
   1650 
   1651 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1652 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1653 }
   1654 
   1655 #define TRACEME_VFORK_SIGNALMASKED_CRASH(test, sig)			\
   1656 ATF_TC(test);								\
   1657 ATF_TC_HEAD(test, tc)							\
   1658 {									\
   1659 	atf_tc_set_md_var(tc, "descr",					\
   1660 	    "Verify PT_TRACE_ME followed by a crash signal " #sig " in a " \
   1661 	    "vfork(2)ed child with a masked signal");			\
   1662 }									\
   1663 									\
   1664 ATF_TC_BODY(test, tc)							\
   1665 {									\
   1666 									\
   1667 	traceme_vfork_signalmasked_crash(sig);				\
   1668 }
   1669 
   1670 TRACEME_VFORK_SIGNALMASKED_CRASH(traceme_vfork_signalmasked_crash_trap, SIGTRAP)
   1671 TRACEME_VFORK_SIGNALMASKED_CRASH(traceme_vfork_signalmasked_crash_segv, SIGSEGV)
   1672 TRACEME_VFORK_SIGNALMASKED_CRASH(traceme_vfork_signalmasked_crash_ill, SIGILL)
   1673 TRACEME_VFORK_SIGNALMASKED_CRASH(traceme_vfork_signalmasked_crash_fpe, SIGFPE)
   1674 TRACEME_VFORK_SIGNALMASKED_CRASH(traceme_vfork_signalmasked_crash_bus, SIGBUS)
   1675 
   1676 /// ----------------------------------------------------------------------------
   1677 
   1678 static void
   1679 traceme_vfork_signalignored_crash(int sig)
   1680 {
   1681 	pid_t child, wpid;
   1682 #if defined(TWAIT_HAVE_STATUS)
   1683 	int status;
   1684 #endif
   1685 	struct sigaction sa;
   1686 
   1687 #ifndef PTRACE_ILLEGAL_ASM
   1688 	if (sig == SIGILL)
   1689 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
   1690 #endif
   1691 
   1692 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
   1693 		atf_tc_skip("FP exceptions are not supported");
   1694 
   1695 	DPRINTF("Before forking process PID=%d\n", getpid());
   1696 	RL(child = vfork());
   1697 	if (child == 0) {
   1698 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   1699 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   1700 
   1701 		memset(&sa, 0, sizeof(sa));
   1702 		sa.sa_handler = SIG_IGN;
   1703 		sigemptyset(&sa.sa_mask);
   1704 
   1705 		FORKEE_ASSERT(sigaction(sig, &sa, NULL) != -1);
   1706 
   1707 		DPRINTF("Before executing a trap\n");
   1708 		switch (sig) {
   1709 		case SIGTRAP:
   1710 			trigger_trap();
   1711 			break;
   1712 		case SIGSEGV:
   1713 			trigger_segv();
   1714 			break;
   1715 		case SIGILL:
   1716 			trigger_ill();
   1717 			break;
   1718 		case SIGFPE:
   1719 			trigger_fpe();
   1720 			break;
   1721 		case SIGBUS:
   1722 			trigger_bus();
   1723 			break;
   1724 		default:
   1725 			/* NOTREACHED */
   1726 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1727 		}
   1728 
   1729 		/* NOTREACHED */
   1730 		FORKEE_ASSERTX(0 && "This shall not be reached");
   1731 	}
   1732 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   1733 
   1734 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1735 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   1736 
   1737 	validate_status_signaled(status, sig, 1);
   1738 
   1739 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   1740 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   1741 }
   1742 
   1743 #define TRACEME_VFORK_SIGNALIGNORED_CRASH(test, sig)			\
   1744 ATF_TC(test);								\
   1745 ATF_TC_HEAD(test, tc)							\
   1746 {									\
   1747 	atf_tc_set_md_var(tc, "descr",					\
   1748 	    "Verify PT_TRACE_ME followed by a crash signal " #sig " in a " \
   1749 	    "vfork(2)ed child with ignored signal");			\
   1750 }									\
   1751 									\
   1752 ATF_TC_BODY(test, tc)							\
   1753 {									\
   1754 									\
   1755 	traceme_vfork_signalignored_crash(sig);				\
   1756 }
   1757 
   1758 TRACEME_VFORK_SIGNALIGNORED_CRASH(traceme_vfork_signalignored_crash_trap,
   1759     SIGTRAP)
   1760 TRACEME_VFORK_SIGNALIGNORED_CRASH(traceme_vfork_signalignored_crash_segv,
   1761     SIGSEGV)
   1762 TRACEME_VFORK_SIGNALIGNORED_CRASH(traceme_vfork_signalignored_crash_ill,
   1763     SIGILL)
   1764 TRACEME_VFORK_SIGNALIGNORED_CRASH(traceme_vfork_signalignored_crash_fpe,
   1765     SIGFPE)
   1766 TRACEME_VFORK_SIGNALIGNORED_CRASH(traceme_vfork_signalignored_crash_bus,
   1767     SIGBUS)
   1768 
   1769 /// ----------------------------------------------------------------------------
   1770 
   1771 #if defined(TWAIT_HAVE_PID)
   1772 static void
   1773 unrelated_tracer_sees_crash(int sig, bool masked, bool ignored)
   1774 {
   1775 	const int sigval = SIGSTOP;
   1776 	struct msg_fds parent_tracee, parent_tracer;
   1777 	const int exitval = 10;
   1778 	pid_t tracee, tracer, wpid;
   1779 	uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
   1780 #if defined(TWAIT_HAVE_STATUS)
   1781 	int status;
   1782 #endif
   1783 	struct sigaction sa;
   1784 	struct ptrace_siginfo info;
   1785 	sigset_t intmask;
   1786 	struct kinfo_proc2 kp;
   1787 	size_t len = sizeof(kp);
   1788 
   1789 	int name[6];
   1790 	const size_t namelen = __arraycount(name);
   1791 	ki_sigset_t kp_sigmask;
   1792 	ki_sigset_t kp_sigignore;
   1793 
   1794 #ifndef PTRACE_ILLEGAL_ASM
   1795 	if (sig == SIGILL)
   1796 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
   1797 #endif
   1798 
   1799 	if (sig == SIGFPE && !are_fpu_exceptions_supported())
   1800 		atf_tc_skip("FP exceptions are not supported");
   1801 
   1802 	memset(&info, 0, sizeof(info));
   1803 
   1804 	DPRINTF("Spawn tracee\n");
   1805 	SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0);
   1806 	tracee = atf_utils_fork();
   1807 	if (tracee == 0) {
   1808 		// Wait for parent to let us crash
   1809 		CHILD_FROM_PARENT("exit tracee", parent_tracee, msg);
   1810 
   1811 		if (masked) {
   1812 			sigemptyset(&intmask);
   1813 			sigaddset(&intmask, sig);
   1814 			sigprocmask(SIG_BLOCK, &intmask, NULL);
   1815 		}
   1816 
   1817 		if (ignored) {
   1818 			memset(&sa, 0, sizeof(sa));
   1819 			sa.sa_handler = SIG_IGN;
   1820 			sigemptyset(&sa.sa_mask);
   1821 			FORKEE_ASSERT(sigaction(sig, &sa, NULL) != -1);
   1822 		}
   1823 
   1824 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   1825 		FORKEE_ASSERT(raise(sigval) == 0);
   1826 
   1827 		DPRINTF("Before executing a trap\n");
   1828 		switch (sig) {
   1829 		case SIGTRAP:
   1830 			trigger_trap();
   1831 			break;
   1832 		case SIGSEGV:
   1833 			trigger_segv();
   1834 			break;
   1835 		case SIGILL:
   1836 			trigger_ill();
   1837 			break;
   1838 		case SIGFPE:
   1839 			trigger_fpe();
   1840 			break;
   1841 		case SIGBUS:
   1842 			trigger_bus();
   1843 			break;
   1844 		default:
   1845 			/* NOTREACHED */
   1846 			FORKEE_ASSERTX(0 && "This shall not be reached");
   1847 		}
   1848 
   1849 		/* NOTREACHED */
   1850 		FORKEE_ASSERTX(0 && "This shall not be reached");
   1851 	}
   1852 
   1853 	DPRINTF("Spawn debugger\n");
   1854 	SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0);
   1855 	tracer = atf_utils_fork();
   1856 	if (tracer == 0) {
   1857 		/* Fork again and drop parent to reattach to PID 1 */
   1858 		tracer = atf_utils_fork();
   1859 		if (tracer != 0)
   1860 			_exit(exitval);
   1861 
   1862 		DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid());
   1863 		FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
   1864 
   1865 		/* Wait for tracee and assert that it was stopped w/ SIGSTOP */
   1866 		FORKEE_REQUIRE_SUCCESS(
   1867 		    wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
   1868 
   1869 		forkee_status_stopped(status, SIGSTOP);
   1870 
   1871 		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the "
   1872 		    "traced process\n");
   1873 		SYSCALL_REQUIRE(
   1874 		    ptrace(PT_GET_SIGINFO, tracee, &info, sizeof(info)) != -1);
   1875 
   1876 		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1877 		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
   1878 		    "si_errno=%#x\n", info.psi_siginfo.si_signo,
   1879 		    info.psi_siginfo.si_code, info.psi_siginfo.si_errno);
   1880 
   1881 		FORKEE_ASSERT_EQ(info.psi_siginfo.si_signo, SIGSTOP);
   1882 		FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SI_USER);
   1883 
   1884 		/* Resume tracee with PT_CONTINUE */
   1885 		FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
   1886 
   1887 		/* Inform parent that tracer has attached to tracee */
   1888 		CHILD_TO_PARENT("tracer ready", parent_tracer, msg);
   1889 
   1890 		/* Wait for parent to tell use that tracee should have exited */
   1891 		CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg);
   1892 
   1893 		/* Wait for tracee and assert that it exited */
   1894 		FORKEE_REQUIRE_SUCCESS(
   1895 		    wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
   1896 
   1897 		forkee_status_stopped(status, sigval);
   1898 
   1899 		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the "
   1900 		    "traced process\n");
   1901 		SYSCALL_REQUIRE(
   1902 		    ptrace(PT_GET_SIGINFO, tracee, &info, sizeof(info)) != -1);
   1903 
   1904 		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1905 		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
   1906 		    "si_errno=%#x\n", info.psi_siginfo.si_signo,
   1907 		    info.psi_siginfo.si_code, info.psi_siginfo.si_errno);
   1908 
   1909 		FORKEE_ASSERT_EQ(info.psi_siginfo.si_signo, sigval);
   1910 		FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SI_LWP);
   1911 
   1912 		name[0] = CTL_KERN,
   1913 		name[1] = KERN_PROC2,
   1914 		name[2] = KERN_PROC_PID;
   1915 		name[3] = tracee;
   1916 		name[4] = sizeof(kp);
   1917 		name[5] = 1;
   1918 
   1919 		FORKEE_ASSERT_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
   1920 
   1921 		if (masked)
   1922 			kp_sigmask = kp.p_sigmask;
   1923 
   1924 		if (ignored)
   1925 			kp_sigignore = kp.p_sigignore;
   1926 
   1927 		/* Resume tracee with PT_CONTINUE */
   1928 		FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
   1929 
   1930 		/* Wait for tracee and assert that it exited */
   1931 		FORKEE_REQUIRE_SUCCESS(
   1932 		    wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
   1933 
   1934 		forkee_status_stopped(status, sig);
   1935 
   1936 		DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the "
   1937 		    "traced process\n");
   1938 		SYSCALL_REQUIRE(
   1939 		    ptrace(PT_GET_SIGINFO, tracee, &info, sizeof(info)) != -1);
   1940 
   1941 		DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
   1942 		DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
   1943 		    "si_errno=%#x\n", info.psi_siginfo.si_signo,
   1944 		    info.psi_siginfo.si_code, info.psi_siginfo.si_errno);
   1945 
   1946 		FORKEE_ASSERT_EQ(info.psi_siginfo.si_signo, sig);
   1947 
   1948 		FORKEE_ASSERT_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
   1949 
   1950 		if (masked) {
   1951 			DPRINTF("kp_sigmask="
   1952 			    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
   1953 			    PRIx32 "\n",
   1954 			    kp_sigmask.__bits[0], kp_sigmask.__bits[1],
   1955 			    kp_sigmask.__bits[2], kp_sigmask.__bits[3]);
   1956 
   1957 			DPRINTF("kp.p_sigmask="
   1958 			    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
   1959 			    PRIx32 "\n",
   1960 			    kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
   1961 			    kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
   1962 
   1963 #ifdef __SOFTFP__
   1964 			/*
   1965 			 * See above in traceme_signalmasked_crash
   1966 			 * about the softfloat trap SIGFPE delivery
   1967 			 * quirk that requires us to fudge this test.
   1968 			 */
   1969 			if (sig == SIGFPE) {
   1970 				softfloat_fudge_sigs(&kp_sigmask,
   1971 				    &kp.p_sigmask);
   1972 			}
   1973 #endif
   1974 
   1975 			FORKEE_ASSERT_MEMEQ(&kp_sigmask, &kp.p_sigmask,
   1976 			    sizeof(kp_sigmask));
   1977 		}
   1978 
   1979 		if (ignored) {
   1980 			DPRINTF("kp_sigignore="
   1981 			    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
   1982 			    PRIx32 "\n",
   1983 			    kp_sigignore.__bits[0], kp_sigignore.__bits[1],
   1984 			    kp_sigignore.__bits[2], kp_sigignore.__bits[3]);
   1985 
   1986 			DPRINTF("kp.p_sigignore="
   1987 			    "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02"
   1988 			    PRIx32 "\n",
   1989 			    kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
   1990 			    kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
   1991 
   1992 #ifdef __SOFTFP__
   1993 			/*
   1994 			 * See above in traceme_signalignored_crash
   1995 			 * about the softfloat trap SIGFPE delivery
   1996 			 * quirk that requires us to fudge this test.
   1997 			 */
   1998 			if (sig == SIGFPE) {
   1999 				softfloat_fudge_sigs(&kp_sigignore,
   2000 				    &kp.p_sigignore);
   2001 			}
   2002 #endif
   2003 
   2004 			FORKEE_ASSERT_MEMEQ(&kp_sigignore, &kp.p_sigignore,
   2005 			    sizeof(kp_sigignore));
   2006 		}
   2007 
   2008 		switch (sig) {
   2009 		case SIGTRAP:
   2010 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, TRAP_BRKPT);
   2011 			break;
   2012 		case SIGSEGV:
   2013 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
   2014 			break;
   2015 		case SIGILL:
   2016 			FORKEE_ASSERT(info.psi_siginfo.si_code >= ILL_ILLOPC &&
   2017 			            info.psi_siginfo.si_code <= ILL_BADSTK);
   2018 			break;
   2019 		case SIGFPE:
   2020 // XXXQEMU		FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_FLTDIV);
   2021 			break;
   2022 		case SIGBUS:
   2023 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, BUS_ADRERR);
   2024 			break;
   2025 		}
   2026 
   2027 		FORKEE_ASSERT(ptrace(PT_KILL, tracee, NULL, 0) != -1);
   2028 		DPRINTF("Before calling %s() for the tracee\n", TWAIT_FNAME);
   2029 		FORKEE_REQUIRE_SUCCESS(
   2030 		    wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
   2031 
   2032 		forkee_status_signaled(status, SIGKILL, 0);
   2033 
   2034 		/* Inform parent that tracer is exiting normally */
   2035 		CHILD_TO_PARENT("tracer done", parent_tracer, msg);
   2036 
   2037 		DPRINTF("Before exiting of the tracer process\n");
   2038 		_exit(0 /* collect by initproc */);
   2039 	}
   2040 
   2041 	DPRINTF("Wait for the tracer process (direct child) to exit "
   2042 	    "calling %s()\n", TWAIT_FNAME);
   2043 	TWAIT_REQUIRE_SUCCESS(
   2044 	    wpid = TWAIT_GENERIC(tracer, &status, 0), tracer);
   2045 
   2046 	validate_status_exited(status, exitval);
   2047 
   2048 	DPRINTF("Wait for the non-exited tracee process with %s()\n",
   2049 	    TWAIT_FNAME);
   2050 	TWAIT_REQUIRE_SUCCESS(
   2051 	    wpid = TWAIT_GENERIC(tracee, NULL, WNOHANG), 0);
   2052 
   2053 	DPRINTF("Wait for the tracer to attach to the tracee\n");
   2054 	PARENT_FROM_CHILD("tracer ready", parent_tracer, msg);
   2055 
   2056 	DPRINTF("Resume the tracee and let it crash\n");
   2057 	PARENT_TO_CHILD("exit tracee", parent_tracee,  msg);
   2058 
   2059 	DPRINTF("Resume the tracer and let it detect crashed tracee\n");
   2060 	PARENT_TO_CHILD("Message 2", parent_tracer, msg);
   2061 
   2062 	DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n",
   2063 	    TWAIT_FNAME);
   2064 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
   2065 
   2066 	validate_status_signaled(status, SIGKILL, 0);
   2067 
   2068 	DPRINTF("Await normal exit of tracer\n");
   2069 	PARENT_FROM_CHILD("tracer done", parent_tracer, msg);
   2070 
   2071 	msg_close(&parent_tracer);
   2072 	msg_close(&parent_tracee);
   2073 }
   2074 
   2075 #define UNRELATED_TRACER_SEES_CRASH(test, sig)				\
   2076 ATF_TC(test);								\
   2077 ATF_TC_HEAD(test, tc)							\
   2078 {									\
   2079 	atf_tc_set_md_var(tc, "descr",					\
   2080 	    "Assert that an unrelated tracer sees crash signal from "	\
   2081 	    "the debuggee");						\
   2082 }									\
   2083 									\
   2084 ATF_TC_BODY(test, tc)							\
   2085 {									\
   2086 									\
   2087 	unrelated_tracer_sees_crash(sig, false, false);			\
   2088 }
   2089 
   2090 UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_trap, SIGTRAP)
   2091 UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_segv, SIGSEGV)
   2092 UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_ill, SIGILL)
   2093 UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_fpe, SIGFPE)
   2094 UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_bus, SIGBUS)
   2095 
   2096 #define UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(test, sig)		\
   2097 ATF_TC(test);								\
   2098 ATF_TC_HEAD(test, tc)							\
   2099 {									\
   2100 	atf_tc_set_md_var(tc, "descr",					\
   2101 	    "Assert that an unrelated tracer sees crash signal from "	\
   2102 	    "the debuggee with masked signal");				\
   2103 }									\
   2104 									\
   2105 ATF_TC_BODY(test, tc)							\
   2106 {									\
   2107 									\
   2108 	unrelated_tracer_sees_crash(sig, true, false);			\
   2109 }
   2110 
   2111 UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(
   2112     unrelated_tracer_sees_signalmasked_crash_trap, SIGTRAP)
   2113 UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(
   2114     unrelated_tracer_sees_signalmasked_crash_segv, SIGSEGV)
   2115 UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(
   2116     unrelated_tracer_sees_signalmasked_crash_ill, SIGILL)
   2117 UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(
   2118     unrelated_tracer_sees_signalmasked_crash_fpe, SIGFPE)
   2119 UNRELATED_TRACER_SEES_SIGNALMASKED_CRASH(
   2120     unrelated_tracer_sees_signalmasked_crash_bus, SIGBUS)
   2121 
   2122 #define UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(test, sig)		\
   2123 ATF_TC(test);								\
   2124 ATF_TC_HEAD(test, tc)							\
   2125 {									\
   2126 	atf_tc_set_md_var(tc, "descr",					\
   2127 	    "Assert that an unrelated tracer sees crash signal from "	\
   2128 	    "the debuggee with signal ignored");			\
   2129 }									\
   2130 									\
   2131 ATF_TC_BODY(test, tc)							\
   2132 {									\
   2133 									\
   2134 	unrelated_tracer_sees_crash(sig, false, true);			\
   2135 }
   2136 
   2137 UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(
   2138     unrelated_tracer_sees_signalignored_crash_trap, SIGTRAP)
   2139 UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(
   2140     unrelated_tracer_sees_signalignored_crash_segv, SIGSEGV)
   2141 UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(
   2142     unrelated_tracer_sees_signalignored_crash_ill, SIGILL)
   2143 UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(
   2144     unrelated_tracer_sees_signalignored_crash_fpe, SIGFPE)
   2145 UNRELATED_TRACER_SEES_SIGNALIGNORED_CRASH(
   2146     unrelated_tracer_sees_signalignored_crash_bus, SIGBUS)
   2147 #endif
   2148 
   2149 /// ----------------------------------------------------------------------------
   2150 
   2151 ATF_TC(signal_mask_unrelated);
   2152 ATF_TC_HEAD(signal_mask_unrelated, tc)
   2153 {
   2154 	atf_tc_set_md_var(tc, "descr",
   2155 	    "Verify that masking single unrelated signal does not stop tracer "
   2156 	    "from catching other signals");
   2157 }
   2158 
   2159 ATF_TC_BODY(signal_mask_unrelated, tc)
   2160 {
   2161 	const int exitval = 5;
   2162 	const int sigval = SIGSTOP;
   2163 	const int sigmasked = SIGTRAP;
   2164 	const int signotmasked = SIGINT;
   2165 	pid_t child, wpid;
   2166 #if defined(TWAIT_HAVE_STATUS)
   2167 	int status;
   2168 #endif
   2169 	sigset_t intmask;
   2170 
   2171 	DPRINTF("Before forking process PID=%d\n", getpid());
   2172 	RL(child = fork());
   2173 	if (child == 0) {
   2174 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
   2175 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
   2176 
   2177 		sigemptyset(&intmask);
   2178 		sigaddset(&intmask, sigmasked);
   2179 		sigprocmask(SIG_BLOCK, &intmask, NULL);
   2180 
   2181 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
   2182 		FORKEE_ASSERT(raise(sigval) == 0);
   2183 
   2184 		DPRINTF("Before raising %s from child\n",
   2185 		    strsignal(signotmasked));
   2186 		FORKEE_ASSERT(raise(signotmasked) == 0);
   2187 
   2188 		DPRINTF("Before exiting of the child process\n");
   2189 		_exit(exitval);
   2190 	}
   2191 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
   2192 
   2193 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   2194 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   2195 
   2196 	validate_status_stopped(status, sigval);
   2197 
   2198 	DPRINTF("Before resuming the child process where it left off and "
   2199 	    "without signal to be sent\n");
   2200 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
   2201 
   2202 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   2203 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   2204 
   2205 	validate_status_stopped(status, signotmasked);
   2206 
   2207 	DPRINTF("Before resuming the child process where it left off and "
   2208 	    "without signal to be sent\n");
   2209 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
   2210 
   2211 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   2212 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
   2213 
   2214 	validate_status_exited(status, exitval);
   2215 
   2216 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
   2217 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
   2218 }
   2219 
   2220 /// ----------------------------------------------------------------------------
   2221 
   2222 #define ATF_TP_ADD_TCS_PTRACE_WAIT_SIGNAL() \
   2223 	ATF_TP_ADD_TC(tp, traceme_raise1); \
   2224 	ATF_TP_ADD_TC(tp, traceme_raise2); \
   2225 	ATF_TP_ADD_TC(tp, traceme_raise3); \
   2226 	ATF_TP_ADD_TC(tp, traceme_raise4); \
   2227 	ATF_TP_ADD_TC(tp, traceme_raise5); \
   2228 	ATF_TP_ADD_TC(tp, traceme_raise6); \
   2229 	ATF_TP_ADD_TC(tp, traceme_raise7); \
   2230 	ATF_TP_ADD_TC(tp, traceme_raise8); \
   2231 	ATF_TP_ADD_TC(tp, traceme_raise9); \
   2232 	ATF_TP_ADD_TC(tp, traceme_raise10); \
   2233 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored1); \
   2234 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored2); \
   2235 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored3); \
   2236 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored4); \
   2237 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored5); \
   2238 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored6); \
   2239 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored7); \
   2240 	ATF_TP_ADD_TC(tp, traceme_raisesignal_ignored8); \
   2241 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked1); \
   2242 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked2); \
   2243 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked3); \
   2244 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked4); \
   2245 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked5); \
   2246 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked6); \
   2247 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked7); \
   2248 	ATF_TP_ADD_TC(tp, traceme_raisesignal_masked8); \
   2249 	ATF_TP_ADD_TC(tp, traceme_crash_trap); \
   2250 	ATF_TP_ADD_TC(tp, traceme_crash_segv); \
   2251 	ATF_TP_ADD_TC(tp, traceme_crash_ill); \
   2252 	ATF_TP_ADD_TC(tp, traceme_crash_fpe); \
   2253 	ATF_TP_ADD_TC(tp, traceme_crash_bus); \
   2254 	ATF_TP_ADD_TC(tp, traceme_signalmasked_crash_trap); \
   2255 	ATF_TP_ADD_TC(tp, traceme_signalmasked_crash_segv); \
   2256 	ATF_TP_ADD_TC(tp, traceme_signalmasked_crash_ill); \
   2257 	ATF_TP_ADD_TC(tp, traceme_signalmasked_crash_fpe); \
   2258 	ATF_TP_ADD_TC(tp, traceme_signalmasked_crash_bus); \
   2259 	ATF_TP_ADD_TC(tp, traceme_signalignored_crash_trap); \
   2260 	ATF_TP_ADD_TC(tp, traceme_signalignored_crash_segv); \
   2261 	ATF_TP_ADD_TC(tp, traceme_signalignored_crash_ill); \
   2262 	ATF_TP_ADD_TC(tp, traceme_signalignored_crash_fpe); \
   2263 	ATF_TP_ADD_TC(tp, traceme_signalignored_crash_bus); \
   2264 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle1); \
   2265 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle2); \
   2266 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle3); \
   2267 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle4); \
   2268 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle5); \
   2269 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle6); \
   2270 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle7); \
   2271 	ATF_TP_ADD_TC(tp, traceme_sendsignal_handle8); \
   2272 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked1); \
   2273 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked2); \
   2274 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked3); \
   2275 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked4); \
   2276 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked5); \
   2277 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked6); \
   2278 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked7); \
   2279 	ATF_TP_ADD_TC(tp, traceme_sendsignal_masked8); \
   2280 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored1); \
   2281 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored2); \
   2282 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored3); \
   2283 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored4); \
   2284 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored5); \
   2285 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored6); \
   2286 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored7); \
   2287 	ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored8); \
   2288 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple1); \
   2289 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple2); \
   2290 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple3); \
   2291 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple4); \
   2292 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple5); \
   2293 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple6); \
   2294 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple7); \
   2295 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple8); \
   2296 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple9); \
   2297 	ATF_TP_ADD_TC(tp, traceme_sendsignal_simple10); \
   2298 	ATF_TP_ADD_TC(tp, traceme_vfork_raise1); \
   2299 	ATF_TP_ADD_TC(tp, traceme_vfork_raise2); \
   2300 	ATF_TP_ADD_TC(tp, traceme_vfork_raise3); \
   2301 	ATF_TP_ADD_TC(tp, traceme_vfork_raise4); \
   2302 	ATF_TP_ADD_TC(tp, traceme_vfork_raise5); \
   2303 	ATF_TP_ADD_TC(tp, traceme_vfork_raise6); \
   2304 	ATF_TP_ADD_TC(tp, traceme_vfork_raise7); \
   2305 	ATF_TP_ADD_TC(tp, traceme_vfork_raise8); \
   2306 	ATF_TP_ADD_TC(tp, traceme_vfork_raise9); \
   2307 	ATF_TP_ADD_TC(tp, traceme_vfork_raise10); \
   2308 	ATF_TP_ADD_TC(tp, traceme_vfork_raise11); \
   2309 	ATF_TP_ADD_TC(tp, traceme_vfork_raise12); \
   2310 	ATF_TP_ADD_TC(tp, traceme_vfork_raise13); \
   2311 	ATF_TP_ADD_TC(tp, traceme_vfork_crash_trap); \
   2312 	ATF_TP_ADD_TC(tp, traceme_vfork_crash_segv); \
   2313 	ATF_TP_ADD_TC(tp, traceme_vfork_crash_ill); \
   2314 	ATF_TP_ADD_TC(tp, traceme_vfork_crash_fpe); \
   2315 	ATF_TP_ADD_TC(tp, traceme_vfork_crash_bus); \
   2316 	ATF_TP_ADD_TC(tp, traceme_vfork_signalmasked_crash_trap); \
   2317 	ATF_TP_ADD_TC(tp, traceme_vfork_signalmasked_crash_segv); \
   2318 	ATF_TP_ADD_TC(tp, traceme_vfork_signalmasked_crash_ill); \
   2319 	ATF_TP_ADD_TC(tp, traceme_vfork_signalmasked_crash_fpe); \
   2320 	ATF_TP_ADD_TC(tp, traceme_vfork_signalmasked_crash_bus); \
   2321 	ATF_TP_ADD_TC(tp, traceme_vfork_signalignored_crash_trap); \
   2322 	ATF_TP_ADD_TC(tp, traceme_vfork_signalignored_crash_segv); \
   2323 	ATF_TP_ADD_TC(tp, traceme_vfork_signalignored_crash_ill); \
   2324 	ATF_TP_ADD_TC(tp, traceme_vfork_signalignored_crash_fpe); \
   2325 	ATF_TP_ADD_TC(tp, traceme_vfork_signalignored_crash_bus); \
   2326 	ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_trap); \
   2327 	ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_segv); \
   2328 	ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_ill); \
   2329 	ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_fpe); \
   2330 	ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_bus); \
   2331 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2332 	    unrelated_tracer_sees_signalmasked_crash_trap); \
   2333 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2334 	    unrelated_tracer_sees_signalmasked_crash_segv); \
   2335 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2336 	    unrelated_tracer_sees_signalmasked_crash_ill); \
   2337 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2338 	    unrelated_tracer_sees_signalmasked_crash_fpe); \
   2339 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2340 	    unrelated_tracer_sees_signalmasked_crash_bus); \
   2341 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2342 	    unrelated_tracer_sees_signalignored_crash_trap); \
   2343 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2344 	    unrelated_tracer_sees_signalignored_crash_segv); \
   2345 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2346 	    unrelated_tracer_sees_signalignored_crash_ill); \
   2347 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2348 	    unrelated_tracer_sees_signalignored_crash_fpe); \
   2349 	ATF_TP_ADD_TC_HAVE_PID(tp, \
   2350 	    unrelated_tracer_sees_signalignored_crash_bus); \
   2351 	ATF_TP_ADD_TC(tp, signal_mask_unrelated);
   2352