| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_ptrace_wait.c,v 1.67 2017/01/27 16:06:23 kamil Exp $ */ | | 1 | /* $NetBSD: t_ptrace_wait.c,v 1.68 2017/01/27 16:35:47 kamil Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 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 | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.67 2017/01/27 16:06:23 kamil Exp $"); | | 30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.68 2017/01/27 16:35:47 kamil Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/types.h> | | 33 | #include <sys/types.h> |
34 | #include <sys/ptrace.h> | | 34 | #include <sys/ptrace.h> |
35 | #include <sys/resource.h> | | 35 | #include <sys/resource.h> |
36 | #include <sys/stat.h> | | 36 | #include <sys/stat.h> |
37 | #include <sys/sysctl.h> | | 37 | #include <sys/sysctl.h> |
38 | #include <sys/wait.h> | | 38 | #include <sys/wait.h> |
39 | #include <machine/reg.h> | | 39 | #include <machine/reg.h> |
40 | #include <elf.h> | | 40 | #include <elf.h> |
41 | #include <err.h> | | 41 | #include <err.h> |
42 | #include <errno.h> | | 42 | #include <errno.h> |
43 | #include <lwp.h> | | 43 | #include <lwp.h> |
| @@ -6366,26 +6366,234 @@ ATF_TC_BODY(signal8, tc) | | | @@ -6366,26 +6366,234 @@ ATF_TC_BODY(signal8, tc) |
6366 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); | | 6366 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
6367 | | | 6367 | |
6368 | printf("Before calling %s() for the child - expected exited\n", | | 6368 | printf("Before calling %s() for the child - expected exited\n", |
6369 | TWAIT_FNAME); | | 6369 | TWAIT_FNAME); |
6370 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); | | 6370 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
6371 | | | 6371 | |
6372 | validate_status_exited(status, exitval); | | 6372 | validate_status_exited(status, exitval); |
6373 | | | 6373 | |
6374 | printf("Before calling %s() for the child - expected no process\n", | | 6374 | printf("Before calling %s() for the child - expected no process\n", |
6375 | TWAIT_FNAME); | | 6375 | TWAIT_FNAME); |
6376 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); | | 6376 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
6377 | } | | 6377 | } |
6378 | | | 6378 | |
| | | 6379 | ATF_TC(signal9); |
| | | 6380 | ATF_TC_HEAD(signal9, tc) |
| | | 6381 | { |
| | | 6382 | atf_tc_set_md_var(tc, "descr", |
| | | 6383 | "Verify that masking SIGTRAP in tracee does not stop tracer from " |
| | | 6384 | "catching PTRACE_LWP_CREATE breakpoint"); |
| | | 6385 | } |
| | | 6386 | |
| | | 6387 | ATF_TC_BODY(signal9, tc) |
| | | 6388 | { |
| | | 6389 | const int exitval = 5; |
| | | 6390 | const int sigval = SIGSTOP; |
| | | 6391 | const int sigmasked = SIGTRAP; |
| | | 6392 | pid_t child, wpid; |
| | | 6393 | #if defined(TWAIT_HAVE_STATUS) |
| | | 6394 | int status; |
| | | 6395 | #endif |
| | | 6396 | sigset_t intmask; |
| | | 6397 | ptrace_state_t state; |
| | | 6398 | const int slen = sizeof(state); |
| | | 6399 | ptrace_event_t event; |
| | | 6400 | const int elen = sizeof(event); |
| | | 6401 | ucontext_t uc; |
| | | 6402 | lwpid_t lid; |
| | | 6403 | static const size_t ssize = 16*1024; |
| | | 6404 | void *stack; |
| | | 6405 | |
| | | 6406 | atf_tc_expect_fail("PR kern/51918"); |
| | | 6407 | |
| | | 6408 | printf("Before forking process PID=%d\n", getpid()); |
| | | 6409 | ATF_REQUIRE((child = fork()) != -1); |
| | | 6410 | if (child == 0) { |
| | | 6411 | printf("Before calling PT_TRACE_ME from child %d\n", getpid()); |
| | | 6412 | FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); |
| | | 6413 | |
| | | 6414 | sigemptyset(&intmask); |
| | | 6415 | sigaddset(&intmask, sigmasked); |
| | | 6416 | sigprocmask(SIG_BLOCK, &intmask, NULL); |
| | | 6417 | |
| | | 6418 | printf("Before raising %s from child\n", strsignal(sigval)); |
| | | 6419 | FORKEE_ASSERT(raise(sigval) == 0); |
| | | 6420 | |
| | | 6421 | printf("Before allocating memory for stack in child\n"); |
| | | 6422 | FORKEE_ASSERT((stack = malloc(ssize)) != NULL); |
| | | 6423 | |
| | | 6424 | printf("Before making context for new lwp in child\n"); |
| | | 6425 | _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); |
| | | 6426 | |
| | | 6427 | printf("Before creating new in child\n"); |
| | | 6428 | FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); |
| | | 6429 | |
| | | 6430 | printf("Before waiting for lwp %d to exit\n", lid); |
| | | 6431 | FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); |
| | | 6432 | |
| | | 6433 | printf("Before verifying that reported %d and running lid %d " |
| | | 6434 | "are the same\n", lid, the_lwp_id); |
| | | 6435 | FORKEE_ASSERT_EQ(lid, the_lwp_id); |
| | | 6436 | |
| | | 6437 | printf("Before exiting of the child process\n"); |
| | | 6438 | _exit(exitval); |
| | | 6439 | } |
| | | 6440 | printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); |
| | | 6441 | |
| | | 6442 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 6443 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6444 | |
| | | 6445 | validate_status_stopped(status, sigval); |
| | | 6446 | |
| | | 6447 | printf("Set empty EVENT_MASK for the child %d\n", child); |
| | | 6448 | event.pe_set_event = PTRACE_LWP_CREATE; |
| | | 6449 | ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); |
| | | 6450 | |
| | | 6451 | printf("Before resuming the child process where it left off and " |
| | | 6452 | "without signal to be sent\n"); |
| | | 6453 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 6454 | |
| | | 6455 | printf("Before calling %s() for the child - expected stopped " |
| | | 6456 | "SIGTRAP\n", TWAIT_FNAME); |
| | | 6457 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6458 | |
| | | 6459 | validate_status_stopped(status, sigmasked); |
| | | 6460 | |
| | | 6461 | ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); |
| | | 6462 | |
| | | 6463 | ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); |
| | | 6464 | |
| | | 6465 | lid = state.pe_lwp; |
| | | 6466 | printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); |
| | | 6467 | |
| | | 6468 | printf("Before resuming the child process where it left off and " |
| | | 6469 | "without signal to be sent\n"); |
| | | 6470 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 6471 | |
| | | 6472 | printf("Before calling %s() for the child - expected exited\n", |
| | | 6473 | TWAIT_FNAME); |
| | | 6474 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6475 | |
| | | 6476 | validate_status_exited(status, exitval); |
| | | 6477 | |
| | | 6478 | printf("Before calling %s() for the child - expected no process\n", |
| | | 6479 | TWAIT_FNAME); |
| | | 6480 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
| | | 6481 | } |
| | | 6482 | |
| | | 6483 | ATF_TC(signal10); |
| | | 6484 | ATF_TC_HEAD(signal10, tc) |
| | | 6485 | { |
| | | 6486 | atf_tc_set_md_var(tc, "descr", |
| | | 6487 | "Verify that masking SIGTRAP in tracee does not stop tracer from " |
| | | 6488 | "catching PTRACE_LWP_EXIT breakpoint"); |
| | | 6489 | } |
| | | 6490 | |
| | | 6491 | ATF_TC_BODY(signal10, tc) |
| | | 6492 | { |
| | | 6493 | const int exitval = 5; |
| | | 6494 | const int sigval = SIGSTOP; |
| | | 6495 | const int sigmasked = SIGTRAP; |
| | | 6496 | pid_t child, wpid; |
| | | 6497 | #if defined(TWAIT_HAVE_STATUS) |
| | | 6498 | int status; |
| | | 6499 | #endif |
| | | 6500 | sigset_t intmask; |
| | | 6501 | ptrace_state_t state; |
| | | 6502 | const int slen = sizeof(state); |
| | | 6503 | ptrace_event_t event; |
| | | 6504 | const int elen = sizeof(event); |
| | | 6505 | ucontext_t uc; |
| | | 6506 | lwpid_t lid; |
| | | 6507 | static const size_t ssize = 16*1024; |
| | | 6508 | void *stack; |
| | | 6509 | |
| | | 6510 | atf_tc_expect_fail("PR kern/51918"); |
| | | 6511 | |
| | | 6512 | printf("Before forking process PID=%d\n", getpid()); |
| | | 6513 | ATF_REQUIRE((child = fork()) != -1); |
| | | 6514 | if (child == 0) { |
| | | 6515 | printf("Before calling PT_TRACE_ME from child %d\n", getpid()); |
| | | 6516 | FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); |
| | | 6517 | |
| | | 6518 | sigemptyset(&intmask); |
| | | 6519 | sigaddset(&intmask, sigmasked); |
| | | 6520 | sigprocmask(SIG_BLOCK, &intmask, NULL); |
| | | 6521 | |
| | | 6522 | printf("Before raising %s from child\n", strsignal(sigval)); |
| | | 6523 | FORKEE_ASSERT(raise(sigval) == 0); |
| | | 6524 | |
| | | 6525 | printf("Before allocating memory for stack in child\n"); |
| | | 6526 | FORKEE_ASSERT((stack = malloc(ssize)) != NULL); |
| | | 6527 | |
| | | 6528 | printf("Before making context for new lwp in child\n"); |
| | | 6529 | _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); |
| | | 6530 | |
| | | 6531 | printf("Before creating new in child\n"); |
| | | 6532 | FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); |
| | | 6533 | |
| | | 6534 | printf("Before waiting for lwp %d to exit\n", lid); |
| | | 6535 | FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); |
| | | 6536 | |
| | | 6537 | printf("Before verifying that reported %d and running lid %d " |
| | | 6538 | "are the same\n", lid, the_lwp_id); |
| | | 6539 | FORKEE_ASSERT_EQ(lid, the_lwp_id); |
| | | 6540 | |
| | | 6541 | printf("Before exiting of the child process\n"); |
| | | 6542 | _exit(exitval); |
| | | 6543 | } |
| | | 6544 | printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); |
| | | 6545 | |
| | | 6546 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 6547 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6548 | |
| | | 6549 | validate_status_stopped(status, sigval); |
| | | 6550 | |
| | | 6551 | printf("Set empty EVENT_MASK for the child %d\n", child); |
| | | 6552 | event.pe_set_event = PTRACE_LWP_EXIT; |
| | | 6553 | ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); |
| | | 6554 | |
| | | 6555 | printf("Before resuming the child process where it left off and " |
| | | 6556 | "without signal to be sent\n"); |
| | | 6557 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 6558 | |
| | | 6559 | printf("Before calling %s() for the child - expected stopped " |
| | | 6560 | "SIGTRAP\n", TWAIT_FNAME); |
| | | 6561 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6562 | |
| | | 6563 | validate_status_stopped(status, sigmasked); |
| | | 6564 | |
| | | 6565 | ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); |
| | | 6566 | |
| | | 6567 | ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); |
| | | 6568 | |
| | | 6569 | lid = state.pe_lwp; |
| | | 6570 | printf("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); |
| | | 6571 | |
| | | 6572 | printf("Before resuming the child process where it left off and " |
| | | 6573 | "without signal to be sent\n"); |
| | | 6574 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 6575 | |
| | | 6576 | printf("Before calling %s() for the child - expected exited\n", |
| | | 6577 | TWAIT_FNAME); |
| | | 6578 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 6579 | |
| | | 6580 | validate_status_exited(status, exitval); |
| | | 6581 | |
| | | 6582 | printf("Before calling %s() for the child - expected no process\n", |
| | | 6583 | TWAIT_FNAME); |
| | | 6584 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
| | | 6585 | } |
| | | 6586 | |
6379 | ATF_TP_ADD_TCS(tp) | | 6587 | ATF_TP_ADD_TCS(tp) |
6380 | { | | 6588 | { |
6381 | setvbuf(stdout, NULL, _IONBF, 0); | | 6589 | setvbuf(stdout, NULL, _IONBF, 0); |
6382 | setvbuf(stderr, NULL, _IONBF, 0); | | 6590 | setvbuf(stderr, NULL, _IONBF, 0); |
6383 | ATF_TP_ADD_TC(tp, traceme1); | | 6591 | ATF_TP_ADD_TC(tp, traceme1); |
6384 | ATF_TP_ADD_TC(tp, traceme2); | | 6592 | ATF_TP_ADD_TC(tp, traceme2); |
6385 | ATF_TP_ADD_TC(tp, traceme3); | | 6593 | ATF_TP_ADD_TC(tp, traceme3); |
6386 | ATF_TP_ADD_TC(tp, traceme4); | | 6594 | ATF_TP_ADD_TC(tp, traceme4); |
6387 | | | 6595 | |
6388 | ATF_TP_ADD_TC_HAVE_PID(tp, attach1); | | 6596 | ATF_TP_ADD_TC_HAVE_PID(tp, attach1); |
6389 | ATF_TP_ADD_TC_HAVE_PID(tp, attach2); | | 6597 | ATF_TP_ADD_TC_HAVE_PID(tp, attach2); |
6390 | ATF_TP_ADD_TC(tp, attach3); | | 6598 | ATF_TP_ADD_TC(tp, attach3); |
6391 | ATF_TP_ADD_TC(tp, attach4); | | 6599 | ATF_TP_ADD_TC(tp, attach4); |
| @@ -6476,16 +6684,18 @@ ATF_TP_ADD_TCS(tp) | | | @@ -6476,16 +6684,18 @@ ATF_TP_ADD_TCS(tp) |
6476 | | | 6684 | |
6477 | ATF_TP_ADD_TC(tp, lwp_create1); | | 6685 | ATF_TP_ADD_TC(tp, lwp_create1); |
6478 | | | 6686 | |
6479 | ATF_TP_ADD_TC(tp, lwp_exit1); | | 6687 | ATF_TP_ADD_TC(tp, lwp_exit1); |
6480 | | | 6688 | |
6481 | ATF_TP_ADD_TC(tp, signal1); | | 6689 | ATF_TP_ADD_TC(tp, signal1); |
6482 | ATF_TP_ADD_TC(tp, signal2); | | 6690 | ATF_TP_ADD_TC(tp, signal2); |
6483 | ATF_TP_ADD_TC(tp, signal3); | | 6691 | ATF_TP_ADD_TC(tp, signal3); |
6484 | ATF_TP_ADD_TC_PT_STEP(tp, signal4); | | 6692 | ATF_TP_ADD_TC_PT_STEP(tp, signal4); |
6485 | ATF_TP_ADD_TC(tp, signal5); | | 6693 | ATF_TP_ADD_TC(tp, signal5); |
6486 | ATF_TP_ADD_TC_HAVE_PID(tp, signal6); | | 6694 | ATF_TP_ADD_TC_HAVE_PID(tp, signal6); |
6487 | ATF_TP_ADD_TC_HAVE_PID(tp, signal7); | | 6695 | ATF_TP_ADD_TC_HAVE_PID(tp, signal7); |
6488 | ATF_TP_ADD_TC(tp, signal8); | | 6696 | ATF_TP_ADD_TC(tp, signal8); |
| | | 6697 | ATF_TP_ADD_TC(tp, signal9); |
| | | 6698 | ATF_TP_ADD_TC(tp, signal10); |
6489 | | | 6699 | |
6490 | return atf_no_error(); | | 6700 | return atf_no_error(); |
6491 | } | | 6701 | } |