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