diff options
| author | kamil <kamil@NetBSD.org> | 2017-04-01 23:25:08 +0000 |
|---|---|---|
| committer | kamil <kamil@NetBSD.org> | 2017-04-01 23:25:08 +0000 |
| commit | 469abe78fb5b882ea46d7e14cfe2535f28184bf1 (patch) | |
| tree | b78de07733727228aa0988d256c07e701e140724 /tests/kernel | |
| parent | 51077d5f142c7e0205f45b9243fffd0c68b2ab61 (diff) | |
Refactor dbregs_dr*_dont_inherit_execve ATF tests for x86/
Eliminate duplicated code.
Sponsored by <The NetBSD Foundation>
Diffstat (limited to 'tests/kernel')
| -rw-r--r-- | tests/kernel/arch/x86/t_ptrace_wait.c | 525 |
1 files changed, 23 insertions, 502 deletions
diff --git a/tests/kernel/arch/x86/t_ptrace_wait.c b/tests/kernel/arch/x86/t_ptrace_wait.c index e773e8e4fc8..32a79ab86b7 100644 --- a/tests/kernel/arch/x86/t_ptrace_wait.c +++ b/tests/kernel/arch/x86/t_ptrace_wait.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.6 2017/03/30 20:24:35 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.7 2017/04/01 23:25:08 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.6 2017/03/30 20:24:35 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.7 2017/04/01 23:25:08 kamil Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -1798,16 +1798,8 @@ ATF_TC_BODY(dbregs_dr3_dont_inherit_lwp, tc) dbregs_dont_inherit_lwp(3); } -#if defined(HAVE_DBREGS) -ATF_TC(dbregs_dr0_dont_inherit_execve); -ATF_TC_HEAD(dbregs_dr0_dont_inherit_execve, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that execve(2) is intercepted by tracer and Debug " - "Register 0 is reset"); -} - -ATF_TC_BODY(dbregs_dr0_dont_inherit_execve, tc) +static void +dbregs_dont_inherit_execve(int reg) { const int sigval = SIGTRAP; pid_t child, wpid; @@ -1849,9 +1841,9 @@ ATF_TC_BODY(dbregs_dr0_dont_inherit_execve, tc) for (i = 0; i < __arraycount(r1.dr); i++) printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - r1.dr[0] = (long)(intptr_t)check_happy; - printf("Set DR0 (r1.dr[0]) to new value %" PRIxREGISTER "\n", - r1.dr[0]); + r1.dr[reg] = (long)(intptr_t)check_happy; + printf("Set DR%d (r1.dr[%d]) to new value %" PRIxREGISTER "\n", + reg, reg, r1.dr[reg]); printf("New state of the debug registers (r1):\n"); for (i = 0; i < __arraycount(r1.dr); i++) @@ -1900,9 +1892,20 @@ ATF_TC_BODY(dbregs_dr0_dont_inherit_execve, tc) printf("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); } -#endif -#if defined(HAVE_DBREGS) +ATF_TC(dbregs_dr0_dont_inherit_execve); +ATF_TC_HEAD(dbregs_dr0_dont_inherit_execve, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that execve(2) is intercepted by tracer and Debug " + "Register 0 is reset"); +} + +ATF_TC_BODY(dbregs_dr0_dont_inherit_execve, tc) +{ + dbregs_dont_inherit_execve(0); +} + ATF_TC(dbregs_dr1_dont_inherit_execve); ATF_TC_HEAD(dbregs_dr1_dont_inherit_execve, tc) { @@ -1913,100 +1916,9 @@ ATF_TC_HEAD(dbregs_dr1_dont_inherit_execve, tc) ATF_TC_BODY(dbregs_dr1_dont_inherit_execve, tc) { - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - size_t i; - struct dbreg r1; - struct dbreg r2; - - struct ptrace_siginfo info; - memset(&info, 0, sizeof(info)); - - printf("Before forking process PID=%d\n", getpid()); - ATF_REQUIRE((child = fork()) != -1); - if (child == 0) { - printf("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - printf("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - printf("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - FORKEE_ASSERT(0 && "Not reached"); - } - printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Call GETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1); - - printf("State of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - r1.dr[1] = (long)(intptr_t)check_happy; - printf("Set DR1 (r1.dr[1]) to new value %" PRIxREGISTER "\n", - r1.dr[1]); - - printf("New state of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - printf("Call SETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); - - printf("Signal traced to lwpid=%d\n", info.psi_lwpid); - printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - printf("Call GETDBREGS for the child process after execve(2)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1); - - printf("State of the debug registers (r2):\n"); - for (i = 0; i < __arraycount(r2.dr); i++) - printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]); - - printf("Assert that (r1) and (r2) are not the same\n"); - ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) != 0); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); + dbregs_dont_inherit_execve(1); } -#endif -#if defined(HAVE_DBREGS) ATF_TC(dbregs_dr2_dont_inherit_execve); ATF_TC_HEAD(dbregs_dr2_dont_inherit_execve, tc) { @@ -2017,100 +1929,9 @@ ATF_TC_HEAD(dbregs_dr2_dont_inherit_execve, tc) ATF_TC_BODY(dbregs_dr2_dont_inherit_execve, tc) { - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - size_t i; - struct dbreg r1; - struct dbreg r2; - - struct ptrace_siginfo info; - memset(&info, 0, sizeof(info)); - - printf("Before forking process PID=%d\n", getpid()); - ATF_REQUIRE((child = fork()) != -1); - if (child == 0) { - printf("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - printf("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - printf("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - FORKEE_ASSERT(0 && "Not reached"); - } - printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Call GETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1); - - printf("State of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - r1.dr[2] = (long)(intptr_t)check_happy; - printf("Set DR2 (r1.dr[2]) to new value %" PRIxREGISTER "\n", - r1.dr[2]); - - printf("New state of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - printf("Call SETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); - - printf("Signal traced to lwpid=%d\n", info.psi_lwpid); - printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - printf("Call GETDBREGS for the child process after execve(2)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1); - - printf("State of the debug registers (r2):\n"); - for (i = 0; i < __arraycount(r2.dr); i++) - printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]); - - printf("Assert that (r1) and (r2) are not the same\n"); - ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) != 0); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); + dbregs_dont_inherit_execve(2); } -#endif -#if defined(HAVE_DBREGS) ATF_TC(dbregs_dr3_dont_inherit_execve); ATF_TC_HEAD(dbregs_dr3_dont_inherit_execve, tc) { @@ -2121,307 +1942,9 @@ ATF_TC_HEAD(dbregs_dr3_dont_inherit_execve, tc) ATF_TC_BODY(dbregs_dr3_dont_inherit_execve, tc) { - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - size_t i; - struct dbreg r1; - struct dbreg r2; - - struct ptrace_siginfo info; - memset(&info, 0, sizeof(info)); - - printf("Before forking process PID=%d\n", getpid()); - ATF_REQUIRE((child = fork()) != -1); - if (child == 0) { - printf("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - printf("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - printf("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - FORKEE_ASSERT(0 && "Not reached"); - } - printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Call GETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1); - - printf("State of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - r1.dr[3] = (long)(intptr_t)check_happy; - printf("Set DR3 (r1.dr[3]) to new value %" PRIxREGISTER "\n", - r1.dr[3]); - - printf("New state of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - printf("Call SETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); - - printf("Signal traced to lwpid=%d\n", info.psi_lwpid); - printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - printf("Call GETDBREGS for the child process after execve(2)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1); - - printf("State of the debug registers (r2):\n"); - for (i = 0; i < __arraycount(r2.dr); i++) - printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]); - - printf("Assert that (r1) and (r2) are not the same\n"); - ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) != 0); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); -} -#endif - -#if defined(HAVE_DBREGS) -ATF_TC(dbregs_dr6_dont_inherit_execve); -ATF_TC_HEAD(dbregs_dr6_dont_inherit_execve, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that execve(2) is intercepted by tracer and Debug " - "Register 6 is reset"); + dbregs_dont_inherit_execve(3); } -ATF_TC_BODY(dbregs_dr6_dont_inherit_execve, tc) -{ - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - size_t i; - struct dbreg r1; - struct dbreg r2; - - struct ptrace_siginfo info; - memset(&info, 0, sizeof(info)); - - printf("Before forking process PID=%d\n", getpid()); - ATF_REQUIRE((child = fork()) != -1); - if (child == 0) { - printf("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - printf("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - printf("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - FORKEE_ASSERT(0 && "Not reached"); - } - printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Call GETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1); - - printf("State of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - r1.dr[6] = 1; /* breakpoint condition dr0 detected */ - printf("Set DR6 (r1.dr[6]) to new value %" PRIxREGISTER "\n", - r1.dr[6]); - - printf("New state of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - printf("Call SETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); - - printf("Signal traced to lwpid=%d\n", info.psi_lwpid); - printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - printf("Call GETDBREGS for the child process after execve(2)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1); - - printf("State of the debug registers (r2):\n"); - for (i = 0; i < __arraycount(r2.dr); i++) - printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]); - - printf("Assert that (r1) and (r2) are not the same\n"); - ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) != 0); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); -} -#endif - -#if defined(HAVE_DBREGS) -ATF_TC(dbregs_dr7_dont_inherit_execve); -ATF_TC_HEAD(dbregs_dr7_dont_inherit_execve, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that execve(2) is intercepted by tracer and Debug " - "Register 7 is reset"); -} - -ATF_TC_BODY(dbregs_dr7_dont_inherit_execve, tc) -{ - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - size_t i; - struct dbreg r1; - struct dbreg r2; - - struct ptrace_siginfo info; - memset(&info, 0, sizeof(info)); - - printf("Before forking process PID=%d\n", getpid()); - ATF_REQUIRE((child = fork()) != -1); - if (child == 0) { - printf("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - printf("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - printf("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - FORKEE_ASSERT(0 && "Not reached"); - } - printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Call GETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r1, 0) != -1); - - printf("State of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - r1.dr[7] = __BIT(16); /* break on data writes dr0 */ - printf("Set DR7 (r1.dr[7]) to new value %" PRIxREGISTER "\n", - r1.dr[7]); - - printf("New state of the debug registers (r1):\n"); - for (i = 0; i < __arraycount(r1.dr); i++) - printf("r1[%zu]=%" PRIxREGISTER "\n", i, r1.dr[i]); - - printf("Call SETDBREGS for the child process (r1)\n"); - ATF_REQUIRE(ptrace(PT_SETDBREGS, child, &r1, 0) != -1); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - validate_status_stopped(status, sigval); - - printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); - - printf("Signal traced to lwpid=%d\n", info.psi_lwpid); - printf("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - printf("Call GETDBREGS for the child process after execve(2)\n"); - ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1); - - printf("State of the debug registers (r2):\n"); - for (i = 0; i < __arraycount(r2.dr); i++) - printf("r2[%zu]=%" PRIxREGISTER "\n", i, r2.dr[i]); - - printf("Assert that (r1) and (r2) are not the same\n"); - ATF_REQUIRE(memcmp(&r1, &r2, sizeof(r1)) != 0); - - printf("Before resuming the child process where it left off and " - "without signal to be sent\n"); - ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); - - printf("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); -} -#endif - ATF_TP_ADD_TCS(tp) { setvbuf(stdout, NULL, _IONBF, 0); @@ -2503,8 +2026,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr1_dont_inherit_execve); ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr2_dont_inherit_execve); ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr3_dont_inherit_execve); - ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr6_dont_inherit_execve); - ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_dr7_dont_inherit_execve); return atf_no_error(); } |
