2 * Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/cpuset.h>
32 #include <sys/event.h>
34 #include <sys/procctl.h>
35 #include <sys/ptrace.h>
36 #include <sys/queue.h>
38 #include <sys/syscall.h>
39 #include <sys/sysctl.h>
43 #include <machine/cpufunc.h>
46 #include <semaphore.h>
54 * A variant of ATF_REQUIRE that is suitable for use in child
55 * processes. This only works if the parent process is tripped up by
56 * the early exit and fails some requirement itself.
58 #define CHILD_REQUIRE(exp) do { \
60 child_fail_require(__FILE__, __LINE__, \
65 child_fail_require(const char *file, int line, const char *str)
69 snprintf(buf, sizeof(buf), "%s:%d: %s\n", file, line, str);
70 write(2, buf, strlen(buf));
78 /* Attach the parent process as a tracer of this process. */
79 CHILD_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
86 attach_child(pid_t pid)
91 ATF_REQUIRE(ptrace(PT_ATTACH, pid, NULL, 0) == 0);
93 wpid = waitpid(pid, &status, 0);
94 ATF_REQUIRE(wpid == pid);
95 ATF_REQUIRE(WIFSTOPPED(status));
96 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
100 wait_for_zombie(pid_t pid)
104 * Wait for a process to exit. This is kind of gross, but
105 * there is not a better way.
107 * Prior to r325719, the kern.proc.pid.<pid> sysctl failed
108 * with ESRCH. After that change, a valid struct kinfo_proc
109 * is returned for zombies with ki_stat set to SZOMB.
112 struct kinfo_proc kp;
118 mib[2] = KERN_PROC_PID;
121 if (sysctl(mib, nitems(mib), &kp, &len, NULL, 0) == -1) {
122 ATF_REQUIRE(errno == ESRCH);
125 if (kp.ki_stat == SZOMB)
132 * Verify that a parent debugger process "sees" the exit of a debugged
133 * process exactly once when attached via PT_TRACE_ME.
135 ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_trace_me);
136 ATF_TC_BODY(ptrace__parent_wait_after_trace_me, tc)
141 ATF_REQUIRE((child = fork()) != -1);
149 /* Parent process. */
151 /* The first wait() should report the stop from SIGSTOP. */
152 wpid = waitpid(child, &status, 0);
153 ATF_REQUIRE(wpid == child);
154 ATF_REQUIRE(WIFSTOPPED(status));
155 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
157 /* Continue the child ignoring the SIGSTOP. */
158 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
160 /* The second wait() should report the exit status. */
161 wpid = waitpid(child, &status, 0);
162 ATF_REQUIRE(wpid == child);
163 ATF_REQUIRE(WIFEXITED(status));
164 ATF_REQUIRE(WEXITSTATUS(status) == 1);
166 /* The child should no longer exist. */
167 wpid = waitpid(child, &status, 0);
168 ATF_REQUIRE(wpid == -1);
169 ATF_REQUIRE(errno == ECHILD);
173 * Verify that a parent debugger process "sees" the exit of a debugged
174 * process exactly once when attached via PT_ATTACH.
176 ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_attach);
177 ATF_TC_BODY(ptrace__parent_wait_after_attach, tc)
180 int cpipe[2], status;
183 ATF_REQUIRE(pipe(cpipe) == 0);
184 ATF_REQUIRE((child = fork()) != -1);
189 /* Wait for the parent to attach. */
190 CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0);
196 /* Parent process. */
198 /* Attach to the child process. */
201 /* Continue the child ignoring the SIGSTOP. */
202 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
204 /* Signal the child to exit. */
207 /* The second wait() should report the exit status. */
208 wpid = waitpid(child, &status, 0);
209 ATF_REQUIRE(wpid == child);
210 ATF_REQUIRE(WIFEXITED(status));
211 ATF_REQUIRE(WEXITSTATUS(status) == 1);
213 /* The child should no longer exist. */
214 wpid = waitpid(child, &status, 0);
215 ATF_REQUIRE(wpid == -1);
216 ATF_REQUIRE(errno == ECHILD);
220 * Verify that a parent process "sees" the exit of a debugged process only
221 * after the debugger has seen it.
223 ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_child_debugger);
224 ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc)
226 pid_t child, debugger, wpid;
227 int cpipe[2], dpipe[2], status;
230 ATF_REQUIRE(pipe(cpipe) == 0);
231 ATF_REQUIRE((child = fork()) != -1);
237 /* Wait for parent to be ready. */
238 CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
244 ATF_REQUIRE(pipe(dpipe) == 0);
245 ATF_REQUIRE((debugger = fork()) != -1);
248 /* Debugger process. */
251 CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
253 wpid = waitpid(child, &status, 0);
254 CHILD_REQUIRE(wpid == child);
255 CHILD_REQUIRE(WIFSTOPPED(status));
256 CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
258 CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
260 /* Signal parent that debugger is attached. */
261 CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
263 /* Wait for parent's failed wait. */
264 CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
266 wpid = waitpid(child, &status, 0);
267 CHILD_REQUIRE(wpid == child);
268 CHILD_REQUIRE(WIFEXITED(status));
269 CHILD_REQUIRE(WEXITSTATUS(status) == 1);
275 /* Parent process. */
277 /* Wait for the debugger to attach to the child. */
278 ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == sizeof(c));
280 /* Release the child. */
281 ATF_REQUIRE(write(cpipe[0], &c, sizeof(c)) == sizeof(c));
282 ATF_REQUIRE(read(cpipe[0], &c, sizeof(c)) == 0);
285 wait_for_zombie(child);
288 * This wait should return a pid of 0 to indicate no status to
289 * report. The parent should see the child as non-exited
290 * until the debugger sees the exit.
292 wpid = waitpid(child, &status, WNOHANG);
293 ATF_REQUIRE(wpid == 0);
295 /* Signal the debugger to wait for the child. */
298 /* Wait for the debugger. */
299 wpid = waitpid(debugger, &status, 0);
300 ATF_REQUIRE(wpid == debugger);
301 ATF_REQUIRE(WIFEXITED(status));
302 ATF_REQUIRE(WEXITSTATUS(status) == 0);
304 /* The child process should now be ready. */
305 wpid = waitpid(child, &status, WNOHANG);
306 ATF_REQUIRE(wpid == child);
307 ATF_REQUIRE(WIFEXITED(status));
308 ATF_REQUIRE(WEXITSTATUS(status) == 1);
312 * Verify that a parent process "sees" the exit of a debugged process
313 * only after a non-direct-child debugger has seen it. In particular,
314 * various wait() calls in the parent must avoid failing with ESRCH by
315 * checking the parent's orphan list for the debugee.
317 ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_unrelated_debugger);
318 ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
320 pid_t child, debugger, fpid, wpid;
321 int cpipe[2], dpipe[2], status;
324 ATF_REQUIRE(pipe(cpipe) == 0);
325 ATF_REQUIRE((child = fork()) != -1);
331 /* Wait for parent to be ready. */
332 CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
338 ATF_REQUIRE(pipe(dpipe) == 0);
339 ATF_REQUIRE((debugger = fork()) != -1);
342 /* Debugger parent. */
345 * Fork again and drop the debugger parent so that the
346 * debugger is not a child of the main parent.
348 CHILD_REQUIRE((fpid = fork()) != -1);
352 /* Debugger process. */
355 CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
357 wpid = waitpid(child, &status, 0);
358 CHILD_REQUIRE(wpid == child);
359 CHILD_REQUIRE(WIFSTOPPED(status));
360 CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
362 CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
364 /* Signal parent that debugger is attached. */
365 CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
367 /* Wait for parent's failed wait. */
368 CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == sizeof(c));
370 wpid = waitpid(child, &status, 0);
371 CHILD_REQUIRE(wpid == child);
372 CHILD_REQUIRE(WIFEXITED(status));
373 CHILD_REQUIRE(WEXITSTATUS(status) == 1);
379 /* Parent process. */
381 /* Wait for the debugger parent process to exit. */
382 wpid = waitpid(debugger, &status, 0);
383 ATF_REQUIRE(wpid == debugger);
384 ATF_REQUIRE(WIFEXITED(status));
385 ATF_REQUIRE(WEXITSTATUS(status) == 2);
387 /* A WNOHANG wait here should see the non-exited child. */
388 wpid = waitpid(child, &status, WNOHANG);
389 ATF_REQUIRE(wpid == 0);
391 /* Wait for the debugger to attach to the child. */
392 ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == sizeof(c));
394 /* Release the child. */
395 ATF_REQUIRE(write(cpipe[0], &c, sizeof(c)) == sizeof(c));
396 ATF_REQUIRE(read(cpipe[0], &c, sizeof(c)) == 0);
399 wait_for_zombie(child);
402 * This wait should return a pid of 0 to indicate no status to
403 * report. The parent should see the child as non-exited
404 * until the debugger sees the exit.
406 wpid = waitpid(child, &status, WNOHANG);
407 ATF_REQUIRE(wpid == 0);
409 /* Signal the debugger to wait for the child. */
410 ATF_REQUIRE(write(dpipe[0], &c, sizeof(c)) == sizeof(c));
412 /* Wait for the debugger. */
413 ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == 0);
416 /* The child process should now be ready. */
417 wpid = waitpid(child, &status, WNOHANG);
418 ATF_REQUIRE(wpid == child);
419 ATF_REQUIRE(WIFEXITED(status));
420 ATF_REQUIRE(WEXITSTATUS(status) == 1);
424 * The parent process should always act the same regardless of how the
425 * debugger is attached to it.
428 follow_fork_parent(bool use_vfork)
434 CHILD_REQUIRE((fpid = vfork()) != -1);
436 CHILD_REQUIRE((fpid = fork()) != -1);
442 wpid = waitpid(fpid, &status, 0);
443 CHILD_REQUIRE(wpid == fpid);
444 CHILD_REQUIRE(WIFEXITED(status));
445 CHILD_REQUIRE(WEXITSTATUS(status) == 2);
451 * Helper routine for follow fork tests. This waits for two stops
452 * that report both "sides" of a fork. It returns the pid of the new
456 handle_fork_events(pid_t parent, struct ptrace_lwpinfo *ppl)
458 struct ptrace_lwpinfo pl;
459 bool fork_reported[2];
463 fork_reported[0] = false;
464 fork_reported[1] = false;
468 * Each process should report a fork event. The parent should
469 * report a PL_FLAG_FORKED event, and the child should report
470 * a PL_FLAG_CHILD event.
472 for (i = 0; i < 2; i++) {
473 wpid = wait(&status);
474 ATF_REQUIRE(wpid > 0);
475 ATF_REQUIRE(WIFSTOPPED(status));
477 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
479 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
481 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
482 (PL_FLAG_FORKED | PL_FLAG_CHILD));
483 if (pl.pl_flags & PL_FLAG_CHILD) {
484 ATF_REQUIRE(wpid != parent);
485 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
486 ATF_REQUIRE(!fork_reported[1]);
490 ATF_REQUIRE(child == wpid);
493 fork_reported[1] = true;
495 ATF_REQUIRE(wpid == parent);
496 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
497 ATF_REQUIRE(!fork_reported[0]);
499 child = pl.pl_child_pid;
501 ATF_REQUIRE(child == pl.pl_child_pid);
504 fork_reported[0] = true;
512 * Verify that a new child process is stopped after a followed fork and
513 * that the traced parent sees the exit of the child after the debugger
514 * when both processes remain attached to the debugger.
516 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached);
517 ATF_TC_BODY(ptrace__follow_fork_both_attached, tc)
519 pid_t children[2], fpid, wpid;
522 ATF_REQUIRE((fpid = fork()) != -1);
525 follow_fork_parent(false);
528 /* Parent process. */
531 /* The first wait() should report the stop from SIGSTOP. */
532 wpid = waitpid(children[0], &status, 0);
533 ATF_REQUIRE(wpid == children[0]);
534 ATF_REQUIRE(WIFSTOPPED(status));
535 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
537 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
539 /* Continue the child ignoring the SIGSTOP. */
540 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
542 children[1] = handle_fork_events(children[0], NULL);
543 ATF_REQUIRE(children[1] > 0);
545 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
546 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
549 * The child can't exit until the grandchild reports status, so the
550 * grandchild should report its exit first to the debugger.
552 wpid = wait(&status);
553 ATF_REQUIRE(wpid == children[1]);
554 ATF_REQUIRE(WIFEXITED(status));
555 ATF_REQUIRE(WEXITSTATUS(status) == 2);
557 wpid = wait(&status);
558 ATF_REQUIRE(wpid == children[0]);
559 ATF_REQUIRE(WIFEXITED(status));
560 ATF_REQUIRE(WEXITSTATUS(status) == 1);
562 wpid = wait(&status);
563 ATF_REQUIRE(wpid == -1);
564 ATF_REQUIRE(errno == ECHILD);
568 * Verify that a new child process is stopped after a followed fork
569 * and that the traced parent sees the exit of the child when the new
570 * child process is detached after it reports its fork.
572 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached);
573 ATF_TC_BODY(ptrace__follow_fork_child_detached, tc)
575 pid_t children[2], fpid, wpid;
578 ATF_REQUIRE((fpid = fork()) != -1);
581 follow_fork_parent(false);
584 /* Parent process. */
587 /* The first wait() should report the stop from SIGSTOP. */
588 wpid = waitpid(children[0], &status, 0);
589 ATF_REQUIRE(wpid == children[0]);
590 ATF_REQUIRE(WIFSTOPPED(status));
591 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
593 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
595 /* Continue the child ignoring the SIGSTOP. */
596 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
598 children[1] = handle_fork_events(children[0], NULL);
599 ATF_REQUIRE(children[1] > 0);
601 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
602 ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
605 * Should not see any status from the grandchild now, only the
608 wpid = wait(&status);
609 ATF_REQUIRE(wpid == children[0]);
610 ATF_REQUIRE(WIFEXITED(status));
611 ATF_REQUIRE(WEXITSTATUS(status) == 1);
613 wpid = wait(&status);
614 ATF_REQUIRE(wpid == -1);
615 ATF_REQUIRE(errno == ECHILD);
619 * Verify that a new child process is stopped after a followed fork
620 * and that the traced parent sees the exit of the child when the
621 * traced parent is detached after the fork.
623 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached);
624 ATF_TC_BODY(ptrace__follow_fork_parent_detached, tc)
626 pid_t children[2], fpid, wpid;
629 ATF_REQUIRE((fpid = fork()) != -1);
632 follow_fork_parent(false);
635 /* Parent process. */
638 /* The first wait() should report the stop from SIGSTOP. */
639 wpid = waitpid(children[0], &status, 0);
640 ATF_REQUIRE(wpid == children[0]);
641 ATF_REQUIRE(WIFSTOPPED(status));
642 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
644 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
646 /* Continue the child ignoring the SIGSTOP. */
647 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
649 children[1] = handle_fork_events(children[0], NULL);
650 ATF_REQUIRE(children[1] > 0);
652 ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
653 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
656 * The child can't exit until the grandchild reports status, so the
657 * grandchild should report its exit first to the debugger.
659 * Even though the child process is detached, it is still a
660 * child of the debugger, so it will still report it's exit
661 * after the grandchild.
663 wpid = wait(&status);
664 ATF_REQUIRE(wpid == children[1]);
665 ATF_REQUIRE(WIFEXITED(status));
666 ATF_REQUIRE(WEXITSTATUS(status) == 2);
668 wpid = wait(&status);
669 ATF_REQUIRE(wpid == children[0]);
670 ATF_REQUIRE(WIFEXITED(status));
671 ATF_REQUIRE(WEXITSTATUS(status) == 1);
673 wpid = wait(&status);
674 ATF_REQUIRE(wpid == -1);
675 ATF_REQUIRE(errno == ECHILD);
679 attach_fork_parent(int cpipe[2])
685 /* Double-fork to disassociate from the debugger. */
686 CHILD_REQUIRE((fpid = fork()) != -1);
690 /* Send the pid of the disassociated child to the debugger. */
692 CHILD_REQUIRE(write(cpipe[1], &fpid, sizeof(fpid)) == sizeof(fpid));
694 /* Wait for the debugger to attach. */
695 CHILD_REQUIRE(read(cpipe[1], &fpid, sizeof(fpid)) == 0);
699 * Verify that a new child process is stopped after a followed fork and
700 * that the traced parent sees the exit of the child after the debugger
701 * when both processes remain attached to the debugger. In this test
702 * the parent that forks is not a direct child of the debugger.
704 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached_unrelated_debugger);
705 ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc)
707 pid_t children[2], fpid, wpid;
708 int cpipe[2], status;
710 ATF_REQUIRE(pipe(cpipe) == 0);
711 ATF_REQUIRE((fpid = fork()) != -1);
713 attach_fork_parent(cpipe);
714 follow_fork_parent(false);
717 /* Parent process. */
720 /* Wait for the direct child to exit. */
721 wpid = waitpid(fpid, &status, 0);
722 ATF_REQUIRE(wpid == fpid);
723 ATF_REQUIRE(WIFEXITED(status));
724 ATF_REQUIRE(WEXITSTATUS(status) == 3);
726 /* Read the pid of the fork parent. */
727 ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
728 sizeof(children[0]));
730 /* Attach to the fork parent. */
731 attach_child(children[0]);
733 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
735 /* Continue the fork parent ignoring the SIGSTOP. */
736 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
738 /* Signal the fork parent to continue. */
741 children[1] = handle_fork_events(children[0], NULL);
742 ATF_REQUIRE(children[1] > 0);
744 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
745 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
748 * The fork parent can't exit until the child reports status,
749 * so the child should report its exit first to the debugger.
751 wpid = wait(&status);
752 ATF_REQUIRE(wpid == children[1]);
753 ATF_REQUIRE(WIFEXITED(status));
754 ATF_REQUIRE(WEXITSTATUS(status) == 2);
756 wpid = wait(&status);
757 ATF_REQUIRE(wpid == children[0]);
758 ATF_REQUIRE(WIFEXITED(status));
759 ATF_REQUIRE(WEXITSTATUS(status) == 1);
761 wpid = wait(&status);
762 ATF_REQUIRE(wpid == -1);
763 ATF_REQUIRE(errno == ECHILD);
767 * Verify that a new child process is stopped after a followed fork
768 * and that the traced parent sees the exit of the child when the new
769 * child process is detached after it reports its fork. In this test
770 * the parent that forks is not a direct child of the debugger.
772 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached_unrelated_debugger);
773 ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc)
775 pid_t children[2], fpid, wpid;
776 int cpipe[2], status;
778 ATF_REQUIRE(pipe(cpipe) == 0);
779 ATF_REQUIRE((fpid = fork()) != -1);
781 attach_fork_parent(cpipe);
782 follow_fork_parent(false);
785 /* Parent process. */
788 /* Wait for the direct child to exit. */
789 wpid = waitpid(fpid, &status, 0);
790 ATF_REQUIRE(wpid == fpid);
791 ATF_REQUIRE(WIFEXITED(status));
792 ATF_REQUIRE(WEXITSTATUS(status) == 3);
794 /* Read the pid of the fork parent. */
795 ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
796 sizeof(children[0]));
798 /* Attach to the fork parent. */
799 attach_child(children[0]);
801 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
803 /* Continue the fork parent ignoring the SIGSTOP. */
804 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
806 /* Signal the fork parent to continue. */
809 children[1] = handle_fork_events(children[0], NULL);
810 ATF_REQUIRE(children[1] > 0);
812 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
813 ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
816 * Should not see any status from the child now, only the fork
819 wpid = wait(&status);
820 ATF_REQUIRE(wpid == children[0]);
821 ATF_REQUIRE(WIFEXITED(status));
822 ATF_REQUIRE(WEXITSTATUS(status) == 1);
824 wpid = wait(&status);
825 ATF_REQUIRE(wpid == -1);
826 ATF_REQUIRE(errno == ECHILD);
830 * Verify that a new child process is stopped after a followed fork
831 * and that the traced parent sees the exit of the child when the
832 * traced parent is detached after the fork. In this test the parent
833 * that forks is not a direct child of the debugger.
835 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached_unrelated_debugger);
836 ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc)
838 pid_t children[2], fpid, wpid;
839 int cpipe[2], status;
841 ATF_REQUIRE(pipe(cpipe) == 0);
842 ATF_REQUIRE((fpid = fork()) != -1);
844 attach_fork_parent(cpipe);
845 follow_fork_parent(false);
848 /* Parent process. */
851 /* Wait for the direct child to exit. */
852 wpid = waitpid(fpid, &status, 0);
853 ATF_REQUIRE(wpid == fpid);
854 ATF_REQUIRE(WIFEXITED(status));
855 ATF_REQUIRE(WEXITSTATUS(status) == 3);
857 /* Read the pid of the fork parent. */
858 ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
859 sizeof(children[0]));
861 /* Attach to the fork parent. */
862 attach_child(children[0]);
864 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
866 /* Continue the fork parent ignoring the SIGSTOP. */
867 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
869 /* Signal the fork parent to continue. */
872 children[1] = handle_fork_events(children[0], NULL);
873 ATF_REQUIRE(children[1] > 0);
875 ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
876 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
879 * Should not see any status from the fork parent now, only
882 wpid = wait(&status);
883 ATF_REQUIRE(wpid == children[1]);
884 ATF_REQUIRE(WIFEXITED(status));
885 ATF_REQUIRE(WEXITSTATUS(status) == 2);
887 wpid = wait(&status);
888 ATF_REQUIRE(wpid == -1);
889 ATF_REQUIRE(errno == ECHILD);
893 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
894 * child process created via fork() reports the correct value.
896 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_fork);
897 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_fork, tc)
899 struct ptrace_lwpinfo pl[2];
900 pid_t children[2], fpid, wpid;
903 ATF_REQUIRE((fpid = fork()) != -1);
906 follow_fork_parent(false);
909 /* Parent process. */
912 /* The first wait() should report the stop from SIGSTOP. */
913 wpid = waitpid(children[0], &status, 0);
914 ATF_REQUIRE(wpid == children[0]);
915 ATF_REQUIRE(WIFSTOPPED(status));
916 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
918 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
920 /* Continue the child ignoring the SIGSTOP. */
921 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
923 /* Wait for both halves of the fork event to get reported. */
924 children[1] = handle_fork_events(children[0], pl);
925 ATF_REQUIRE(children[1] > 0);
927 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
928 ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
929 ATF_REQUIRE(pl[0].pl_syscall_code == SYS_fork);
930 ATF_REQUIRE(pl[0].pl_syscall_code == pl[1].pl_syscall_code);
931 ATF_REQUIRE(pl[0].pl_syscall_narg == pl[1].pl_syscall_narg);
933 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
934 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
937 * The child can't exit until the grandchild reports status, so the
938 * grandchild should report its exit first to the debugger.
940 wpid = wait(&status);
941 ATF_REQUIRE(wpid == children[1]);
942 ATF_REQUIRE(WIFEXITED(status));
943 ATF_REQUIRE(WEXITSTATUS(status) == 2);
945 wpid = wait(&status);
946 ATF_REQUIRE(wpid == children[0]);
947 ATF_REQUIRE(WIFEXITED(status));
948 ATF_REQUIRE(WEXITSTATUS(status) == 1);
950 wpid = wait(&status);
951 ATF_REQUIRE(wpid == -1);
952 ATF_REQUIRE(errno == ECHILD);
956 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
957 * child process created via vfork() reports the correct value.
959 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_vfork);
960 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_vfork, tc)
962 struct ptrace_lwpinfo pl[2];
963 pid_t children[2], fpid, wpid;
966 ATF_REQUIRE((fpid = fork()) != -1);
969 follow_fork_parent(true);
972 /* Parent process. */
975 /* The first wait() should report the stop from SIGSTOP. */
976 wpid = waitpid(children[0], &status, 0);
977 ATF_REQUIRE(wpid == children[0]);
978 ATF_REQUIRE(WIFSTOPPED(status));
979 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
981 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
983 /* Continue the child ignoring the SIGSTOP. */
984 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
986 /* Wait for both halves of the fork event to get reported. */
987 children[1] = handle_fork_events(children[0], pl);
988 ATF_REQUIRE(children[1] > 0);
990 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
991 ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
992 ATF_REQUIRE(pl[0].pl_syscall_code == SYS_vfork);
993 ATF_REQUIRE(pl[0].pl_syscall_code == pl[1].pl_syscall_code);
994 ATF_REQUIRE(pl[0].pl_syscall_narg == pl[1].pl_syscall_narg);
996 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
997 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1000 * The child can't exit until the grandchild reports status, so the
1001 * grandchild should report its exit first to the debugger.
1003 wpid = wait(&status);
1004 ATF_REQUIRE(wpid == children[1]);
1005 ATF_REQUIRE(WIFEXITED(status));
1006 ATF_REQUIRE(WEXITSTATUS(status) == 2);
1008 wpid = wait(&status);
1009 ATF_REQUIRE(wpid == children[0]);
1010 ATF_REQUIRE(WIFEXITED(status));
1011 ATF_REQUIRE(WEXITSTATUS(status) == 1);
1013 wpid = wait(&status);
1014 ATF_REQUIRE(wpid == -1);
1015 ATF_REQUIRE(errno == ECHILD);
1019 simple_thread(void *arg __unused)
1026 simple_thread_main(void)
1030 CHILD_REQUIRE(pthread_create(&thread, NULL, simple_thread, NULL) == 0);
1031 CHILD_REQUIRE(pthread_join(thread, NULL) == 0);
1036 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
1037 * thread reports the correct value.
1039 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_thread);
1040 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
1042 struct ptrace_lwpinfo pl;
1047 ATF_REQUIRE((fpid = fork()) != -1);
1050 simple_thread_main();
1053 /* The first wait() should report the stop from SIGSTOP. */
1054 wpid = waitpid(fpid, &status, 0);
1055 ATF_REQUIRE(wpid == fpid);
1056 ATF_REQUIRE(WIFSTOPPED(status));
1057 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1059 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1061 mainlwp = pl.pl_lwpid;
1064 * Continue the child ignoring the SIGSTOP and tracing all
1065 * system call exits.
1067 ATF_REQUIRE(ptrace(PT_TO_SCX, fpid, (caddr_t)1, 0) != -1);
1070 * Wait for the new thread to arrive. pthread_create() might
1071 * invoke any number of system calls. For now we just wait
1072 * for the new thread to arrive and make sure it reports a
1073 * valid system call code. If ptrace grows thread event
1074 * reporting then this test can be made more precise.
1077 wpid = waitpid(fpid, &status, 0);
1078 ATF_REQUIRE(wpid == fpid);
1079 ATF_REQUIRE(WIFSTOPPED(status));
1080 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1082 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1084 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SCX) != 0);
1085 ATF_REQUIRE(pl.pl_syscall_code != 0);
1086 if (pl.pl_lwpid != mainlwp)
1087 /* New thread seen. */
1090 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1093 /* Wait for the child to exit. */
1094 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1096 wpid = waitpid(fpid, &status, 0);
1097 ATF_REQUIRE(wpid == fpid);
1098 if (WIFEXITED(status))
1101 ATF_REQUIRE(WIFSTOPPED(status));
1102 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1103 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1106 ATF_REQUIRE(WEXITSTATUS(status) == 1);
1108 wpid = wait(&status);
1109 ATF_REQUIRE(wpid == -1);
1110 ATF_REQUIRE(errno == ECHILD);
1114 * Verify that the expected LWP events are reported for a child thread.
1116 ATF_TC_WITHOUT_HEAD(ptrace__lwp_events);
1117 ATF_TC_BODY(ptrace__lwp_events, tc)
1119 struct ptrace_lwpinfo pl;
1124 ATF_REQUIRE((fpid = fork()) != -1);
1127 simple_thread_main();
1130 /* The first wait() should report the stop from SIGSTOP. */
1131 wpid = waitpid(fpid, &status, 0);
1132 ATF_REQUIRE(wpid == fpid);
1133 ATF_REQUIRE(WIFSTOPPED(status));
1134 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1136 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1138 lwps[0] = pl.pl_lwpid;
1140 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, wpid, NULL, 1) == 0);
1142 /* Continue the child ignoring the SIGSTOP. */
1143 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1145 /* The first event should be for the child thread's birth. */
1146 wpid = waitpid(fpid, &status, 0);
1147 ATF_REQUIRE(wpid == fpid);
1148 ATF_REQUIRE(WIFSTOPPED(status));
1149 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1151 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1152 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)) ==
1153 (PL_FLAG_BORN | PL_FLAG_SCX));
1154 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
1155 lwps[1] = pl.pl_lwpid;
1157 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1159 /* The next event should be for the child thread's death. */
1160 wpid = waitpid(fpid, &status, 0);
1161 ATF_REQUIRE(wpid == fpid);
1162 ATF_REQUIRE(WIFSTOPPED(status));
1163 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1165 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1166 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_EXITED | PL_FLAG_SCE)) ==
1167 (PL_FLAG_EXITED | PL_FLAG_SCE));
1168 ATF_REQUIRE(pl.pl_lwpid == lwps[1]);
1170 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1172 /* The last event should be for the child process's exit. */
1173 wpid = waitpid(fpid, &status, 0);
1174 ATF_REQUIRE(WIFEXITED(status));
1175 ATF_REQUIRE(WEXITSTATUS(status) == 1);
1177 wpid = wait(&status);
1178 ATF_REQUIRE(wpid == -1);
1179 ATF_REQUIRE(errno == ECHILD);
1183 exec_thread(void *arg __unused)
1186 execl("/usr/bin/true", "true", NULL);
1191 exec_thread_main(void)
1195 CHILD_REQUIRE(pthread_create(&thread, NULL, exec_thread, NULL) == 0);
1202 * Verify that the expected LWP events are reported for a multithreaded
1203 * process that calls execve(2).
1205 ATF_TC_WITHOUT_HEAD(ptrace__lwp_events_exec);
1206 ATF_TC_BODY(ptrace__lwp_events_exec, tc)
1208 struct ptrace_lwpinfo pl;
1213 ATF_REQUIRE((fpid = fork()) != -1);
1219 /* The first wait() should report the stop from SIGSTOP. */
1220 wpid = waitpid(fpid, &status, 0);
1221 ATF_REQUIRE(wpid == fpid);
1222 ATF_REQUIRE(WIFSTOPPED(status));
1223 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1225 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1227 lwps[0] = pl.pl_lwpid;
1229 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, wpid, NULL, 1) == 0);
1231 /* Continue the child ignoring the SIGSTOP. */
1232 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1234 /* The first event should be for the child thread's birth. */
1235 wpid = waitpid(fpid, &status, 0);
1236 ATF_REQUIRE(wpid == fpid);
1237 ATF_REQUIRE(WIFSTOPPED(status));
1238 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1240 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1241 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)) ==
1242 (PL_FLAG_BORN | PL_FLAG_SCX));
1243 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
1244 lwps[1] = pl.pl_lwpid;
1246 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1249 * The next event should be for the main thread's death due to
1250 * single threading from execve().
1252 wpid = waitpid(fpid, &status, 0);
1253 ATF_REQUIRE(wpid == fpid);
1254 ATF_REQUIRE(WIFSTOPPED(status));
1255 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1257 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1258 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_EXITED | PL_FLAG_SCE)) ==
1260 ATF_REQUIRE(pl.pl_lwpid == lwps[0]);
1262 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1264 /* The next event should be for the child process's exec. */
1265 wpid = waitpid(fpid, &status, 0);
1266 ATF_REQUIRE(WIFSTOPPED(status));
1267 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1269 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1270 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_EXEC | PL_FLAG_SCX)) ==
1271 (PL_FLAG_EXEC | PL_FLAG_SCX));
1272 ATF_REQUIRE(pl.pl_lwpid == lwps[1]);
1274 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1276 /* The last event should be for the child process's exit. */
1277 wpid = waitpid(fpid, &status, 0);
1278 ATF_REQUIRE(WIFEXITED(status));
1279 ATF_REQUIRE(WEXITSTATUS(status) == 0);
1281 wpid = wait(&status);
1282 ATF_REQUIRE(wpid == -1);
1283 ATF_REQUIRE(errno == ECHILD);
1287 handler(int sig __unused)
1295 signal(SIGINFO, handler);
1301 * Verify that the expected ptrace event is reported for a signal.
1303 ATF_TC_WITHOUT_HEAD(ptrace__siginfo);
1304 ATF_TC_BODY(ptrace__siginfo, tc)
1306 struct ptrace_lwpinfo pl;
1310 ATF_REQUIRE((fpid = fork()) != -1);
1316 /* The first wait() should report the stop from SIGSTOP. */
1317 wpid = waitpid(fpid, &status, 0);
1318 ATF_REQUIRE(wpid == fpid);
1319 ATF_REQUIRE(WIFSTOPPED(status));
1320 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1322 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1324 /* The next event should be for the SIGINFO. */
1325 wpid = waitpid(fpid, &status, 0);
1326 ATF_REQUIRE(WIFSTOPPED(status));
1327 ATF_REQUIRE(WSTOPSIG(status) == SIGINFO);
1329 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1330 ATF_REQUIRE(pl.pl_event == PL_EVENT_SIGNAL);
1331 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
1332 ATF_REQUIRE(pl.pl_siginfo.si_code == SI_LWP);
1333 ATF_REQUIRE(pl.pl_siginfo.si_pid == wpid);
1335 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1337 /* The last event should be for the child process's exit. */
1338 wpid = waitpid(fpid, &status, 0);
1339 ATF_REQUIRE(WIFEXITED(status));
1340 ATF_REQUIRE(WEXITSTATUS(status) == 0);
1342 wpid = wait(&status);
1343 ATF_REQUIRE(wpid == -1);
1344 ATF_REQUIRE(errno == ECHILD);
1348 * Verify that the expected ptrace events are reported for PTRACE_EXEC.
1350 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_exec_disable);
1351 ATF_TC_BODY(ptrace__ptrace_exec_disable, tc)
1356 ATF_REQUIRE((fpid = fork()) != -1);
1362 /* The first wait() should report the stop from SIGSTOP. */
1363 wpid = waitpid(fpid, &status, 0);
1364 ATF_REQUIRE(wpid == fpid);
1365 ATF_REQUIRE(WIFSTOPPED(status));
1366 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1369 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1370 sizeof(events)) == 0);
1372 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1374 /* Should get one event at exit. */
1375 wpid = waitpid(fpid, &status, 0);
1376 ATF_REQUIRE(WIFEXITED(status));
1377 ATF_REQUIRE(WEXITSTATUS(status) == 0);
1379 wpid = wait(&status);
1380 ATF_REQUIRE(wpid == -1);
1381 ATF_REQUIRE(errno == ECHILD);
1384 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_exec_enable);
1385 ATF_TC_BODY(ptrace__ptrace_exec_enable, tc)
1387 struct ptrace_lwpinfo pl;
1391 ATF_REQUIRE((fpid = fork()) != -1);
1397 /* The first wait() should report the stop from SIGSTOP. */
1398 wpid = waitpid(fpid, &status, 0);
1399 ATF_REQUIRE(wpid == fpid);
1400 ATF_REQUIRE(WIFSTOPPED(status));
1401 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1403 events = PTRACE_EXEC;
1404 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1405 sizeof(events)) == 0);
1407 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1409 /* The next event should be for the child process's exec. */
1410 wpid = waitpid(fpid, &status, 0);
1411 ATF_REQUIRE(WIFSTOPPED(status));
1412 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1414 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1415 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_EXEC | PL_FLAG_SCX)) ==
1416 (PL_FLAG_EXEC | PL_FLAG_SCX));
1418 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1420 /* The last event should be for the child process's exit. */
1421 wpid = waitpid(fpid, &status, 0);
1422 ATF_REQUIRE(WIFEXITED(status));
1423 ATF_REQUIRE(WEXITSTATUS(status) == 0);
1425 wpid = wait(&status);
1426 ATF_REQUIRE(wpid == -1);
1427 ATF_REQUIRE(errno == ECHILD);
1430 ATF_TC_WITHOUT_HEAD(ptrace__event_mask);
1431 ATF_TC_BODY(ptrace__event_mask, tc)
1436 ATF_REQUIRE((fpid = fork()) != -1);
1442 /* The first wait() should report the stop from SIGSTOP. */
1443 wpid = waitpid(fpid, &status, 0);
1444 ATF_REQUIRE(wpid == fpid);
1445 ATF_REQUIRE(WIFSTOPPED(status));
1446 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1448 /* PT_FOLLOW_FORK should toggle the state of PTRACE_FORK. */
1449 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, fpid, NULL, 1) != -1);
1450 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1451 sizeof(events)) == 0);
1452 ATF_REQUIRE(events & PTRACE_FORK);
1453 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, fpid, NULL, 0) != -1);
1454 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1455 sizeof(events)) == 0);
1456 ATF_REQUIRE(!(events & PTRACE_FORK));
1458 /* PT_LWP_EVENTS should toggle the state of PTRACE_LWP. */
1459 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, fpid, NULL, 1) != -1);
1460 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1461 sizeof(events)) == 0);
1462 ATF_REQUIRE(events & PTRACE_LWP);
1463 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, fpid, NULL, 0) != -1);
1464 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1465 sizeof(events)) == 0);
1466 ATF_REQUIRE(!(events & PTRACE_LWP));
1468 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1470 /* Should get one event at exit. */
1471 wpid = waitpid(fpid, &status, 0);
1472 ATF_REQUIRE(WIFEXITED(status));
1473 ATF_REQUIRE(WEXITSTATUS(status) == 0);
1475 wpid = wait(&status);
1476 ATF_REQUIRE(wpid == -1);
1477 ATF_REQUIRE(errno == ECHILD);
1481 * Verify that the expected ptrace events are reported for PTRACE_VFORK.
1483 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_vfork);
1484 ATF_TC_BODY(ptrace__ptrace_vfork, tc)
1486 struct ptrace_lwpinfo pl;
1490 ATF_REQUIRE((fpid = fork()) != -1);
1493 follow_fork_parent(true);
1496 /* The first wait() should report the stop from SIGSTOP. */
1497 wpid = waitpid(fpid, &status, 0);
1498 ATF_REQUIRE(wpid == fpid);
1499 ATF_REQUIRE(WIFSTOPPED(status));
1500 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1502 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1503 sizeof(events)) == 0);
1504 events |= PTRACE_VFORK;
1505 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1506 sizeof(events)) == 0);
1508 /* Continue the child ignoring the SIGSTOP. */
1509 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) != -1);
1511 /* The next event should report the end of the vfork. */
1512 wpid = wait(&status);
1513 ATF_REQUIRE(wpid == fpid);
1514 ATF_REQUIRE(WIFSTOPPED(status));
1515 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1516 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1517 ATF_REQUIRE((pl.pl_flags & PL_FLAG_VFORK_DONE) != 0);
1519 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) != -1);
1521 wpid = wait(&status);
1522 ATF_REQUIRE(wpid == fpid);
1523 ATF_REQUIRE(WIFEXITED(status));
1524 ATF_REQUIRE(WEXITSTATUS(status) == 1);
1526 wpid = wait(&status);
1527 ATF_REQUIRE(wpid == -1);
1528 ATF_REQUIRE(errno == ECHILD);
1531 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_vfork_follow);
1532 ATF_TC_BODY(ptrace__ptrace_vfork_follow, tc)
1534 struct ptrace_lwpinfo pl[2];
1535 pid_t children[2], fpid, wpid;
1538 ATF_REQUIRE((fpid = fork()) != -1);
1541 follow_fork_parent(true);
1544 /* Parent process. */
1547 /* The first wait() should report the stop from SIGSTOP. */
1548 wpid = waitpid(children[0], &status, 0);
1549 ATF_REQUIRE(wpid == children[0]);
1550 ATF_REQUIRE(WIFSTOPPED(status));
1551 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1553 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, children[0], (caddr_t)&events,
1554 sizeof(events)) == 0);
1555 events |= PTRACE_FORK | PTRACE_VFORK;
1556 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, children[0], (caddr_t)&events,
1557 sizeof(events)) == 0);
1559 /* Continue the child ignoring the SIGSTOP. */
1560 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1562 /* Wait for both halves of the fork event to get reported. */
1563 children[1] = handle_fork_events(children[0], pl);
1564 ATF_REQUIRE(children[1] > 0);
1566 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_VFORKED) != 0);
1568 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1569 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1572 * The child can't exit until the grandchild reports status, so the
1573 * grandchild should report its exit first to the debugger.
1575 wpid = waitpid(children[1], &status, 0);
1576 ATF_REQUIRE(wpid == children[1]);
1577 ATF_REQUIRE(WIFEXITED(status));
1578 ATF_REQUIRE(WEXITSTATUS(status) == 2);
1581 * The child should report it's vfork() completion before it
1584 wpid = wait(&status);
1585 ATF_REQUIRE(wpid == children[0]);
1586 ATF_REQUIRE(WIFSTOPPED(status));
1587 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1588 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl[0], sizeof(pl[0])) !=
1590 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_VFORK_DONE) != 0);
1592 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1594 wpid = wait(&status);
1595 ATF_REQUIRE(wpid == children[0]);
1596 ATF_REQUIRE(WIFEXITED(status));
1597 ATF_REQUIRE(WEXITSTATUS(status) == 1);
1599 wpid = wait(&status);
1600 ATF_REQUIRE(wpid == -1);
1601 ATF_REQUIRE(errno == ECHILD);
1605 * XXX: There's nothing inherently platform specific about this test, however a
1606 * userspace visible breakpoint() is a prerequisite.
1608 #if defined(__amd64__) || defined(__i386__) || defined(__sparc64__)
1610 * Verify that no more events are reported after PT_KILL except for the
1611 * process exit when stopped due to a breakpoint trap.
1613 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_breakpoint);
1614 ATF_TC_BODY(ptrace__PT_KILL_breakpoint, tc)
1619 ATF_REQUIRE((fpid = fork()) != -1);
1626 /* The first wait() should report the stop from SIGSTOP. */
1627 wpid = waitpid(fpid, &status, 0);
1628 ATF_REQUIRE(wpid == fpid);
1629 ATF_REQUIRE(WIFSTOPPED(status));
1630 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1632 /* Continue the child ignoring the SIGSTOP. */
1633 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1635 /* The second wait() should report hitting the breakpoint. */
1636 wpid = waitpid(fpid, &status, 0);
1637 ATF_REQUIRE(wpid == fpid);
1638 ATF_REQUIRE(WIFSTOPPED(status));
1639 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1641 /* Kill the child process. */
1642 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
1644 /* The last wait() should report the SIGKILL. */
1645 wpid = waitpid(fpid, &status, 0);
1646 ATF_REQUIRE(wpid == fpid);
1647 ATF_REQUIRE(WIFSIGNALED(status));
1648 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
1650 wpid = wait(&status);
1651 ATF_REQUIRE(wpid == -1);
1652 ATF_REQUIRE(errno == ECHILD);
1654 #endif /* defined(__amd64__) || defined(__i386__) || defined(__sparc64__) */
1657 * Verify that no more events are reported after PT_KILL except for the
1658 * process exit when stopped inside of a system call.
1660 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_system_call);
1661 ATF_TC_BODY(ptrace__PT_KILL_system_call, tc)
1663 struct ptrace_lwpinfo pl;
1667 ATF_REQUIRE((fpid = fork()) != -1);
1674 /* The first wait() should report the stop from SIGSTOP. */
1675 wpid = waitpid(fpid, &status, 0);
1676 ATF_REQUIRE(wpid == fpid);
1677 ATF_REQUIRE(WIFSTOPPED(status));
1678 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1680 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
1681 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
1683 /* The second wait() should report a system call entry for getpid(). */
1684 wpid = waitpid(fpid, &status, 0);
1685 ATF_REQUIRE(wpid == fpid);
1686 ATF_REQUIRE(WIFSTOPPED(status));
1687 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1689 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1690 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
1692 /* Kill the child process. */
1693 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
1695 /* The last wait() should report the SIGKILL. */
1696 wpid = waitpid(fpid, &status, 0);
1697 ATF_REQUIRE(wpid == fpid);
1698 ATF_REQUIRE(WIFSIGNALED(status));
1699 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
1701 wpid = wait(&status);
1702 ATF_REQUIRE(wpid == -1);
1703 ATF_REQUIRE(errno == ECHILD);
1707 * Verify that no more events are reported after PT_KILL except for the
1708 * process exit when killing a multithreaded process.
1710 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_threads);
1711 ATF_TC_BODY(ptrace__PT_KILL_threads, tc)
1713 struct ptrace_lwpinfo pl;
1718 ATF_REQUIRE((fpid = fork()) != -1);
1721 simple_thread_main();
1724 /* The first wait() should report the stop from SIGSTOP. */
1725 wpid = waitpid(fpid, &status, 0);
1726 ATF_REQUIRE(wpid == fpid);
1727 ATF_REQUIRE(WIFSTOPPED(status));
1728 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1730 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1732 main_lwp = pl.pl_lwpid;
1734 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, wpid, NULL, 1) == 0);
1736 /* Continue the child ignoring the SIGSTOP. */
1737 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1739 /* The first event should be for the child thread's birth. */
1740 wpid = waitpid(fpid, &status, 0);
1741 ATF_REQUIRE(wpid == fpid);
1742 ATF_REQUIRE(WIFSTOPPED(status));
1743 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1745 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1746 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)) ==
1747 (PL_FLAG_BORN | PL_FLAG_SCX));
1748 ATF_REQUIRE(pl.pl_lwpid != main_lwp);
1750 /* Kill the child process. */
1751 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
1753 /* The last wait() should report the SIGKILL. */
1754 wpid = waitpid(fpid, &status, 0);
1755 ATF_REQUIRE(wpid == fpid);
1756 ATF_REQUIRE(WIFSIGNALED(status));
1757 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
1759 wpid = wait(&status);
1760 ATF_REQUIRE(wpid == -1);
1761 ATF_REQUIRE(errno == ECHILD);
1765 mask_usr1_thread(void *arg)
1767 pthread_barrier_t *pbarrier;
1770 pbarrier = (pthread_barrier_t*)arg;
1772 sigemptyset(&sigmask);
1773 sigaddset(&sigmask, SIGUSR1);
1774 CHILD_REQUIRE(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == 0);
1776 /* Sync up with other thread after sigmask updated. */
1777 pthread_barrier_wait(pbarrier);
1786 * Verify that the SIGKILL from PT_KILL takes priority over other signals
1787 * and prevents spurious stops due to those other signals.
1789 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_competing_signal);
1790 ATF_TC_BODY(ptrace__PT_KILL_competing_signal, tc)
1796 pthread_barrier_t barrier;
1797 struct sched_param sched_param;
1799 ATF_REQUIRE((fpid = fork()) != -1);
1801 /* Bind to one CPU so only one thread at a time will run. */
1803 CPU_SET(0, &setmask);
1805 CHILD_REQUIRE(cpuset(&setid) == 0);
1806 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
1807 CPU_WHICH_CPUSET, setid, sizeof(setmask), &setmask) == 0);
1809 CHILD_REQUIRE(pthread_barrier_init(&barrier, NULL, 2) == 0);
1811 CHILD_REQUIRE(pthread_create(&t, NULL, mask_usr1_thread,
1812 (void*)&barrier) == 0);
1815 * Give the main thread higher priority. The test always
1816 * assumes that, if both threads are able to run, the main
1817 * thread runs first.
1819 sched_param.sched_priority =
1820 (sched_get_priority_max(SCHED_FIFO) +
1821 sched_get_priority_min(SCHED_FIFO)) / 2;
1822 CHILD_REQUIRE(pthread_setschedparam(pthread_self(),
1823 SCHED_FIFO, &sched_param) == 0);
1824 sched_param.sched_priority -= RQ_PPQ;
1825 CHILD_REQUIRE(pthread_setschedparam(t, SCHED_FIFO,
1826 &sched_param) == 0);
1829 sigemptyset(&sigmask);
1830 sigaddset(&sigmask, SIGUSR2);
1831 CHILD_REQUIRE(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == 0);
1833 /* Sync up with other thread after sigmask updated. */
1834 pthread_barrier_wait(&barrier);
1844 /* The first wait() should report the stop from SIGSTOP. */
1845 wpid = waitpid(fpid, &status, 0);
1846 ATF_REQUIRE(wpid == fpid);
1847 ATF_REQUIRE(WIFSTOPPED(status));
1848 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1850 /* Continue the child ignoring the SIGSTOP. */
1851 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
1853 /* Send a signal that only the second thread can handle. */
1854 ATF_REQUIRE(kill(fpid, SIGUSR2) == 0);
1856 /* The second wait() should report the SIGUSR2. */
1857 wpid = waitpid(fpid, &status, 0);
1858 ATF_REQUIRE(wpid == fpid);
1859 ATF_REQUIRE(WIFSTOPPED(status));
1860 ATF_REQUIRE(WSTOPSIG(status) == SIGUSR2);
1862 /* Send a signal that only the first thread can handle. */
1863 ATF_REQUIRE(kill(fpid, SIGUSR1) == 0);
1865 /* Replace the SIGUSR2 with a kill. */
1866 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
1868 /* The last wait() should report the SIGKILL (not the SIGUSR signal). */
1869 wpid = waitpid(fpid, &status, 0);
1870 ATF_REQUIRE(wpid == fpid);
1871 ATF_REQUIRE(WIFSIGNALED(status));
1872 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
1874 wpid = wait(&status);
1875 ATF_REQUIRE(wpid == -1);
1876 ATF_REQUIRE(errno == ECHILD);
1880 * Verify that the SIGKILL from PT_KILL takes priority over other stop events
1881 * and prevents spurious stops caused by those events.
1883 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_competing_stop);
1884 ATF_TC_BODY(ptrace__PT_KILL_competing_stop, tc)
1890 pthread_barrier_t barrier;
1892 struct ptrace_lwpinfo pl;
1893 struct sched_param sched_param;
1895 ATF_REQUIRE((fpid = fork()) != -1);
1899 /* Bind to one CPU so only one thread at a time will run. */
1901 CPU_SET(0, &setmask);
1903 CHILD_REQUIRE(cpuset(&setid) == 0);
1904 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
1905 CPU_WHICH_CPUSET, setid, sizeof(setmask), &setmask) == 0);
1907 CHILD_REQUIRE(pthread_barrier_init(&barrier, NULL, 2) == 0);
1909 CHILD_REQUIRE(pthread_create(&t, NULL, mask_usr1_thread,
1910 (void*)&barrier) == 0);
1913 * Give the main thread higher priority. The test always
1914 * assumes that, if both threads are able to run, the main
1915 * thread runs first.
1917 sched_param.sched_priority =
1918 (sched_get_priority_max(SCHED_FIFO) +
1919 sched_get_priority_min(SCHED_FIFO)) / 2;
1920 CHILD_REQUIRE(pthread_setschedparam(pthread_self(),
1921 SCHED_FIFO, &sched_param) == 0);
1922 sched_param.sched_priority -= RQ_PPQ;
1923 CHILD_REQUIRE(pthread_setschedparam(t, SCHED_FIFO,
1924 &sched_param) == 0);
1927 sigemptyset(&sigmask);
1928 sigaddset(&sigmask, SIGUSR2);
1929 CHILD_REQUIRE(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == 0);
1931 /* Sync up with other thread after sigmask updated. */
1932 pthread_barrier_wait(&barrier);
1934 /* Sync up with the test before doing the getpid(). */
1941 /* The first wait() should report the stop from SIGSTOP. */
1942 wpid = waitpid(fpid, &status, 0);
1943 ATF_REQUIRE(wpid == fpid);
1944 ATF_REQUIRE(WIFSTOPPED(status));
1945 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1947 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1948 main_lwp = pl.pl_lwpid;
1950 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
1951 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
1954 * Continue until child is done with setup, which is indicated with
1955 * SIGSTOP. Ignore system calls in the meantime.
1958 wpid = waitpid(fpid, &status, 0);
1959 ATF_REQUIRE(wpid == fpid);
1960 ATF_REQUIRE(WIFSTOPPED(status));
1961 if (WSTOPSIG(status) == SIGTRAP) {
1962 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1964 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
1966 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
1969 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
1972 /* Proceed, allowing main thread to hit syscall entry for getpid(). */
1973 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
1975 wpid = waitpid(fpid, &status, 0);
1976 ATF_REQUIRE(wpid == fpid);
1977 ATF_REQUIRE(WIFSTOPPED(status));
1978 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1980 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1982 ATF_REQUIRE(pl.pl_lwpid == main_lwp);
1983 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
1984 /* Prevent the main thread from hitting its syscall exit for now. */
1985 ATF_REQUIRE(ptrace(PT_SUSPEND, main_lwp, 0, 0) == 0);
1988 * Proceed, allowing second thread to hit syscall exit for
1989 * pthread_barrier_wait().
1991 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
1993 wpid = waitpid(fpid, &status, 0);
1994 ATF_REQUIRE(wpid == fpid);
1995 ATF_REQUIRE(WIFSTOPPED(status));
1996 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
1998 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
2000 ATF_REQUIRE(pl.pl_lwpid != main_lwp);
2001 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2003 /* Send a signal that only the second thread can handle. */
2004 ATF_REQUIRE(kill(fpid, SIGUSR2) == 0);
2006 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
2008 /* The next wait() should report the SIGUSR2. */
2009 wpid = waitpid(fpid, &status, 0);
2010 ATF_REQUIRE(wpid == fpid);
2011 ATF_REQUIRE(WIFSTOPPED(status));
2012 ATF_REQUIRE(WSTOPSIG(status) == SIGUSR2);
2014 /* Allow the main thread to try to finish its system call. */
2015 ATF_REQUIRE(ptrace(PT_RESUME, main_lwp, 0, 0) == 0);
2018 * At this point, the main thread is in the middle of a system call and
2019 * has been resumed. The second thread has taken a SIGUSR2 which will
2020 * be replaced with a SIGKILL below. The main thread will get to run
2021 * first. It should notice the kill request (even though the signal
2022 * replacement occurred in the other thread) and exit accordingly. It
2023 * should not stop for the system call exit event.
2026 /* Replace the SIGUSR2 with a kill. */
2027 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
2029 /* The last wait() should report the SIGKILL (not a syscall exit). */
2030 wpid = waitpid(fpid, &status, 0);
2031 ATF_REQUIRE(wpid == fpid);
2032 ATF_REQUIRE(WIFSIGNALED(status));
2033 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
2035 wpid = wait(&status);
2036 ATF_REQUIRE(wpid == -1);
2037 ATF_REQUIRE(errno == ECHILD);
2041 sigusr1_handler(int sig)
2044 CHILD_REQUIRE(sig == SIGUSR1);
2049 * Verify that even if the signal queue is full for a child process,
2050 * a PT_KILL will kill the process.
2052 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_with_signal_full_sigqueue);
2053 ATF_TC_BODY(ptrace__PT_KILL_with_signal_full_sigqueue, tc)
2057 int max_pending_per_proc;
2061 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2063 ATF_REQUIRE((fpid = fork()) != -1);
2069 /* The first wait() should report the stop from SIGSTOP. */
2070 wpid = waitpid(fpid, &status, 0);
2071 ATF_REQUIRE(wpid == fpid);
2072 ATF_REQUIRE(WIFSTOPPED(status));
2073 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2075 len = sizeof(max_pending_per_proc);
2076 ATF_REQUIRE(sysctlbyname("kern.sigqueue.max_pending_per_proc",
2077 &max_pending_per_proc, &len, NULL, 0) == 0);
2079 /* Fill the signal queue. */
2080 for (i = 0; i < max_pending_per_proc; ++i)
2081 ATF_REQUIRE(kill(fpid, SIGUSR1) == 0);
2083 /* Kill the child process. */
2084 ATF_REQUIRE(ptrace(PT_KILL, fpid, 0, 0) == 0);
2086 /* The last wait() should report the SIGKILL. */
2087 wpid = waitpid(fpid, &status, 0);
2088 ATF_REQUIRE(wpid == fpid);
2089 ATF_REQUIRE(WIFSIGNALED(status));
2090 ATF_REQUIRE(WTERMSIG(status) == SIGKILL);
2092 wpid = wait(&status);
2093 ATF_REQUIRE(wpid == -1);
2094 ATF_REQUIRE(errno == ECHILD);
2098 * Verify that when stopped at a system call entry, a signal can be
2099 * requested with PT_CONTINUE which will be delivered once the system
2102 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_system_call_entry);
2103 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_system_call_entry, tc)
2105 struct ptrace_lwpinfo pl;
2109 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2111 ATF_REQUIRE((fpid = fork()) != -1);
2118 /* The first wait() should report the stop from SIGSTOP. */
2119 wpid = waitpid(fpid, &status, 0);
2120 ATF_REQUIRE(wpid == fpid);
2121 ATF_REQUIRE(WIFSTOPPED(status));
2122 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2124 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2125 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
2127 /* The second wait() should report a system call entry for getpid(). */
2128 wpid = waitpid(fpid, &status, 0);
2129 ATF_REQUIRE(wpid == fpid);
2130 ATF_REQUIRE(WIFSTOPPED(status));
2131 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2133 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2134 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2136 /* Continue the child process with a signal. */
2137 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2141 * The last wait() should report exit 2, i.e., a normal _exit
2142 * from the signal handler. In the meantime, catch and proceed
2143 * past any syscall stops.
2145 wpid = waitpid(fpid, &status, 0);
2146 ATF_REQUIRE(wpid == fpid);
2147 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2148 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2149 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2150 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2152 ATF_REQUIRE(WIFEXITED(status));
2153 ATF_REQUIRE(WEXITSTATUS(status) == 2);
2158 wpid = wait(&status);
2159 ATF_REQUIRE(wpid == -1);
2160 ATF_REQUIRE(errno == ECHILD);
2164 sigusr1_counting_handler(int sig)
2166 static int counter = 0;
2168 CHILD_REQUIRE(sig == SIGUSR1);
2175 * Verify that, when continuing from a stop at system call entry and exit,
2176 * a signal can be requested from both stops, and both will be delivered when
2177 * the system call is complete.
2179 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit);
2180 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit, tc)
2182 struct ptrace_lwpinfo pl;
2186 ATF_REQUIRE(signal(SIGUSR1, sigusr1_counting_handler) != SIG_ERR);
2188 ATF_REQUIRE((fpid = fork()) != -1);
2195 /* The first wait() should report the stop from SIGSTOP. */
2196 wpid = waitpid(fpid, &status, 0);
2197 ATF_REQUIRE(wpid == fpid);
2198 ATF_REQUIRE(WIFSTOPPED(status));
2199 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2201 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2202 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
2204 /* The second wait() should report a system call entry for getpid(). */
2205 wpid = waitpid(fpid, &status, 0);
2206 ATF_REQUIRE(wpid == fpid);
2207 ATF_REQUIRE(WIFSTOPPED(status));
2208 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2210 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2211 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2213 /* Continue the child process with a signal. */
2214 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2216 /* The third wait() should report a system call exit for getpid(). */
2217 wpid = waitpid(fpid, &status, 0);
2218 ATF_REQUIRE(wpid == fpid);
2219 ATF_REQUIRE(WIFSTOPPED(status));
2220 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2222 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2223 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2225 /* Continue the child process with a signal. */
2226 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2230 * The last wait() should report exit 2, i.e., a normal _exit
2231 * from the signal handler. In the meantime, catch and proceed
2232 * past any syscall stops.
2234 wpid = waitpid(fpid, &status, 0);
2235 ATF_REQUIRE(wpid == fpid);
2236 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2237 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2238 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2239 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2241 ATF_REQUIRE(WIFEXITED(status));
2242 ATF_REQUIRE(WEXITSTATUS(status) == 2);
2247 wpid = wait(&status);
2248 ATF_REQUIRE(wpid == -1);
2249 ATF_REQUIRE(errno == ECHILD);
2253 * Verify that even if the signal queue is full for a child process,
2254 * a PT_CONTINUE with a signal will not result in loss of that signal.
2256 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_full_sigqueue);
2257 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_full_sigqueue, tc)
2261 int max_pending_per_proc;
2265 ATF_REQUIRE(signal(SIGUSR2, handler) != SIG_ERR);
2266 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2268 ATF_REQUIRE((fpid = fork()) != -1);
2274 /* The first wait() should report the stop from SIGSTOP. */
2275 wpid = waitpid(fpid, &status, 0);
2276 ATF_REQUIRE(wpid == fpid);
2277 ATF_REQUIRE(WIFSTOPPED(status));
2278 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2280 len = sizeof(max_pending_per_proc);
2281 ATF_REQUIRE(sysctlbyname("kern.sigqueue.max_pending_per_proc",
2282 &max_pending_per_proc, &len, NULL, 0) == 0);
2284 /* Fill the signal queue. */
2285 for (i = 0; i < max_pending_per_proc; ++i)
2286 ATF_REQUIRE(kill(fpid, SIGUSR2) == 0);
2288 /* Continue with signal. */
2289 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2292 wpid = waitpid(fpid, &status, 0);
2293 ATF_REQUIRE(wpid == fpid);
2294 if (WIFSTOPPED(status)) {
2295 ATF_REQUIRE(WSTOPSIG(status) == SIGUSR2);
2296 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2299 * The last wait() should report normal _exit from the
2302 ATF_REQUIRE(WIFEXITED(status));
2303 ATF_REQUIRE(WEXITSTATUS(status) == 2);
2308 wpid = wait(&status);
2309 ATF_REQUIRE(wpid == -1);
2310 ATF_REQUIRE(errno == ECHILD);
2314 * Verify that, after stopping due to a signal, that signal can be
2315 * replaced with another signal.
2317 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_change_sig);
2318 ATF_TC_BODY(ptrace__PT_CONTINUE_change_sig, tc)
2320 struct ptrace_lwpinfo pl;
2324 ATF_REQUIRE((fpid = fork()) != -1);
2331 /* The first wait() should report the stop from SIGSTOP. */
2332 wpid = waitpid(fpid, &status, 0);
2333 ATF_REQUIRE(wpid == fpid);
2334 ATF_REQUIRE(WIFSTOPPED(status));
2335 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2337 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2339 /* Send a signal without ptrace. */
2340 ATF_REQUIRE(kill(fpid, SIGINT) == 0);
2342 /* The second wait() should report a SIGINT was received. */
2343 wpid = waitpid(fpid, &status, 0);
2344 ATF_REQUIRE(wpid == fpid);
2345 ATF_REQUIRE(WIFSTOPPED(status));
2346 ATF_REQUIRE(WSTOPSIG(status) == SIGINT);
2348 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2349 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
2350 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGINT);
2352 /* Continue the child process with a different signal. */
2353 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGTERM) == 0);
2356 * The last wait() should report having died due to the new
2359 wpid = waitpid(fpid, &status, 0);
2360 ATF_REQUIRE(wpid == fpid);
2361 ATF_REQUIRE(WIFSIGNALED(status));
2362 ATF_REQUIRE(WTERMSIG(status) == SIGTERM);
2364 wpid = wait(&status);
2365 ATF_REQUIRE(wpid == -1);
2366 ATF_REQUIRE(errno == ECHILD);
2370 * Verify that a signal can be passed through to the child even when there
2371 * was no true signal originally. Such cases arise when a SIGTRAP is
2372 * invented for e.g, system call stops.
2374 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_sigtrap_system_call_entry);
2375 ATF_TC_BODY(ptrace__PT_CONTINUE_with_sigtrap_system_call_entry, tc)
2377 struct ptrace_lwpinfo pl;
2381 ATF_REQUIRE((fpid = fork()) != -1);
2388 /* The first wait() should report the stop from SIGSTOP. */
2389 wpid = waitpid(fpid, &status, 0);
2390 ATF_REQUIRE(wpid == fpid);
2391 ATF_REQUIRE(WIFSTOPPED(status));
2392 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2394 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2395 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
2397 /* The second wait() should report a system call entry for getpid(). */
2398 wpid = waitpid(fpid, &status, 0);
2399 ATF_REQUIRE(wpid == fpid);
2400 ATF_REQUIRE(WIFSTOPPED(status));
2401 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2403 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2404 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2406 /* Continue the child process with a SIGTRAP. */
2407 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGTRAP) == 0);
2411 * The last wait() should report exit due to SIGTRAP. In the
2412 * meantime, catch and proceed past any syscall stops.
2414 wpid = waitpid(fpid, &status, 0);
2415 ATF_REQUIRE(wpid == fpid);
2416 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2417 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2418 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2419 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2421 ATF_REQUIRE(WIFSIGNALED(status));
2422 ATF_REQUIRE(WTERMSIG(status) == SIGTRAP);
2427 wpid = wait(&status);
2428 ATF_REQUIRE(wpid == -1);
2429 ATF_REQUIRE(errno == ECHILD);
2434 * A mixed bag PT_CONTINUE with signal test.
2436 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_mix);
2437 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_mix, tc)
2439 struct ptrace_lwpinfo pl;
2443 ATF_REQUIRE(signal(SIGUSR1, sigusr1_counting_handler) != SIG_ERR);
2445 ATF_REQUIRE((fpid = fork()) != -1);
2452 /* The first wait() should report the stop from SIGSTOP. */
2453 wpid = waitpid(fpid, &status, 0);
2454 ATF_REQUIRE(wpid == fpid);
2455 ATF_REQUIRE(WIFSTOPPED(status));
2456 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2458 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2459 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
2461 /* The second wait() should report a system call entry for getpid(). */
2462 wpid = waitpid(fpid, &status, 0);
2463 ATF_REQUIRE(wpid == fpid);
2464 ATF_REQUIRE(WIFSTOPPED(status));
2465 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2467 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2468 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2470 /* Continue with the first SIGUSR1. */
2471 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2473 /* The next wait() should report a system call exit for getpid(). */
2474 wpid = waitpid(fpid, &status, 0);
2475 ATF_REQUIRE(wpid == fpid);
2476 ATF_REQUIRE(WIFSTOPPED(status));
2477 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
2479 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2480 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2482 /* Send an ABRT without ptrace. */
2483 ATF_REQUIRE(kill(fpid, SIGABRT) == 0);
2485 /* Continue normally. */
2486 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2488 /* The next wait() should report the SIGABRT. */
2489 wpid = waitpid(fpid, &status, 0);
2490 ATF_REQUIRE(wpid == fpid);
2491 ATF_REQUIRE(WIFSTOPPED(status));
2492 ATF_REQUIRE(WSTOPSIG(status) == SIGABRT);
2494 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2495 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
2496 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGABRT);
2498 /* Continue, replacing the SIGABRT with another SIGUSR1. */
2499 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2503 * The last wait() should report exit 2, i.e., a normal _exit
2504 * from the signal handler. In the meantime, catch and proceed
2505 * past any syscall stops.
2507 wpid = waitpid(fpid, &status, 0);
2508 ATF_REQUIRE(wpid == fpid);
2509 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2510 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2511 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2512 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2514 ATF_REQUIRE(WIFEXITED(status));
2515 ATF_REQUIRE(WEXITSTATUS(status) == 2);
2520 wpid = wait(&status);
2521 ATF_REQUIRE(wpid == -1);
2522 ATF_REQUIRE(errno == ECHILD);
2527 * Verify a signal delivered by ptrace is noticed by kevent(2).
2529 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_kqueue);
2530 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_kqueue, tc)
2533 int status, kq, nevents;
2536 ATF_REQUIRE(signal(SIGUSR1, SIG_IGN) != SIG_ERR);
2538 ATF_REQUIRE((fpid = fork()) != -1);
2540 CHILD_REQUIRE((kq = kqueue()) > 0);
2541 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
2542 CHILD_REQUIRE(kevent(kq, &kev, 1, NULL, 0, NULL) == 0);
2547 nevents = kevent(kq, NULL, 0, &kev, 1, NULL);
2548 if (nevents == -1 && errno == EINTR)
2550 CHILD_REQUIRE(nevents > 0);
2551 CHILD_REQUIRE(kev.filter == EVFILT_SIGNAL);
2552 CHILD_REQUIRE(kev.ident == SIGUSR1);
2559 /* The first wait() should report the stop from SIGSTOP. */
2560 wpid = waitpid(fpid, &status, 0);
2561 ATF_REQUIRE(wpid == fpid);
2562 ATF_REQUIRE(WIFSTOPPED(status));
2563 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2565 /* Continue with the SIGUSR1. */
2566 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2569 * The last wait() should report normal exit with code 1.
2571 wpid = waitpid(fpid, &status, 0);
2572 ATF_REQUIRE(wpid == fpid);
2573 ATF_REQUIRE(WIFEXITED(status));
2574 ATF_REQUIRE(WEXITSTATUS(status) == 1);
2576 wpid = wait(&status);
2577 ATF_REQUIRE(wpid == -1);
2578 ATF_REQUIRE(errno == ECHILD);
2581 static sem_t sigusr1_sem;
2584 sigusr1_sempost_handler(int sig __unused)
2587 CHILD_REQUIRE(sem_post(&sigusr1_sem) == 0);
2591 signal_thread(void *arg)
2596 pthread_barrier_t *pbarrier = (pthread_barrier_t*)arg;
2598 /* Wait for this thread to receive a SIGUSR1. */
2600 err = sem_wait(&sigusr1_sem);
2601 CHILD_REQUIRE(err == 0 || errno == EINTR);
2602 } while (err != 0 && errno == EINTR);
2604 /* Free our companion thread from the barrier. */
2605 pthread_barrier_wait(pbarrier);
2608 * Swap ignore duties; the next SIGUSR1 should go to the
2611 CHILD_REQUIRE(sigemptyset(&sigmask) == 0);
2612 CHILD_REQUIRE(sigaddset(&sigmask, SIGUSR1) == 0);
2613 CHILD_REQUIRE(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == 0);
2615 /* Sync up threads after swapping signal masks. */
2616 pthread_barrier_wait(pbarrier);
2618 /* Wait until our companion has received its SIGUSR1. */
2619 pthread_barrier_wait(pbarrier);
2625 * Verify that if ptrace stops due to a signal but continues with
2626 * a different signal that the new signal is routed to a thread
2627 * that can accept it, and that that thread is awakened by the signal
2628 * in a timely manner.
2630 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_thread_sigmask);
2631 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_thread_sigmask, tc)
2637 pthread_barrier_t barrier;
2639 ATF_REQUIRE(pthread_barrier_init(&barrier, NULL, 2) == 0);
2640 ATF_REQUIRE(sem_init(&sigusr1_sem, 0, 0) == 0);
2641 ATF_REQUIRE(signal(SIGUSR1, sigusr1_sempost_handler) != SIG_ERR);
2643 ATF_REQUIRE((fpid = fork()) != -1);
2645 CHILD_REQUIRE(pthread_create(&t, NULL, signal_thread, (void*)&barrier) == 0);
2647 /* The other thread should receive the first SIGUSR1. */
2648 CHILD_REQUIRE(sigemptyset(&sigmask) == 0);
2649 CHILD_REQUIRE(sigaddset(&sigmask, SIGUSR1) == 0);
2650 CHILD_REQUIRE(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == 0);
2654 /* Wait until other thread has received its SIGUSR1. */
2655 pthread_barrier_wait(&barrier);
2658 * Swap ignore duties; the next SIGUSR1 should go to this
2661 CHILD_REQUIRE(pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL) == 0);
2663 /* Sync up threads after swapping signal masks. */
2664 pthread_barrier_wait(&barrier);
2667 * Sync up with test code; we're ready for the next SIGUSR1
2672 /* Wait for this thread to receive a SIGUSR1. */
2674 err = sem_wait(&sigusr1_sem);
2675 CHILD_REQUIRE(err == 0 || errno == EINTR);
2676 } while (err != 0 && errno == EINTR);
2678 /* Free the other thread from the barrier. */
2679 pthread_barrier_wait(&barrier);
2681 CHILD_REQUIRE(pthread_join(t, NULL) == 0);
2686 /* The first wait() should report the stop from SIGSTOP. */
2687 wpid = waitpid(fpid, &status, 0);
2688 ATF_REQUIRE(wpid == fpid);
2689 ATF_REQUIRE(WIFSTOPPED(status));
2690 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2692 /* Continue the child ignoring the SIGSTOP. */
2693 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2696 * Send a signal without ptrace that either thread will accept (USR2,
2699 ATF_REQUIRE(kill(fpid, SIGUSR2) == 0);
2701 /* The second wait() should report a SIGUSR2 was received. */
2702 wpid = waitpid(fpid, &status, 0);
2703 ATF_REQUIRE(wpid == fpid);
2704 ATF_REQUIRE(WIFSTOPPED(status));
2705 ATF_REQUIRE(WSTOPSIG(status) == SIGUSR2);
2707 /* Continue the child, changing the signal to USR1. */
2708 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2710 /* The next wait() should report the stop from SIGSTOP. */
2711 wpid = waitpid(fpid, &status, 0);
2712 ATF_REQUIRE(wpid == fpid);
2713 ATF_REQUIRE(WIFSTOPPED(status));
2714 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2716 /* Continue the child ignoring the SIGSTOP. */
2717 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2719 ATF_REQUIRE(kill(fpid, SIGUSR2) == 0);
2721 /* The next wait() should report a SIGUSR2 was received. */
2722 wpid = waitpid(fpid, &status, 0);
2723 ATF_REQUIRE(wpid == fpid);
2724 ATF_REQUIRE(WIFSTOPPED(status));
2725 ATF_REQUIRE(WSTOPSIG(status) == SIGUSR2);
2727 /* Continue the child, changing the signal to USR1. */
2728 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1) == 0);
2730 /* The last wait() should report normal exit with code 1. */
2731 wpid = waitpid(fpid, &status, 0);
2732 ATF_REQUIRE(wpid == fpid);
2733 ATF_REQUIRE(WIFEXITED(status));
2734 ATF_REQUIRE(WEXITSTATUS(status) == 1);
2736 wpid = wait(&status);
2737 ATF_REQUIRE(wpid == -1);
2738 ATF_REQUIRE(errno == ECHILD);
2742 raise_sigstop_thread(void *arg __unused)
2750 sleep_thread(void *arg __unused)
2758 terminate_with_pending_sigstop(bool sigstop_from_main_thread)
2767 * Become the reaper for this process tree. We need to be able to check
2768 * that both child and grandchild have died.
2770 ATF_REQUIRE(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL) == 0);
2773 ATF_REQUIRE(fpid >= 0);
2776 CHILD_REQUIRE(fpid >= 0);
2780 /* Pin to CPU 0 to serialize thread execution. */
2782 CPU_SET(0, &setmask);
2783 CHILD_REQUIRE(cpuset(&setid) == 0);
2784 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
2785 CPU_WHICH_CPUSET, setid,
2786 sizeof(setmask), &setmask) == 0);
2788 if (sigstop_from_main_thread) {
2790 * We expect the SIGKILL sent when our parent
2791 * dies to be delivered to the new thread.
2792 * Raise the SIGSTOP in this thread so the
2795 CHILD_REQUIRE(pthread_create(&t, NULL,
2796 sleep_thread, NULL) == 0);
2800 * We expect the SIGKILL to be delivered to
2801 * this thread. After creating the new thread,
2802 * just get off the CPU so the other thread can
2803 * raise the SIGSTOP.
2805 CHILD_REQUIRE(pthread_create(&t, NULL,
2806 raise_sigstop_thread, NULL) == 0);
2812 /* First stop is trace_me() immediately after fork. */
2813 wpid = waitpid(fpid, &status, 0);
2814 CHILD_REQUIRE(wpid == fpid);
2815 CHILD_REQUIRE(WIFSTOPPED(status));
2816 CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2818 CHILD_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2820 /* Second stop is from the raise(SIGSTOP). */
2821 wpid = waitpid(fpid, &status, 0);
2822 CHILD_REQUIRE(wpid == fpid);
2823 CHILD_REQUIRE(WIFSTOPPED(status));
2824 CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2827 * Terminate tracing process without detaching. Our child
2834 * We should get a normal exit from our immediate child and a SIGKILL
2835 * exit from our grandchild. The latter case is the interesting one.
2836 * Our grandchild should not have stopped due to the SIGSTOP that was
2837 * left dangling when its parent died.
2839 for (i = 0; i < 2; ++i) {
2840 wpid = wait(&status);
2842 ATF_REQUIRE(WIFEXITED(status) &&
2843 WEXITSTATUS(status) == 0);
2845 ATF_REQUIRE(WIFSIGNALED(status) &&
2846 WTERMSIG(status) == SIGKILL);
2851 * These two tests ensure that if the tracing process exits without detaching
2852 * just after the child received a SIGSTOP, the child is cleanly killed and
2853 * doesn't go to sleep due to the SIGSTOP. The parent's death will send a
2854 * SIGKILL to the child. If the SIGKILL and the SIGSTOP are handled by
2855 * different threads, the SIGKILL must win. There are two variants of this
2856 * test, designed to catch the case where the SIGKILL is delivered to the
2857 * younger thread (the first test) and the case where the SIGKILL is delivered
2858 * to the older thread (the second test). This behavior has changed in the
2859 * past, so make no assumption.
2861 ATF_TC_WITHOUT_HEAD(ptrace__parent_terminate_with_pending_sigstop1);
2862 ATF_TC_BODY(ptrace__parent_terminate_with_pending_sigstop1, tc)
2865 terminate_with_pending_sigstop(true);
2867 ATF_TC_WITHOUT_HEAD(ptrace__parent_terminate_with_pending_sigstop2);
2868 ATF_TC_BODY(ptrace__parent_terminate_with_pending_sigstop2, tc)
2871 terminate_with_pending_sigstop(false);
2875 * Verify that after ptrace() discards a SIGKILL signal, the event mask
2878 ATF_TC_WITHOUT_HEAD(ptrace__event_mask_sigkill_discard);
2879 ATF_TC_BODY(ptrace__event_mask_sigkill_discard, tc)
2881 struct ptrace_lwpinfo pl;
2883 int status, event_mask, new_event_mask;
2885 ATF_REQUIRE((fpid = fork()) != -1);
2892 /* The first wait() should report the stop from trace_me(). */
2893 wpid = waitpid(fpid, &status, 0);
2894 ATF_REQUIRE(wpid == fpid);
2895 ATF_REQUIRE(WIFSTOPPED(status));
2896 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2898 /* Set several unobtrusive event bits. */
2899 event_mask = PTRACE_EXEC | PTRACE_FORK | PTRACE_LWP;
2900 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, wpid, (caddr_t)&event_mask,
2901 sizeof(event_mask)) == 0);
2903 /* Send a SIGKILL without using ptrace. */
2904 ATF_REQUIRE(kill(fpid, SIGKILL) == 0);
2906 /* Continue the child ignoring the SIGSTOP. */
2907 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2909 /* The next stop should be due to the SIGKILL. */
2910 wpid = waitpid(fpid, &status, 0);
2911 ATF_REQUIRE(wpid == fpid);
2912 ATF_REQUIRE(WIFSTOPPED(status));
2913 ATF_REQUIRE(WSTOPSIG(status) == SIGKILL);
2915 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2916 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
2917 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGKILL);
2919 /* Continue the child ignoring the SIGKILL. */
2920 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2922 /* The next wait() should report the stop from SIGSTOP. */
2923 wpid = waitpid(fpid, &status, 0);
2924 ATF_REQUIRE(wpid == fpid);
2925 ATF_REQUIRE(WIFSTOPPED(status));
2926 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2928 /* Check the current event mask. It should not have changed. */
2930 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, wpid, (caddr_t)&new_event_mask,
2931 sizeof(new_event_mask)) == 0);
2932 ATF_REQUIRE(event_mask == new_event_mask);
2934 /* Continue the child to let it exit. */
2935 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
2937 /* The last event should be for the child process's exit. */
2938 wpid = waitpid(fpid, &status, 0);
2939 ATF_REQUIRE(WIFEXITED(status));
2940 ATF_REQUIRE(WEXITSTATUS(status) == 0);
2942 wpid = wait(&status);
2943 ATF_REQUIRE(wpid == -1);
2944 ATF_REQUIRE(errno == ECHILD);
2947 #if defined(__amd64__) || defined(__i386__)
2949 * Only x86 both define breakpoint() and have a PC after breakpoint so
2950 * that restarting doesn't retrigger the breakpoint.
2953 continue_thread(void *arg __unused)
2960 continue_thread_main(void)
2962 pthread_t threads[2];
2964 CHILD_REQUIRE(pthread_create(&threads[0], NULL, continue_thread,
2966 CHILD_REQUIRE(pthread_create(&threads[1], NULL, continue_thread,
2968 CHILD_REQUIRE(pthread_join(threads[0], NULL) == 0);
2969 CHILD_REQUIRE(pthread_join(threads[1], NULL) == 0);
2974 * Ensure that PT_CONTINUE clears the status of the thread that
2975 * triggered the stop even if a different thread's LWP was passed to
2978 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_different_thread);
2979 ATF_TC_BODY(ptrace__PT_CONTINUE_different_thread, tc)
2981 struct ptrace_lwpinfo pl;
2987 ATF_REQUIRE((fpid = fork()) != -1);
2990 continue_thread_main();
2993 /* The first wait() should report the stop from SIGSTOP. */
2994 wpid = waitpid(fpid, &status, 0);
2995 ATF_REQUIRE(wpid == fpid);
2996 ATF_REQUIRE(WIFSTOPPED(status));
2997 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
2999 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
3002 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, wpid, NULL, 1) == 0);
3004 /* Continue the child ignoring the SIGSTOP. */
3005 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3007 /* One of the new threads should report it's birth. */
3008 wpid = waitpid(fpid, &status, 0);
3009 ATF_REQUIRE(wpid == fpid);
3010 ATF_REQUIRE(WIFSTOPPED(status));
3011 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
3013 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3014 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)) ==
3015 (PL_FLAG_BORN | PL_FLAG_SCX));
3016 lwps[0] = pl.pl_lwpid;
3019 * Suspend this thread to ensure both threads are alive before
3020 * hitting the breakpoint.
3022 ATF_REQUIRE(ptrace(PT_SUSPEND, lwps[0], NULL, 0) != -1);
3024 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3026 /* Second thread should report it's birth. */
3027 wpid = waitpid(fpid, &status, 0);
3028 ATF_REQUIRE(wpid == fpid);
3029 ATF_REQUIRE(WIFSTOPPED(status));
3030 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
3032 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3033 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)) ==
3034 (PL_FLAG_BORN | PL_FLAG_SCX));
3035 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
3036 lwps[1] = pl.pl_lwpid;
3038 /* Resume both threads waiting for breakpoint events. */
3039 hit_break[0] = hit_break[1] = false;
3040 ATF_REQUIRE(ptrace(PT_RESUME, lwps[0], NULL, 0) != -1);
3041 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3043 /* One thread should report a breakpoint. */
3044 wpid = waitpid(fpid, &status, 0);
3045 ATF_REQUIRE(wpid == fpid);
3046 ATF_REQUIRE(WIFSTOPPED(status));
3047 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
3049 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3050 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3051 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGTRAP &&
3052 pl.pl_siginfo.si_code == TRAP_BRKPT);
3053 if (pl.pl_lwpid == lwps[0])
3057 hit_break[i] = true;
3060 * Resume both threads but pass the other thread's LWPID to
3063 ATF_REQUIRE(ptrace(PT_CONTINUE, lwps[i ^ 1], (caddr_t)1, 0) == 0);
3066 * Will now get two thread exit events and one more breakpoint
3069 for (j = 0; j < 3; j++) {
3070 wpid = waitpid(fpid, &status, 0);
3071 ATF_REQUIRE(wpid == fpid);
3072 ATF_REQUIRE(WIFSTOPPED(status));
3073 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
3075 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
3078 if (pl.pl_lwpid == lwps[0])
3083 ATF_REQUIRE_MSG(lwps[i] != 0, "event for exited thread");
3084 if (pl.pl_flags & PL_FLAG_EXITED) {
3085 ATF_REQUIRE_MSG(hit_break[i],
3086 "exited thread did not report breakpoint");
3089 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3090 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGTRAP &&
3091 pl.pl_siginfo.si_code == TRAP_BRKPT);
3092 ATF_REQUIRE_MSG(!hit_break[i],
3093 "double breakpoint event");
3094 hit_break[i] = true;
3097 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3100 /* Both threads should have exited. */
3101 ATF_REQUIRE(lwps[0] == 0);
3102 ATF_REQUIRE(lwps[1] == 0);
3104 /* The last event should be for the child process's exit. */
3105 wpid = waitpid(fpid, &status, 0);
3106 ATF_REQUIRE(WIFEXITED(status));
3107 ATF_REQUIRE(WEXITSTATUS(status) == 1);
3109 wpid = wait(&status);
3110 ATF_REQUIRE(wpid == -1);
3111 ATF_REQUIRE(errno == ECHILD);
3116 * Verify that PT_LWPINFO doesn't return stale siginfo.
3118 ATF_TC_WITHOUT_HEAD(ptrace__PT_LWPINFO_stale_siginfo);
3119 ATF_TC_BODY(ptrace__PT_LWPINFO_stale_siginfo, tc)
3121 struct ptrace_lwpinfo pl;
3125 ATF_REQUIRE((fpid = fork()) != -1);
3132 /* The first wait() should report the stop from SIGSTOP. */
3133 wpid = waitpid(fpid, &status, 0);
3134 ATF_REQUIRE(wpid == fpid);
3135 ATF_REQUIRE(WIFSTOPPED(status));
3136 ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
3138 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3140 /* The next stop should report the SIGABRT in the child body. */
3141 wpid = waitpid(fpid, &status, 0);
3142 ATF_REQUIRE(wpid == fpid);
3143 ATF_REQUIRE(WIFSTOPPED(status));
3144 ATF_REQUIRE(WSTOPSIG(status) == SIGABRT);
3146 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3147 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3148 ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGABRT);
3151 * Continue the process ignoring the signal, but enabling
3154 ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
3157 * The next stop should report a system call entry from
3158 * exit(). PL_FLAGS_SI should not be set.
3160 wpid = waitpid(fpid, &status, 0);
3161 ATF_REQUIRE(wpid == fpid);
3162 ATF_REQUIRE(WIFSTOPPED(status));
3163 ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
3165 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3166 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
3167 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) == 0);
3169 /* Disable syscall tracing and continue the child to let it exit. */
3170 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
3171 sizeof(events)) == 0);
3172 events &= ~PTRACE_SYSCALL;
3173 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
3174 sizeof(events)) == 0);
3175 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
3177 /* The last event should be for the child process's exit. */
3178 wpid = waitpid(fpid, &status, 0);
3179 ATF_REQUIRE(WIFEXITED(status));
3180 ATF_REQUIRE(WEXITSTATUS(status) == 1);
3182 wpid = wait(&status);
3183 ATF_REQUIRE(wpid == -1);
3184 ATF_REQUIRE(errno == ECHILD);
3190 ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me);
3191 ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach);
3192 ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger);
3193 ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger);
3194 ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached);
3195 ATF_TP_ADD_TC(tp, ptrace__follow_fork_child_detached);
3196 ATF_TP_ADD_TC(tp, ptrace__follow_fork_parent_detached);
3197 ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached_unrelated_debugger);
3199 ptrace__follow_fork_child_detached_unrelated_debugger);
3201 ptrace__follow_fork_parent_detached_unrelated_debugger);
3202 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_fork);
3203 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_vfork);
3204 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_thread);
3205 ATF_TP_ADD_TC(tp, ptrace__lwp_events);
3206 ATF_TP_ADD_TC(tp, ptrace__lwp_events_exec);
3207 ATF_TP_ADD_TC(tp, ptrace__siginfo);
3208 ATF_TP_ADD_TC(tp, ptrace__ptrace_exec_disable);
3209 ATF_TP_ADD_TC(tp, ptrace__ptrace_exec_enable);
3210 ATF_TP_ADD_TC(tp, ptrace__event_mask);
3211 ATF_TP_ADD_TC(tp, ptrace__ptrace_vfork);
3212 ATF_TP_ADD_TC(tp, ptrace__ptrace_vfork_follow);
3213 #if defined(__amd64__) || defined(__i386__) || defined(__sparc64__)
3214 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_breakpoint);
3216 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_system_call);
3217 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_threads);
3218 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_competing_signal);
3219 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_competing_stop);
3220 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_with_signal_full_sigqueue);
3221 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_system_call_entry);
3223 ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit);
3224 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_full_sigqueue);
3225 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_change_sig);
3226 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_sigtrap_system_call_entry);
3227 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_mix);
3228 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_kqueue);
3229 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_thread_sigmask);
3230 ATF_TP_ADD_TC(tp, ptrace__parent_terminate_with_pending_sigstop1);
3231 ATF_TP_ADD_TC(tp, ptrace__parent_terminate_with_pending_sigstop2);
3232 ATF_TP_ADD_TC(tp, ptrace__event_mask_sigkill_discard);
3233 #if defined(__amd64__) || defined(__i386__)
3234 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_different_thread);
3236 ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo);
3238 return (atf_no_error());