| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_ptrace_wait.c,v 1.63 2017/01/26 20:15:44 kamil Exp $ */ | | 1 | /* $NetBSD: t_ptrace_wait.c,v 1.64 2017/01/26 22:32:48 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.63 2017/01/26 20:15:44 kamil Exp $"); | | 30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.64 2017/01/26 22:32:48 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> |
| @@ -5856,26 +5856,99 @@ ATF_TC_BODY(signal3, tc) | | | @@ -5856,26 +5856,99 @@ ATF_TC_BODY(signal3, tc) |
5856 | printf("Before resuming the child process where it left off and " | | 5856 | printf("Before resuming the child process where it left off and " |
5857 | "without signal to be sent\n"); | | 5857 | "without signal to be sent\n"); |
5858 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); | | 5858 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
5859 | | | 5859 | |
5860 | printf("Before calling %s() for the child\n", TWAIT_FNAME); | | 5860 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
5861 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); | | 5861 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
5862 | | | 5862 | |
5863 | validate_status_exited(status, exitval); | | 5863 | validate_status_exited(status, exitval); |
5864 | | | 5864 | |
5865 | printf("Before calling %s() for the child\n", TWAIT_FNAME); | | 5865 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
5866 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); | | 5866 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
5867 | } | | 5867 | } |
5868 | | | 5868 | |
| | | 5869 | #if defined(PT_STEP) |
| | | 5870 | ATF_TC(signal4); |
| | | 5871 | ATF_TC_HEAD(signal4, tc) |
| | | 5872 | { |
| | | 5873 | atf_tc_set_md_var(tc, "descr", |
| | | 5874 | "Verify that masking SIGTRAP in tracee does not stop tracer from " |
| | | 5875 | "catching single step trap"); |
| | | 5876 | } |
| | | 5877 | |
| | | 5878 | ATF_TC_BODY(signal4, tc) |
| | | 5879 | { |
| | | 5880 | const int exitval = 5; |
| | | 5881 | const int sigval = SIGSTOP; |
| | | 5882 | const int sigmasked = SIGTRAP; |
| | | 5883 | pid_t child, wpid; |
| | | 5884 | #if defined(TWAIT_HAVE_STATUS) |
| | | 5885 | int status; |
| | | 5886 | #endif |
| | | 5887 | sigset_t intmask; |
| | | 5888 | int happy; |
| | | 5889 | |
| | | 5890 | atf_tc_expect_fail("PR kern/51918"); |
| | | 5891 | |
| | | 5892 | printf("Before forking process PID=%d\n", getpid()); |
| | | 5893 | ATF_REQUIRE((child = fork()) != -1); |
| | | 5894 | if (child == 0) { |
| | | 5895 | printf("Before calling PT_TRACE_ME from child %d\n", getpid()); |
| | | 5896 | FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); |
| | | 5897 | |
| | | 5898 | happy = check_happy(100); |
| | | 5899 | |
| | | 5900 | sigemptyset(&intmask); |
| | | 5901 | sigaddset(&intmask, sigmasked); |
| | | 5902 | sigprocmask(SIG_BLOCK, &intmask, NULL); |
| | | 5903 | |
| | | 5904 | printf("Before raising %s from child\n", strsignal(sigval)); |
| | | 5905 | FORKEE_ASSERT(raise(sigval) == 0); |
| | | 5906 | |
| | | 5907 | FORKEE_ASSERT_EQ(happy, check_happy(100)); |
| | | 5908 | |
| | | 5909 | printf("Before exiting of the child process\n"); |
| | | 5910 | _exit(exitval); |
| | | 5911 | } |
| | | 5912 | printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); |
| | | 5913 | |
| | | 5914 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 5915 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 5916 | |
| | | 5917 | validate_status_stopped(status, sigval); |
| | | 5918 | |
| | | 5919 | printf("Before resuming the child process where it left off and " |
| | | 5920 | "without signal to be sent\n"); |
| | | 5921 | ATF_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1); |
| | | 5922 | |
| | | 5923 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 5924 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 5925 | |
| | | 5926 | validate_status_stopped(status, sigmasked); |
| | | 5927 | |
| | | 5928 | printf("Before resuming the child process where it left off and " |
| | | 5929 | "without signal to be sent\n"); |
| | | 5930 | ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); |
| | | 5931 | |
| | | 5932 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 5933 | TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); |
| | | 5934 | |
| | | 5935 | validate_status_exited(status, exitval); |
| | | 5936 | |
| | | 5937 | printf("Before calling %s() for the child\n", TWAIT_FNAME); |
| | | 5938 | TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); |
| | | 5939 | } |
| | | 5940 | #endif |
| | | 5941 | |
5869 | ATF_TP_ADD_TCS(tp) | | 5942 | ATF_TP_ADD_TCS(tp) |
5870 | { | | 5943 | { |
5871 | setvbuf(stdout, NULL, _IONBF, 0); | | 5944 | setvbuf(stdout, NULL, _IONBF, 0); |
5872 | setvbuf(stderr, NULL, _IONBF, 0); | | 5945 | setvbuf(stderr, NULL, _IONBF, 0); |
5873 | ATF_TP_ADD_TC(tp, traceme1); | | 5946 | ATF_TP_ADD_TC(tp, traceme1); |
5874 | ATF_TP_ADD_TC(tp, traceme2); | | 5947 | ATF_TP_ADD_TC(tp, traceme2); |
5875 | ATF_TP_ADD_TC(tp, traceme3); | | 5948 | ATF_TP_ADD_TC(tp, traceme3); |
5876 | ATF_TP_ADD_TC(tp, traceme4); | | 5949 | ATF_TP_ADD_TC(tp, traceme4); |
5877 | | | 5950 | |
5878 | ATF_TP_ADD_TC_HAVE_PID(tp, attach1); | | 5951 | ATF_TP_ADD_TC_HAVE_PID(tp, attach1); |
5879 | ATF_TP_ADD_TC_HAVE_PID(tp, attach2); | | 5952 | ATF_TP_ADD_TC_HAVE_PID(tp, attach2); |
5880 | ATF_TP_ADD_TC(tp, attach3); | | 5953 | ATF_TP_ADD_TC(tp, attach3); |
5881 | ATF_TP_ADD_TC(tp, attach4); | | 5954 | ATF_TP_ADD_TC(tp, attach4); |
| @@ -5961,16 +6034,17 @@ ATF_TP_ADD_TCS(tp) | | | @@ -5961,16 +6034,17 @@ ATF_TP_ADD_TCS(tp) |
5961 | ATF_TP_ADD_TC(tp, siginfo2); | | 6034 | ATF_TP_ADD_TC(tp, siginfo2); |
5962 | ATF_TP_ADD_TC(tp, siginfo3); | | 6035 | ATF_TP_ADD_TC(tp, siginfo3); |
5963 | ATF_TP_ADD_TC(tp, siginfo4); | | 6036 | ATF_TP_ADD_TC(tp, siginfo4); |
5964 | ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5); | | 6037 | ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5); |
5965 | ATF_TP_ADD_TC_PT_STEP(tp, siginfo6); | | 6038 | ATF_TP_ADD_TC_PT_STEP(tp, siginfo6); |
5966 | | | 6039 | |
5967 | ATF_TP_ADD_TC(tp, lwp_create1); | | 6040 | ATF_TP_ADD_TC(tp, lwp_create1); |
5968 | | | 6041 | |
5969 | ATF_TP_ADD_TC(tp, lwp_exit1); | | 6042 | ATF_TP_ADD_TC(tp, lwp_exit1); |
5970 | | | 6043 | |
5971 | ATF_TP_ADD_TC(tp, signal1); | | 6044 | ATF_TP_ADD_TC(tp, signal1); |
5972 | ATF_TP_ADD_TC(tp, signal2); | | 6045 | ATF_TP_ADD_TC(tp, signal2); |
5973 | ATF_TP_ADD_TC(tp, signal3); | | 6046 | ATF_TP_ADD_TC(tp, signal3); |
| | | 6047 | ATF_TP_ADD_TC_PT_STEP(tp, signal4); |
5974 | | | 6048 | |
5975 | return atf_no_error(); | | 6049 | return atf_no_error(); |
5976 | } | | 6050 | } |