| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_ptrace_wait.c,v 1.60 2017/01/14 19:17:10 kamil Exp $ */ | | 1 | /* $NetBSD: t_ptrace_wait.c,v 1.61 2017/01/25 17:01:57 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,36 +17,37 @@ | | | @@ -17,36 +17,37 @@ |
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.60 2017/01/14 19:17:10 kamil Exp $"); | | 30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.61 2017/01/25 17:01:57 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 <err.h> | | 41 | #include <err.h> |
41 | #include <errno.h> | | 42 | #include <errno.h> |
42 | #include <lwp.h> | | 43 | #include <lwp.h> |
43 | #include <signal.h> | | 44 | #include <signal.h> |
44 | #include <stdint.h> | | 45 | #include <stdint.h> |
45 | #include <stdio.h> | | 46 | #include <stdio.h> |
46 | #include <stdlib.h> | | 47 | #include <stdlib.h> |
47 | #include <strings.h> | | 48 | #include <strings.h> |
48 | #include <unistd.h> | | 49 | #include <unistd.h> |
49 | | | 50 | |
50 | #include <atf-c.h> | | 51 | #include <atf-c.h> |
51 | | | 52 | |
52 | #include "h_macros.h" | | 53 | #include "h_macros.h" |
| @@ -2397,26 +2398,92 @@ ATF_TC_BODY(io_write_d4, tc) | | | @@ -2397,26 +2398,92 @@ ATF_TC_BODY(io_write_d4, tc) |
2397 | printf("Before resuming the child process where it left off and " | | 2398 | printf("Before resuming the child process where it left off and " |
2398 | "without signal to be sent\n"); | | 2399 | "without signal to be sent\n"); |
2399 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); | | 2400 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
2400 | | | 2401 | |
2401 | printf("Before calling %s() for the child\n", TWAIT_FNAME); | | 2402 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
2402 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); | | 2403 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
2403 | | | 2404 | |
2404 | validate_status_exited(status, exitval); | | 2405 | validate_status_exited(status, exitval); |
2405 | | | 2406 | |
2406 | printf("Before calling %s() for the child\n", TWAIT_FNAME); | | 2407 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
2407 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); | | 2408 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
2408 | } | | 2409 | } |
2409 | | | 2410 | |
| | | 2411 | ATF_TC(io_read_auxv1); |
| | | 2412 | ATF_TC_HEAD(io_read_auxv1, tc) |
| | | 2413 | { |
| | | 2414 | atf_tc_set_md_var(tc, "descr", |
| | | 2415 | "Verify PT_READ_AUXV called for tracee"); |
| | | 2416 | } |
| | | 2417 | |
| | | 2418 | ATF_TC_BODY(io_read_auxv1, tc) |
| | | 2419 | { |
| | | 2420 | const int exitval = 5; |
| | | 2421 | const int sigval = SIGSTOP; |
| | | 2422 | pid_t child, wpid; |
| | | 2423 | #if defined(TWAIT_HAVE_STATUS) |
| | | 2424 | int status; |
| | | 2425 | #endif |
| | | 2426 | AuxInfo ai[100], *aip; |
| | | 2427 | struct ptrace_io_desc io = { |
| | | 2428 | .piod_op = PIOD_READ_AUXV, |
| | | 2429 | .piod_offs = 0, |
| | | 2430 | .piod_addr = ai, |
| | | 2431 | .piod_len = sizeof(ai) |
| | | 2432 | }; |
| | | 2433 | |
| | | 2434 | printf("Before forking process PID=%d\n", getpid()); |
| | | 2435 | ATF_REQUIRE((child = fork()) != -1); |
| | | 2436 | if (child == 0) { |
| | | 2437 | printf("Before calling PT_TRACE_ME from child %d\n", getpid()); |
| | | 2438 | FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); |
| | | 2439 | |
| | | 2440 | printf("Before raising %s from child\n", strsignal(sigval)); |
| | | 2441 | FORKEE_ASSERT(raise(sigval) == 0); |
| | | 2442 | |
| | | 2443 | printf("Before exiting of the child process\n"); |
| | | 2444 | _exit(exitval); |
| | | 2445 | } |
| | | 2446 | printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); |
| | | 2447 | |
| | | 2448 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 2449 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 2450 | |
| | | 2451 | validate_status_stopped(status, sigval); |
| | | 2452 | |
| | | 2453 | printf("Read new AUXV from tracee (PID=%d) by tracer (PID=%d)\n", |
| | | 2454 | child, getpid()); |
| | | 2455 | ATF_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); |
| | | 2456 | |
| | | 2457 | printf("Asserting that AUXV length (%zu) is > 0\n", io.piod_len); |
| | | 2458 | ATF_REQUIRE(io.piod_len > 0); |
| | | 2459 | |
| | | 2460 | for (aip = ai; aip->a_type != AT_NULL; aip++) |
| | | 2461 | printf("a_type=%#llx a_v=%#llx\n", |
| | | 2462 | (long long int)aip->a_type, (long long int)aip->a_v); |
| | | 2463 | |
| | | 2464 | printf("Before resuming the child process where it left off and " |
| | | 2465 | "without signal to be sent\n"); |
| | | 2466 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 2467 | |
| | | 2468 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 2469 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 2470 | |
| | | 2471 | validate_status_exited(status, exitval); |
| | | 2472 | |
| | | 2473 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 2474 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
| | | 2475 | } |
| | | 2476 | |
2410 | ATF_TC(read_d1); | | 2477 | ATF_TC(read_d1); |
2411 | ATF_TC_HEAD(read_d1, tc) | | 2478 | ATF_TC_HEAD(read_d1, tc) |
2412 | { | | 2479 | { |
2413 | atf_tc_set_md_var(tc, "descr", | | 2480 | atf_tc_set_md_var(tc, "descr", |
2414 | "Verify PT_READ_D called once"); | | 2481 | "Verify PT_READ_D called once"); |
2415 | } | | 2482 | } |
2416 | | | 2483 | |
2417 | ATF_TC_BODY(read_d1, tc) | | 2484 | ATF_TC_BODY(read_d1, tc) |
2418 | { | | 2485 | { |
2419 | const int exitval = 5; | | 2486 | const int exitval = 5; |
2420 | const int sigval = SIGSTOP; | | 2487 | const int sigval = SIGSTOP; |
2421 | pid_t child, wpid; | | 2488 | pid_t child, wpid; |
2422 | int lookup_me = 0; | | 2489 | int lookup_me = 0; |
| @@ -5657,26 +5724,28 @@ ATF_TP_ADD_TCS(tp) | | | @@ -5657,26 +5724,28 @@ ATF_TP_ADD_TCS(tp) |
5657 | ATF_TP_ADD_TC(tp, read_d_write_d_handshake1); | | 5724 | ATF_TP_ADD_TC(tp, read_d_write_d_handshake1); |
5658 | ATF_TP_ADD_TC(tp, read_d_write_d_handshake2); | | 5725 | ATF_TP_ADD_TC(tp, read_d_write_d_handshake2); |
5659 | | | 5726 | |
5660 | ATF_TP_ADD_TC(tp, io_read_i1); | | 5727 | ATF_TP_ADD_TC(tp, io_read_i1); |
5661 | ATF_TP_ADD_TC(tp, io_read_i2); | | 5728 | ATF_TP_ADD_TC(tp, io_read_i2); |
5662 | ATF_TP_ADD_TC(tp, io_read_i3); | | 5729 | ATF_TP_ADD_TC(tp, io_read_i3); |
5663 | ATF_TP_ADD_TC(tp, io_read_i4); | | 5730 | ATF_TP_ADD_TC(tp, io_read_i4); |
5664 | | | 5731 | |
5665 | ATF_TP_ADD_TC(tp, read_i1); | | 5732 | ATF_TP_ADD_TC(tp, read_i1); |
5666 | ATF_TP_ADD_TC(tp, read_i2); | | 5733 | ATF_TP_ADD_TC(tp, read_i2); |
5667 | ATF_TP_ADD_TC(tp, read_i3); | | 5734 | ATF_TP_ADD_TC(tp, read_i3); |
5668 | ATF_TP_ADD_TC(tp, read_i4); | | 5735 | ATF_TP_ADD_TC(tp, read_i4); |
5669 | | | 5736 | |
| | | 5737 | ATF_TP_ADD_TC(tp, io_read_auxv1); |
| | | 5738 | |
5670 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); | | 5739 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); |
5671 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2); | | 5740 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2); |
5672 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3); | | 5741 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3); |
5673 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs4); | | 5742 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs4); |
5674 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs5); | | 5743 | ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs5); |
5675 | | | 5744 | |
5676 | ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs1); | | 5745 | ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs1); |
5677 | ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs2); | | 5746 | ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs2); |
5678 | | | 5747 | |
5679 | ATF_TP_ADD_TC_PT_STEP(tp, step1); | | 5748 | ATF_TP_ADD_TC_PT_STEP(tp, step1); |
5680 | ATF_TP_ADD_TC_PT_STEP(tp, step2); | | 5749 | ATF_TP_ADD_TC_PT_STEP(tp, step2); |
5681 | ATF_TP_ADD_TC_PT_STEP(tp, step3); | | 5750 | ATF_TP_ADD_TC_PT_STEP(tp, step3); |
5682 | ATF_TP_ADD_TC_PT_STEP(tp, step4); | | 5751 | ATF_TP_ADD_TC_PT_STEP(tp, step4); |