2 * Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/types.h>
30 #include <sys/cpuset.h>
31 #include <sys/event.h>
34 #include <sys/procctl.h>
35 #include <sys/procdesc.h>
36 #define _WANT_MIPS_REGNUM
37 #include <sys/ptrace.h>
38 #include <sys/queue.h>
40 #include <sys/syscall.h>
41 #include <sys/sysctl.h>
45 #include <machine/cpufunc.h>
48 #include <semaphore.h>
57 * Architectures with a user-visible breakpoint().
59 #if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \
60 defined(__i386__) || defined(__mips__) || defined(__riscv) || \
62 #define HAVE_BREAKPOINT
66 * Adjust PC to skip over a breakpoint when stopped for a breakpoint trap.
68 #ifdef HAVE_BREAKPOINT
69 #if defined(__aarch64__)
70 #define SKIP_BREAK(reg) ((reg)->elr += 4)
71 #elif defined(__amd64__) || defined(__i386__)
72 #define SKIP_BREAK(reg)
73 #elif defined(__arm__)
74 #define SKIP_BREAK(reg) ((reg)->r_pc += 4)
75 #elif defined(__mips__)
76 #define SKIP_BREAK(reg) ((reg)->r_regs[PC] += 4)
77 #elif defined(__riscv)
78 #define SKIP_BREAK(reg) ((reg)->sepc += 4)
79 #elif defined(__sparc64__)
80 #define SKIP_BREAK(reg) do { \
81 (reg)->r_tpc = (reg)->r_tnpc + 4; \
88 * A variant of ATF_REQUIRE that is suitable for use in child
89 * processes. This only works if the parent process is tripped up by
90 * the early exit and fails some requirement itself.
92 #define CHILD_REQUIRE(exp) do { \
94 child_fail_require(__FILE__, __LINE__, \
98 #define CHILD_REQUIRE_EQ(actual, expected) do { \
99 __typeof__(expected) _e = expected; \
100 __typeof__(actual) _a = actual; \
102 child_fail_require(__FILE__, __LINE__, #actual \
103 " (%jd) == " #expected " (%jd) not met\n", \
104 (intmax_t)_a, (intmax_t)_e); \
108 child_fail_require(const char *file, int line, const char *fmt, ...)
113 /* Use write() not fprintf() to avoid possible duplicate output. */
114 snprintf(buf, sizeof(buf), "%s:%d: ", file, line);
115 write(STDERR_FILENO, buf, strlen(buf));
117 vsnprintf(buf, sizeof(buf), fmt, ap);
118 write(STDERR_FILENO, buf, strlen(buf));
124 #define REQUIRE_EQ(actual, expected) do { \
125 __typeof__(expected) _e = expected; \
126 __typeof__(actual) _a = actual; \
127 ATF_REQUIRE_MSG(_e == _a, #actual " (%jd) == " \
128 #expected " (%jd) not met", (intmax_t)_a, (intmax_t)_e); \
135 /* Attach the parent process as a tracer of this process. */
136 CHILD_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
138 /* Trigger a stop. */
143 attach_child(pid_t pid)
148 REQUIRE_EQ(ptrace(PT_ATTACH, pid, NULL, 0), 0);
150 wpid = waitpid(pid, &status, 0);
151 REQUIRE_EQ(wpid, pid);
152 ATF_REQUIRE(WIFSTOPPED(status));
153 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
157 wait_for_zombie(pid_t pid)
161 * Wait for a process to exit. This is kind of gross, but
162 * there is not a better way.
164 * Prior to r325719, the kern.proc.pid.<pid> sysctl failed
165 * with ESRCH. After that change, a valid struct kinfo_proc
166 * is returned for zombies with ki_stat set to SZOMB.
169 struct kinfo_proc kp;
175 mib[2] = KERN_PROC_PID;
178 if (sysctl(mib, nitems(mib), &kp, &len, NULL, 0) == -1) {
179 REQUIRE_EQ(errno, ESRCH);
182 if (kp.ki_stat == SZOMB)
189 * Verify that a parent debugger process "sees" the exit of a debugged
190 * process exactly once when attached via PT_TRACE_ME.
192 ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_trace_me);
193 ATF_TC_BODY(ptrace__parent_wait_after_trace_me, tc)
198 ATF_REQUIRE((child = fork()) != -1);
206 /* Parent process. */
208 /* The first wait() should report the stop from SIGSTOP. */
209 wpid = waitpid(child, &status, 0);
210 REQUIRE_EQ(wpid, child);
211 ATF_REQUIRE(WIFSTOPPED(status));
212 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
214 /* Continue the child ignoring the SIGSTOP. */
215 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
217 /* The second wait() should report the exit status. */
218 wpid = waitpid(child, &status, 0);
219 REQUIRE_EQ(wpid, child);
220 ATF_REQUIRE(WIFEXITED(status));
221 REQUIRE_EQ(WEXITSTATUS(status), 1);
223 /* The child should no longer exist. */
224 wpid = waitpid(child, &status, 0);
225 REQUIRE_EQ(wpid, -1);
226 REQUIRE_EQ(errno, ECHILD);
230 * Verify that a parent debugger process "sees" the exit of a debugged
231 * process exactly once when attached via PT_ATTACH.
233 ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_attach);
234 ATF_TC_BODY(ptrace__parent_wait_after_attach, tc)
237 int cpipe[2], status;
240 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
241 atf_tc_skip("https://bugs.freebsd.org/244055");
243 REQUIRE_EQ(pipe(cpipe), 0);
244 ATF_REQUIRE((child = fork()) != -1);
249 /* Wait for the parent to attach. */
250 CHILD_REQUIRE_EQ(0, read(cpipe[1], &c, sizeof(c)));
256 /* Parent process. */
258 /* Attach to the child process. */
261 /* Continue the child ignoring the SIGSTOP. */
262 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
264 /* Signal the child to exit. */
267 /* The second wait() should report the exit status. */
268 wpid = waitpid(child, &status, 0);
269 REQUIRE_EQ(wpid, child);
270 ATF_REQUIRE(WIFEXITED(status));
271 REQUIRE_EQ(WEXITSTATUS(status), 1);
273 /* The child should no longer exist. */
274 wpid = waitpid(child, &status, 0);
275 REQUIRE_EQ(wpid, -1);
276 REQUIRE_EQ(errno, ECHILD);
280 * Verify that a parent process "sees" the exit of a debugged process only
281 * after the debugger has seen it.
283 ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_child_debugger);
284 ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc)
286 pid_t child, debugger, wpid;
287 int cpipe[2], dpipe[2], status;
290 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
291 atf_tc_skip("https://bugs.freebsd.org/239399");
293 REQUIRE_EQ(pipe(cpipe), 0);
294 ATF_REQUIRE((child = fork()) != -1);
300 /* Wait for parent to be ready. */
301 CHILD_REQUIRE_EQ(read(cpipe[1], &c, sizeof(c)), sizeof(c));
307 REQUIRE_EQ(pipe(dpipe), 0);
308 ATF_REQUIRE((debugger = fork()) != -1);
311 /* Debugger process. */
314 CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
316 wpid = waitpid(child, &status, 0);
317 CHILD_REQUIRE_EQ(wpid, child);
318 CHILD_REQUIRE(WIFSTOPPED(status));
319 CHILD_REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
321 CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
323 /* Signal parent that debugger is attached. */
324 CHILD_REQUIRE_EQ(write(dpipe[1], &c, sizeof(c)), sizeof(c));
326 /* Wait for parent's failed wait. */
327 CHILD_REQUIRE_EQ(read(dpipe[1], &c, sizeof(c)), 0);
329 wpid = waitpid(child, &status, 0);
330 CHILD_REQUIRE_EQ(wpid, child);
331 CHILD_REQUIRE(WIFEXITED(status));
332 CHILD_REQUIRE_EQ(WEXITSTATUS(status), 1);
338 /* Parent process. */
340 /* Wait for the debugger to attach to the child. */
341 REQUIRE_EQ(read(dpipe[0], &c, sizeof(c)), sizeof(c));
343 /* Release the child. */
344 REQUIRE_EQ(write(cpipe[0], &c, sizeof(c)), sizeof(c));
345 REQUIRE_EQ(read(cpipe[0], &c, sizeof(c)), 0);
348 wait_for_zombie(child);
351 * This wait should return a pid of 0 to indicate no status to
352 * report. The parent should see the child as non-exited
353 * until the debugger sees the exit.
355 wpid = waitpid(child, &status, WNOHANG);
358 /* Signal the debugger to wait for the child. */
361 /* Wait for the debugger. */
362 wpid = waitpid(debugger, &status, 0);
363 REQUIRE_EQ(wpid, debugger);
364 ATF_REQUIRE(WIFEXITED(status));
365 REQUIRE_EQ(WEXITSTATUS(status), 0);
367 /* The child process should now be ready. */
368 wpid = waitpid(child, &status, WNOHANG);
369 REQUIRE_EQ(wpid, child);
370 ATF_REQUIRE(WIFEXITED(status));
371 REQUIRE_EQ(WEXITSTATUS(status), 1);
375 * Verify that a parent process "sees" the exit of a debugged process
376 * only after a non-direct-child debugger has seen it. In particular,
377 * various wait() calls in the parent must avoid failing with ESRCH by
378 * checking the parent's orphan list for the debugee.
380 ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_unrelated_debugger);
381 ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
383 pid_t child, debugger, fpid, wpid;
384 int cpipe[2], dpipe[2], status;
387 REQUIRE_EQ(pipe(cpipe), 0);
388 ATF_REQUIRE((child = fork()) != -1);
394 /* Wait for parent to be ready. */
395 CHILD_REQUIRE_EQ(read(cpipe[1], &c, sizeof(c)), sizeof(c));
401 REQUIRE_EQ(pipe(dpipe), 0);
402 ATF_REQUIRE((debugger = fork()) != -1);
405 /* Debugger parent. */
408 * Fork again and drop the debugger parent so that the
409 * debugger is not a child of the main parent.
411 CHILD_REQUIRE((fpid = fork()) != -1);
415 /* Debugger process. */
418 CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
420 wpid = waitpid(child, &status, 0);
421 CHILD_REQUIRE_EQ(wpid, child);
422 CHILD_REQUIRE(WIFSTOPPED(status));
423 CHILD_REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
425 CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
427 /* Signal parent that debugger is attached. */
428 CHILD_REQUIRE_EQ(write(dpipe[1], &c, sizeof(c)), sizeof(c));
430 /* Wait for parent's failed wait. */
431 CHILD_REQUIRE_EQ(read(dpipe[1], &c, sizeof(c)), sizeof(c));
433 wpid = waitpid(child, &status, 0);
434 CHILD_REQUIRE_EQ(wpid, child);
435 CHILD_REQUIRE(WIFEXITED(status));
436 CHILD_REQUIRE_EQ(WEXITSTATUS(status), 1);
442 /* Parent process. */
444 /* Wait for the debugger parent process to exit. */
445 wpid = waitpid(debugger, &status, 0);
446 REQUIRE_EQ(wpid, debugger);
447 ATF_REQUIRE(WIFEXITED(status));
448 REQUIRE_EQ(WEXITSTATUS(status), 2);
450 /* A WNOHANG wait here should see the non-exited child. */
451 wpid = waitpid(child, &status, WNOHANG);
454 /* Wait for the debugger to attach to the child. */
455 REQUIRE_EQ(read(dpipe[0], &c, sizeof(c)), sizeof(c));
457 /* Release the child. */
458 REQUIRE_EQ(write(cpipe[0], &c, sizeof(c)), sizeof(c));
459 REQUIRE_EQ(read(cpipe[0], &c, sizeof(c)), 0);
462 wait_for_zombie(child);
465 * This wait should return a pid of 0 to indicate no status to
466 * report. The parent should see the child as non-exited
467 * until the debugger sees the exit.
469 wpid = waitpid(child, &status, WNOHANG);
472 /* Signal the debugger to wait for the child. */
473 REQUIRE_EQ(write(dpipe[0], &c, sizeof(c)), sizeof(c));
475 /* Wait for the debugger. */
476 REQUIRE_EQ(read(dpipe[0], &c, sizeof(c)), 0);
479 /* The child process should now be ready. */
480 wpid = waitpid(child, &status, WNOHANG);
481 REQUIRE_EQ(wpid, child);
482 ATF_REQUIRE(WIFEXITED(status));
483 REQUIRE_EQ(WEXITSTATUS(status), 1);
487 * Make sure that we can collect the exit status of an orphaned process.
489 ATF_TC_WITHOUT_HEAD(ptrace__parent_exits_before_child);
490 ATF_TC_BODY(ptrace__parent_exits_before_child, tc)
493 int cpipe1[2], cpipe2[2], gcpipe[2], status;
496 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
497 atf_tc_skip("https://bugs.freebsd.org/244056");
499 REQUIRE_EQ(pipe(cpipe1), 0);
500 REQUIRE_EQ(pipe(cpipe2), 0);
501 REQUIRE_EQ(pipe(gcpipe), 0);
503 REQUIRE_EQ(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL), 0);
505 ATF_REQUIRE((child = fork()) != -1);
507 CHILD_REQUIRE((gchild = fork()) != -1);
511 n = read(gcpipe[0], &status, sizeof(status));
512 } while (n == -1 && errno == EINTR);
516 CHILD_REQUIRE(write(cpipe1[1], &gchild, sizeof(gchild)) ==
518 CHILD_REQUIRE(read(cpipe2[0], &status, sizeof(status)) ==
523 REQUIRE_EQ(read(cpipe1[0], &gchild, sizeof(gchild)), sizeof(gchild));
525 REQUIRE_EQ(ptrace(PT_ATTACH, gchild, NULL, 0), 0);
528 REQUIRE_EQ(write(cpipe2[1], &status, sizeof(status)), sizeof(status));
529 REQUIRE_EQ(waitpid(child, &status, 0), child);
530 ATF_REQUIRE(WIFEXITED(status));
531 REQUIRE_EQ(WEXITSTATUS(status), 0);
534 REQUIRE_EQ(write(gcpipe[1], &status, sizeof(status)), sizeof(status));
535 REQUIRE_EQ(waitpid(gchild, &status, 0), gchild);
536 ATF_REQUIRE(WIFSTOPPED(status));
537 REQUIRE_EQ(ptrace(PT_DETACH, gchild, (caddr_t)1, 0), 0);
538 REQUIRE_EQ(waitpid(gchild, &status, 0), gchild);
539 ATF_REQUIRE(WIFEXITED(status));
540 REQUIRE_EQ(WEXITSTATUS(status), 0);
542 REQUIRE_EQ(close(cpipe1[0]), 0);
543 REQUIRE_EQ(close(cpipe1[1]), 0);
544 REQUIRE_EQ(close(cpipe2[0]), 0);
545 REQUIRE_EQ(close(cpipe2[1]), 0);
546 REQUIRE_EQ(close(gcpipe[0]), 0);
547 REQUIRE_EQ(close(gcpipe[1]), 0);
551 * The parent process should always act the same regardless of how the
552 * debugger is attached to it.
555 follow_fork_parent(bool use_vfork)
561 CHILD_REQUIRE((fpid = vfork()) != -1);
563 CHILD_REQUIRE((fpid = fork()) != -1);
569 wpid = waitpid(fpid, &status, 0);
570 CHILD_REQUIRE_EQ(wpid, fpid);
571 CHILD_REQUIRE(WIFEXITED(status));
572 CHILD_REQUIRE_EQ(WEXITSTATUS(status), 2);
578 * Helper routine for follow fork tests. This waits for two stops
579 * that report both "sides" of a fork. It returns the pid of the new
583 handle_fork_events(pid_t parent, struct ptrace_lwpinfo *ppl)
585 struct ptrace_lwpinfo pl;
586 bool fork_reported[2];
590 fork_reported[0] = false;
591 fork_reported[1] = false;
595 * Each process should report a fork event. The parent should
596 * report a PL_FLAG_FORKED event, and the child should report
597 * a PL_FLAG_CHILD event.
599 for (i = 0; i < 2; i++) {
600 wpid = wait(&status);
601 ATF_REQUIRE(wpid > 0);
602 ATF_REQUIRE(WIFSTOPPED(status));
604 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
606 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
608 ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
609 (PL_FLAG_FORKED | PL_FLAG_CHILD));
610 if (pl.pl_flags & PL_FLAG_CHILD) {
611 ATF_REQUIRE(wpid != parent);
612 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
613 ATF_REQUIRE(!fork_reported[1]);
617 REQUIRE_EQ(child, wpid);
620 fork_reported[1] = true;
622 REQUIRE_EQ(wpid, parent);
623 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
624 ATF_REQUIRE(!fork_reported[0]);
626 child = pl.pl_child_pid;
628 REQUIRE_EQ(child, pl.pl_child_pid);
631 fork_reported[0] = true;
639 * Verify that a new child process is stopped after a followed fork and
640 * that the traced parent sees the exit of the child after the debugger
641 * when both processes remain attached to the debugger.
643 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached);
644 ATF_TC_BODY(ptrace__follow_fork_both_attached, tc)
646 pid_t children[2], fpid, wpid;
649 ATF_REQUIRE((fpid = fork()) != -1);
652 follow_fork_parent(false);
655 /* Parent process. */
658 /* The first wait() should report the stop from SIGSTOP. */
659 wpid = waitpid(children[0], &status, 0);
660 REQUIRE_EQ(wpid, children[0]);
661 ATF_REQUIRE(WIFSTOPPED(status));
662 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
664 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
666 /* Continue the child ignoring the SIGSTOP. */
667 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
669 children[1] = handle_fork_events(children[0], NULL);
670 ATF_REQUIRE(children[1] > 0);
672 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
673 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
676 * The child can't exit until the grandchild reports status, so the
677 * grandchild should report its exit first to the debugger.
679 wpid = wait(&status);
680 REQUIRE_EQ(wpid, children[1]);
681 ATF_REQUIRE(WIFEXITED(status));
682 REQUIRE_EQ(WEXITSTATUS(status), 2);
684 wpid = wait(&status);
685 REQUIRE_EQ(wpid, children[0]);
686 ATF_REQUIRE(WIFEXITED(status));
687 REQUIRE_EQ(WEXITSTATUS(status), 1);
689 wpid = wait(&status);
690 REQUIRE_EQ(wpid, -1);
691 REQUIRE_EQ(errno, ECHILD);
695 * Verify that a new child process is stopped after a followed fork
696 * and that the traced parent sees the exit of the child when the new
697 * child process is detached after it reports its fork.
699 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached);
700 ATF_TC_BODY(ptrace__follow_fork_child_detached, tc)
702 pid_t children[2], fpid, wpid;
705 ATF_REQUIRE((fpid = fork()) != -1);
708 follow_fork_parent(false);
711 /* Parent process. */
714 /* The first wait() should report the stop from SIGSTOP. */
715 wpid = waitpid(children[0], &status, 0);
716 REQUIRE_EQ(wpid, children[0]);
717 ATF_REQUIRE(WIFSTOPPED(status));
718 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
720 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
722 /* Continue the child ignoring the SIGSTOP. */
723 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
725 children[1] = handle_fork_events(children[0], NULL);
726 ATF_REQUIRE(children[1] > 0);
728 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
729 ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
732 * Should not see any status from the grandchild now, only the
735 wpid = wait(&status);
736 REQUIRE_EQ(wpid, children[0]);
737 ATF_REQUIRE(WIFEXITED(status));
738 REQUIRE_EQ(WEXITSTATUS(status), 1);
740 wpid = wait(&status);
741 REQUIRE_EQ(wpid, -1);
742 REQUIRE_EQ(errno, ECHILD);
746 * Verify that a new child process is stopped after a followed fork
747 * and that the traced parent sees the exit of the child when the
748 * traced parent is detached after the fork.
750 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached);
751 ATF_TC_BODY(ptrace__follow_fork_parent_detached, tc)
753 pid_t children[2], fpid, wpid;
756 ATF_REQUIRE((fpid = fork()) != -1);
759 follow_fork_parent(false);
762 /* Parent process. */
765 /* The first wait() should report the stop from SIGSTOP. */
766 wpid = waitpid(children[0], &status, 0);
767 REQUIRE_EQ(wpid, children[0]);
768 ATF_REQUIRE(WIFSTOPPED(status));
769 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
771 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
773 /* Continue the child ignoring the SIGSTOP. */
774 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
776 children[1] = handle_fork_events(children[0], NULL);
777 ATF_REQUIRE(children[1] > 0);
779 ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
780 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
783 * The child can't exit until the grandchild reports status, so the
784 * grandchild should report its exit first to the debugger.
786 * Even though the child process is detached, it is still a
787 * child of the debugger, so it will still report it's exit
788 * after the grandchild.
790 wpid = wait(&status);
791 REQUIRE_EQ(wpid, children[1]);
792 ATF_REQUIRE(WIFEXITED(status));
793 REQUIRE_EQ(WEXITSTATUS(status), 2);
795 wpid = wait(&status);
796 REQUIRE_EQ(wpid, children[0]);
797 ATF_REQUIRE(WIFEXITED(status));
798 REQUIRE_EQ(WEXITSTATUS(status), 1);
800 wpid = wait(&status);
801 REQUIRE_EQ(wpid, -1);
802 REQUIRE_EQ(errno, ECHILD);
806 attach_fork_parent(int cpipe[2])
812 /* Double-fork to disassociate from the debugger. */
813 CHILD_REQUIRE((fpid = fork()) != -1);
817 /* Send the pid of the disassociated child to the debugger. */
819 CHILD_REQUIRE_EQ(write(cpipe[1], &fpid, sizeof(fpid)), sizeof(fpid));
821 /* Wait for the debugger to attach. */
822 CHILD_REQUIRE_EQ(read(cpipe[1], &fpid, sizeof(fpid)), 0);
826 * Verify that a new child process is stopped after a followed fork and
827 * that the traced parent sees the exit of the child after the debugger
828 * when both processes remain attached to the debugger. In this test
829 * the parent that forks is not a direct child of the debugger.
831 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached_unrelated_debugger);
832 ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc)
834 pid_t children[2], fpid, wpid;
835 int cpipe[2], status;
837 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
838 atf_tc_skip("https://bugs.freebsd.org/239397");
840 REQUIRE_EQ(pipe(cpipe), 0);
841 ATF_REQUIRE((fpid = fork()) != -1);
843 attach_fork_parent(cpipe);
844 follow_fork_parent(false);
847 /* Parent process. */
850 /* Wait for the direct child to exit. */
851 wpid = waitpid(fpid, &status, 0);
852 REQUIRE_EQ(wpid, fpid);
853 ATF_REQUIRE(WIFEXITED(status));
854 REQUIRE_EQ(WEXITSTATUS(status), 3);
856 /* Read the pid of the fork parent. */
857 REQUIRE_EQ(read(cpipe[0], &children[0], sizeof(children[0])),
858 sizeof(children[0]));
860 /* Attach to the fork parent. */
861 attach_child(children[0]);
863 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
865 /* Continue the fork parent ignoring the SIGSTOP. */
866 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
868 /* Signal the fork parent to continue. */
871 children[1] = handle_fork_events(children[0], NULL);
872 ATF_REQUIRE(children[1] > 0);
874 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
875 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
878 * The fork parent can't exit until the child reports status,
879 * so the child should report its exit first to the debugger.
881 wpid = wait(&status);
882 REQUIRE_EQ(wpid, children[1]);
883 ATF_REQUIRE(WIFEXITED(status));
884 REQUIRE_EQ(WEXITSTATUS(status), 2);
886 wpid = wait(&status);
887 REQUIRE_EQ(wpid, children[0]);
888 ATF_REQUIRE(WIFEXITED(status));
889 REQUIRE_EQ(WEXITSTATUS(status), 1);
891 wpid = wait(&status);
892 REQUIRE_EQ(wpid, -1);
893 REQUIRE_EQ(errno, ECHILD);
897 * Verify that a new child process is stopped after a followed fork
898 * and that the traced parent sees the exit of the child when the new
899 * child process is detached after it reports its fork. In this test
900 * the parent that forks is not a direct child of the debugger.
902 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached_unrelated_debugger);
903 ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc)
905 pid_t children[2], fpid, wpid;
906 int cpipe[2], status;
908 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
909 atf_tc_skip("https://bugs.freebsd.org/239292");
911 REQUIRE_EQ(pipe(cpipe), 0);
912 ATF_REQUIRE((fpid = fork()) != -1);
914 attach_fork_parent(cpipe);
915 follow_fork_parent(false);
918 /* Parent process. */
921 /* Wait for the direct child to exit. */
922 wpid = waitpid(fpid, &status, 0);
923 REQUIRE_EQ(wpid, fpid);
924 ATF_REQUIRE(WIFEXITED(status));
925 REQUIRE_EQ(WEXITSTATUS(status), 3);
927 /* Read the pid of the fork parent. */
928 REQUIRE_EQ(read(cpipe[0], &children[0], sizeof(children[0])),
929 sizeof(children[0]));
931 /* Attach to the fork parent. */
932 attach_child(children[0]);
934 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
936 /* Continue the fork parent ignoring the SIGSTOP. */
937 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
939 /* Signal the fork parent to continue. */
942 children[1] = handle_fork_events(children[0], NULL);
943 ATF_REQUIRE(children[1] > 0);
945 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
946 ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
949 * Should not see any status from the child now, only the fork
952 wpid = wait(&status);
953 REQUIRE_EQ(wpid, children[0]);
954 ATF_REQUIRE(WIFEXITED(status));
955 REQUIRE_EQ(WEXITSTATUS(status), 1);
957 wpid = wait(&status);
958 REQUIRE_EQ(wpid, -1);
959 REQUIRE_EQ(errno, ECHILD);
963 * Verify that a new child process is stopped after a followed fork
964 * and that the traced parent sees the exit of the child when the
965 * traced parent is detached after the fork. In this test the parent
966 * that forks is not a direct child of the debugger.
968 ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached_unrelated_debugger);
969 ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc)
971 pid_t children[2], fpid, wpid;
972 int cpipe[2], status;
974 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
975 atf_tc_skip("https://bugs.freebsd.org/239425");
977 REQUIRE_EQ(pipe(cpipe), 0);
978 ATF_REQUIRE((fpid = fork()) != -1);
980 attach_fork_parent(cpipe);
981 follow_fork_parent(false);
984 /* Parent process. */
987 /* Wait for the direct child to exit. */
988 wpid = waitpid(fpid, &status, 0);
989 REQUIRE_EQ(wpid, fpid);
990 ATF_REQUIRE(WIFEXITED(status));
991 REQUIRE_EQ(WEXITSTATUS(status), 3);
993 /* Read the pid of the fork parent. */
994 REQUIRE_EQ(read(cpipe[0], &children[0], sizeof(children[0])),
995 sizeof(children[0]));
997 /* Attach to the fork parent. */
998 attach_child(children[0]);
1000 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
1002 /* Continue the fork parent ignoring the SIGSTOP. */
1003 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1005 /* Signal the fork parent to continue. */
1008 children[1] = handle_fork_events(children[0], NULL);
1009 ATF_REQUIRE(children[1] > 0);
1011 ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
1012 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1015 * Should not see any status from the fork parent now, only
1018 wpid = wait(&status);
1019 REQUIRE_EQ(wpid, children[1]);
1020 ATF_REQUIRE(WIFEXITED(status));
1021 REQUIRE_EQ(WEXITSTATUS(status), 2);
1023 wpid = wait(&status);
1024 REQUIRE_EQ(wpid, -1);
1025 REQUIRE_EQ(errno, ECHILD);
1029 * Verify that a child process does not see an unrelated debugger as its
1030 * parent but sees its original parent process.
1032 ATF_TC_WITHOUT_HEAD(ptrace__getppid);
1033 ATF_TC_BODY(ptrace__getppid, tc)
1035 pid_t child, debugger, ppid, wpid;
1036 int cpipe[2], dpipe[2], status;
1039 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
1040 atf_tc_skip("https://bugs.freebsd.org/240510");
1042 REQUIRE_EQ(pipe(cpipe), 0);
1043 ATF_REQUIRE((child = fork()) != -1);
1046 /* Child process. */
1049 /* Wait for parent to be ready. */
1050 CHILD_REQUIRE_EQ(read(cpipe[1], &c, sizeof(c)), sizeof(c));
1052 /* Report the parent PID to the parent. */
1054 CHILD_REQUIRE(write(cpipe[1], &ppid, sizeof(ppid)) ==
1061 REQUIRE_EQ(pipe(dpipe), 0);
1062 ATF_REQUIRE((debugger = fork()) != -1);
1064 if (debugger == 0) {
1065 /* Debugger process. */
1068 CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
1070 wpid = waitpid(child, &status, 0);
1071 CHILD_REQUIRE_EQ(wpid, child);
1072 CHILD_REQUIRE(WIFSTOPPED(status));
1073 CHILD_REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1075 CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
1077 /* Signal parent that debugger is attached. */
1078 CHILD_REQUIRE_EQ(write(dpipe[1], &c, sizeof(c)), sizeof(c));
1080 /* Wait for traced child to exit. */
1081 wpid = waitpid(child, &status, 0);
1082 CHILD_REQUIRE_EQ(wpid, child);
1083 CHILD_REQUIRE(WIFEXITED(status));
1084 CHILD_REQUIRE_EQ(WEXITSTATUS(status), 1);
1090 /* Parent process. */
1092 /* Wait for the debugger to attach to the child. */
1093 REQUIRE_EQ(read(dpipe[0], &c, sizeof(c)), sizeof(c));
1095 /* Release the child. */
1096 REQUIRE_EQ(write(cpipe[0], &c, sizeof(c)), sizeof(c));
1098 /* Read the parent PID from the child. */
1099 REQUIRE_EQ(read(cpipe[0], &ppid, sizeof(ppid)), sizeof(ppid));
1102 REQUIRE_EQ(ppid, getpid());
1104 /* Wait for the debugger. */
1105 wpid = waitpid(debugger, &status, 0);
1106 REQUIRE_EQ(wpid, debugger);
1107 ATF_REQUIRE(WIFEXITED(status));
1108 REQUIRE_EQ(WEXITSTATUS(status), 0);
1110 /* The child process should now be ready. */
1111 wpid = waitpid(child, &status, WNOHANG);
1112 REQUIRE_EQ(wpid, child);
1113 ATF_REQUIRE(WIFEXITED(status));
1114 REQUIRE_EQ(WEXITSTATUS(status), 1);
1118 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
1119 * child process created via fork() reports the correct value.
1121 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_fork);
1122 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_fork, tc)
1124 struct ptrace_lwpinfo pl[2];
1125 pid_t children[2], fpid, wpid;
1128 ATF_REQUIRE((fpid = fork()) != -1);
1131 follow_fork_parent(false);
1134 /* Parent process. */
1137 /* The first wait() should report the stop from SIGSTOP. */
1138 wpid = waitpid(children[0], &status, 0);
1139 REQUIRE_EQ(wpid, children[0]);
1140 ATF_REQUIRE(WIFSTOPPED(status));
1141 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1143 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
1145 /* Continue the child ignoring the SIGSTOP. */
1146 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1148 /* Wait for both halves of the fork event to get reported. */
1149 children[1] = handle_fork_events(children[0], pl);
1150 ATF_REQUIRE(children[1] > 0);
1152 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
1153 ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
1154 REQUIRE_EQ(pl[0].pl_syscall_code, SYS_fork);
1155 REQUIRE_EQ(pl[0].pl_syscall_code, pl[1].pl_syscall_code);
1156 REQUIRE_EQ(pl[0].pl_syscall_narg, pl[1].pl_syscall_narg);
1158 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1159 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1162 * The child can't exit until the grandchild reports status, so the
1163 * grandchild should report its exit first to the debugger.
1165 wpid = wait(&status);
1166 REQUIRE_EQ(wpid, children[1]);
1167 ATF_REQUIRE(WIFEXITED(status));
1168 REQUIRE_EQ(WEXITSTATUS(status), 2);
1170 wpid = wait(&status);
1171 REQUIRE_EQ(wpid, children[0]);
1172 ATF_REQUIRE(WIFEXITED(status));
1173 REQUIRE_EQ(WEXITSTATUS(status), 1);
1175 wpid = wait(&status);
1176 REQUIRE_EQ(wpid, -1);
1177 REQUIRE_EQ(errno, ECHILD);
1181 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
1182 * child process created via vfork() reports the correct value.
1184 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_vfork);
1185 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_vfork, tc)
1187 struct ptrace_lwpinfo pl[2];
1188 pid_t children[2], fpid, wpid;
1191 ATF_REQUIRE((fpid = fork()) != -1);
1194 follow_fork_parent(true);
1197 /* Parent process. */
1200 /* The first wait() should report the stop from SIGSTOP. */
1201 wpid = waitpid(children[0], &status, 0);
1202 REQUIRE_EQ(wpid, children[0]);
1203 ATF_REQUIRE(WIFSTOPPED(status));
1204 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1206 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
1208 /* Continue the child ignoring the SIGSTOP. */
1209 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1211 /* Wait for both halves of the fork event to get reported. */
1212 children[1] = handle_fork_events(children[0], pl);
1213 ATF_REQUIRE(children[1] > 0);
1215 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
1216 ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
1217 REQUIRE_EQ(pl[0].pl_syscall_code, SYS_vfork);
1218 REQUIRE_EQ(pl[0].pl_syscall_code, pl[1].pl_syscall_code);
1219 REQUIRE_EQ(pl[0].pl_syscall_narg, pl[1].pl_syscall_narg);
1221 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1222 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1225 * The child can't exit until the grandchild reports status, so the
1226 * grandchild should report its exit first to the debugger.
1228 wpid = wait(&status);
1229 REQUIRE_EQ(wpid, children[1]);
1230 ATF_REQUIRE(WIFEXITED(status));
1231 REQUIRE_EQ(WEXITSTATUS(status), 2);
1233 wpid = wait(&status);
1234 REQUIRE_EQ(wpid, children[0]);
1235 ATF_REQUIRE(WIFEXITED(status));
1236 REQUIRE_EQ(WEXITSTATUS(status), 1);
1238 wpid = wait(&status);
1239 REQUIRE_EQ(wpid, -1);
1240 REQUIRE_EQ(errno, ECHILD);
1244 simple_thread(void *arg __unused)
1251 simple_thread_main(void)
1255 CHILD_REQUIRE_EQ(pthread_create(&thread, NULL, simple_thread, NULL), 0);
1256 CHILD_REQUIRE_EQ(pthread_join(thread, NULL), 0);
1261 * Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
1262 * thread reports the correct value.
1264 ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_thread);
1265 ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
1267 struct ptrace_lwpinfo pl;
1272 ATF_REQUIRE((fpid = fork()) != -1);
1275 simple_thread_main();
1278 /* The first wait() should report the stop from SIGSTOP. */
1279 wpid = waitpid(fpid, &status, 0);
1280 REQUIRE_EQ(wpid, fpid);
1281 ATF_REQUIRE(WIFSTOPPED(status));
1282 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1284 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1286 mainlwp = pl.pl_lwpid;
1289 * Continue the child ignoring the SIGSTOP and tracing all
1290 * system call exits.
1292 ATF_REQUIRE(ptrace(PT_TO_SCX, fpid, (caddr_t)1, 0) != -1);
1295 * Wait for the new thread to arrive. pthread_create() might
1296 * invoke any number of system calls. For now we just wait
1297 * for the new thread to arrive and make sure it reports a
1298 * valid system call code. If ptrace grows thread event
1299 * reporting then this test can be made more precise.
1302 wpid = waitpid(fpid, &status, 0);
1303 REQUIRE_EQ(wpid, fpid);
1304 ATF_REQUIRE(WIFSTOPPED(status));
1305 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1307 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1309 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SCX) != 0);
1310 ATF_REQUIRE(pl.pl_syscall_code != 0);
1311 if (pl.pl_lwpid != mainlwp)
1312 /* New thread seen. */
1315 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1318 /* Wait for the child to exit. */
1319 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1321 wpid = waitpid(fpid, &status, 0);
1322 REQUIRE_EQ(wpid, fpid);
1323 if (WIFEXITED(status))
1326 ATF_REQUIRE(WIFSTOPPED(status));
1327 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1328 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1331 REQUIRE_EQ(WEXITSTATUS(status), 1);
1333 wpid = wait(&status);
1334 REQUIRE_EQ(wpid, -1);
1335 REQUIRE_EQ(errno, ECHILD);
1339 * Verify that the expected LWP events are reported for a child thread.
1341 ATF_TC_WITHOUT_HEAD(ptrace__lwp_events);
1342 ATF_TC_BODY(ptrace__lwp_events, tc)
1344 struct ptrace_lwpinfo pl;
1349 ATF_REQUIRE((fpid = fork()) != -1);
1352 simple_thread_main();
1355 /* The first wait() should report the stop from SIGSTOP. */
1356 wpid = waitpid(fpid, &status, 0);
1357 REQUIRE_EQ(wpid, fpid);
1358 ATF_REQUIRE(WIFSTOPPED(status));
1359 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1361 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1363 lwps[0] = pl.pl_lwpid;
1365 REQUIRE_EQ(ptrace(PT_LWP_EVENTS, wpid, NULL, 1), 0);
1367 /* Continue the child ignoring the SIGSTOP. */
1368 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1370 /* The first event should be for the child thread's birth. */
1371 wpid = waitpid(fpid, &status, 0);
1372 REQUIRE_EQ(wpid, fpid);
1373 ATF_REQUIRE(WIFSTOPPED(status));
1374 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1376 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1377 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)),
1378 (PL_FLAG_BORN | PL_FLAG_SCX));
1379 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
1380 lwps[1] = pl.pl_lwpid;
1382 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1384 /* The next event should be for the child thread's death. */
1385 wpid = waitpid(fpid, &status, 0);
1386 REQUIRE_EQ(wpid, fpid);
1387 ATF_REQUIRE(WIFSTOPPED(status));
1388 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1390 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1391 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_EXITED | PL_FLAG_SCE)),
1392 (PL_FLAG_EXITED | PL_FLAG_SCE));
1393 REQUIRE_EQ(pl.pl_lwpid, lwps[1]);
1395 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1397 /* The last event should be for the child process's exit. */
1398 wpid = waitpid(fpid, &status, 0);
1399 ATF_REQUIRE(WIFEXITED(status));
1400 REQUIRE_EQ(WEXITSTATUS(status), 1);
1402 wpid = wait(&status);
1403 REQUIRE_EQ(wpid, -1);
1404 REQUIRE_EQ(errno, ECHILD);
1408 exec_thread(void *arg __unused)
1411 execl("/usr/bin/true", "true", NULL);
1416 exec_thread_main(void)
1420 CHILD_REQUIRE_EQ(pthread_create(&thread, NULL, exec_thread, NULL), 0);
1427 * Verify that the expected LWP events are reported for a multithreaded
1428 * process that calls execve(2).
1430 ATF_TC_WITHOUT_HEAD(ptrace__lwp_events_exec);
1431 ATF_TC_BODY(ptrace__lwp_events_exec, tc)
1433 struct ptrace_lwpinfo pl;
1438 ATF_REQUIRE((fpid = fork()) != -1);
1444 /* The first wait() should report the stop from SIGSTOP. */
1445 wpid = waitpid(fpid, &status, 0);
1446 REQUIRE_EQ(wpid, fpid);
1447 ATF_REQUIRE(WIFSTOPPED(status));
1448 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1450 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1452 lwps[0] = pl.pl_lwpid;
1454 REQUIRE_EQ(ptrace(PT_LWP_EVENTS, wpid, NULL, 1), 0);
1456 /* Continue the child ignoring the SIGSTOP. */
1457 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1459 /* The first event should be for the child thread's birth. */
1460 wpid = waitpid(fpid, &status, 0);
1461 REQUIRE_EQ(wpid, fpid);
1462 ATF_REQUIRE(WIFSTOPPED(status));
1463 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1465 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1466 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)),
1467 (PL_FLAG_BORN | PL_FLAG_SCX));
1468 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
1469 lwps[1] = pl.pl_lwpid;
1471 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1474 * The next event should be for the main thread's death due to
1475 * single threading from execve().
1477 wpid = waitpid(fpid, &status, 0);
1478 REQUIRE_EQ(wpid, fpid);
1479 ATF_REQUIRE(WIFSTOPPED(status));
1480 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1482 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1483 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_EXITED | PL_FLAG_SCE)),
1485 REQUIRE_EQ(pl.pl_lwpid, lwps[0]);
1487 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1489 /* The next event should be for the child process's exec. */
1490 wpid = waitpid(fpid, &status, 0);
1491 ATF_REQUIRE(WIFSTOPPED(status));
1492 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1494 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1495 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_EXEC | PL_FLAG_SCX)),
1496 (PL_FLAG_EXEC | PL_FLAG_SCX));
1497 REQUIRE_EQ(pl.pl_lwpid, lwps[1]);
1499 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1501 /* The last event should be for the child process's exit. */
1502 wpid = waitpid(fpid, &status, 0);
1503 ATF_REQUIRE(WIFEXITED(status));
1504 REQUIRE_EQ(WEXITSTATUS(status), 0);
1506 wpid = wait(&status);
1507 REQUIRE_EQ(wpid, -1);
1508 REQUIRE_EQ(errno, ECHILD);
1512 handler(int sig __unused)
1520 signal(SIGINFO, handler);
1526 * Verify that the expected ptrace event is reported for a signal.
1528 ATF_TC_WITHOUT_HEAD(ptrace__siginfo);
1529 ATF_TC_BODY(ptrace__siginfo, tc)
1531 struct ptrace_lwpinfo pl;
1535 ATF_REQUIRE((fpid = fork()) != -1);
1541 /* The first wait() should report the stop from SIGSTOP. */
1542 wpid = waitpid(fpid, &status, 0);
1543 REQUIRE_EQ(wpid, fpid);
1544 ATF_REQUIRE(WIFSTOPPED(status));
1545 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1547 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1549 /* The next event should be for the SIGINFO. */
1550 wpid = waitpid(fpid, &status, 0);
1551 ATF_REQUIRE(WIFSTOPPED(status));
1552 REQUIRE_EQ(WSTOPSIG(status), SIGINFO);
1554 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1555 REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL);
1556 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
1557 REQUIRE_EQ(pl.pl_siginfo.si_code, SI_LWP);
1558 REQUIRE_EQ(pl.pl_siginfo.si_pid, wpid);
1560 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1562 /* The last event should be for the child process's exit. */
1563 wpid = waitpid(fpid, &status, 0);
1564 ATF_REQUIRE(WIFEXITED(status));
1565 REQUIRE_EQ(WEXITSTATUS(status), 0);
1567 wpid = wait(&status);
1568 REQUIRE_EQ(wpid, -1);
1569 REQUIRE_EQ(errno, ECHILD);
1573 * Verify that the expected ptrace events are reported for PTRACE_EXEC.
1575 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_exec_disable);
1576 ATF_TC_BODY(ptrace__ptrace_exec_disable, tc)
1581 ATF_REQUIRE((fpid = fork()) != -1);
1587 /* The first wait() should report the stop from SIGSTOP. */
1588 wpid = waitpid(fpid, &status, 0);
1589 REQUIRE_EQ(wpid, fpid);
1590 ATF_REQUIRE(WIFSTOPPED(status));
1591 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1594 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1595 sizeof(events)) == 0);
1597 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1599 /* Should get one event at exit. */
1600 wpid = waitpid(fpid, &status, 0);
1601 ATF_REQUIRE(WIFEXITED(status));
1602 REQUIRE_EQ(WEXITSTATUS(status), 0);
1604 wpid = wait(&status);
1605 REQUIRE_EQ(wpid, -1);
1606 REQUIRE_EQ(errno, ECHILD);
1609 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_exec_enable);
1610 ATF_TC_BODY(ptrace__ptrace_exec_enable, tc)
1612 struct ptrace_lwpinfo pl;
1616 ATF_REQUIRE((fpid = fork()) != -1);
1622 /* The first wait() should report the stop from SIGSTOP. */
1623 wpid = waitpid(fpid, &status, 0);
1624 REQUIRE_EQ(wpid, fpid);
1625 ATF_REQUIRE(WIFSTOPPED(status));
1626 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1628 events = PTRACE_EXEC;
1629 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1630 sizeof(events)) == 0);
1632 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1634 /* The next event should be for the child process's exec. */
1635 wpid = waitpid(fpid, &status, 0);
1636 ATF_REQUIRE(WIFSTOPPED(status));
1637 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1639 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1640 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_EXEC | PL_FLAG_SCX)),
1641 (PL_FLAG_EXEC | PL_FLAG_SCX));
1643 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1645 /* The last event should be for the child process's exit. */
1646 wpid = waitpid(fpid, &status, 0);
1647 ATF_REQUIRE(WIFEXITED(status));
1648 REQUIRE_EQ(WEXITSTATUS(status), 0);
1650 wpid = wait(&status);
1651 REQUIRE_EQ(wpid, -1);
1652 REQUIRE_EQ(errno, ECHILD);
1655 ATF_TC_WITHOUT_HEAD(ptrace__event_mask);
1656 ATF_TC_BODY(ptrace__event_mask, tc)
1661 ATF_REQUIRE((fpid = fork()) != -1);
1667 /* The first wait() should report the stop from SIGSTOP. */
1668 wpid = waitpid(fpid, &status, 0);
1669 REQUIRE_EQ(wpid, fpid);
1670 ATF_REQUIRE(WIFSTOPPED(status));
1671 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1673 /* PT_FOLLOW_FORK should toggle the state of PTRACE_FORK. */
1674 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, fpid, NULL, 1) != -1);
1675 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1676 sizeof(events)) == 0);
1677 ATF_REQUIRE(events & PTRACE_FORK);
1678 ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, fpid, NULL, 0) != -1);
1679 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1680 sizeof(events)) == 0);
1681 ATF_REQUIRE(!(events & PTRACE_FORK));
1683 /* PT_LWP_EVENTS should toggle the state of PTRACE_LWP. */
1684 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, fpid, NULL, 1) != -1);
1685 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1686 sizeof(events)) == 0);
1687 ATF_REQUIRE(events & PTRACE_LWP);
1688 ATF_REQUIRE(ptrace(PT_LWP_EVENTS, fpid, NULL, 0) != -1);
1689 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1690 sizeof(events)) == 0);
1691 ATF_REQUIRE(!(events & PTRACE_LWP));
1693 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1695 /* Should get one event at exit. */
1696 wpid = waitpid(fpid, &status, 0);
1697 ATF_REQUIRE(WIFEXITED(status));
1698 REQUIRE_EQ(WEXITSTATUS(status), 0);
1700 wpid = wait(&status);
1701 REQUIRE_EQ(wpid, -1);
1702 REQUIRE_EQ(errno, ECHILD);
1706 * Verify that the expected ptrace events are reported for PTRACE_VFORK.
1708 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_vfork);
1709 ATF_TC_BODY(ptrace__ptrace_vfork, tc)
1711 struct ptrace_lwpinfo pl;
1715 ATF_REQUIRE((fpid = fork()) != -1);
1718 follow_fork_parent(true);
1721 /* The first wait() should report the stop from SIGSTOP. */
1722 wpid = waitpid(fpid, &status, 0);
1723 REQUIRE_EQ(wpid, fpid);
1724 ATF_REQUIRE(WIFSTOPPED(status));
1725 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1727 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
1728 sizeof(events)) == 0);
1729 events |= PTRACE_VFORK;
1730 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
1731 sizeof(events)) == 0);
1733 /* Continue the child ignoring the SIGSTOP. */
1734 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) != -1);
1736 /* The next event should report the end of the vfork. */
1737 wpid = wait(&status);
1738 REQUIRE_EQ(wpid, fpid);
1739 ATF_REQUIRE(WIFSTOPPED(status));
1740 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1741 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1742 ATF_REQUIRE((pl.pl_flags & PL_FLAG_VFORK_DONE) != 0);
1744 ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) != -1);
1746 wpid = wait(&status);
1747 REQUIRE_EQ(wpid, fpid);
1748 ATF_REQUIRE(WIFEXITED(status));
1749 REQUIRE_EQ(WEXITSTATUS(status), 1);
1751 wpid = wait(&status);
1752 REQUIRE_EQ(wpid, -1);
1753 REQUIRE_EQ(errno, ECHILD);
1756 ATF_TC_WITHOUT_HEAD(ptrace__ptrace_vfork_follow);
1757 ATF_TC_BODY(ptrace__ptrace_vfork_follow, tc)
1759 struct ptrace_lwpinfo pl[2];
1760 pid_t children[2], fpid, wpid;
1763 ATF_REQUIRE((fpid = fork()) != -1);
1766 follow_fork_parent(true);
1769 /* Parent process. */
1772 /* The first wait() should report the stop from SIGSTOP. */
1773 wpid = waitpid(children[0], &status, 0);
1774 REQUIRE_EQ(wpid, children[0]);
1775 ATF_REQUIRE(WIFSTOPPED(status));
1776 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1778 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, children[0], (caddr_t)&events,
1779 sizeof(events)) == 0);
1780 events |= PTRACE_FORK | PTRACE_VFORK;
1781 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, children[0], (caddr_t)&events,
1782 sizeof(events)) == 0);
1784 /* Continue the child ignoring the SIGSTOP. */
1785 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1787 /* Wait for both halves of the fork event to get reported. */
1788 children[1] = handle_fork_events(children[0], pl);
1789 ATF_REQUIRE(children[1] > 0);
1791 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_VFORKED) != 0);
1793 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1794 ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
1797 * The child can't exit until the grandchild reports status, so the
1798 * grandchild should report its exit first to the debugger.
1800 wpid = waitpid(children[1], &status, 0);
1801 REQUIRE_EQ(wpid, children[1]);
1802 ATF_REQUIRE(WIFEXITED(status));
1803 REQUIRE_EQ(WEXITSTATUS(status), 2);
1806 * The child should report it's vfork() completion before it
1809 wpid = wait(&status);
1810 REQUIRE_EQ(wpid, children[0]);
1811 ATF_REQUIRE(WIFSTOPPED(status));
1812 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1813 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl[0], sizeof(pl[0])) !=
1815 ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_VFORK_DONE) != 0);
1817 ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
1819 wpid = wait(&status);
1820 REQUIRE_EQ(wpid, children[0]);
1821 ATF_REQUIRE(WIFEXITED(status));
1822 REQUIRE_EQ(WEXITSTATUS(status), 1);
1824 wpid = wait(&status);
1825 REQUIRE_EQ(wpid, -1);
1826 REQUIRE_EQ(errno, ECHILD);
1829 #ifdef HAVE_BREAKPOINT
1831 * Verify that no more events are reported after PT_KILL except for the
1832 * process exit when stopped due to a breakpoint trap.
1834 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_breakpoint);
1835 ATF_TC_BODY(ptrace__PT_KILL_breakpoint, tc)
1840 ATF_REQUIRE((fpid = fork()) != -1);
1847 /* The first wait() should report the stop from SIGSTOP. */
1848 wpid = waitpid(fpid, &status, 0);
1849 REQUIRE_EQ(wpid, fpid);
1850 ATF_REQUIRE(WIFSTOPPED(status));
1851 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1853 /* Continue the child ignoring the SIGSTOP. */
1854 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1856 /* The second wait() should report hitting the breakpoint. */
1857 wpid = waitpid(fpid, &status, 0);
1858 REQUIRE_EQ(wpid, fpid);
1859 ATF_REQUIRE(WIFSTOPPED(status));
1860 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1862 /* Kill the child process. */
1863 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
1865 /* The last wait() should report the SIGKILL. */
1866 wpid = waitpid(fpid, &status, 0);
1867 REQUIRE_EQ(wpid, fpid);
1868 ATF_REQUIRE(WIFSIGNALED(status));
1869 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
1871 wpid = wait(&status);
1872 REQUIRE_EQ(wpid, -1);
1873 REQUIRE_EQ(errno, ECHILD);
1875 #endif /* HAVE_BREAKPOINT */
1878 * Verify that no more events are reported after PT_KILL except for the
1879 * process exit when stopped inside of a system call.
1881 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_system_call);
1882 ATF_TC_BODY(ptrace__PT_KILL_system_call, tc)
1884 struct ptrace_lwpinfo pl;
1888 ATF_REQUIRE((fpid = fork()) != -1);
1895 /* The first wait() should report the stop from SIGSTOP. */
1896 wpid = waitpid(fpid, &status, 0);
1897 REQUIRE_EQ(wpid, fpid);
1898 ATF_REQUIRE(WIFSTOPPED(status));
1899 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1901 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
1902 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
1904 /* The second wait() should report a system call entry for getpid(). */
1905 wpid = waitpid(fpid, &status, 0);
1906 REQUIRE_EQ(wpid, fpid);
1907 ATF_REQUIRE(WIFSTOPPED(status));
1908 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1910 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1911 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
1913 /* Kill the child process. */
1914 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
1916 /* The last wait() should report the SIGKILL. */
1917 wpid = waitpid(fpid, &status, 0);
1918 REQUIRE_EQ(wpid, fpid);
1919 ATF_REQUIRE(WIFSIGNALED(status));
1920 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
1922 wpid = wait(&status);
1923 REQUIRE_EQ(wpid, -1);
1924 REQUIRE_EQ(errno, ECHILD);
1928 * Verify that no more events are reported after PT_KILL except for the
1929 * process exit when killing a multithreaded process.
1931 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_threads);
1932 ATF_TC_BODY(ptrace__PT_KILL_threads, tc)
1934 struct ptrace_lwpinfo pl;
1939 ATF_REQUIRE((fpid = fork()) != -1);
1942 simple_thread_main();
1945 /* The first wait() should report the stop from SIGSTOP. */
1946 wpid = waitpid(fpid, &status, 0);
1947 REQUIRE_EQ(wpid, fpid);
1948 ATF_REQUIRE(WIFSTOPPED(status));
1949 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
1951 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
1953 main_lwp = pl.pl_lwpid;
1955 REQUIRE_EQ(ptrace(PT_LWP_EVENTS, wpid, NULL, 1), 0);
1957 /* Continue the child ignoring the SIGSTOP. */
1958 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
1960 /* The first event should be for the child thread's birth. */
1961 wpid = waitpid(fpid, &status, 0);
1962 REQUIRE_EQ(wpid, fpid);
1963 ATF_REQUIRE(WIFSTOPPED(status));
1964 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
1966 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
1967 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)),
1968 (PL_FLAG_BORN | PL_FLAG_SCX));
1969 ATF_REQUIRE(pl.pl_lwpid != main_lwp);
1971 /* Kill the child process. */
1972 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
1974 /* The last wait() should report the SIGKILL. */
1975 wpid = waitpid(fpid, &status, 0);
1976 REQUIRE_EQ(wpid, fpid);
1977 ATF_REQUIRE(WIFSIGNALED(status));
1978 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
1980 wpid = wait(&status);
1981 REQUIRE_EQ(wpid, -1);
1982 REQUIRE_EQ(errno, ECHILD);
1986 mask_usr1_thread(void *arg)
1988 pthread_barrier_t *pbarrier;
1991 pbarrier = (pthread_barrier_t*)arg;
1993 sigemptyset(&sigmask);
1994 sigaddset(&sigmask, SIGUSR1);
1995 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_BLOCK, &sigmask, NULL), 0);
1997 /* Sync up with other thread after sigmask updated. */
1998 pthread_barrier_wait(pbarrier);
2007 * Verify that the SIGKILL from PT_KILL takes priority over other signals
2008 * and prevents spurious stops due to those other signals.
2010 ATF_TC(ptrace__PT_KILL_competing_signal);
2011 ATF_TC_HEAD(ptrace__PT_KILL_competing_signal, tc)
2014 atf_tc_set_md_var(tc, "require.user", "root");
2016 ATF_TC_BODY(ptrace__PT_KILL_competing_signal, tc)
2022 pthread_barrier_t barrier;
2023 struct sched_param sched_param;
2025 ATF_REQUIRE((fpid = fork()) != -1);
2027 /* Bind to one CPU so only one thread at a time will run. */
2029 CPU_SET(0, &setmask);
2031 CHILD_REQUIRE_EQ(cpuset(&setid), 0);
2032 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
2033 CPU_WHICH_CPUSET, setid, sizeof(setmask), &setmask) == 0);
2035 CHILD_REQUIRE_EQ(pthread_barrier_init(&barrier, NULL, 2), 0);
2037 CHILD_REQUIRE(pthread_create(&t, NULL, mask_usr1_thread,
2038 (void*)&barrier) == 0);
2041 * Give the main thread higher priority. The test always
2042 * assumes that, if both threads are able to run, the main
2043 * thread runs first.
2045 sched_param.sched_priority =
2046 (sched_get_priority_max(SCHED_FIFO) +
2047 sched_get_priority_min(SCHED_FIFO)) / 2;
2048 CHILD_REQUIRE(pthread_setschedparam(pthread_self(),
2049 SCHED_FIFO, &sched_param) == 0);
2050 sched_param.sched_priority -= RQ_PPQ;
2051 CHILD_REQUIRE(pthread_setschedparam(t, SCHED_FIFO,
2052 &sched_param) == 0);
2055 sigemptyset(&sigmask);
2056 sigaddset(&sigmask, SIGUSR2);
2057 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_BLOCK, &sigmask, NULL), 0);
2059 /* Sync up with other thread after sigmask updated. */
2060 pthread_barrier_wait(&barrier);
2070 /* The first wait() should report the stop from SIGSTOP. */
2071 wpid = waitpid(fpid, &status, 0);
2072 REQUIRE_EQ(wpid, fpid);
2073 ATF_REQUIRE(WIFSTOPPED(status));
2074 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2076 /* Continue the child ignoring the SIGSTOP. */
2077 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2079 /* Send a signal that only the second thread can handle. */
2080 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
2082 /* The second wait() should report the SIGUSR2. */
2083 wpid = waitpid(fpid, &status, 0);
2084 REQUIRE_EQ(wpid, fpid);
2085 ATF_REQUIRE(WIFSTOPPED(status));
2086 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
2088 /* Send a signal that only the first thread can handle. */
2089 REQUIRE_EQ(kill(fpid, SIGUSR1), 0);
2091 /* Replace the SIGUSR2 with a kill. */
2092 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
2094 /* The last wait() should report the SIGKILL (not the SIGUSR signal). */
2095 wpid = waitpid(fpid, &status, 0);
2096 REQUIRE_EQ(wpid, fpid);
2097 ATF_REQUIRE(WIFSIGNALED(status));
2098 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
2100 wpid = wait(&status);
2101 REQUIRE_EQ(wpid, -1);
2102 REQUIRE_EQ(errno, ECHILD);
2106 * Verify that the SIGKILL from PT_KILL takes priority over other stop events
2107 * and prevents spurious stops caused by those events.
2109 ATF_TC(ptrace__PT_KILL_competing_stop);
2110 ATF_TC_HEAD(ptrace__PT_KILL_competing_stop, tc)
2113 atf_tc_set_md_var(tc, "require.user", "root");
2115 ATF_TC_BODY(ptrace__PT_KILL_competing_stop, tc)
2121 pthread_barrier_t barrier;
2123 struct ptrace_lwpinfo pl;
2124 struct sched_param sched_param;
2126 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
2127 atf_tc_skip("https://bugs.freebsd.org/220841");
2129 ATF_REQUIRE((fpid = fork()) != -1);
2133 /* Bind to one CPU so only one thread at a time will run. */
2135 CPU_SET(0, &setmask);
2137 CHILD_REQUIRE_EQ(cpuset(&setid), 0);
2138 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
2139 CPU_WHICH_CPUSET, setid, sizeof(setmask), &setmask) == 0);
2141 CHILD_REQUIRE_EQ(pthread_barrier_init(&barrier, NULL, 2), 0);
2143 CHILD_REQUIRE(pthread_create(&t, NULL, mask_usr1_thread,
2144 (void*)&barrier) == 0);
2147 * Give the main thread higher priority. The test always
2148 * assumes that, if both threads are able to run, the main
2149 * thread runs first.
2151 sched_param.sched_priority =
2152 (sched_get_priority_max(SCHED_FIFO) +
2153 sched_get_priority_min(SCHED_FIFO)) / 2;
2154 CHILD_REQUIRE(pthread_setschedparam(pthread_self(),
2155 SCHED_FIFO, &sched_param) == 0);
2156 sched_param.sched_priority -= RQ_PPQ;
2157 CHILD_REQUIRE(pthread_setschedparam(t, SCHED_FIFO,
2158 &sched_param) == 0);
2161 sigemptyset(&sigmask);
2162 sigaddset(&sigmask, SIGUSR2);
2163 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_BLOCK, &sigmask, NULL), 0);
2165 /* Sync up with other thread after sigmask updated. */
2166 pthread_barrier_wait(&barrier);
2168 /* Sync up with the test before doing the getpid(). */
2175 /* The first wait() should report the stop from SIGSTOP. */
2176 wpid = waitpid(fpid, &status, 0);
2177 REQUIRE_EQ(wpid, fpid);
2178 ATF_REQUIRE(WIFSTOPPED(status));
2179 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2181 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2182 main_lwp = pl.pl_lwpid;
2184 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2185 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2188 * Continue until child is done with setup, which is indicated with
2189 * SIGSTOP. Ignore system calls in the meantime.
2192 wpid = waitpid(fpid, &status, 0);
2193 REQUIRE_EQ(wpid, fpid);
2194 ATF_REQUIRE(WIFSTOPPED(status));
2195 if (WSTOPSIG(status) == SIGTRAP) {
2196 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
2198 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2200 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2203 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2206 /* Proceed, allowing main thread to hit syscall entry for getpid(). */
2207 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2209 wpid = waitpid(fpid, &status, 0);
2210 REQUIRE_EQ(wpid, fpid);
2211 ATF_REQUIRE(WIFSTOPPED(status));
2212 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2214 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
2216 REQUIRE_EQ(pl.pl_lwpid, main_lwp);
2217 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2218 /* Prevent the main thread from hitting its syscall exit for now. */
2219 REQUIRE_EQ(ptrace(PT_SUSPEND, main_lwp, 0, 0), 0);
2222 * Proceed, allowing second thread to hit syscall exit for
2223 * pthread_barrier_wait().
2225 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2227 wpid = waitpid(fpid, &status, 0);
2228 REQUIRE_EQ(wpid, fpid);
2229 ATF_REQUIRE(WIFSTOPPED(status));
2230 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2232 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
2234 ATF_REQUIRE(pl.pl_lwpid != main_lwp);
2235 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2237 /* Send a signal that only the second thread can handle. */
2238 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
2240 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2242 /* The next wait() should report the SIGUSR2. */
2243 wpid = waitpid(fpid, &status, 0);
2244 REQUIRE_EQ(wpid, fpid);
2245 ATF_REQUIRE(WIFSTOPPED(status));
2246 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
2248 /* Allow the main thread to try to finish its system call. */
2249 REQUIRE_EQ(ptrace(PT_RESUME, main_lwp, 0, 0), 0);
2252 * At this point, the main thread is in the middle of a system call and
2253 * has been resumed. The second thread has taken a SIGUSR2 which will
2254 * be replaced with a SIGKILL below. The main thread will get to run
2255 * first. It should notice the kill request (even though the signal
2256 * replacement occurred in the other thread) and exit accordingly. It
2257 * should not stop for the system call exit event.
2260 /* Replace the SIGUSR2 with a kill. */
2261 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
2263 /* The last wait() should report the SIGKILL (not a syscall exit). */
2264 wpid = waitpid(fpid, &status, 0);
2265 REQUIRE_EQ(wpid, fpid);
2266 ATF_REQUIRE(WIFSIGNALED(status));
2267 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
2269 wpid = wait(&status);
2270 REQUIRE_EQ(wpid, -1);
2271 REQUIRE_EQ(errno, ECHILD);
2275 sigusr1_handler(int sig)
2278 CHILD_REQUIRE_EQ(sig, SIGUSR1);
2283 * Verify that even if the signal queue is full for a child process,
2284 * a PT_KILL will kill the process.
2286 ATF_TC_WITHOUT_HEAD(ptrace__PT_KILL_with_signal_full_sigqueue);
2287 ATF_TC_BODY(ptrace__PT_KILL_with_signal_full_sigqueue, tc)
2291 int max_pending_per_proc;
2295 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2297 ATF_REQUIRE((fpid = fork()) != -1);
2303 /* The first wait() should report the stop from SIGSTOP. */
2304 wpid = waitpid(fpid, &status, 0);
2305 REQUIRE_EQ(wpid, fpid);
2306 ATF_REQUIRE(WIFSTOPPED(status));
2307 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2309 len = sizeof(max_pending_per_proc);
2310 ATF_REQUIRE(sysctlbyname("kern.sigqueue.max_pending_per_proc",
2311 &max_pending_per_proc, &len, NULL, 0) == 0);
2313 /* Fill the signal queue. */
2314 for (i = 0; i < max_pending_per_proc; ++i)
2315 REQUIRE_EQ(kill(fpid, SIGUSR1), 0);
2317 /* Kill the child process. */
2318 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
2320 /* The last wait() should report the SIGKILL. */
2321 wpid = waitpid(fpid, &status, 0);
2322 REQUIRE_EQ(wpid, fpid);
2323 ATF_REQUIRE(WIFSIGNALED(status));
2324 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
2326 wpid = wait(&status);
2327 REQUIRE_EQ(wpid, -1);
2328 REQUIRE_EQ(errno, ECHILD);
2332 * Verify that when stopped at a system call entry, a signal can be
2333 * requested with PT_CONTINUE which will be delivered once the system
2336 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_system_call_entry);
2337 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_system_call_entry, tc)
2339 struct ptrace_lwpinfo pl;
2343 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2345 ATF_REQUIRE((fpid = fork()) != -1);
2352 /* The first wait() should report the stop from SIGSTOP. */
2353 wpid = waitpid(fpid, &status, 0);
2354 REQUIRE_EQ(wpid, fpid);
2355 ATF_REQUIRE(WIFSTOPPED(status));
2356 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2358 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2359 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2361 /* The second wait() should report a system call entry for getpid(). */
2362 wpid = waitpid(fpid, &status, 0);
2363 REQUIRE_EQ(wpid, fpid);
2364 ATF_REQUIRE(WIFSTOPPED(status));
2365 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2367 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2368 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2370 /* Continue the child process with a signal. */
2371 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2375 * The last wait() should report exit 2, i.e., a normal _exit
2376 * from the signal handler. In the meantime, catch and proceed
2377 * past any syscall stops.
2379 wpid = waitpid(fpid, &status, 0);
2380 REQUIRE_EQ(wpid, fpid);
2381 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2382 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2383 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2384 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2386 ATF_REQUIRE(WIFEXITED(status));
2387 REQUIRE_EQ(WEXITSTATUS(status), 2);
2392 wpid = wait(&status);
2393 REQUIRE_EQ(wpid, -1);
2394 REQUIRE_EQ(errno, ECHILD);
2398 sigusr1_counting_handler(int sig)
2400 static int counter = 0;
2402 CHILD_REQUIRE_EQ(sig, SIGUSR1);
2409 * Verify that, when continuing from a stop at system call entry and exit,
2410 * a signal can be requested from both stops, and both will be delivered when
2411 * the system call is complete.
2413 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit);
2414 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit, tc)
2416 struct ptrace_lwpinfo pl;
2420 ATF_REQUIRE(signal(SIGUSR1, sigusr1_counting_handler) != SIG_ERR);
2422 ATF_REQUIRE((fpid = fork()) != -1);
2429 /* The first wait() should report the stop from SIGSTOP. */
2430 wpid = waitpid(fpid, &status, 0);
2431 REQUIRE_EQ(wpid, fpid);
2432 ATF_REQUIRE(WIFSTOPPED(status));
2433 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2435 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2436 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2438 /* The second wait() should report a system call entry for getpid(). */
2439 wpid = waitpid(fpid, &status, 0);
2440 REQUIRE_EQ(wpid, fpid);
2441 ATF_REQUIRE(WIFSTOPPED(status));
2442 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2444 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2445 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2447 /* Continue the child process with a signal. */
2448 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2450 /* The third wait() should report a system call exit for getpid(). */
2451 wpid = waitpid(fpid, &status, 0);
2452 REQUIRE_EQ(wpid, fpid);
2453 ATF_REQUIRE(WIFSTOPPED(status));
2454 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2456 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2457 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2459 /* Continue the child process with a signal. */
2460 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2464 * The last wait() should report exit 2, i.e., a normal _exit
2465 * from the signal handler. In the meantime, catch and proceed
2466 * past any syscall stops.
2468 wpid = waitpid(fpid, &status, 0);
2469 REQUIRE_EQ(wpid, fpid);
2470 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2471 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2472 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2473 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2475 ATF_REQUIRE(WIFEXITED(status));
2476 REQUIRE_EQ(WEXITSTATUS(status), 2);
2481 wpid = wait(&status);
2482 REQUIRE_EQ(wpid, -1);
2483 REQUIRE_EQ(errno, ECHILD);
2487 * Verify that even if the signal queue is full for a child process,
2488 * a PT_CONTINUE with a signal will not result in loss of that signal.
2490 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_full_sigqueue);
2491 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_full_sigqueue, tc)
2495 int max_pending_per_proc;
2499 ATF_REQUIRE(signal(SIGUSR2, handler) != SIG_ERR);
2500 ATF_REQUIRE(signal(SIGUSR1, sigusr1_handler) != SIG_ERR);
2502 ATF_REQUIRE((fpid = fork()) != -1);
2508 /* The first wait() should report the stop from SIGSTOP. */
2509 wpid = waitpid(fpid, &status, 0);
2510 REQUIRE_EQ(wpid, fpid);
2511 ATF_REQUIRE(WIFSTOPPED(status));
2512 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2514 len = sizeof(max_pending_per_proc);
2515 ATF_REQUIRE(sysctlbyname("kern.sigqueue.max_pending_per_proc",
2516 &max_pending_per_proc, &len, NULL, 0) == 0);
2518 /* Fill the signal queue. */
2519 for (i = 0; i < max_pending_per_proc; ++i)
2520 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
2522 /* Continue with signal. */
2523 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2526 wpid = waitpid(fpid, &status, 0);
2527 REQUIRE_EQ(wpid, fpid);
2528 if (WIFSTOPPED(status)) {
2529 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
2530 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2533 * The last wait() should report normal _exit from the
2536 ATF_REQUIRE(WIFEXITED(status));
2537 REQUIRE_EQ(WEXITSTATUS(status), 2);
2542 wpid = wait(&status);
2543 REQUIRE_EQ(wpid, -1);
2544 REQUIRE_EQ(errno, ECHILD);
2547 static sem_t sigusr1_sem;
2548 static int got_usr1;
2551 sigusr1_sempost_handler(int sig __unused)
2555 CHILD_REQUIRE_EQ(sem_post(&sigusr1_sem), 0);
2559 * Verify that even if the signal queue is full for a child process,
2560 * and the signal is masked, a PT_CONTINUE with a signal will not
2561 * result in loss of that signal.
2563 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_masked_full_sigqueue);
2564 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_masked_full_sigqueue, tc)
2566 struct ptrace_lwpinfo pl;
2569 int max_pending_per_proc;
2574 ATF_REQUIRE(signal(SIGUSR2, handler) != SIG_ERR);
2575 REQUIRE_EQ(sem_init(&sigusr1_sem, 0, 0), 0);
2576 ATF_REQUIRE(signal(SIGUSR1, sigusr1_sempost_handler) != SIG_ERR);
2579 ATF_REQUIRE((fpid = fork()) != -1);
2581 CHILD_REQUIRE_EQ(sigemptyset(&sigmask), 0);
2582 CHILD_REQUIRE_EQ(sigaddset(&sigmask, SIGUSR1), 0);
2583 CHILD_REQUIRE_EQ(sigprocmask(SIG_BLOCK, &sigmask, NULL), 0);
2586 CHILD_REQUIRE_EQ(got_usr1, 0);
2588 /* Allow the pending SIGUSR1 in now. */
2589 CHILD_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &sigmask, NULL), 0);
2590 /* Wait to receive the SIGUSR1. */
2592 err = sem_wait(&sigusr1_sem);
2593 CHILD_REQUIRE(err == 0 || errno == EINTR);
2594 } while (err != 0 && errno == EINTR);
2595 CHILD_REQUIRE_EQ(got_usr1, 1);
2599 /* The first wait() should report the stop from SIGSTOP. */
2600 wpid = waitpid(fpid, &status, 0);
2601 REQUIRE_EQ(wpid, fpid);
2602 ATF_REQUIRE(WIFSTOPPED(status));
2603 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2605 len = sizeof(max_pending_per_proc);
2606 ATF_REQUIRE(sysctlbyname("kern.sigqueue.max_pending_per_proc",
2607 &max_pending_per_proc, &len, NULL, 0) == 0);
2609 /* Fill the signal queue. */
2610 for (i = 0; i < max_pending_per_proc; ++i)
2611 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
2613 /* Continue with signal. */
2614 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2616 /* Collect and ignore all of the SIGUSR2. */
2617 for (i = 0; i < max_pending_per_proc; ++i) {
2618 wpid = waitpid(fpid, &status, 0);
2619 REQUIRE_EQ(wpid, fpid);
2620 ATF_REQUIRE(WIFSTOPPED(status));
2621 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
2622 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2625 /* Now our PT_CONTINUE'd SIGUSR1 should cause a stop after unmask. */
2626 wpid = waitpid(fpid, &status, 0);
2627 REQUIRE_EQ(wpid, fpid);
2628 ATF_REQUIRE(WIFSTOPPED(status));
2629 REQUIRE_EQ(WSTOPSIG(status), SIGUSR1);
2630 ATF_REQUIRE(ptrace(PT_LWPINFO, fpid, (caddr_t)&pl, sizeof(pl)) != -1);
2631 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGUSR1);
2633 /* Continue the child, ignoring the SIGUSR1. */
2634 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2636 /* The last wait() should report exit after receiving SIGUSR1. */
2637 wpid = waitpid(fpid, &status, 0);
2638 REQUIRE_EQ(wpid, fpid);
2639 ATF_REQUIRE(WIFEXITED(status));
2640 REQUIRE_EQ(WEXITSTATUS(status), 1);
2642 wpid = wait(&status);
2643 REQUIRE_EQ(wpid, -1);
2644 REQUIRE_EQ(errno, ECHILD);
2648 * Verify that, after stopping due to a signal, that signal can be
2649 * replaced with another signal.
2651 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_change_sig);
2652 ATF_TC_BODY(ptrace__PT_CONTINUE_change_sig, tc)
2654 struct ptrace_lwpinfo pl;
2658 ATF_REQUIRE((fpid = fork()) != -1);
2665 /* The first wait() should report the stop from SIGSTOP. */
2666 wpid = waitpid(fpid, &status, 0);
2667 REQUIRE_EQ(wpid, fpid);
2668 ATF_REQUIRE(WIFSTOPPED(status));
2669 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2671 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2673 /* Send a signal without ptrace. */
2674 REQUIRE_EQ(kill(fpid, SIGINT), 0);
2676 /* The second wait() should report a SIGINT was received. */
2677 wpid = waitpid(fpid, &status, 0);
2678 REQUIRE_EQ(wpid, fpid);
2679 ATF_REQUIRE(WIFSTOPPED(status));
2680 REQUIRE_EQ(WSTOPSIG(status), SIGINT);
2682 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2683 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
2684 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGINT);
2686 /* Continue the child process with a different signal. */
2687 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGTERM), 0);
2690 * The last wait() should report having died due to the new
2693 wpid = waitpid(fpid, &status, 0);
2694 REQUIRE_EQ(wpid, fpid);
2695 ATF_REQUIRE(WIFSIGNALED(status));
2696 REQUIRE_EQ(WTERMSIG(status), SIGTERM);
2698 wpid = wait(&status);
2699 REQUIRE_EQ(wpid, -1);
2700 REQUIRE_EQ(errno, ECHILD);
2704 * Verify that a signal can be passed through to the child even when there
2705 * was no true signal originally. Such cases arise when a SIGTRAP is
2706 * invented for e.g, system call stops.
2708 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_sigtrap_system_call_entry);
2709 ATF_TC_BODY(ptrace__PT_CONTINUE_with_sigtrap_system_call_entry, tc)
2711 struct ptrace_lwpinfo pl;
2716 ATF_REQUIRE((fpid = fork()) != -1);
2719 /* SIGTRAP expected to cause exit on syscall entry. */
2720 rl.rlim_cur = rl.rlim_max = 0;
2721 REQUIRE_EQ(setrlimit(RLIMIT_CORE, &rl), 0);
2726 /* The first wait() should report the stop from SIGSTOP. */
2727 wpid = waitpid(fpid, &status, 0);
2728 REQUIRE_EQ(wpid, fpid);
2729 ATF_REQUIRE(WIFSTOPPED(status));
2730 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2732 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2733 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2735 /* The second wait() should report a system call entry for getpid(). */
2736 wpid = waitpid(fpid, &status, 0);
2737 REQUIRE_EQ(wpid, fpid);
2738 ATF_REQUIRE(WIFSTOPPED(status));
2739 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2741 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2742 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2744 /* Continue the child process with a SIGTRAP. */
2745 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGTRAP), 0);
2749 * The last wait() should report exit due to SIGTRAP. In the
2750 * meantime, catch and proceed past any syscall stops.
2752 wpid = waitpid(fpid, &status, 0);
2753 REQUIRE_EQ(wpid, fpid);
2754 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2755 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2756 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2757 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2759 ATF_REQUIRE(WIFSIGNALED(status));
2760 REQUIRE_EQ(WTERMSIG(status), SIGTRAP);
2765 wpid = wait(&status);
2766 REQUIRE_EQ(wpid, -1);
2767 REQUIRE_EQ(errno, ECHILD);
2771 * A mixed bag PT_CONTINUE with signal test.
2773 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_mix);
2774 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_mix, tc)
2776 struct ptrace_lwpinfo pl;
2780 ATF_REQUIRE(signal(SIGUSR1, sigusr1_counting_handler) != SIG_ERR);
2782 ATF_REQUIRE((fpid = fork()) != -1);
2789 /* The first wait() should report the stop from SIGSTOP. */
2790 wpid = waitpid(fpid, &status, 0);
2791 REQUIRE_EQ(wpid, fpid);
2792 ATF_REQUIRE(WIFSTOPPED(status));
2793 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2795 /* Continue the child ignoring the SIGSTOP and tracing system calls. */
2796 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
2798 /* The second wait() should report a system call entry for getpid(). */
2799 wpid = waitpid(fpid, &status, 0);
2800 REQUIRE_EQ(wpid, fpid);
2801 ATF_REQUIRE(WIFSTOPPED(status));
2802 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2804 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2805 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
2807 /* Continue with the first SIGUSR1. */
2808 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2810 /* The next wait() should report a system call exit for getpid(). */
2811 wpid = waitpid(fpid, &status, 0);
2812 REQUIRE_EQ(wpid, fpid);
2813 ATF_REQUIRE(WIFSTOPPED(status));
2814 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
2816 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2817 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
2819 /* Send an ABRT without ptrace. */
2820 REQUIRE_EQ(kill(fpid, SIGABRT), 0);
2822 /* Continue normally. */
2823 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2825 /* The next wait() should report the SIGABRT. */
2826 wpid = waitpid(fpid, &status, 0);
2827 REQUIRE_EQ(wpid, fpid);
2828 ATF_REQUIRE(WIFSTOPPED(status));
2829 REQUIRE_EQ(WSTOPSIG(status), SIGABRT);
2831 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2832 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
2833 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGABRT);
2835 /* Continue, replacing the SIGABRT with another SIGUSR1. */
2836 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2840 * The last wait() should report exit 2, i.e., a normal _exit
2841 * from the signal handler. In the meantime, catch and proceed
2842 * past any syscall stops.
2844 wpid = waitpid(fpid, &status, 0);
2845 REQUIRE_EQ(wpid, fpid);
2846 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
2847 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
2848 ATF_REQUIRE(pl.pl_flags & (PL_FLAG_SCE | PL_FLAG_SCX));
2849 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
2851 ATF_REQUIRE(WIFEXITED(status));
2852 REQUIRE_EQ(WEXITSTATUS(status), 2);
2857 wpid = wait(&status);
2858 REQUIRE_EQ(wpid, -1);
2859 REQUIRE_EQ(errno, ECHILD);
2863 * Verify a signal delivered by ptrace is noticed by kevent(2).
2865 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_kqueue);
2866 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_kqueue, tc)
2869 int status, kq, nevents;
2872 ATF_REQUIRE(signal(SIGUSR1, SIG_IGN) != SIG_ERR);
2874 ATF_REQUIRE((fpid = fork()) != -1);
2876 CHILD_REQUIRE((kq = kqueue()) > 0);
2877 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
2878 CHILD_REQUIRE_EQ(kevent(kq, &kev, 1, NULL, 0, NULL), 0);
2883 nevents = kevent(kq, NULL, 0, &kev, 1, NULL);
2884 if (nevents == -1 && errno == EINTR)
2886 CHILD_REQUIRE(nevents > 0);
2887 CHILD_REQUIRE_EQ(kev.filter, EVFILT_SIGNAL);
2888 CHILD_REQUIRE_EQ(kev.ident, SIGUSR1);
2895 /* The first wait() should report the stop from SIGSTOP. */
2896 wpid = waitpid(fpid, &status, 0);
2897 REQUIRE_EQ(wpid, fpid);
2898 ATF_REQUIRE(WIFSTOPPED(status));
2899 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2901 /* Continue with the SIGUSR1. */
2902 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
2905 * The last wait() should report normal exit with code 1.
2907 wpid = waitpid(fpid, &status, 0);
2908 REQUIRE_EQ(wpid, fpid);
2909 ATF_REQUIRE(WIFEXITED(status));
2910 REQUIRE_EQ(WEXITSTATUS(status), 1);
2912 wpid = wait(&status);
2913 REQUIRE_EQ(wpid, -1);
2914 REQUIRE_EQ(errno, ECHILD);
2918 signal_thread(void *arg)
2923 pthread_barrier_t *pbarrier = (pthread_barrier_t*)arg;
2925 /* Wait for this thread to receive a SIGUSR1. */
2927 err = sem_wait(&sigusr1_sem);
2928 CHILD_REQUIRE(err == 0 || errno == EINTR);
2929 } while (err != 0 && errno == EINTR);
2931 /* Free our companion thread from the barrier. */
2932 pthread_barrier_wait(pbarrier);
2935 * Swap ignore duties; the next SIGUSR1 should go to the
2938 CHILD_REQUIRE_EQ(sigemptyset(&sigmask), 0);
2939 CHILD_REQUIRE_EQ(sigaddset(&sigmask, SIGUSR1), 0);
2940 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_BLOCK, &sigmask, NULL), 0);
2942 /* Sync up threads after swapping signal masks. */
2943 pthread_barrier_wait(pbarrier);
2945 /* Wait until our companion has received its SIGUSR1. */
2946 pthread_barrier_wait(pbarrier);
2952 * Verify that a traced process with blocked signal received the
2953 * signal from kill() once unmasked.
2955 ATF_TC_WITHOUT_HEAD(ptrace__killed_with_sigmask);
2956 ATF_TC_BODY(ptrace__killed_with_sigmask, tc)
2958 struct ptrace_lwpinfo pl;
2963 REQUIRE_EQ(sem_init(&sigusr1_sem, 0, 0), 0);
2964 ATF_REQUIRE(signal(SIGUSR1, sigusr1_sempost_handler) != SIG_ERR);
2967 ATF_REQUIRE((fpid = fork()) != -1);
2969 CHILD_REQUIRE_EQ(sigemptyset(&sigmask), 0);
2970 CHILD_REQUIRE_EQ(sigaddset(&sigmask, SIGUSR1), 0);
2971 CHILD_REQUIRE_EQ(sigprocmask(SIG_BLOCK, &sigmask, NULL), 0);
2974 CHILD_REQUIRE_EQ(got_usr1, 0);
2976 /* Allow the pending SIGUSR1 in now. */
2977 CHILD_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &sigmask, NULL), 0);
2978 /* Wait to receive a SIGUSR1. */
2980 err = sem_wait(&sigusr1_sem);
2981 CHILD_REQUIRE(err == 0 || errno == EINTR);
2982 } while (err != 0 && errno == EINTR);
2983 CHILD_REQUIRE_EQ(got_usr1, 1);
2987 /* The first wait() should report the stop from SIGSTOP. */
2988 wpid = waitpid(fpid, &status, 0);
2989 REQUIRE_EQ(wpid, fpid);
2990 ATF_REQUIRE(WIFSTOPPED(status));
2991 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
2992 ATF_REQUIRE(ptrace(PT_LWPINFO, fpid, (caddr_t)&pl, sizeof(pl)) != -1);
2993 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGSTOP);
2995 /* Send blocked SIGUSR1 which should cause a stop. */
2996 REQUIRE_EQ(kill(fpid, SIGUSR1), 0);
2998 /* Continue the child ignoring the SIGSTOP. */
2999 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3001 /* The next wait() should report the kill(SIGUSR1) was received. */
3002 wpid = waitpid(fpid, &status, 0);
3003 REQUIRE_EQ(wpid, fpid);
3004 ATF_REQUIRE(WIFSTOPPED(status));
3005 REQUIRE_EQ(WSTOPSIG(status), SIGUSR1);
3006 ATF_REQUIRE(ptrace(PT_LWPINFO, fpid, (caddr_t)&pl, sizeof(pl)) != -1);
3007 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGUSR1);
3009 /* Continue the child, allowing in the SIGUSR1. */
3010 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
3012 /* The last wait() should report normal exit with code 1. */
3013 wpid = waitpid(fpid, &status, 0);
3014 REQUIRE_EQ(wpid, fpid);
3015 ATF_REQUIRE(WIFEXITED(status));
3016 REQUIRE_EQ(WEXITSTATUS(status), 1);
3018 wpid = wait(&status);
3019 REQUIRE_EQ(wpid, -1);
3020 REQUIRE_EQ(errno, ECHILD);
3024 * Verify that a traced process with blocked signal received the
3025 * signal from PT_CONTINUE once unmasked.
3027 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_sigmask);
3028 ATF_TC_BODY(ptrace__PT_CONTINUE_with_sigmask, tc)
3030 struct ptrace_lwpinfo pl;
3035 REQUIRE_EQ(sem_init(&sigusr1_sem, 0, 0), 0);
3036 ATF_REQUIRE(signal(SIGUSR1, sigusr1_sempost_handler) != SIG_ERR);
3039 ATF_REQUIRE((fpid = fork()) != -1);
3041 CHILD_REQUIRE_EQ(sigemptyset(&sigmask), 0);
3042 CHILD_REQUIRE_EQ(sigaddset(&sigmask, SIGUSR1), 0);
3043 CHILD_REQUIRE_EQ(sigprocmask(SIG_BLOCK, &sigmask, NULL), 0);
3046 CHILD_REQUIRE_EQ(got_usr1, 0);
3048 /* Allow the pending SIGUSR1 in now. */
3049 CHILD_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &sigmask, NULL), 0);
3050 /* Wait to receive a SIGUSR1. */
3052 err = sem_wait(&sigusr1_sem);
3053 CHILD_REQUIRE(err == 0 || errno == EINTR);
3054 } while (err != 0 && errno == EINTR);
3056 CHILD_REQUIRE_EQ(got_usr1, 1);
3060 /* The first wait() should report the stop from SIGSTOP. */
3061 wpid = waitpid(fpid, &status, 0);
3062 REQUIRE_EQ(wpid, fpid);
3063 ATF_REQUIRE(WIFSTOPPED(status));
3064 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3065 ATF_REQUIRE(ptrace(PT_LWPINFO, fpid, (caddr_t)&pl, sizeof(pl)) != -1);
3066 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGSTOP);
3068 /* Continue the child replacing SIGSTOP with SIGUSR1. */
3069 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
3071 /* The next wait() should report the SIGUSR1 was received. */
3072 wpid = waitpid(fpid, &status, 0);
3073 REQUIRE_EQ(wpid, fpid);
3074 ATF_REQUIRE(WIFSTOPPED(status));
3075 REQUIRE_EQ(WSTOPSIG(status), SIGUSR1);
3076 ATF_REQUIRE(ptrace(PT_LWPINFO, fpid, (caddr_t)&pl, sizeof(pl)) != -1);
3077 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGUSR1);
3079 /* Continue the child, ignoring the SIGUSR1. */
3080 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3082 /* The last wait() should report normal exit with code 1. */
3083 wpid = waitpid(fpid, &status, 0);
3084 REQUIRE_EQ(wpid, fpid);
3085 ATF_REQUIRE(WIFEXITED(status));
3086 REQUIRE_EQ(WEXITSTATUS(status), 1);
3088 wpid = wait(&status);
3089 REQUIRE_EQ(wpid, -1);
3090 REQUIRE_EQ(errno, ECHILD);
3094 * Verify that if ptrace stops due to a signal but continues with
3095 * a different signal that the new signal is routed to a thread
3096 * that can accept it, and that the thread is awakened by the signal
3097 * in a timely manner.
3099 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_thread_sigmask);
3100 ATF_TC_BODY(ptrace__PT_CONTINUE_with_signal_thread_sigmask, tc)
3106 pthread_barrier_t barrier;
3108 REQUIRE_EQ(pthread_barrier_init(&barrier, NULL, 2), 0);
3109 REQUIRE_EQ(sem_init(&sigusr1_sem, 0, 0), 0);
3110 ATF_REQUIRE(signal(SIGUSR1, sigusr1_sempost_handler) != SIG_ERR);
3112 ATF_REQUIRE((fpid = fork()) != -1);
3114 CHILD_REQUIRE_EQ(pthread_create(&t, NULL, signal_thread,
3115 (void *)&barrier), 0);
3117 /* The other thread should receive the first SIGUSR1. */
3118 CHILD_REQUIRE_EQ(sigemptyset(&sigmask), 0);
3119 CHILD_REQUIRE_EQ(sigaddset(&sigmask, SIGUSR1), 0);
3120 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_BLOCK, &sigmask, NULL), 0);
3124 /* Wait until other thread has received its SIGUSR1. */
3125 pthread_barrier_wait(&barrier);
3128 * Swap ignore duties; the next SIGUSR1 should go to this
3131 CHILD_REQUIRE_EQ(pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL),
3134 /* Sync up threads after swapping signal masks. */
3135 pthread_barrier_wait(&barrier);
3138 * Sync up with test code; we're ready for the next SIGUSR1
3143 /* Wait for this thread to receive a SIGUSR1. */
3145 err = sem_wait(&sigusr1_sem);
3146 CHILD_REQUIRE(err == 0 || errno == EINTR);
3147 } while (err != 0 && errno == EINTR);
3149 /* Free the other thread from the barrier. */
3150 pthread_barrier_wait(&barrier);
3152 CHILD_REQUIRE_EQ(pthread_join(t, NULL), 0);
3157 /* The first wait() should report the stop from SIGSTOP. */
3158 wpid = waitpid(fpid, &status, 0);
3159 REQUIRE_EQ(wpid, fpid);
3160 ATF_REQUIRE(WIFSTOPPED(status));
3161 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3163 /* Continue the child ignoring the SIGSTOP. */
3164 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3167 * Send a signal without ptrace that either thread will accept (USR2,
3170 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
3172 /* The second wait() should report a SIGUSR2 was received. */
3173 wpid = waitpid(fpid, &status, 0);
3174 REQUIRE_EQ(wpid, fpid);
3175 ATF_REQUIRE(WIFSTOPPED(status));
3176 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
3178 /* Continue the child, changing the signal to USR1. */
3179 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
3181 /* The next wait() should report the stop from SIGSTOP. */
3182 wpid = waitpid(fpid, &status, 0);
3183 REQUIRE_EQ(wpid, fpid);
3184 ATF_REQUIRE(WIFSTOPPED(status));
3185 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3187 /* Continue the child ignoring the SIGSTOP. */
3188 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3190 REQUIRE_EQ(kill(fpid, SIGUSR2), 0);
3192 /* The next wait() should report a SIGUSR2 was received. */
3193 wpid = waitpid(fpid, &status, 0);
3194 REQUIRE_EQ(wpid, fpid);
3195 ATF_REQUIRE(WIFSTOPPED(status));
3196 REQUIRE_EQ(WSTOPSIG(status), SIGUSR2);
3198 /* Continue the child, changing the signal to USR1. */
3199 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, SIGUSR1), 0);
3201 /* The last wait() should report normal exit with code 1. */
3202 wpid = waitpid(fpid, &status, 0);
3203 REQUIRE_EQ(wpid, fpid);
3204 ATF_REQUIRE(WIFEXITED(status));
3205 REQUIRE_EQ(WEXITSTATUS(status), 1);
3207 wpid = wait(&status);
3208 REQUIRE_EQ(wpid, -1);
3209 REQUIRE_EQ(errno, ECHILD);
3213 raise_sigstop_thread(void *arg __unused)
3221 sleep_thread(void *arg __unused)
3229 terminate_with_pending_sigstop(bool sigstop_from_main_thread)
3238 * Become the reaper for this process tree. We need to be able to check
3239 * that both child and grandchild have died.
3241 REQUIRE_EQ(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL), 0);
3244 ATF_REQUIRE(fpid >= 0);
3247 CHILD_REQUIRE(fpid >= 0);
3251 /* Pin to CPU 0 to serialize thread execution. */
3253 CPU_SET(0, &setmask);
3254 CHILD_REQUIRE_EQ(cpuset(&setid), 0);
3255 CHILD_REQUIRE(cpuset_setaffinity(CPU_LEVEL_CPUSET,
3256 CPU_WHICH_CPUSET, setid,
3257 sizeof(setmask), &setmask) == 0);
3259 if (sigstop_from_main_thread) {
3261 * We expect the SIGKILL sent when our parent
3262 * dies to be delivered to the new thread.
3263 * Raise the SIGSTOP in this thread so the
3266 CHILD_REQUIRE(pthread_create(&t, NULL,
3267 sleep_thread, NULL) == 0);
3271 * We expect the SIGKILL to be delivered to
3272 * this thread. After creating the new thread,
3273 * just get off the CPU so the other thread can
3274 * raise the SIGSTOP.
3276 CHILD_REQUIRE(pthread_create(&t, NULL,
3277 raise_sigstop_thread, NULL) == 0);
3283 /* First stop is trace_me() immediately after fork. */
3284 wpid = waitpid(fpid, &status, 0);
3285 CHILD_REQUIRE_EQ(wpid, fpid);
3286 CHILD_REQUIRE(WIFSTOPPED(status));
3287 CHILD_REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3289 CHILD_REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3291 /* Second stop is from the raise(SIGSTOP). */
3292 wpid = waitpid(fpid, &status, 0);
3293 CHILD_REQUIRE_EQ(wpid, fpid);
3294 CHILD_REQUIRE(WIFSTOPPED(status));
3295 CHILD_REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3298 * Terminate tracing process without detaching. Our child
3305 * We should get a normal exit from our immediate child and a SIGKILL
3306 * exit from our grandchild. The latter case is the interesting one.
3307 * Our grandchild should not have stopped due to the SIGSTOP that was
3308 * left dangling when its parent died.
3310 for (i = 0; i < 2; ++i) {
3311 wpid = wait(&status);
3313 ATF_REQUIRE(WIFEXITED(status));
3314 REQUIRE_EQ(WEXITSTATUS(status), 0);
3316 ATF_REQUIRE(WIFSIGNALED(status));
3317 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
3323 * These two tests ensure that if the tracing process exits without detaching
3324 * just after the child received a SIGSTOP, the child is cleanly killed and
3325 * doesn't go to sleep due to the SIGSTOP. The parent's death will send a
3326 * SIGKILL to the child. If the SIGKILL and the SIGSTOP are handled by
3327 * different threads, the SIGKILL must win. There are two variants of this
3328 * test, designed to catch the case where the SIGKILL is delivered to the
3329 * younger thread (the first test) and the case where the SIGKILL is delivered
3330 * to the older thread (the second test). This behavior has changed in the
3331 * past, so make no assumption.
3333 ATF_TC(ptrace__parent_terminate_with_pending_sigstop1);
3334 ATF_TC_HEAD(ptrace__parent_terminate_with_pending_sigstop1, tc)
3337 atf_tc_set_md_var(tc, "require.user", "root");
3339 ATF_TC_BODY(ptrace__parent_terminate_with_pending_sigstop1, tc)
3342 terminate_with_pending_sigstop(true);
3345 ATF_TC(ptrace__parent_terminate_with_pending_sigstop2);
3346 ATF_TC_HEAD(ptrace__parent_terminate_with_pending_sigstop2, tc)
3349 atf_tc_set_md_var(tc, "require.user", "root");
3351 ATF_TC_BODY(ptrace__parent_terminate_with_pending_sigstop2, tc)
3354 terminate_with_pending_sigstop(false);
3358 * Verify that after ptrace() discards a SIGKILL signal, the event mask
3361 ATF_TC_WITHOUT_HEAD(ptrace__event_mask_sigkill_discard);
3362 ATF_TC_BODY(ptrace__event_mask_sigkill_discard, tc)
3364 struct ptrace_lwpinfo pl;
3366 int status, event_mask, new_event_mask;
3368 ATF_REQUIRE((fpid = fork()) != -1);
3375 /* The first wait() should report the stop from trace_me(). */
3376 wpid = waitpid(fpid, &status, 0);
3377 REQUIRE_EQ(wpid, fpid);
3378 ATF_REQUIRE(WIFSTOPPED(status));
3379 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3381 /* Set several unobtrusive event bits. */
3382 event_mask = PTRACE_EXEC | PTRACE_FORK | PTRACE_LWP;
3383 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, wpid, (caddr_t)&event_mask,
3384 sizeof(event_mask)) == 0);
3386 /* Send a SIGKILL without using ptrace. */
3387 REQUIRE_EQ(kill(fpid, SIGKILL), 0);
3389 /* Continue the child ignoring the SIGSTOP. */
3390 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3392 /* The next stop should be due to the SIGKILL. */
3393 wpid = waitpid(fpid, &status, 0);
3394 REQUIRE_EQ(wpid, fpid);
3395 ATF_REQUIRE(WIFSTOPPED(status));
3396 REQUIRE_EQ(WSTOPSIG(status), SIGKILL);
3398 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3399 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3400 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGKILL);
3402 /* Continue the child ignoring the SIGKILL. */
3403 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3405 /* The next wait() should report the stop from SIGSTOP. */
3406 wpid = waitpid(fpid, &status, 0);
3407 REQUIRE_EQ(wpid, fpid);
3408 ATF_REQUIRE(WIFSTOPPED(status));
3409 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3411 /* Check the current event mask. It should not have changed. */
3413 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, wpid, (caddr_t)&new_event_mask,
3414 sizeof(new_event_mask)) == 0);
3415 REQUIRE_EQ(event_mask, new_event_mask);
3417 /* Continue the child to let it exit. */
3418 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3420 /* The last event should be for the child process's exit. */
3421 wpid = waitpid(fpid, &status, 0);
3422 ATF_REQUIRE(WIFEXITED(status));
3423 REQUIRE_EQ(WEXITSTATUS(status), 0);
3425 wpid = wait(&status);
3426 REQUIRE_EQ(wpid, -1);
3427 REQUIRE_EQ(errno, ECHILD);
3431 flock_thread(void *arg)
3436 (void)flock(fd, LOCK_EX);
3437 (void)flock(fd, LOCK_UN);
3442 * Verify that PT_ATTACH will suspend threads sleeping in an SBDRY section.
3443 * We rely on the fact that the lockf implementation sets SBDRY before blocking
3444 * on a lock. This is a regression test for r318191.
3446 ATF_TC_WITHOUT_HEAD(ptrace__PT_ATTACH_with_SBDRY_thread);
3447 ATF_TC_BODY(ptrace__PT_ATTACH_with_SBDRY_thread, tc)
3449 pthread_barrier_t barrier;
3450 pthread_barrierattr_t battr;
3453 int error, fd, i, status;
3455 REQUIRE_EQ(pthread_barrierattr_init(&battr), 0);
3456 ATF_REQUIRE(pthread_barrierattr_setpshared(&battr,
3457 PTHREAD_PROCESS_SHARED) == 0);
3458 REQUIRE_EQ(pthread_barrier_init(&barrier, &battr, 2), 0);
3460 (void)snprintf(tmpfile, sizeof(tmpfile), "./ptrace.XXXXXX");
3461 fd = mkstemp(tmpfile);
3462 ATF_REQUIRE(fd >= 0);
3464 ATF_REQUIRE((child = fork()) != -1);
3469 error = pthread_barrier_wait(&barrier);
3470 if (error != 0 && error != PTHREAD_BARRIER_SERIAL_THREAD)
3473 cfd = open(tmpfile, O_RDONLY);
3478 * We want at least two threads blocked on the file lock since
3479 * the SIGSTOP from PT_ATTACH may kick one of them out of
3482 if (pthread_create(&t[0], NULL, flock_thread, &cfd) != 0)
3484 if (pthread_create(&t[1], NULL, flock_thread, &cfd) != 0)
3486 if (pthread_join(t[0], NULL) != 0)
3488 if (pthread_join(t[1], NULL) != 0)
3493 REQUIRE_EQ(flock(fd, LOCK_EX), 0);
3495 error = pthread_barrier_wait(&barrier);
3496 ATF_REQUIRE(error == 0 || error == PTHREAD_BARRIER_SERIAL_THREAD);
3499 * Give the child some time to block. Is there a better way to do this?
3504 * Attach and give the child 3 seconds to stop.
3506 REQUIRE_EQ(ptrace(PT_ATTACH, child, NULL, 0), 0);
3507 for (i = 0; i < 3; i++) {
3508 wpid = waitpid(child, &status, WNOHANG);
3509 if (wpid == child && WIFSTOPPED(status) &&
3510 WSTOPSIG(status) == SIGSTOP)
3514 ATF_REQUIRE_MSG(i < 3, "failed to stop child process after PT_ATTACH");
3516 REQUIRE_EQ(ptrace(PT_DETACH, child, NULL, 0), 0);
3518 REQUIRE_EQ(flock(fd, LOCK_UN), 0);
3519 REQUIRE_EQ(unlink(tmpfile), 0);
3520 REQUIRE_EQ(close(fd), 0);
3524 sigusr1_step_handler(int sig)
3527 CHILD_REQUIRE_EQ(sig, SIGUSR1);
3532 * Verify that PT_STEP with a signal invokes the signal before
3533 * stepping the next instruction (and that the next instruction is
3534 * stepped correctly).
3536 ATF_TC_WITHOUT_HEAD(ptrace__PT_STEP_with_signal);
3537 ATF_TC_BODY(ptrace__PT_STEP_with_signal, tc)
3539 struct ptrace_lwpinfo pl;
3543 ATF_REQUIRE((fpid = fork()) != -1);
3546 signal(SIGUSR1, sigusr1_step_handler);
3551 /* The first wait() should report the stop from SIGSTOP. */
3552 wpid = waitpid(fpid, &status, 0);
3553 REQUIRE_EQ(wpid, fpid);
3554 ATF_REQUIRE(WIFSTOPPED(status));
3555 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3557 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3559 /* The next stop should report the SIGABRT in the child body. */
3560 wpid = waitpid(fpid, &status, 0);
3561 REQUIRE_EQ(wpid, fpid);
3562 ATF_REQUIRE(WIFSTOPPED(status));
3563 REQUIRE_EQ(WSTOPSIG(status), SIGABRT);
3565 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3566 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3567 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGABRT);
3569 /* Step the child process inserting SIGUSR1. */
3570 REQUIRE_EQ(ptrace(PT_STEP, fpid, (caddr_t)1, SIGUSR1), 0);
3572 /* The next stop should report the SIGABRT in the signal handler. */
3573 wpid = waitpid(fpid, &status, 0);
3574 REQUIRE_EQ(wpid, fpid);
3575 ATF_REQUIRE(WIFSTOPPED(status));
3576 REQUIRE_EQ(WSTOPSIG(status), SIGABRT);
3578 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3579 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3580 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGABRT);
3582 /* Continue the child process discarding the signal. */
3583 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3585 /* The next stop should report a trace trap from PT_STEP. */
3586 wpid = waitpid(fpid, &status, 0);
3587 REQUIRE_EQ(wpid, fpid);
3588 ATF_REQUIRE(WIFSTOPPED(status));
3589 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3591 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3592 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3593 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGTRAP);
3594 REQUIRE_EQ(pl.pl_siginfo.si_code, TRAP_TRACE);
3596 /* Continue the child to let it exit. */
3597 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3599 /* The last event should be for the child process's exit. */
3600 wpid = waitpid(fpid, &status, 0);
3601 ATF_REQUIRE(WIFEXITED(status));
3602 REQUIRE_EQ(WEXITSTATUS(status), 1);
3604 wpid = wait(&status);
3605 REQUIRE_EQ(wpid, -1);
3606 REQUIRE_EQ(errno, ECHILD);
3609 #ifdef HAVE_BREAKPOINT
3611 * Verify that a SIGTRAP event with the TRAP_BRKPT code is reported
3612 * for a breakpoint trap.
3614 ATF_TC_WITHOUT_HEAD(ptrace__breakpoint_siginfo);
3615 ATF_TC_BODY(ptrace__breakpoint_siginfo, tc)
3617 struct ptrace_lwpinfo pl;
3621 ATF_REQUIRE((fpid = fork()) != -1);
3628 /* The first wait() should report the stop from SIGSTOP. */
3629 wpid = waitpid(fpid, &status, 0);
3630 REQUIRE_EQ(wpid, fpid);
3631 ATF_REQUIRE(WIFSTOPPED(status));
3632 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3634 /* Continue the child ignoring the SIGSTOP. */
3635 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3637 /* The second wait() should report hitting the breakpoint. */
3638 wpid = waitpid(fpid, &status, 0);
3639 REQUIRE_EQ(wpid, fpid);
3640 ATF_REQUIRE(WIFSTOPPED(status));
3641 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3643 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3644 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3645 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGTRAP);
3646 REQUIRE_EQ(pl.pl_siginfo.si_code, TRAP_BRKPT);
3648 /* Kill the child process. */
3649 REQUIRE_EQ(ptrace(PT_KILL, fpid, 0, 0), 0);
3651 /* The last wait() should report the SIGKILL. */
3652 wpid = waitpid(fpid, &status, 0);
3653 REQUIRE_EQ(wpid, fpid);
3654 ATF_REQUIRE(WIFSIGNALED(status));
3655 REQUIRE_EQ(WTERMSIG(status), SIGKILL);
3657 wpid = wait(&status);
3658 REQUIRE_EQ(wpid, -1);
3659 REQUIRE_EQ(errno, ECHILD);
3661 #endif /* HAVE_BREAKPOINT */
3664 * Verify that a SIGTRAP event with the TRAP_TRACE code is reported
3665 * for a single-step trap from PT_STEP.
3667 ATF_TC_WITHOUT_HEAD(ptrace__step_siginfo);
3668 ATF_TC_BODY(ptrace__step_siginfo, tc)
3670 struct ptrace_lwpinfo pl;
3674 ATF_REQUIRE((fpid = fork()) != -1);
3680 /* The first wait() should report the stop from SIGSTOP. */
3681 wpid = waitpid(fpid, &status, 0);
3682 REQUIRE_EQ(wpid, fpid);
3683 ATF_REQUIRE(WIFSTOPPED(status));
3684 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3686 /* Step the child ignoring the SIGSTOP. */
3687 REQUIRE_EQ(ptrace(PT_STEP, fpid, (caddr_t)1, 0), 0);
3689 /* The second wait() should report a single-step trap. */
3690 wpid = waitpid(fpid, &status, 0);
3691 REQUIRE_EQ(wpid, fpid);
3692 ATF_REQUIRE(WIFSTOPPED(status));
3693 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3695 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3696 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3697 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGTRAP);
3698 REQUIRE_EQ(pl.pl_siginfo.si_code, TRAP_TRACE);
3700 /* Continue the child process. */
3701 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3703 /* The last event should be for the child process's exit. */
3704 wpid = waitpid(fpid, &status, 0);
3705 ATF_REQUIRE(WIFEXITED(status));
3706 REQUIRE_EQ(WEXITSTATUS(status), 1);
3708 wpid = wait(&status);
3709 REQUIRE_EQ(wpid, -1);
3710 REQUIRE_EQ(errno, ECHILD);
3713 #if defined(HAVE_BREAKPOINT) && defined(SKIP_BREAK)
3715 continue_thread(void *arg __unused)
3722 continue_thread_main(void)
3724 pthread_t threads[2];
3726 CHILD_REQUIRE(pthread_create(&threads[0], NULL, continue_thread,
3728 CHILD_REQUIRE(pthread_create(&threads[1], NULL, continue_thread,
3730 CHILD_REQUIRE_EQ(pthread_join(threads[0], NULL), 0);
3731 CHILD_REQUIRE_EQ(pthread_join(threads[1], NULL), 0);
3736 * Ensure that PT_CONTINUE clears the status of the thread that
3737 * triggered the stop even if a different thread's LWP was passed to
3740 ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_different_thread);
3741 ATF_TC_BODY(ptrace__PT_CONTINUE_different_thread, tc)
3743 struct ptrace_lwpinfo pl;
3750 ATF_REQUIRE((fpid = fork()) != -1);
3753 continue_thread_main();
3756 /* The first wait() should report the stop from SIGSTOP. */
3757 wpid = waitpid(fpid, &status, 0);
3758 REQUIRE_EQ(wpid, fpid);
3759 ATF_REQUIRE(WIFSTOPPED(status));
3760 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3762 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
3765 REQUIRE_EQ(ptrace(PT_LWP_EVENTS, wpid, NULL, 1), 0);
3767 /* Continue the child ignoring the SIGSTOP. */
3768 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3770 /* One of the new threads should report it's birth. */
3771 wpid = waitpid(fpid, &status, 0);
3772 REQUIRE_EQ(wpid, fpid);
3773 ATF_REQUIRE(WIFSTOPPED(status));
3774 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3776 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3777 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)),
3778 (PL_FLAG_BORN | PL_FLAG_SCX));
3779 lwps[0] = pl.pl_lwpid;
3782 * Suspend this thread to ensure both threads are alive before
3783 * hitting the breakpoint.
3785 ATF_REQUIRE(ptrace(PT_SUSPEND, lwps[0], NULL, 0) != -1);
3787 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3789 /* Second thread should report it's birth. */
3790 wpid = waitpid(fpid, &status, 0);
3791 REQUIRE_EQ(wpid, fpid);
3792 ATF_REQUIRE(WIFSTOPPED(status));
3793 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3795 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3796 REQUIRE_EQ((pl.pl_flags & (PL_FLAG_BORN | PL_FLAG_SCX)),
3797 (PL_FLAG_BORN | PL_FLAG_SCX));
3798 ATF_REQUIRE(pl.pl_lwpid != lwps[0]);
3799 lwps[1] = pl.pl_lwpid;
3801 /* Resume both threads waiting for breakpoint events. */
3802 hit_break[0] = hit_break[1] = false;
3803 ATF_REQUIRE(ptrace(PT_RESUME, lwps[0], NULL, 0) != -1);
3804 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3806 /* One thread should report a breakpoint. */
3807 wpid = waitpid(fpid, &status, 0);
3808 REQUIRE_EQ(wpid, fpid);
3809 ATF_REQUIRE(WIFSTOPPED(status));
3810 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3812 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3813 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3814 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGTRAP);
3815 REQUIRE_EQ(pl.pl_siginfo.si_code, TRAP_BRKPT);
3816 if (pl.pl_lwpid == lwps[0])
3820 hit_break[i] = true;
3821 ATF_REQUIRE(ptrace(PT_GETREGS, pl.pl_lwpid, (caddr_t)®, 0) != -1);
3823 ATF_REQUIRE(ptrace(PT_SETREGS, pl.pl_lwpid, (caddr_t)®, 0) != -1);
3826 * Resume both threads but pass the other thread's LWPID to
3829 REQUIRE_EQ(ptrace(PT_CONTINUE, lwps[i ^ 1], (caddr_t)1, 0), 0);
3832 * Will now get two thread exit events and one more breakpoint
3835 for (j = 0; j < 3; j++) {
3836 wpid = waitpid(fpid, &status, 0);
3837 REQUIRE_EQ(wpid, fpid);
3838 ATF_REQUIRE(WIFSTOPPED(status));
3839 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3841 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
3844 if (pl.pl_lwpid == lwps[0])
3849 ATF_REQUIRE_MSG(lwps[i] != 0, "event for exited thread");
3850 if (pl.pl_flags & PL_FLAG_EXITED) {
3851 ATF_REQUIRE_MSG(hit_break[i],
3852 "exited thread did not report breakpoint");
3855 ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) != 0);
3856 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGTRAP);
3857 REQUIRE_EQ(pl.pl_siginfo.si_code, TRAP_BRKPT);
3858 ATF_REQUIRE_MSG(!hit_break[i],
3859 "double breakpoint event");
3860 hit_break[i] = true;
3861 ATF_REQUIRE(ptrace(PT_GETREGS, pl.pl_lwpid, (caddr_t)®,
3864 ATF_REQUIRE(ptrace(PT_SETREGS, pl.pl_lwpid, (caddr_t)®,
3868 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3871 /* Both threads should have exited. */
3872 REQUIRE_EQ(lwps[0], 0);
3873 REQUIRE_EQ(lwps[1], 0);
3875 /* The last event should be for the child process's exit. */
3876 wpid = waitpid(fpid, &status, 0);
3877 ATF_REQUIRE(WIFEXITED(status));
3878 REQUIRE_EQ(WEXITSTATUS(status), 1);
3880 wpid = wait(&status);
3881 REQUIRE_EQ(wpid, -1);
3882 REQUIRE_EQ(errno, ECHILD);
3887 * Verify that PT_LWPINFO doesn't return stale siginfo.
3889 ATF_TC_WITHOUT_HEAD(ptrace__PT_LWPINFO_stale_siginfo);
3890 ATF_TC_BODY(ptrace__PT_LWPINFO_stale_siginfo, tc)
3892 struct ptrace_lwpinfo pl;
3896 ATF_REQUIRE((fpid = fork()) != -1);
3903 /* The first wait() should report the stop from SIGSTOP. */
3904 wpid = waitpid(fpid, &status, 0);
3905 REQUIRE_EQ(wpid, fpid);
3906 ATF_REQUIRE(WIFSTOPPED(status));
3907 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3909 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3911 /* The next stop should report the SIGABRT in the child body. */
3912 wpid = waitpid(fpid, &status, 0);
3913 REQUIRE_EQ(wpid, fpid);
3914 ATF_REQUIRE(WIFSTOPPED(status));
3915 REQUIRE_EQ(WSTOPSIG(status), SIGABRT);
3917 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3918 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
3919 REQUIRE_EQ(pl.pl_siginfo.si_signo, SIGABRT);
3922 * Continue the process ignoring the signal, but enabling
3925 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
3928 * The next stop should report a system call entry from
3929 * exit(). PL_FLAGS_SI should not be set.
3931 wpid = waitpid(fpid, &status, 0);
3932 REQUIRE_EQ(wpid, fpid);
3933 ATF_REQUIRE(WIFSTOPPED(status));
3934 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3936 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3937 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
3938 REQUIRE_EQ((pl.pl_flags & PL_FLAG_SI), 0);
3940 /* Disable syscall tracing and continue the child to let it exit. */
3941 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
3942 sizeof(events)) == 0);
3943 events &= ~PTRACE_SYSCALL;
3944 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
3945 sizeof(events)) == 0);
3946 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
3948 /* The last event should be for the child process's exit. */
3949 wpid = waitpid(fpid, &status, 0);
3950 ATF_REQUIRE(WIFEXITED(status));
3951 REQUIRE_EQ(WEXITSTATUS(status), 1);
3953 wpid = wait(&status);
3954 REQUIRE_EQ(wpid, -1);
3955 REQUIRE_EQ(errno, ECHILD);
3959 * A simple test of PT_GET_SC_ARGS and PT_GET_SC_RET.
3961 ATF_TC_WITHOUT_HEAD(ptrace__syscall_args);
3962 ATF_TC_BODY(ptrace__syscall_args, tc)
3964 struct ptrace_lwpinfo pl;
3965 struct ptrace_sc_ret psr;
3970 ATF_REQUIRE((fpid = fork()) != -1);
3978 /* The first wait() should report the stop from SIGSTOP. */
3979 wpid = waitpid(fpid, &status, 0);
3980 REQUIRE_EQ(wpid, fpid);
3981 ATF_REQUIRE(WIFSTOPPED(status));
3982 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
3985 * Continue the process ignoring the signal, but enabling
3988 REQUIRE_EQ(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0), 0);
3991 * The next stop should be the syscall entry from getpid().
3993 wpid = waitpid(fpid, &status, 0);
3994 REQUIRE_EQ(wpid, fpid);
3995 ATF_REQUIRE(WIFSTOPPED(status));
3996 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
3998 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
3999 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
4000 REQUIRE_EQ(pl.pl_syscall_code, SYS_getpid);
4002 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4005 * The next stop should be the syscall exit from getpid().
4007 wpid = waitpid(fpid, &status, 0);
4008 REQUIRE_EQ(wpid, fpid);
4009 ATF_REQUIRE(WIFSTOPPED(status));
4010 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
4012 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
4013 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
4014 REQUIRE_EQ(pl.pl_syscall_code, SYS_getpid);
4016 ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr,
4017 sizeof(psr)) != -1);
4018 REQUIRE_EQ(psr.sr_error, 0);
4019 REQUIRE_EQ(psr.sr_retval[0], wpid);
4021 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4024 * The next stop should be the syscall entry from kill().
4026 wpid = waitpid(fpid, &status, 0);
4027 REQUIRE_EQ(wpid, fpid);
4028 ATF_REQUIRE(WIFSTOPPED(status));
4029 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
4031 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
4032 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
4033 REQUIRE_EQ(pl.pl_syscall_code, SYS_kill);
4034 REQUIRE_EQ(pl.pl_syscall_narg, 2);
4036 ATF_REQUIRE(ptrace(PT_GET_SC_ARGS, wpid, (caddr_t)args,
4037 sizeof(args)) != -1);
4038 REQUIRE_EQ(args[0], wpid);
4039 REQUIRE_EQ(args[1], 0);
4041 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4044 * The next stop should be the syscall exit from kill().
4046 wpid = waitpid(fpid, &status, 0);
4047 REQUIRE_EQ(wpid, fpid);
4048 ATF_REQUIRE(WIFSTOPPED(status));
4049 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
4051 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
4052 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
4053 REQUIRE_EQ(pl.pl_syscall_code, SYS_kill);
4055 ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr,
4056 sizeof(psr)) != -1);
4057 REQUIRE_EQ(psr.sr_error, 0);
4059 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4062 * The next stop should be the syscall entry from close().
4064 wpid = waitpid(fpid, &status, 0);
4065 REQUIRE_EQ(wpid, fpid);
4066 ATF_REQUIRE(WIFSTOPPED(status));
4067 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
4069 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
4070 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
4071 REQUIRE_EQ(pl.pl_syscall_code, SYS_close);
4072 REQUIRE_EQ(pl.pl_syscall_narg, 1);
4074 ATF_REQUIRE(ptrace(PT_GET_SC_ARGS, wpid, (caddr_t)args,
4075 sizeof(args)) != -1);
4076 REQUIRE_EQ(args[0], 3);
4078 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4081 * The next stop should be the syscall exit from close().
4083 wpid = waitpid(fpid, &status, 0);
4084 REQUIRE_EQ(wpid, fpid);
4085 ATF_REQUIRE(WIFSTOPPED(status));
4086 REQUIRE_EQ(WSTOPSIG(status), SIGTRAP);
4088 ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
4089 ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX);
4090 REQUIRE_EQ(pl.pl_syscall_code, SYS_close);
4092 ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr,
4093 sizeof(psr)) != -1);
4094 REQUIRE_EQ(psr.sr_error, EBADF);
4096 /* Disable syscall tracing and continue the child to let it exit. */
4097 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
4098 sizeof(events)) == 0);
4099 events &= ~PTRACE_SYSCALL;
4100 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
4101 sizeof(events)) == 0);
4102 REQUIRE_EQ(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0), 0);
4104 /* The last event should be for the child process's exit. */
4105 wpid = waitpid(fpid, &status, 0);
4106 ATF_REQUIRE(WIFEXITED(status));
4107 REQUIRE_EQ(WEXITSTATUS(status), 1);
4109 wpid = wait(&status);
4110 REQUIRE_EQ(wpid, -1);
4111 REQUIRE_EQ(errno, ECHILD);
4115 * Verify that when the process is traced that it isn't reparent
4116 * to the init process when we close all process descriptors.
4118 ATF_TC(ptrace__proc_reparent);
4119 ATF_TC_HEAD(ptrace__proc_reparent, tc)
4122 atf_tc_set_md_var(tc, "timeout", "2");
4124 ATF_TC_BODY(ptrace__proc_reparent, tc)
4126 pid_t traced, debuger, wpid;
4129 traced = pdfork(&pd, 0);
4130 ATF_REQUIRE(traced >= 0);
4135 ATF_REQUIRE(pd >= 0);
4138 ATF_REQUIRE(debuger >= 0);
4140 /* The traced process is reparented to debuger. */
4141 REQUIRE_EQ(ptrace(PT_ATTACH, traced, 0, 0), 0);
4142 wpid = waitpid(traced, &status, 0);
4143 REQUIRE_EQ(wpid, traced);
4144 ATF_REQUIRE(WIFSTOPPED(status));
4145 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
4146 REQUIRE_EQ(close(pd), 0);
4147 REQUIRE_EQ(ptrace(PT_DETACH, traced, (caddr_t)1, 0), 0);
4149 /* We closed pd so we should not have any child. */
4150 wpid = wait(&status);
4151 REQUIRE_EQ(wpid, -1);
4152 REQUIRE_EQ(errno, ECHILD);
4157 REQUIRE_EQ(close(pd), 0);
4158 wpid = waitpid(debuger, &status, 0);
4159 REQUIRE_EQ(wpid, debuger);
4160 REQUIRE_EQ(WEXITSTATUS(status), 0);
4162 /* Check if we still have any child. */
4163 wpid = wait(&status);
4164 REQUIRE_EQ(wpid, -1);
4165 REQUIRE_EQ(errno, ECHILD);
4169 * Ensure that traced processes created with pdfork(2) are visible to
4172 ATF_TC_WITHOUT_HEAD(ptrace__procdesc_wait_child);
4173 ATF_TC_BODY(ptrace__procdesc_wait_child, tc)
4178 child = pdfork(&pd, 0);
4179 ATF_REQUIRE(child >= 0);
4183 (void)raise(SIGSTOP);
4187 wpid = waitpid(child, &status, 0);
4188 REQUIRE_EQ(wpid, child);
4189 ATF_REQUIRE(WIFSTOPPED(status));
4190 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
4192 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
4194 wpid = wait(&status);
4195 REQUIRE_EQ(wpid, child);
4196 ATF_REQUIRE(WIFSTOPPED(status));
4197 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
4199 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
4202 * If process was created by pdfork, the return code have to
4203 * be collected through process descriptor.
4205 wpid = wait(&status);
4206 REQUIRE_EQ(wpid, -1);
4207 REQUIRE_EQ(errno, ECHILD);
4209 ATF_REQUIRE(close(pd) != -1);
4213 * Ensure that traced processes created with pdfork(2) are not visible
4214 * after returning to parent - waitid(P_ALL).
4216 ATF_TC_WITHOUT_HEAD(ptrace__procdesc_reparent_wait_child);
4217 ATF_TC_BODY(ptrace__procdesc_reparent_wait_child, tc)
4219 pid_t traced, debuger, wpid;
4222 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
4223 atf_tc_skip("https://bugs.freebsd.org/243605");
4225 traced = pdfork(&pd, 0);
4226 ATF_REQUIRE(traced >= 0);
4231 ATF_REQUIRE(pd >= 0);
4234 ATF_REQUIRE(debuger >= 0);
4236 /* The traced process is reparented to debuger. */
4237 REQUIRE_EQ(ptrace(PT_ATTACH, traced, 0, 0), 0);
4238 wpid = waitpid(traced, &status, 0);
4239 REQUIRE_EQ(wpid, traced);
4240 ATF_REQUIRE(WIFSTOPPED(status));
4241 REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
4243 /* Allow process to die. */
4244 REQUIRE_EQ(ptrace(PT_CONTINUE, traced, (caddr_t)1, 0), 0);
4245 wpid = waitpid(traced, &status, 0);
4246 REQUIRE_EQ(wpid, traced);
4247 ATF_REQUIRE(WIFEXITED(status));
4248 REQUIRE_EQ(WEXITSTATUS(status), 0);
4250 /* Reparent back to the orginal process. */
4251 REQUIRE_EQ(close(pd), 0);
4255 wpid = waitpid(debuger, &status, 0);
4256 REQUIRE_EQ(wpid, debuger);
4257 REQUIRE_EQ(WEXITSTATUS(status), 0);
4260 * We have a child but it has a process descriptori
4261 * so we should not be able to collect it process.
4263 wpid = wait(&status);
4264 REQUIRE_EQ(wpid, -1);
4265 REQUIRE_EQ(errno, ECHILD);
4267 REQUIRE_EQ(close(pd), 0);
4273 ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me);
4274 ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach);
4275 ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger);
4276 ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger);
4277 ATF_TP_ADD_TC(tp, ptrace__parent_exits_before_child);
4278 ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached);
4279 ATF_TP_ADD_TC(tp, ptrace__follow_fork_child_detached);
4280 ATF_TP_ADD_TC(tp, ptrace__follow_fork_parent_detached);
4281 ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached_unrelated_debugger);
4283 ptrace__follow_fork_child_detached_unrelated_debugger);
4285 ptrace__follow_fork_parent_detached_unrelated_debugger);
4286 ATF_TP_ADD_TC(tp, ptrace__getppid);
4287 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_fork);
4288 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_vfork);
4289 ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_thread);
4290 ATF_TP_ADD_TC(tp, ptrace__lwp_events);
4291 ATF_TP_ADD_TC(tp, ptrace__lwp_events_exec);
4292 ATF_TP_ADD_TC(tp, ptrace__siginfo);
4293 ATF_TP_ADD_TC(tp, ptrace__ptrace_exec_disable);
4294 ATF_TP_ADD_TC(tp, ptrace__ptrace_exec_enable);
4295 ATF_TP_ADD_TC(tp, ptrace__event_mask);
4296 ATF_TP_ADD_TC(tp, ptrace__ptrace_vfork);
4297 ATF_TP_ADD_TC(tp, ptrace__ptrace_vfork_follow);
4298 #ifdef HAVE_BREAKPOINT
4299 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_breakpoint);
4301 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_system_call);
4302 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_threads);
4303 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_competing_signal);
4304 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_competing_stop);
4305 ATF_TP_ADD_TC(tp, ptrace__PT_KILL_with_signal_full_sigqueue);
4306 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_system_call_entry);
4308 ptrace__PT_CONTINUE_with_signal_system_call_entry_and_exit);
4309 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_full_sigqueue);
4310 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_masked_full_sigqueue);
4311 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_change_sig);
4312 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_sigtrap_system_call_entry);
4313 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_mix);
4314 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_kqueue);
4315 ATF_TP_ADD_TC(tp, ptrace__killed_with_sigmask);
4316 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_sigmask);
4317 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_with_signal_thread_sigmask);
4318 ATF_TP_ADD_TC(tp, ptrace__parent_terminate_with_pending_sigstop1);
4319 ATF_TP_ADD_TC(tp, ptrace__parent_terminate_with_pending_sigstop2);
4320 ATF_TP_ADD_TC(tp, ptrace__event_mask_sigkill_discard);
4321 ATF_TP_ADD_TC(tp, ptrace__PT_ATTACH_with_SBDRY_thread);
4322 ATF_TP_ADD_TC(tp, ptrace__PT_STEP_with_signal);
4323 #ifdef HAVE_BREAKPOINT
4324 ATF_TP_ADD_TC(tp, ptrace__breakpoint_siginfo);
4326 ATF_TP_ADD_TC(tp, ptrace__step_siginfo);
4327 #if defined(HAVE_BREAKPOINT) && defined(SKIP_BREAK)
4328 ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_different_thread);
4330 ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo);
4331 ATF_TP_ADD_TC(tp, ptrace__syscall_args);
4332 ATF_TP_ADD_TC(tp, ptrace__proc_reparent);
4333 ATF_TP_ADD_TC(tp, ptrace__procdesc_wait_child);
4334 ATF_TP_ADD_TC(tp, ptrace__procdesc_reparent_wait_child);
4336 return (atf_no_error());