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