1 /* $NetBSD: t_ptrace_wait.c,v 1.69 2017/01/27 16:43:07 kamil Exp $ */
4 * Copyright (c) 2016 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: t_ptrace_wait.c,v 1.69 2017/01/27 16:43:07 kamil Exp $");
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/ptrace.h>
35 #include <sys/resource.h>
37 #include <sys/sysctl.h>
39 #include <machine/reg.h>
55 #include "t_ptrace_wait.h"
58 #define PARENT_TO_CHILD(info, fds, msg) \
59 ATF_REQUIRE(msg_write_child(info " to child " # fds, &fds, &msg, sizeof(msg)) == 0)
61 #define CHILD_FROM_PARENT(info, fds, msg) \
62 FORKEE_ASSERT(msg_read_parent(info " from parent " # fds, &fds, &msg, sizeof(msg)) == 0)
64 #define CHILD_TO_PARENT(info, fds, msg) \
65 FORKEE_ASSERT(msg_write_parent(info " to parent " # fds, &fds, &msg, sizeof(msg)) == 0)
67 #define PARENT_FROM_CHILD(info, fds, msg) \
68 ATF_REQUIRE(msg_read_child(info " from parent " # fds, &fds, &msg, sizeof(msg)) == 0)
72 ATF_TC_HEAD(traceme1, tc)
74 atf_tc_set_md_var(tc, "descr",
75 "Verify SIGSTOP followed by _exit(2) in a child");
78 ATF_TC_BODY(traceme1, tc)
80 const int exitval = 5;
81 const int sigval = SIGSTOP;
83 #if defined(TWAIT_HAVE_STATUS)
87 printf("Before forking process PID=%d\n", getpid());
88 ATF_REQUIRE((child = fork()) != -1);
90 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
91 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
93 printf("Before raising %s from child\n", strsignal(sigval));
94 FORKEE_ASSERT(raise(sigval) == 0);
96 printf("Before exiting of the child process\n");
99 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
101 printf("Before calling %s() for the child\n", TWAIT_FNAME);
102 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
104 validate_status_stopped(status, sigval);
106 printf("Before resuming the child process where it left off and "
107 "without signal to be sent\n");
108 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
110 printf("Before calling %s() for the child\n", TWAIT_FNAME);
111 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
113 validate_status_exited(status, exitval);
115 printf("Before calling %s() for the child\n", TWAIT_FNAME);
116 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
120 ATF_TC_HEAD(traceme2, tc)
122 atf_tc_set_md_var(tc, "descr",
123 "Verify SIGSTOP followed by _exit(2) in a child");
126 static int traceme2_caught = 0;
129 traceme2_sighandler(int sig)
131 FORKEE_ASSERT_EQ(sig, SIGINT);
136 ATF_TC_BODY(traceme2, tc)
138 const int exitval = 5;
139 const int sigval = SIGSTOP, sigsent = SIGINT;
142 #if defined(TWAIT_HAVE_STATUS)
146 printf("Before forking process PID=%d\n", getpid());
147 ATF_REQUIRE((child = fork()) != -1);
149 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
150 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
152 sa.sa_handler = traceme2_sighandler;
153 sa.sa_flags = SA_SIGINFO;
154 sigemptyset(&sa.sa_mask);
156 FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1);
158 printf("Before raising %s from child\n", strsignal(sigval));
159 FORKEE_ASSERT(raise(sigval) == 0);
161 FORKEE_ASSERT_EQ(traceme2_caught, 1);
163 printf("Before exiting of the child process\n");
166 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
168 printf("Before calling %s() for the child\n", TWAIT_FNAME);
169 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
171 validate_status_stopped(status, sigval);
173 printf("Before resuming the child process where it left off and with "
174 "signal %s to be sent\n", strsignal(sigsent));
175 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
177 printf("Before calling %s() for the child\n", TWAIT_FNAME);
178 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
180 validate_status_exited(status, exitval);
182 printf("Before calling %s() for the exited child\n", TWAIT_FNAME);
183 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
187 ATF_TC_HEAD(traceme3, tc)
189 atf_tc_set_md_var(tc, "descr",
190 "Verify SIGSTOP followed by termination by a signal in a child");
193 ATF_TC_BODY(traceme3, tc)
195 const int sigval = SIGSTOP, sigsent = SIGINT /* Without core-dump */;
197 #if defined(TWAIT_HAVE_STATUS)
201 printf("Before forking process PID=%d\n", getpid());
202 ATF_REQUIRE((child = fork()) != -1);
204 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
205 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
207 printf("Before raising %s from child\n", strsignal(sigval));
208 FORKEE_ASSERT(raise(sigval) == 0);
212 "Child should be terminated by a signal from its parent");
214 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
216 printf("Before calling %s() for the child\n", TWAIT_FNAME);
217 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
219 validate_status_stopped(status, sigval);
221 printf("Before resuming the child process where it left off and with "
222 "signal %s to be sent\n", strsignal(sigsent));
223 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
225 printf("Before calling %s() for the child\n", TWAIT_FNAME);
226 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
228 validate_status_signaled(status, sigsent, 0);
230 printf("Before calling %s() for the exited child\n", TWAIT_FNAME);
231 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
235 ATF_TC_HEAD(traceme4, tc)
237 atf_tc_set_md_var(tc, "descr",
238 "Verify SIGSTOP followed by SIGCONT and _exit(2) in a child");
241 ATF_TC_BODY(traceme4, tc)
243 const int exitval = 5;
244 const int sigval = SIGSTOP, sigsent = SIGCONT;
246 #if defined(TWAIT_HAVE_STATUS)
250 printf("Before forking process PID=%d\n", getpid());
251 ATF_REQUIRE((child = fork()) != -1);
253 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
254 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
256 printf("Before raising %s from child\n", strsignal(sigval));
257 FORKEE_ASSERT(raise(sigval) == 0);
259 printf("Before raising %s from child\n", strsignal(sigsent));
260 FORKEE_ASSERT(raise(sigsent) == 0);
262 printf("Before exiting of the child process\n");
265 printf("Parent process PID=%d, child's PID=%d\n", getpid(),child);
267 printf("Before calling %s() for the child\n", TWAIT_FNAME);
268 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
270 validate_status_stopped(status, sigval);
272 printf("Before resuming the child process where it left off and "
273 "without signal to be sent\n");
274 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
276 printf("Before calling %s() for the child\n", TWAIT_FNAME);
277 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
279 validate_status_stopped(status, sigsent);
281 printf("Before resuming the child process where it left off and "
282 "without signal to be sent\n");
283 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
285 printf("Before calling %s() for the child\n", TWAIT_FNAME);
286 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
288 validate_status_exited(status, exitval);
290 printf("Before calling %s() for the exited child\n", TWAIT_FNAME);
291 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
294 #if defined(TWAIT_HAVE_PID)
296 ATF_TC_HEAD(attach1, tc)
298 atf_tc_set_md_var(tc, "descr",
299 "Assert that tracer sees process termination before the parent");
302 ATF_TC_BODY(attach1, tc)
304 struct msg_fds parent_tracee, parent_tracer;
305 const int exitval_tracee = 5;
306 const int exitval_tracer = 10;
307 pid_t tracee, tracer, wpid;
308 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
309 #if defined(TWAIT_HAVE_STATUS)
313 printf("Spawn tracee\n");
314 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
315 tracee = atf_utils_fork();
317 // Wait for parent to let us exit
318 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg);
319 _exit(exitval_tracee);
322 printf("Spawn debugger\n");
323 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
324 tracer = atf_utils_fork();
326 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
327 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
329 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
330 FORKEE_REQUIRE_SUCCESS(
331 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
333 forkee_status_stopped(status, SIGSTOP);
335 /* Resume tracee with PT_CONTINUE */
336 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
338 /* Inform parent that tracer has attached to tracee */
339 CHILD_TO_PARENT("tracer ready", parent_tracer, msg);
341 /* Wait for parent to tell use that tracee should have exited */
342 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg);
344 /* Wait for tracee and assert that it exited */
345 FORKEE_REQUIRE_SUCCESS(
346 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
348 forkee_status_exited(status, exitval_tracee);
349 printf("Tracee %d exited with %d\n", tracee, exitval_tracee);
351 printf("Before exiting of the tracer process\n");
352 _exit(exitval_tracer);
355 printf("Wait for the tracer to attach to the tracee\n");
356 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg);
358 printf("Resume the tracee and let it exit\n");
359 PARENT_TO_CHILD("exit tracee", parent_tracee, msg);
361 printf("Detect that tracee is zombie\n");
362 await_zombie(tracee);
365 printf("Assert that there is no status about tracee %d - "
366 "Tracer must detect zombie first - calling %s()\n", tracee,
368 TWAIT_REQUIRE_SUCCESS(
369 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
371 printf("Tell the tracer child should have exited\n");
372 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg);
373 printf("Wait for tracer to finish its job and exit - calling %s()\n",
376 printf("Wait from tracer child to complete waiting for tracee\n");
377 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0),
380 validate_status_exited(status, exitval_tracer);
382 printf("Wait for tracee to finish its job and exit - calling %s()\n",
384 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
387 validate_status_exited(status, exitval_tracee);
389 msg_close(&parent_tracer);
390 msg_close(&parent_tracee);
394 #if defined(TWAIT_HAVE_PID)
396 ATF_TC_HEAD(attach2, tc)
398 atf_tc_set_md_var(tc, "descr",
399 "Assert that any tracer sees process termination before its "
403 ATF_TC_BODY(attach2, tc)
405 struct msg_fds parent_tracer, parent_tracee;
406 const int exitval_tracee = 5;
407 const int exitval_tracer1 = 10, exitval_tracer2 = 20;
408 pid_t tracee, tracer, wpid;
409 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
410 #if defined(TWAIT_HAVE_STATUS)
414 printf("Spawn tracee\n");
415 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
416 tracee = atf_utils_fork();
418 /* Wait for message from the parent */
419 CHILD_FROM_PARENT("Message 1", parent_tracee, msg);
420 _exit(exitval_tracee);
423 printf("Spawn debugger\n");
424 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
425 tracer = atf_utils_fork();
427 /* Fork again and drop parent to reattach to PID 1 */
428 tracer = atf_utils_fork();
430 _exit(exitval_tracer1);
432 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
433 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
435 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
436 FORKEE_REQUIRE_SUCCESS(
437 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
439 forkee_status_stopped(status, SIGSTOP);
441 /* Resume tracee with PT_CONTINUE */
442 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
444 /* Inform parent that tracer has attached to tracee */
445 CHILD_TO_PARENT("Message 1", parent_tracer, msg);
446 CHILD_FROM_PARENT("Message 2", parent_tracer, msg);
448 /* Wait for tracee and assert that it exited */
449 FORKEE_REQUIRE_SUCCESS(
450 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
452 forkee_status_exited(status, exitval_tracee);
454 printf("Before exiting of the tracer process\n");
455 _exit(exitval_tracer2);
457 printf("Wait for the tracer process (direct child) to exit calling "
458 "%s()\n", TWAIT_FNAME);
459 TWAIT_REQUIRE_SUCCESS(
460 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer);
462 validate_status_exited(status, exitval_tracer1);
464 printf("Wait for the non-exited tracee process with %s()\n",
466 TWAIT_REQUIRE_SUCCESS(
467 wpid = TWAIT_GENERIC(tracee, NULL, WNOHANG), 0);
469 printf("Wait for the tracer to attach to the tracee\n");
470 PARENT_FROM_CHILD("Message 1", parent_tracer, msg);
471 printf("Resume the tracee and let it exit\n");
472 PARENT_TO_CHILD("Message 1", parent_tracee, msg);
474 printf("Detect that tracee is zombie\n");
475 await_zombie(tracee);
477 printf("Assert that there is no status about tracee - "
478 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME);
479 TWAIT_REQUIRE_SUCCESS(
480 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
482 printf("Resume the tracer and let it detect exited tracee\n");
483 PARENT_TO_CHILD("Message 2", parent_tracer, msg);
485 printf("Wait for tracee to finish its job and exit - calling %s()\n",
487 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
490 validate_status_exited(status, exitval_tracee);
492 msg_close(&parent_tracer);
493 msg_close(&parent_tracee);
499 ATF_TC_HEAD(attach3, tc)
501 atf_tc_set_md_var(tc, "descr",
502 "Assert that tracer parent can PT_ATTACH to its child");
505 ATF_TC_BODY(attach3, tc)
507 struct msg_fds parent_tracee;
508 const int exitval_tracee = 5;
510 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
511 #if defined(TWAIT_HAVE_STATUS)
515 printf("Spawn tracee\n");
516 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
517 tracee = atf_utils_fork();
519 CHILD_FROM_PARENT("Message 1", parent_tracee, msg);
520 printf("Parent should now attach to tracee\n");
522 CHILD_FROM_PARENT("Message 2", parent_tracee, msg);
523 /* Wait for message from the parent */
524 _exit(exitval_tracee);
526 PARENT_TO_CHILD("Message 1", parent_tracee, msg);
528 printf("Before calling PT_ATTACH for tracee %d\n", tracee);
529 ATF_REQUIRE(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
531 printf("Wait for the stopped tracee process with %s()\n",
533 TWAIT_REQUIRE_SUCCESS(
534 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
536 validate_status_stopped(status, SIGSTOP);
538 printf("Resume tracee with PT_CONTINUE\n");
539 ATF_REQUIRE(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
541 printf("Let the tracee exit now\n");
542 PARENT_TO_CHILD("Message 2", parent_tracee, msg);
544 printf("Wait for tracee to exit with %s()\n", TWAIT_FNAME);
545 TWAIT_REQUIRE_SUCCESS(
546 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
548 validate_status_exited(status, exitval_tracee);
550 printf("Before calling %s() for tracee\n", TWAIT_FNAME);
551 TWAIT_REQUIRE_FAILURE(ECHILD,
552 wpid = TWAIT_GENERIC(tracee, &status, 0));
554 msg_close(&parent_tracee);
558 ATF_TC_HEAD(attach4, tc)
560 atf_tc_set_md_var(tc, "descr",
561 "Assert that tracer child can PT_ATTACH to its parent");
564 ATF_TC_BODY(attach4, tc)
566 struct msg_fds parent_tracee;
567 const int exitval_tracer = 5;
569 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
570 #if defined(TWAIT_HAVE_STATUS)
574 printf("Spawn tracer\n");
575 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
576 tracer = atf_utils_fork();
579 /* Wait for message from the parent */
580 CHILD_FROM_PARENT("Message 1", parent_tracee, msg);
582 printf("Attach to parent PID %d with PT_ATTACH from child\n",
584 FORKEE_ASSERT(ptrace(PT_ATTACH, getppid(), NULL, 0) != -1);
586 printf("Wait for the stopped parent process with %s()\n",
588 FORKEE_REQUIRE_SUCCESS(
589 wpid = TWAIT_GENERIC(getppid(), &status, 0), getppid());
591 forkee_status_stopped(status, SIGSTOP);
593 printf("Resume parent with PT_DETACH\n");
594 FORKEE_ASSERT(ptrace(PT_DETACH, getppid(), (void *)1, 0)
597 /* Tell parent we are ready */
598 CHILD_TO_PARENT("Message 1", parent_tracee, msg);
600 _exit(exitval_tracer);
603 printf("Wait for the tracer to become ready\n");
604 PARENT_TO_CHILD("Message 1", parent_tracee, msg);
605 printf("Allow the tracer to exit now\n");
606 PARENT_FROM_CHILD("Message 1", parent_tracee, msg);
608 printf("Wait for tracer to exit with %s()\n", TWAIT_FNAME);
609 TWAIT_REQUIRE_SUCCESS(
610 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer);
612 validate_status_exited(status, exitval_tracer);
614 printf("Before calling %s() for tracer\n", TWAIT_FNAME);
615 TWAIT_REQUIRE_FAILURE(ECHILD,
616 wpid = TWAIT_GENERIC(tracer, &status, 0));
618 msg_close(&parent_tracee);
621 #if defined(TWAIT_HAVE_PID)
623 ATF_TC_HEAD(attach5, tc)
625 atf_tc_set_md_var(tc, "descr",
626 "Assert that tracer sees its parent when attached to tracer "
627 "(check getppid(2))");
630 ATF_TC_BODY(attach5, tc)
632 struct msg_fds parent_tracer, parent_tracee;
633 const int exitval_tracee = 5;
634 const int exitval_tracer = 10;
635 pid_t parent, tracee, tracer, wpid;
636 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
637 #if defined(TWAIT_HAVE_STATUS)
641 printf("Spawn tracee\n");
642 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
643 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
644 tracee = atf_utils_fork();
648 /* Emit message to the parent */
649 CHILD_TO_PARENT("tracee ready", parent_tracee, msg);
650 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg);
652 FORKEE_ASSERT_EQ(parent, getppid());
654 _exit(exitval_tracee);
656 printf("Wait for child to record its parent identifier (pid)\n");
657 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg);
659 printf("Spawn debugger\n");
660 tracer = atf_utils_fork();
662 /* No IPC to communicate with the child */
663 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
664 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
666 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
667 FORKEE_REQUIRE_SUCCESS(
668 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
670 forkee_status_stopped(status, SIGSTOP);
672 /* Resume tracee with PT_CONTINUE */
673 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
675 /* Inform parent that tracer has attached to tracee */
676 CHILD_TO_PARENT("tracer ready", parent_tracer, msg);
678 /* Wait for parent to tell use that tracee should have exited */
679 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg);
681 /* Wait for tracee and assert that it exited */
682 FORKEE_REQUIRE_SUCCESS(
683 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
685 forkee_status_exited(status, exitval_tracee);
687 printf("Before exiting of the tracer process\n");
688 _exit(exitval_tracer);
691 printf("Wait for the tracer to attach to the tracee\n");
692 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg);
694 printf("Resume the tracee and let it exit\n");
695 PARENT_TO_CHILD("exit tracee", parent_tracee, msg);
697 printf("Detect that tracee is zombie\n");
698 await_zombie(tracee);
700 printf("Assert that there is no status about tracee - "
701 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME);
702 TWAIT_REQUIRE_SUCCESS(
703 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
705 printf("Tell the tracer child should have exited\n");
706 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg);
708 printf("Wait from tracer child to complete waiting for tracee\n");
709 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0),
712 validate_status_exited(status, exitval_tracer);
714 printf("Wait for tracee to finish its job and exit - calling %s()\n",
716 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
719 validate_status_exited(status, exitval_tracee);
721 msg_close(&parent_tracer);
722 msg_close(&parent_tracee);
726 #if defined(TWAIT_HAVE_PID)
728 ATF_TC_HEAD(attach6, tc)
730 atf_tc_set_md_var(tc, "descr",
731 "Assert that tracer sees its parent when attached to tracer "
732 "(check sysctl(7) and struct kinfo_proc2)");
735 ATF_TC_BODY(attach6, tc)
737 struct msg_fds parent_tracee, parent_tracer;
738 const int exitval_tracee = 5;
739 const int exitval_tracer = 10;
740 pid_t parent, tracee, tracer, wpid;
741 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
742 #if defined(TWAIT_HAVE_STATUS)
745 int name[CTL_MAXNAME];
746 struct kinfo_proc2 kp;
747 size_t len = sizeof(kp);
748 unsigned int namelen;
750 printf("Spawn tracee\n");
751 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
752 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
753 tracee = atf_utils_fork();
757 /* Emit message to the parent */
758 CHILD_TO_PARENT("Message 1", parent_tracee, msg);
759 CHILD_FROM_PARENT("Message 2", parent_tracee, msg);
762 name[namelen++] = CTL_KERN;
763 name[namelen++] = KERN_PROC2;
764 name[namelen++] = KERN_PROC_PID;
765 name[namelen++] = getpid();
766 name[namelen++] = len;
769 FORKEE_ASSERT(sysctl(name, namelen, &kp, &len, NULL, 0) == 0);
770 FORKEE_ASSERT_EQ(parent, kp.p_ppid);
772 _exit(exitval_tracee);
775 printf("Wait for child to record its parent identifier (pid)\n");
776 PARENT_FROM_CHILD("Message 1", parent_tracee, msg);
778 printf("Spawn debugger\n");
779 tracer = atf_utils_fork();
781 /* No IPC to communicate with the child */
782 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
783 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
785 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
786 FORKEE_REQUIRE_SUCCESS(
787 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
789 forkee_status_stopped(status, SIGSTOP);
791 /* Resume tracee with PT_CONTINUE */
792 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
794 /* Inform parent that tracer has attached to tracee */
795 CHILD_TO_PARENT("Message 1", parent_tracer, msg);
797 CHILD_FROM_PARENT("Message 2", parent_tracer, msg);
799 /* Wait for tracee and assert that it exited */
800 FORKEE_REQUIRE_SUCCESS(
801 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
803 forkee_status_exited(status, exitval_tracee);
805 printf("Before exiting of the tracer process\n");
806 _exit(exitval_tracer);
809 printf("Wait for the tracer to attach to the tracee\n");
810 PARENT_FROM_CHILD("Message 1", parent_tracer, msg);
812 printf("Resume the tracee and let it exit\n");
813 PARENT_TO_CHILD("Message 1", parent_tracee, msg);
815 printf("Detect that tracee is zombie\n");
816 await_zombie(tracee);
818 printf("Assert that there is no status about tracee - "
819 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME);
820 TWAIT_REQUIRE_SUCCESS(
821 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
823 printf("Resume the tracer and let it detect exited tracee\n");
824 PARENT_TO_CHILD("Message 2", parent_tracer, msg);
826 printf("Wait for tracer to finish its job and exit - calling %s()\n",
828 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0),
831 validate_status_exited(status, exitval_tracer);
833 printf("Wait for tracee to finish its job and exit - calling %s()\n",
835 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
838 validate_status_exited(status, exitval_tracee);
840 msg_close(&parent_tracee);
841 msg_close(&parent_tracer);
845 #if defined(TWAIT_HAVE_PID)
847 ATF_TC_HEAD(attach7, tc)
849 atf_tc_set_md_var(tc, "descr",
850 "Assert that tracer sees its parent when attached to tracer "
851 "(check /proc/curproc/status 3rd column)");
854 ATF_TC_BODY(attach7, tc)
856 struct msg_fds parent_tracee, parent_tracer;
858 const int exitval_tracee = 5;
859 const int exitval_tracer = 10;
860 pid_t parent, tracee, tracer, wpid;
861 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
862 #if defined(TWAIT_HAVE_STATUS)
867 const char *fname = "/proc/curproc/status";
868 char s_executable[MAXPATHLEN];
872 * EXECUTABLE PID PPID ...
875 ATF_REQUIRE((rv = stat(fname, &st)) == 0 || (errno == ENOENT));
877 atf_tc_skip("/proc/curproc/status not found");
880 printf("Spawn tracee\n");
881 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
882 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
883 tracee = atf_utils_fork();
887 // Wait for parent to let us exit
888 CHILD_TO_PARENT("tracee ready", parent_tracee, msg);
889 CHILD_FROM_PARENT("tracee exit", parent_tracee, msg);
891 FORKEE_ASSERT((fp = fopen(fname, "r")) != NULL);
892 fscanf(fp, "%s %d %d", s_executable, &s_pid, &s_ppid);
893 FORKEE_ASSERT(fclose(fp) == 0);
894 FORKEE_ASSERT_EQ(parent, s_ppid);
896 _exit(exitval_tracee);
899 printf("Wait for child to record its parent identifier (pid)\n");
900 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg);
902 printf("Spawn debugger\n");
903 tracer = atf_utils_fork();
905 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
906 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
908 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
909 FORKEE_REQUIRE_SUCCESS(
910 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
912 forkee_status_stopped(status, SIGSTOP);
914 /* Resume tracee with PT_CONTINUE */
915 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
917 /* Inform parent that tracer has attached to tracee */
918 CHILD_TO_PARENT("tracer ready", parent_tracer, msg);
920 /* Wait for parent to tell use that tracee should have exited */
921 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg);
923 /* Wait for tracee and assert that it exited */
924 FORKEE_REQUIRE_SUCCESS(
925 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
927 forkee_status_exited(status, exitval_tracee);
929 printf("Before exiting of the tracer process\n");
930 _exit(exitval_tracer);
932 printf("Wait for the tracer to attach to the tracee\n");
933 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg);
934 printf("Resume the tracee and let it exit\n");
935 PARENT_TO_CHILD("tracee exit", parent_tracee, msg);
937 printf("Detect that tracee is zombie\n");
938 await_zombie(tracee);
940 printf("Assert that there is no status about tracee - "
941 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME);
942 TWAIT_REQUIRE_SUCCESS(
943 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
945 printf("Resume the tracer and let it detect exited tracee\n");
946 PARENT_TO_CHILD("Message 2", parent_tracer, msg);
948 printf("Wait for tracer to finish its job and exit - calling %s()\n",
950 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0),
953 validate_status_exited(status, exitval_tracer);
955 printf("Wait for tracee to finish its job and exit - calling %s()\n",
957 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
960 validate_status_exited(status, exitval_tracee);
962 msg_close(&parent_tracee);
963 msg_close(&parent_tracer);
968 ATF_TC_HEAD(eventmask1, tc)
970 atf_tc_set_md_var(tc, "descr",
971 "Verify that empty EVENT_MASK is preserved");
974 ATF_TC_BODY(eventmask1, tc)
976 const int exitval = 5;
977 const int sigval = SIGSTOP;
979 #if defined(TWAIT_HAVE_STATUS)
982 ptrace_event_t set_event, get_event;
983 const int len = sizeof(ptrace_event_t);
985 printf("Before forking process PID=%d\n", getpid());
986 ATF_REQUIRE((child = fork()) != -1);
988 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
989 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
991 printf("Before raising %s from child\n", strsignal(sigval));
992 FORKEE_ASSERT(raise(sigval) == 0);
994 printf("Before exiting of the child process\n");
997 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
999 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1000 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1002 validate_status_stopped(status, sigval);
1004 set_event.pe_set_event = 0;
1005 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1006 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1007 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1009 printf("Before resuming the child process where it left off and "
1010 "without signal to be sent\n");
1011 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1013 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1014 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1016 validate_status_exited(status, exitval);
1018 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1019 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1023 ATF_TC_HEAD(eventmask2, tc)
1025 atf_tc_set_md_var(tc, "descr",
1026 "Verify that PTRACE_FORK in EVENT_MASK is preserved");
1029 ATF_TC_BODY(eventmask2, tc)
1031 const int exitval = 5;
1032 const int sigval = SIGSTOP;
1034 #if defined(TWAIT_HAVE_STATUS)
1037 ptrace_event_t set_event, get_event;
1038 const int len = sizeof(ptrace_event_t);
1040 printf("Before forking process PID=%d\n", getpid());
1041 ATF_REQUIRE((child = fork()) != -1);
1043 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1044 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1046 printf("Before raising %s from child\n", strsignal(sigval));
1047 FORKEE_ASSERT(raise(sigval) == 0);
1049 printf("Before exiting of the child process\n");
1052 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1054 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1055 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1057 validate_status_stopped(status, sigval);
1059 set_event.pe_set_event = PTRACE_FORK;
1060 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1061 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1062 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1064 printf("Before resuming the child process where it left off and "
1065 "without signal to be sent\n");
1066 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1068 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1069 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1071 validate_status_exited(status, exitval);
1073 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1074 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1078 ATF_TC_HEAD(eventmask3, tc)
1080 atf_tc_set_md_var(tc, "descr",
1081 "Verify that PTRACE_VFORK in EVENT_MASK is preserved");
1084 ATF_TC_BODY(eventmask3, tc)
1086 const int exitval = 5;
1087 const int sigval = SIGSTOP;
1089 #if defined(TWAIT_HAVE_STATUS)
1092 ptrace_event_t set_event, get_event;
1093 const int len = sizeof(ptrace_event_t);
1095 atf_tc_expect_fail("PR kern/51630");
1097 printf("Before forking process PID=%d\n", getpid());
1098 ATF_REQUIRE((child = fork()) != -1);
1100 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1101 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1103 printf("Before raising %s from child\n", strsignal(sigval));
1104 FORKEE_ASSERT(raise(sigval) == 0);
1106 printf("Before exiting of the child process\n");
1109 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1111 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1112 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1114 validate_status_stopped(status, sigval);
1116 set_event.pe_set_event = PTRACE_VFORK;
1117 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1118 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1119 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1121 printf("Before resuming the child process where it left off and "
1122 "without signal to be sent\n");
1123 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1125 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1126 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1128 validate_status_exited(status, exitval);
1130 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1131 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1135 ATF_TC_HEAD(eventmask4, tc)
1137 atf_tc_set_md_var(tc, "descr",
1138 "Verify that PTRACE_VFORK_DONE in EVENT_MASK is preserved");
1141 ATF_TC_BODY(eventmask4, tc)
1143 const int exitval = 5;
1144 const int sigval = SIGSTOP;
1146 #if defined(TWAIT_HAVE_STATUS)
1149 ptrace_event_t set_event, get_event;
1150 const int len = sizeof(ptrace_event_t);
1152 printf("Before forking process PID=%d\n", getpid());
1153 ATF_REQUIRE((child = fork()) != -1);
1155 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1156 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1158 printf("Before raising %s from child\n", strsignal(sigval));
1159 FORKEE_ASSERT(raise(sigval) == 0);
1161 printf("Before exiting of the child process\n");
1164 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1166 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1167 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1169 validate_status_stopped(status, sigval);
1171 set_event.pe_set_event = PTRACE_VFORK_DONE;
1172 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1173 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1174 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1176 printf("Before resuming the child process where it left off and "
1177 "without signal to be sent\n");
1178 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1180 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1181 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1183 validate_status_exited(status, exitval);
1185 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1186 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1190 ATF_TC_HEAD(eventmask5, tc)
1192 atf_tc_set_md_var(tc, "descr",
1193 "Verify that PTRACE_LWP_CREATE in EVENT_MASK is preserved");
1196 ATF_TC_BODY(eventmask5, tc)
1198 const int exitval = 5;
1199 const int sigval = SIGSTOP;
1201 #if defined(TWAIT_HAVE_STATUS)
1204 ptrace_event_t set_event, get_event;
1205 const int len = sizeof(ptrace_event_t);
1207 printf("Before forking process PID=%d\n", getpid());
1208 ATF_REQUIRE((child = fork()) != -1);
1210 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1211 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1213 printf("Before raising %s from child\n", strsignal(sigval));
1214 FORKEE_ASSERT(raise(sigval) == 0);
1216 printf("Before exiting of the child process\n");
1219 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1221 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1222 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1224 validate_status_stopped(status, sigval);
1226 set_event.pe_set_event = PTRACE_LWP_CREATE;
1227 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1228 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1229 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1231 printf("Before resuming the child process where it left off and "
1232 "without signal to be sent\n");
1233 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1235 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1236 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1238 validate_status_exited(status, exitval);
1240 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1241 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1245 ATF_TC_HEAD(eventmask6, tc)
1247 atf_tc_set_md_var(tc, "descr",
1248 "Verify that PTRACE_LWP_EXIT in EVENT_MASK is preserved");
1251 ATF_TC_BODY(eventmask6, tc)
1253 const int exitval = 5;
1254 const int sigval = SIGSTOP;
1256 #if defined(TWAIT_HAVE_STATUS)
1259 ptrace_event_t set_event, get_event;
1260 const int len = sizeof(ptrace_event_t);
1262 printf("Before forking process PID=%d\n", getpid());
1263 ATF_REQUIRE((child = fork()) != -1);
1265 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1266 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1268 printf("Before raising %s from child\n", strsignal(sigval));
1269 FORKEE_ASSERT(raise(sigval) == 0);
1271 printf("Before exiting of the child process\n");
1274 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1276 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1277 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1279 validate_status_stopped(status, sigval);
1281 set_event.pe_set_event = PTRACE_LWP_EXIT;
1282 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1);
1283 ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1);
1284 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0);
1286 printf("Before resuming the child process where it left off and "
1287 "without signal to be sent\n");
1288 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1290 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1291 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1293 validate_status_exited(status, exitval);
1295 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1296 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1299 #if defined(TWAIT_HAVE_PID)
1301 ATF_TC_HEAD(fork1, tc)
1303 atf_tc_set_md_var(tc, "descr",
1304 "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK "
1305 "set to PTRACE_FORK");
1308 ATF_TC_BODY(fork1, tc)
1310 const int exitval = 5;
1311 const int exitval2 = 15;
1312 const int sigval = SIGSTOP;
1313 pid_t child, child2, wpid;
1314 #if defined(TWAIT_HAVE_STATUS)
1317 ptrace_state_t state;
1318 const int slen = sizeof(state);
1319 ptrace_event_t event;
1320 const int elen = sizeof(event);
1322 printf("Before forking process PID=%d\n", getpid());
1323 ATF_REQUIRE((child = fork()) != -1);
1325 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1326 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1328 printf("Before raising %s from child\n", strsignal(sigval));
1329 FORKEE_ASSERT(raise(sigval) == 0);
1331 FORKEE_ASSERT((child2 = fork()) != 1);
1336 FORKEE_REQUIRE_SUCCESS
1337 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1339 forkee_status_exited(status, exitval2);
1341 printf("Before exiting of the child process\n");
1344 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1346 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1347 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1349 validate_status_stopped(status, sigval);
1351 printf("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child);
1352 event.pe_set_event = PTRACE_FORK;
1353 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1355 printf("Before resuming the child process where it left off and "
1356 "without signal to be sent\n");
1357 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1359 printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
1360 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1362 validate_status_stopped(status, SIGTRAP);
1364 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
1365 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
1367 child2 = state.pe_other_pid;
1368 printf("Reported PTRACE_FORK event with forkee %d\n", child2);
1370 printf("Before calling %s() for the forkee %d of the child %d\n",
1371 TWAIT_FNAME, child2, child);
1372 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
1375 validate_status_stopped(status, SIGTRAP);
1377 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
1378 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
1379 ATF_REQUIRE_EQ(state.pe_other_pid, child);
1381 printf("Before resuming the forkee process where it left off and "
1382 "without signal to be sent\n");
1383 ATF_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
1385 printf("Before resuming the child process where it left off and "
1386 "without signal to be sent\n");
1387 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1389 printf("Before calling %s() for the forkee - expected exited\n",
1391 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
1394 validate_status_exited(status, exitval2);
1396 printf("Before calling %s() for the forkee - expected no process\n",
1398 TWAIT_REQUIRE_FAILURE(ECHILD,
1399 wpid = TWAIT_GENERIC(child2, &status, 0));
1401 printf("Before calling %s() for the child - expected stopped "
1402 "SIGCHLD\n", TWAIT_FNAME);
1403 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1405 validate_status_stopped(status, SIGCHLD);
1407 printf("Before resuming the child process where it left off and "
1408 "without signal to be sent\n");
1409 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1411 printf("Before calling %s() for the child - expected exited\n",
1413 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1415 validate_status_exited(status, exitval);
1417 printf("Before calling %s() for the child - expected no process\n",
1419 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1424 ATF_TC_HEAD(fork2, tc)
1426 atf_tc_set_md_var(tc, "descr",
1427 "Verify that fork(2) is not intercepted by ptrace(2) with empty "
1431 ATF_TC_BODY(fork2, tc)
1433 const int exitval = 5;
1434 const int exitval2 = 15;
1435 const int sigval = SIGSTOP;
1436 pid_t child, child2, wpid;
1437 #if defined(TWAIT_HAVE_STATUS)
1440 ptrace_event_t event;
1441 const int elen = sizeof(event);
1443 printf("Before forking process PID=%d\n", getpid());
1444 ATF_REQUIRE((child = fork()) != -1);
1446 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1447 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1449 printf("Before raising %s from child\n", strsignal(sigval));
1450 FORKEE_ASSERT(raise(sigval) == 0);
1452 FORKEE_ASSERT((child2 = fork()) != 1);
1457 FORKEE_REQUIRE_SUCCESS
1458 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1460 forkee_status_exited(status, exitval2);
1462 printf("Before exiting of the child process\n");
1465 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1467 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1468 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1470 validate_status_stopped(status, sigval);
1472 printf("Set empty EVENT_MASK for the child %d\n", child);
1473 event.pe_set_event = 0;
1474 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1476 printf("Before resuming the child process where it left off and "
1477 "without signal to be sent\n");
1478 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1480 printf("Before calling %s() for the child - expected stopped "
1481 "SIGCHLD\n", TWAIT_FNAME);
1482 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1484 validate_status_stopped(status, SIGCHLD);
1486 printf("Before resuming the child process where it left off and "
1487 "without signal to be sent\n");
1488 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1490 printf("Before calling %s() for the child - expected exited\n",
1492 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1494 validate_status_exited(status, exitval);
1496 printf("Before calling %s() for the child - expected no process\n",
1498 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1501 #if defined(TWAIT_HAVE_PID)
1503 ATF_TC_HEAD(vfork1, tc)
1505 atf_tc_set_md_var(tc, "descr",
1506 "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK "
1507 "set to PTRACE_VFORK");
1510 ATF_TC_BODY(vfork1, tc)
1512 const int exitval = 5;
1513 const int exitval2 = 15;
1514 const int sigval = SIGSTOP;
1515 pid_t child, child2, wpid;
1516 #if defined(TWAIT_HAVE_STATUS)
1519 ptrace_state_t state;
1520 const int slen = sizeof(state);
1521 ptrace_event_t event;
1522 const int elen = sizeof(event);
1524 atf_tc_expect_fail("PR kern/51630");
1526 printf("Before forking process PID=%d\n", getpid());
1527 ATF_REQUIRE((child = fork()) != -1);
1529 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1530 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1532 printf("Before raising %s from child\n", strsignal(sigval));
1533 FORKEE_ASSERT(raise(sigval) == 0);
1535 FORKEE_ASSERT((child2 = vfork()) != 1);
1540 FORKEE_REQUIRE_SUCCESS
1541 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1543 forkee_status_exited(status, exitval2);
1545 printf("Before exiting of the child process\n");
1548 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1550 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1551 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1553 validate_status_stopped(status, sigval);
1555 printf("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child);
1556 event.pe_set_event = PTRACE_VFORK;
1557 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1559 printf("Before resuming the child process where it left off and "
1560 "without signal to be sent\n");
1561 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1563 printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
1564 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1566 validate_status_stopped(status, SIGTRAP);
1568 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
1569 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK);
1571 child2 = state.pe_other_pid;
1572 printf("Reported PTRACE_VFORK event with forkee %d\n", child2);
1574 printf("Before calling %s() for the forkee %d of the child %d\n",
1575 TWAIT_FNAME, child2, child);
1576 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
1579 validate_status_stopped(status, SIGTRAP);
1581 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
1582 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK);
1583 ATF_REQUIRE_EQ(state.pe_other_pid, child);
1585 printf("Before resuming the forkee process where it left off and "
1586 "without signal to be sent\n");
1587 ATF_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
1589 printf("Before resuming the child process where it left off and "
1590 "without signal to be sent\n");
1591 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1593 printf("Before calling %s() for the forkee - expected exited\n",
1595 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
1598 validate_status_exited(status, exitval2);
1600 printf("Before calling %s() for the forkee - expected no process\n",
1602 TWAIT_REQUIRE_FAILURE(ECHILD,
1603 wpid = TWAIT_GENERIC(child2, &status, 0));
1605 printf("Before calling %s() for the child - expected stopped "
1606 "SIGCHLD\n", TWAIT_FNAME);
1607 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1609 validate_status_stopped(status, SIGCHLD);
1611 printf("Before resuming the child process where it left off and "
1612 "without signal to be sent\n");
1613 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1615 printf("Before calling %s() for the child - expected exited\n",
1617 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1619 validate_status_exited(status, exitval);
1621 printf("Before calling %s() for the child - expected no process\n",
1623 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1628 ATF_TC_HEAD(vfork2, tc)
1630 atf_tc_set_md_var(tc, "descr",
1631 "Verify that vfork(2) is not intercepted by ptrace(2) with empty "
1635 ATF_TC_BODY(vfork2, tc)
1637 const int exitval = 5;
1638 const int exitval2 = 15;
1639 const int sigval = SIGSTOP;
1640 pid_t child, child2, wpid;
1641 #if defined(TWAIT_HAVE_STATUS)
1644 ptrace_event_t event;
1645 const int elen = sizeof(event);
1647 printf("Before forking process PID=%d\n", getpid());
1648 ATF_REQUIRE((child = fork()) != -1);
1650 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1651 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1653 printf("Before raising %s from child\n", strsignal(sigval));
1654 FORKEE_ASSERT(raise(sigval) == 0);
1656 FORKEE_ASSERT((child2 = vfork()) != 1);
1661 FORKEE_REQUIRE_SUCCESS
1662 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1664 forkee_status_exited(status, exitval2);
1666 printf("Before exiting of the child process\n");
1669 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1671 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1672 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1674 validate_status_stopped(status, sigval);
1676 printf("Set empty EVENT_MASK for the child %d\n", child);
1677 event.pe_set_event = 0;
1678 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1680 printf("Before resuming the child process where it left off and "
1681 "without signal to be sent\n");
1682 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1684 printf("Before calling %s() for the child - expected stopped "
1685 "SIGCHLD\n", TWAIT_FNAME);
1686 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1688 validate_status_stopped(status, SIGCHLD);
1690 printf("Before resuming the child process where it left off and "
1691 "without signal to be sent\n");
1692 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1694 printf("Before calling %s() for the child - expected exited\n",
1696 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1698 validate_status_exited(status, exitval);
1700 printf("Before calling %s() for the child - expected no process\n",
1702 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1706 ATF_TC_HEAD(vforkdone1, tc)
1708 atf_tc_set_md_var(tc, "descr",
1709 "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK "
1710 "set to PTRACE_VFORK_DONE");
1713 ATF_TC_BODY(vforkdone1, tc)
1715 const int exitval = 5;
1716 const int exitval2 = 15;
1717 const int sigval = SIGSTOP;
1718 pid_t child, child2, wpid;
1719 #if defined(TWAIT_HAVE_STATUS)
1722 ptrace_state_t state;
1723 const int slen = sizeof(state);
1724 ptrace_event_t event;
1725 const int elen = sizeof(event);
1727 printf("Before forking process PID=%d\n", getpid());
1728 ATF_REQUIRE((child = fork()) != -1);
1730 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1731 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1733 printf("Before raising %s from child\n", strsignal(sigval));
1734 FORKEE_ASSERT(raise(sigval) == 0);
1736 FORKEE_ASSERT((child2 = vfork()) != 1);
1741 FORKEE_REQUIRE_SUCCESS
1742 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1744 forkee_status_exited(status, exitval2);
1746 printf("Before exiting of the child process\n");
1749 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1751 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1752 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1754 validate_status_stopped(status, sigval);
1756 printf("Enable PTRACE_VFORK_DONE in EVENT_MASK for the child %d\n",
1758 event.pe_set_event = PTRACE_VFORK_DONE;
1759 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1761 printf("Before resuming the child process where it left off and "
1762 "without signal to be sent\n");
1763 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1765 printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
1766 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1768 validate_status_stopped(status, SIGTRAP);
1770 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
1771 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE);
1773 child2 = state.pe_other_pid;
1774 printf("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2);
1776 printf("Before resuming the child process where it left off and "
1777 "without signal to be sent\n");
1778 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1780 printf("Before calling %s() for the child - expected stopped "
1781 "SIGCHLD\n", TWAIT_FNAME);
1782 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1784 validate_status_stopped(status, SIGCHLD);
1786 printf("Before resuming the child process where it left off and "
1787 "without signal to be sent\n");
1788 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1790 printf("Before calling %s() for the child - expected exited\n",
1792 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1794 validate_status_exited(status, exitval);
1796 printf("Before calling %s() for the child - expected no process\n",
1798 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1802 ATF_TC_HEAD(vforkdone2, tc)
1804 atf_tc_set_md_var(tc, "descr",
1805 "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK "
1806 "set to PTRACE_FORK | PTRACE_VFORK_DONE");
1809 ATF_TC_BODY(vforkdone2, tc)
1811 const int exitval = 5;
1812 const int exitval2 = 15;
1813 const int sigval = SIGSTOP;
1814 pid_t child, child2, wpid;
1815 #if defined(TWAIT_HAVE_STATUS)
1818 ptrace_state_t state;
1819 const int slen = sizeof(state);
1820 ptrace_event_t event;
1821 const int elen = sizeof(event);
1823 printf("Before forking process PID=%d\n", getpid());
1824 ATF_REQUIRE((child = fork()) != -1);
1826 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1827 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1829 printf("Before raising %s from child\n", strsignal(sigval));
1830 FORKEE_ASSERT(raise(sigval) == 0);
1832 FORKEE_ASSERT((child2 = vfork()) != 1);
1837 FORKEE_REQUIRE_SUCCESS
1838 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
1840 forkee_status_exited(status, exitval2);
1842 printf("Before exiting of the child process\n");
1845 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1847 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1848 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1850 validate_status_stopped(status, sigval);
1852 printf("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child);
1853 event.pe_set_event = PTRACE_FORK | PTRACE_VFORK_DONE;
1854 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
1856 printf("Before resuming the child process where it left off and "
1857 "without signal to be sent\n");
1858 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1860 printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
1861 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1863 validate_status_stopped(status, SIGTRAP);
1865 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
1866 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE);
1868 child2 = state.pe_other_pid;
1869 printf("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2);
1871 printf("Before resuming the child process where it left off and "
1872 "without signal to be sent\n");
1873 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1875 printf("Before calling %s() for the child - expected stopped "
1876 "SIGCHLD\n", TWAIT_FNAME);
1877 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1879 validate_status_stopped(status, SIGCHLD);
1881 printf("Before resuming the child process where it left off and "
1882 "without signal to be sent\n");
1883 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1885 printf("Before calling %s() for the child - expected exited\n",
1887 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1889 validate_status_exited(status, exitval);
1891 printf("Before calling %s() for the child - expected no process\n",
1893 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1897 ATF_TC_HEAD(io_read_d1, tc)
1899 atf_tc_set_md_var(tc, "descr",
1900 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint8_t)");
1903 ATF_TC_BODY(io_read_d1, tc)
1905 const int exitval = 5;
1906 const int sigval = SIGSTOP;
1908 uint8_t lookup_me = 0;
1909 const uint8_t magic = 0xab;
1910 struct ptrace_io_desc io = {
1911 .piod_op = PIOD_READ_D,
1912 .piod_offs = &lookup_me,
1913 .piod_addr = &lookup_me,
1914 .piod_len = sizeof(lookup_me)
1916 #if defined(TWAIT_HAVE_STATUS)
1920 printf("Before forking process PID=%d\n", getpid());
1921 ATF_REQUIRE((child = fork()) != -1);
1923 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1924 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1928 printf("Before raising %s from child\n", strsignal(sigval));
1929 FORKEE_ASSERT(raise(sigval) == 0);
1931 printf("Before exiting of the child process\n");
1934 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
1936 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1937 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1939 validate_status_stopped(status, sigval);
1941 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
1943 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
1945 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
1946 "got value %" PRIx8 " != expected %" PRIx8, lookup_me, magic);
1948 printf("Before resuming the child process where it left off and "
1949 "without signal to be sent\n");
1950 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
1952 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1953 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
1955 validate_status_exited(status, exitval);
1957 printf("Before calling %s() for the child\n", TWAIT_FNAME);
1958 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
1962 ATF_TC_HEAD(io_read_d2, tc)
1964 atf_tc_set_md_var(tc, "descr",
1965 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint16_t)");
1968 ATF_TC_BODY(io_read_d2, tc)
1970 const int exitval = 5;
1971 const int sigval = SIGSTOP;
1973 uint16_t lookup_me = 0;
1974 const uint16_t magic = 0x1234;
1975 struct ptrace_io_desc io = {
1976 .piod_op = PIOD_READ_D,
1977 .piod_offs = &lookup_me,
1978 .piod_addr = &lookup_me,
1979 .piod_len = sizeof(lookup_me)
1981 #if defined(TWAIT_HAVE_STATUS)
1985 printf("Before forking process PID=%d\n", getpid());
1986 ATF_REQUIRE((child = fork()) != -1);
1988 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
1989 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
1993 printf("Before raising %s from child\n", strsignal(sigval));
1994 FORKEE_ASSERT(raise(sigval) == 0);
1996 printf("Before exiting of the child process\n");
1999 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2001 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2002 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2004 validate_status_stopped(status, sigval);
2006 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
2008 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2010 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
2011 "got value %" PRIx16 " != expected %" PRIx16, lookup_me, magic);
2013 printf("Before resuming the child process where it left off and "
2014 "without signal to be sent\n");
2015 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2017 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2018 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2020 validate_status_exited(status, exitval);
2022 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2023 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2027 ATF_TC_HEAD(io_read_d3, tc)
2029 atf_tc_set_md_var(tc, "descr",
2030 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint32_t)");
2033 ATF_TC_BODY(io_read_d3, tc)
2035 const int exitval = 5;
2036 const int sigval = SIGSTOP;
2038 uint32_t lookup_me = 0;
2039 const uint32_t magic = 0x1234abcd;
2040 struct ptrace_io_desc io = {
2041 .piod_op = PIOD_READ_D,
2042 .piod_offs = &lookup_me,
2043 .piod_addr = &lookup_me,
2044 .piod_len = sizeof(lookup_me)
2046 #if defined(TWAIT_HAVE_STATUS)
2050 printf("Before forking process PID=%d\n", getpid());
2051 ATF_REQUIRE((child = fork()) != -1);
2053 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2054 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2058 printf("Before raising %s from child\n", strsignal(sigval));
2059 FORKEE_ASSERT(raise(sigval) == 0);
2061 printf("Before exiting of the child process\n");
2064 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2066 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2067 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2069 validate_status_stopped(status, sigval);
2071 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
2073 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2075 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
2076 "got value %" PRIx32 " != expected %" PRIx32, lookup_me, magic);
2078 printf("Before resuming the child process where it left off and "
2079 "without signal to be sent\n");
2080 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2082 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2083 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2085 validate_status_exited(status, exitval);
2087 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2088 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2092 ATF_TC_HEAD(io_read_d4, tc)
2094 atf_tc_set_md_var(tc, "descr",
2095 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint64_t)");
2098 ATF_TC_BODY(io_read_d4, tc)
2100 const int exitval = 5;
2101 const int sigval = SIGSTOP;
2103 uint64_t lookup_me = 0;
2104 const uint64_t magic = 0x1234abcd9876dcfa;
2105 struct ptrace_io_desc io = {
2106 .piod_op = PIOD_READ_D,
2107 .piod_offs = &lookup_me,
2108 .piod_addr = &lookup_me,
2109 .piod_len = sizeof(lookup_me)
2111 #if defined(TWAIT_HAVE_STATUS)
2115 printf("Before forking process PID=%d\n", getpid());
2116 ATF_REQUIRE((child = fork()) != -1);
2118 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2119 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2123 printf("Before raising %s from child\n", strsignal(sigval));
2124 FORKEE_ASSERT(raise(sigval) == 0);
2126 printf("Before exiting of the child process\n");
2129 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2131 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2132 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2134 validate_status_stopped(status, sigval);
2136 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
2138 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2140 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
2141 "got value %" PRIx64 " != expected %" PRIx64, lookup_me, magic);
2143 printf("Before resuming the child process where it left off and "
2144 "without signal to be sent\n");
2145 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2147 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2148 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2150 validate_status_exited(status, exitval);
2152 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2153 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2156 ATF_TC(io_write_d1);
2157 ATF_TC_HEAD(io_write_d1, tc)
2159 atf_tc_set_md_var(tc, "descr",
2160 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint8_t)");
2163 ATF_TC_BODY(io_write_d1, tc)
2165 const int exitval = 5;
2166 const int sigval = SIGSTOP;
2168 uint8_t lookup_me = 0;
2169 const uint8_t magic = 0xab;
2170 struct ptrace_io_desc io = {
2171 .piod_op = PIOD_WRITE_D,
2172 .piod_offs = &lookup_me,
2173 .piod_addr = &lookup_me,
2174 .piod_len = sizeof(lookup_me)
2176 #if defined(TWAIT_HAVE_STATUS)
2180 printf("Before forking process PID=%d\n", getpid());
2181 ATF_REQUIRE((child = fork()) != -1);
2183 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2184 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2186 printf("Before raising %s from child\n", strsignal(sigval));
2187 FORKEE_ASSERT(raise(sigval) == 0);
2189 FORKEE_ASSERT_EQ(lookup_me, magic);
2191 printf("Before exiting of the child process\n");
2194 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2196 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2197 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2199 validate_status_stopped(status, sigval);
2203 printf("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n",
2205 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2207 printf("Before resuming the child process where it left off and "
2208 "without signal to be sent\n");
2209 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2211 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2212 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2214 validate_status_exited(status, exitval);
2216 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2217 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2220 ATF_TC(io_write_d2);
2221 ATF_TC_HEAD(io_write_d2, tc)
2223 atf_tc_set_md_var(tc, "descr",
2224 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint16_t)");
2227 ATF_TC_BODY(io_write_d2, tc)
2229 const int exitval = 5;
2230 const int sigval = SIGSTOP;
2232 uint16_t lookup_me = 0;
2233 const uint16_t magic = 0xab12;
2234 struct ptrace_io_desc io = {
2235 .piod_op = PIOD_WRITE_D,
2236 .piod_offs = &lookup_me,
2237 .piod_addr = &lookup_me,
2238 .piod_len = sizeof(lookup_me)
2240 #if defined(TWAIT_HAVE_STATUS)
2244 printf("Before forking process PID=%d\n", getpid());
2245 ATF_REQUIRE((child = fork()) != -1);
2247 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2248 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2250 printf("Before raising %s from child\n", strsignal(sigval));
2251 FORKEE_ASSERT(raise(sigval) == 0);
2253 FORKEE_ASSERT_EQ(lookup_me, magic);
2255 printf("Before exiting of the child process\n");
2258 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2260 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2261 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2263 validate_status_stopped(status, sigval);
2267 printf("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n",
2269 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2271 printf("Before resuming the child process where it left off and "
2272 "without signal to be sent\n");
2273 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2275 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2276 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2278 validate_status_exited(status, exitval);
2280 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2281 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2284 ATF_TC(io_write_d3);
2285 ATF_TC_HEAD(io_write_d3, tc)
2287 atf_tc_set_md_var(tc, "descr",
2288 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint32_t)");
2291 ATF_TC_BODY(io_write_d3, tc)
2293 const int exitval = 5;
2294 const int sigval = SIGSTOP;
2296 uint32_t lookup_me = 0;
2297 const uint32_t magic = 0xab127643;
2298 struct ptrace_io_desc io = {
2299 .piod_op = PIOD_WRITE_D,
2300 .piod_offs = &lookup_me,
2301 .piod_addr = &lookup_me,
2302 .piod_len = sizeof(lookup_me)
2304 #if defined(TWAIT_HAVE_STATUS)
2308 printf("Before forking process PID=%d\n", getpid());
2309 ATF_REQUIRE((child = fork()) != -1);
2311 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2312 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2314 printf("Before raising %s from child\n", strsignal(sigval));
2315 FORKEE_ASSERT(raise(sigval) == 0);
2317 FORKEE_ASSERT_EQ(lookup_me, magic);
2319 printf("Before exiting of the child process\n");
2322 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2324 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2325 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2327 validate_status_stopped(status, sigval);
2331 printf("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n",
2333 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2335 printf("Before resuming the child process where it left off and "
2336 "without signal to be sent\n");
2337 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2339 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2340 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2342 validate_status_exited(status, exitval);
2344 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2345 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2348 ATF_TC(io_write_d4);
2349 ATF_TC_HEAD(io_write_d4, tc)
2351 atf_tc_set_md_var(tc, "descr",
2352 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint64_t)");
2355 ATF_TC_BODY(io_write_d4, tc)
2357 const int exitval = 5;
2358 const int sigval = SIGSTOP;
2360 uint64_t lookup_me = 0;
2361 const uint64_t magic = 0xab12764376490123;
2362 struct ptrace_io_desc io = {
2363 .piod_op = PIOD_WRITE_D,
2364 .piod_offs = &lookup_me,
2365 .piod_addr = &lookup_me,
2366 .piod_len = sizeof(lookup_me)
2368 #if defined(TWAIT_HAVE_STATUS)
2372 printf("Before forking process PID=%d\n", getpid());
2373 ATF_REQUIRE((child = fork()) != -1);
2375 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2376 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2378 printf("Before raising %s from child\n", strsignal(sigval));
2379 FORKEE_ASSERT(raise(sigval) == 0);
2381 FORKEE_ASSERT_EQ(lookup_me, magic);
2383 printf("Before exiting of the child process\n");
2386 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2388 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2389 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2391 validate_status_stopped(status, sigval);
2395 printf("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n",
2397 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2399 printf("Before resuming the child process where it left off and "
2400 "without signal to be sent\n");
2401 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2403 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2404 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2406 validate_status_exited(status, exitval);
2408 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2409 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2412 ATF_TC(io_read_auxv1);
2413 ATF_TC_HEAD(io_read_auxv1, tc)
2415 atf_tc_set_md_var(tc, "descr",
2416 "Verify PT_READ_AUXV called for tracee");
2419 ATF_TC_BODY(io_read_auxv1, tc)
2421 const int exitval = 5;
2422 const int sigval = SIGSTOP;
2424 #if defined(TWAIT_HAVE_STATUS)
2427 AuxInfo ai[100], *aip;
2428 struct ptrace_io_desc io = {
2429 .piod_op = PIOD_READ_AUXV,
2432 .piod_len = sizeof(ai)
2435 printf("Before forking process PID=%d\n", getpid());
2436 ATF_REQUIRE((child = fork()) != -1);
2438 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2439 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2441 printf("Before raising %s from child\n", strsignal(sigval));
2442 FORKEE_ASSERT(raise(sigval) == 0);
2444 printf("Before exiting of the child process\n");
2447 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2449 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2450 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2452 validate_status_stopped(status, sigval);
2454 printf("Read new AUXV from tracee (PID=%d) by tracer (PID=%d)\n",
2456 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
2458 printf("Asserting that AUXV length (%zu) is > 0\n", io.piod_len);
2459 ATF_REQUIRE(io.piod_len > 0);
2461 for (aip = ai; aip->a_type != AT_NULL; aip++)
2462 printf("a_type=%#llx a_v=%#llx\n",
2463 (long long int)aip->a_type, (long long int)aip->a_v);
2465 printf("Before resuming the child process where it left off and "
2466 "without signal to be sent\n");
2467 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2469 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2470 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2472 validate_status_exited(status, exitval);
2474 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2475 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2479 ATF_TC_HEAD(read_d1, tc)
2481 atf_tc_set_md_var(tc, "descr",
2482 "Verify PT_READ_D called once");
2485 ATF_TC_BODY(read_d1, tc)
2487 const int exitval = 5;
2488 const int sigval = SIGSTOP;
2491 const int magic = (int)random();
2492 #if defined(TWAIT_HAVE_STATUS)
2496 printf("Before forking process PID=%d\n", getpid());
2497 ATF_REQUIRE((child = fork()) != -1);
2499 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2500 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2504 printf("Before raising %s from child\n", strsignal(sigval));
2505 FORKEE_ASSERT(raise(sigval) == 0);
2507 printf("Before exiting of the child process\n");
2510 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2512 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2513 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2515 validate_status_stopped(status, sigval);
2517 printf("Read new lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
2520 lookup_me = ptrace(PT_READ_D, child, &lookup_me, 0);
2521 ATF_REQUIRE_EQ(errno, 0);
2523 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
2524 "got value %#x != expected %#x", lookup_me, magic);
2526 printf("Before resuming the child process where it left off and "
2527 "without signal to be sent\n");
2528 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2530 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2531 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2533 validate_status_exited(status, exitval);
2535 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2536 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2540 ATF_TC_HEAD(read_d2, tc)
2542 atf_tc_set_md_var(tc, "descr",
2543 "Verify PT_READ_D called twice");
2546 ATF_TC_BODY(read_d2, tc)
2548 const int exitval = 5;
2549 const int sigval = SIGSTOP;
2553 const int magic1 = (int)random();
2554 const int magic2 = (int)random();
2555 #if defined(TWAIT_HAVE_STATUS)
2559 printf("Before forking process PID=%d\n", getpid());
2560 ATF_REQUIRE((child = fork()) != -1);
2562 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2563 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2565 lookup_me1 = magic1;
2566 lookup_me2 = magic2;
2568 printf("Before raising %s from child\n", strsignal(sigval));
2569 FORKEE_ASSERT(raise(sigval) == 0);
2571 printf("Before exiting of the child process\n");
2574 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2576 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2577 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2579 validate_status_stopped(status, sigval);
2581 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
2584 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0);
2585 ATF_REQUIRE_EQ(errno, 0);
2587 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
2588 "got value %#x != expected %#x", lookup_me1, magic1);
2590 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
2593 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0);
2594 ATF_REQUIRE_EQ(errno, 0);
2596 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
2597 "got value %#x != expected %#x", lookup_me2, magic2);
2599 printf("Before resuming the child process where it left off and "
2600 "without signal to be sent\n");
2601 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2603 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2604 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2606 validate_status_exited(status, exitval);
2608 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2609 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2613 ATF_TC_HEAD(read_d3, tc)
2615 atf_tc_set_md_var(tc, "descr",
2616 "Verify PT_READ_D called three times");
2619 ATF_TC_BODY(read_d3, tc)
2621 const int exitval = 5;
2622 const int sigval = SIGSTOP;
2627 const int magic1 = (int)random();
2628 const int magic2 = (int)random();
2629 const int magic3 = (int)random();
2630 #if defined(TWAIT_HAVE_STATUS)
2634 printf("Before forking process PID=%d\n", getpid());
2635 ATF_REQUIRE((child = fork()) != -1);
2637 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2638 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2640 lookup_me1 = magic1;
2641 lookup_me2 = magic2;
2642 lookup_me3 = magic3;
2644 printf("Before raising %s from child\n", strsignal(sigval));
2645 FORKEE_ASSERT(raise(sigval) == 0);
2647 printf("Before exiting of the child process\n");
2650 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2652 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2653 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2655 validate_status_stopped(status, sigval);
2657 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
2660 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0);
2661 ATF_REQUIRE_EQ(errno, 0);
2663 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
2664 "got value %#x != expected %#x", lookup_me1, magic1);
2666 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
2669 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0);
2670 ATF_REQUIRE_EQ(errno, 0);
2672 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
2673 "got value %#x != expected %#x", lookup_me2, magic2);
2675 printf("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n",
2678 lookup_me3 = ptrace(PT_READ_D, child, &lookup_me3, 0);
2679 ATF_REQUIRE_EQ(errno, 0);
2681 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3,
2682 "got value %#x != expected %#x", lookup_me3, magic3);
2684 printf("Before resuming the child process where it left off and "
2685 "without signal to be sent\n");
2686 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2688 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2689 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2691 validate_status_exited(status, exitval);
2693 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2694 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2698 ATF_TC_HEAD(read_d4, tc)
2700 atf_tc_set_md_var(tc, "descr",
2701 "Verify PT_READ_D called four times");
2704 ATF_TC_BODY(read_d4, tc)
2706 const int exitval = 5;
2707 const int sigval = SIGSTOP;
2713 const int magic1 = (int)random();
2714 const int magic2 = (int)random();
2715 const int magic3 = (int)random();
2716 const int magic4 = (int)random();
2717 #if defined(TWAIT_HAVE_STATUS)
2721 printf("Before forking process PID=%d\n", getpid());
2722 ATF_REQUIRE((child = fork()) != -1);
2724 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2725 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2727 lookup_me1 = magic1;
2728 lookup_me2 = magic2;
2729 lookup_me3 = magic3;
2730 lookup_me4 = magic4;
2732 printf("Before raising %s from child\n", strsignal(sigval));
2733 FORKEE_ASSERT(raise(sigval) == 0);
2735 printf("Before exiting of the child process\n");
2738 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2740 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2741 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2743 validate_status_stopped(status, sigval);
2745 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
2748 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0);
2749 ATF_REQUIRE_EQ(errno, 0);
2751 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
2752 "got value %#x != expected %#x", lookup_me1, magic1);
2754 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
2757 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0);
2758 ATF_REQUIRE_EQ(errno, 0);
2760 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
2761 "got value %#x != expected %#x", lookup_me2, magic2);
2763 printf("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n",
2766 lookup_me3 = ptrace(PT_READ_D, child, &lookup_me3, 0);
2767 ATF_REQUIRE_EQ(errno, 0);
2769 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3,
2770 "got value %#x != expected %#x", lookup_me3, magic3);
2772 printf("Read new lookup_me4 from tracee (PID=%d) by tracer (PID=%d)\n",
2775 lookup_me4 = ptrace(PT_READ_D, child, &lookup_me4, 0);
2776 ATF_REQUIRE_EQ(errno, 0);
2778 ATF_REQUIRE_EQ_MSG(lookup_me4, magic4,
2779 "got value %#x != expected %#x", lookup_me4, magic4);
2781 printf("Before resuming the child process where it left off and "
2782 "without signal to be sent\n");
2783 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2785 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2786 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2788 validate_status_exited(status, exitval);
2790 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2791 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2795 ATF_TC_HEAD(write_d1, tc)
2797 atf_tc_set_md_var(tc, "descr",
2798 "Verify PT_WRITE_D called once");
2801 ATF_TC_BODY(write_d1, tc)
2803 const int exitval = 5;
2804 const int sigval = SIGSTOP;
2807 const int magic = (int)random();
2808 #if defined(TWAIT_HAVE_STATUS)
2812 printf("Before forking process PID=%d\n", getpid());
2813 ATF_REQUIRE((child = fork()) != -1);
2815 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2816 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2818 printf("Before raising %s from child\n", strsignal(sigval));
2819 FORKEE_ASSERT(raise(sigval) == 0);
2821 FORKEE_ASSERT_EQ(lookup_me, magic);
2823 printf("Before exiting of the child process\n");
2826 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2828 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2829 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2831 validate_status_stopped(status, sigval);
2833 printf("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n",
2835 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me, magic) != -1);
2837 printf("Before resuming the child process where it left off and "
2838 "without signal to be sent\n");
2839 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2841 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2842 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2844 validate_status_exited(status, exitval);
2846 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2847 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2851 ATF_TC_HEAD(write_d2, tc)
2853 atf_tc_set_md_var(tc, "descr",
2854 "Verify PT_WRITE_D called twice");
2857 ATF_TC_BODY(write_d2, tc)
2859 const int exitval = 5;
2860 const int sigval = SIGSTOP;
2864 const int magic1 = (int)random();
2865 const int magic2 = (int)random();
2866 #if defined(TWAIT_HAVE_STATUS)
2870 printf("Before forking process PID=%d\n", getpid());
2871 ATF_REQUIRE((child = fork()) != -1);
2873 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2874 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2876 printf("Before raising %s from child\n", strsignal(sigval));
2877 FORKEE_ASSERT(raise(sigval) == 0);
2879 FORKEE_ASSERT_EQ(lookup_me1, magic1);
2880 FORKEE_ASSERT_EQ(lookup_me2, magic2);
2882 printf("Before exiting of the child process\n");
2885 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2887 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2888 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2890 validate_status_stopped(status, sigval);
2892 printf("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n",
2894 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1);
2896 printf("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n",
2898 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1);
2900 printf("Before resuming the child process where it left off and "
2901 "without signal to be sent\n");
2902 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2904 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2905 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2907 validate_status_exited(status, exitval);
2909 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2910 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2914 ATF_TC_HEAD(write_d3, tc)
2916 atf_tc_set_md_var(tc, "descr",
2917 "Verify PT_WRITE_D called three times");
2920 ATF_TC_BODY(write_d3, tc)
2922 const int exitval = 5;
2923 const int sigval = SIGSTOP;
2928 const int magic1 = (int)random();
2929 const int magic2 = (int)random();
2930 const int magic3 = (int)random();
2931 #if defined(TWAIT_HAVE_STATUS)
2935 printf("Before forking process PID=%d\n", getpid());
2936 ATF_REQUIRE((child = fork()) != -1);
2938 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
2939 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
2941 printf("Before raising %s from child\n", strsignal(sigval));
2942 FORKEE_ASSERT(raise(sigval) == 0);
2944 FORKEE_ASSERT_EQ(lookup_me1, magic1);
2945 FORKEE_ASSERT_EQ(lookup_me2, magic2);
2946 FORKEE_ASSERT_EQ(lookup_me3, magic3);
2948 printf("Before exiting of the child process\n");
2951 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
2953 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2954 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2956 validate_status_stopped(status, sigval);
2958 printf("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n",
2960 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1);
2962 printf("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n",
2964 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1);
2966 printf("Write new lookup_me3 to tracee (PID=%d) from tracer (PID=%d)\n",
2968 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me3, magic3) != -1);
2970 printf("Before resuming the child process where it left off and "
2971 "without signal to be sent\n");
2972 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
2974 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2975 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
2977 validate_status_exited(status, exitval);
2979 printf("Before calling %s() for the child\n", TWAIT_FNAME);
2980 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
2984 ATF_TC_HEAD(write_d4, tc)
2986 atf_tc_set_md_var(tc, "descr",
2987 "Verify PT_WRITE_D called four times");
2990 ATF_TC_BODY(write_d4, tc)
2992 const int exitval = 5;
2993 const int sigval = SIGSTOP;
2999 const int magic1 = (int)random();
3000 const int magic2 = (int)random();
3001 const int magic3 = (int)random();
3002 const int magic4 = (int)random();
3003 #if defined(TWAIT_HAVE_STATUS)
3007 printf("Before forking process PID=%d\n", getpid());
3008 ATF_REQUIRE((child = fork()) != -1);
3010 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3011 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3013 printf("Before raising %s from child\n", strsignal(sigval));
3014 FORKEE_ASSERT(raise(sigval) == 0);
3016 FORKEE_ASSERT_EQ(lookup_me1, magic1);
3017 FORKEE_ASSERT_EQ(lookup_me2, magic2);
3018 FORKEE_ASSERT_EQ(lookup_me3, magic3);
3019 FORKEE_ASSERT_EQ(lookup_me4, magic4);
3021 printf("Before exiting of the child process\n");
3024 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3026 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3027 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3029 validate_status_stopped(status, sigval);
3031 printf("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n",
3033 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1);
3035 printf("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n",
3037 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1);
3039 printf("Write new lookup_me3 to tracee (PID=%d) from tracer (PID=%d)\n",
3041 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me3, magic3) != -1);
3043 printf("Write new lookup_me4 to tracee (PID=%d) from tracer (PID=%d)\n",
3045 ATF_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me4, magic4) != -1);
3047 printf("Before resuming the child process where it left off and "
3048 "without signal to be sent\n");
3049 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3051 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3052 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3054 validate_status_exited(status, exitval);
3056 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3057 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3060 ATF_TC(io_read_d_write_d_handshake1);
3061 ATF_TC_HEAD(io_read_d_write_d_handshake1, tc)
3063 atf_tc_set_md_var(tc, "descr",
3064 "Verify PT_IO with PIOD_READ_D and PIOD_WRITE_D handshake");
3067 ATF_TC_BODY(io_read_d_write_d_handshake1, tc)
3069 const int exitval = 5;
3070 const int sigval = SIGSTOP;
3072 uint8_t lookup_me_fromtracee = 0;
3073 const uint8_t magic_fromtracee = (uint8_t)random();
3074 uint8_t lookup_me_totracee = 0;
3075 const uint8_t magic_totracee = (uint8_t)random();
3076 struct ptrace_io_desc io_fromtracee = {
3077 .piod_op = PIOD_READ_D,
3078 .piod_offs = &lookup_me_fromtracee,
3079 .piod_addr = &lookup_me_fromtracee,
3080 .piod_len = sizeof(lookup_me_fromtracee)
3082 struct ptrace_io_desc io_totracee = {
3083 .piod_op = PIOD_WRITE_D,
3084 .piod_offs = &lookup_me_totracee,
3085 .piod_addr = &lookup_me_totracee,
3086 .piod_len = sizeof(lookup_me_totracee)
3088 #if defined(TWAIT_HAVE_STATUS)
3092 printf("Before forking process PID=%d\n", getpid());
3093 ATF_REQUIRE((child = fork()) != -1);
3095 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3096 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3098 lookup_me_fromtracee = magic_fromtracee;
3100 printf("Before raising %s from child\n", strsignal(sigval));
3101 FORKEE_ASSERT(raise(sigval) == 0);
3103 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee);
3105 printf("Before exiting of the child process\n");
3108 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3110 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3111 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3113 validate_status_stopped(status, sigval);
3115 printf("Read lookup_me_fromtracee PID=%d by tracer (PID=%d)\n",
3117 ATF_REQUIRE(ptrace(PT_IO, child, &io_fromtracee, 0) != -1);
3119 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee,
3120 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_fromtracee,
3123 lookup_me_totracee = magic_totracee;
3125 printf("Write lookup_me_totracee to PID=%d by tracer (PID=%d)\n",
3127 ATF_REQUIRE(ptrace(PT_IO, child, &io_totracee, 0) != -1);
3129 ATF_REQUIRE_EQ_MSG(lookup_me_totracee, magic_totracee,
3130 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_totracee,
3133 printf("Before resuming the child process where it left off and "
3134 "without signal to be sent\n");
3135 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3137 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3138 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3140 validate_status_exited(status, exitval);
3142 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3143 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3146 ATF_TC(io_read_d_write_d_handshake2);
3147 ATF_TC_HEAD(io_read_d_write_d_handshake2, tc)
3149 atf_tc_set_md_var(tc, "descr",
3150 "Verify PT_IO with PIOD_WRITE_D and PIOD_READ_D handshake");
3153 ATF_TC_BODY(io_read_d_write_d_handshake2, tc)
3155 const int exitval = 5;
3156 const int sigval = SIGSTOP;
3158 uint8_t lookup_me_fromtracee = 0;
3159 const uint8_t magic_fromtracee = (uint8_t)random();
3160 uint8_t lookup_me_totracee = 0;
3161 const uint8_t magic_totracee = (uint8_t)random();
3162 struct ptrace_io_desc io_fromtracee = {
3163 .piod_op = PIOD_READ_D,
3164 .piod_offs = &lookup_me_fromtracee,
3165 .piod_addr = &lookup_me_fromtracee,
3166 .piod_len = sizeof(lookup_me_fromtracee)
3168 struct ptrace_io_desc io_totracee = {
3169 .piod_op = PIOD_WRITE_D,
3170 .piod_offs = &lookup_me_totracee,
3171 .piod_addr = &lookup_me_totracee,
3172 .piod_len = sizeof(lookup_me_totracee)
3174 #if defined(TWAIT_HAVE_STATUS)
3178 printf("Before forking process PID=%d\n", getpid());
3179 ATF_REQUIRE((child = fork()) != -1);
3181 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3182 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3184 lookup_me_fromtracee = magic_fromtracee;
3186 printf("Before raising %s from child\n", strsignal(sigval));
3187 FORKEE_ASSERT(raise(sigval) == 0);
3189 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee);
3191 printf("Before exiting of the child process\n");
3194 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3196 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3197 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3199 validate_status_stopped(status, sigval);
3201 lookup_me_totracee = magic_totracee;
3203 printf("Write lookup_me_totracee to PID=%d by tracer (PID=%d)\n",
3205 ATF_REQUIRE(ptrace(PT_IO, child, &io_totracee, 0) != -1);
3207 ATF_REQUIRE_EQ_MSG(lookup_me_totracee, magic_totracee,
3208 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_totracee,
3211 printf("Read lookup_me_fromtracee PID=%d by tracer (PID=%d)\n",
3213 ATF_REQUIRE(ptrace(PT_IO, child, &io_fromtracee, 0) != -1);
3215 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee,
3216 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_fromtracee,
3219 printf("Before resuming the child process where it left off and "
3220 "without signal to be sent\n");
3221 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3223 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3224 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3226 validate_status_exited(status, exitval);
3228 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3229 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3232 ATF_TC(read_d_write_d_handshake1);
3233 ATF_TC_HEAD(read_d_write_d_handshake1, tc)
3235 atf_tc_set_md_var(tc, "descr",
3236 "Verify PT_READ_D with PT_WRITE_D handshake");
3239 ATF_TC_BODY(read_d_write_d_handshake1, tc)
3241 const int exitval = 5;
3242 const int sigval = SIGSTOP;
3244 int lookup_me_fromtracee = 0;
3245 const int magic_fromtracee = (int)random();
3246 int lookup_me_totracee = 0;
3247 const int magic_totracee = (int)random();
3248 #if defined(TWAIT_HAVE_STATUS)
3252 printf("Before forking process PID=%d\n", getpid());
3253 ATF_REQUIRE((child = fork()) != -1);
3255 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3256 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3258 lookup_me_fromtracee = magic_fromtracee;
3260 printf("Before raising %s from child\n", strsignal(sigval));
3261 FORKEE_ASSERT(raise(sigval) == 0);
3263 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee);
3265 printf("Before exiting of the child process\n");
3268 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3270 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3271 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3273 validate_status_stopped(status, sigval);
3275 printf("Read new lookup_me_fromtracee PID=%d by tracer (PID=%d)\n",
3278 lookup_me_fromtracee =
3279 ptrace(PT_READ_D, child, &lookup_me_fromtracee, 0);
3280 ATF_REQUIRE_EQ(errno, 0);
3282 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee,
3283 "got value %#x != expected %#x", lookup_me_fromtracee,
3286 printf("Write new lookup_me_totracee to PID=%d from tracer (PID=%d)\n",
3289 (ptrace(PT_WRITE_D, child, &lookup_me_totracee, magic_totracee)
3292 printf("Before resuming the child process where it left off and "
3293 "without signal to be sent\n");
3294 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3296 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3297 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3299 validate_status_exited(status, exitval);
3301 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3302 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3305 ATF_TC(read_d_write_d_handshake2);
3306 ATF_TC_HEAD(read_d_write_d_handshake2, tc)
3308 atf_tc_set_md_var(tc, "descr",
3309 "Verify PT_WRITE_D with PT_READ_D handshake");
3312 ATF_TC_BODY(read_d_write_d_handshake2, tc)
3314 const int exitval = 5;
3315 const int sigval = SIGSTOP;
3317 int lookup_me_fromtracee = 0;
3318 const int magic_fromtracee = (int)random();
3319 int lookup_me_totracee = 0;
3320 const int magic_totracee = (int)random();
3321 #if defined(TWAIT_HAVE_STATUS)
3325 printf("Before forking process PID=%d\n", getpid());
3326 ATF_REQUIRE((child = fork()) != -1);
3328 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3329 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3331 lookup_me_fromtracee = magic_fromtracee;
3333 printf("Before raising %s from child\n", strsignal(sigval));
3334 FORKEE_ASSERT(raise(sigval) == 0);
3336 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee);
3338 printf("Before exiting of the child process\n");
3341 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3343 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3344 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3346 validate_status_stopped(status, sigval);
3348 printf("Write new lookup_me_totracee to PID=%d from tracer (PID=%d)\n",
3351 (ptrace(PT_WRITE_D, child, &lookup_me_totracee, magic_totracee)
3354 printf("Read new lookup_me_fromtracee PID=%d by tracer (PID=%d)\n",
3357 lookup_me_fromtracee =
3358 ptrace(PT_READ_D, child, &lookup_me_fromtracee, 0);
3359 ATF_REQUIRE_EQ(errno, 0);
3361 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee,
3362 "got value %#x != expected %#x", lookup_me_fromtracee,
3365 printf("Before resuming the child process where it left off and "
3366 "without signal to be sent\n");
3367 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3369 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3370 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3372 validate_status_exited(status, exitval);
3374 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3375 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3378 /* These dummy functions are used to be copied with ptrace(2) calls */
3380 dummy_fn1(int a, int b, int c, int d)
3388 return a + b * c - d;
3392 dummy_fn2(int a, int b, int c, int d)
3400 return a + b * c - d;
3404 dummy_fn3(int a, int b, int c, int d)
3412 return a + b * c - d;
3416 dummy_fn4(int a, int b, int c, int d)
3424 return a + b * c - d;
3428 ATF_TC_HEAD(io_read_i1, tc)
3430 atf_tc_set_md_var(tc, "descr",
3431 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint8_t)");
3434 ATF_TC_BODY(io_read_i1, tc)
3436 const int exitval = 5;
3437 const int sigval = SIGSTOP;
3439 uint8_t lookup_me = 0;
3441 memcpy(&magic, dummy_fn1, sizeof(magic));
3442 struct ptrace_io_desc io = {
3443 .piod_op = PIOD_READ_I,
3444 .piod_offs = dummy_fn1,
3445 .piod_addr = &lookup_me,
3446 .piod_len = sizeof(lookup_me)
3448 #if defined(TWAIT_HAVE_STATUS)
3452 printf("Before forking process PID=%d\n", getpid());
3453 ATF_REQUIRE((child = fork()) != -1);
3455 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3456 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3458 printf("Before raising %s from child\n", strsignal(sigval));
3459 FORKEE_ASSERT(raise(sigval) == 0);
3461 printf("Before exiting of the child process\n");
3464 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3466 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3467 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3469 validate_status_stopped(status, sigval);
3471 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
3473 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
3475 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
3476 "got value %" PRIx8 " != expected %" PRIx8, lookup_me, magic);
3478 printf("Before resuming the child process where it left off and "
3479 "without signal to be sent\n");
3480 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3482 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3483 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3485 validate_status_exited(status, exitval);
3487 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3488 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3492 ATF_TC_HEAD(io_read_i2, tc)
3494 atf_tc_set_md_var(tc, "descr",
3495 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint16_t)");
3498 ATF_TC_BODY(io_read_i2, tc)
3500 const int exitval = 5;
3501 const int sigval = SIGSTOP;
3503 uint16_t lookup_me = 0;
3505 memcpy(&magic, dummy_fn1, sizeof(magic));
3506 struct ptrace_io_desc io = {
3507 .piod_op = PIOD_READ_I,
3508 .piod_offs = dummy_fn1,
3509 .piod_addr = &lookup_me,
3510 .piod_len = sizeof(lookup_me)
3512 #if defined(TWAIT_HAVE_STATUS)
3516 printf("Before forking process PID=%d\n", getpid());
3517 ATF_REQUIRE((child = fork()) != -1);
3519 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3520 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3522 printf("Before raising %s from child\n", strsignal(sigval));
3523 FORKEE_ASSERT(raise(sigval) == 0);
3525 printf("Before exiting of the child process\n");
3528 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3530 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3531 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3533 validate_status_stopped(status, sigval);
3535 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
3537 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
3539 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
3540 "got value %" PRIx16 " != expected %" PRIx16, lookup_me, magic);
3542 printf("Before resuming the child process where it left off and "
3543 "without signal to be sent\n");
3544 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3546 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3547 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3549 validate_status_exited(status, exitval);
3551 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3552 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3556 ATF_TC_HEAD(io_read_i3, tc)
3558 atf_tc_set_md_var(tc, "descr",
3559 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint32_t)");
3562 ATF_TC_BODY(io_read_i3, tc)
3564 const int exitval = 5;
3565 const int sigval = SIGSTOP;
3567 uint32_t lookup_me = 0;
3569 memcpy(&magic, dummy_fn1, sizeof(magic));
3570 struct ptrace_io_desc io = {
3571 .piod_op = PIOD_READ_I,
3572 .piod_offs = dummy_fn1,
3573 .piod_addr = &lookup_me,
3574 .piod_len = sizeof(lookup_me)
3576 #if defined(TWAIT_HAVE_STATUS)
3580 printf("Before forking process PID=%d\n", getpid());
3581 ATF_REQUIRE((child = fork()) != -1);
3583 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3584 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3586 printf("Before raising %s from child\n", strsignal(sigval));
3587 FORKEE_ASSERT(raise(sigval) == 0);
3589 printf("Before exiting of the child process\n");
3592 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3594 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3595 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3597 validate_status_stopped(status, sigval);
3599 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
3601 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
3603 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
3604 "got value %" PRIx32 " != expected %" PRIx32, lookup_me, magic);
3606 printf("Before resuming the child process where it left off and "
3607 "without signal to be sent\n");
3608 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3610 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3611 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3613 validate_status_exited(status, exitval);
3615 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3616 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3620 ATF_TC_HEAD(io_read_i4, tc)
3622 atf_tc_set_md_var(tc, "descr",
3623 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint64_t)");
3626 ATF_TC_BODY(io_read_i4, tc)
3628 const int exitval = 5;
3629 const int sigval = SIGSTOP;
3631 uint64_t lookup_me = 0;
3633 memcpy(&magic, dummy_fn1, sizeof(magic));
3634 struct ptrace_io_desc io = {
3635 .piod_op = PIOD_READ_I,
3636 .piod_offs = dummy_fn1,
3637 .piod_addr = &lookup_me,
3638 .piod_len = sizeof(lookup_me)
3640 #if defined(TWAIT_HAVE_STATUS)
3644 printf("Before forking process PID=%d\n", getpid());
3645 ATF_REQUIRE((child = fork()) != -1);
3647 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3648 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3650 printf("Before raising %s from child\n", strsignal(sigval));
3651 FORKEE_ASSERT(raise(sigval) == 0);
3653 printf("Before exiting of the child process\n");
3656 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3658 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3659 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3661 validate_status_stopped(status, sigval);
3663 printf("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
3665 ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1);
3667 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
3668 "got value %" PRIx64 " != expected %" PRIx64, lookup_me, magic);
3670 printf("Before resuming the child process where it left off and "
3671 "without signal to be sent\n");
3672 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3674 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3675 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3677 validate_status_exited(status, exitval);
3679 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3680 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3684 ATF_TC_HEAD(read_i1, tc)
3686 atf_tc_set_md_var(tc, "descr",
3687 "Verify PT_READ_I called once");
3690 ATF_TC_BODY(read_i1, tc)
3692 const int exitval = 5;
3693 const int sigval = SIGSTOP;
3697 memcpy(&magic, dummy_fn1, sizeof(magic));
3698 #if defined(TWAIT_HAVE_STATUS)
3702 printf("Before forking process PID=%d\n", getpid());
3703 ATF_REQUIRE((child = fork()) != -1);
3705 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3706 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3708 printf("Before raising %s from child\n", strsignal(sigval));
3709 FORKEE_ASSERT(raise(sigval) == 0);
3711 printf("Before exiting of the child process\n");
3714 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3716 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3717 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3719 validate_status_stopped(status, sigval);
3721 printf("Read new lookup_me from tracee (PID=%d) by tracer (PID=%d)\n",
3724 lookup_me = ptrace(PT_READ_I, child, dummy_fn1, 0);
3725 ATF_REQUIRE_EQ(errno, 0);
3727 ATF_REQUIRE_EQ_MSG(lookup_me, magic,
3728 "got value %#x != expected %#x", lookup_me, magic);
3730 printf("Before resuming the child process where it left off and "
3731 "without signal to be sent\n");
3732 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3734 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3735 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3737 validate_status_exited(status, exitval);
3739 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3740 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3744 ATF_TC_HEAD(read_i2, tc)
3746 atf_tc_set_md_var(tc, "descr",
3747 "Verify PT_READ_I called twice");
3750 ATF_TC_BODY(read_i2, tc)
3752 const int exitval = 5;
3753 const int sigval = SIGSTOP;
3759 memcpy(&magic1, dummy_fn1, sizeof(magic1));
3760 memcpy(&magic2, dummy_fn2, sizeof(magic2));
3761 #if defined(TWAIT_HAVE_STATUS)
3765 printf("Before forking process PID=%d\n", getpid());
3766 ATF_REQUIRE((child = fork()) != -1);
3768 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3769 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3771 printf("Before raising %s from child\n", strsignal(sigval));
3772 FORKEE_ASSERT(raise(sigval) == 0);
3774 printf("Before exiting of the child process\n");
3777 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3779 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3780 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3782 validate_status_stopped(status, sigval);
3784 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
3787 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0);
3788 ATF_REQUIRE_EQ(errno, 0);
3790 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
3791 "got value %#x != expected %#x", lookup_me1, magic1);
3793 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
3796 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0);
3797 ATF_REQUIRE_EQ(errno, 0);
3799 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
3800 "got value %#x != expected %#x", lookup_me2, magic2);
3802 printf("Before resuming the child process where it left off and "
3803 "without signal to be sent\n");
3804 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3806 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3807 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3809 validate_status_exited(status, exitval);
3811 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3812 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3816 ATF_TC_HEAD(read_i3, tc)
3818 atf_tc_set_md_var(tc, "descr",
3819 "Verify PT_READ_I called three times");
3822 ATF_TC_BODY(read_i3, tc)
3824 const int exitval = 5;
3825 const int sigval = SIGSTOP;
3833 memcpy(&magic1, dummy_fn1, sizeof(magic1));
3834 memcpy(&magic2, dummy_fn2, sizeof(magic2));
3835 memcpy(&magic3, dummy_fn3, sizeof(magic3));
3836 #if defined(TWAIT_HAVE_STATUS)
3840 printf("Before forking process PID=%d\n", getpid());
3841 ATF_REQUIRE((child = fork()) != -1);
3843 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3844 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3846 printf("Before raising %s from child\n", strsignal(sigval));
3847 FORKEE_ASSERT(raise(sigval) == 0);
3849 printf("Before exiting of the child process\n");
3852 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3854 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3855 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3857 validate_status_stopped(status, sigval);
3859 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
3862 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0);
3863 ATF_REQUIRE_EQ(errno, 0);
3865 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
3866 "got value %#x != expected %#x", lookup_me1, magic1);
3868 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
3871 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0);
3872 ATF_REQUIRE_EQ(errno, 0);
3874 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
3875 "got value %#x != expected %#x", lookup_me2, magic2);
3877 printf("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n",
3880 lookup_me3 = ptrace(PT_READ_I, child, dummy_fn3, 0);
3881 ATF_REQUIRE_EQ(errno, 0);
3883 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3,
3884 "got value %#x != expected %#x", lookup_me3, magic3);
3886 printf("Before resuming the child process where it left off and "
3887 "without signal to be sent\n");
3888 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3890 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3891 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3893 validate_status_exited(status, exitval);
3895 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3896 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3900 ATF_TC_HEAD(read_i4, tc)
3902 atf_tc_set_md_var(tc, "descr",
3903 "Verify PT_READ_I called four times");
3906 ATF_TC_BODY(read_i4, tc)
3908 const int exitval = 5;
3909 const int sigval = SIGSTOP;
3919 memcpy(&magic1, dummy_fn1, sizeof(magic1));
3920 memcpy(&magic2, dummy_fn2, sizeof(magic2));
3921 memcpy(&magic3, dummy_fn3, sizeof(magic3));
3922 memcpy(&magic4, dummy_fn4, sizeof(magic4));
3923 #if defined(TWAIT_HAVE_STATUS)
3927 printf("Before forking process PID=%d\n", getpid());
3928 ATF_REQUIRE((child = fork()) != -1);
3930 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
3931 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
3933 printf("Before raising %s from child\n", strsignal(sigval));
3934 FORKEE_ASSERT(raise(sigval) == 0);
3936 printf("Before exiting of the child process\n");
3939 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
3941 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3942 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3944 validate_status_stopped(status, sigval);
3946 printf("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n",
3949 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0);
3950 ATF_REQUIRE_EQ(errno, 0);
3952 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1,
3953 "got value %#x != expected %#x", lookup_me1, magic1);
3955 printf("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n",
3958 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0);
3959 ATF_REQUIRE_EQ(errno, 0);
3961 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2,
3962 "got value %#x != expected %#x", lookup_me2, magic2);
3964 printf("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n",
3967 lookup_me3 = ptrace(PT_READ_I, child, dummy_fn3, 0);
3968 ATF_REQUIRE_EQ(errno, 0);
3970 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3,
3971 "got value %#x != expected %#x", lookup_me3, magic3);
3973 printf("Read new lookup_me4 from tracee (PID=%d) by tracer (PID=%d)\n",
3976 lookup_me4 = ptrace(PT_READ_I, child, dummy_fn4, 0);
3977 ATF_REQUIRE_EQ(errno, 0);
3979 ATF_REQUIRE_EQ_MSG(lookup_me4, magic4,
3980 "got value %#x != expected %#x", lookup_me4, magic4);
3982 printf("Before resuming the child process where it left off and "
3983 "without signal to be sent\n");
3984 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
3986 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3987 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
3989 validate_status_exited(status, exitval);
3991 printf("Before calling %s() for the child\n", TWAIT_FNAME);
3992 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
3995 #if defined(HAVE_GPREGS)
3997 ATF_TC_HEAD(regs1, tc)
3999 atf_tc_set_md_var(tc, "descr",
4000 "Verify plain PT_GETREGS call without further steps");
4003 ATF_TC_BODY(regs1, tc)
4005 const int exitval = 5;
4006 const int sigval = SIGSTOP;
4008 #if defined(TWAIT_HAVE_STATUS)
4013 printf("Before forking process PID=%d\n", getpid());
4014 ATF_REQUIRE((child = fork()) != -1);
4016 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4017 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4019 printf("Before raising %s from child\n", strsignal(sigval));
4020 FORKEE_ASSERT(raise(sigval) == 0);
4022 printf("Before exiting of the child process\n");
4025 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4027 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4028 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4030 validate_status_stopped(status, sigval);
4032 printf("Call GETREGS for the child process\n");
4033 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4035 printf("Before resuming the child process where it left off and "
4036 "without signal to be sent\n");
4037 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4039 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4040 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4042 validate_status_exited(status, exitval);
4044 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4045 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4049 #if defined(HAVE_GPREGS)
4051 ATF_TC_HEAD(regs2, tc)
4053 atf_tc_set_md_var(tc, "descr",
4054 "Verify plain PT_GETREGS call and retrieve PC");
4057 ATF_TC_BODY(regs2, tc)
4059 const int exitval = 5;
4060 const int sigval = SIGSTOP;
4062 #if defined(TWAIT_HAVE_STATUS)
4067 printf("Before forking process PID=%d\n", getpid());
4068 ATF_REQUIRE((child = fork()) != -1);
4070 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4071 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4073 printf("Before raising %s from child\n", strsignal(sigval));
4074 FORKEE_ASSERT(raise(sigval) == 0);
4076 printf("Before exiting of the child process\n");
4079 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4081 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4082 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4084 validate_status_stopped(status, sigval);
4086 printf("Call GETREGS for the child process\n");
4087 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4089 printf("Retrieved PC=%" PRIxREGISTER "\n", PTRACE_REG_PC(&r));
4091 printf("Before resuming the child process where it left off and "
4092 "without signal to be sent\n");
4093 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4095 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4096 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4098 validate_status_exited(status, exitval);
4100 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4101 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4105 #if defined(HAVE_GPREGS)
4107 ATF_TC_HEAD(regs3, tc)
4109 atf_tc_set_md_var(tc, "descr",
4110 "Verify plain PT_GETREGS call and retrieve SP");
4113 ATF_TC_BODY(regs3, tc)
4115 const int exitval = 5;
4116 const int sigval = SIGSTOP;
4118 #if defined(TWAIT_HAVE_STATUS)
4123 printf("Before forking process PID=%d\n", getpid());
4124 ATF_REQUIRE((child = fork()) != -1);
4126 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4127 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4129 printf("Before raising %s from child\n", strsignal(sigval));
4130 FORKEE_ASSERT(raise(sigval) == 0);
4132 printf("Before exiting of the child process\n");
4135 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4137 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4138 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4140 validate_status_stopped(status, sigval);
4142 printf("Call GETREGS for the child process\n");
4143 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4145 printf("Retrieved SP=%" PRIxREGISTER "\n", PTRACE_REG_SP(&r));
4147 printf("Before resuming the child process where it left off and "
4148 "without signal to be sent\n");
4149 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4151 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4152 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4154 validate_status_exited(status, exitval);
4156 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4157 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4161 #if defined(HAVE_GPREGS)
4163 ATF_TC_HEAD(regs4, tc)
4165 atf_tc_set_md_var(tc, "descr",
4166 "Verify plain PT_GETREGS call and retrieve INTRV");
4169 ATF_TC_BODY(regs4, tc)
4171 const int exitval = 5;
4172 const int sigval = SIGSTOP;
4174 #if defined(TWAIT_HAVE_STATUS)
4179 printf("Before forking process PID=%d\n", getpid());
4180 ATF_REQUIRE((child = fork()) != -1);
4182 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4183 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4185 printf("Before raising %s from child\n", strsignal(sigval));
4186 FORKEE_ASSERT(raise(sigval) == 0);
4188 printf("Before exiting of the child process\n");
4191 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4193 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4194 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4196 validate_status_stopped(status, sigval);
4198 printf("Call GETREGS for the child process\n");
4199 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4201 printf("Retrieved INTRV=%" PRIxREGISTER "\n", PTRACE_REG_INTRV(&r));
4203 printf("Before resuming the child process where it left off and "
4204 "without signal to be sent\n");
4205 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4207 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4208 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4210 validate_status_exited(status, exitval);
4212 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4213 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4217 #if defined(HAVE_GPREGS)
4219 ATF_TC_HEAD(regs5, tc)
4221 atf_tc_set_md_var(tc, "descr",
4222 "Verify PT_GETREGS and PT_SETREGS calls without changing regs");
4225 ATF_TC_BODY(regs5, tc)
4227 const int exitval = 5;
4228 const int sigval = SIGSTOP;
4230 #if defined(TWAIT_HAVE_STATUS)
4235 printf("Before forking process PID=%d\n", getpid());
4236 ATF_REQUIRE((child = fork()) != -1);
4238 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4239 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4241 printf("Before raising %s from child\n", strsignal(sigval));
4242 FORKEE_ASSERT(raise(sigval) == 0);
4244 printf("Before exiting of the child process\n");
4247 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4249 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4250 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4252 validate_status_stopped(status, sigval);
4254 printf("Call GETREGS for the child process\n");
4255 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4257 printf("Call SETREGS for the child process (without changed regs)\n");
4258 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
4260 printf("Before resuming the child process where it left off and "
4261 "without signal to be sent\n");
4262 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4264 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4265 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4267 validate_status_exited(status, exitval);
4269 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4270 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4274 #if defined(HAVE_FPREGS)
4276 ATF_TC_HEAD(fpregs1, tc)
4278 atf_tc_set_md_var(tc, "descr",
4279 "Verify plain PT_GETFPREGS call without further steps");
4282 ATF_TC_BODY(fpregs1, tc)
4284 const int exitval = 5;
4285 const int sigval = SIGSTOP;
4287 #if defined(TWAIT_HAVE_STATUS)
4292 printf("Before forking process PID=%d\n", getpid());
4293 ATF_REQUIRE((child = fork()) != -1);
4295 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4296 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4298 printf("Before raising %s from child\n", strsignal(sigval));
4299 FORKEE_ASSERT(raise(sigval) == 0);
4301 printf("Before exiting of the child process\n");
4304 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4306 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4307 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4309 validate_status_stopped(status, sigval);
4311 printf("Call GETFPREGS for the child process\n");
4312 ATF_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1);
4314 printf("Before resuming the child process where it left off and "
4315 "without signal to be sent\n");
4316 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4318 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4319 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4321 validate_status_exited(status, exitval);
4323 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4324 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4328 #if defined(HAVE_FPREGS)
4330 ATF_TC_HEAD(fpregs2, tc)
4332 atf_tc_set_md_var(tc, "descr",
4333 "Verify PT_GETFPREGS and PT_SETFPREGS calls without changing "
4337 ATF_TC_BODY(fpregs2, tc)
4339 const int exitval = 5;
4340 const int sigval = SIGSTOP;
4342 #if defined(TWAIT_HAVE_STATUS)
4347 printf("Before forking process PID=%d\n", getpid());
4348 ATF_REQUIRE((child = fork()) != -1);
4350 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4351 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4353 printf("Before raising %s from child\n", strsignal(sigval));
4354 FORKEE_ASSERT(raise(sigval) == 0);
4356 printf("Before exiting of the child process\n");
4359 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4361 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4362 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4364 validate_status_stopped(status, sigval);
4366 printf("Call GETFPREGS for the child process\n");
4367 ATF_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1);
4369 printf("Call SETFPREGS for the child (without changed regs)\n");
4370 ATF_REQUIRE(ptrace(PT_SETFPREGS, child, &r, 0) != -1);
4372 printf("Before resuming the child process where it left off and "
4373 "without signal to be sent\n");
4374 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4376 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4377 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4379 validate_status_exited(status, exitval);
4381 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4382 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4386 #if defined(PT_STEP)
4388 ATF_TC_HEAD(step1, tc)
4390 atf_tc_set_md_var(tc, "descr",
4391 "Verify single PT_STEP call");
4394 ATF_TC_BODY(step1, tc)
4396 const int exitval = 5;
4397 const int sigval = SIGSTOP;
4399 #if defined(TWAIT_HAVE_STATUS)
4404 printf("Before forking process PID=%d\n", getpid());
4405 ATF_REQUIRE((child = fork()) != -1);
4407 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4408 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4410 happy = check_happy(100);
4412 printf("Before raising %s from child\n", strsignal(sigval));
4413 FORKEE_ASSERT(raise(sigval) == 0);
4415 FORKEE_ASSERT_EQ(happy, check_happy(100));
4417 printf("Before exiting of the child process\n");
4420 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4422 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4423 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4425 validate_status_stopped(status, sigval);
4427 printf("Before resuming the child process where it left off and "
4428 "without signal to be sent (use PT_STEP)\n");
4429 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
4431 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4432 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4434 validate_status_stopped(status, SIGTRAP);
4436 printf("Before resuming the child process where it left off and "
4437 "without signal to be sent\n");
4438 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4440 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4441 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4443 validate_status_exited(status, exitval);
4445 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4446 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4450 #if defined(PT_STEP)
4452 ATF_TC_HEAD(step2, tc)
4454 atf_tc_set_md_var(tc, "descr",
4455 "Verify PT_STEP called twice");
4458 ATF_TC_BODY(step2, tc)
4460 const int exitval = 5;
4461 const int sigval = SIGSTOP;
4463 #if defined(TWAIT_HAVE_STATUS)
4469 printf("Before forking process PID=%d\n", getpid());
4470 ATF_REQUIRE((child = fork()) != -1);
4472 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4473 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4475 happy = check_happy(999);
4477 printf("Before raising %s from child\n", strsignal(sigval));
4478 FORKEE_ASSERT(raise(sigval) == 0);
4480 FORKEE_ASSERT_EQ(happy, check_happy(999));
4482 printf("Before exiting of the child process\n");
4485 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4487 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4488 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4490 validate_status_stopped(status, sigval);
4493 printf("Before resuming the child process where it left off "
4494 "and without signal to be sent (use PT_STEP)\n");
4495 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
4497 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4498 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
4501 validate_status_stopped(status, SIGTRAP);
4504 printf("Before resuming the child process where it left off and "
4505 "without signal to be sent\n");
4506 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4508 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4509 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4511 validate_status_exited(status, exitval);
4513 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4514 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4518 #if defined(PT_STEP)
4520 ATF_TC_HEAD(step3, tc)
4522 atf_tc_set_md_var(tc, "descr",
4523 "Verify PT_STEP called three times");
4526 ATF_TC_BODY(step3, tc)
4528 const int exitval = 5;
4529 const int sigval = SIGSTOP;
4531 #if defined(TWAIT_HAVE_STATUS)
4537 printf("Before forking process PID=%d\n", getpid());
4538 ATF_REQUIRE((child = fork()) != -1);
4540 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4541 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4543 happy = check_happy(999);
4545 printf("Before raising %s from child\n", strsignal(sigval));
4546 FORKEE_ASSERT(raise(sigval) == 0);
4548 FORKEE_ASSERT_EQ(happy, check_happy(999));
4550 printf("Before exiting of the child process\n");
4553 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4555 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4556 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4558 validate_status_stopped(status, sigval);
4561 printf("Before resuming the child process where it left off "
4562 "and without signal to be sent (use PT_STEP)\n");
4563 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
4565 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4566 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
4569 validate_status_stopped(status, SIGTRAP);
4572 printf("Before resuming the child process where it left off and "
4573 "without signal to be sent\n");
4574 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4576 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4577 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4579 validate_status_exited(status, exitval);
4581 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4582 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4586 #if defined(PT_STEP)
4588 ATF_TC_HEAD(step4, tc)
4590 atf_tc_set_md_var(tc, "descr",
4591 "Verify PT_STEP called four times");
4594 ATF_TC_BODY(step4, tc)
4596 const int exitval = 5;
4597 const int sigval = SIGSTOP;
4599 #if defined(TWAIT_HAVE_STATUS)
4605 printf("Before forking process PID=%d\n", getpid());
4606 ATF_REQUIRE((child = fork()) != -1);
4608 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4609 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4611 happy = check_happy(999);
4613 printf("Before raising %s from child\n", strsignal(sigval));
4614 FORKEE_ASSERT(raise(sigval) == 0);
4616 FORKEE_ASSERT_EQ(happy, check_happy(999));
4618 printf("Before exiting of the child process\n");
4621 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4623 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4624 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4626 validate_status_stopped(status, sigval);
4629 printf("Before resuming the child process where it left off "
4630 "and without signal to be sent (use PT_STEP)\n");
4631 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
4633 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4634 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
4637 validate_status_stopped(status, SIGTRAP);
4640 printf("Before resuming the child process where it left off and "
4641 "without signal to be sent\n");
4642 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4644 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4645 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4647 validate_status_exited(status, exitval);
4649 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4650 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4655 ATF_TC_HEAD(kill1, tc)
4657 atf_tc_set_md_var(tc, "descr",
4658 "Verify that PT_CONTINUE with SIGKILL terminates child");
4661 ATF_TC_BODY(kill1, tc)
4663 const int sigval = SIGSTOP, sigsent = SIGKILL;
4665 #if defined(TWAIT_HAVE_STATUS)
4669 printf("Before forking process PID=%d\n", getpid());
4670 ATF_REQUIRE((child = fork()) != -1);
4672 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4673 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4675 printf("Before raising %s from child\n", strsignal(sigval));
4676 FORKEE_ASSERT(raise(sigval) == 0);
4680 "Child should be terminated by a signal from its parent");
4682 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4684 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4685 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4687 validate_status_stopped(status, sigval);
4689 printf("Before resuming the child process where it left off and "
4690 "without signal to be sent\n");
4691 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
4693 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4694 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4696 validate_status_signaled(status, sigsent, 0);
4698 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4699 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4703 ATF_TC_HEAD(kill2, tc)
4705 atf_tc_set_md_var(tc, "descr",
4706 "Verify that PT_KILL terminates child");
4709 ATF_TC_BODY(kill2, tc)
4711 const int sigval = SIGSTOP;
4713 #if defined(TWAIT_HAVE_STATUS)
4717 printf("Before forking process PID=%d\n", getpid());
4718 ATF_REQUIRE((child = fork()) != -1);
4720 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4721 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4723 printf("Before raising %s from child\n", strsignal(sigval));
4724 FORKEE_ASSERT(raise(sigval) == 0);
4728 "Child should be terminated by a signal from its parent");
4730 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4732 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4733 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4735 validate_status_stopped(status, sigval);
4737 printf("Before resuming the child process where it left off and "
4738 "without signal to be sent\n");
4739 ATF_REQUIRE(ptrace(PT_KILL, child, (void*)1, 0) != -1);
4741 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4742 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4744 validate_status_signaled(status, SIGKILL, 0);
4746 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4747 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4751 ATF_TC_HEAD(lwpinfo1, tc)
4753 atf_tc_set_md_var(tc, "descr",
4754 "Verify basic LWPINFO call for single thread (PT_TRACE_ME)");
4757 ATF_TC_BODY(lwpinfo1, tc)
4759 const int exitval = 5;
4760 const int sigval = SIGSTOP;
4762 #if defined(TWAIT_HAVE_STATUS)
4765 struct ptrace_lwpinfo info = {0, 0};
4767 printf("Before forking process PID=%d\n", getpid());
4768 ATF_REQUIRE((child = fork()) != -1);
4770 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4771 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4773 printf("Before raising %s from child\n", strsignal(sigval));
4774 FORKEE_ASSERT(raise(sigval) == 0);
4776 printf("Before exiting of the child process\n");
4779 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4781 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4782 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4784 validate_status_stopped(status, sigval);
4786 printf("Before calling ptrace(2) with PT_LWPINFO for child\n");
4787 ATF_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1);
4789 printf("Assert that there exists a thread\n");
4790 ATF_REQUIRE(info.pl_lwpid > 0);
4792 printf("Assert that lwp thread %d received event PL_EVENT_SIGNAL\n",
4794 ATF_REQUIRE_EQ_MSG(info.pl_event, PL_EVENT_SIGNAL,
4795 "Received event %d != expected event %d",
4796 info.pl_event, PL_EVENT_SIGNAL);
4798 printf("Before calling ptrace(2) with PT_LWPINFO for child\n");
4799 ATF_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1);
4801 printf("Assert that there are no more lwp threads in child\n");
4802 ATF_REQUIRE_EQ(info.pl_lwpid, 0);
4804 printf("Before resuming the child process where it left off and "
4805 "without signal to be sent\n");
4806 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4808 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4809 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4811 validate_status_exited(status, exitval);
4813 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4814 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4817 #if defined(TWAIT_HAVE_PID)
4819 ATF_TC_HEAD(lwpinfo2, tc)
4821 atf_tc_set_md_var(tc, "descr",
4822 "Verify basic LWPINFO call for single thread (PT_ATTACH from "
4826 ATF_TC_BODY(lwpinfo2, tc)
4828 struct msg_fds parent_tracee, parent_tracer;
4829 const int exitval_tracee = 5;
4830 const int exitval_tracer = 10;
4831 pid_t tracee, tracer, wpid;
4832 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */
4833 #if defined(TWAIT_HAVE_STATUS)
4836 struct ptrace_lwpinfo info = {0, 0};
4838 printf("Spawn tracee\n");
4839 ATF_REQUIRE(msg_open(&parent_tracee) == 0);
4840 ATF_REQUIRE(msg_open(&parent_tracer) == 0);
4841 tracee = atf_utils_fork();
4844 /* Wait for message from the parent */
4845 CHILD_TO_PARENT("tracee ready", parent_tracee, msg);
4846 CHILD_FROM_PARENT("tracee exit", parent_tracee, msg);
4848 _exit(exitval_tracee);
4850 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg);
4852 printf("Spawn debugger\n");
4853 tracer = atf_utils_fork();
4855 /* No IPC to communicate with the child */
4856 printf("Before calling PT_ATTACH from tracee %d\n", getpid());
4857 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1);
4859 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */
4860 FORKEE_REQUIRE_SUCCESS(
4861 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
4863 forkee_status_stopped(status, SIGSTOP);
4865 printf("Before calling ptrace(2) with PT_LWPINFO for child\n");
4866 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info))
4869 printf("Assert that there exists a thread\n");
4870 FORKEE_ASSERTX(info.pl_lwpid > 0);
4872 printf("Assert that lwp thread %d received event "
4873 "PL_EVENT_SIGNAL\n", info.pl_lwpid);
4874 FORKEE_ASSERT_EQ(info.pl_event, PL_EVENT_SIGNAL);
4876 printf("Before calling ptrace(2) with PT_LWPINFO for child\n");
4877 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info))
4880 printf("Assert that there are no more lwp threads in child\n");
4881 FORKEE_ASSERTX(info.pl_lwpid == 0);
4883 /* Resume tracee with PT_CONTINUE */
4884 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1);
4886 /* Inform parent that tracer has attached to tracee */
4887 CHILD_TO_PARENT("tracer ready", parent_tracer, msg);
4888 /* Wait for parent */
4889 CHILD_FROM_PARENT("tracer wait", parent_tracer, msg);
4891 /* Wait for tracee and assert that it exited */
4892 FORKEE_REQUIRE_SUCCESS(
4893 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee);
4895 forkee_status_exited(status, exitval_tracee);
4897 printf("Before exiting of the tracer process\n");
4898 _exit(exitval_tracer);
4901 printf("Wait for the tracer to attach to the tracee\n");
4902 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg);
4904 printf("Resume the tracee and let it exit\n");
4905 PARENT_TO_CHILD("tracee exit", parent_tracee, msg);
4907 printf("Detect that tracee is zombie\n");
4908 await_zombie(tracee);
4910 printf("Assert that there is no status about tracee - "
4911 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME);
4912 TWAIT_REQUIRE_SUCCESS(
4913 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0);
4915 printf("Resume the tracer and let it detect exited tracee\n");
4916 PARENT_TO_CHILD("tracer wait", parent_tracer, msg);
4918 printf("Wait for tracer to finish its job and exit - calling %s()\n",
4920 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0),
4923 validate_status_exited(status, exitval_tracer);
4925 printf("Wait for tracee to finish its job and exit - calling %s()\n",
4927 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
4930 validate_status_exited(status, exitval_tracee);
4932 msg_close(&parent_tracer);
4933 msg_close(&parent_tracee);
4938 ATF_TC_HEAD(siginfo1, tc)
4940 atf_tc_set_md_var(tc, "descr",
4941 "Verify basic PT_GET_SIGINFO call for SIGTRAP from tracee");
4944 ATF_TC_BODY(siginfo1, tc)
4946 const int exitval = 5;
4947 const int sigval = SIGTRAP;
4949 #if defined(TWAIT_HAVE_STATUS)
4952 struct ptrace_siginfo info;
4953 memset(&info, 0, sizeof(info));
4955 printf("Before forking process PID=%d\n", getpid());
4956 ATF_REQUIRE((child = fork()) != -1);
4958 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
4959 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
4961 printf("Before raising %s from child\n", strsignal(sigval));
4962 FORKEE_ASSERT(raise(sigval) == 0);
4964 printf("Before exiting of the child process\n");
4967 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
4969 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4970 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4972 validate_status_stopped(status, sigval);
4974 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
4975 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
4977 printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
4978 printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
4979 info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
4980 info.psi_siginfo.si_errno);
4982 printf("Before resuming the child process where it left off and "
4983 "without signal to be sent\n");
4984 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
4986 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4987 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
4989 validate_status_exited(status, exitval);
4991 printf("Before calling %s() for the child\n", TWAIT_FNAME);
4992 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
4996 ATF_TC_HEAD(siginfo2, tc)
4998 atf_tc_set_md_var(tc, "descr",
4999 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls without "
5000 "modification of SIGINT from tracee");
5003 static int siginfo2_caught = 0;
5006 siginfo2_sighandler(int sig)
5008 FORKEE_ASSERT_EQ(sig, SIGINT);
5013 ATF_TC_BODY(siginfo2, tc)
5015 const int exitval = 5;
5016 const int sigval = SIGINT;
5018 struct sigaction sa;
5019 #if defined(TWAIT_HAVE_STATUS)
5022 struct ptrace_siginfo info;
5023 memset(&info, 0, sizeof(info));
5025 printf("Before forking process PID=%d\n", getpid());
5026 ATF_REQUIRE((child = fork()) != -1);
5028 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5029 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5031 sa.sa_handler = siginfo2_sighandler;
5032 sa.sa_flags = SA_SIGINFO;
5033 sigemptyset(&sa.sa_mask);
5035 FORKEE_ASSERT(sigaction(sigval, &sa, NULL) != -1);
5037 printf("Before raising %s from child\n", strsignal(sigval));
5038 FORKEE_ASSERT(raise(sigval) == 0);
5040 FORKEE_ASSERT_EQ(siginfo2_caught, 1);
5042 printf("Before exiting of the child process\n");
5045 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5047 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5048 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5050 validate_status_stopped(status, sigval);
5052 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5053 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5055 printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
5056 printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
5057 info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
5058 info.psi_siginfo.si_errno);
5060 printf("Before calling ptrace(2) with PT_SET_SIGINFO for child\n");
5061 ATF_REQUIRE(ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1);
5063 printf("Before resuming the child process where it left off and "
5064 "without signal to be sent\n");
5065 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigval) != -1);
5067 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5068 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5070 validate_status_exited(status, exitval);
5072 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5073 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5077 ATF_TC_HEAD(siginfo3, tc)
5079 atf_tc_set_md_var(tc, "descr",
5080 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls with "
5081 "setting signal to new value");
5084 static int siginfo3_caught = 0;
5087 siginfo3_sigaction(int sig, siginfo_t *info, void *ctx)
5089 FORKEE_ASSERT_EQ(sig, SIGTRAP);
5091 FORKEE_ASSERT_EQ(info->si_signo, SIGTRAP);
5092 FORKEE_ASSERT_EQ(info->si_code, TRAP_BRKPT);
5097 ATF_TC_BODY(siginfo3, tc)
5099 const int exitval = 5;
5100 const int sigval = SIGINT;
5101 const int sigfaked = SIGTRAP;
5102 const int sicodefaked = TRAP_BRKPT;
5104 struct sigaction sa;
5105 #if defined(TWAIT_HAVE_STATUS)
5108 struct ptrace_siginfo info;
5109 memset(&info, 0, sizeof(info));
5111 printf("Before forking process PID=%d\n", getpid());
5112 ATF_REQUIRE((child = fork()) != -1);
5114 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5115 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5117 sa.sa_sigaction = siginfo3_sigaction;
5118 sa.sa_flags = SA_SIGINFO;
5119 sigemptyset(&sa.sa_mask);
5121 FORKEE_ASSERT(sigaction(sigfaked, &sa, NULL) != -1);
5123 printf("Before raising %s from child\n", strsignal(sigval));
5124 FORKEE_ASSERT(raise(sigval) == 0);
5126 FORKEE_ASSERT_EQ(siginfo3_caught, 1);
5128 printf("Before exiting of the child process\n");
5131 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5133 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5134 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5136 validate_status_stopped(status, sigval);
5138 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5139 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5141 printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
5142 printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
5143 info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
5144 info.psi_siginfo.si_errno);
5146 printf("Before setting new faked signal to signo=%d si_code=%d\n",
5147 sigfaked, sicodefaked);
5148 info.psi_siginfo.si_signo = sigfaked;
5149 info.psi_siginfo.si_code = sicodefaked;
5151 printf("Before calling ptrace(2) with PT_SET_SIGINFO for child\n");
5152 ATF_REQUIRE(ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1);
5154 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5155 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5157 printf("Before checking siginfo_t\n");
5158 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigfaked);
5159 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, sicodefaked);
5161 printf("Before resuming the child process where it left off and "
5162 "without signal to be sent\n");
5163 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigfaked) != -1);
5165 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5166 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5168 validate_status_exited(status, exitval);
5170 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5171 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5175 ATF_TC_HEAD(siginfo4, tc)
5177 atf_tc_set_md_var(tc, "descr",
5178 "Detect SIGTRAP TRAP_EXEC from tracee");
5181 ATF_TC_BODY(siginfo4, tc)
5183 const int sigval = SIGTRAP;
5185 #if defined(TWAIT_HAVE_STATUS)
5189 struct ptrace_siginfo info;
5190 memset(&info, 0, sizeof(info));
5192 printf("Before forking process PID=%d\n", getpid());
5193 ATF_REQUIRE((child = fork()) != -1);
5195 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5196 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5198 printf("Before calling execve(2) from child\n");
5199 execlp("/bin/echo", "/bin/echo", NULL);
5201 FORKEE_ASSERT(0 && "Not reached");
5203 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5205 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5206 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5208 validate_status_stopped(status, sigval);
5210 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5211 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5213 printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
5214 printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n",
5215 info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
5216 info.psi_siginfo.si_errno);
5218 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
5219 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC);
5221 printf("Before resuming the child process where it left off and "
5222 "without signal to be sent\n");
5223 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5225 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5226 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5228 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5229 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5232 #if defined(TWAIT_HAVE_PID)
5234 ATF_TC_HEAD(siginfo5, tc)
5236 atf_tc_set_md_var(tc, "descr",
5237 "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK "
5238 "set to PTRACE_FORK and reports correct signal information");
5241 ATF_TC_BODY(siginfo5, tc)
5243 const int exitval = 5;
5244 const int exitval2 = 15;
5245 const int sigval = SIGSTOP;
5246 pid_t child, child2, wpid;
5247 #if defined(TWAIT_HAVE_STATUS)
5250 ptrace_state_t state;
5251 const int slen = sizeof(state);
5252 ptrace_event_t event;
5253 const int elen = sizeof(event);
5254 struct ptrace_siginfo info;
5256 memset(&info, 0, sizeof(info));
5258 printf("Before forking process PID=%d\n", getpid());
5259 ATF_REQUIRE((child = fork()) != -1);
5261 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5262 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5264 printf("Before raising %s from child\n", strsignal(sigval));
5265 FORKEE_ASSERT(raise(sigval) == 0);
5267 FORKEE_ASSERT((child2 = fork()) != 1);
5272 FORKEE_REQUIRE_SUCCESS
5273 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
5275 forkee_status_exited(status, exitval2);
5277 printf("Before exiting of the child process\n");
5280 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5282 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5283 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5285 validate_status_stopped(status, sigval);
5287 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5288 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5290 printf("Before checking siginfo_t\n");
5291 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
5292 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
5294 printf("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child);
5295 event.pe_set_event = PTRACE_FORK;
5296 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
5298 printf("Before resuming the child process where it left off and "
5299 "without signal to be sent\n");
5300 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5302 printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
5303 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5305 validate_status_stopped(status, SIGTRAP);
5307 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5308 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5310 printf("Before checking siginfo_t\n");
5311 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
5312 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD);
5314 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
5315 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
5317 child2 = state.pe_other_pid;
5318 printf("Reported PTRACE_FORK event with forkee %d\n", child2);
5320 printf("Before calling %s() for the forkee %d of the child %d\n",
5321 TWAIT_FNAME, child2, child);
5322 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
5325 validate_status_stopped(status, SIGTRAP);
5327 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5328 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5330 printf("Before checking siginfo_t\n");
5331 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
5332 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD);
5334 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
5335 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
5336 ATF_REQUIRE_EQ(state.pe_other_pid, child);
5338 printf("Before resuming the forkee process where it left off and "
5339 "without signal to be sent\n");
5340 ATF_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
5342 printf("Before resuming the child process where it left off and "
5343 "without signal to be sent\n");
5344 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5346 printf("Before calling %s() for the forkee - expected exited\n",
5348 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
5351 validate_status_exited(status, exitval2);
5353 printf("Before calling %s() for the forkee - expected no process\n",
5355 TWAIT_REQUIRE_FAILURE(ECHILD,
5356 wpid = TWAIT_GENERIC(child2, &status, 0));
5358 printf("Before calling %s() for the child - expected stopped "
5359 "SIGCHLD\n", TWAIT_FNAME);
5360 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5362 validate_status_stopped(status, SIGCHLD);
5364 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5365 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5367 printf("Before checking siginfo_t\n");
5368 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGCHLD);
5369 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, CLD_EXITED);
5371 printf("Before resuming the child process where it left off and "
5372 "without signal to be sent\n");
5373 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5375 printf("Before calling %s() for the child - expected exited\n",
5377 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5379 validate_status_exited(status, exitval);
5381 printf("Before calling %s() for the child - expected no process\n",
5383 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5387 #if defined(PT_STEP)
5389 ATF_TC_HEAD(siginfo6, tc)
5391 atf_tc_set_md_var(tc, "descr",
5392 "Verify single PT_STEP call with signal information check");
5395 ATF_TC_BODY(siginfo6, tc)
5397 const int exitval = 5;
5398 const int sigval = SIGSTOP;
5400 #if defined(TWAIT_HAVE_STATUS)
5404 struct ptrace_siginfo info;
5406 memset(&info, 0, sizeof(info));
5408 printf("Before forking process PID=%d\n", getpid());
5409 ATF_REQUIRE((child = fork()) != -1);
5411 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5412 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5414 happy = check_happy(100);
5416 printf("Before raising %s from child\n", strsignal(sigval));
5417 FORKEE_ASSERT(raise(sigval) == 0);
5419 FORKEE_ASSERT_EQ(happy, check_happy(100));
5421 printf("Before exiting of the child process\n");
5424 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5426 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5427 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5429 validate_status_stopped(status, sigval);
5431 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5432 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5434 printf("Before checking siginfo_t\n");
5435 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
5436 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
5438 printf("Before resuming the child process where it left off and "
5439 "without signal to be sent (use PT_STEP)\n");
5440 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
5442 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5443 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5445 validate_status_stopped(status, SIGTRAP);
5447 printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
5448 ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1);
5450 printf("Before checking siginfo_t\n");
5451 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
5452 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_TRACE);
5454 printf("Before resuming the child process where it left off and "
5455 "without signal to be sent\n");
5456 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5458 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5459 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5461 validate_status_exited(status, exitval);
5463 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5464 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5468 volatile lwpid_t the_lwp_id = 0;
5471 lwp_main_func(void *arg)
5473 the_lwp_id = _lwp_self();
5477 ATF_TC(lwp_create1);
5478 ATF_TC_HEAD(lwp_create1, tc)
5480 atf_tc_set_md_var(tc, "descr",
5481 "Verify that 1 LWP creation is intercepted by ptrace(2) with "
5482 "EVENT_MASK set to PTRACE_LWP_CREATE");
5485 ATF_TC_BODY(lwp_create1, tc)
5487 const int exitval = 5;
5488 const int sigval = SIGSTOP;
5490 #if defined(TWAIT_HAVE_STATUS)
5493 ptrace_state_t state;
5494 const int slen = sizeof(state);
5495 ptrace_event_t event;
5496 const int elen = sizeof(event);
5499 static const size_t ssize = 16*1024;
5502 printf("Before forking process PID=%d\n", getpid());
5503 ATF_REQUIRE((child = fork()) != -1);
5505 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5506 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5508 printf("Before raising %s from child\n", strsignal(sigval));
5509 FORKEE_ASSERT(raise(sigval) == 0);
5511 printf("Before allocating memory for stack in child\n");
5512 FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
5514 printf("Before making context for new lwp in child\n");
5515 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
5517 printf("Before creating new in child\n");
5518 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
5520 printf("Before waiting for lwp %d to exit\n", lid);
5521 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
5523 printf("Before verifying that reported %d and running lid %d "
5524 "are the same\n", lid, the_lwp_id);
5525 FORKEE_ASSERT_EQ(lid, the_lwp_id);
5527 printf("Before exiting of the child process\n");
5530 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5532 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5533 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5535 validate_status_stopped(status, sigval);
5537 printf("Set empty EVENT_MASK for the child %d\n", child);
5538 event.pe_set_event = PTRACE_LWP_CREATE;
5539 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
5541 printf("Before resuming the child process where it left off and "
5542 "without signal to be sent\n");
5543 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5545 printf("Before calling %s() for the child - expected stopped "
5546 "SIGTRAP\n", TWAIT_FNAME);
5547 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5549 validate_status_stopped(status, SIGTRAP);
5551 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
5553 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
5556 printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
5558 printf("Before resuming the child process where it left off and "
5559 "without signal to be sent\n");
5560 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5562 printf("Before calling %s() for the child - expected exited\n",
5564 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5566 validate_status_exited(status, exitval);
5568 printf("Before calling %s() for the child - expected no process\n",
5570 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5574 ATF_TC_HEAD(lwp_exit1, tc)
5576 atf_tc_set_md_var(tc, "descr",
5577 "Verify that 1 LWP creation is intercepted by ptrace(2) with "
5578 "EVENT_MASK set to PTRACE_LWP_EXIT");
5581 ATF_TC_BODY(lwp_exit1, tc)
5583 const int exitval = 5;
5584 const int sigval = SIGSTOP;
5586 #if defined(TWAIT_HAVE_STATUS)
5589 ptrace_state_t state;
5590 const int slen = sizeof(state);
5591 ptrace_event_t event;
5592 const int elen = sizeof(event);
5595 static const size_t ssize = 16*1024;
5598 printf("Before forking process PID=%d\n", getpid());
5599 ATF_REQUIRE((child = fork()) != -1);
5601 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5602 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5604 printf("Before raising %s from child\n", strsignal(sigval));
5605 FORKEE_ASSERT(raise(sigval) == 0);
5607 printf("Before allocating memory for stack in child\n");
5608 FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
5610 printf("Before making context for new lwp in child\n");
5611 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
5613 printf("Before creating new in child\n");
5614 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
5616 printf("Before waiting for lwp %d to exit\n", lid);
5617 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
5619 printf("Before verifying that reported %d and running lid %d "
5620 "are the same\n", lid, the_lwp_id);
5621 FORKEE_ASSERT_EQ(lid, the_lwp_id);
5623 printf("Before exiting of the child process\n");
5626 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5628 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5629 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5631 validate_status_stopped(status, sigval);
5633 printf("Set empty EVENT_MASK for the child %d\n", child);
5634 event.pe_set_event = PTRACE_LWP_EXIT;
5635 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
5637 printf("Before resuming the child process where it left off and "
5638 "without signal to be sent\n");
5639 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5641 printf("Before calling %s() for the child - expected stopped "
5642 "SIGTRAP\n", TWAIT_FNAME);
5643 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5645 validate_status_stopped(status, SIGTRAP);
5647 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
5649 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT);
5652 printf("Reported PTRACE_LWP_EXIT event with lid %d\n", lid);
5654 printf("Before resuming the child process where it left off and "
5655 "without signal to be sent\n");
5656 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5658 printf("Before calling %s() for the child - expected exited\n",
5660 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5662 validate_status_exited(status, exitval);
5664 printf("Before calling %s() for the child - expected no process\n",
5666 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5670 ATF_TC_HEAD(signal1, tc)
5672 atf_tc_set_md_var(tc, "descr",
5673 "Verify that masking single unrelated signal does not stop tracer "
5674 "from catching other signals");
5677 ATF_TC_BODY(signal1, tc)
5679 const int exitval = 5;
5680 const int sigval = SIGSTOP;
5681 const int sigmasked = SIGTRAP;
5682 const int signotmasked = SIGINT;
5684 #if defined(TWAIT_HAVE_STATUS)
5689 printf("Before forking process PID=%d\n", getpid());
5690 ATF_REQUIRE((child = fork()) != -1);
5692 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5693 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5695 sigemptyset(&intmask);
5696 sigaddset(&intmask, sigmasked);
5697 sigprocmask(SIG_BLOCK, &intmask, NULL);
5699 printf("Before raising %s from child\n", strsignal(sigval));
5700 FORKEE_ASSERT(raise(sigval) == 0);
5702 printf("Before raising %s from child\n",
5703 strsignal(signotmasked));
5704 FORKEE_ASSERT(raise(signotmasked) == 0);
5706 printf("Before exiting of the child process\n");
5709 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5711 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5712 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5714 validate_status_stopped(status, sigval);
5716 printf("Before resuming the child process where it left off and "
5717 "without signal to be sent\n");
5718 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5720 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5721 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5723 validate_status_stopped(status, signotmasked);
5725 printf("Before resuming the child process where it left off and "
5726 "without signal to be sent\n");
5727 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5729 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5730 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5732 validate_status_exited(status, exitval);
5734 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5735 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5739 ATF_TC_HEAD(signal2, tc)
5741 atf_tc_set_md_var(tc, "descr",
5742 "Verify that masking SIGTRAP in tracee stops tracer from "
5743 "catching this raised signal");
5746 ATF_TC_BODY(signal2, tc)
5748 const int exitval = 5;
5749 const int sigval = SIGSTOP;
5750 const int sigmasked = SIGTRAP;
5752 #if defined(TWAIT_HAVE_STATUS)
5757 printf("Before forking process PID=%d\n", getpid());
5758 ATF_REQUIRE((child = fork()) != -1);
5760 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5761 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5763 sigemptyset(&intmask);
5764 sigaddset(&intmask, sigmasked);
5765 sigprocmask(SIG_BLOCK, &intmask, NULL);
5767 printf("Before raising %s from child\n", strsignal(sigval));
5768 FORKEE_ASSERT(raise(sigval) == 0);
5770 printf("Before raising %s breakpoint from child\n",
5771 strsignal(sigmasked));
5772 FORKEE_ASSERT(raise(sigmasked) == 0);
5774 printf("Before exiting of the child process\n");
5777 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5779 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5780 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5782 validate_status_stopped(status, sigval);
5784 printf("Before resuming the child process where it left off and "
5785 "without signal to be sent\n");
5786 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5788 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5789 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5791 validate_status_exited(status, exitval);
5793 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5794 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5798 ATF_TC_HEAD(signal3, tc)
5800 atf_tc_set_md_var(tc, "descr",
5801 "Verify that masking SIGTRAP in tracee does not stop tracer from "
5802 "catching software breakpoints");
5805 ATF_TC_BODY(signal3, tc)
5807 const int exitval = 5;
5808 const int sigval = SIGSTOP;
5809 const int sigmasked = SIGTRAP;
5811 #if defined(TWAIT_HAVE_STATUS)
5816 atf_tc_expect_fail("PR kern/51918");
5818 printf("Before forking process PID=%d\n", getpid());
5819 ATF_REQUIRE((child = fork()) != -1);
5821 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5822 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5824 sigemptyset(&intmask);
5825 sigaddset(&intmask, sigmasked);
5826 sigprocmask(SIG_BLOCK, &intmask, NULL);
5828 printf("Before raising %s from child\n", strsignal(sigval));
5829 FORKEE_ASSERT(raise(sigval) == 0);
5831 printf("Before raising software breakpoint from child\n");
5832 #if defined(__x86_64__)
5833 __asm__ __volatile__ ("int3\n;");
5838 printf("Before exiting of the child process\n");
5841 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5843 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5844 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5846 validate_status_stopped(status, sigval);
5848 printf("Before resuming the child process where it left off and "
5849 "without signal to be sent\n");
5850 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5852 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5853 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5855 validate_status_stopped(status, sigmasked);
5857 printf("Before resuming the child process where it left off and "
5858 "without signal to be sent\n");
5859 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5861 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5862 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5864 validate_status_exited(status, exitval);
5866 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5867 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5870 #if defined(PT_STEP)
5872 ATF_TC_HEAD(signal4, tc)
5874 atf_tc_set_md_var(tc, "descr",
5875 "Verify that masking SIGTRAP in tracee does not stop tracer from "
5876 "catching single step trap");
5879 ATF_TC_BODY(signal4, tc)
5881 const int exitval = 5;
5882 const int sigval = SIGSTOP;
5883 const int sigmasked = SIGTRAP;
5885 #if defined(TWAIT_HAVE_STATUS)
5891 atf_tc_expect_fail("PR kern/51918");
5893 printf("Before forking process PID=%d\n", getpid());
5894 ATF_REQUIRE((child = fork()) != -1);
5896 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5897 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5899 happy = check_happy(100);
5901 sigemptyset(&intmask);
5902 sigaddset(&intmask, sigmasked);
5903 sigprocmask(SIG_BLOCK, &intmask, NULL);
5905 printf("Before raising %s from child\n", strsignal(sigval));
5906 FORKEE_ASSERT(raise(sigval) == 0);
5908 FORKEE_ASSERT_EQ(happy, check_happy(100));
5910 printf("Before exiting of the child process\n");
5913 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5915 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5916 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5918 validate_status_stopped(status, sigval);
5920 printf("Before resuming the child process where it left off and "
5921 "without signal to be sent\n");
5922 ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1);
5924 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5925 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5927 validate_status_stopped(status, sigmasked);
5929 printf("Before resuming the child process where it left off and "
5930 "without signal to be sent\n");
5931 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5933 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5934 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5936 validate_status_exited(status, exitval);
5938 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5939 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
5944 ATF_TC_HEAD(signal5, tc)
5946 atf_tc_set_md_var(tc, "descr",
5947 "Verify that masking SIGTRAP in tracee does not stop tracer from "
5948 "catching exec() breakpoint");
5951 ATF_TC_BODY(signal5, tc)
5953 const int exitval = 5;
5954 const int sigval = SIGSTOP;
5955 const int sigmasked = SIGTRAP;
5957 #if defined(TWAIT_HAVE_STATUS)
5962 atf_tc_expect_fail("PR kern/51918");
5964 printf("Before forking process PID=%d\n", getpid());
5965 ATF_REQUIRE((child = fork()) != -1);
5967 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
5968 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
5970 sigemptyset(&intmask);
5971 sigaddset(&intmask, sigmasked);
5972 sigprocmask(SIG_BLOCK, &intmask, NULL);
5974 printf("Before raising %s from child\n", strsignal(sigval));
5975 FORKEE_ASSERT(raise(sigval) == 0);
5977 printf("Before calling execve(2) from child\n");
5978 execlp("/bin/echo", "/bin/echo", NULL);
5980 printf("Before exiting of the child process\n");
5983 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
5985 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5986 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5988 validate_status_stopped(status, sigval);
5990 printf("Before resuming the child process where it left off and "
5991 "without signal to be sent\n");
5992 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
5994 printf("Before calling %s() for the child\n", TWAIT_FNAME);
5995 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
5997 validate_status_stopped(status, sigmasked);
5999 printf("Before resuming the child process where it left off and "
6000 "without signal to be sent\n");
6001 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6003 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6004 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6006 validate_status_exited(status, exitval);
6008 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6009 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6012 #if defined(TWAIT_HAVE_PID)
6014 ATF_TC_HEAD(signal6, tc)
6016 atf_tc_set_md_var(tc, "descr",
6017 "Verify that masking SIGTRAP in tracee does not stop tracer from "
6018 "catching PTRACE_FORK breakpoint");
6021 ATF_TC_BODY(signal6, tc)
6023 const int exitval = 5;
6024 const int exitval2 = 15;
6025 const int sigval = SIGSTOP;
6026 const int sigmasked = SIGTRAP;
6027 pid_t child, child2, wpid;
6028 #if defined(TWAIT_HAVE_STATUS)
6032 ptrace_state_t state;
6033 const int slen = sizeof(state);
6034 ptrace_event_t event;
6035 const int elen = sizeof(event);
6037 atf_tc_expect_fail("PR kern/51918");
6039 printf("Before forking process PID=%d\n", getpid());
6040 ATF_REQUIRE((child = fork()) != -1);
6042 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
6043 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
6045 sigemptyset(&intmask);
6046 sigaddset(&intmask, sigmasked);
6047 sigprocmask(SIG_BLOCK, &intmask, NULL);
6049 printf("Before raising %s from child\n", strsignal(sigval));
6050 FORKEE_ASSERT(raise(sigval) == 0);
6052 FORKEE_ASSERT((child2 = fork()) != 1);
6057 FORKEE_REQUIRE_SUCCESS
6058 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
6060 forkee_status_exited(status, exitval2);
6062 printf("Before exiting of the child process\n");
6065 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
6067 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6068 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6070 validate_status_stopped(status, sigval);
6072 printf("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child);
6073 event.pe_set_event = PTRACE_FORK;
6074 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
6076 printf("Before resuming the child process where it left off and "
6077 "without signal to be sent\n");
6078 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6080 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6081 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6083 validate_status_stopped(status, sigmasked);
6085 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
6086 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
6088 child2 = state.pe_other_pid;
6089 printf("Reported PTRACE_FORK event with forkee %d\n", child2);
6091 printf("Before calling %s() for the child2\n", TWAIT_FNAME);
6092 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
6095 validate_status_stopped(status, SIGTRAP);
6097 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
6098 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
6099 ATF_REQUIRE_EQ(state.pe_other_pid, child);
6101 printf("Before resuming the forkee process where it left off and "
6102 "without signal to be sent\n");
6103 ATF_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
6105 printf("Before resuming the child process where it left off and "
6106 "without signal to be sent\n");
6107 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6109 printf("Before calling %s() for the forkee - expected exited\n",
6111 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
6114 validate_status_exited(status, exitval2);
6116 printf("Before calling %s() for the forkee - expected no process\n",
6118 TWAIT_REQUIRE_FAILURE(ECHILD,
6119 wpid = TWAIT_GENERIC(child2, &status, 0));
6121 printf("Before calling %s() for the child - expected stopped "
6122 "SIGCHLD\n", TWAIT_FNAME);
6123 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6125 validate_status_stopped(status, SIGCHLD);
6127 printf("Before resuming the child process where it left off and "
6128 "without signal to be sent\n");
6129 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6131 printf("Before calling %s() for the child - expected exited\n",
6133 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6135 validate_status_exited(status, exitval);
6137 printf("Before calling %s() for the child - expected no process\n",
6139 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6143 #if defined(TWAIT_HAVE_PID)
6145 ATF_TC_HEAD(signal7, tc)
6147 atf_tc_set_md_var(tc, "descr",
6148 "Verify that masking SIGTRAP in tracee does not stop tracer from "
6149 "catching PTRACE_VFORK breakpoint");
6152 ATF_TC_BODY(signal7, tc)
6154 const int exitval = 5;
6155 const int exitval2 = 15;
6156 const int sigval = SIGSTOP;
6157 const int sigmasked = SIGTRAP;
6158 pid_t child, child2, wpid;
6159 #if defined(TWAIT_HAVE_STATUS)
6163 ptrace_state_t state;
6164 const int slen = sizeof(state);
6165 ptrace_event_t event;
6166 const int elen = sizeof(event);
6168 atf_tc_expect_fail("PR kern/51918 PR kern/51630");
6170 printf("Before forking process PID=%d\n", getpid());
6171 ATF_REQUIRE((child = fork()) != -1);
6173 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
6174 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
6176 sigemptyset(&intmask);
6177 sigaddset(&intmask, sigmasked);
6178 sigprocmask(SIG_BLOCK, &intmask, NULL);
6180 printf("Before raising %s from child\n", strsignal(sigval));
6181 FORKEE_ASSERT(raise(sigval) == 0);
6183 FORKEE_ASSERT((child2 = fork()) != 1);
6188 FORKEE_REQUIRE_SUCCESS
6189 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
6191 forkee_status_exited(status, exitval2);
6193 printf("Before exiting of the child process\n");
6196 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
6198 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6199 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6201 validate_status_stopped(status, sigval);
6203 printf("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child);
6204 event.pe_set_event = PTRACE_VFORK;
6205 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
6207 printf("Before resuming the child process where it left off and "
6208 "without signal to be sent\n");
6209 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6211 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6212 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6214 validate_status_stopped(status, sigmasked);
6216 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
6217 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK);
6219 child2 = state.pe_other_pid;
6220 printf("Reported PTRACE_VFORK event with forkee %d\n", child2);
6222 printf("Before calling %s() for the child2\n", TWAIT_FNAME);
6223 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
6226 validate_status_stopped(status, SIGTRAP);
6228 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
6229 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK);
6230 ATF_REQUIRE_EQ(state.pe_other_pid, child);
6232 printf("Before resuming the forkee process where it left off and "
6233 "without signal to be sent\n");
6234 ATF_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
6236 printf("Before resuming the child process where it left off and "
6237 "without signal to be sent\n");
6238 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6240 printf("Before calling %s() for the forkee - expected exited\n",
6242 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
6245 validate_status_exited(status, exitval2);
6247 printf("Before calling %s() for the forkee - expected no process\n",
6249 TWAIT_REQUIRE_FAILURE(ECHILD,
6250 wpid = TWAIT_GENERIC(child2, &status, 0));
6252 printf("Before calling %s() for the child - expected stopped "
6253 "SIGCHLD\n", TWAIT_FNAME);
6254 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6256 validate_status_stopped(status, SIGCHLD);
6258 printf("Before resuming the child process where it left off and "
6259 "without signal to be sent\n");
6260 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6262 printf("Before calling %s() for the child - expected exited\n",
6264 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6266 validate_status_exited(status, exitval);
6268 printf("Before calling %s() for the child - expected no process\n",
6270 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6275 ATF_TC_HEAD(signal8, tc)
6277 atf_tc_set_md_var(tc, "descr",
6278 "Verify that masking SIGTRAP in tracee does not stop tracer from "
6279 "catching PTRACE_VFORK_DONE breakpoint");
6282 ATF_TC_BODY(signal8, tc)
6284 const int exitval = 5;
6285 const int exitval2 = 15;
6286 const int sigval = SIGSTOP;
6287 const int sigmasked = SIGTRAP;
6288 pid_t child, child2, wpid;
6289 #if defined(TWAIT_HAVE_STATUS)
6293 ptrace_state_t state;
6294 const int slen = sizeof(state);
6295 ptrace_event_t event;
6296 const int elen = sizeof(event);
6298 atf_tc_expect_fail("PR kern/51918");
6300 printf("Before forking process PID=%d\n", getpid());
6301 ATF_REQUIRE((child = fork()) != -1);
6303 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
6304 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
6306 sigemptyset(&intmask);
6307 sigaddset(&intmask, sigmasked);
6308 sigprocmask(SIG_BLOCK, &intmask, NULL);
6310 printf("Before raising %s from child\n", strsignal(sigval));
6311 FORKEE_ASSERT(raise(sigval) == 0);
6313 FORKEE_ASSERT((child2 = vfork()) != 1);
6318 FORKEE_REQUIRE_SUCCESS
6319 (wpid = TWAIT_GENERIC(child2, &status, 0), child2);
6321 forkee_status_exited(status, exitval2);
6323 printf("Before exiting of the child process\n");
6326 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
6328 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6329 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6331 validate_status_stopped(status, sigval);
6333 printf("Enable PTRACE_VFORK_DONE in EVENT_MASK for the child %d\n",
6335 event.pe_set_event = PTRACE_VFORK_DONE;
6336 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
6338 printf("Before resuming the child process where it left off and "
6339 "without signal to be sent\n");
6340 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6342 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6343 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6345 validate_status_stopped(status, sigmasked);
6347 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
6348 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE);
6350 child2 = state.pe_other_pid;
6351 printf("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2);
6353 printf("Before resuming the child process where it left off and "
6354 "without signal to be sent\n");
6355 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6357 printf("Before calling %s() for the child - expected stopped "
6358 "SIGCHLD\n", TWAIT_FNAME);
6359 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6361 validate_status_stopped(status, SIGCHLD);
6363 printf("Before resuming the child process where it left off and "
6364 "without signal to be sent\n");
6365 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6367 printf("Before calling %s() for the child - expected exited\n",
6369 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6371 validate_status_exited(status, exitval);
6373 printf("Before calling %s() for the child - expected no process\n",
6375 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6379 ATF_TC_HEAD(signal9, tc)
6381 atf_tc_set_md_var(tc, "descr",
6382 "Verify that masking SIGTRAP in tracee does not stop tracer from "
6383 "catching PTRACE_LWP_CREATE breakpoint");
6386 ATF_TC_BODY(signal9, tc)
6388 const int exitval = 5;
6389 const int sigval = SIGSTOP;
6390 const int sigmasked = SIGTRAP;
6392 #if defined(TWAIT_HAVE_STATUS)
6396 ptrace_state_t state;
6397 const int slen = sizeof(state);
6398 ptrace_event_t event;
6399 const int elen = sizeof(event);
6402 static const size_t ssize = 16*1024;
6405 atf_tc_expect_fail("PR kern/51918");
6407 printf("Before forking process PID=%d\n", getpid());
6408 ATF_REQUIRE((child = fork()) != -1);
6410 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
6411 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
6413 sigemptyset(&intmask);
6414 sigaddset(&intmask, sigmasked);
6415 sigprocmask(SIG_BLOCK, &intmask, NULL);
6417 printf("Before raising %s from child\n", strsignal(sigval));
6418 FORKEE_ASSERT(raise(sigval) == 0);
6420 printf("Before allocating memory for stack in child\n");
6421 FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
6423 printf("Before making context for new lwp in child\n");
6424 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
6426 printf("Before creating new in child\n");
6427 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
6429 printf("Before waiting for lwp %d to exit\n", lid);
6430 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
6432 printf("Before verifying that reported %d and running lid %d "
6433 "are the same\n", lid, the_lwp_id);
6434 FORKEE_ASSERT_EQ(lid, the_lwp_id);
6436 printf("Before exiting of the child process\n");
6439 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
6441 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6442 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6444 validate_status_stopped(status, sigval);
6446 printf("Set empty EVENT_MASK for the child %d\n", child);
6447 event.pe_set_event = PTRACE_LWP_CREATE;
6448 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
6450 printf("Before resuming the child process where it left off and "
6451 "without signal to be sent\n");
6452 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6454 printf("Before calling %s() for the child - expected stopped "
6455 "SIGTRAP\n", TWAIT_FNAME);
6456 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6458 validate_status_stopped(status, sigmasked);
6460 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
6462 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
6465 printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
6467 printf("Before resuming the child process where it left off and "
6468 "without signal to be sent\n");
6469 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6471 printf("Before calling %s() for the child - expected exited\n",
6473 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6475 validate_status_exited(status, exitval);
6477 printf("Before calling %s() for the child - expected no process\n",
6479 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6483 ATF_TC_HEAD(signal10, tc)
6485 atf_tc_set_md_var(tc, "descr",
6486 "Verify that masking SIGTRAP in tracee does not stop tracer from "
6487 "catching PTRACE_LWP_EXIT breakpoint");
6490 ATF_TC_BODY(signal10, tc)
6492 const int exitval = 5;
6493 const int sigval = SIGSTOP;
6494 const int sigmasked = SIGTRAP;
6496 #if defined(TWAIT_HAVE_STATUS)
6500 ptrace_state_t state;
6501 const int slen = sizeof(state);
6502 ptrace_event_t event;
6503 const int elen = sizeof(event);
6506 static const size_t ssize = 16*1024;
6509 atf_tc_expect_fail("PR kern/51918");
6511 printf("Before forking process PID=%d\n", getpid());
6512 ATF_REQUIRE((child = fork()) != -1);
6514 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
6515 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
6517 sigemptyset(&intmask);
6518 sigaddset(&intmask, sigmasked);
6519 sigprocmask(SIG_BLOCK, &intmask, NULL);
6521 printf("Before raising %s from child\n", strsignal(sigval));
6522 FORKEE_ASSERT(raise(sigval) == 0);
6524 printf("Before allocating memory for stack in child\n");
6525 FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
6527 printf("Before making context for new lwp in child\n");
6528 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize);
6530 printf("Before creating new in child\n");
6531 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0);
6533 printf("Before waiting for lwp %d to exit\n", lid);
6534 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
6536 printf("Before verifying that reported %d and running lid %d "
6537 "are the same\n", lid, the_lwp_id);
6538 FORKEE_ASSERT_EQ(lid, the_lwp_id);
6540 printf("Before exiting of the child process\n");
6543 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
6545 printf("Before calling %s() for the child\n", TWAIT_FNAME);
6546 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6548 validate_status_stopped(status, sigval);
6550 printf("Set empty EVENT_MASK for the child %d\n", child);
6551 event.pe_set_event = PTRACE_LWP_EXIT;
6552 ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
6554 printf("Before resuming the child process where it left off and "
6555 "without signal to be sent\n");
6556 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6558 printf("Before calling %s() for the child - expected stopped "
6559 "SIGTRAP\n", TWAIT_FNAME);
6560 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6562 validate_status_stopped(status, sigmasked);
6564 ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
6566 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT);
6569 printf("Reported PTRACE_LWP_EXIT event with lid %d\n", lid);
6571 printf("Before resuming the child process where it left off and "
6572 "without signal to be sent\n");
6573 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
6575 printf("Before calling %s() for the child - expected exited\n",
6577 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
6579 validate_status_exited(status, exitval);
6581 printf("Before calling %s() for the child - expected no process\n",
6583 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
6588 setvbuf(stdout, NULL, _IONBF, 0);
6589 setvbuf(stderr, NULL, _IONBF, 0);
6590 ATF_TP_ADD_TC(tp, traceme1);
6591 ATF_TP_ADD_TC(tp, traceme2);
6592 ATF_TP_ADD_TC(tp, traceme3);
6593 ATF_TP_ADD_TC(tp, traceme4);
6595 ATF_TP_ADD_TC_HAVE_PID(tp, attach1);
6596 ATF_TP_ADD_TC_HAVE_PID(tp, attach2);
6597 ATF_TP_ADD_TC(tp, attach3);
6598 ATF_TP_ADD_TC(tp, attach4);
6599 ATF_TP_ADD_TC_HAVE_PID(tp, attach5);
6600 ATF_TP_ADD_TC_HAVE_PID(tp, attach6);
6601 ATF_TP_ADD_TC_HAVE_PID(tp, attach7);
6603 ATF_TP_ADD_TC(tp, eventmask1);
6604 ATF_TP_ADD_TC(tp, eventmask2);
6605 ATF_TP_ADD_TC(tp, eventmask3);
6606 ATF_TP_ADD_TC(tp, eventmask4);
6607 ATF_TP_ADD_TC(tp, eventmask5);
6608 ATF_TP_ADD_TC(tp, eventmask6);
6610 ATF_TP_ADD_TC_HAVE_PID(tp, fork1);
6611 ATF_TP_ADD_TC(tp, fork2);
6613 ATF_TP_ADD_TC_HAVE_PID(tp, vfork1);
6614 ATF_TP_ADD_TC(tp, vfork2);
6616 ATF_TP_ADD_TC(tp, vforkdone1);
6617 ATF_TP_ADD_TC(tp, vforkdone2);
6619 ATF_TP_ADD_TC(tp, io_read_d1);
6620 ATF_TP_ADD_TC(tp, io_read_d2);
6621 ATF_TP_ADD_TC(tp, io_read_d3);
6622 ATF_TP_ADD_TC(tp, io_read_d4);
6624 ATF_TP_ADD_TC(tp, io_write_d1);
6625 ATF_TP_ADD_TC(tp, io_write_d2);
6626 ATF_TP_ADD_TC(tp, io_write_d3);
6627 ATF_TP_ADD_TC(tp, io_write_d4);
6629 ATF_TP_ADD_TC(tp, read_d1);
6630 ATF_TP_ADD_TC(tp, read_d2);
6631 ATF_TP_ADD_TC(tp, read_d3);
6632 ATF_TP_ADD_TC(tp, read_d4);
6634 ATF_TP_ADD_TC(tp, write_d1);
6635 ATF_TP_ADD_TC(tp, write_d2);
6636 ATF_TP_ADD_TC(tp, write_d3);
6637 ATF_TP_ADD_TC(tp, write_d4);
6639 ATF_TP_ADD_TC(tp, io_read_d_write_d_handshake1);
6640 ATF_TP_ADD_TC(tp, io_read_d_write_d_handshake2);
6642 ATF_TP_ADD_TC(tp, read_d_write_d_handshake1);
6643 ATF_TP_ADD_TC(tp, read_d_write_d_handshake2);
6645 ATF_TP_ADD_TC(tp, io_read_i1);
6646 ATF_TP_ADD_TC(tp, io_read_i2);
6647 ATF_TP_ADD_TC(tp, io_read_i3);
6648 ATF_TP_ADD_TC(tp, io_read_i4);
6650 ATF_TP_ADD_TC(tp, read_i1);
6651 ATF_TP_ADD_TC(tp, read_i2);
6652 ATF_TP_ADD_TC(tp, read_i3);
6653 ATF_TP_ADD_TC(tp, read_i4);
6655 ATF_TP_ADD_TC(tp, io_read_auxv1);
6657 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1);
6658 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2);
6659 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3);
6660 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs4);
6661 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs5);
6663 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs1);
6664 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs2);
6666 ATF_TP_ADD_TC_PT_STEP(tp, step1);
6667 ATF_TP_ADD_TC_PT_STEP(tp, step2);
6668 ATF_TP_ADD_TC_PT_STEP(tp, step3);
6669 ATF_TP_ADD_TC_PT_STEP(tp, step4);
6671 ATF_TP_ADD_TC(tp, kill1);
6672 ATF_TP_ADD_TC(tp, kill2);
6674 ATF_TP_ADD_TC(tp, lwpinfo1);
6675 ATF_TP_ADD_TC_HAVE_PID(tp, lwpinfo2);
6677 ATF_TP_ADD_TC(tp, siginfo1);
6678 ATF_TP_ADD_TC(tp, siginfo2);
6679 ATF_TP_ADD_TC(tp, siginfo3);
6680 ATF_TP_ADD_TC(tp, siginfo4);
6681 ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5);
6682 ATF_TP_ADD_TC_PT_STEP(tp, siginfo6);
6684 ATF_TP_ADD_TC(tp, lwp_create1);
6686 ATF_TP_ADD_TC(tp, lwp_exit1);
6688 ATF_TP_ADD_TC(tp, signal1);
6689 ATF_TP_ADD_TC(tp, signal2);
6690 ATF_TP_ADD_TC(tp, signal3);
6691 ATF_TP_ADD_TC_PT_STEP(tp, signal4);
6692 ATF_TP_ADD_TC(tp, signal5);
6693 ATF_TP_ADD_TC_HAVE_PID(tp, signal6);
6694 ATF_TP_ADD_TC_HAVE_PID(tp, signal7);
6695 ATF_TP_ADD_TC(tp, signal8);
6696 ATF_TP_ADD_TC(tp, signal9);
6697 ATF_TP_ADD_TC(tp, signal10);
6699 return atf_no_error();