Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel/arch/amd64 Add new tests dbregs_dr*_dont_inheri...



details:   https://anonhg.NetBSD.org/src/rev/6b116f24c248
branches:  trunk
changeset: 821870:6b116f24c248
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Feb 20 05:40:51 2017 +0000

description:
Add new tests dbregs_dr*_dont_inherit_lwp and improve i386 compat

Add new tests:
 - dbregs_dr0_dont_inherit_lwp
 - dbregs_dr1_dont_inherit_lwp
 - dbregs_dr2_dont_inherit_lwp
 - dbregs_dr3_dont_inherit_lwp

Fix memcmp(3) usage when comparing registers. Comparing with len is
incorrect as it should be len*sizeof(register) or just sizeof(registers).

Don't check for 16 Debug Registers, it's amd64 specific and not portable
to i386.

Don't compare registers before and after triggering a trap, it's a bug that
was hidden by incorrect usage of memcmp(3).

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/kernel/arch/amd64/t_ptrace_wait.c |  1111 ++++++++++++++----------------
 1 files changed, 537 insertions(+), 574 deletions(-)

diffs (truncated from 2069 to 300 lines):

diff -r 8f317483500f -r 6b116f24c248 tests/kernel/arch/amd64/t_ptrace_wait.c
--- a/tests/kernel/arch/amd64/t_ptrace_wait.c   Mon Feb 20 05:40:03 2017 +0000
+++ b/tests/kernel/arch/amd64/t_ptrace_wait.c   Mon Feb 20 05:40:51 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.19 2017/02/20 02:56:03 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.20 2017/02/20 05:40:51 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.19 2017/02/20 02:56:03 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.20 2017/02/20 05:40:51 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -39,6 +39,7 @@
 #include <machine/reg.h>
 #include <err.h>
 #include <errno.h>
+#include <lwp.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdint.h>
@@ -294,7 +295,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -378,7 +379,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -462,7 +463,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -546,7 +547,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -636,7 +637,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -726,7 +727,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -816,7 +817,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -906,7 +907,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -1002,7 +1003,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -1098,7 +1099,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -1194,7 +1195,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -1290,7 +1291,7 @@
        ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
 
        printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 0);
+       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");
@@ -1324,9 +1325,6 @@
        int status;
 #endif
        struct dbreg r1;
-       struct dbreg r2;
-       /* Number of available CPU Debug Registers on AMD64 */
-       const size_t len = 16;
        size_t i;
        volatile int watchme;
        union u dr7;
@@ -1339,11 +1337,6 @@
        dr7.bits.condition_dr0 = 1;     /* 0b01 -- break on data write only */
        dr7.bits.len_dr0 = 0;           /* 0b00 -- 1 byte */
 
-       printf("Assert that known number of Debug Registers (%zu) is valid\n",
-           len);
-       ATF_REQUIRE_EQ(__arraycount(r1.dr), len);
-       ATF_REQUIRE_EQ(__arraycount(r2.dr), len);
-
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -1416,12 +1409,6 @@
 
        validate_status_stopped(status, sigval);
 
-       printf("Call GETDBREGS for the child process (r2)\n");
-       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
-
-       printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 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);
@@ -1454,9 +1441,6 @@
        int status;
 #endif
        struct dbreg r1;
-       struct dbreg r2;
-       /* Number of available CPU Debug Registers on AMD64 */
-       const size_t len = 16;
        size_t i;
        volatile int watchme;
        union u dr7;
@@ -1469,11 +1453,6 @@
        dr7.bits.condition_dr1 = 1;     /* 0b01 -- break on data write only */
        dr7.bits.len_dr1 = 0;           /* 0b00 -- 1 byte */
 
-       printf("Assert that known number of Debug Registers (%zu) is valid\n",
-           len);
-       ATF_REQUIRE_EQ(__arraycount(r1.dr), len);
-       ATF_REQUIRE_EQ(__arraycount(r2.dr), len);
-
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -1546,12 +1525,6 @@
 
        validate_status_stopped(status, sigval);
 
-       printf("Call GETDBREGS for the child process (r2)\n");
-       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
-
-       printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 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);
@@ -1584,9 +1557,6 @@
        int status;
 #endif
        struct dbreg r1;
-       struct dbreg r2;
-       /* Number of available CPU Debug Registers on AMD64 */
-       const size_t len = 16;
        size_t i;
        volatile int watchme;
        union u dr7;
@@ -1599,11 +1569,6 @@
        dr7.bits.condition_dr2 = 1;     /* 0b01 -- break on data write only */
        dr7.bits.len_dr2 = 0;           /* 0b00 -- 1 byte */
 
-       printf("Assert that known number of Debug Registers (%zu) is valid\n",
-           len);
-       ATF_REQUIRE_EQ(__arraycount(r1.dr), len);
-       ATF_REQUIRE_EQ(__arraycount(r2.dr), len);
-
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -1676,12 +1641,6 @@
 
        validate_status_stopped(status, sigval);
 
-       printf("Call GETDBREGS for the child process (r2)\n");
-       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
-
-       printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 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);
@@ -1714,9 +1673,6 @@
        int status;
 #endif
        struct dbreg r1;
-       struct dbreg r2;
-       /* Number of available CPU Debug Registers on AMD64 */
-       const size_t len = 16;
        size_t i;
        volatile int watchme;
        union u dr7;
@@ -1729,11 +1685,6 @@
        dr7.bits.condition_dr3 = 1;     /* 0b01 -- break on data write only */
        dr7.bits.len_dr3 = 0;           /* 0b00 -- 1 byte */
 
-       printf("Assert that known number of Debug Registers (%zu) is valid\n",
-           len);
-       ATF_REQUIRE_EQ(__arraycount(r1.dr), len);
-       ATF_REQUIRE_EQ(__arraycount(r2.dr), len);
-
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -1806,12 +1757,6 @@
 
        validate_status_stopped(status, sigval);
 
-       printf("Call GETDBREGS for the child process (r2)\n");
-       ATF_REQUIRE(ptrace(PT_GETDBREGS, child, &r2, 0) != -1);
-
-       printf("Assert that (r1) and (r2) are the same\n");
-       ATF_REQUIRE(memcmp(&r1, &r2, len) == 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);
@@ -1844,9 +1789,6 @@
        int status;
 #endif
        struct dbreg r1;
-       struct dbreg r2;
-       /* Number of available CPU Debug Registers on AMD64 */
-       const size_t len = 16;
        size_t i;
        volatile int watchme;
        union u dr7;
@@ -1859,11 +1801,6 @@
        dr7.bits.condition_dr0 = 1;     /* 0b01 -- break on data write only */
        dr7.bits.len_dr0 = 1;           /* 0b01 -- 2 bytes */
 
-       printf("Assert that known number of Debug Registers (%zu) is valid\n",
-           len);
-       ATF_REQUIRE_EQ(__arraycount(r1.dr), len);
-       ATF_REQUIRE_EQ(__arraycount(r2.dr), len);
-
        printf("Before forking process PID=%d\n", getpid());
        ATF_REQUIRE((child = fork()) != -1);
        if (child == 0) {
@@ -1936,12 +1873,6 @@
 
        validate_status_stopped(status, sigval);
 



Home | Main Index | Thread Index | Old Index