t_ptrace_wait.c revision 1.32
1/* $NetBSD: t_ptrace_wait.c,v 1.32 2018/04/15 00:19:23 kamil Exp $ */ 2 3/*- 4 * Copyright (c) 2016 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30__RCSID("$NetBSD: t_ptrace_wait.c,v 1.32 2018/04/15 00:19:23 kamil Exp $"); 31 32#include <sys/param.h> 33#include <sys/types.h> 34#include <sys/ptrace.h> 35#include <sys/resource.h> 36#include <sys/stat.h> 37#include <sys/syscall.h> 38#include <sys/sysctl.h> 39#include <sys/wait.h> 40#include <machine/reg.h> 41#include <elf.h> 42#include <err.h> 43#include <errno.h> 44#include <lwp.h> 45#include <sched.h> 46#include <signal.h> 47#include <stdint.h> 48#include <stdio.h> 49#include <stdlib.h> 50#include <strings.h> 51#include <time.h> 52#include <unistd.h> 53 54#include <atf-c.h> 55 56#include "h_macros.h" 57 58#include "t_ptrace_wait.h" 59#include "msg.h" 60 61#define PARENT_TO_CHILD(info, fds, msg) \ 62 SYSCALL_REQUIRE(msg_write_child(info " to child " # fds, &fds, &msg, sizeof(msg)) == 0) 63 64#define CHILD_FROM_PARENT(info, fds, msg) \ 65 FORKEE_ASSERT(msg_read_parent(info " from parent " # fds, &fds, &msg, sizeof(msg)) == 0) 66 67#define CHILD_TO_PARENT(info, fds, msg) \ 68 FORKEE_ASSERT(msg_write_parent(info " to parent " # fds, &fds, &msg, sizeof(msg)) == 0) 69 70#define PARENT_FROM_CHILD(info, fds, msg) \ 71 SYSCALL_REQUIRE(msg_read_child(info " from parent " # fds, &fds, &msg, sizeof(msg)) == 0) 72 73#define SYSCALL_REQUIRE(expr) ATF_REQUIRE_MSG(expr, "%s: %s", # expr, \ 74 strerror(errno)) 75#define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \ 76 "%d(%s) != %d", res, strerror(res), exp) 77 78static int debug = 0; 79 80#define DPRINTF(a, ...) do \ 81 if (debug) printf(a, ##__VA_ARGS__); \ 82 while (/*CONSTCOND*/0) 83 84 85ATF_TC(traceme1); 86ATF_TC_HEAD(traceme1, tc) 87{ 88 atf_tc_set_md_var(tc, "descr", 89 "Verify SIGSTOP followed by _exit(2) in a child"); 90} 91 92ATF_TC_BODY(traceme1, tc) 93{ 94 const int exitval = 5; 95 const int sigval = SIGSTOP; 96 pid_t child, wpid; 97#if defined(TWAIT_HAVE_STATUS) 98 int status; 99#endif 100 101 DPRINTF("Before forking process PID=%d\n", getpid()); 102 SYSCALL_REQUIRE((child = fork()) != -1); 103 if (child == 0) { 104 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 105 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 106 107 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 108 FORKEE_ASSERT(raise(sigval) == 0); 109 110 DPRINTF("Before exiting of the child process\n"); 111 _exit(exitval); 112 } 113 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 114 115 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 116 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 117 118 validate_status_stopped(status, sigval); 119 120 DPRINTF("Before resuming the child process where it left off and " 121 "without signal to be sent\n"); 122 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 123 124 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 125 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 126 127 validate_status_exited(status, exitval); 128 129 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 130 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 131} 132 133ATF_TC(traceme2); 134ATF_TC_HEAD(traceme2, tc) 135{ 136 atf_tc_set_md_var(tc, "descr", 137 "Verify that a signal emitted by a tracer to a child is caught by " 138 "a signal handler"); 139} 140 141static int traceme2_caught = 0; 142 143static void 144traceme2_sighandler(int sig) 145{ 146 FORKEE_ASSERT_EQ(sig, SIGINT); 147 148 ++traceme2_caught; 149} 150 151ATF_TC_BODY(traceme2, tc) 152{ 153 const int exitval = 5; 154 const int sigval = SIGSTOP, sigsent = SIGINT; 155 pid_t child, wpid; 156 struct sigaction sa; 157#if defined(TWAIT_HAVE_STATUS) 158 int status; 159#endif 160 161 DPRINTF("Before forking process PID=%d\n", getpid()); 162 SYSCALL_REQUIRE((child = fork()) != -1); 163 if (child == 0) { 164 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 165 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 166 167 sa.sa_handler = traceme2_sighandler; 168 sa.sa_flags = SA_SIGINFO; 169 sigemptyset(&sa.sa_mask); 170 171 FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1); 172 173 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 174 FORKEE_ASSERT(raise(sigval) == 0); 175 176 FORKEE_ASSERT_EQ(traceme2_caught, 1); 177 178 DPRINTF("Before exiting of the child process\n"); 179 _exit(exitval); 180 } 181 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 182 183 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 184 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 185 186 validate_status_stopped(status, sigval); 187 188 DPRINTF("Before resuming the child process where it left off and with " 189 "signal %s to be sent\n", strsignal(sigsent)); 190 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 191 192 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 193 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 194 195 validate_status_exited(status, exitval); 196 197 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 198 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 199} 200 201ATF_TC(traceme3); 202ATF_TC_HEAD(traceme3, tc) 203{ 204 atf_tc_set_md_var(tc, "descr", 205 "Verify SIGSTOP followed by termination by a signal in a child"); 206} 207 208ATF_TC_BODY(traceme3, tc) 209{ 210 const int sigval = SIGSTOP, sigsent = SIGINT /* Without core-dump */; 211 pid_t child, wpid; 212#if defined(TWAIT_HAVE_STATUS) 213 int status; 214#endif 215 216 DPRINTF("Before forking process PID=%d\n", getpid()); 217 SYSCALL_REQUIRE((child = fork()) != -1); 218 if (child == 0) { 219 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 220 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 221 222 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 223 FORKEE_ASSERT(raise(sigval) == 0); 224 225 /* NOTREACHED */ 226 FORKEE_ASSERTX(0 && 227 "Child should be terminated by a signal from its parent"); 228 } 229 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 230 231 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 232 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 233 234 validate_status_stopped(status, sigval); 235 236 DPRINTF("Before resuming the child process where it left off and with " 237 "signal %s to be sent\n", strsignal(sigsent)); 238 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 239 240 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 241 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 242 243 validate_status_signaled(status, sigsent, 0); 244 245 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 246 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 247} 248 249ATF_TC(traceme4); 250ATF_TC_HEAD(traceme4, tc) 251{ 252 atf_tc_set_md_var(tc, "descr", 253 "Verify SIGSTOP followed by SIGCONT and _exit(2) in a child"); 254} 255 256ATF_TC_BODY(traceme4, tc) 257{ 258 const int exitval = 5; 259 const int sigval = SIGSTOP, sigsent = SIGCONT; 260 pid_t child, wpid; 261#if defined(TWAIT_HAVE_STATUS) 262 int status; 263#endif 264 265 DPRINTF("Before forking process PID=%d\n", getpid()); 266 SYSCALL_REQUIRE((child = fork()) != -1); 267 if (child == 0) { 268 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 269 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 270 271 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 272 FORKEE_ASSERT(raise(sigval) == 0); 273 274 DPRINTF("Before raising %s from child\n", strsignal(sigsent)); 275 FORKEE_ASSERT(raise(sigsent) == 0); 276 277 DPRINTF("Before exiting of the child process\n"); 278 _exit(exitval); 279 } 280 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(),child); 281 282 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 283 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 284 285 validate_status_stopped(status, sigval); 286 287 DPRINTF("Before resuming the child process where it left off and " 288 "without signal to be sent\n"); 289 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 290 291 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 292 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 293 294 validate_status_stopped(status, sigsent); 295 296 DPRINTF("Before resuming the child process where it left off and " 297 "without signal to be sent\n"); 298 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 299 300 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 301 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 302 303 validate_status_exited(status, exitval); 304 305 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 306 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 307} 308 309#if defined(TWAIT_HAVE_PID) 310ATF_TC(attach1); 311ATF_TC_HEAD(attach1, tc) 312{ 313 atf_tc_set_md_var(tc, "descr", 314 "Assert that tracer sees process termination before the parent"); 315} 316 317static void 318attach1_raw(bool raw) 319{ 320 struct msg_fds parent_tracee, parent_tracer; 321 const int exitval_tracee = 5; 322 const int exitval_tracer = 10; 323 pid_t tracee, tracer, wpid; 324 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 325#if defined(TWAIT_HAVE_STATUS) 326 int status; 327#endif 328 329 DPRINTF("Spawn tracee\n"); 330 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 331 tracee = atf_utils_fork(); 332 if (tracee == 0) { 333 // Wait for parent to let us exit 334 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); 335 _exit(exitval_tracee); 336 } 337 338 DPRINTF("Spawn debugger\n"); 339 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 340 tracer = atf_utils_fork(); 341 if (tracer == 0) { 342 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 343 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 344 345 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 346 FORKEE_REQUIRE_SUCCESS( 347 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 348 349 forkee_status_stopped(status, SIGSTOP); 350 351 /* Resume tracee with PT_CONTINUE */ 352 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 353 354 /* Inform parent that tracer has attached to tracee */ 355 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 356 357 /* Wait for parent to tell use that tracee should have exited */ 358 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 359 360 /* Wait for tracee and assert that it exited */ 361 FORKEE_REQUIRE_SUCCESS( 362 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 363 364 forkee_status_exited(status, exitval_tracee); 365 DPRINTF("Tracee %d exited with %d\n", tracee, exitval_tracee); 366 367 DPRINTF("Before exiting of the tracer process\n"); 368 _exit(exitval_tracer); 369 } 370 371 DPRINTF("Wait for the tracer to attach to the tracee\n"); 372 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 373 374 DPRINTF("Resume the tracee and let it exit\n"); 375 PARENT_TO_CHILD("exit tracee", parent_tracee, msg); 376 377 DPRINTF("Detect that tracee is zombie\n"); 378 if (raw) 379 await_zombie_raw(tracee, 0); 380 else 381 await_zombie(tracee); 382 383 DPRINTF("Assert that there is no status about tracee %d - " 384 "Tracer must detect zombie first - calling %s()\n", tracee, 385 TWAIT_FNAME); 386 TWAIT_REQUIRE_SUCCESS( 387 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 388 389 DPRINTF("Tell the tracer child should have exited\n"); 390 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg); 391 DPRINTF("Wait for tracer to finish its job and exit - calling %s()\n", 392 TWAIT_FNAME); 393 394 DPRINTF("Wait from tracer child to complete waiting for tracee\n"); 395 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 396 tracer); 397 398 validate_status_exited(status, exitval_tracer); 399 400 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 401 TWAIT_FNAME); 402 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 403 tracee); 404 405 validate_status_exited(status, exitval_tracee); 406 407 msg_close(&parent_tracer); 408 msg_close(&parent_tracee); 409} 410 411ATF_TC_BODY(attach1, tc) 412{ 413 414 /* Reuse this test with race1 */ 415 attach1_raw(false); 416} 417 418#endif 419 420#if defined(TWAIT_HAVE_PID) 421ATF_TC(attach2); 422ATF_TC_HEAD(attach2, tc) 423{ 424 atf_tc_set_md_var(tc, "descr", 425 "Assert that any tracer sees process termination before its " 426 "parent"); 427} 428 429ATF_TC_BODY(attach2, tc) 430{ 431 struct msg_fds parent_tracer, parent_tracee; 432 const int exitval_tracee = 5; 433 const int exitval_tracer1 = 10, exitval_tracer2 = 20; 434 pid_t tracee, tracer, wpid; 435 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 436#if defined(TWAIT_HAVE_STATUS) 437 int status; 438#endif 439 440 DPRINTF("Spawn tracee\n"); 441 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 442 tracee = atf_utils_fork(); 443 if (tracee == 0) { 444 /* Wait for message from the parent */ 445 CHILD_FROM_PARENT("Message 1", parent_tracee, msg); 446 _exit(exitval_tracee); 447 } 448 449 DPRINTF("Spawn debugger\n"); 450 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 451 tracer = atf_utils_fork(); 452 if (tracer == 0) { 453 /* Fork again and drop parent to reattach to PID 1 */ 454 tracer = atf_utils_fork(); 455 if (tracer != 0) 456 _exit(exitval_tracer1); 457 458 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 459 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 460 461 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 462 FORKEE_REQUIRE_SUCCESS( 463 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 464 465 forkee_status_stopped(status, SIGSTOP); 466 467 /* Resume tracee with PT_CONTINUE */ 468 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 469 470 /* Inform parent that tracer has attached to tracee */ 471 CHILD_TO_PARENT("Message 1", parent_tracer, msg); 472 CHILD_FROM_PARENT("Message 2", parent_tracer, msg); 473 474 /* Wait for tracee and assert that it exited */ 475 FORKEE_REQUIRE_SUCCESS( 476 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 477 478 forkee_status_exited(status, exitval_tracee); 479 480 DPRINTF("Before exiting of the tracer process\n"); 481 _exit(exitval_tracer2); 482 } 483 DPRINTF("Wait for the tracer process (direct child) to exit calling " 484 "%s()\n", TWAIT_FNAME); 485 TWAIT_REQUIRE_SUCCESS( 486 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer); 487 488 validate_status_exited(status, exitval_tracer1); 489 490 DPRINTF("Wait for the non-exited tracee process with %s()\n", 491 TWAIT_FNAME); 492 TWAIT_REQUIRE_SUCCESS( 493 wpid = TWAIT_GENERIC(tracee, NULL, WNOHANG), 0); 494 495 DPRINTF("Wait for the tracer to attach to the tracee\n"); 496 PARENT_FROM_CHILD("Message 1", parent_tracer, msg); 497 DPRINTF("Resume the tracee and let it exit\n"); 498 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 499 500 DPRINTF("Detect that tracee is zombie\n"); 501 await_zombie(tracee); 502 503 DPRINTF("Assert that there is no status about tracee - " 504 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 505 TWAIT_REQUIRE_SUCCESS( 506 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 507 508 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 509 PARENT_TO_CHILD("Message 2", parent_tracer, msg); 510 511 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 512 TWAIT_FNAME); 513 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, 0), 514 tracee); 515 516 validate_status_exited(status, exitval_tracee); 517 518 msg_close(&parent_tracer); 519 msg_close(&parent_tracee); 520} 521#endif 522 523ATF_TC(attach3); 524ATF_TC_HEAD(attach3, tc) 525{ 526 atf_tc_set_md_var(tc, "descr", 527 "Assert that tracer parent can PT_ATTACH to its child"); 528} 529 530ATF_TC_BODY(attach3, tc) 531{ 532 struct msg_fds parent_tracee; 533 const int exitval_tracee = 5; 534 pid_t tracee, wpid; 535 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 536#if defined(TWAIT_HAVE_STATUS) 537 int status; 538#endif 539 540 DPRINTF("Spawn tracee\n"); 541 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 542 tracee = atf_utils_fork(); 543 if (tracee == 0) { 544 CHILD_FROM_PARENT("Message 1", parent_tracee, msg); 545 DPRINTF("Parent should now attach to tracee\n"); 546 547 CHILD_FROM_PARENT("Message 2", parent_tracee, msg); 548 /* Wait for message from the parent */ 549 _exit(exitval_tracee); 550 } 551 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 552 553 DPRINTF("Before calling PT_ATTACH for tracee %d\n", tracee); 554 SYSCALL_REQUIRE(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 555 556 DPRINTF("Wait for the stopped tracee process with %s()\n", 557 TWAIT_FNAME); 558 TWAIT_REQUIRE_SUCCESS( 559 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 560 561 validate_status_stopped(status, SIGSTOP); 562 563 DPRINTF("Resume tracee with PT_CONTINUE\n"); 564 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 565 566 DPRINTF("Let the tracee exit now\n"); 567 PARENT_TO_CHILD("Message 2", parent_tracee, msg); 568 569 DPRINTF("Wait for tracee to exit with %s()\n", TWAIT_FNAME); 570 TWAIT_REQUIRE_SUCCESS( 571 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 572 573 validate_status_exited(status, exitval_tracee); 574 575 DPRINTF("Before calling %s() for tracee\n", TWAIT_FNAME); 576 TWAIT_REQUIRE_FAILURE(ECHILD, 577 wpid = TWAIT_GENERIC(tracee, &status, 0)); 578 579 msg_close(&parent_tracee); 580} 581 582ATF_TC(attach4); 583ATF_TC_HEAD(attach4, tc) 584{ 585 atf_tc_set_md_var(tc, "descr", 586 "Assert that tracer child can PT_ATTACH to its parent"); 587} 588 589ATF_TC_BODY(attach4, tc) 590{ 591 struct msg_fds parent_tracee; 592 const int exitval_tracer = 5; 593 pid_t tracer, wpid; 594 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 595#if defined(TWAIT_HAVE_STATUS) 596 int status; 597#endif 598 599 DPRINTF("Spawn tracer\n"); 600 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 601 tracer = atf_utils_fork(); 602 if (tracer == 0) { 603 604 /* Wait for message from the parent */ 605 CHILD_FROM_PARENT("Message 1", parent_tracee, msg); 606 607 DPRINTF("Attach to parent PID %d with PT_ATTACH from child\n", 608 getppid()); 609 FORKEE_ASSERT(ptrace(PT_ATTACH, getppid(), NULL, 0) != -1); 610 611 DPRINTF("Wait for the stopped parent process with %s()\n", 612 TWAIT_FNAME); 613 FORKEE_REQUIRE_SUCCESS( 614 wpid = TWAIT_GENERIC(getppid(), &status, 0), getppid()); 615 616 forkee_status_stopped(status, SIGSTOP); 617 618 DPRINTF("Resume parent with PT_DETACH\n"); 619 FORKEE_ASSERT(ptrace(PT_DETACH, getppid(), (void *)1, 0) 620 != -1); 621 622 /* Tell parent we are ready */ 623 CHILD_TO_PARENT("Message 1", parent_tracee, msg); 624 625 _exit(exitval_tracer); 626 } 627 628 DPRINTF("Wait for the tracer to become ready\n"); 629 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 630 DPRINTF("Allow the tracer to exit now\n"); 631 PARENT_FROM_CHILD("Message 1", parent_tracee, msg); 632 633 DPRINTF("Wait for tracer to exit with %s()\n", TWAIT_FNAME); 634 TWAIT_REQUIRE_SUCCESS( 635 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer); 636 637 validate_status_exited(status, exitval_tracer); 638 639 DPRINTF("Before calling %s() for tracer\n", TWAIT_FNAME); 640 TWAIT_REQUIRE_FAILURE(ECHILD, 641 wpid = TWAIT_GENERIC(tracer, &status, 0)); 642 643 msg_close(&parent_tracee); 644} 645 646#if defined(TWAIT_HAVE_PID) 647ATF_TC(attach5); 648ATF_TC_HEAD(attach5, tc) 649{ 650 atf_tc_set_md_var(tc, "descr", 651 "Assert that tracer sees its parent when attached to tracer " 652 "(check getppid(2))"); 653} 654 655ATF_TC_BODY(attach5, tc) 656{ 657 struct msg_fds parent_tracer, parent_tracee; 658 const int exitval_tracee = 5; 659 const int exitval_tracer = 10; 660 pid_t parent, tracee, tracer, wpid; 661 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 662#if defined(TWAIT_HAVE_STATUS) 663 int status; 664#endif 665 666 DPRINTF("Spawn tracee\n"); 667 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 668 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 669 tracee = atf_utils_fork(); 670 if (tracee == 0) { 671 parent = getppid(); 672 673 /* Emit message to the parent */ 674 CHILD_TO_PARENT("tracee ready", parent_tracee, msg); 675 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); 676 677 FORKEE_ASSERT_EQ(parent, getppid()); 678 679 _exit(exitval_tracee); 680 } 681 DPRINTF("Wait for child to record its parent identifier (pid)\n"); 682 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg); 683 684 DPRINTF("Spawn debugger\n"); 685 tracer = atf_utils_fork(); 686 if (tracer == 0) { 687 /* No IPC to communicate with the child */ 688 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 689 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 690 691 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 692 FORKEE_REQUIRE_SUCCESS( 693 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 694 695 forkee_status_stopped(status, SIGSTOP); 696 697 /* Resume tracee with PT_CONTINUE */ 698 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 699 700 /* Inform parent that tracer has attached to tracee */ 701 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 702 703 /* Wait for parent to tell use that tracee should have exited */ 704 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 705 706 /* Wait for tracee and assert that it exited */ 707 FORKEE_REQUIRE_SUCCESS( 708 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 709 710 forkee_status_exited(status, exitval_tracee); 711 712 DPRINTF("Before exiting of the tracer process\n"); 713 _exit(exitval_tracer); 714 } 715 716 DPRINTF("Wait for the tracer to attach to the tracee\n"); 717 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 718 719 DPRINTF("Resume the tracee and let it exit\n"); 720 PARENT_TO_CHILD("exit tracee", parent_tracee, msg); 721 722 DPRINTF("Detect that tracee is zombie\n"); 723 await_zombie(tracee); 724 725 DPRINTF("Assert that there is no status about tracee - " 726 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 727 TWAIT_REQUIRE_SUCCESS( 728 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 729 730 DPRINTF("Tell the tracer child should have exited\n"); 731 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg); 732 733 DPRINTF("Wait from tracer child to complete waiting for tracee\n"); 734 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 735 tracer); 736 737 validate_status_exited(status, exitval_tracer); 738 739 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 740 TWAIT_FNAME); 741 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 742 tracee); 743 744 validate_status_exited(status, exitval_tracee); 745 746 msg_close(&parent_tracer); 747 msg_close(&parent_tracee); 748} 749#endif 750 751#if defined(TWAIT_HAVE_PID) 752ATF_TC(attach6); 753ATF_TC_HEAD(attach6, tc) 754{ 755 atf_tc_set_md_var(tc, "descr", 756 "Assert that tracer sees its parent when attached to tracer " 757 "(check sysctl(7) and struct kinfo_proc2)"); 758} 759 760ATF_TC_BODY(attach6, tc) 761{ 762 struct msg_fds parent_tracee, parent_tracer; 763 const int exitval_tracee = 5; 764 const int exitval_tracer = 10; 765 pid_t parent, tracee, tracer, wpid; 766 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 767#if defined(TWAIT_HAVE_STATUS) 768 int status; 769#endif 770 int name[CTL_MAXNAME]; 771 struct kinfo_proc2 kp; 772 size_t len = sizeof(kp); 773 unsigned int namelen; 774 775 DPRINTF("Spawn tracee\n"); 776 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 777 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 778 tracee = atf_utils_fork(); 779 if (tracee == 0) { 780 parent = getppid(); 781 782 /* Emit message to the parent */ 783 CHILD_TO_PARENT("Message 1", parent_tracee, msg); 784 CHILD_FROM_PARENT("Message 2", parent_tracee, msg); 785 786 namelen = 0; 787 name[namelen++] = CTL_KERN; 788 name[namelen++] = KERN_PROC2; 789 name[namelen++] = KERN_PROC_PID; 790 name[namelen++] = getpid(); 791 name[namelen++] = len; 792 name[namelen++] = 1; 793 794 FORKEE_ASSERT(sysctl(name, namelen, &kp, &len, NULL, 0) == 0); 795 FORKEE_ASSERT_EQ(parent, kp.p_ppid); 796 797 _exit(exitval_tracee); 798 } 799 800 DPRINTF("Wait for child to record its parent identifier (pid)\n"); 801 PARENT_FROM_CHILD("Message 1", parent_tracee, msg); 802 803 DPRINTF("Spawn debugger\n"); 804 tracer = atf_utils_fork(); 805 if (tracer == 0) { 806 /* No IPC to communicate with the child */ 807 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 808 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 809 810 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 811 FORKEE_REQUIRE_SUCCESS( 812 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 813 814 forkee_status_stopped(status, SIGSTOP); 815 816 /* Resume tracee with PT_CONTINUE */ 817 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 818 819 /* Inform parent that tracer has attached to tracee */ 820 CHILD_TO_PARENT("Message 1", parent_tracer, msg); 821 822 CHILD_FROM_PARENT("Message 2", parent_tracer, msg); 823 824 /* Wait for tracee and assert that it exited */ 825 FORKEE_REQUIRE_SUCCESS( 826 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 827 828 forkee_status_exited(status, exitval_tracee); 829 830 DPRINTF("Before exiting of the tracer process\n"); 831 _exit(exitval_tracer); 832 } 833 834 DPRINTF("Wait for the tracer to attach to the tracee\n"); 835 PARENT_FROM_CHILD("Message 1", parent_tracer, msg); 836 837 DPRINTF("Resume the tracee and let it exit\n"); 838 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 839 840 DPRINTF("Detect that tracee is zombie\n"); 841 await_zombie(tracee); 842 843 DPRINTF("Assert that there is no status about tracee - " 844 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 845 TWAIT_REQUIRE_SUCCESS( 846 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 847 848 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 849 PARENT_TO_CHILD("Message 2", parent_tracer, msg); 850 851 DPRINTF("Wait for tracer to finish its job and exit - calling %s()\n", 852 TWAIT_FNAME); 853 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 854 tracer); 855 856 validate_status_exited(status, exitval_tracer); 857 858 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 859 TWAIT_FNAME); 860 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 861 tracee); 862 863 validate_status_exited(status, exitval_tracee); 864 865 msg_close(&parent_tracee); 866 msg_close(&parent_tracer); 867} 868#endif 869 870#if defined(TWAIT_HAVE_PID) 871ATF_TC(attach7); 872ATF_TC_HEAD(attach7, tc) 873{ 874 atf_tc_set_md_var(tc, "descr", 875 "Assert that tracer sees its parent when attached to tracer " 876 "(check /proc/curproc/status 3rd column)"); 877} 878 879ATF_TC_BODY(attach7, tc) 880{ 881 struct msg_fds parent_tracee, parent_tracer; 882 int rv; 883 const int exitval_tracee = 5; 884 const int exitval_tracer = 10; 885 pid_t parent, tracee, tracer, wpid; 886 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 887#if defined(TWAIT_HAVE_STATUS) 888 int status; 889#endif 890 FILE *fp; 891 struct stat st; 892 const char *fname = "/proc/curproc/status"; 893 char s_executable[MAXPATHLEN]; 894 int s_pid, s_ppid; 895 /* 896 * Format: 897 * EXECUTABLE PID PPID ... 898 */ 899 900 SYSCALL_REQUIRE((rv = stat(fname, &st)) == 0 || (errno == ENOENT)); 901 if (rv != 0) { 902 atf_tc_skip("/proc/curproc/status not found"); 903 } 904 905 DPRINTF("Spawn tracee\n"); 906 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 907 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 908 tracee = atf_utils_fork(); 909 if (tracee == 0) { 910 parent = getppid(); 911 912 // Wait for parent to let us exit 913 CHILD_TO_PARENT("tracee ready", parent_tracee, msg); 914 CHILD_FROM_PARENT("tracee exit", parent_tracee, msg); 915 916 FORKEE_ASSERT((fp = fopen(fname, "r")) != NULL); 917 fscanf(fp, "%s %d %d", s_executable, &s_pid, &s_ppid); 918 FORKEE_ASSERT(fclose(fp) == 0); 919 FORKEE_ASSERT_EQ(parent, s_ppid); 920 921 _exit(exitval_tracee); 922 } 923 924 DPRINTF("Wait for child to record its parent identifier (pid)\n"); 925 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg); 926 927 DPRINTF("Spawn debugger\n"); 928 tracer = atf_utils_fork(); 929 if (tracer == 0) { 930 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 931 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 932 933 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 934 FORKEE_REQUIRE_SUCCESS( 935 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 936 937 forkee_status_stopped(status, SIGSTOP); 938 939 /* Resume tracee with PT_CONTINUE */ 940 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 941 942 /* Inform parent that tracer has attached to tracee */ 943 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 944 945 /* Wait for parent to tell use that tracee should have exited */ 946 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 947 948 /* Wait for tracee and assert that it exited */ 949 FORKEE_REQUIRE_SUCCESS( 950 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 951 952 forkee_status_exited(status, exitval_tracee); 953 954 DPRINTF("Before exiting of the tracer process\n"); 955 _exit(exitval_tracer); 956 } 957 DPRINTF("Wait for the tracer to attach to the tracee\n"); 958 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 959 DPRINTF("Resume the tracee and let it exit\n"); 960 PARENT_TO_CHILD("tracee exit", parent_tracee, msg); 961 962 DPRINTF("Detect that tracee is zombie\n"); 963 await_zombie(tracee); 964 965 DPRINTF("Assert that there is no status about tracee - " 966 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 967 TWAIT_REQUIRE_SUCCESS( 968 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 969 970 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 971 PARENT_TO_CHILD("Message 2", parent_tracer, msg); 972 973 DPRINTF("Wait for tracer to finish its job and exit - calling %s()\n", 974 TWAIT_FNAME); 975 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 976 tracer); 977 978 validate_status_exited(status, exitval_tracer); 979 980 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 981 TWAIT_FNAME); 982 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 983 tracee); 984 985 validate_status_exited(status, exitval_tracee); 986 987 msg_close(&parent_tracee); 988 msg_close(&parent_tracer); 989} 990#endif 991 992ATF_TC(eventmask1); 993ATF_TC_HEAD(eventmask1, tc) 994{ 995 atf_tc_set_md_var(tc, "descr", 996 "Verify that empty EVENT_MASK is preserved"); 997} 998 999ATF_TC_BODY(eventmask1, tc) 1000{ 1001 const int exitval = 5; 1002 const int sigval = SIGSTOP; 1003 pid_t child, wpid; 1004#if defined(TWAIT_HAVE_STATUS) 1005 int status; 1006#endif 1007 ptrace_event_t set_event, get_event; 1008 const int len = sizeof(ptrace_event_t); 1009 1010 DPRINTF("Before forking process PID=%d\n", getpid()); 1011 SYSCALL_REQUIRE((child = fork()) != -1); 1012 if (child == 0) { 1013 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1014 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1015 1016 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1017 FORKEE_ASSERT(raise(sigval) == 0); 1018 1019 DPRINTF("Before exiting of the child process\n"); 1020 _exit(exitval); 1021 } 1022 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1023 1024 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1025 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1026 1027 validate_status_stopped(status, sigval); 1028 1029 set_event.pe_set_event = 0; 1030 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1031 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1032 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1033 1034 DPRINTF("Before resuming the child process where it left off and " 1035 "without signal to be sent\n"); 1036 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1037 1038 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1039 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1040 1041 validate_status_exited(status, exitval); 1042 1043 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1044 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1045} 1046 1047ATF_TC(eventmask2); 1048ATF_TC_HEAD(eventmask2, tc) 1049{ 1050 atf_tc_set_md_var(tc, "descr", 1051 "Verify that PTRACE_FORK in EVENT_MASK is preserved"); 1052} 1053 1054ATF_TC_BODY(eventmask2, tc) 1055{ 1056 const int exitval = 5; 1057 const int sigval = SIGSTOP; 1058 pid_t child, wpid; 1059#if defined(TWAIT_HAVE_STATUS) 1060 int status; 1061#endif 1062 ptrace_event_t set_event, get_event; 1063 const int len = sizeof(ptrace_event_t); 1064 1065 DPRINTF("Before forking process PID=%d\n", getpid()); 1066 SYSCALL_REQUIRE((child = fork()) != -1); 1067 if (child == 0) { 1068 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1069 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1070 1071 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1072 FORKEE_ASSERT(raise(sigval) == 0); 1073 1074 DPRINTF("Before exiting of the child process\n"); 1075 _exit(exitval); 1076 } 1077 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1078 1079 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1080 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1081 1082 validate_status_stopped(status, sigval); 1083 1084 set_event.pe_set_event = PTRACE_FORK; 1085 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1086 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1087 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1088 1089 DPRINTF("Before resuming the child process where it left off and " 1090 "without signal to be sent\n"); 1091 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1092 1093 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1094 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1095 1096 validate_status_exited(status, exitval); 1097 1098 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1099 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1100} 1101 1102ATF_TC(eventmask3); 1103ATF_TC_HEAD(eventmask3, tc) 1104{ 1105 atf_tc_set_md_var(tc, "descr", 1106 "Verify that PTRACE_VFORK in EVENT_MASK is preserved"); 1107} 1108 1109ATF_TC_BODY(eventmask3, tc) 1110{ 1111 const int exitval = 5; 1112 const int sigval = SIGSTOP; 1113 pid_t child, wpid; 1114#if defined(TWAIT_HAVE_STATUS) 1115 int status; 1116#endif 1117 ptrace_event_t set_event, get_event; 1118 const int len = sizeof(ptrace_event_t); 1119 1120 atf_tc_expect_fail("PR kern/51630"); 1121 1122 DPRINTF("Before forking process PID=%d\n", getpid()); 1123 SYSCALL_REQUIRE((child = fork()) != -1); 1124 if (child == 0) { 1125 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1126 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1127 1128 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1129 FORKEE_ASSERT(raise(sigval) == 0); 1130 1131 DPRINTF("Before exiting of the child process\n"); 1132 _exit(exitval); 1133 } 1134 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1135 1136 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1137 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1138 1139 validate_status_stopped(status, sigval); 1140 1141 set_event.pe_set_event = PTRACE_VFORK; 1142 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1 || errno == ENOTSUP); 1143 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1144 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1145 1146 DPRINTF("Before resuming the child process where it left off and " 1147 "without signal to be sent\n"); 1148 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1149 1150 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1151 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1152 1153 validate_status_exited(status, exitval); 1154 1155 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1156 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1157} 1158 1159ATF_TC(eventmask4); 1160ATF_TC_HEAD(eventmask4, tc) 1161{ 1162 atf_tc_set_md_var(tc, "descr", 1163 "Verify that PTRACE_VFORK_DONE in EVENT_MASK is preserved"); 1164} 1165 1166ATF_TC_BODY(eventmask4, tc) 1167{ 1168 const int exitval = 5; 1169 const int sigval = SIGSTOP; 1170 pid_t child, wpid; 1171#if defined(TWAIT_HAVE_STATUS) 1172 int status; 1173#endif 1174 ptrace_event_t set_event, get_event; 1175 const int len = sizeof(ptrace_event_t); 1176 1177 DPRINTF("Before forking process PID=%d\n", getpid()); 1178 SYSCALL_REQUIRE((child = fork()) != -1); 1179 if (child == 0) { 1180 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1181 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1182 1183 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1184 FORKEE_ASSERT(raise(sigval) == 0); 1185 1186 DPRINTF("Before exiting of the child process\n"); 1187 _exit(exitval); 1188 } 1189 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1190 1191 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1192 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1193 1194 validate_status_stopped(status, sigval); 1195 1196 set_event.pe_set_event = PTRACE_VFORK_DONE; 1197 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1198 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1199 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1200 1201 DPRINTF("Before resuming the child process where it left off and " 1202 "without signal to be sent\n"); 1203 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1204 1205 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1206 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1207 1208 validate_status_exited(status, exitval); 1209 1210 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1211 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1212} 1213 1214ATF_TC(eventmask5); 1215ATF_TC_HEAD(eventmask5, tc) 1216{ 1217 atf_tc_set_md_var(tc, "descr", 1218 "Verify that PTRACE_LWP_CREATE in EVENT_MASK is preserved"); 1219} 1220 1221ATF_TC_BODY(eventmask5, tc) 1222{ 1223 const int exitval = 5; 1224 const int sigval = SIGSTOP; 1225 pid_t child, wpid; 1226#if defined(TWAIT_HAVE_STATUS) 1227 int status; 1228#endif 1229 ptrace_event_t set_event, get_event; 1230 const int len = sizeof(ptrace_event_t); 1231 1232 DPRINTF("Before forking process PID=%d\n", getpid()); 1233 SYSCALL_REQUIRE((child = fork()) != -1); 1234 if (child == 0) { 1235 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1236 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1237 1238 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1239 FORKEE_ASSERT(raise(sigval) == 0); 1240 1241 DPRINTF("Before exiting of the child process\n"); 1242 _exit(exitval); 1243 } 1244 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1245 1246 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1247 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1248 1249 validate_status_stopped(status, sigval); 1250 1251 set_event.pe_set_event = PTRACE_LWP_CREATE; 1252 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1253 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1254 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1255 1256 DPRINTF("Before resuming the child process where it left off and " 1257 "without signal to be sent\n"); 1258 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1259 1260 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1261 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1262 1263 validate_status_exited(status, exitval); 1264 1265 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1266 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1267} 1268 1269ATF_TC(eventmask6); 1270ATF_TC_HEAD(eventmask6, tc) 1271{ 1272 atf_tc_set_md_var(tc, "descr", 1273 "Verify that PTRACE_LWP_EXIT in EVENT_MASK is preserved"); 1274} 1275 1276ATF_TC_BODY(eventmask6, tc) 1277{ 1278 const int exitval = 5; 1279 const int sigval = SIGSTOP; 1280 pid_t child, wpid; 1281#if defined(TWAIT_HAVE_STATUS) 1282 int status; 1283#endif 1284 ptrace_event_t set_event, get_event; 1285 const int len = sizeof(ptrace_event_t); 1286 1287 DPRINTF("Before forking process PID=%d\n", getpid()); 1288 SYSCALL_REQUIRE((child = fork()) != -1); 1289 if (child == 0) { 1290 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1291 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1292 1293 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1294 FORKEE_ASSERT(raise(sigval) == 0); 1295 1296 DPRINTF("Before exiting of the child process\n"); 1297 _exit(exitval); 1298 } 1299 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1300 1301 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1302 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1303 1304 validate_status_stopped(status, sigval); 1305 1306 set_event.pe_set_event = PTRACE_LWP_EXIT; 1307 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1308 SYSCALL_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1309 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1310 1311 DPRINTF("Before resuming the child process where it left off and " 1312 "without signal to be sent\n"); 1313 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1314 1315 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1316 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1317 1318 validate_status_exited(status, exitval); 1319 1320 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1321 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1322} 1323 1324static void 1325fork_body(pid_t (*fn)(void), bool trackfork, bool trackvfork, 1326 bool trackvforkdone, bool detachchild, bool detachparent) 1327{ 1328 const int exitval = 5; 1329 const int exitval2 = 15; 1330 const int sigval = SIGSTOP; 1331 pid_t child, child2 = 0, wpid; 1332#if defined(TWAIT_HAVE_STATUS) 1333 int status; 1334#endif 1335 ptrace_state_t state; 1336 const int slen = sizeof(state); 1337 ptrace_event_t event; 1338 const int elen = sizeof(event); 1339 1340 if (trackvfork) { 1341 atf_tc_expect_fail("PR kern/51630"); 1342 } 1343 1344 DPRINTF("Before forking process PID=%d\n", getpid()); 1345 SYSCALL_REQUIRE((child = fork()) != -1); 1346 if (child == 0) { 1347 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1348 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1349 1350 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1351 FORKEE_ASSERT(raise(sigval) == 0); 1352 1353 FORKEE_ASSERT((child2 = (fn)()) != -1); 1354 1355 if (child2 == 0) 1356 _exit(exitval2); 1357 1358 FORKEE_REQUIRE_SUCCESS 1359 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 1360 1361 forkee_status_exited(status, exitval2); 1362 1363 DPRINTF("Before exiting of the child process\n"); 1364 _exit(exitval); 1365 } 1366 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1367 1368 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1369 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1370 1371 validate_status_stopped(status, sigval); 1372 1373 DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n", 1374 trackfork ? "|PTRACE_FORK" : "", 1375 trackvfork ? "|PTRACE_VFORK" : "", 1376 trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child); 1377 event.pe_set_event = 0; 1378 if (trackfork) 1379 event.pe_set_event |= PTRACE_FORK; 1380 if (trackvfork) 1381 event.pe_set_event |= PTRACE_VFORK; 1382 if (trackvforkdone) 1383 event.pe_set_event |= PTRACE_VFORK_DONE; 1384 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 1385 1386 DPRINTF("Before resuming the child process where it left off and " 1387 "without signal to be sent\n"); 1388 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1389 1390#if defined(TWAIT_HAVE_PID) 1391 if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) { 1392 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, 1393 child); 1394 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 1395 child); 1396 1397 validate_status_stopped(status, SIGTRAP); 1398 1399 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, 1400 slen) != -1); 1401 if (trackfork && fn == fork) { 1402 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK, 1403 PTRACE_FORK); 1404 } 1405 if (trackvfork && fn == vfork) { 1406 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK, 1407 PTRACE_VFORK); 1408 } 1409 1410 child2 = state.pe_other_pid; 1411 DPRINTF("Reported ptrace event with forkee %d\n", child2); 1412 1413 DPRINTF("Before calling %s() for the forkee %d of the child " 1414 "%d\n", TWAIT_FNAME, child2, child); 1415 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 1416 child2); 1417 1418 validate_status_stopped(status, SIGTRAP); 1419 1420 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, 1421 slen) != -1); 1422 if (trackfork && fn == fork) { 1423 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK, 1424 PTRACE_FORK); 1425 } 1426 if (trackvfork && fn == vfork) { 1427 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK, 1428 PTRACE_VFORK); 1429 } 1430 1431 ATF_REQUIRE_EQ(state.pe_other_pid, child); 1432 1433 DPRINTF("Before resuming the forkee process where it left off " 1434 "and without signal to be sent\n"); 1435 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) 1436 != -1); 1437 1438 DPRINTF("Before resuming the child process where it left off " 1439 "and without signal to be sent\n"); 1440 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1441 } 1442#endif 1443 1444 if (trackvforkdone && fn == vfork) { 1445 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, 1446 child); 1447 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 1448 child); 1449 1450 validate_status_stopped(status, SIGTRAP); 1451 1452 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, 1453 slen) != -1); 1454 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); 1455 1456 child2 = state.pe_other_pid; 1457 DPRINTF("Reported PTRACE_VFORK_DONE event with forkee %d\n", 1458 child2); 1459 1460 DPRINTF("Before resuming the child process where it left off " 1461 "and without signal to be sent\n"); 1462 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1463 } 1464 1465#if defined(TWAIT_HAVE_PID) 1466 if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) { 1467 DPRINTF("Before calling %s() for the forkee - expected exited" 1468 "\n", TWAIT_FNAME); 1469 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 1470 child2); 1471 1472 validate_status_exited(status, exitval2); 1473 1474 DPRINTF("Before calling %s() for the forkee - expected no " 1475 "process\n", TWAIT_FNAME); 1476 TWAIT_REQUIRE_FAILURE(ECHILD, 1477 wpid = TWAIT_GENERIC(child2, &status, 0)); 1478 } 1479#endif 1480 1481 DPRINTF("Before calling %s() for the child - expected stopped " 1482 "SIGCHLD\n", TWAIT_FNAME); 1483 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1484 1485 validate_status_stopped(status, SIGCHLD); 1486 1487 DPRINTF("Before resuming the child process where it left off and " 1488 "without signal to be sent\n"); 1489 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1490 1491 DPRINTF("Before calling %s() for the child - expected exited\n", 1492 TWAIT_FNAME); 1493 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1494 1495 validate_status_exited(status, exitval); 1496 1497 DPRINTF("Before calling %s() for the child - expected no process\n", 1498 TWAIT_FNAME); 1499 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1500} 1501 1502#define FORK_TEST(name,descr,fun,tfork,tvfork,tvforkdone,detchild,detparent) \ 1503ATF_TC(name); \ 1504ATF_TC_HEAD(name, tc) \ 1505{ \ 1506 atf_tc_set_md_var(tc, "descr", descr); \ 1507} \ 1508 \ 1509ATF_TC_BODY(name, tc) \ 1510{ \ 1511 \ 1512 fork_body(fun, tfork, tvfork, tvforkdone, detchild, detparent); \ 1513} 1514 1515#define F false 1516#define T true 1517 1518#define F_IF__0(x) 1519#define F_IF__1(x) x 1520#define F_IF__(x,y) F_IF__ ## x (y) 1521#define F_IF_(x,y) F_IF__(x,y) 1522#define F_IF(x,y) F_IF_(x,y) 1523 1524#define DSCR(function,forkbit,vforkbit,vforkdonebit,dchildbit,dparentbit) \ 1525 "Verify " #function "(2) called with 0" \ 1526 F_IF(forkbit,"|PTRACE_FORK") \ 1527 F_IF(vforkbit,"|PTRACE_VFORK") \ 1528 F_IF(vforkdonebit,"|PTRACE_VFORK_DONE") \ 1529 " in EVENT_MASK." \ 1530 F_IF(dchildbit," Detach child in this test.") \ 1531 F_IF(dparentbit," Detach parent in this test.") 1532 1533FORK_TEST(fork1, DSCR(fork,0,0,0,0,0), fork, F, F, F, F, F) 1534#if defined(TWAIT_HAVE_PID) 1535FORK_TEST(fork2, DSCR(fork,1,0,0,0,0), fork, T, F, F, F, F) 1536FORK_TEST(fork3, DSCR(fork,0,1,0,0,0), fork, F, T, F, F, F) 1537FORK_TEST(fork4, DSCR(fork,1,1,0,0,0), fork, T, T, F, F, F) 1538#endif 1539FORK_TEST(fork5, DSCR(fork,0,0,1,0,0), fork, F, F, T, F, F) 1540#if defined(TWAIT_HAVE_PID) 1541FORK_TEST(fork6, DSCR(fork,1,0,1,0,0), fork, T, F, T, F, F) 1542FORK_TEST(fork7, DSCR(fork,0,1,1,0,0), fork, F, T, T, F, F) 1543FORK_TEST(fork8, DSCR(fork,1,1,1,0,0), fork, T, T, T, F, F) 1544#endif 1545 1546FORK_TEST(vfork1, DSCR(vfork,0,0,0,0,0), vfork, F, F, F, F, F) 1547#if defined(TWAIT_HAVE_PID) 1548FORK_TEST(vfork2, DSCR(vfork,1,0,0,0,0), vfork, T, F, F, F, F) 1549FORK_TEST(vfork3, DSCR(vfork,0,1,0,0,0), vfork, F, T, F, F, F) 1550FORK_TEST(vfork4, DSCR(vfork,1,1,0,0,0), vfork, T, T, F, F, F) 1551#endif 1552FORK_TEST(vfork5, DSCR(vfork,0,0,1,0,0), vfork, F, F, T, F, F) 1553#if defined(TWAIT_HAVE_PID) 1554FORK_TEST(vfork6, DSCR(vfork,1,0,1,0,0), vfork, T, F, T, F, F) 1555FORK_TEST(vfork7, DSCR(vfork,0,1,1,0,0), vfork, F, T, T, F, F) 1556FORK_TEST(vfork8, DSCR(vfork,1,1,1,0,0), vfork, T, T, T, F, F) 1557#endif 1558 1559 1560 1561 1562ATF_TC(io_read_d1); 1563ATF_TC_HEAD(io_read_d1, tc) 1564{ 1565 atf_tc_set_md_var(tc, "descr", 1566 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint8_t)"); 1567} 1568 1569ATF_TC_BODY(io_read_d1, tc) 1570{ 1571 const int exitval = 5; 1572 const int sigval = SIGSTOP; 1573 pid_t child, wpid; 1574 uint8_t lookup_me = 0; 1575 const uint8_t magic = 0xab; 1576 struct ptrace_io_desc io = { 1577 .piod_op = PIOD_READ_D, 1578 .piod_offs = &lookup_me, 1579 .piod_addr = &lookup_me, 1580 .piod_len = sizeof(lookup_me) 1581 }; 1582#if defined(TWAIT_HAVE_STATUS) 1583 int status; 1584#endif 1585 1586 DPRINTF("Before forking process PID=%d\n", getpid()); 1587 SYSCALL_REQUIRE((child = fork()) != -1); 1588 if (child == 0) { 1589 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1590 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1591 1592 lookup_me = magic; 1593 1594 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1595 FORKEE_ASSERT(raise(sigval) == 0); 1596 1597 DPRINTF("Before exiting of the child process\n"); 1598 _exit(exitval); 1599 } 1600 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1601 1602 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1603 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1604 1605 validate_status_stopped(status, sigval); 1606 1607 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 1608 child, getpid()); 1609 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1610 1611 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 1612 "got value %" PRIx8 " != expected %" PRIx8, lookup_me, magic); 1613 1614 DPRINTF("Before resuming the child process where it left off and " 1615 "without signal to be sent\n"); 1616 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1617 1618 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1619 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1620 1621 validate_status_exited(status, exitval); 1622 1623 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1624 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1625} 1626 1627ATF_TC(io_read_d2); 1628ATF_TC_HEAD(io_read_d2, tc) 1629{ 1630 atf_tc_set_md_var(tc, "descr", 1631 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint16_t)"); 1632} 1633 1634ATF_TC_BODY(io_read_d2, tc) 1635{ 1636 const int exitval = 5; 1637 const int sigval = SIGSTOP; 1638 pid_t child, wpid; 1639 uint16_t lookup_me = 0; 1640 const uint16_t magic = 0x1234; 1641 struct ptrace_io_desc io = { 1642 .piod_op = PIOD_READ_D, 1643 .piod_offs = &lookup_me, 1644 .piod_addr = &lookup_me, 1645 .piod_len = sizeof(lookup_me) 1646 }; 1647#if defined(TWAIT_HAVE_STATUS) 1648 int status; 1649#endif 1650 1651 DPRINTF("Before forking process PID=%d\n", getpid()); 1652 SYSCALL_REQUIRE((child = fork()) != -1); 1653 if (child == 0) { 1654 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1655 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1656 1657 lookup_me = magic; 1658 1659 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1660 FORKEE_ASSERT(raise(sigval) == 0); 1661 1662 DPRINTF("Before exiting of the child process\n"); 1663 _exit(exitval); 1664 } 1665 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1666 1667 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1668 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1669 1670 validate_status_stopped(status, sigval); 1671 1672 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 1673 child, getpid()); 1674 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1675 1676 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 1677 "got value %" PRIx16 " != expected %" PRIx16, lookup_me, magic); 1678 1679 DPRINTF("Before resuming the child process where it left off and " 1680 "without signal to be sent\n"); 1681 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1682 1683 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1684 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1685 1686 validate_status_exited(status, exitval); 1687 1688 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1689 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1690} 1691 1692ATF_TC(io_read_d3); 1693ATF_TC_HEAD(io_read_d3, tc) 1694{ 1695 atf_tc_set_md_var(tc, "descr", 1696 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint32_t)"); 1697} 1698 1699ATF_TC_BODY(io_read_d3, tc) 1700{ 1701 const int exitval = 5; 1702 const int sigval = SIGSTOP; 1703 pid_t child, wpid; 1704 uint32_t lookup_me = 0; 1705 const uint32_t magic = 0x1234abcd; 1706 struct ptrace_io_desc io = { 1707 .piod_op = PIOD_READ_D, 1708 .piod_offs = &lookup_me, 1709 .piod_addr = &lookup_me, 1710 .piod_len = sizeof(lookup_me) 1711 }; 1712#if defined(TWAIT_HAVE_STATUS) 1713 int status; 1714#endif 1715 1716 DPRINTF("Before forking process PID=%d\n", getpid()); 1717 SYSCALL_REQUIRE((child = fork()) != -1); 1718 if (child == 0) { 1719 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1720 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1721 1722 lookup_me = magic; 1723 1724 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1725 FORKEE_ASSERT(raise(sigval) == 0); 1726 1727 DPRINTF("Before exiting of the child process\n"); 1728 _exit(exitval); 1729 } 1730 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1731 1732 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1733 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1734 1735 validate_status_stopped(status, sigval); 1736 1737 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 1738 child, getpid()); 1739 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1740 1741 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 1742 "got value %" PRIx32 " != expected %" PRIx32, lookup_me, magic); 1743 1744 DPRINTF("Before resuming the child process where it left off and " 1745 "without signal to be sent\n"); 1746 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1747 1748 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1749 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1750 1751 validate_status_exited(status, exitval); 1752 1753 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1754 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1755} 1756 1757ATF_TC(io_read_d4); 1758ATF_TC_HEAD(io_read_d4, tc) 1759{ 1760 atf_tc_set_md_var(tc, "descr", 1761 "Verify PT_IO with PIOD_READ_D and len = sizeof(uint64_t)"); 1762} 1763 1764ATF_TC_BODY(io_read_d4, tc) 1765{ 1766 const int exitval = 5; 1767 const int sigval = SIGSTOP; 1768 pid_t child, wpid; 1769 uint64_t lookup_me = 0; 1770 const uint64_t magic = 0x1234abcd9876dcfa; 1771 struct ptrace_io_desc io = { 1772 .piod_op = PIOD_READ_D, 1773 .piod_offs = &lookup_me, 1774 .piod_addr = &lookup_me, 1775 .piod_len = sizeof(lookup_me) 1776 }; 1777#if defined(TWAIT_HAVE_STATUS) 1778 int status; 1779#endif 1780 1781 DPRINTF("Before forking process PID=%d\n", getpid()); 1782 SYSCALL_REQUIRE((child = fork()) != -1); 1783 if (child == 0) { 1784 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1785 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1786 1787 lookup_me = magic; 1788 1789 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1790 FORKEE_ASSERT(raise(sigval) == 0); 1791 1792 DPRINTF("Before exiting of the child process\n"); 1793 _exit(exitval); 1794 } 1795 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1796 1797 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1798 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1799 1800 validate_status_stopped(status, sigval); 1801 1802 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 1803 child, getpid()); 1804 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1805 1806 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 1807 "got value %" PRIx64 " != expected %" PRIx64, lookup_me, magic); 1808 1809 DPRINTF("Before resuming the child process where it left off and " 1810 "without signal to be sent\n"); 1811 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1812 1813 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1814 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1815 1816 validate_status_exited(status, exitval); 1817 1818 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1819 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1820} 1821 1822ATF_TC(io_write_d1); 1823ATF_TC_HEAD(io_write_d1, tc) 1824{ 1825 atf_tc_set_md_var(tc, "descr", 1826 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint8_t)"); 1827} 1828 1829ATF_TC_BODY(io_write_d1, tc) 1830{ 1831 const int exitval = 5; 1832 const int sigval = SIGSTOP; 1833 pid_t child, wpid; 1834 uint8_t lookup_me = 0; 1835 const uint8_t magic = 0xab; 1836 struct ptrace_io_desc io = { 1837 .piod_op = PIOD_WRITE_D, 1838 .piod_offs = &lookup_me, 1839 .piod_addr = &lookup_me, 1840 .piod_len = sizeof(lookup_me) 1841 }; 1842#if defined(TWAIT_HAVE_STATUS) 1843 int status; 1844#endif 1845 1846 DPRINTF("Before forking process PID=%d\n", getpid()); 1847 SYSCALL_REQUIRE((child = fork()) != -1); 1848 if (child == 0) { 1849 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1850 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1851 1852 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1853 FORKEE_ASSERT(raise(sigval) == 0); 1854 1855 FORKEE_ASSERT_EQ(lookup_me, magic); 1856 1857 DPRINTF("Before exiting of the child process\n"); 1858 _exit(exitval); 1859 } 1860 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1861 1862 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1863 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1864 1865 validate_status_stopped(status, sigval); 1866 1867 lookup_me = magic; 1868 1869 DPRINTF("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n", 1870 child, getpid()); 1871 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1872 1873 DPRINTF("Before resuming the child process where it left off and " 1874 "without signal to be sent\n"); 1875 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1876 1877 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1878 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1879 1880 validate_status_exited(status, exitval); 1881 1882 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1883 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1884} 1885 1886ATF_TC(io_write_d2); 1887ATF_TC_HEAD(io_write_d2, tc) 1888{ 1889 atf_tc_set_md_var(tc, "descr", 1890 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint16_t)"); 1891} 1892 1893ATF_TC_BODY(io_write_d2, tc) 1894{ 1895 const int exitval = 5; 1896 const int sigval = SIGSTOP; 1897 pid_t child, wpid; 1898 uint16_t lookup_me = 0; 1899 const uint16_t magic = 0xab12; 1900 struct ptrace_io_desc io = { 1901 .piod_op = PIOD_WRITE_D, 1902 .piod_offs = &lookup_me, 1903 .piod_addr = &lookup_me, 1904 .piod_len = sizeof(lookup_me) 1905 }; 1906#if defined(TWAIT_HAVE_STATUS) 1907 int status; 1908#endif 1909 1910 DPRINTF("Before forking process PID=%d\n", getpid()); 1911 SYSCALL_REQUIRE((child = fork()) != -1); 1912 if (child == 0) { 1913 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1914 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1915 1916 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1917 FORKEE_ASSERT(raise(sigval) == 0); 1918 1919 FORKEE_ASSERT_EQ(lookup_me, magic); 1920 1921 DPRINTF("Before exiting of the child process\n"); 1922 _exit(exitval); 1923 } 1924 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1925 1926 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1927 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1928 1929 validate_status_stopped(status, sigval); 1930 1931 lookup_me = magic; 1932 1933 DPRINTF("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n", 1934 child, getpid()); 1935 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 1936 1937 DPRINTF("Before resuming the child process where it left off and " 1938 "without signal to be sent\n"); 1939 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1940 1941 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1942 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1943 1944 validate_status_exited(status, exitval); 1945 1946 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1947 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1948} 1949 1950ATF_TC(io_write_d3); 1951ATF_TC_HEAD(io_write_d3, tc) 1952{ 1953 atf_tc_set_md_var(tc, "descr", 1954 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint32_t)"); 1955} 1956 1957ATF_TC_BODY(io_write_d3, tc) 1958{ 1959 const int exitval = 5; 1960 const int sigval = SIGSTOP; 1961 pid_t child, wpid; 1962 uint32_t lookup_me = 0; 1963 const uint32_t magic = 0xab127643; 1964 struct ptrace_io_desc io = { 1965 .piod_op = PIOD_WRITE_D, 1966 .piod_offs = &lookup_me, 1967 .piod_addr = &lookup_me, 1968 .piod_len = sizeof(lookup_me) 1969 }; 1970#if defined(TWAIT_HAVE_STATUS) 1971 int status; 1972#endif 1973 1974 DPRINTF("Before forking process PID=%d\n", getpid()); 1975 SYSCALL_REQUIRE((child = fork()) != -1); 1976 if (child == 0) { 1977 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1978 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1979 1980 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1981 FORKEE_ASSERT(raise(sigval) == 0); 1982 1983 FORKEE_ASSERT_EQ(lookup_me, magic); 1984 1985 DPRINTF("Before exiting of the child process\n"); 1986 _exit(exitval); 1987 } 1988 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1989 1990 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1991 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1992 1993 validate_status_stopped(status, sigval); 1994 1995 lookup_me = magic; 1996 1997 DPRINTF("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n", 1998 child, getpid()); 1999 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 2000 2001 DPRINTF("Before resuming the child process where it left off and " 2002 "without signal to be sent\n"); 2003 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2004 2005 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2006 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2007 2008 validate_status_exited(status, exitval); 2009 2010 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2011 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2012} 2013 2014ATF_TC(io_write_d4); 2015ATF_TC_HEAD(io_write_d4, tc) 2016{ 2017 atf_tc_set_md_var(tc, "descr", 2018 "Verify PT_IO with PIOD_WRITE_D and len = sizeof(uint64_t)"); 2019} 2020 2021ATF_TC_BODY(io_write_d4, tc) 2022{ 2023 const int exitval = 5; 2024 const int sigval = SIGSTOP; 2025 pid_t child, wpid; 2026 uint64_t lookup_me = 0; 2027 const uint64_t magic = 0xab12764376490123; 2028 struct ptrace_io_desc io = { 2029 .piod_op = PIOD_WRITE_D, 2030 .piod_offs = &lookup_me, 2031 .piod_addr = &lookup_me, 2032 .piod_len = sizeof(lookup_me) 2033 }; 2034#if defined(TWAIT_HAVE_STATUS) 2035 int status; 2036#endif 2037 2038 DPRINTF("Before forking process PID=%d\n", getpid()); 2039 SYSCALL_REQUIRE((child = fork()) != -1); 2040 if (child == 0) { 2041 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2042 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2043 2044 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2045 FORKEE_ASSERT(raise(sigval) == 0); 2046 2047 FORKEE_ASSERT_EQ(lookup_me, magic); 2048 2049 DPRINTF("Before exiting of the child process\n"); 2050 _exit(exitval); 2051 } 2052 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2053 2054 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2055 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2056 2057 validate_status_stopped(status, sigval); 2058 2059 lookup_me = magic; 2060 2061 DPRINTF("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n", 2062 child, getpid()); 2063 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 2064 2065 DPRINTF("Before resuming the child process where it left off and " 2066 "without signal to be sent\n"); 2067 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2068 2069 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2070 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2071 2072 validate_status_exited(status, exitval); 2073 2074 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2075 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2076} 2077 2078ATF_TC(io_read_auxv1); 2079ATF_TC_HEAD(io_read_auxv1, tc) 2080{ 2081 atf_tc_set_md_var(tc, "descr", 2082 "Verify PT_READ_AUXV called for tracee"); 2083} 2084 2085ATF_TC_BODY(io_read_auxv1, tc) 2086{ 2087 const int exitval = 5; 2088 const int sigval = SIGSTOP; 2089 pid_t child, wpid; 2090#if defined(TWAIT_HAVE_STATUS) 2091 int status; 2092#endif 2093 AuxInfo ai[100], *aip; 2094 struct ptrace_io_desc io = { 2095 .piod_op = PIOD_READ_AUXV, 2096 .piod_offs = 0, 2097 .piod_addr = ai, 2098 .piod_len = sizeof(ai) 2099 }; 2100 2101 DPRINTF("Before forking process PID=%d\n", getpid()); 2102 SYSCALL_REQUIRE((child = fork()) != -1); 2103 if (child == 0) { 2104 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2105 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2106 2107 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2108 FORKEE_ASSERT(raise(sigval) == 0); 2109 2110 DPRINTF("Before exiting of the child process\n"); 2111 _exit(exitval); 2112 } 2113 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2114 2115 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2116 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2117 2118 validate_status_stopped(status, sigval); 2119 2120 DPRINTF("Read new AUXV from tracee (PID=%d) by tracer (PID=%d)\n", 2121 child, getpid()); 2122 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 2123 2124 DPRINTF("Asserting that AUXV length (%zu) is > 0\n", io.piod_len); 2125 ATF_REQUIRE(io.piod_len > 0); 2126 2127 for (aip = ai; aip->a_type != AT_NULL; aip++) 2128 DPRINTF("a_type=%#llx a_v=%#llx\n", 2129 (long long int)aip->a_type, (long long int)aip->a_v); 2130 2131 DPRINTF("Before resuming the child process where it left off and " 2132 "without signal to be sent\n"); 2133 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2134 2135 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2136 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2137 2138 validate_status_exited(status, exitval); 2139 2140 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2141 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2142} 2143 2144ATF_TC(read_d1); 2145ATF_TC_HEAD(read_d1, tc) 2146{ 2147 atf_tc_set_md_var(tc, "descr", 2148 "Verify PT_READ_D called once"); 2149} 2150 2151ATF_TC_BODY(read_d1, tc) 2152{ 2153 const int exitval = 5; 2154 const int sigval = SIGSTOP; 2155 pid_t child, wpid; 2156 int lookup_me = 0; 2157 const int magic = (int)random(); 2158#if defined(TWAIT_HAVE_STATUS) 2159 int status; 2160#endif 2161 2162 DPRINTF("Before forking process PID=%d\n", getpid()); 2163 SYSCALL_REQUIRE((child = fork()) != -1); 2164 if (child == 0) { 2165 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2166 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2167 2168 lookup_me = magic; 2169 2170 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2171 FORKEE_ASSERT(raise(sigval) == 0); 2172 2173 DPRINTF("Before exiting of the child process\n"); 2174 _exit(exitval); 2175 } 2176 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2177 2178 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2179 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2180 2181 validate_status_stopped(status, sigval); 2182 2183 DPRINTF("Read new lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 2184 child, getpid()); 2185 errno = 0; 2186 lookup_me = ptrace(PT_READ_D, child, &lookup_me, 0); 2187 SYSCALL_REQUIRE_ERRNO(errno, 0); 2188 2189 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 2190 "got value %#x != expected %#x", lookup_me, magic); 2191 2192 DPRINTF("Before resuming the child process where it left off and " 2193 "without signal to be sent\n"); 2194 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2195 2196 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2197 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2198 2199 validate_status_exited(status, exitval); 2200 2201 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2202 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2203} 2204 2205ATF_TC(read_d2); 2206ATF_TC_HEAD(read_d2, tc) 2207{ 2208 atf_tc_set_md_var(tc, "descr", 2209 "Verify PT_READ_D called twice"); 2210} 2211 2212ATF_TC_BODY(read_d2, tc) 2213{ 2214 const int exitval = 5; 2215 const int sigval = SIGSTOP; 2216 pid_t child, wpid; 2217 int lookup_me1 = 0; 2218 int lookup_me2 = 0; 2219 const int magic1 = (int)random(); 2220 const int magic2 = (int)random(); 2221#if defined(TWAIT_HAVE_STATUS) 2222 int status; 2223#endif 2224 2225 DPRINTF("Before forking process PID=%d\n", getpid()); 2226 SYSCALL_REQUIRE((child = fork()) != -1); 2227 if (child == 0) { 2228 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2229 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2230 2231 lookup_me1 = magic1; 2232 lookup_me2 = magic2; 2233 2234 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2235 FORKEE_ASSERT(raise(sigval) == 0); 2236 2237 DPRINTF("Before exiting of the child process\n"); 2238 _exit(exitval); 2239 } 2240 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2241 2242 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2243 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2244 2245 validate_status_stopped(status, sigval); 2246 2247 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 2248 child, getpid()); 2249 errno = 0; 2250 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0); 2251 SYSCALL_REQUIRE_ERRNO(errno, 0); 2252 2253 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 2254 "got value %#x != expected %#x", lookup_me1, magic1); 2255 2256 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 2257 child, getpid()); 2258 errno = 0; 2259 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0); 2260 SYSCALL_REQUIRE_ERRNO(errno, 0); 2261 2262 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 2263 "got value %#x != expected %#x", lookup_me2, magic2); 2264 2265 DPRINTF("Before resuming the child process where it left off and " 2266 "without signal to be sent\n"); 2267 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2268 2269 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2270 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2271 2272 validate_status_exited(status, exitval); 2273 2274 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2275 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2276} 2277 2278ATF_TC(read_d3); 2279ATF_TC_HEAD(read_d3, tc) 2280{ 2281 atf_tc_set_md_var(tc, "descr", 2282 "Verify PT_READ_D called three times"); 2283} 2284 2285ATF_TC_BODY(read_d3, tc) 2286{ 2287 const int exitval = 5; 2288 const int sigval = SIGSTOP; 2289 pid_t child, wpid; 2290 int lookup_me1 = 0; 2291 int lookup_me2 = 0; 2292 int lookup_me3 = 0; 2293 const int magic1 = (int)random(); 2294 const int magic2 = (int)random(); 2295 const int magic3 = (int)random(); 2296#if defined(TWAIT_HAVE_STATUS) 2297 int status; 2298#endif 2299 2300 DPRINTF("Before forking process PID=%d\n", getpid()); 2301 SYSCALL_REQUIRE((child = fork()) != -1); 2302 if (child == 0) { 2303 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2304 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2305 2306 lookup_me1 = magic1; 2307 lookup_me2 = magic2; 2308 lookup_me3 = magic3; 2309 2310 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2311 FORKEE_ASSERT(raise(sigval) == 0); 2312 2313 DPRINTF("Before exiting of the child process\n"); 2314 _exit(exitval); 2315 } 2316 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2317 2318 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2319 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2320 2321 validate_status_stopped(status, sigval); 2322 2323 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 2324 child, getpid()); 2325 errno = 0; 2326 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0); 2327 SYSCALL_REQUIRE_ERRNO(errno, 0); 2328 2329 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 2330 "got value %#x != expected %#x", lookup_me1, magic1); 2331 2332 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 2333 child, getpid()); 2334 errno = 0; 2335 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0); 2336 SYSCALL_REQUIRE_ERRNO(errno, 0); 2337 2338 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 2339 "got value %#x != expected %#x", lookup_me2, magic2); 2340 2341 DPRINTF("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n", 2342 child, getpid()); 2343 errno = 0; 2344 lookup_me3 = ptrace(PT_READ_D, child, &lookup_me3, 0); 2345 SYSCALL_REQUIRE_ERRNO(errno, 0); 2346 2347 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3, 2348 "got value %#x != expected %#x", lookup_me3, magic3); 2349 2350 DPRINTF("Before resuming the child process where it left off and " 2351 "without signal to be sent\n"); 2352 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2353 2354 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2355 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2356 2357 validate_status_exited(status, exitval); 2358 2359 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2360 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2361} 2362 2363ATF_TC(read_d4); 2364ATF_TC_HEAD(read_d4, tc) 2365{ 2366 atf_tc_set_md_var(tc, "descr", 2367 "Verify PT_READ_D called four times"); 2368} 2369 2370ATF_TC_BODY(read_d4, tc) 2371{ 2372 const int exitval = 5; 2373 const int sigval = SIGSTOP; 2374 pid_t child, wpid; 2375 int lookup_me1 = 0; 2376 int lookup_me2 = 0; 2377 int lookup_me3 = 0; 2378 int lookup_me4 = 0; 2379 const int magic1 = (int)random(); 2380 const int magic2 = (int)random(); 2381 const int magic3 = (int)random(); 2382 const int magic4 = (int)random(); 2383#if defined(TWAIT_HAVE_STATUS) 2384 int status; 2385#endif 2386 2387 DPRINTF("Before forking process PID=%d\n", getpid()); 2388 SYSCALL_REQUIRE((child = fork()) != -1); 2389 if (child == 0) { 2390 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2391 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2392 2393 lookup_me1 = magic1; 2394 lookup_me2 = magic2; 2395 lookup_me3 = magic3; 2396 lookup_me4 = magic4; 2397 2398 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2399 FORKEE_ASSERT(raise(sigval) == 0); 2400 2401 DPRINTF("Before exiting of the child process\n"); 2402 _exit(exitval); 2403 } 2404 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2405 2406 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2407 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2408 2409 validate_status_stopped(status, sigval); 2410 2411 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 2412 child, getpid()); 2413 errno = 0; 2414 lookup_me1 = ptrace(PT_READ_D, child, &lookup_me1, 0); 2415 SYSCALL_REQUIRE_ERRNO(errno, 0); 2416 2417 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 2418 "got value %#x != expected %#x", lookup_me1, magic1); 2419 2420 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 2421 child, getpid()); 2422 errno = 0; 2423 lookup_me2 = ptrace(PT_READ_D, child, &lookup_me2, 0); 2424 SYSCALL_REQUIRE_ERRNO(errno, 0); 2425 2426 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 2427 "got value %#x != expected %#x", lookup_me2, magic2); 2428 2429 DPRINTF("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n", 2430 child, getpid()); 2431 errno = 0; 2432 lookup_me3 = ptrace(PT_READ_D, child, &lookup_me3, 0); 2433 SYSCALL_REQUIRE_ERRNO(errno, 0); 2434 2435 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3, 2436 "got value %#x != expected %#x", lookup_me3, magic3); 2437 2438 DPRINTF("Read new lookup_me4 from tracee (PID=%d) by tracer (PID=%d)\n", 2439 child, getpid()); 2440 errno = 0; 2441 lookup_me4 = ptrace(PT_READ_D, child, &lookup_me4, 0); 2442 SYSCALL_REQUIRE_ERRNO(errno, 0); 2443 2444 ATF_REQUIRE_EQ_MSG(lookup_me4, magic4, 2445 "got value %#x != expected %#x", lookup_me4, magic4); 2446 2447 DPRINTF("Before resuming the child process where it left off and " 2448 "without signal to be sent\n"); 2449 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2450 2451 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2452 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2453 2454 validate_status_exited(status, exitval); 2455 2456 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2457 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2458} 2459 2460ATF_TC(write_d1); 2461ATF_TC_HEAD(write_d1, tc) 2462{ 2463 atf_tc_set_md_var(tc, "descr", 2464 "Verify PT_WRITE_D called once"); 2465} 2466 2467ATF_TC_BODY(write_d1, tc) 2468{ 2469 const int exitval = 5; 2470 const int sigval = SIGSTOP; 2471 pid_t child, wpid; 2472 int lookup_me = 0; 2473 const int magic = (int)random(); 2474#if defined(TWAIT_HAVE_STATUS) 2475 int status; 2476#endif 2477 2478 DPRINTF("Before forking process PID=%d\n", getpid()); 2479 SYSCALL_REQUIRE((child = fork()) != -1); 2480 if (child == 0) { 2481 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2482 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2483 2484 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2485 FORKEE_ASSERT(raise(sigval) == 0); 2486 2487 FORKEE_ASSERT_EQ(lookup_me, magic); 2488 2489 DPRINTF("Before exiting of the child process\n"); 2490 _exit(exitval); 2491 } 2492 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2493 2494 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2495 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2496 2497 validate_status_stopped(status, sigval); 2498 2499 DPRINTF("Write new lookup_me to tracee (PID=%d) from tracer (PID=%d)\n", 2500 child, getpid()); 2501 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me, magic) != -1); 2502 2503 DPRINTF("Before resuming the child process where it left off and " 2504 "without signal to be sent\n"); 2505 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2506 2507 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2508 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2509 2510 validate_status_exited(status, exitval); 2511 2512 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2513 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2514} 2515 2516ATF_TC(write_d2); 2517ATF_TC_HEAD(write_d2, tc) 2518{ 2519 atf_tc_set_md_var(tc, "descr", 2520 "Verify PT_WRITE_D called twice"); 2521} 2522 2523ATF_TC_BODY(write_d2, tc) 2524{ 2525 const int exitval = 5; 2526 const int sigval = SIGSTOP; 2527 pid_t child, wpid; 2528 int lookup_me1 = 0; 2529 int lookup_me2 = 0; 2530 const int magic1 = (int)random(); 2531 const int magic2 = (int)random(); 2532#if defined(TWAIT_HAVE_STATUS) 2533 int status; 2534#endif 2535 2536 DPRINTF("Before forking process PID=%d\n", getpid()); 2537 SYSCALL_REQUIRE((child = fork()) != -1); 2538 if (child == 0) { 2539 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2540 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2541 2542 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2543 FORKEE_ASSERT(raise(sigval) == 0); 2544 2545 FORKEE_ASSERT_EQ(lookup_me1, magic1); 2546 FORKEE_ASSERT_EQ(lookup_me2, magic2); 2547 2548 DPRINTF("Before exiting of the child process\n"); 2549 _exit(exitval); 2550 } 2551 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2552 2553 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2554 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2555 2556 validate_status_stopped(status, sigval); 2557 2558 DPRINTF("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n", 2559 child, getpid()); 2560 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1); 2561 2562 DPRINTF("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n", 2563 child, getpid()); 2564 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1); 2565 2566 DPRINTF("Before resuming the child process where it left off and " 2567 "without signal to be sent\n"); 2568 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2569 2570 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2571 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2572 2573 validate_status_exited(status, exitval); 2574 2575 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2576 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2577} 2578 2579ATF_TC(write_d3); 2580ATF_TC_HEAD(write_d3, tc) 2581{ 2582 atf_tc_set_md_var(tc, "descr", 2583 "Verify PT_WRITE_D called three times"); 2584} 2585 2586ATF_TC_BODY(write_d3, tc) 2587{ 2588 const int exitval = 5; 2589 const int sigval = SIGSTOP; 2590 pid_t child, wpid; 2591 int lookup_me1 = 0; 2592 int lookup_me2 = 0; 2593 int lookup_me3 = 0; 2594 const int magic1 = (int)random(); 2595 const int magic2 = (int)random(); 2596 const int magic3 = (int)random(); 2597#if defined(TWAIT_HAVE_STATUS) 2598 int status; 2599#endif 2600 2601 DPRINTF("Before forking process PID=%d\n", getpid()); 2602 SYSCALL_REQUIRE((child = fork()) != -1); 2603 if (child == 0) { 2604 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2605 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2606 2607 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2608 FORKEE_ASSERT(raise(sigval) == 0); 2609 2610 FORKEE_ASSERT_EQ(lookup_me1, magic1); 2611 FORKEE_ASSERT_EQ(lookup_me2, magic2); 2612 FORKEE_ASSERT_EQ(lookup_me3, magic3); 2613 2614 DPRINTF("Before exiting of the child process\n"); 2615 _exit(exitval); 2616 } 2617 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2618 2619 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2620 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2621 2622 validate_status_stopped(status, sigval); 2623 2624 DPRINTF("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n", 2625 child, getpid()); 2626 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1); 2627 2628 DPRINTF("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n", 2629 child, getpid()); 2630 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1); 2631 2632 DPRINTF("Write new lookup_me3 to tracee (PID=%d) from tracer (PID=%d)\n", 2633 child, getpid()); 2634 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me3, magic3) != -1); 2635 2636 DPRINTF("Before resuming the child process where it left off and " 2637 "without signal to be sent\n"); 2638 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2639 2640 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2641 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2642 2643 validate_status_exited(status, exitval); 2644 2645 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2646 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2647} 2648 2649ATF_TC(write_d4); 2650ATF_TC_HEAD(write_d4, tc) 2651{ 2652 atf_tc_set_md_var(tc, "descr", 2653 "Verify PT_WRITE_D called four times"); 2654} 2655 2656ATF_TC_BODY(write_d4, tc) 2657{ 2658 const int exitval = 5; 2659 const int sigval = SIGSTOP; 2660 pid_t child, wpid; 2661 int lookup_me1 = 0; 2662 int lookup_me2 = 0; 2663 int lookup_me3 = 0; 2664 int lookup_me4 = 0; 2665 const int magic1 = (int)random(); 2666 const int magic2 = (int)random(); 2667 const int magic3 = (int)random(); 2668 const int magic4 = (int)random(); 2669#if defined(TWAIT_HAVE_STATUS) 2670 int status; 2671#endif 2672 2673 DPRINTF("Before forking process PID=%d\n", getpid()); 2674 SYSCALL_REQUIRE((child = fork()) != -1); 2675 if (child == 0) { 2676 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2677 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2678 2679 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2680 FORKEE_ASSERT(raise(sigval) == 0); 2681 2682 FORKEE_ASSERT_EQ(lookup_me1, magic1); 2683 FORKEE_ASSERT_EQ(lookup_me2, magic2); 2684 FORKEE_ASSERT_EQ(lookup_me3, magic3); 2685 FORKEE_ASSERT_EQ(lookup_me4, magic4); 2686 2687 DPRINTF("Before exiting of the child process\n"); 2688 _exit(exitval); 2689 } 2690 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2691 2692 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2693 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2694 2695 validate_status_stopped(status, sigval); 2696 2697 DPRINTF("Write new lookup_me1 to tracee (PID=%d) from tracer (PID=%d)\n", 2698 child, getpid()); 2699 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me1, magic1) != -1); 2700 2701 DPRINTF("Write new lookup_me2 to tracee (PID=%d) from tracer (PID=%d)\n", 2702 child, getpid()); 2703 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me2, magic2) != -1); 2704 2705 DPRINTF("Write new lookup_me3 to tracee (PID=%d) from tracer (PID=%d)\n", 2706 child, getpid()); 2707 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me3, magic3) != -1); 2708 2709 DPRINTF("Write new lookup_me4 to tracee (PID=%d) from tracer (PID=%d)\n", 2710 child, getpid()); 2711 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, &lookup_me4, magic4) != -1); 2712 2713 DPRINTF("Before resuming the child process where it left off and " 2714 "without signal to be sent\n"); 2715 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2716 2717 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2718 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2719 2720 validate_status_exited(status, exitval); 2721 2722 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2723 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2724} 2725 2726ATF_TC(io_read_d_write_d_handshake1); 2727ATF_TC_HEAD(io_read_d_write_d_handshake1, tc) 2728{ 2729 atf_tc_set_md_var(tc, "descr", 2730 "Verify PT_IO with PIOD_READ_D and PIOD_WRITE_D handshake"); 2731} 2732 2733ATF_TC_BODY(io_read_d_write_d_handshake1, tc) 2734{ 2735 const int exitval = 5; 2736 const int sigval = SIGSTOP; 2737 pid_t child, wpid; 2738 uint8_t lookup_me_fromtracee = 0; 2739 const uint8_t magic_fromtracee = (uint8_t)random(); 2740 uint8_t lookup_me_totracee = 0; 2741 const uint8_t magic_totracee = (uint8_t)random(); 2742 struct ptrace_io_desc io_fromtracee = { 2743 .piod_op = PIOD_READ_D, 2744 .piod_offs = &lookup_me_fromtracee, 2745 .piod_addr = &lookup_me_fromtracee, 2746 .piod_len = sizeof(lookup_me_fromtracee) 2747 }; 2748 struct ptrace_io_desc io_totracee = { 2749 .piod_op = PIOD_WRITE_D, 2750 .piod_offs = &lookup_me_totracee, 2751 .piod_addr = &lookup_me_totracee, 2752 .piod_len = sizeof(lookup_me_totracee) 2753 }; 2754#if defined(TWAIT_HAVE_STATUS) 2755 int status; 2756#endif 2757 2758 DPRINTF("Before forking process PID=%d\n", getpid()); 2759 SYSCALL_REQUIRE((child = fork()) != -1); 2760 if (child == 0) { 2761 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2762 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2763 2764 lookup_me_fromtracee = magic_fromtracee; 2765 2766 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2767 FORKEE_ASSERT(raise(sigval) == 0); 2768 2769 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee); 2770 2771 DPRINTF("Before exiting of the child process\n"); 2772 _exit(exitval); 2773 } 2774 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2775 2776 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2777 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2778 2779 validate_status_stopped(status, sigval); 2780 2781 DPRINTF("Read lookup_me_fromtracee PID=%d by tracer (PID=%d)\n", 2782 child, getpid()); 2783 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io_fromtracee, 0) != -1); 2784 2785 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee, 2786 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_fromtracee, 2787 magic_fromtracee); 2788 2789 lookup_me_totracee = magic_totracee; 2790 2791 DPRINTF("Write lookup_me_totracee to PID=%d by tracer (PID=%d)\n", 2792 child, getpid()); 2793 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io_totracee, 0) != -1); 2794 2795 ATF_REQUIRE_EQ_MSG(lookup_me_totracee, magic_totracee, 2796 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_totracee, 2797 magic_totracee); 2798 2799 DPRINTF("Before resuming the child process where it left off and " 2800 "without signal to be sent\n"); 2801 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2802 2803 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2804 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2805 2806 validate_status_exited(status, exitval); 2807 2808 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2809 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2810} 2811 2812ATF_TC(io_read_d_write_d_handshake2); 2813ATF_TC_HEAD(io_read_d_write_d_handshake2, tc) 2814{ 2815 atf_tc_set_md_var(tc, "descr", 2816 "Verify PT_IO with PIOD_WRITE_D and PIOD_READ_D handshake"); 2817} 2818 2819ATF_TC_BODY(io_read_d_write_d_handshake2, tc) 2820{ 2821 const int exitval = 5; 2822 const int sigval = SIGSTOP; 2823 pid_t child, wpid; 2824 uint8_t lookup_me_fromtracee = 0; 2825 const uint8_t magic_fromtracee = (uint8_t)random(); 2826 uint8_t lookup_me_totracee = 0; 2827 const uint8_t magic_totracee = (uint8_t)random(); 2828 struct ptrace_io_desc io_fromtracee = { 2829 .piod_op = PIOD_READ_D, 2830 .piod_offs = &lookup_me_fromtracee, 2831 .piod_addr = &lookup_me_fromtracee, 2832 .piod_len = sizeof(lookup_me_fromtracee) 2833 }; 2834 struct ptrace_io_desc io_totracee = { 2835 .piod_op = PIOD_WRITE_D, 2836 .piod_offs = &lookup_me_totracee, 2837 .piod_addr = &lookup_me_totracee, 2838 .piod_len = sizeof(lookup_me_totracee) 2839 }; 2840#if defined(TWAIT_HAVE_STATUS) 2841 int status; 2842#endif 2843 2844 DPRINTF("Before forking process PID=%d\n", getpid()); 2845 SYSCALL_REQUIRE((child = fork()) != -1); 2846 if (child == 0) { 2847 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2848 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2849 2850 lookup_me_fromtracee = magic_fromtracee; 2851 2852 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2853 FORKEE_ASSERT(raise(sigval) == 0); 2854 2855 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee); 2856 2857 DPRINTF("Before exiting of the child process\n"); 2858 _exit(exitval); 2859 } 2860 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2861 2862 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2863 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2864 2865 validate_status_stopped(status, sigval); 2866 2867 lookup_me_totracee = magic_totracee; 2868 2869 DPRINTF("Write lookup_me_totracee to PID=%d by tracer (PID=%d)\n", 2870 child, getpid()); 2871 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io_totracee, 0) != -1); 2872 2873 ATF_REQUIRE_EQ_MSG(lookup_me_totracee, magic_totracee, 2874 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_totracee, 2875 magic_totracee); 2876 2877 DPRINTF("Read lookup_me_fromtracee PID=%d by tracer (PID=%d)\n", 2878 child, getpid()); 2879 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io_fromtracee, 0) != -1); 2880 2881 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee, 2882 "got value %" PRIx8 " != expected %" PRIx8, lookup_me_fromtracee, 2883 magic_fromtracee); 2884 2885 DPRINTF("Before resuming the child process where it left off and " 2886 "without signal to be sent\n"); 2887 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2888 2889 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2890 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2891 2892 validate_status_exited(status, exitval); 2893 2894 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2895 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2896} 2897 2898ATF_TC(read_d_write_d_handshake1); 2899ATF_TC_HEAD(read_d_write_d_handshake1, tc) 2900{ 2901 atf_tc_set_md_var(tc, "descr", 2902 "Verify PT_READ_D with PT_WRITE_D handshake"); 2903} 2904 2905ATF_TC_BODY(read_d_write_d_handshake1, tc) 2906{ 2907 const int exitval = 5; 2908 const int sigval = SIGSTOP; 2909 pid_t child, wpid; 2910 int lookup_me_fromtracee = 0; 2911 const int magic_fromtracee = (int)random(); 2912 int lookup_me_totracee = 0; 2913 const int magic_totracee = (int)random(); 2914#if defined(TWAIT_HAVE_STATUS) 2915 int status; 2916#endif 2917 2918 DPRINTF("Before forking process PID=%d\n", getpid()); 2919 SYSCALL_REQUIRE((child = fork()) != -1); 2920 if (child == 0) { 2921 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2922 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2923 2924 lookup_me_fromtracee = magic_fromtracee; 2925 2926 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2927 FORKEE_ASSERT(raise(sigval) == 0); 2928 2929 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee); 2930 2931 DPRINTF("Before exiting of the child process\n"); 2932 _exit(exitval); 2933 } 2934 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2935 2936 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2937 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2938 2939 validate_status_stopped(status, sigval); 2940 2941 DPRINTF("Read new lookup_me_fromtracee PID=%d by tracer (PID=%d)\n", 2942 child, getpid()); 2943 errno = 0; 2944 lookup_me_fromtracee = 2945 ptrace(PT_READ_D, child, &lookup_me_fromtracee, 0); 2946 SYSCALL_REQUIRE_ERRNO(errno, 0); 2947 2948 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee, 2949 "got value %#x != expected %#x", lookup_me_fromtracee, 2950 magic_fromtracee); 2951 2952 DPRINTF("Write new lookup_me_totracee to PID=%d from tracer (PID=%d)\n", 2953 child, getpid()); 2954 ATF_REQUIRE 2955 (ptrace(PT_WRITE_D, child, &lookup_me_totracee, magic_totracee) 2956 != -1); 2957 2958 DPRINTF("Before resuming the child process where it left off and " 2959 "without signal to be sent\n"); 2960 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2961 2962 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2963 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2964 2965 validate_status_exited(status, exitval); 2966 2967 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2968 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2969} 2970 2971ATF_TC(read_d_write_d_handshake2); 2972ATF_TC_HEAD(read_d_write_d_handshake2, tc) 2973{ 2974 atf_tc_set_md_var(tc, "descr", 2975 "Verify PT_WRITE_D with PT_READ_D handshake"); 2976} 2977 2978ATF_TC_BODY(read_d_write_d_handshake2, tc) 2979{ 2980 const int exitval = 5; 2981 const int sigval = SIGSTOP; 2982 pid_t child, wpid; 2983 int lookup_me_fromtracee = 0; 2984 const int magic_fromtracee = (int)random(); 2985 int lookup_me_totracee = 0; 2986 const int magic_totracee = (int)random(); 2987#if defined(TWAIT_HAVE_STATUS) 2988 int status; 2989#endif 2990 2991 DPRINTF("Before forking process PID=%d\n", getpid()); 2992 SYSCALL_REQUIRE((child = fork()) != -1); 2993 if (child == 0) { 2994 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2995 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2996 2997 lookup_me_fromtracee = magic_fromtracee; 2998 2999 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3000 FORKEE_ASSERT(raise(sigval) == 0); 3001 3002 FORKEE_ASSERT_EQ(lookup_me_totracee, magic_totracee); 3003 3004 DPRINTF("Before exiting of the child process\n"); 3005 _exit(exitval); 3006 } 3007 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3008 3009 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3010 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3011 3012 validate_status_stopped(status, sigval); 3013 3014 DPRINTF("Write new lookup_me_totracee to PID=%d from tracer (PID=%d)\n", 3015 child, getpid()); 3016 ATF_REQUIRE 3017 (ptrace(PT_WRITE_D, child, &lookup_me_totracee, magic_totracee) 3018 != -1); 3019 3020 DPRINTF("Read new lookup_me_fromtracee PID=%d by tracer (PID=%d)\n", 3021 child, getpid()); 3022 errno = 0; 3023 lookup_me_fromtracee = 3024 ptrace(PT_READ_D, child, &lookup_me_fromtracee, 0); 3025 SYSCALL_REQUIRE_ERRNO(errno, 0); 3026 3027 ATF_REQUIRE_EQ_MSG(lookup_me_fromtracee, magic_fromtracee, 3028 "got value %#x != expected %#x", lookup_me_fromtracee, 3029 magic_fromtracee); 3030 3031 DPRINTF("Before resuming the child process where it left off and " 3032 "without signal to be sent\n"); 3033 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3034 3035 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3036 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3037 3038 validate_status_exited(status, exitval); 3039 3040 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3041 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3042} 3043 3044/* These dummy functions are used to be copied with ptrace(2) calls */ 3045static int __used 3046dummy_fn1(int a, int b, int c, int d) 3047{ 3048 3049 a *= 1; 3050 b += 2; 3051 c -= 3; 3052 d /= 4; 3053 3054 return a + b * c - d; 3055} 3056 3057static int __used 3058dummy_fn2(int a, int b, int c, int d) 3059{ 3060 3061 a *= 4; 3062 b += 3; 3063 c -= 2; 3064 d /= 1; 3065 3066 return a + b * c - d; 3067} 3068 3069static int __used 3070dummy_fn3(int a, int b, int c, int d) 3071{ 3072 3073 a *= 10; 3074 b += 20; 3075 c -= 30; 3076 d /= 40; 3077 3078 return a + b * c - d; 3079} 3080 3081static int __used 3082dummy_fn4(int a, int b, int c, int d) 3083{ 3084 3085 a *= 40; 3086 b += 30; 3087 c -= 20; 3088 d /= 10; 3089 3090 return a + b * c - d; 3091} 3092 3093ATF_TC(io_read_i1); 3094ATF_TC_HEAD(io_read_i1, tc) 3095{ 3096 atf_tc_set_md_var(tc, "descr", 3097 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint8_t)"); 3098} 3099 3100ATF_TC_BODY(io_read_i1, tc) 3101{ 3102 const int exitval = 5; 3103 const int sigval = SIGSTOP; 3104 pid_t child, wpid; 3105 uint8_t lookup_me = 0; 3106 uint8_t magic; 3107 memcpy(&magic, dummy_fn1, sizeof(magic)); 3108 struct ptrace_io_desc io = { 3109 .piod_op = PIOD_READ_I, 3110 .piod_offs = dummy_fn1, 3111 .piod_addr = &lookup_me, 3112 .piod_len = sizeof(lookup_me) 3113 }; 3114#if defined(TWAIT_HAVE_STATUS) 3115 int status; 3116#endif 3117 3118 DPRINTF("Before forking process PID=%d\n", getpid()); 3119 SYSCALL_REQUIRE((child = fork()) != -1); 3120 if (child == 0) { 3121 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3122 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3123 3124 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3125 FORKEE_ASSERT(raise(sigval) == 0); 3126 3127 DPRINTF("Before exiting of the child process\n"); 3128 _exit(exitval); 3129 } 3130 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3131 3132 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3133 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3134 3135 validate_status_stopped(status, sigval); 3136 3137 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 3138 child, getpid()); 3139 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 3140 3141 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 3142 "got value %" PRIx8 " != expected %" PRIx8, lookup_me, magic); 3143 3144 DPRINTF("Before resuming the child process where it left off and " 3145 "without signal to be sent\n"); 3146 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3147 3148 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3149 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3150 3151 validate_status_exited(status, exitval); 3152 3153 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3154 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3155} 3156 3157ATF_TC(io_read_i2); 3158ATF_TC_HEAD(io_read_i2, tc) 3159{ 3160 atf_tc_set_md_var(tc, "descr", 3161 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint16_t)"); 3162} 3163 3164ATF_TC_BODY(io_read_i2, tc) 3165{ 3166 const int exitval = 5; 3167 const int sigval = SIGSTOP; 3168 pid_t child, wpid; 3169 uint16_t lookup_me = 0; 3170 uint16_t magic; 3171 memcpy(&magic, dummy_fn1, sizeof(magic)); 3172 struct ptrace_io_desc io = { 3173 .piod_op = PIOD_READ_I, 3174 .piod_offs = dummy_fn1, 3175 .piod_addr = &lookup_me, 3176 .piod_len = sizeof(lookup_me) 3177 }; 3178#if defined(TWAIT_HAVE_STATUS) 3179 int status; 3180#endif 3181 3182 DPRINTF("Before forking process PID=%d\n", getpid()); 3183 SYSCALL_REQUIRE((child = fork()) != -1); 3184 if (child == 0) { 3185 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3186 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3187 3188 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3189 FORKEE_ASSERT(raise(sigval) == 0); 3190 3191 DPRINTF("Before exiting of the child process\n"); 3192 _exit(exitval); 3193 } 3194 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3195 3196 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3197 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3198 3199 validate_status_stopped(status, sigval); 3200 3201 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 3202 child, getpid()); 3203 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 3204 3205 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 3206 "got value %" PRIx16 " != expected %" PRIx16, lookup_me, magic); 3207 3208 DPRINTF("Before resuming the child process where it left off and " 3209 "without signal to be sent\n"); 3210 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3211 3212 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3213 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3214 3215 validate_status_exited(status, exitval); 3216 3217 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3218 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3219} 3220 3221ATF_TC(io_read_i3); 3222ATF_TC_HEAD(io_read_i3, tc) 3223{ 3224 atf_tc_set_md_var(tc, "descr", 3225 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint32_t)"); 3226} 3227 3228ATF_TC_BODY(io_read_i3, tc) 3229{ 3230 const int exitval = 5; 3231 const int sigval = SIGSTOP; 3232 pid_t child, wpid; 3233 uint32_t lookup_me = 0; 3234 uint32_t magic; 3235 memcpy(&magic, dummy_fn1, sizeof(magic)); 3236 struct ptrace_io_desc io = { 3237 .piod_op = PIOD_READ_I, 3238 .piod_offs = dummy_fn1, 3239 .piod_addr = &lookup_me, 3240 .piod_len = sizeof(lookup_me) 3241 }; 3242#if defined(TWAIT_HAVE_STATUS) 3243 int status; 3244#endif 3245 3246 DPRINTF("Before forking process PID=%d\n", getpid()); 3247 SYSCALL_REQUIRE((child = fork()) != -1); 3248 if (child == 0) { 3249 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3250 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3251 3252 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3253 FORKEE_ASSERT(raise(sigval) == 0); 3254 3255 DPRINTF("Before exiting of the child process\n"); 3256 _exit(exitval); 3257 } 3258 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3259 3260 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3261 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3262 3263 validate_status_stopped(status, sigval); 3264 3265 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 3266 child, getpid()); 3267 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 3268 3269 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 3270 "got value %" PRIx32 " != expected %" PRIx32, lookup_me, magic); 3271 3272 DPRINTF("Before resuming the child process where it left off and " 3273 "without signal to be sent\n"); 3274 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3275 3276 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3277 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3278 3279 validate_status_exited(status, exitval); 3280 3281 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3282 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3283} 3284 3285ATF_TC(io_read_i4); 3286ATF_TC_HEAD(io_read_i4, tc) 3287{ 3288 atf_tc_set_md_var(tc, "descr", 3289 "Verify PT_IO with PIOD_READ_I and len = sizeof(uint64_t)"); 3290} 3291 3292ATF_TC_BODY(io_read_i4, tc) 3293{ 3294 const int exitval = 5; 3295 const int sigval = SIGSTOP; 3296 pid_t child, wpid; 3297 uint64_t lookup_me = 0; 3298 uint64_t magic; 3299 memcpy(&magic, dummy_fn1, sizeof(magic)); 3300 struct ptrace_io_desc io = { 3301 .piod_op = PIOD_READ_I, 3302 .piod_offs = dummy_fn1, 3303 .piod_addr = &lookup_me, 3304 .piod_len = sizeof(lookup_me) 3305 }; 3306#if defined(TWAIT_HAVE_STATUS) 3307 int status; 3308#endif 3309 3310 DPRINTF("Before forking process PID=%d\n", getpid()); 3311 SYSCALL_REQUIRE((child = fork()) != -1); 3312 if (child == 0) { 3313 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3314 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3315 3316 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3317 FORKEE_ASSERT(raise(sigval) == 0); 3318 3319 DPRINTF("Before exiting of the child process\n"); 3320 _exit(exitval); 3321 } 3322 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3323 3324 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3325 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3326 3327 validate_status_stopped(status, sigval); 3328 3329 DPRINTF("Read lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 3330 child, getpid()); 3331 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 3332 3333 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 3334 "got value %" PRIx64 " != expected %" PRIx64, lookup_me, magic); 3335 3336 DPRINTF("Before resuming the child process where it left off and " 3337 "without signal to be sent\n"); 3338 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3339 3340 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3341 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3342 3343 validate_status_exited(status, exitval); 3344 3345 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3346 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3347} 3348 3349ATF_TC(read_i1); 3350ATF_TC_HEAD(read_i1, tc) 3351{ 3352 atf_tc_set_md_var(tc, "descr", 3353 "Verify PT_READ_I called once"); 3354} 3355 3356ATF_TC_BODY(read_i1, tc) 3357{ 3358 const int exitval = 5; 3359 const int sigval = SIGSTOP; 3360 pid_t child, wpid; 3361 int lookup_me = 0; 3362 int magic; 3363 memcpy(&magic, dummy_fn1, sizeof(magic)); 3364#if defined(TWAIT_HAVE_STATUS) 3365 int status; 3366#endif 3367 3368 DPRINTF("Before forking process PID=%d\n", getpid()); 3369 SYSCALL_REQUIRE((child = fork()) != -1); 3370 if (child == 0) { 3371 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3372 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3373 3374 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3375 FORKEE_ASSERT(raise(sigval) == 0); 3376 3377 DPRINTF("Before exiting of the child process\n"); 3378 _exit(exitval); 3379 } 3380 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3381 3382 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3383 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3384 3385 validate_status_stopped(status, sigval); 3386 3387 DPRINTF("Read new lookup_me from tracee (PID=%d) by tracer (PID=%d)\n", 3388 child, getpid()); 3389 errno = 0; 3390 lookup_me = ptrace(PT_READ_I, child, dummy_fn1, 0); 3391 SYSCALL_REQUIRE_ERRNO(errno, 0); 3392 3393 ATF_REQUIRE_EQ_MSG(lookup_me, magic, 3394 "got value %#x != expected %#x", lookup_me, magic); 3395 3396 DPRINTF("Before resuming the child process where it left off and " 3397 "without signal to be sent\n"); 3398 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3399 3400 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3401 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3402 3403 validate_status_exited(status, exitval); 3404 3405 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3406 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3407} 3408 3409ATF_TC(read_i2); 3410ATF_TC_HEAD(read_i2, tc) 3411{ 3412 atf_tc_set_md_var(tc, "descr", 3413 "Verify PT_READ_I called twice"); 3414} 3415 3416ATF_TC_BODY(read_i2, tc) 3417{ 3418 const int exitval = 5; 3419 const int sigval = SIGSTOP; 3420 pid_t child, wpid; 3421 int lookup_me1 = 0; 3422 int lookup_me2 = 0; 3423 int magic1; 3424 int magic2; 3425 memcpy(&magic1, dummy_fn1, sizeof(magic1)); 3426 memcpy(&magic2, dummy_fn2, sizeof(magic2)); 3427#if defined(TWAIT_HAVE_STATUS) 3428 int status; 3429#endif 3430 3431 DPRINTF("Before forking process PID=%d\n", getpid()); 3432 SYSCALL_REQUIRE((child = fork()) != -1); 3433 if (child == 0) { 3434 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3435 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3436 3437 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3438 FORKEE_ASSERT(raise(sigval) == 0); 3439 3440 DPRINTF("Before exiting of the child process\n"); 3441 _exit(exitval); 3442 } 3443 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3444 3445 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3446 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3447 3448 validate_status_stopped(status, sigval); 3449 3450 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 3451 child, getpid()); 3452 errno = 0; 3453 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0); 3454 SYSCALL_REQUIRE_ERRNO(errno, 0); 3455 3456 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 3457 "got value %#x != expected %#x", lookup_me1, magic1); 3458 3459 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 3460 child, getpid()); 3461 errno = 0; 3462 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0); 3463 SYSCALL_REQUIRE_ERRNO(errno, 0); 3464 3465 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 3466 "got value %#x != expected %#x", lookup_me2, magic2); 3467 3468 DPRINTF("Before resuming the child process where it left off and " 3469 "without signal to be sent\n"); 3470 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3471 3472 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3473 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3474 3475 validate_status_exited(status, exitval); 3476 3477 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3478 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3479} 3480 3481ATF_TC(read_i3); 3482ATF_TC_HEAD(read_i3, tc) 3483{ 3484 atf_tc_set_md_var(tc, "descr", 3485 "Verify PT_READ_I called three times"); 3486} 3487 3488ATF_TC_BODY(read_i3, tc) 3489{ 3490 const int exitval = 5; 3491 const int sigval = SIGSTOP; 3492 pid_t child, wpid; 3493 int lookup_me1 = 0; 3494 int lookup_me2 = 0; 3495 int lookup_me3 = 0; 3496 int magic1; 3497 int magic2; 3498 int magic3; 3499 memcpy(&magic1, dummy_fn1, sizeof(magic1)); 3500 memcpy(&magic2, dummy_fn2, sizeof(magic2)); 3501 memcpy(&magic3, dummy_fn3, sizeof(magic3)); 3502#if defined(TWAIT_HAVE_STATUS) 3503 int status; 3504#endif 3505 3506 DPRINTF("Before forking process PID=%d\n", getpid()); 3507 SYSCALL_REQUIRE((child = fork()) != -1); 3508 if (child == 0) { 3509 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3510 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3511 3512 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3513 FORKEE_ASSERT(raise(sigval) == 0); 3514 3515 DPRINTF("Before exiting of the child process\n"); 3516 _exit(exitval); 3517 } 3518 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3519 3520 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3521 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3522 3523 validate_status_stopped(status, sigval); 3524 3525 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 3526 child, getpid()); 3527 errno = 0; 3528 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0); 3529 SYSCALL_REQUIRE_ERRNO(errno, 0); 3530 3531 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 3532 "got value %#x != expected %#x", lookup_me1, magic1); 3533 3534 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 3535 child, getpid()); 3536 errno = 0; 3537 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0); 3538 SYSCALL_REQUIRE_ERRNO(errno, 0); 3539 3540 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 3541 "got value %#x != expected %#x", lookup_me2, magic2); 3542 3543 DPRINTF("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n", 3544 child, getpid()); 3545 errno = 0; 3546 lookup_me3 = ptrace(PT_READ_I, child, dummy_fn3, 0); 3547 SYSCALL_REQUIRE_ERRNO(errno, 0); 3548 3549 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3, 3550 "got value %#x != expected %#x", lookup_me3, magic3); 3551 3552 DPRINTF("Before resuming the child process where it left off and " 3553 "without signal to be sent\n"); 3554 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3555 3556 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3557 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3558 3559 validate_status_exited(status, exitval); 3560 3561 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3562 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3563} 3564 3565ATF_TC(read_i4); 3566ATF_TC_HEAD(read_i4, tc) 3567{ 3568 atf_tc_set_md_var(tc, "descr", 3569 "Verify PT_READ_I called four times"); 3570} 3571 3572ATF_TC_BODY(read_i4, tc) 3573{ 3574 const int exitval = 5; 3575 const int sigval = SIGSTOP; 3576 pid_t child, wpid; 3577 int lookup_me1 = 0; 3578 int lookup_me2 = 0; 3579 int lookup_me3 = 0; 3580 int lookup_me4 = 0; 3581 int magic1; 3582 int magic2; 3583 int magic3; 3584 int magic4; 3585 memcpy(&magic1, dummy_fn1, sizeof(magic1)); 3586 memcpy(&magic2, dummy_fn2, sizeof(magic2)); 3587 memcpy(&magic3, dummy_fn3, sizeof(magic3)); 3588 memcpy(&magic4, dummy_fn4, sizeof(magic4)); 3589#if defined(TWAIT_HAVE_STATUS) 3590 int status; 3591#endif 3592 3593 DPRINTF("Before forking process PID=%d\n", getpid()); 3594 SYSCALL_REQUIRE((child = fork()) != -1); 3595 if (child == 0) { 3596 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3597 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3598 3599 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3600 FORKEE_ASSERT(raise(sigval) == 0); 3601 3602 DPRINTF("Before exiting of the child process\n"); 3603 _exit(exitval); 3604 } 3605 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3606 3607 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3608 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3609 3610 validate_status_stopped(status, sigval); 3611 3612 DPRINTF("Read new lookup_me1 from tracee (PID=%d) by tracer (PID=%d)\n", 3613 child, getpid()); 3614 errno = 0; 3615 lookup_me1 = ptrace(PT_READ_I, child, dummy_fn1, 0); 3616 SYSCALL_REQUIRE_ERRNO(errno, 0); 3617 3618 ATF_REQUIRE_EQ_MSG(lookup_me1, magic1, 3619 "got value %#x != expected %#x", lookup_me1, magic1); 3620 3621 DPRINTF("Read new lookup_me2 from tracee (PID=%d) by tracer (PID=%d)\n", 3622 child, getpid()); 3623 errno = 0; 3624 lookup_me2 = ptrace(PT_READ_I, child, dummy_fn2, 0); 3625 SYSCALL_REQUIRE_ERRNO(errno, 0); 3626 3627 ATF_REQUIRE_EQ_MSG(lookup_me2, magic2, 3628 "got value %#x != expected %#x", lookup_me2, magic2); 3629 3630 DPRINTF("Read new lookup_me3 from tracee (PID=%d) by tracer (PID=%d)\n", 3631 child, getpid()); 3632 errno = 0; 3633 lookup_me3 = ptrace(PT_READ_I, child, dummy_fn3, 0); 3634 SYSCALL_REQUIRE_ERRNO(errno, 0); 3635 3636 ATF_REQUIRE_EQ_MSG(lookup_me3, magic3, 3637 "got value %#x != expected %#x", lookup_me3, magic3); 3638 3639 DPRINTF("Read new lookup_me4 from tracee (PID=%d) by tracer (PID=%d)\n", 3640 child, getpid()); 3641 errno = 0; 3642 lookup_me4 = ptrace(PT_READ_I, child, dummy_fn4, 0); 3643 SYSCALL_REQUIRE_ERRNO(errno, 0); 3644 3645 ATF_REQUIRE_EQ_MSG(lookup_me4, magic4, 3646 "got value %#x != expected %#x", lookup_me4, magic4); 3647 3648 DPRINTF("Before resuming the child process where it left off and " 3649 "without signal to be sent\n"); 3650 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3651 3652 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3653 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3654 3655 validate_status_exited(status, exitval); 3656 3657 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3658 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3659} 3660 3661#if defined(HAVE_GPREGS) 3662ATF_TC(regs1); 3663ATF_TC_HEAD(regs1, tc) 3664{ 3665 atf_tc_set_md_var(tc, "descr", 3666 "Verify plain PT_GETREGS call without further steps"); 3667} 3668 3669ATF_TC_BODY(regs1, tc) 3670{ 3671 const int exitval = 5; 3672 const int sigval = SIGSTOP; 3673 pid_t child, wpid; 3674#if defined(TWAIT_HAVE_STATUS) 3675 int status; 3676#endif 3677 struct reg r; 3678 3679 DPRINTF("Before forking process PID=%d\n", getpid()); 3680 SYSCALL_REQUIRE((child = fork()) != -1); 3681 if (child == 0) { 3682 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3683 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3684 3685 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3686 FORKEE_ASSERT(raise(sigval) == 0); 3687 3688 DPRINTF("Before exiting of the child process\n"); 3689 _exit(exitval); 3690 } 3691 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3692 3693 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3694 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3695 3696 validate_status_stopped(status, sigval); 3697 3698 DPRINTF("Call GETREGS for the child process\n"); 3699 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3700 3701 DPRINTF("Before resuming the child process where it left off and " 3702 "without signal to be sent\n"); 3703 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3704 3705 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3706 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3707 3708 validate_status_exited(status, exitval); 3709 3710 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3711 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3712} 3713#endif 3714 3715#if defined(HAVE_GPREGS) 3716ATF_TC(regs2); 3717ATF_TC_HEAD(regs2, tc) 3718{ 3719 atf_tc_set_md_var(tc, "descr", 3720 "Verify plain PT_GETREGS call and retrieve PC"); 3721} 3722 3723ATF_TC_BODY(regs2, tc) 3724{ 3725 const int exitval = 5; 3726 const int sigval = SIGSTOP; 3727 pid_t child, wpid; 3728#if defined(TWAIT_HAVE_STATUS) 3729 int status; 3730#endif 3731 struct reg r; 3732 3733 DPRINTF("Before forking process PID=%d\n", getpid()); 3734 SYSCALL_REQUIRE((child = fork()) != -1); 3735 if (child == 0) { 3736 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3737 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3738 3739 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3740 FORKEE_ASSERT(raise(sigval) == 0); 3741 3742 DPRINTF("Before exiting of the child process\n"); 3743 _exit(exitval); 3744 } 3745 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3746 3747 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3748 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3749 3750 validate_status_stopped(status, sigval); 3751 3752 DPRINTF("Call GETREGS for the child process\n"); 3753 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3754 3755 DPRINTF("Retrieved PC=%" PRIxREGISTER "\n", PTRACE_REG_PC(&r)); 3756 3757 DPRINTF("Before resuming the child process where it left off and " 3758 "without signal to be sent\n"); 3759 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3760 3761 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3762 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3763 3764 validate_status_exited(status, exitval); 3765 3766 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3767 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3768} 3769#endif 3770 3771#if defined(HAVE_GPREGS) 3772ATF_TC(regs3); 3773ATF_TC_HEAD(regs3, tc) 3774{ 3775 atf_tc_set_md_var(tc, "descr", 3776 "Verify plain PT_GETREGS call and retrieve SP"); 3777} 3778 3779ATF_TC_BODY(regs3, tc) 3780{ 3781 const int exitval = 5; 3782 const int sigval = SIGSTOP; 3783 pid_t child, wpid; 3784#if defined(TWAIT_HAVE_STATUS) 3785 int status; 3786#endif 3787 struct reg r; 3788 3789 DPRINTF("Before forking process PID=%d\n", getpid()); 3790 SYSCALL_REQUIRE((child = fork()) != -1); 3791 if (child == 0) { 3792 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3793 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3794 3795 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3796 FORKEE_ASSERT(raise(sigval) == 0); 3797 3798 DPRINTF("Before exiting of the child process\n"); 3799 _exit(exitval); 3800 } 3801 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3802 3803 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3804 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3805 3806 validate_status_stopped(status, sigval); 3807 3808 DPRINTF("Call GETREGS for the child process\n"); 3809 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3810 3811 DPRINTF("Retrieved SP=%" PRIxREGISTER "\n", PTRACE_REG_SP(&r)); 3812 3813 DPRINTF("Before resuming the child process where it left off and " 3814 "without signal to be sent\n"); 3815 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3816 3817 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3818 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3819 3820 validate_status_exited(status, exitval); 3821 3822 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3823 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3824} 3825#endif 3826 3827#if defined(HAVE_GPREGS) 3828ATF_TC(regs4); 3829ATF_TC_HEAD(regs4, tc) 3830{ 3831 atf_tc_set_md_var(tc, "descr", 3832 "Verify plain PT_GETREGS call and retrieve INTRV"); 3833} 3834 3835ATF_TC_BODY(regs4, tc) 3836{ 3837 const int exitval = 5; 3838 const int sigval = SIGSTOP; 3839 pid_t child, wpid; 3840#if defined(TWAIT_HAVE_STATUS) 3841 int status; 3842#endif 3843 struct reg r; 3844 3845 DPRINTF("Before forking process PID=%d\n", getpid()); 3846 SYSCALL_REQUIRE((child = fork()) != -1); 3847 if (child == 0) { 3848 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3849 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3850 3851 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3852 FORKEE_ASSERT(raise(sigval) == 0); 3853 3854 DPRINTF("Before exiting of the child process\n"); 3855 _exit(exitval); 3856 } 3857 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3858 3859 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3860 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3861 3862 validate_status_stopped(status, sigval); 3863 3864 DPRINTF("Call GETREGS for the child process\n"); 3865 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3866 3867 DPRINTF("Retrieved INTRV=%" PRIxREGISTER "\n", PTRACE_REG_INTRV(&r)); 3868 3869 DPRINTF("Before resuming the child process where it left off and " 3870 "without signal to be sent\n"); 3871 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3872 3873 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3874 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3875 3876 validate_status_exited(status, exitval); 3877 3878 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3879 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3880} 3881#endif 3882 3883#if defined(HAVE_GPREGS) 3884ATF_TC(regs5); 3885ATF_TC_HEAD(regs5, tc) 3886{ 3887 atf_tc_set_md_var(tc, "descr", 3888 "Verify PT_GETREGS and PT_SETREGS calls without changing regs"); 3889} 3890 3891ATF_TC_BODY(regs5, tc) 3892{ 3893 const int exitval = 5; 3894 const int sigval = SIGSTOP; 3895 pid_t child, wpid; 3896#if defined(TWAIT_HAVE_STATUS) 3897 int status; 3898#endif 3899 struct reg r; 3900 3901 DPRINTF("Before forking process PID=%d\n", getpid()); 3902 SYSCALL_REQUIRE((child = fork()) != -1); 3903 if (child == 0) { 3904 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3905 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3906 3907 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3908 FORKEE_ASSERT(raise(sigval) == 0); 3909 3910 DPRINTF("Before exiting of the child process\n"); 3911 _exit(exitval); 3912 } 3913 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3914 3915 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3916 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3917 3918 validate_status_stopped(status, sigval); 3919 3920 DPRINTF("Call GETREGS for the child process\n"); 3921 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3922 3923 DPRINTF("Call SETREGS for the child process (without changed regs)\n"); 3924 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 3925 3926 DPRINTF("Before resuming the child process where it left off and " 3927 "without signal to be sent\n"); 3928 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3929 3930 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3931 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3932 3933 validate_status_exited(status, exitval); 3934 3935 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3936 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3937} 3938#endif 3939 3940#if defined(HAVE_FPREGS) 3941ATF_TC(fpregs1); 3942ATF_TC_HEAD(fpregs1, tc) 3943{ 3944 atf_tc_set_md_var(tc, "descr", 3945 "Verify plain PT_GETFPREGS call without further steps"); 3946} 3947 3948ATF_TC_BODY(fpregs1, tc) 3949{ 3950 const int exitval = 5; 3951 const int sigval = SIGSTOP; 3952 pid_t child, wpid; 3953#if defined(TWAIT_HAVE_STATUS) 3954 int status; 3955#endif 3956 struct fpreg r; 3957 3958 DPRINTF("Before forking process PID=%d\n", getpid()); 3959 SYSCALL_REQUIRE((child = fork()) != -1); 3960 if (child == 0) { 3961 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3962 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3963 3964 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3965 FORKEE_ASSERT(raise(sigval) == 0); 3966 3967 DPRINTF("Before exiting of the child process\n"); 3968 _exit(exitval); 3969 } 3970 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3971 3972 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3973 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3974 3975 validate_status_stopped(status, sigval); 3976 3977 DPRINTF("Call GETFPREGS for the child process\n"); 3978 SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1); 3979 3980 DPRINTF("Before resuming the child process where it left off and " 3981 "without signal to be sent\n"); 3982 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3983 3984 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3985 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3986 3987 validate_status_exited(status, exitval); 3988 3989 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3990 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3991} 3992#endif 3993 3994#if defined(HAVE_FPREGS) 3995ATF_TC(fpregs2); 3996ATF_TC_HEAD(fpregs2, tc) 3997{ 3998 atf_tc_set_md_var(tc, "descr", 3999 "Verify PT_GETFPREGS and PT_SETFPREGS calls without changing " 4000 "regs"); 4001} 4002 4003ATF_TC_BODY(fpregs2, tc) 4004{ 4005 const int exitval = 5; 4006 const int sigval = SIGSTOP; 4007 pid_t child, wpid; 4008#if defined(TWAIT_HAVE_STATUS) 4009 int status; 4010#endif 4011 struct fpreg r; 4012 4013 DPRINTF("Before forking process PID=%d\n", getpid()); 4014 SYSCALL_REQUIRE((child = fork()) != -1); 4015 if (child == 0) { 4016 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4017 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4018 4019 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4020 FORKEE_ASSERT(raise(sigval) == 0); 4021 4022 DPRINTF("Before exiting of the child process\n"); 4023 _exit(exitval); 4024 } 4025 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4026 4027 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4028 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4029 4030 validate_status_stopped(status, sigval); 4031 4032 DPRINTF("Call GETFPREGS for the child process\n"); 4033 SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1); 4034 4035 DPRINTF("Call SETFPREGS for the child (without changed regs)\n"); 4036 SYSCALL_REQUIRE(ptrace(PT_SETFPREGS, child, &r, 0) != -1); 4037 4038 DPRINTF("Before resuming the child process where it left off and " 4039 "without signal to be sent\n"); 4040 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4041 4042 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4043 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4044 4045 validate_status_exited(status, exitval); 4046 4047 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4048 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4049} 4050#endif 4051 4052#if defined(PT_STEP) 4053static void 4054ptrace_step(int N, int setstep) 4055{ 4056 const int exitval = 5; 4057 const int sigval = SIGSTOP; 4058 pid_t child, wpid; 4059#if defined(TWAIT_HAVE_STATUS) 4060 int status; 4061#endif 4062 int happy; 4063 4064#if defined(__arm__) 4065 /* PT_STEP not supported on arm 32-bit */ 4066 atf_tc_expect_fail("PR kern/52119"); 4067#endif 4068 4069 DPRINTF("Before forking process PID=%d\n", getpid()); 4070 SYSCALL_REQUIRE((child = fork()) != -1); 4071 if (child == 0) { 4072 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4073 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4074 4075 happy = check_happy(999); 4076 4077 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4078 FORKEE_ASSERT(raise(sigval) == 0); 4079 4080 FORKEE_ASSERT_EQ(happy, check_happy(999)); 4081 4082 DPRINTF("Before exiting of the child process\n"); 4083 _exit(exitval); 4084 } 4085 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4086 4087 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4088 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4089 4090 validate_status_stopped(status, sigval); 4091 4092 while (N --> 0) { 4093 if (setstep) { 4094 DPRINTF("Before resuming the child process where it " 4095 "left off and without signal to be sent (use " 4096 "PT_SETSTEP and PT_CONTINUE)\n"); 4097 SYSCALL_REQUIRE(ptrace(PT_SETSTEP, child, 0, 0) != -1); 4098 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) 4099 != -1); 4100 } else { 4101 DPRINTF("Before resuming the child process where it " 4102 "left off and without signal to be sent (use " 4103 "PT_STEP)\n"); 4104 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) 4105 != -1); 4106 } 4107 4108 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4109 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 4110 child); 4111 4112 validate_status_stopped(status, SIGTRAP); 4113 4114 if (setstep) { 4115 SYSCALL_REQUIRE(ptrace(PT_CLEARSTEP, child, 0, 0) != -1); 4116 } 4117 } 4118 4119 DPRINTF("Before resuming the child process where it left off and " 4120 "without signal to be sent\n"); 4121 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4122 4123 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4124 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4125 4126 validate_status_exited(status, exitval); 4127 4128 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4129 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4130} 4131#endif 4132 4133#if defined(PT_STEP) 4134ATF_TC(step1); 4135ATF_TC_HEAD(step1, tc) 4136{ 4137 atf_tc_set_md_var(tc, "descr", 4138 "Verify single PT_STEP call"); 4139} 4140 4141ATF_TC_BODY(step1, tc) 4142{ 4143 ptrace_step(1, 0); 4144} 4145#endif 4146 4147#if defined(PT_STEP) 4148ATF_TC(step2); 4149ATF_TC_HEAD(step2, tc) 4150{ 4151 atf_tc_set_md_var(tc, "descr", 4152 "Verify PT_STEP called twice"); 4153} 4154 4155ATF_TC_BODY(step2, tc) 4156{ 4157 ptrace_step(2, 0); 4158} 4159#endif 4160 4161#if defined(PT_STEP) 4162ATF_TC(step3); 4163ATF_TC_HEAD(step3, tc) 4164{ 4165 atf_tc_set_md_var(tc, "descr", 4166 "Verify PT_STEP called three times"); 4167} 4168 4169ATF_TC_BODY(step3, tc) 4170{ 4171 ptrace_step(3, 0); 4172} 4173#endif 4174 4175#if defined(PT_STEP) 4176ATF_TC(step4); 4177ATF_TC_HEAD(step4, tc) 4178{ 4179 atf_tc_set_md_var(tc, "descr", 4180 "Verify PT_STEP called four times"); 4181} 4182 4183ATF_TC_BODY(step4, tc) 4184{ 4185 ptrace_step(4, 0); 4186} 4187#endif 4188 4189#if defined(PT_STEP) 4190ATF_TC(setstep1); 4191ATF_TC_HEAD(setstep1, tc) 4192{ 4193 atf_tc_set_md_var(tc, "descr", 4194 "Verify single PT_SETSTEP call"); 4195} 4196 4197ATF_TC_BODY(setstep1, tc) 4198{ 4199 ptrace_step(1, 1); 4200} 4201#endif 4202 4203#if defined(PT_STEP) 4204ATF_TC(setstep2); 4205ATF_TC_HEAD(setstep2, tc) 4206{ 4207 atf_tc_set_md_var(tc, "descr", 4208 "Verify PT_SETSTEP called twice"); 4209} 4210 4211ATF_TC_BODY(setstep2, tc) 4212{ 4213 ptrace_step(2, 1); 4214} 4215#endif 4216 4217#if defined(PT_STEP) 4218ATF_TC(setstep3); 4219ATF_TC_HEAD(setstep3, tc) 4220{ 4221 atf_tc_set_md_var(tc, "descr", 4222 "Verify PT_SETSTEP called three times"); 4223} 4224 4225ATF_TC_BODY(setstep3, tc) 4226{ 4227 ptrace_step(3, 1); 4228} 4229#endif 4230 4231#if defined(PT_STEP) 4232ATF_TC(setstep4); 4233ATF_TC_HEAD(setstep4, tc) 4234{ 4235 atf_tc_set_md_var(tc, "descr", 4236 "Verify PT_SETSTEP called four times"); 4237} 4238 4239ATF_TC_BODY(setstep4, tc) 4240{ 4241 ptrace_step(4, 1); 4242} 4243#endif 4244 4245ATF_TC(kill1); 4246ATF_TC_HEAD(kill1, tc) 4247{ 4248 atf_tc_set_md_var(tc, "descr", 4249 "Verify that PT_CONTINUE with SIGKILL terminates child"); 4250} 4251 4252ATF_TC_BODY(kill1, tc) 4253{ 4254 const int sigval = SIGSTOP, sigsent = SIGKILL; 4255 pid_t child, wpid; 4256#if defined(TWAIT_HAVE_STATUS) 4257 int status; 4258#endif 4259 4260 DPRINTF("Before forking process PID=%d\n", getpid()); 4261 SYSCALL_REQUIRE((child = fork()) != -1); 4262 if (child == 0) { 4263 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4264 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4265 4266 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4267 FORKEE_ASSERT(raise(sigval) == 0); 4268 4269 /* NOTREACHED */ 4270 FORKEE_ASSERTX(0 && 4271 "Child should be terminated by a signal from its parent"); 4272 } 4273 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4274 4275 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4276 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4277 4278 validate_status_stopped(status, sigval); 4279 4280 DPRINTF("Before resuming the child process where it left off and " 4281 "without signal to be sent\n"); 4282 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 4283 4284 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4285 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4286 4287 validate_status_signaled(status, sigsent, 0); 4288 4289 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4290 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4291} 4292 4293ATF_TC(kill2); 4294ATF_TC_HEAD(kill2, tc) 4295{ 4296 atf_tc_set_md_var(tc, "descr", 4297 "Verify that PT_KILL terminates child"); 4298} 4299 4300ATF_TC_BODY(kill2, tc) 4301{ 4302 const int sigval = SIGSTOP; 4303 pid_t child, wpid; 4304#if defined(TWAIT_HAVE_STATUS) 4305 int status; 4306#endif 4307 4308 DPRINTF("Before forking process PID=%d\n", getpid()); 4309 SYSCALL_REQUIRE((child = fork()) != -1); 4310 if (child == 0) { 4311 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4312 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4313 4314 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4315 FORKEE_ASSERT(raise(sigval) == 0); 4316 4317 /* NOTREACHED */ 4318 FORKEE_ASSERTX(0 && 4319 "Child should be terminated by a signal from its parent"); 4320 } 4321 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4322 4323 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4324 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4325 4326 validate_status_stopped(status, sigval); 4327 4328 DPRINTF("Before resuming the child process where it left off and " 4329 "without signal to be sent\n"); 4330 SYSCALL_REQUIRE(ptrace(PT_KILL, child, (void*)1, 0) != -1); 4331 4332 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4333 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4334 4335 validate_status_signaled(status, SIGKILL, 0); 4336 4337 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4338 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4339} 4340 4341ATF_TC(lwpinfo1); 4342ATF_TC_HEAD(lwpinfo1, tc) 4343{ 4344 atf_tc_set_md_var(tc, "descr", 4345 "Verify basic LWPINFO call for single thread (PT_TRACE_ME)"); 4346} 4347 4348ATF_TC_BODY(lwpinfo1, tc) 4349{ 4350 const int exitval = 5; 4351 const int sigval = SIGSTOP; 4352 pid_t child, wpid; 4353#if defined(TWAIT_HAVE_STATUS) 4354 int status; 4355#endif 4356 struct ptrace_lwpinfo info = {0, 0}; 4357 4358 DPRINTF("Before forking process PID=%d\n", getpid()); 4359 SYSCALL_REQUIRE((child = fork()) != -1); 4360 if (child == 0) { 4361 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4362 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4363 4364 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4365 FORKEE_ASSERT(raise(sigval) == 0); 4366 4367 DPRINTF("Before exiting of the child process\n"); 4368 _exit(exitval); 4369 } 4370 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4371 4372 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4373 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4374 4375 validate_status_stopped(status, sigval); 4376 4377 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 4378 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1); 4379 4380 DPRINTF("Assert that there exists a thread\n"); 4381 ATF_REQUIRE(info.pl_lwpid > 0); 4382 4383 DPRINTF("Assert that lwp thread %d received event PL_EVENT_SIGNAL\n", 4384 info.pl_lwpid); 4385 ATF_REQUIRE_EQ_MSG(info.pl_event, PL_EVENT_SIGNAL, 4386 "Received event %d != expected event %d", 4387 info.pl_event, PL_EVENT_SIGNAL); 4388 4389 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 4390 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1); 4391 4392 DPRINTF("Assert that there are no more lwp threads in child\n"); 4393 ATF_REQUIRE_EQ(info.pl_lwpid, 0); 4394 4395 DPRINTF("Before resuming the child process where it left off and " 4396 "without signal to be sent\n"); 4397 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4398 4399 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4400 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4401 4402 validate_status_exited(status, exitval); 4403 4404 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4405 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4406} 4407 4408#if defined(TWAIT_HAVE_PID) 4409ATF_TC(lwpinfo2); 4410ATF_TC_HEAD(lwpinfo2, tc) 4411{ 4412 atf_tc_set_md_var(tc, "descr", 4413 "Verify basic LWPINFO call for single thread (PT_ATTACH from " 4414 "tracer)"); 4415} 4416 4417ATF_TC_BODY(lwpinfo2, tc) 4418{ 4419 struct msg_fds parent_tracee, parent_tracer; 4420 const int exitval_tracee = 5; 4421 const int exitval_tracer = 10; 4422 pid_t tracee, tracer, wpid; 4423 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 4424#if defined(TWAIT_HAVE_STATUS) 4425 int status; 4426#endif 4427 struct ptrace_lwpinfo info = {0, 0}; 4428 4429 DPRINTF("Spawn tracee\n"); 4430 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 4431 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 4432 tracee = atf_utils_fork(); 4433 if (tracee == 0) { 4434 4435 /* Wait for message from the parent */ 4436 CHILD_TO_PARENT("tracee ready", parent_tracee, msg); 4437 CHILD_FROM_PARENT("tracee exit", parent_tracee, msg); 4438 4439 _exit(exitval_tracee); 4440 } 4441 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg); 4442 4443 DPRINTF("Spawn debugger\n"); 4444 tracer = atf_utils_fork(); 4445 if (tracer == 0) { 4446 /* No IPC to communicate with the child */ 4447 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 4448 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 4449 4450 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 4451 FORKEE_REQUIRE_SUCCESS( 4452 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 4453 4454 forkee_status_stopped(status, SIGSTOP); 4455 4456 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 4457 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info)) 4458 != -1); 4459 4460 DPRINTF("Assert that there exists a thread\n"); 4461 FORKEE_ASSERTX(info.pl_lwpid > 0); 4462 4463 DPRINTF("Assert that lwp thread %d received event " 4464 "PL_EVENT_SIGNAL\n", info.pl_lwpid); 4465 FORKEE_ASSERT_EQ(info.pl_event, PL_EVENT_SIGNAL); 4466 4467 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 4468 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info)) 4469 != -1); 4470 4471 DPRINTF("Assert that there are no more lwp threads in child\n"); 4472 FORKEE_ASSERTX(info.pl_lwpid == 0); 4473 4474 /* Resume tracee with PT_CONTINUE */ 4475 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 4476 4477 /* Inform parent that tracer has attached to tracee */ 4478 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 4479 /* Wait for parent */ 4480 CHILD_FROM_PARENT("tracer wait", parent_tracer, msg); 4481 4482 /* Wait for tracee and assert that it exited */ 4483 FORKEE_REQUIRE_SUCCESS( 4484 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 4485 4486 forkee_status_exited(status, exitval_tracee); 4487 4488 DPRINTF("Before exiting of the tracer process\n"); 4489 _exit(exitval_tracer); 4490 } 4491 4492 DPRINTF("Wait for the tracer to attach to the tracee\n"); 4493 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 4494 4495 DPRINTF("Resume the tracee and let it exit\n"); 4496 PARENT_TO_CHILD("tracee exit", parent_tracee, msg); 4497 4498 DPRINTF("Detect that tracee is zombie\n"); 4499 await_zombie(tracee); 4500 4501 DPRINTF("Assert that there is no status about tracee - " 4502 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 4503 TWAIT_REQUIRE_SUCCESS( 4504 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 4505 4506 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 4507 PARENT_TO_CHILD("tracer wait", parent_tracer, msg); 4508 4509 DPRINTF("Wait for tracer to finish its job and exit - calling %s()\n", 4510 TWAIT_FNAME); 4511 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 4512 tracer); 4513 4514 validate_status_exited(status, exitval_tracer); 4515 4516 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 4517 TWAIT_FNAME); 4518 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 4519 tracee); 4520 4521 validate_status_exited(status, exitval_tracee); 4522 4523 msg_close(&parent_tracer); 4524 msg_close(&parent_tracee); 4525} 4526#endif 4527 4528ATF_TC(siginfo1); 4529ATF_TC_HEAD(siginfo1, tc) 4530{ 4531 atf_tc_set_md_var(tc, "descr", 4532 "Verify basic PT_GET_SIGINFO call for SIGTRAP from tracee"); 4533} 4534 4535ATF_TC_BODY(siginfo1, tc) 4536{ 4537 const int exitval = 5; 4538 const int sigval = SIGTRAP; 4539 pid_t child, wpid; 4540#if defined(TWAIT_HAVE_STATUS) 4541 int status; 4542#endif 4543 struct ptrace_siginfo info; 4544 memset(&info, 0, sizeof(info)); 4545 4546 DPRINTF("Before forking process PID=%d\n", getpid()); 4547 SYSCALL_REQUIRE((child = fork()) != -1); 4548 if (child == 0) { 4549 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4550 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4551 4552 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4553 FORKEE_ASSERT(raise(sigval) == 0); 4554 4555 DPRINTF("Before exiting of the child process\n"); 4556 _exit(exitval); 4557 } 4558 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4559 4560 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4561 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4562 4563 validate_status_stopped(status, sigval); 4564 4565 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4566 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4567 4568 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 4569 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 4570 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 4571 info.psi_siginfo.si_errno); 4572 4573 DPRINTF("Before resuming the child process where it left off and " 4574 "without signal to be sent\n"); 4575 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4576 4577 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4578 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4579 4580 validate_status_exited(status, exitval); 4581 4582 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4583 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4584} 4585 4586ATF_TC(siginfo2); 4587ATF_TC_HEAD(siginfo2, tc) 4588{ 4589 atf_tc_set_md_var(tc, "descr", 4590 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls without " 4591 "modification of SIGINT from tracee"); 4592} 4593 4594static int siginfo2_caught = 0; 4595 4596static void 4597siginfo2_sighandler(int sig) 4598{ 4599 FORKEE_ASSERT_EQ(sig, SIGINT); 4600 4601 ++siginfo2_caught; 4602} 4603 4604ATF_TC_BODY(siginfo2, tc) 4605{ 4606 const int exitval = 5; 4607 const int sigval = SIGINT; 4608 pid_t child, wpid; 4609 struct sigaction sa; 4610#if defined(TWAIT_HAVE_STATUS) 4611 int status; 4612#endif 4613 struct ptrace_siginfo info; 4614 memset(&info, 0, sizeof(info)); 4615 4616 DPRINTF("Before forking process PID=%d\n", getpid()); 4617 SYSCALL_REQUIRE((child = fork()) != -1); 4618 if (child == 0) { 4619 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4620 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4621 4622 sa.sa_handler = siginfo2_sighandler; 4623 sa.sa_flags = SA_SIGINFO; 4624 sigemptyset(&sa.sa_mask); 4625 4626 FORKEE_ASSERT(sigaction(sigval, &sa, NULL) != -1); 4627 4628 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4629 FORKEE_ASSERT(raise(sigval) == 0); 4630 4631 FORKEE_ASSERT_EQ(siginfo2_caught, 1); 4632 4633 DPRINTF("Before exiting of the child process\n"); 4634 _exit(exitval); 4635 } 4636 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4637 4638 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4639 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4640 4641 validate_status_stopped(status, sigval); 4642 4643 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4644 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4645 4646 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 4647 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 4648 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 4649 info.psi_siginfo.si_errno); 4650 4651 DPRINTF("Before calling ptrace(2) with PT_SET_SIGINFO for child\n"); 4652 SYSCALL_REQUIRE(ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1); 4653 4654 DPRINTF("Before resuming the child process where it left off and " 4655 "without signal to be sent\n"); 4656 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigval) != -1); 4657 4658 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4659 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4660 4661 validate_status_exited(status, exitval); 4662 4663 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4664 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4665} 4666 4667ATF_TC(siginfo3); 4668ATF_TC_HEAD(siginfo3, tc) 4669{ 4670 atf_tc_set_md_var(tc, "descr", 4671 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls with " 4672 "setting signal to new value"); 4673} 4674 4675static int siginfo3_caught = 0; 4676 4677static void 4678siginfo3_sigaction(int sig, siginfo_t *info, void *ctx) 4679{ 4680 FORKEE_ASSERT_EQ(sig, SIGTRAP); 4681 4682 FORKEE_ASSERT_EQ(info->si_signo, SIGTRAP); 4683 FORKEE_ASSERT_EQ(info->si_code, TRAP_BRKPT); 4684 4685 ++siginfo3_caught; 4686} 4687 4688ATF_TC_BODY(siginfo3, tc) 4689{ 4690 const int exitval = 5; 4691 const int sigval = SIGINT; 4692 const int sigfaked = SIGTRAP; 4693 const int sicodefaked = TRAP_BRKPT; 4694 pid_t child, wpid; 4695 struct sigaction sa; 4696#if defined(TWAIT_HAVE_STATUS) 4697 int status; 4698#endif 4699 struct ptrace_siginfo info; 4700 memset(&info, 0, sizeof(info)); 4701 4702 DPRINTF("Before forking process PID=%d\n", getpid()); 4703 SYSCALL_REQUIRE((child = fork()) != -1); 4704 if (child == 0) { 4705 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4706 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4707 4708 sa.sa_sigaction = siginfo3_sigaction; 4709 sa.sa_flags = SA_SIGINFO; 4710 sigemptyset(&sa.sa_mask); 4711 4712 FORKEE_ASSERT(sigaction(sigfaked, &sa, NULL) != -1); 4713 4714 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4715 FORKEE_ASSERT(raise(sigval) == 0); 4716 4717 FORKEE_ASSERT_EQ(siginfo3_caught, 1); 4718 4719 DPRINTF("Before exiting of the child process\n"); 4720 _exit(exitval); 4721 } 4722 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4723 4724 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4725 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4726 4727 validate_status_stopped(status, sigval); 4728 4729 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4730 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4731 4732 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 4733 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 4734 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 4735 info.psi_siginfo.si_errno); 4736 4737 DPRINTF("Before setting new faked signal to signo=%d si_code=%d\n", 4738 sigfaked, sicodefaked); 4739 info.psi_siginfo.si_signo = sigfaked; 4740 info.psi_siginfo.si_code = sicodefaked; 4741 4742 DPRINTF("Before calling ptrace(2) with PT_SET_SIGINFO for child\n"); 4743 SYSCALL_REQUIRE(ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1); 4744 4745 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4746 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4747 4748 DPRINTF("Before checking siginfo_t\n"); 4749 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigfaked); 4750 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, sicodefaked); 4751 4752 DPRINTF("Before resuming the child process where it left off and " 4753 "without signal to be sent\n"); 4754 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigfaked) != -1); 4755 4756 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4757 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4758 4759 validate_status_exited(status, exitval); 4760 4761 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4762 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4763} 4764 4765ATF_TC(siginfo4); 4766ATF_TC_HEAD(siginfo4, tc) 4767{ 4768 atf_tc_set_md_var(tc, "descr", 4769 "Detect SIGTRAP TRAP_EXEC from tracee"); 4770} 4771 4772ATF_TC_BODY(siginfo4, tc) 4773{ 4774 const int sigval = SIGTRAP; 4775 pid_t child, wpid; 4776#if defined(TWAIT_HAVE_STATUS) 4777 int status; 4778#endif 4779 4780 struct ptrace_siginfo info; 4781 memset(&info, 0, sizeof(info)); 4782 4783 DPRINTF("Before forking process PID=%d\n", getpid()); 4784 SYSCALL_REQUIRE((child = fork()) != -1); 4785 if (child == 0) { 4786 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4787 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4788 4789 DPRINTF("Before calling execve(2) from child\n"); 4790 execlp("/bin/echo", "/bin/echo", NULL); 4791 4792 FORKEE_ASSERT(0 && "Not reached"); 4793 } 4794 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4795 4796 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4797 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4798 4799 validate_status_stopped(status, sigval); 4800 4801 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4802 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4803 4804 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 4805 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 4806 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 4807 info.psi_siginfo.si_errno); 4808 4809 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 4810 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); 4811 4812 DPRINTF("Before resuming the child process where it left off and " 4813 "without signal to be sent\n"); 4814 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4815 4816 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4817 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4818 4819 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4820 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4821} 4822 4823#if defined(TWAIT_HAVE_PID) 4824ATF_TC(siginfo5); 4825ATF_TC_HEAD(siginfo5, tc) 4826{ 4827 atf_tc_set_md_var(tc, "descr", 4828 "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK " 4829 "set to PTRACE_FORK and reports correct signal information"); 4830} 4831 4832ATF_TC_BODY(siginfo5, tc) 4833{ 4834 const int exitval = 5; 4835 const int exitval2 = 15; 4836 const int sigval = SIGSTOP; 4837 pid_t child, child2, wpid; 4838#if defined(TWAIT_HAVE_STATUS) 4839 int status; 4840#endif 4841 ptrace_state_t state; 4842 const int slen = sizeof(state); 4843 ptrace_event_t event; 4844 const int elen = sizeof(event); 4845 struct ptrace_siginfo info; 4846 4847 memset(&info, 0, sizeof(info)); 4848 4849 DPRINTF("Before forking process PID=%d\n", getpid()); 4850 SYSCALL_REQUIRE((child = fork()) != -1); 4851 if (child == 0) { 4852 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4853 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4854 4855 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4856 FORKEE_ASSERT(raise(sigval) == 0); 4857 4858 FORKEE_ASSERT((child2 = fork()) != -1); 4859 4860 if (child2 == 0) 4861 _exit(exitval2); 4862 4863 FORKEE_REQUIRE_SUCCESS 4864 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 4865 4866 forkee_status_exited(status, exitval2); 4867 4868 DPRINTF("Before exiting of the child process\n"); 4869 _exit(exitval); 4870 } 4871 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4872 4873 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4874 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4875 4876 validate_status_stopped(status, sigval); 4877 4878 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4879 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4880 4881 DPRINTF("Before checking siginfo_t\n"); 4882 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 4883 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 4884 4885 DPRINTF("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child); 4886 event.pe_set_event = PTRACE_FORK; 4887 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 4888 4889 DPRINTF("Before resuming the child process where it left off and " 4890 "without signal to be sent\n"); 4891 DPRINTF("We expect two SIGTRAP events, for child %d (TRAP_CHLD, " 4892 "pe_report_event=PTRACE_FORK, state.pe_other_pid=child2) and " 4893 "for child2 (TRAP_CHLD, pe_report_event=PTRACE_FORK, " 4894 "state.pe_other_pid=child)\n", child); 4895 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4896 4897 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, child); 4898 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4899 4900 validate_status_stopped(status, SIGTRAP); 4901 4902 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4903 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4904 4905 DPRINTF("Before checking siginfo_t\n"); 4906 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 4907 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD); 4908 4909 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4910 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 4911 4912 child2 = state.pe_other_pid; 4913 DPRINTF("Reported PTRACE_FORK event with forkee %d\n", child2); 4914 4915 DPRINTF("Before calling %s() for the forkee %d of the child %d\n", 4916 TWAIT_FNAME, child2, child); 4917 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4918 child2); 4919 4920 validate_status_stopped(status, SIGTRAP); 4921 4922 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4923 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4924 4925 DPRINTF("Before checking siginfo_t\n"); 4926 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 4927 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD); 4928 4929 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 4930 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 4931 ATF_REQUIRE_EQ(state.pe_other_pid, child); 4932 4933 DPRINTF("Before resuming the forkee process where it left off and " 4934 "without signal to be sent\n"); 4935 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 4936 4937 DPRINTF("Before resuming the child process where it left off and " 4938 "without signal to be sent\n"); 4939 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4940 4941 DPRINTF("Before calling %s() for the forkee - expected exited\n", 4942 TWAIT_FNAME); 4943 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4944 child2); 4945 4946 validate_status_exited(status, exitval2); 4947 4948 DPRINTF("Before calling %s() for the forkee - expected no process\n", 4949 TWAIT_FNAME); 4950 TWAIT_REQUIRE_FAILURE(ECHILD, 4951 wpid = TWAIT_GENERIC(child2, &status, 0)); 4952 4953 DPRINTF("Before calling %s() for the child - expected stopped " 4954 "SIGCHLD\n", TWAIT_FNAME); 4955 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4956 4957 validate_status_stopped(status, SIGCHLD); 4958 4959 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4960 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4961 4962 DPRINTF("Before checking siginfo_t\n"); 4963 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGCHLD); 4964 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, CLD_EXITED); 4965 4966 DPRINTF("Before resuming the child process where it left off and " 4967 "without signal to be sent\n"); 4968 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4969 4970 DPRINTF("Before calling %s() for the child - expected exited\n", 4971 TWAIT_FNAME); 4972 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4973 4974 validate_status_exited(status, exitval); 4975 4976 DPRINTF("Before calling %s() for the child - expected no process\n", 4977 TWAIT_FNAME); 4978 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4979} 4980#endif 4981 4982#if defined(PT_STEP) 4983ATF_TC(siginfo6); 4984ATF_TC_HEAD(siginfo6, tc) 4985{ 4986 atf_tc_set_md_var(tc, "descr", 4987 "Verify single PT_STEP call with signal information check"); 4988} 4989 4990ATF_TC_BODY(siginfo6, tc) 4991{ 4992 const int exitval = 5; 4993 const int sigval = SIGSTOP; 4994 pid_t child, wpid; 4995#if defined(TWAIT_HAVE_STATUS) 4996 int status; 4997#endif 4998 int happy; 4999 struct ptrace_siginfo info; 5000 5001#if defined(__arm__) 5002 /* PT_STEP not supported on arm 32-bit */ 5003 atf_tc_expect_fail("PR kern/52119"); 5004#endif 5005 5006 memset(&info, 0, sizeof(info)); 5007 5008 DPRINTF("Before forking process PID=%d\n", getpid()); 5009 SYSCALL_REQUIRE((child = fork()) != -1); 5010 if (child == 0) { 5011 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5012 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5013 5014 happy = check_happy(100); 5015 5016 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5017 FORKEE_ASSERT(raise(sigval) == 0); 5018 5019 FORKEE_ASSERT_EQ(happy, check_happy(100)); 5020 5021 DPRINTF("Before exiting of the child process\n"); 5022 _exit(exitval); 5023 } 5024 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5025 5026 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5027 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5028 5029 validate_status_stopped(status, sigval); 5030 5031 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 5032 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 5033 5034 DPRINTF("Before checking siginfo_t\n"); 5035 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 5036 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 5037 5038 DPRINTF("Before resuming the child process where it left off and " 5039 "without signal to be sent (use PT_STEP)\n"); 5040 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1); 5041 5042 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5043 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5044 5045 validate_status_stopped(status, SIGTRAP); 5046 5047 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 5048 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 5049 5050 DPRINTF("Before checking siginfo_t\n"); 5051 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 5052 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_TRACE); 5053 5054 DPRINTF("Before resuming the child process where it left off and " 5055 "without signal to be sent\n"); 5056 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5057 5058 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5059 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5060 5061 validate_status_exited(status, exitval); 5062 5063 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5064 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5065} 5066#endif 5067 5068volatile lwpid_t the_lwp_id = 0; 5069 5070static void 5071lwp_main_func(void *arg) 5072{ 5073 the_lwp_id = _lwp_self(); 5074 _lwp_exit(); 5075} 5076 5077ATF_TC(lwp_create1); 5078ATF_TC_HEAD(lwp_create1, tc) 5079{ 5080 atf_tc_set_md_var(tc, "descr", 5081 "Verify that 1 LWP creation is intercepted by ptrace(2) with " 5082 "EVENT_MASK set to PTRACE_LWP_CREATE"); 5083} 5084 5085ATF_TC_BODY(lwp_create1, tc) 5086{ 5087 const int exitval = 5; 5088 const int sigval = SIGSTOP; 5089 pid_t child, wpid; 5090#if defined(TWAIT_HAVE_STATUS) 5091 int status; 5092#endif 5093 ptrace_state_t state; 5094 const int slen = sizeof(state); 5095 ptrace_event_t event; 5096 const int elen = sizeof(event); 5097 ucontext_t uc; 5098 lwpid_t lid; 5099 static const size_t ssize = 16*1024; 5100 void *stack; 5101 5102 DPRINTF("Before forking process PID=%d\n", getpid()); 5103 SYSCALL_REQUIRE((child = fork()) != -1); 5104 if (child == 0) { 5105 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5106 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5107 5108 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5109 FORKEE_ASSERT(raise(sigval) == 0); 5110 5111 DPRINTF("Before allocating memory for stack in child\n"); 5112 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 5113 5114 DPRINTF("Before making context for new lwp in child\n"); 5115 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 5116 5117 DPRINTF("Before creating new in child\n"); 5118 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 5119 5120 DPRINTF("Before waiting for lwp %d to exit\n", lid); 5121 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 5122 5123 DPRINTF("Before verifying that reported %d and running lid %d " 5124 "are the same\n", lid, the_lwp_id); 5125 FORKEE_ASSERT_EQ(lid, the_lwp_id); 5126 5127 DPRINTF("Before exiting of the child process\n"); 5128 _exit(exitval); 5129 } 5130 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5131 5132 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5133 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5134 5135 validate_status_stopped(status, sigval); 5136 5137 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 5138 event.pe_set_event = PTRACE_LWP_CREATE; 5139 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5140 5141 DPRINTF("Before resuming the child process where it left off and " 5142 "without signal to be sent\n"); 5143 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5144 5145 DPRINTF("Before calling %s() for the child - expected stopped " 5146 "SIGTRAP\n", TWAIT_FNAME); 5147 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5148 5149 validate_status_stopped(status, SIGTRAP); 5150 5151 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5152 5153 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); 5154 5155 lid = state.pe_lwp; 5156 DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); 5157 5158 DPRINTF("Before resuming the child process where it left off and " 5159 "without signal to be sent\n"); 5160 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5161 5162 DPRINTF("Before calling %s() for the child - expected exited\n", 5163 TWAIT_FNAME); 5164 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5165 5166 validate_status_exited(status, exitval); 5167 5168 DPRINTF("Before calling %s() for the child - expected no process\n", 5169 TWAIT_FNAME); 5170 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5171} 5172 5173ATF_TC(lwp_exit1); 5174ATF_TC_HEAD(lwp_exit1, tc) 5175{ 5176 atf_tc_set_md_var(tc, "descr", 5177 "Verify that 1 LWP creation is intercepted by ptrace(2) with " 5178 "EVENT_MASK set to PTRACE_LWP_EXIT"); 5179} 5180 5181ATF_TC_BODY(lwp_exit1, tc) 5182{ 5183 const int exitval = 5; 5184 const int sigval = SIGSTOP; 5185 pid_t child, wpid; 5186#if defined(TWAIT_HAVE_STATUS) 5187 int status; 5188#endif 5189 ptrace_state_t state; 5190 const int slen = sizeof(state); 5191 ptrace_event_t event; 5192 const int elen = sizeof(event); 5193 ucontext_t uc; 5194 lwpid_t lid; 5195 static const size_t ssize = 16*1024; 5196 void *stack; 5197 5198 DPRINTF("Before forking process PID=%d\n", getpid()); 5199 SYSCALL_REQUIRE((child = fork()) != -1); 5200 if (child == 0) { 5201 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5202 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5203 5204 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5205 FORKEE_ASSERT(raise(sigval) == 0); 5206 5207 DPRINTF("Before allocating memory for stack in child\n"); 5208 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 5209 5210 DPRINTF("Before making context for new lwp in child\n"); 5211 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 5212 5213 DPRINTF("Before creating new in child\n"); 5214 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 5215 5216 DPRINTF("Before waiting for lwp %d to exit\n", lid); 5217 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 5218 5219 DPRINTF("Before verifying that reported %d and running lid %d " 5220 "are the same\n", lid, the_lwp_id); 5221 FORKEE_ASSERT_EQ(lid, the_lwp_id); 5222 5223 DPRINTF("Before exiting of the child process\n"); 5224 _exit(exitval); 5225 } 5226 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5227 5228 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5229 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5230 5231 validate_status_stopped(status, sigval); 5232 5233 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 5234 event.pe_set_event = PTRACE_LWP_EXIT; 5235 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5236 5237 DPRINTF("Before resuming the child process where it left off and " 5238 "without signal to be sent\n"); 5239 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5240 5241 DPRINTF("Before calling %s() for the child - expected stopped " 5242 "SIGTRAP\n", TWAIT_FNAME); 5243 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5244 5245 validate_status_stopped(status, SIGTRAP); 5246 5247 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5248 5249 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); 5250 5251 lid = state.pe_lwp; 5252 DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); 5253 5254 DPRINTF("Before resuming the child process where it left off and " 5255 "without signal to be sent\n"); 5256 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5257 5258 DPRINTF("Before calling %s() for the child - expected exited\n", 5259 TWAIT_FNAME); 5260 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5261 5262 validate_status_exited(status, exitval); 5263 5264 DPRINTF("Before calling %s() for the child - expected no process\n", 5265 TWAIT_FNAME); 5266 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5267} 5268 5269ATF_TC(signal1); 5270ATF_TC_HEAD(signal1, tc) 5271{ 5272 atf_tc_set_md_var(tc, "descr", 5273 "Verify that masking single unrelated signal does not stop tracer " 5274 "from catching other signals"); 5275} 5276 5277ATF_TC_BODY(signal1, tc) 5278{ 5279 const int exitval = 5; 5280 const int sigval = SIGSTOP; 5281 const int sigmasked = SIGTRAP; 5282 const int signotmasked = SIGINT; 5283 pid_t child, wpid; 5284#if defined(TWAIT_HAVE_STATUS) 5285 int status; 5286#endif 5287 sigset_t intmask; 5288 5289 DPRINTF("Before forking process PID=%d\n", getpid()); 5290 SYSCALL_REQUIRE((child = fork()) != -1); 5291 if (child == 0) { 5292 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5293 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5294 5295 sigemptyset(&intmask); 5296 sigaddset(&intmask, sigmasked); 5297 sigprocmask(SIG_BLOCK, &intmask, NULL); 5298 5299 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5300 FORKEE_ASSERT(raise(sigval) == 0); 5301 5302 DPRINTF("Before raising %s from child\n", 5303 strsignal(signotmasked)); 5304 FORKEE_ASSERT(raise(signotmasked) == 0); 5305 5306 DPRINTF("Before exiting of the child process\n"); 5307 _exit(exitval); 5308 } 5309 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5310 5311 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5312 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5313 5314 validate_status_stopped(status, sigval); 5315 5316 DPRINTF("Before resuming the child process where it left off and " 5317 "without signal to be sent\n"); 5318 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5319 5320 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5321 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5322 5323 validate_status_stopped(status, signotmasked); 5324 5325 DPRINTF("Before resuming the child process where it left off and " 5326 "without signal to be sent\n"); 5327 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5328 5329 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5330 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5331 5332 validate_status_exited(status, exitval); 5333 5334 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5335 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5336} 5337 5338ATF_TC(signal2); 5339ATF_TC_HEAD(signal2, tc) 5340{ 5341 atf_tc_set_md_var(tc, "descr", 5342 "Verify that masking SIGTRAP in tracee stops tracer from " 5343 "catching this raised signal"); 5344} 5345 5346ATF_TC_BODY(signal2, tc) 5347{ 5348 const int exitval = 5; 5349 const int sigval = SIGSTOP; 5350 const int sigmasked = SIGTRAP; 5351 pid_t child, wpid; 5352#if defined(TWAIT_HAVE_STATUS) 5353 int status; 5354#endif 5355 sigset_t intmask; 5356 5357 DPRINTF("Before forking process PID=%d\n", getpid()); 5358 SYSCALL_REQUIRE((child = fork()) != -1); 5359 if (child == 0) { 5360 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5361 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5362 5363 sigemptyset(&intmask); 5364 sigaddset(&intmask, sigmasked); 5365 sigprocmask(SIG_BLOCK, &intmask, NULL); 5366 5367 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5368 FORKEE_ASSERT(raise(sigval) == 0); 5369 5370 DPRINTF("Before raising %s breakpoint from child\n", 5371 strsignal(sigmasked)); 5372 FORKEE_ASSERT(raise(sigmasked) == 0); 5373 5374 DPRINTF("Before exiting of the child process\n"); 5375 _exit(exitval); 5376 } 5377 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5378 5379 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5380 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5381 5382 validate_status_stopped(status, sigval); 5383 5384 DPRINTF("Before resuming the child process where it left off and " 5385 "without signal to be sent\n"); 5386 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5387 5388 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5389 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5390 5391 validate_status_exited(status, exitval); 5392 5393 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5394 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5395} 5396 5397ATF_TC(signal3); 5398ATF_TC_HEAD(signal3, tc) 5399{ 5400 atf_tc_set_md_var(tc, "timeout", "5"); 5401 atf_tc_set_md_var(tc, "descr", 5402 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5403 "catching software breakpoints"); 5404} 5405 5406ATF_TC_BODY(signal3, tc) 5407{ 5408 const int exitval = 5; 5409 const int sigval = SIGSTOP; 5410 const int sigmasked = SIGTRAP; 5411 pid_t child, wpid; 5412#if defined(TWAIT_HAVE_STATUS) 5413 int status; 5414#endif 5415 sigset_t intmask; 5416 5417 atf_tc_expect_fail("PR kern/51918"); 5418 5419 // This test breaks now on some ports, temporarily disable it 5420 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 5421 5422#if defined(__sparc__) 5423 atf_tc_expect_timeout("PR kern/52167"); 5424 5425 // timeout wins, failure still valid 5426 // atf_tc_expect_fail("PR kern/51918"); 5427#endif 5428 5429 DPRINTF("Before forking process PID=%d\n", getpid()); 5430 SYSCALL_REQUIRE((child = fork()) != -1); 5431 if (child == 0) { 5432 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5433 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5434 5435 sigemptyset(&intmask); 5436 sigaddset(&intmask, sigmasked); 5437 sigprocmask(SIG_BLOCK, &intmask, NULL); 5438 5439 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5440 FORKEE_ASSERT(raise(sigval) == 0); 5441 5442 DPRINTF("Before raising software breakpoint from child\n"); 5443 5444#ifdef PTRACE_BREAKPOINT_ASM 5445 PTRACE_BREAKPOINT_ASM; 5446#else 5447 /* port me */ 5448#endif 5449 5450 DPRINTF("Before exiting of the child process\n"); 5451 _exit(exitval); 5452 } 5453 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5454 5455 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5456 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5457 5458 validate_status_stopped(status, sigval); 5459 5460 DPRINTF("Before resuming the child process where it left off and " 5461 "without signal to be sent\n"); 5462 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5463 5464 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5465 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5466 5467 validate_status_stopped(status, sigmasked); 5468 5469 DPRINTF("Before resuming the child process where it left off and " 5470 "without signal to be sent\n"); 5471 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5472 5473 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5474 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5475 5476 validate_status_exited(status, exitval); 5477 5478 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5479 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5480} 5481 5482#if defined(PT_STEP) 5483ATF_TC(signal4); 5484ATF_TC_HEAD(signal4, tc) 5485{ 5486 atf_tc_set_md_var(tc, "descr", 5487 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5488 "catching single step trap"); 5489} 5490 5491ATF_TC_BODY(signal4, tc) 5492{ 5493 const int exitval = 5; 5494 const int sigval = SIGSTOP; 5495 const int sigmasked = SIGTRAP; 5496 pid_t child, wpid; 5497#if defined(TWAIT_HAVE_STATUS) 5498 int status; 5499#endif 5500 sigset_t intmask; 5501 int happy; 5502 5503#if defined(__arm__) 5504 /* PT_STEP not supported on arm 32-bit */ 5505 atf_tc_expect_fail("PR kern/51918 PR kern/52119"); 5506#endif 5507 5508 DPRINTF("Before forking process PID=%d\n", getpid()); 5509 SYSCALL_REQUIRE((child = fork()) != -1); 5510 if (child == 0) { 5511 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5512 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5513 5514 happy = check_happy(100); 5515 5516 sigemptyset(&intmask); 5517 sigaddset(&intmask, sigmasked); 5518 sigprocmask(SIG_BLOCK, &intmask, NULL); 5519 5520 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5521 FORKEE_ASSERT(raise(sigval) == 0); 5522 5523 FORKEE_ASSERT_EQ(happy, check_happy(100)); 5524 5525 DPRINTF("Before exiting of the child process\n"); 5526 _exit(exitval); 5527 } 5528 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5529 5530 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5531 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5532 5533 validate_status_stopped(status, sigval); 5534 5535 DPRINTF("Before resuming the child process where it left off and " 5536 "without signal to be sent\n"); 5537 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1); 5538 5539 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5540 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5541 5542 validate_status_stopped(status, sigmasked); 5543 5544 DPRINTF("Before resuming the child process where it left off and " 5545 "without signal to be sent\n"); 5546 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5547 5548 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5549 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5550 5551 validate_status_exited(status, exitval); 5552 5553 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5554 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5555} 5556#endif 5557 5558ATF_TC(signal5); 5559ATF_TC_HEAD(signal5, tc) 5560{ 5561 atf_tc_set_md_var(tc, "descr", 5562 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5563 "catching exec() breakpoint"); 5564} 5565 5566ATF_TC_BODY(signal5, tc) 5567{ 5568 const int exitval = 5; 5569 const int sigval = SIGSTOP; 5570 const int sigmasked = SIGTRAP; 5571 pid_t child, wpid; 5572#if defined(TWAIT_HAVE_STATUS) 5573 int status; 5574#endif 5575 sigset_t intmask; 5576 5577 atf_tc_expect_fail("wrong signal"); 5578 5579 DPRINTF("Before forking process PID=%d\n", getpid()); 5580 SYSCALL_REQUIRE((child = fork()) != -1); 5581 if (child == 0) { 5582 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5583 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5584 5585 sigemptyset(&intmask); 5586 sigaddset(&intmask, sigmasked); 5587 sigprocmask(SIG_BLOCK, &intmask, NULL); 5588 5589 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5590 FORKEE_ASSERT(raise(sigval) == 0); 5591 5592 DPRINTF("Before calling execve(2) from child\n"); 5593 execlp("/bin/echo", "/bin/echo", NULL); 5594 5595 DPRINTF("Before exiting of the child process\n"); 5596 _exit(exitval); 5597 } 5598 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5599 5600 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5601 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5602 5603 validate_status_stopped(status, sigval); 5604 5605 DPRINTF("Before resuming the child process where it left off and " 5606 "without signal to be sent\n"); 5607 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5608 5609 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5610 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5611 5612 validate_status_stopped(status, sigmasked); 5613 5614 DPRINTF("Before resuming the child process where it left off and " 5615 "without signal to be sent\n"); 5616 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5617 5618 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5619 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5620 5621 validate_status_exited(status, exitval); 5622 5623 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5624 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5625} 5626 5627#if defined(TWAIT_HAVE_PID) 5628ATF_TC(signal6); 5629ATF_TC_HEAD(signal6, tc) 5630{ 5631 atf_tc_set_md_var(tc, "timeout", "5"); 5632 atf_tc_set_md_var(tc, "descr", 5633 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5634 "catching PTRACE_FORK breakpoint"); 5635} 5636 5637ATF_TC_BODY(signal6, tc) 5638{ 5639 const int exitval = 5; 5640 const int exitval2 = 15; 5641 const int sigval = SIGSTOP; 5642 const int sigmasked = SIGTRAP; 5643 pid_t child, child2, wpid; 5644#if defined(TWAIT_HAVE_STATUS) 5645 int status; 5646#endif 5647 sigset_t intmask; 5648 ptrace_state_t state; 5649 const int slen = sizeof(state); 5650 ptrace_event_t event; 5651 const int elen = sizeof(event); 5652 5653 atf_tc_expect_timeout("PR kern/51918"); 5654 5655 DPRINTF("Before forking process PID=%d\n", getpid()); 5656 SYSCALL_REQUIRE((child = fork()) != -1); 5657 if (child == 0) { 5658 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5659 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5660 5661 sigemptyset(&intmask); 5662 sigaddset(&intmask, sigmasked); 5663 sigprocmask(SIG_BLOCK, &intmask, NULL); 5664 5665 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5666 FORKEE_ASSERT(raise(sigval) == 0); 5667 5668 FORKEE_ASSERT((child2 = fork()) != -1); 5669 5670 if (child2 == 0) 5671 _exit(exitval2); 5672 5673 FORKEE_REQUIRE_SUCCESS 5674 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 5675 5676 forkee_status_exited(status, exitval2); 5677 5678 DPRINTF("Before exiting of the child process\n"); 5679 _exit(exitval); 5680 } 5681 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5682 5683 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5684 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5685 5686 validate_status_stopped(status, sigval); 5687 5688 DPRINTF("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child); 5689 event.pe_set_event = PTRACE_FORK; 5690 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5691 5692 DPRINTF("Before resuming the child process where it left off and " 5693 "without signal to be sent\n"); 5694 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5695 5696 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5697 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5698 5699 validate_status_stopped(status, sigmasked); 5700 5701 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5702 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 5703 5704 child2 = state.pe_other_pid; 5705 DPRINTF("Reported PTRACE_FORK event with forkee %d\n", child2); 5706 5707 DPRINTF("Before calling %s() for the child2\n", TWAIT_FNAME); 5708 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 5709 child2); 5710 5711 validate_status_stopped(status, SIGTRAP); 5712 5713 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 5714 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 5715 ATF_REQUIRE_EQ(state.pe_other_pid, child); 5716 5717 DPRINTF("Before resuming the forkee process where it left off and " 5718 "without signal to be sent\n"); 5719 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 5720 5721 DPRINTF("Before resuming the child process where it left off and " 5722 "without signal to be sent\n"); 5723 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5724 5725 DPRINTF("Before calling %s() for the forkee - expected exited\n", 5726 TWAIT_FNAME); 5727 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 5728 child2); 5729 5730 validate_status_exited(status, exitval2); 5731 5732 DPRINTF("Before calling %s() for the forkee - expected no process\n", 5733 TWAIT_FNAME); 5734 TWAIT_REQUIRE_FAILURE(ECHILD, 5735 wpid = TWAIT_GENERIC(child2, &status, 0)); 5736 5737 DPRINTF("Before calling %s() for the child - expected stopped " 5738 "SIGCHLD\n", TWAIT_FNAME); 5739 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5740 5741 validate_status_stopped(status, SIGCHLD); 5742 5743 DPRINTF("Before resuming the child process where it left off and " 5744 "without signal to be sent\n"); 5745 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5746 5747 DPRINTF("Before calling %s() for the child - expected exited\n", 5748 TWAIT_FNAME); 5749 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5750 5751 validate_status_exited(status, exitval); 5752 5753 DPRINTF("Before calling %s() for the child - expected no process\n", 5754 TWAIT_FNAME); 5755 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5756} 5757#endif 5758 5759#if defined(TWAIT_HAVE_PID) 5760ATF_TC(signal7); 5761ATF_TC_HEAD(signal7, tc) 5762{ 5763 atf_tc_set_md_var(tc, "descr", 5764 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5765 "catching PTRACE_VFORK breakpoint"); 5766} 5767 5768ATF_TC_BODY(signal7, tc) 5769{ 5770 const int exitval = 5; 5771 const int exitval2 = 15; 5772 const int sigval = SIGSTOP; 5773 const int sigmasked = SIGTRAP; 5774 pid_t child, child2, wpid; 5775#if defined(TWAIT_HAVE_STATUS) 5776 int status; 5777#endif 5778 sigset_t intmask; 5779 ptrace_state_t state; 5780 const int slen = sizeof(state); 5781 ptrace_event_t event; 5782 const int elen = sizeof(event); 5783 5784 atf_tc_expect_fail("PR kern/51918 PR kern/51630"); 5785 5786 DPRINTF("Before forking process PID=%d\n", getpid()); 5787 SYSCALL_REQUIRE((child = fork()) != -1); 5788 if (child == 0) { 5789 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5790 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5791 5792 sigemptyset(&intmask); 5793 sigaddset(&intmask, sigmasked); 5794 sigprocmask(SIG_BLOCK, &intmask, NULL); 5795 5796 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5797 FORKEE_ASSERT(raise(sigval) == 0); 5798 5799 FORKEE_ASSERT((child2 = fork()) != -1); 5800 5801 if (child2 == 0) 5802 _exit(exitval2); 5803 5804 FORKEE_REQUIRE_SUCCESS 5805 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 5806 5807 forkee_status_exited(status, exitval2); 5808 5809 DPRINTF("Before exiting of the child process\n"); 5810 _exit(exitval); 5811 } 5812 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5813 5814 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5815 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5816 5817 validate_status_stopped(status, sigval); 5818 5819 DPRINTF("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child); 5820 event.pe_set_event = PTRACE_VFORK; 5821 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1 || errno == ENOTSUP); 5822 5823 DPRINTF("Before resuming the child process where it left off and " 5824 "without signal to be sent\n"); 5825 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5826 5827 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5828 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5829 5830 validate_status_stopped(status, sigmasked); 5831 5832 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5833 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK); 5834 5835 child2 = state.pe_other_pid; 5836 DPRINTF("Reported PTRACE_VFORK event with forkee %d\n", child2); 5837 5838 DPRINTF("Before calling %s() for the child2\n", TWAIT_FNAME); 5839 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 5840 child2); 5841 5842 validate_status_stopped(status, SIGTRAP); 5843 5844 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 5845 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK); 5846 ATF_REQUIRE_EQ(state.pe_other_pid, child); 5847 5848 DPRINTF("Before resuming the forkee process where it left off and " 5849 "without signal to be sent\n"); 5850 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 5851 5852 DPRINTF("Before resuming the child process where it left off and " 5853 "without signal to be sent\n"); 5854 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5855 5856 DPRINTF("Before calling %s() for the forkee - expected exited\n", 5857 TWAIT_FNAME); 5858 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 5859 child2); 5860 5861 validate_status_exited(status, exitval2); 5862 5863 DPRINTF("Before calling %s() for the forkee - expected no process\n", 5864 TWAIT_FNAME); 5865 TWAIT_REQUIRE_FAILURE(ECHILD, 5866 wpid = TWAIT_GENERIC(child2, &status, 0)); 5867 5868 DPRINTF("Before calling %s() for the child - expected stopped " 5869 "SIGCHLD\n", TWAIT_FNAME); 5870 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5871 5872 validate_status_stopped(status, SIGCHLD); 5873 5874 DPRINTF("Before resuming the child process where it left off and " 5875 "without signal to be sent\n"); 5876 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5877 5878 DPRINTF("Before calling %s() for the child - expected exited\n", 5879 TWAIT_FNAME); 5880 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5881 5882 validate_status_exited(status, exitval); 5883 5884 DPRINTF("Before calling %s() for the child - expected no process\n", 5885 TWAIT_FNAME); 5886 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5887} 5888#endif 5889 5890ATF_TC(signal8); 5891ATF_TC_HEAD(signal8, tc) 5892{ 5893 atf_tc_set_md_var(tc, "descr", 5894 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5895 "catching PTRACE_VFORK_DONE breakpoint"); 5896} 5897 5898ATF_TC_BODY(signal8, tc) 5899{ 5900 const int exitval = 5; 5901 const int exitval2 = 15; 5902 const int sigval = SIGSTOP; 5903 const int sigmasked = SIGTRAP; 5904 pid_t child, child2, wpid; 5905#if defined(TWAIT_HAVE_STATUS) 5906 int status; 5907#endif 5908 sigset_t intmask; 5909 ptrace_state_t state; 5910 const int slen = sizeof(state); 5911 ptrace_event_t event; 5912 const int elen = sizeof(event); 5913 5914 atf_tc_expect_fail("PR kern/51918"); 5915 5916 DPRINTF("Before forking process PID=%d\n", getpid()); 5917 SYSCALL_REQUIRE((child = fork()) != -1); 5918 if (child == 0) { 5919 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5920 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5921 5922 sigemptyset(&intmask); 5923 sigaddset(&intmask, sigmasked); 5924 sigprocmask(SIG_BLOCK, &intmask, NULL); 5925 5926 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5927 FORKEE_ASSERT(raise(sigval) == 0); 5928 5929 FORKEE_ASSERT((child2 = vfork()) != -1); 5930 5931 if (child2 == 0) 5932 _exit(exitval2); 5933 5934 FORKEE_REQUIRE_SUCCESS 5935 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 5936 5937 forkee_status_exited(status, exitval2); 5938 5939 DPRINTF("Before exiting of the child process\n"); 5940 _exit(exitval); 5941 } 5942 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5943 5944 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5945 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5946 5947 validate_status_stopped(status, sigval); 5948 5949 DPRINTF("Enable PTRACE_VFORK_DONE in EVENT_MASK for the child %d\n", 5950 child); 5951 event.pe_set_event = PTRACE_VFORK_DONE; 5952 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5953 5954 DPRINTF("Before resuming the child process where it left off and " 5955 "without signal to be sent\n"); 5956 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5957 5958 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5959 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5960 5961 validate_status_stopped(status, sigmasked); 5962 5963 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5964 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); 5965 5966 child2 = state.pe_other_pid; 5967 DPRINTF("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2); 5968 5969 DPRINTF("Before resuming the child process where it left off and " 5970 "without signal to be sent\n"); 5971 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5972 5973 DPRINTF("Before calling %s() for the child - expected stopped " 5974 "SIGCHLD\n", TWAIT_FNAME); 5975 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5976 5977 validate_status_stopped(status, SIGCHLD); 5978 5979 DPRINTF("Before resuming the child process where it left off and " 5980 "without signal to be sent\n"); 5981 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5982 5983 DPRINTF("Before calling %s() for the child - expected exited\n", 5984 TWAIT_FNAME); 5985 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5986 5987 validate_status_exited(status, exitval); 5988 5989 DPRINTF("Before calling %s() for the child - expected no process\n", 5990 TWAIT_FNAME); 5991 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5992} 5993 5994ATF_TC(signal9); 5995ATF_TC_HEAD(signal9, tc) 5996{ 5997 atf_tc_set_md_var(tc, "descr", 5998 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5999 "catching PTRACE_LWP_CREATE breakpoint"); 6000} 6001 6002ATF_TC_BODY(signal9, tc) 6003{ 6004 const int exitval = 5; 6005 const int sigval = SIGSTOP; 6006 const int sigmasked = SIGTRAP; 6007 pid_t child, wpid; 6008#if defined(TWAIT_HAVE_STATUS) 6009 int status; 6010#endif 6011 sigset_t intmask; 6012 ptrace_state_t state; 6013 const int slen = sizeof(state); 6014 ptrace_event_t event; 6015 const int elen = sizeof(event); 6016 ucontext_t uc; 6017 lwpid_t lid; 6018 static const size_t ssize = 16*1024; 6019 void *stack; 6020 6021 atf_tc_expect_fail("PR kern/51918"); 6022 6023 DPRINTF("Before forking process PID=%d\n", getpid()); 6024 SYSCALL_REQUIRE((child = fork()) != -1); 6025 if (child == 0) { 6026 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6027 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6028 6029 sigemptyset(&intmask); 6030 sigaddset(&intmask, sigmasked); 6031 sigprocmask(SIG_BLOCK, &intmask, NULL); 6032 6033 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6034 FORKEE_ASSERT(raise(sigval) == 0); 6035 6036 DPRINTF("Before allocating memory for stack in child\n"); 6037 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 6038 6039 DPRINTF("Before making context for new lwp in child\n"); 6040 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 6041 6042 DPRINTF("Before creating new in child\n"); 6043 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 6044 6045 DPRINTF("Before waiting for lwp %d to exit\n", lid); 6046 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 6047 6048 DPRINTF("Before verifying that reported %d and running lid %d " 6049 "are the same\n", lid, the_lwp_id); 6050 FORKEE_ASSERT_EQ(lid, the_lwp_id); 6051 6052 DPRINTF("Before exiting of the child process\n"); 6053 _exit(exitval); 6054 } 6055 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6056 6057 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6058 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6059 6060 validate_status_stopped(status, sigval); 6061 6062 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 6063 event.pe_set_event = PTRACE_LWP_CREATE; 6064 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 6065 6066 DPRINTF("Before resuming the child process where it left off and " 6067 "without signal to be sent\n"); 6068 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6069 6070 DPRINTF("Before calling %s() for the child - expected stopped " 6071 "SIGTRAP\n", TWAIT_FNAME); 6072 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6073 6074 validate_status_stopped(status, sigmasked); 6075 6076 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 6077 6078 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); 6079 6080 lid = state.pe_lwp; 6081 DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); 6082 6083 DPRINTF("Before resuming the child process where it left off and " 6084 "without signal to be sent\n"); 6085 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6086 6087 DPRINTF("Before calling %s() for the child - expected exited\n", 6088 TWAIT_FNAME); 6089 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6090 6091 validate_status_exited(status, exitval); 6092 6093 DPRINTF("Before calling %s() for the child - expected no process\n", 6094 TWAIT_FNAME); 6095 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6096} 6097 6098ATF_TC(signal10); 6099ATF_TC_HEAD(signal10, tc) 6100{ 6101 atf_tc_set_md_var(tc, "descr", 6102 "Verify that masking SIGTRAP in tracee does not stop tracer from " 6103 "catching PTRACE_LWP_EXIT breakpoint"); 6104} 6105 6106ATF_TC_BODY(signal10, tc) 6107{ 6108 const int exitval = 5; 6109 const int sigval = SIGSTOP; 6110 const int sigmasked = SIGTRAP; 6111 pid_t child, wpid; 6112#if defined(TWAIT_HAVE_STATUS) 6113 int status; 6114#endif 6115 sigset_t intmask; 6116 ptrace_state_t state; 6117 const int slen = sizeof(state); 6118 ptrace_event_t event; 6119 const int elen = sizeof(event); 6120 ucontext_t uc; 6121 lwpid_t lid; 6122 static const size_t ssize = 16*1024; 6123 void *stack; 6124 6125 atf_tc_expect_fail("PR kern/51918"); 6126 6127 DPRINTF("Before forking process PID=%d\n", getpid()); 6128 SYSCALL_REQUIRE((child = fork()) != -1); 6129 if (child == 0) { 6130 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6131 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6132 6133 sigemptyset(&intmask); 6134 sigaddset(&intmask, sigmasked); 6135 sigprocmask(SIG_BLOCK, &intmask, NULL); 6136 6137 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6138 FORKEE_ASSERT(raise(sigval) == 0); 6139 6140 DPRINTF("Before allocating memory for stack in child\n"); 6141 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 6142 6143 DPRINTF("Before making context for new lwp in child\n"); 6144 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 6145 6146 DPRINTF("Before creating new in child\n"); 6147 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 6148 6149 DPRINTF("Before waiting for lwp %d to exit\n", lid); 6150 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 6151 6152 DPRINTF("Before verifying that reported %d and running lid %d " 6153 "are the same\n", lid, the_lwp_id); 6154 FORKEE_ASSERT_EQ(lid, the_lwp_id); 6155 6156 DPRINTF("Before exiting of the child process\n"); 6157 _exit(exitval); 6158 } 6159 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6160 6161 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6162 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6163 6164 validate_status_stopped(status, sigval); 6165 6166 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 6167 event.pe_set_event = PTRACE_LWP_EXIT; 6168 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 6169 6170 DPRINTF("Before resuming the child process where it left off and " 6171 "without signal to be sent\n"); 6172 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6173 6174 DPRINTF("Before calling %s() for the child - expected stopped " 6175 "SIGTRAP\n", TWAIT_FNAME); 6176 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6177 6178 validate_status_stopped(status, sigmasked); 6179 6180 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 6181 6182 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); 6183 6184 lid = state.pe_lwp; 6185 DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); 6186 6187 DPRINTF("Before resuming the child process where it left off and " 6188 "without signal to be sent\n"); 6189 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6190 6191 DPRINTF("Before calling %s() for the child - expected exited\n", 6192 TWAIT_FNAME); 6193 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6194 6195 validate_status_exited(status, exitval); 6196 6197 DPRINTF("Before calling %s() for the child - expected no process\n", 6198 TWAIT_FNAME); 6199 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6200} 6201 6202static void 6203lwp_main_stop(void *arg) 6204{ 6205 the_lwp_id = _lwp_self(); 6206 6207 raise(SIGTRAP); 6208 6209 _lwp_exit(); 6210} 6211 6212ATF_TC(suspend1); 6213ATF_TC_HEAD(suspend1, tc) 6214{ 6215 atf_tc_set_md_var(tc, "descr", 6216 "Verify that a thread can be suspended by a debugger and later " 6217 "resumed by a tracee"); 6218} 6219 6220ATF_TC_BODY(suspend1, tc) 6221{ 6222 const int exitval = 5; 6223 const int sigval = SIGSTOP; 6224 pid_t child, wpid; 6225#if defined(TWAIT_HAVE_STATUS) 6226 int status; 6227#endif 6228 ucontext_t uc; 6229 lwpid_t lid; 6230 static const size_t ssize = 16*1024; 6231 void *stack; 6232 struct ptrace_lwpinfo pl; 6233 struct ptrace_siginfo psi; 6234 volatile int go = 0; 6235 6236 // Feature pending for refactoring 6237 atf_tc_expect_fail("PR kern/51995"); 6238 6239 // Hangs with qemu 6240 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 6241 6242 DPRINTF("Before forking process PID=%d\n", getpid()); 6243 SYSCALL_REQUIRE((child = fork()) != -1); 6244 if (child == 0) { 6245 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6246 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6247 6248 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6249 FORKEE_ASSERT(raise(sigval) == 0); 6250 6251 DPRINTF("Before allocating memory for stack in child\n"); 6252 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 6253 6254 DPRINTF("Before making context for new lwp in child\n"); 6255 _lwp_makecontext(&uc, lwp_main_stop, NULL, NULL, stack, ssize); 6256 6257 DPRINTF("Before creating new in child\n"); 6258 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 6259 6260 while (go == 0) 6261 continue; 6262 6263 raise(SIGINT); 6264 6265 FORKEE_ASSERT(_lwp_continue(lid) == 0); 6266 6267 DPRINTF("Before waiting for lwp %d to exit\n", lid); 6268 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 6269 6270 DPRINTF("Before verifying that reported %d and running lid %d " 6271 "are the same\n", lid, the_lwp_id); 6272 FORKEE_ASSERT_EQ(lid, the_lwp_id); 6273 6274 DPRINTF("Before exiting of the child process\n"); 6275 _exit(exitval); 6276 } 6277 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6278 6279 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6280 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6281 6282 validate_status_stopped(status, sigval); 6283 6284 DPRINTF("Before resuming the child process where it left off and " 6285 "without signal to be sent\n"); 6286 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6287 6288 DPRINTF("Before calling %s() for the child - expected stopped " 6289 "SIGTRAP\n", TWAIT_FNAME); 6290 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6291 6292 validate_status_stopped(status, SIGTRAP); 6293 6294 DPRINTF("Before reading siginfo and lwpid_t\n"); 6295 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 6296 6297 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 6298 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 6299 6300 DPRINTF("Write new go to tracee (PID=%d) from tracer (PID=%d)\n", 6301 child, getpid()); 6302 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, __UNVOLATILE(&go), 1) != -1); 6303 6304 DPRINTF("Before resuming the child process where it left off and " 6305 "without signal to be sent\n"); 6306 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6307 6308 DPRINTF("Before calling %s() for the child - expected stopped " 6309 "SIGINT\n", TWAIT_FNAME); 6310 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6311 6312 validate_status_stopped(status, SIGINT); 6313 6314 pl.pl_lwpid = 0; 6315 6316 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 6317 while (pl.pl_lwpid != 0) { 6318 6319 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 6320 switch (pl.pl_lwpid) { 6321 case 1: 6322 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL); 6323 break; 6324 case 2: 6325 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SUSPENDED); 6326 break; 6327 } 6328 } 6329 6330 DPRINTF("Before resuming the child process where it left off and " 6331 "without signal to be sent\n"); 6332 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6333 6334 DPRINTF("Before calling %s() for the child - expected exited\n", 6335 TWAIT_FNAME); 6336 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6337 6338 validate_status_exited(status, exitval); 6339 6340 DPRINTF("Before calling %s() for the child - expected no process\n", 6341 TWAIT_FNAME); 6342 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6343} 6344 6345ATF_TC(suspend2); 6346ATF_TC_HEAD(suspend2, tc) 6347{ 6348 atf_tc_set_md_var(tc, "descr", 6349 "Verify that the while the only thread within a process is " 6350 "suspended, the whole process cannot be unstopped"); 6351} 6352 6353ATF_TC_BODY(suspend2, tc) 6354{ 6355 const int exitval = 5; 6356 const int sigval = SIGSTOP; 6357 pid_t child, wpid; 6358#if defined(TWAIT_HAVE_STATUS) 6359 int status; 6360#endif 6361 struct ptrace_siginfo psi; 6362 6363 // Feature pending for refactoring 6364 atf_tc_expect_fail("PR kern/51995"); 6365 6366 // Hangs with qemu 6367 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 6368 6369 DPRINTF("Before forking process PID=%d\n", getpid()); 6370 SYSCALL_REQUIRE((child = fork()) != -1); 6371 if (child == 0) { 6372 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6373 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6374 6375 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6376 FORKEE_ASSERT(raise(sigval) == 0); 6377 6378 DPRINTF("Before exiting of the child process\n"); 6379 _exit(exitval); 6380 } 6381 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6382 6383 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6384 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6385 6386 validate_status_stopped(status, sigval); 6387 6388 DPRINTF("Before reading siginfo and lwpid_t\n"); 6389 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 6390 6391 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 6392 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 6393 6394 DPRINTF("Before resuming the child process where it left off and " 6395 "without signal to be sent\n"); 6396 ATF_REQUIRE_ERRNO(EDEADLK, 6397 ptrace(PT_CONTINUE, child, (void *)1, 0) == -1); 6398 6399 DPRINTF("Before resuming LWP %d\n", psi.psi_lwpid); 6400 SYSCALL_REQUIRE(ptrace(PT_RESUME, child, NULL, psi.psi_lwpid) != -1); 6401 6402 DPRINTF("Before resuming the child process where it left off and " 6403 "without signal to be sent\n"); 6404 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6405 6406 DPRINTF("Before calling %s() for the child - expected exited\n", 6407 TWAIT_FNAME); 6408 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6409 6410 validate_status_exited(status, exitval); 6411 6412 DPRINTF("Before calling %s() for the child - expected no process\n", 6413 TWAIT_FNAME); 6414 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6415} 6416 6417ATF_TC(resume1); 6418ATF_TC_HEAD(resume1, tc) 6419{ 6420 atf_tc_set_md_var(tc, "timeout", "5"); 6421 atf_tc_set_md_var(tc, "descr", 6422 "Verify that a thread can be suspended by a debugger and later " 6423 "resumed by the debugger"); 6424} 6425 6426ATF_TC_BODY(resume1, tc) 6427{ 6428 struct msg_fds fds; 6429 const int exitval = 5; 6430 const int sigval = SIGSTOP; 6431 pid_t child, wpid; 6432 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 6433#if defined(TWAIT_HAVE_STATUS) 6434 int status; 6435#endif 6436 ucontext_t uc; 6437 lwpid_t lid; 6438 static const size_t ssize = 16*1024; 6439 void *stack; 6440 struct ptrace_lwpinfo pl; 6441 struct ptrace_siginfo psi; 6442 6443 // Feature pending for refactoring 6444 atf_tc_expect_fail("PR kern/51995"); 6445 6446 // Hangs with qemu 6447 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 6448 6449 SYSCALL_REQUIRE(msg_open(&fds) == 0); 6450 6451 DPRINTF("Before forking process PID=%d\n", getpid()); 6452 SYSCALL_REQUIRE((child = fork()) != -1); 6453 if (child == 0) { 6454 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6455 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6456 6457 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6458 FORKEE_ASSERT(raise(sigval) == 0); 6459 6460 DPRINTF("Before allocating memory for stack in child\n"); 6461 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 6462 6463 DPRINTF("Before making context for new lwp in child\n"); 6464 _lwp_makecontext(&uc, lwp_main_stop, NULL, NULL, stack, ssize); 6465 6466 DPRINTF("Before creating new in child\n"); 6467 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 6468 6469 CHILD_TO_PARENT("Message", fds, msg); 6470 6471 raise(SIGINT); 6472 6473 DPRINTF("Before waiting for lwp %d to exit\n", lid); 6474 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 6475 6476 DPRINTF("Before verifying that reported %d and running lid %d " 6477 "are the same\n", lid, the_lwp_id); 6478 FORKEE_ASSERT_EQ(lid, the_lwp_id); 6479 6480 DPRINTF("Before exiting of the child process\n"); 6481 _exit(exitval); 6482 } 6483 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6484 6485 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6486 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6487 6488 validate_status_stopped(status, sigval); 6489 6490 DPRINTF("Before resuming the child process where it left off and " 6491 "without signal to be sent\n"); 6492 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6493 6494 DPRINTF("Before calling %s() for the child - expected stopped " 6495 "SIGTRAP\n", TWAIT_FNAME); 6496 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6497 6498 validate_status_stopped(status, SIGTRAP); 6499 6500 DPRINTF("Before reading siginfo and lwpid_t\n"); 6501 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 6502 6503 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 6504 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 6505 6506 PARENT_FROM_CHILD("Message", fds, msg); 6507 6508 DPRINTF("Before resuming the child process where it left off and " 6509 "without signal to be sent\n"); 6510 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6511 6512 DPRINTF("Before calling %s() for the child - expected stopped " 6513 "SIGINT\n", TWAIT_FNAME); 6514 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6515 6516 validate_status_stopped(status, SIGINT); 6517 6518 pl.pl_lwpid = 0; 6519 6520 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 6521 while (pl.pl_lwpid != 0) { 6522 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 6523 switch (pl.pl_lwpid) { 6524 case 1: 6525 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL); 6526 break; 6527 case 2: 6528 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SUSPENDED); 6529 break; 6530 } 6531 } 6532 6533 DPRINTF("Before resuming LWP %d\n", psi.psi_lwpid); 6534 SYSCALL_REQUIRE(ptrace(PT_RESUME, child, NULL, psi.psi_lwpid) != -1); 6535 6536 DPRINTF("Before resuming the child process where it left off and " 6537 "without signal to be sent\n"); 6538 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6539 6540 DPRINTF("Before calling %s() for the child - expected exited\n", 6541 TWAIT_FNAME); 6542 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6543 6544 validate_status_exited(status, exitval); 6545 6546 DPRINTF("Before calling %s() for the child - expected no process\n", 6547 TWAIT_FNAME); 6548 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6549 6550 msg_close(&fds); 6551 6552 DPRINTF("XXX: Test worked this time but for consistency timeout it\n"); 6553 sleep(10); 6554} 6555 6556ATF_TC(syscall1); 6557ATF_TC_HEAD(syscall1, tc) 6558{ 6559 atf_tc_set_md_var(tc, "descr", 6560 "Verify that getpid(2) can be traced with PT_SYSCALL"); 6561} 6562 6563ATF_TC_BODY(syscall1, tc) 6564{ 6565 const int exitval = 5; 6566 const int sigval = SIGSTOP; 6567 pid_t child, wpid; 6568#if defined(TWAIT_HAVE_STATUS) 6569 int status; 6570#endif 6571 struct ptrace_siginfo info; 6572 memset(&info, 0, sizeof(info)); 6573 6574 DPRINTF("Before forking process PID=%d\n", getpid()); 6575 SYSCALL_REQUIRE((child = fork()) != -1); 6576 if (child == 0) { 6577 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6578 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6579 6580 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6581 FORKEE_ASSERT(raise(sigval) == 0); 6582 6583 syscall(SYS_getpid); 6584 6585 DPRINTF("Before exiting of the child process\n"); 6586 _exit(exitval); 6587 } 6588 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6589 6590 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6591 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6592 6593 validate_status_stopped(status, sigval); 6594 6595 DPRINTF("Before resuming the child process where it left off and " 6596 "without signal to be sent\n"); 6597 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 6598 6599 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6600 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6601 6602 validate_status_stopped(status, SIGTRAP); 6603 6604 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 6605 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 6606 6607 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 6608 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); 6609 6610 DPRINTF("Before resuming the child process where it left off and " 6611 "without signal to be sent\n"); 6612 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 6613 6614 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6615 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6616 6617 validate_status_stopped(status, SIGTRAP); 6618 6619 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 6620 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 6621 6622 DPRINTF("Before checking siginfo_t\n"); 6623 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 6624 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); 6625 6626 DPRINTF("Before resuming the child process where it left off and " 6627 "without signal to be sent\n"); 6628 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6629 6630 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6631 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6632 6633 validate_status_exited(status, exitval); 6634 6635 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6636 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6637} 6638 6639ATF_TC(syscallemu1); 6640ATF_TC_HEAD(syscallemu1, tc) 6641{ 6642 atf_tc_set_md_var(tc, "descr", 6643 "Verify that exit(2) can be intercepted with PT_SYSCALLEMU"); 6644} 6645 6646ATF_TC_BODY(syscallemu1, tc) 6647{ 6648 const int exitval = 5; 6649 const int sigval = SIGSTOP; 6650 pid_t child, wpid; 6651#if defined(TWAIT_HAVE_STATUS) 6652 int status; 6653#endif 6654 6655#if defined(__sparc__) && !defined(__sparc64__) 6656 /* syscallemu does not work on sparc (32-bit) */ 6657 atf_tc_expect_fail("PR kern/52166"); 6658#endif 6659 6660 DPRINTF("Before forking process PID=%d\n", getpid()); 6661 SYSCALL_REQUIRE((child = fork()) != -1); 6662 if (child == 0) { 6663 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 6664 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 6665 6666 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 6667 FORKEE_ASSERT(raise(sigval) == 0); 6668 6669 syscall(SYS_exit, 100); 6670 6671 DPRINTF("Before exiting of the child process\n"); 6672 _exit(exitval); 6673 } 6674 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 6675 6676 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6677 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6678 6679 validate_status_stopped(status, sigval); 6680 6681 DPRINTF("Before resuming the child process where it left off and " 6682 "without signal to be sent\n"); 6683 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 6684 6685 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6686 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6687 6688 validate_status_stopped(status, SIGTRAP); 6689 6690 DPRINTF("Set SYSCALLEMU for intercepted syscall\n"); 6691 SYSCALL_REQUIRE(ptrace(PT_SYSCALLEMU, child, (void *)1, 0) != -1); 6692 6693 DPRINTF("Before resuming the child process where it left off and " 6694 "without signal to be sent\n"); 6695 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 6696 6697 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6698 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6699 6700 validate_status_stopped(status, SIGTRAP); 6701 6702 DPRINTF("Before resuming the child process where it left off and " 6703 "without signal to be sent\n"); 6704 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 6705 6706 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6707 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 6708 6709 validate_status_exited(status, exitval); 6710 6711 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 6712 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 6713} 6714 6715#if defined(TWAIT_HAVE_PID) 6716ATF_TC(race1); 6717ATF_TC_HEAD(race1, tc) 6718{ 6719 atf_tc_set_md_var(tc, "descr", 6720 "Assert that await_zombie() in attach1 always finds a single " 6721 "process and no other error is reported"); 6722} 6723 6724ATF_TC_BODY(race1, tc) 6725{ 6726 time_t start, end; 6727 double diff; 6728 unsigned long N = 0; 6729 6730 /* Reuse this test with attach1 */ 6731 6732 start = time(NULL); 6733 while (true) { 6734 DPRINTF("Step: %lu\n", N); 6735 attach1_raw(true); 6736 end = time(NULL); 6737 diff = difftime(end, start); 6738 if (diff >= 5.0) 6739 break; 6740 ++N; 6741 } 6742 DPRINTF("Iterations: %lu\n", N); 6743} 6744#endif 6745 6746#include "t_ptrace_amd64_wait.h" 6747#include "t_ptrace_i386_wait.h" 6748#include "t_ptrace_x86_wait.h" 6749 6750ATF_TP_ADD_TCS(tp) 6751{ 6752 setvbuf(stdout, NULL, _IONBF, 0); 6753 setvbuf(stderr, NULL, _IONBF, 0); 6754 ATF_TP_ADD_TC(tp, traceme1); 6755 ATF_TP_ADD_TC(tp, traceme2); 6756 ATF_TP_ADD_TC(tp, traceme3); 6757 ATF_TP_ADD_TC(tp, traceme4); 6758 6759 ATF_TP_ADD_TC_HAVE_PID(tp, attach1); 6760 ATF_TP_ADD_TC_HAVE_PID(tp, attach2); 6761 ATF_TP_ADD_TC(tp, attach3); 6762 ATF_TP_ADD_TC(tp, attach4); 6763 ATF_TP_ADD_TC_HAVE_PID(tp, attach5); 6764 ATF_TP_ADD_TC_HAVE_PID(tp, attach6); 6765 ATF_TP_ADD_TC_HAVE_PID(tp, attach7); 6766 6767 ATF_TP_ADD_TC(tp, eventmask1); 6768 ATF_TP_ADD_TC(tp, eventmask2); 6769 ATF_TP_ADD_TC(tp, eventmask3); 6770 ATF_TP_ADD_TC(tp, eventmask4); 6771 ATF_TP_ADD_TC(tp, eventmask5); 6772 ATF_TP_ADD_TC(tp, eventmask6); 6773 6774 ATF_TP_ADD_TC(tp, fork1); 6775 ATF_TP_ADD_TC_HAVE_PID(tp, fork2); 6776 ATF_TP_ADD_TC_HAVE_PID(tp, fork3); 6777 ATF_TP_ADD_TC_HAVE_PID(tp, fork4); 6778 ATF_TP_ADD_TC(tp, fork5); 6779 ATF_TP_ADD_TC_HAVE_PID(tp, fork6); 6780 ATF_TP_ADD_TC_HAVE_PID(tp, fork7); 6781 ATF_TP_ADD_TC_HAVE_PID(tp, fork8); 6782 6783 ATF_TP_ADD_TC(tp, vfork1); 6784 ATF_TP_ADD_TC_HAVE_PID(tp, vfork2); 6785 ATF_TP_ADD_TC_HAVE_PID(tp, vfork3); 6786 ATF_TP_ADD_TC_HAVE_PID(tp, vfork4); 6787 ATF_TP_ADD_TC(tp, vfork5); 6788 ATF_TP_ADD_TC_HAVE_PID(tp, vfork6); 6789 ATF_TP_ADD_TC_HAVE_PID(tp, vfork7); 6790 ATF_TP_ADD_TC_HAVE_PID(tp, vfork8); 6791 6792 ATF_TP_ADD_TC(tp, io_read_d1); 6793 ATF_TP_ADD_TC(tp, io_read_d2); 6794 ATF_TP_ADD_TC(tp, io_read_d3); 6795 ATF_TP_ADD_TC(tp, io_read_d4); 6796 6797 ATF_TP_ADD_TC(tp, io_write_d1); 6798 ATF_TP_ADD_TC(tp, io_write_d2); 6799 ATF_TP_ADD_TC(tp, io_write_d3); 6800 ATF_TP_ADD_TC(tp, io_write_d4); 6801 6802 ATF_TP_ADD_TC(tp, read_d1); 6803 ATF_TP_ADD_TC(tp, read_d2); 6804 ATF_TP_ADD_TC(tp, read_d3); 6805 ATF_TP_ADD_TC(tp, read_d4); 6806 6807 ATF_TP_ADD_TC(tp, write_d1); 6808 ATF_TP_ADD_TC(tp, write_d2); 6809 ATF_TP_ADD_TC(tp, write_d3); 6810 ATF_TP_ADD_TC(tp, write_d4); 6811 6812 ATF_TP_ADD_TC(tp, io_read_d_write_d_handshake1); 6813 ATF_TP_ADD_TC(tp, io_read_d_write_d_handshake2); 6814 6815 ATF_TP_ADD_TC(tp, read_d_write_d_handshake1); 6816 ATF_TP_ADD_TC(tp, read_d_write_d_handshake2); 6817 6818 ATF_TP_ADD_TC(tp, io_read_i1); 6819 ATF_TP_ADD_TC(tp, io_read_i2); 6820 ATF_TP_ADD_TC(tp, io_read_i3); 6821 ATF_TP_ADD_TC(tp, io_read_i4); 6822 6823 ATF_TP_ADD_TC(tp, read_i1); 6824 ATF_TP_ADD_TC(tp, read_i2); 6825 ATF_TP_ADD_TC(tp, read_i3); 6826 ATF_TP_ADD_TC(tp, read_i4); 6827 6828 ATF_TP_ADD_TC(tp, io_read_auxv1); 6829 6830 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); 6831 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2); 6832 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3); 6833 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs4); 6834 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs5); 6835 6836 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs1); 6837 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs2); 6838 6839 ATF_TP_ADD_TC_PT_STEP(tp, step1); 6840 ATF_TP_ADD_TC_PT_STEP(tp, step2); 6841 ATF_TP_ADD_TC_PT_STEP(tp, step3); 6842 ATF_TP_ADD_TC_PT_STEP(tp, step4); 6843 6844 ATF_TP_ADD_TC_PT_STEP(tp, setstep1); 6845 ATF_TP_ADD_TC_PT_STEP(tp, setstep2); 6846 ATF_TP_ADD_TC_PT_STEP(tp, setstep3); 6847 ATF_TP_ADD_TC_PT_STEP(tp, setstep4); 6848 6849 ATF_TP_ADD_TC(tp, kill1); 6850 ATF_TP_ADD_TC(tp, kill2); 6851 6852 ATF_TP_ADD_TC(tp, lwpinfo1); 6853 ATF_TP_ADD_TC_HAVE_PID(tp, lwpinfo2); 6854 6855 ATF_TP_ADD_TC(tp, siginfo1); 6856 ATF_TP_ADD_TC(tp, siginfo2); 6857 ATF_TP_ADD_TC(tp, siginfo3); 6858 ATF_TP_ADD_TC(tp, siginfo4); 6859 ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5); 6860 ATF_TP_ADD_TC_PT_STEP(tp, siginfo6); 6861 6862 ATF_TP_ADD_TC(tp, lwp_create1); 6863 6864 ATF_TP_ADD_TC(tp, lwp_exit1); 6865 6866 ATF_TP_ADD_TC(tp, signal1); 6867 ATF_TP_ADD_TC(tp, signal2); 6868 ATF_TP_ADD_TC(tp, signal3); 6869 ATF_TP_ADD_TC_PT_STEP(tp, signal4); 6870 ATF_TP_ADD_TC(tp, signal5); 6871 ATF_TP_ADD_TC_HAVE_PID(tp, signal6); 6872 ATF_TP_ADD_TC_HAVE_PID(tp, signal7); 6873 ATF_TP_ADD_TC(tp, signal8); 6874 ATF_TP_ADD_TC(tp, signal9); 6875 ATF_TP_ADD_TC(tp, signal10); 6876 6877 ATF_TP_ADD_TC(tp, suspend1); 6878 ATF_TP_ADD_TC(tp, suspend2); 6879 6880 ATF_TP_ADD_TC(tp, resume1); 6881 6882 ATF_TP_ADD_TC(tp, syscall1); 6883 6884 ATF_TP_ADD_TC(tp, syscallemu1); 6885 6886 ATF_TP_ADD_TC_HAVE_PID(tp, race1); 6887 6888 ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64(); 6889 ATF_TP_ADD_TCS_PTRACE_WAIT_I386(); 6890 ATF_TP_ADD_TCS_PTRACE_WAIT_X86(); 6891 6892 return atf_no_error(); 6893} 6894