CVS commit: src/tests/kernel/arch/amd64

2017-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Feb 21 08:40:16 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_dont_inherit_execve in arch/amd64

Added tests:
 - dbregs_dr0_dont_inherit_execve
 - dbregs_dr1_dont_inherit_execve
 - dbregs_dr2_dont_inherit_execve
 - dbregs_dr3_dont_inherit_execve
 - dbregs_dr6_dont_inherit_execve
 - dbregs_dr7_dont_inherit_execve

Debug Registers must no be inherited after exec() call.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Feb 21 08:40:16 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_dont_inherit_execve in arch/amd64

Added tests:
 - dbregs_dr0_dont_inherit_execve
 - dbregs_dr1_dont_inherit_execve
 - dbregs_dr2_dont_inherit_execve
 - dbregs_dr3_dont_inherit_execve
 - dbregs_dr6_dont_inherit_execve
 - dbregs_dr7_dont_inherit_execve

Debug Registers must no be inherited after exec() call.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.23 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.24
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.23	Mon Feb 20 06:48:49 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Tue Feb 21 08:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.23 2017/02/20 06:48:49 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.24 2017/02/21 08:40:16 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.23 2017/02/20 06:48:49 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.24 2017/02/21 08:40:16 kamil Exp $");
 
 #include 
 #include 
@@ -6678,6 +6678,624 @@ ATF_TC_BODY(dbregs_dr7_dont_inherit_lwp,
 }
 #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)
+{
+	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(, 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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	r1.dr[0] = (long)(intptr_t)check_happy;
+	printf("Set DR0 (r1.dr[0]) to new value %#lx\n", r1.dr[0]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 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, , 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, , 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, , 0) != -1);
+
+	printf("State of the debug registers (r2):\n");
+	for (i = 0; i < __arraycount(r2.dr); i++)
+		printf("r2[%zu]=%#lx\n", i, r2.dr[i]);
+
+	printf("Assert that (r1) and (r2) are not the same\n");
+	ATF_REQUIRE(memcmp(, , 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, , 0), child);
+
+	printf("Before calling %s() for the child\n", TWAIT_FNAME);
+	

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 06:48:49 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Protect dbregs_dr*_dont_inherit_lwp in arch/amd64 with HAVE_DBREGS

The code for debug registers isn't in HEAD and it might break the build.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 06:48:49 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Protect dbregs_dr*_dont_inherit_lwp in arch/amd64 with HAVE_DBREGS

The code for debug registers isn't in HEAD and it might break the build.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.22 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.23
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.22	Mon Feb 20 06:18:48 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 06:48:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.22 2017/02/20 06:18:48 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.23 2017/02/20 06:48:49 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.22 2017/02/20 06:18:48 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.23 2017/02/20 06:48:49 kamil Exp $");
 
 #include 
 #include 
@@ -5897,13 +5897,14 @@ ATF_TC_BODY(dbregs_dr3_trap_code, tc)
 
 volatile lwpid_t the_lwp_id = 0;
 
-static void
+static void __used
 lwp_main_func(void *arg)
 {
 	the_lwp_id = _lwp_self();
 	_lwp_exit();
 }
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr0_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr0_dont_inherit_lwp, tc)
 {
@@ -6030,7 +6031,9 @@ ATF_TC_BODY(dbregs_dr0_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr1_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr1_dont_inherit_lwp, tc)
 {
@@ -6157,7 +6160,9 @@ ATF_TC_BODY(dbregs_dr1_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr2_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr2_dont_inherit_lwp, tc)
 {
@@ -6284,7 +6289,9 @@ ATF_TC_BODY(dbregs_dr2_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr3_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr3_dont_inherit_lwp, tc)
 {
@@ -6411,7 +6418,9 @@ ATF_TC_BODY(dbregs_dr3_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr6_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr6_dont_inherit_lwp, tc)
 {
@@ -6538,7 +6547,9 @@ ATF_TC_BODY(dbregs_dr6_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
+#if defined(HAVE_DBREGS)
 ATF_TC(dbregs_dr7_dont_inherit_lwp);
 ATF_TC_HEAD(dbregs_dr7_dont_inherit_lwp, tc)
 {
@@ -6665,6 +6676,7 @@ ATF_TC_BODY(dbregs_dr7_dont_inherit_lwp,
 	TWAIT_FNAME);
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
+#endif
 
 ATF_TP_ADD_TCS(tp)
 {



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 06:18:48 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr[67]_dont_inherit_lwp in arch/amd64

New tests:
 - dbregs_dr6_dont_inherit_lwp
 - dbregs_dr7_dont_inherit_lwp

Debug Registers are set always per-LWP and they are never inherited.
If a user wants to reuse them, there is need to set trap on thread creation
(PTRACE_LWP_CREATE) and set them from a debugger on newly created LWP.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 06:18:48 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr[67]_dont_inherit_lwp in arch/amd64

New tests:
 - dbregs_dr6_dont_inherit_lwp
 - dbregs_dr7_dont_inherit_lwp

Debug Registers are set always per-LWP and they are never inherited.
If a user wants to reuse them, there is need to set trap on thread creation
(PTRACE_LWP_CREATE) and set them from a debugger on newly created LWP.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.21 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.22
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.21	Mon Feb 20 05:47:59 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 06:18:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.21 2017/02/20 05:47:59 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.22 2017/02/20 06:18:48 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.21 2017/02/20 05:47:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.22 2017/02/20 06:18:48 kamil Exp $");
 
 #include 
 #include 
@@ -6412,6 +6412,260 @@ ATF_TC_BODY(dbregs_dr3_dont_inherit_lwp,
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
 
+ATF_TC(dbregs_dr6_dont_inherit_lwp);
+ATF_TC_HEAD(dbregs_dr6_dont_inherit_lwp, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that 1 LWP creation is intercepted by ptrace(2) with "
+	"EVENT_MASK set to PTRACE_LWP_CREATE and Debug Register 6 from "
+	"the forker thread is not inherited");
+}
+
+ATF_TC_BODY(dbregs_dr6_dont_inherit_lwp, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	ptrace_state_t state;
+	const int slen = sizeof(state);
+	ptrace_event_t event;
+	const int elen = sizeof(event);
+	ucontext_t uc;
+	lwpid_t lid;
+	static const size_t ssize = 16*1024;
+	void *stack;
+	size_t i;
+	struct dbreg r1;
+	struct dbreg r2;
+
+	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 allocating memory for stack in child\n");
+		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
+
+		printf("Before making context for new lwp in child\n");
+		_lwp_makecontext(, lwp_main_func, NULL, NULL, stack, ssize);
+
+		printf("Before creating new in child\n");
+		FORKEE_ASSERT(_lwp_create(, 0, ) == 0);
+
+		printf("Before waiting for lwp %d to exit\n", lid);
+		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
+
+		printf("Before verifying that reported %d and running lid %d "
+		"are the same\n", lid, the_lwp_id);
+		FORKEE_ASSERT_EQ(lid, the_lwp_id);
+
+		printf("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Set empty EVENT_MASK for the child %d\n", child);
+	event.pe_set_event = PTRACE_LWP_CREATE;
+	ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	r1.dr[6] = 1; /* breakpoint condition dr0 detected */
+	printf("Set DR6 (r1.dr[6]) to new value %#lx\n", r1.dr[6]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 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 - expected stopped "
+	"SIGTRAP\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, SIGTRAP);
+
+	ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
+
+	ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE);
+
+	lid = state.pe_lwp;
+	printf("Reported 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 05:47:59 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Fix more issues with compat to i386 in arch/amd64 tests for Debug Registers

Stop compating the number of available registers with 16, it's amd64
specific. i386 ships with 8 Debug Registers.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.20 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.21
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.20	Mon Feb 20 05:40:51 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 05:47:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.20 2017/02/20 05:40:51 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.21 2017/02/20 05:47:59 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.20 2017/02/20 05:40:51 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.21 2017/02/20 05:47:59 kamil Exp $");
 
 #include 
 #include 
@@ -245,16 +245,9 @@ ATF_TC_BODY(dbregs_preserve_dr0, tc)
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -329,16 +322,9 @@ ATF_TC_BODY(dbregs_preserve_dr1, tc)
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -413,16 +399,9 @@ ATF_TC_BODY(dbregs_preserve_dr2, tc)
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -497,16 +476,9 @@ ATF_TC_BODY(dbregs_preserve_dr3, tc)
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -582,16 +554,9 @@ ATF_TC_BODY(dbregs_preserve_dr0_yield, t
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -672,16 +637,9 @@ ATF_TC_BODY(dbregs_preserve_dr1_yield, t
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -762,16 +720,9 @@ ATF_TC_BODY(dbregs_preserve_dr2_yield, t
 #endif
 	struct dbreg r1;
 	struct dbreg r2;
-	/* Number of available CPU Debug Registers on AMD64 */
-	const size_t len = 16;
 	size_t i;
 	int watchme;
 
-	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) {
@@ -852,16 +803,9 @@ ATF_TC_BODY(dbregs_preserve_dr3_yield, t
 #endif
 	struct dbreg r1;
 	struct dbreg 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 05:47:59 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Fix more issues with compat to i386 in arch/amd64 tests for Debug Registers

Stop compating the number of available registers with 16, it's amd64
specific. i386 ships with 8 Debug Registers.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 05:40:51 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
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 


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.19 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.20
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.19	Mon Feb 20 02:56:03 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 05:40:51 2017
@@ -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 
-__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 
 #include 
@@ -39,6 +39,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.19
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -294,7 +295,7 @@ ATF_TC_BODY(dbregs_preserve_dr0, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr1, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr2, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr3, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr0_yield, t
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr1_yield, t
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr2_yield, t
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr3_yield, t
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , 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_TC_BODY(dbregs_preserve_dr0_continue
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("Assert that (r1) and (r2) are the same\n");
-	ATF_REQUIRE(memcmp(, , len) == 0);
+	ATF_REQUIRE(memcmp(, , sizeof(r1)) == 0);
 
 	printf("Before 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 05:40:51 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
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 


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 02:56:03 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr[0123]_trap_code in arch/amd64

Add new tests:
 - dbregs_dr0_trap_code
 - dbregs_dr1_trap_code
 - dbregs_dr2_trap_code
 - dbregs_dr3_trap_code

This is the final set of tests for trap types that are supposed to be
supported by all amd64 CPUs.

Traps for code (instruction) execution must be set to 1 byte, otherwise
they are undefined. x86 code traps must point to the first byte of an
instruction.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 02:56:03 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr[0123]_trap_code in arch/amd64

Add new tests:
 - dbregs_dr0_trap_code
 - dbregs_dr1_trap_code
 - dbregs_dr2_trap_code
 - dbregs_dr3_trap_code

This is the final set of tests for trap types that are supposed to be
supported by all amd64 CPUs.

Traps for code (instruction) execution must be set to 1 byte, otherwise
they are undefined. x86 code traps must point to the first byte of an
instruction.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.18 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.19
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.18	Mon Feb 20 01:34:53 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 02:56:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.18 2017/02/20 01:34:53 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.19 2017/02/20 02:56:03 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.18 2017/02/20 01:34:53 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.19 2017/02/20 02:56:03 kamil Exp $");
 
 #include 
 #include 
@@ -5986,6 +5986,558 @@ ATF_TC_BODY(dbregs_dr3_trap_variable_rea
 }
 #endif
 
+#if defined(HAVE_DBREGS)
+ATF_TC(dbregs_dr0_trap_code);
+ATF_TC_HEAD(dbregs_dr0_trap_code, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that setting trap with DR0 triggers SIGTRAP "
+	"(break on code execution trap)");
+}
+
+ATF_TC_BODY(dbregs_dr0_trap_code, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	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 = 1;
+	union u dr7;
+
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
+	dr7.raw = 0;
+	dr7.bits.global_dr0_breakpoint = 1;
+	dr7.bits.condition_dr0 = 0;	/* 0b00 -- break on code execution */
+	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) {
+		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("check_happy(%d)=%d\n", watchme, check_happy(watchme));
+
+		printf("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		printf("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	r1.dr[0] = (long)(intptr_t)check_happy;
+	printf("Set DR0 (r1.dr[0]) to new value %#lx\n", r1.dr[0]);
+
+	r1.dr[7] = dr7.raw;
+	printf("Set DR7 (r1.dr[7]) to new value %#lx\n", r1.dr[7]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
+
+	printf("Call CONTINUE for the child process\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, , 0), child);
+
+	validate_status_stopped(status, SIGTRAP);
+
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 01:34:53 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_trap_variable_readwrite_read_*byte* in arch/amd64

Add new tests:
 - dbregs_dr0_trap_variable_readwrite_read_byte
 - dbregs_dr1_trap_variable_readwrite_read_byte
 - dbregs_dr2_trap_variable_readwrite_read_byte
 - dbregs_dr3_trap_variable_readwrite_read_byte
 - dbregs_dr0_trap_variable_readwrite_read_2bytes
 - dbregs_dr1_trap_variable_readwrite_read_2bytes
 - dbregs_dr2_trap_variable_readwrite_read_2bytes
 - dbregs_dr3_trap_variable_readwrite_read_2bytes
 - dbregs_dr0_trap_variable_readwrite_read_4bytes
 - dbregs_dr1_trap_variable_readwrite_read_4bytes
 - dbregs_dr2_trap_variable_readwrite_read_4bytes
 - dbregs_dr3_trap_variable_readwrite_read_4bytes

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.17 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.18
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.17	Mon Feb 20 01:21:47 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 01:34:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.17 2017/02/20 01:21:47 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.18 2017/02/20 01:34:53 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.17 2017/02/20 01:21:47 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.18 2017/02/20 01:34:53 kamil Exp $");
 
 #include 
 #include 
@@ -4426,6 +4426,1566 @@ ATF_TC_BODY(dbregs_dr3_trap_variable_rea
 }
 #endif
 
+#if defined(HAVE_DBREGS)
+ATF_TC(dbregs_dr0_trap_variable_readwrite_read_byte);
+ATF_TC_HEAD(dbregs_dr0_trap_variable_readwrite_read_byte, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that setting trap with DR0 triggers SIGTRAP "
+	"(break on data read/write trap in write 1 byte mode)");
+}
+
+ATF_TC_BODY(dbregs_dr0_trap_variable_readwrite_read_byte, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	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 = 1;
+	union u dr7;
+
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
+	dr7.raw = 0;
+	dr7.bits.global_dr0_breakpoint = 1;
+	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
+	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) {
+		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("watchme=%d\n", watchme);
+
+		printf("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		printf("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	r1.dr[0] = (long)(intptr_t)
+	printf("Set DR0 (r1.dr[0]) to new value %#lx\n", r1.dr[0]);
+
+	r1.dr[7] = dr7.raw;
+	printf("Set DR7 (r1.dr[7]) to new value %#lx\n", r1.dr[7]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
+
+	printf("Call CONTINUE for the child process\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, , 0), child);
+
+	validate_status_stopped(status, SIGTRAP);
+
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
+
+	printf("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 01:34:53 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_trap_variable_readwrite_read_*byte* in arch/amd64

Add new tests:
 - dbregs_dr0_trap_variable_readwrite_read_byte
 - dbregs_dr1_trap_variable_readwrite_read_byte
 - dbregs_dr2_trap_variable_readwrite_read_byte
 - dbregs_dr3_trap_variable_readwrite_read_byte
 - dbregs_dr0_trap_variable_readwrite_read_2bytes
 - dbregs_dr1_trap_variable_readwrite_read_2bytes
 - dbregs_dr2_trap_variable_readwrite_read_2bytes
 - dbregs_dr3_trap_variable_readwrite_read_2bytes
 - dbregs_dr0_trap_variable_readwrite_read_4bytes
 - dbregs_dr1_trap_variable_readwrite_read_4bytes
 - dbregs_dr2_trap_variable_readwrite_read_4bytes
 - dbregs_dr3_trap_variable_readwrite_read_4bytes

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 01:21:47 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_trap_variable_readwrite_write_*byte* in arch/amd64

Add new tests:
 - dbregs_dr0_trap_variable_readwrite_write_byte
 - dbregs_dr1_trap_variable_readwrite_write_byte
 - dbregs_dr2_trap_variable_readwrite_write_byte
 - dbregs_dr3_trap_variable_readwrite_write_byte
 - dbregs_dr0_trap_variable_readwrite_write_2bytes
 - dbregs_dr1_trap_variable_readwrite_write_2bytes
 - dbregs_dr2_trap_variable_readwrite_write_2bytes
 - dbregs_dr3_trap_variable_readwrite_write_2bytes
 - dbregs_dr0_trap_variable_readwrite_write_4bytes
 - dbregs_dr1_trap_variable_readwrite_write_4bytes
 - dbregs_dr2_trap_variable_readwrite_write_4bytes
 - dbregs_dr3_trap_variable_readwrite_write_4bytes

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.16 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.17
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.16	Sun Feb 19 23:58:30 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Mon Feb 20 01:21:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.16 2017/02/19 23:58:30 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.17 2017/02/20 01:21:47 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.16 2017/02/19 23:58:30 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.17 2017/02/20 01:21:47 kamil Exp $");
 
 #include 
 #include 
@@ -1336,7 +1336,7 @@ ATF_TC_BODY(dbregs_dr0_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr0_breakpoint = 1;
-	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
+	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",
@@ -1466,7 +1466,7 @@ ATF_TC_BODY(dbregs_dr1_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr1_breakpoint = 1;
-	dr7.bits.condition_dr1 = 3;	/* 0b11 -- break on data write */
+	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",
@@ -1596,7 +1596,7 @@ ATF_TC_BODY(dbregs_dr2_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr2_breakpoint = 1;
-	dr7.bits.condition_dr2 = 3;	/* 0b11 -- break on data write */
+	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",
@@ -1726,7 +1726,7 @@ ATF_TC_BODY(dbregs_dr3_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr3_breakpoint = 1;
-	dr7.bits.condition_dr3 = 3;	/* 0b11 -- break on data write */
+	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",
@@ -1856,7 +1856,7 @@ ATF_TC_BODY(dbregs_dr0_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr0_breakpoint = 1;
-	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
+	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",
@@ -1986,7 +1986,7 @@ ATF_TC_BODY(dbregs_dr1_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr1_breakpoint = 1;
-	dr7.bits.condition_dr1 = 3;	/* 0b11 -- break on data write */
+	dr7.bits.condition_dr1 = 1;	/* 0b01 -- break on data write only */
 	dr7.bits.len_dr1 = 1;		/* 0b01 -- 2 bytes */
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
@@ -2116,7 +2116,7 @@ ATF_TC_BODY(dbregs_dr2_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr2_breakpoint = 1;
-	dr7.bits.condition_dr2 = 3;	/* 0b11 -- break on data write */
+	dr7.bits.condition_dr2 = 1;	/* 0b01 -- break on data write only */
 	dr7.bits.len_dr2 = 1;		/* 0b01 -- 2 bytes */
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
@@ -2246,7 +2246,7 @@ ATF_TC_BODY(dbregs_dr3_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr3_breakpoint = 1;
-	dr7.bits.condition_dr3 = 3;	/* 0b11 -- break on data write */
+	dr7.bits.condition_dr3 = 1;	/* 0b01 -- break on data write only */
 	dr7.bits.len_dr3 = 1;		/* 0b01 -- 2 bytes */
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
@@ -2376,7 +2376,7 @@ ATF_TC_BODY(dbregs_dr0_trap_variable_wri
 
 	dr7.raw = 0;
 	dr7.bits.global_dr0_breakpoint = 1;
-	dr7.bits.condition_dr0 = 3;	/* 0b11 -- 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Feb 20 01:21:47 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs_dr*_trap_variable_readwrite_write_*byte* in arch/amd64

Add new tests:
 - dbregs_dr0_trap_variable_readwrite_write_byte
 - dbregs_dr1_trap_variable_readwrite_write_byte
 - dbregs_dr2_trap_variable_readwrite_write_byte
 - dbregs_dr3_trap_variable_readwrite_write_byte
 - dbregs_dr0_trap_variable_readwrite_write_2bytes
 - dbregs_dr1_trap_variable_readwrite_write_2bytes
 - dbregs_dr2_trap_variable_readwrite_write_2bytes
 - dbregs_dr3_trap_variable_readwrite_write_2bytes
 - dbregs_dr0_trap_variable_readwrite_write_4bytes
 - dbregs_dr1_trap_variable_readwrite_write_4bytes
 - dbregs_dr2_trap_variable_readwrite_write_4bytes
 - dbregs_dr3_trap_variable_readwrite_write_4bytes

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 19 23:58:30 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Extend dbregs_dr*_trap_variable tests to 1-2-4 byte traps in arch/amd64

Replace the following tests:
 - dbregs_dr0_trap_variable
 - dbregs_dr1_trap_variable
 - dbregs_dr2_trap_variable
 - dbregs_dr3_trap_variable

With new ones:
 - dbregs_dr0_trap_variable_writeonly_byte
 - dbregs_dr1_trap_variable_writeonly_byte
 - dbregs_dr2_trap_variable_writeonly_byte
 - dbregs_dr3_trap_variable_writeonly_byte
 - dbregs_dr0_trap_variable_writeonly_2bytes
 - dbregs_dr1_trap_variable_writeonly_2bytes
 - dbregs_dr2_trap_variable_writeonly_2bytes
 - dbregs_dr3_trap_variable_writeonly_2bytes
 - dbregs_dr0_trap_variable_writeonly_4bytes
 - dbregs_dr1_trap_variable_writeonly_4bytes
 - dbregs_dr2_trap_variable_writeonly_4bytes
 - dbregs_dr3_trap_variable_writeonly_4bytes

All tests pass with my local implementation of debug registers. Once the
interface will be verified, I will prepare it for commit to HEAD.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.15 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.16
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.15	Sun Feb 19 22:09:29 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sun Feb 19 23:58:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.15 2017/02/19 22:09:29 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.16 2017/02/19 23:58:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.15 2017/02/19 22:09:29 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.16 2017/02/19 23:58:30 kamil Exp $");
 
 #include 
 #include 
@@ -1307,14 +1307,1055 @@ ATF_TC_BODY(dbregs_preserve_dr3_continue
 #endif
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs_dr0_trap_variable);
-ATF_TC_HEAD(dbregs_dr0_trap_variable, tc)
+ATF_TC(dbregs_dr0_trap_variable_writeonly_byte);
+ATF_TC_HEAD(dbregs_dr0_trap_variable_writeonly_byte, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
-	"Verify that setting trap with DR0 triggers SIGTRAP");
+	"Verify that setting trap with DR0 triggers SIGTRAP "
+	"(break on data writes only and 1 byte mode)");
 }
 
-ATF_TC_BODY(dbregs_dr0_trap_variable, tc)
+ATF_TC_BODY(dbregs_dr0_trap_variable_writeonly_byte, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	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;
+
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
+	dr7.raw = 0;
+	dr7.bits.global_dr0_breakpoint = 1;
+	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
+	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) {
+		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);
+
+		watchme = 1;
+
+		printf("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		printf("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	r1.dr[0] = (long)(intptr_t)
+	printf("Set DR0 (r1.dr[0]) to new value %#lx\n", r1.dr[0]);
+
+	r1.dr[7] = dr7.raw;
+	printf("Set DR7 (r1.dr[7]) to new value %#lx\n", r1.dr[7]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
+
+	printf("Call CONTINUE for the child process\n");
+	ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+	printf("Before calling %s() 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 19 23:58:30 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Extend dbregs_dr*_trap_variable tests to 1-2-4 byte traps in arch/amd64

Replace the following tests:
 - dbregs_dr0_trap_variable
 - dbregs_dr1_trap_variable
 - dbregs_dr2_trap_variable
 - dbregs_dr3_trap_variable

With new ones:
 - dbregs_dr0_trap_variable_writeonly_byte
 - dbregs_dr1_trap_variable_writeonly_byte
 - dbregs_dr2_trap_variable_writeonly_byte
 - dbregs_dr3_trap_variable_writeonly_byte
 - dbregs_dr0_trap_variable_writeonly_2bytes
 - dbregs_dr1_trap_variable_writeonly_2bytes
 - dbregs_dr2_trap_variable_writeonly_2bytes
 - dbregs_dr3_trap_variable_writeonly_2bytes
 - dbregs_dr0_trap_variable_writeonly_4bytes
 - dbregs_dr1_trap_variable_writeonly_4bytes
 - dbregs_dr2_trap_variable_writeonly_4bytes
 - dbregs_dr3_trap_variable_writeonly_4bytes

All tests pass with my local implementation of debug registers. Once the
interface will be verified, I will prepare it for commit to HEAD.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 19 22:09:29 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add checks for si_code in dbregs_dr[0123]_trap_variable in ATF arch/amd64

Validate that debug register traps generate appropriate SIGTRAP signal with
TRAP_DBREG property in si_code.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.14 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.15
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.14	Sat Feb 18 04:30:34 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sun Feb 19 22:09:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.14 2017/02/18 04:30:34 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.15 2017/02/19 22:09:29 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.14 2017/02/18 04:30:34 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.15 2017/02/19 22:09:29 kamil Exp $");
 
 #include 
 #include 
@@ -1330,6 +1330,9 @@ ATF_TC_BODY(dbregs_dr0_trap_variable, tc
 	volatile int watchme;
 	union u dr7;
 
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
 	dr7.raw = 0;
 	dr7.bits.global_dr0_breakpoint = 1;
 	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
@@ -1392,6 +1395,18 @@ ATF_TC_BODY(dbregs_dr0_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);
+
 	printf("Call CONTINUE for the child process\n");
 	ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
@@ -1444,6 +1459,9 @@ ATF_TC_BODY(dbregs_dr1_trap_variable, tc
 	volatile int watchme;
 	union u dr7;
 
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
 	dr7.raw = 0;
 	dr7.bits.global_dr1_breakpoint = 1;
 	dr7.bits.condition_dr1 = 3;	/* 0b11 -- break on data write */
@@ -1506,6 +1524,18 @@ ATF_TC_BODY(dbregs_dr1_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);
+
 	printf("Call CONTINUE for the child process\n");
 	ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
@@ -1558,6 +1588,9 @@ ATF_TC_BODY(dbregs_dr2_trap_variable, tc
 	volatile int watchme;
 	union u dr7;
 
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
 	dr7.raw = 0;
 	dr7.bits.global_dr2_breakpoint = 1;
 	dr7.bits.condition_dr2 = 3;	/* 0b11 -- break on data write */
@@ -1620,6 +1653,18 @@ ATF_TC_BODY(dbregs_dr2_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_DBREG);
+
 	printf("Call CONTINUE for the child process\n");
 	ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
@@ -1672,6 +1717,9 @@ ATF_TC_BODY(dbregs_dr3_trap_variable, tc
 	volatile int watchme;
 	union u dr7;
 
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
+
 	dr7.raw = 0;
 	dr7.bits.global_dr3_breakpoint = 1;
 	dr7.bits.condition_dr3 = 3;	/* 0b11 -- break on data write */
@@ -1734,6 +1782,18 @@ ATF_TC_BODY(dbregs_dr3_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
+
+	printf("Signal traced to lwpid=%d\n", 

CVS commit: src/tests/kernel/arch/amd64

2017-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 19 22:09:29 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add checks for si_code in dbregs_dr[0123]_trap_variable in ATF arch/amd64

Validate that debug register traps generate appropriate SIGTRAP signal with
TRAP_DBREG property in si_code.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 18 04:30:34 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Synchronize struct dbreg with FreeBSD - rename field member .dbregs to .dr

Currently this code is disabled in HEAD and the dbreg struct has to be
committed first in order to be used. Before enabling it I'm working on
reducing needless differences with FreeBSD and Linux.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-02-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 18 04:30:34 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Synchronize struct dbreg with FreeBSD - rename field member .dbregs to .dr

Currently this code is disabled in HEAD and the dbreg struct has to be
committed first in order to be used. Before enabling it I'm working on
reducing needless differences with FreeBSD and Linux.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.13 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.14
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.13	Sat Feb 18 02:28:21 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sat Feb 18 04:30:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.13 2017/02/18 02:28:21 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.14 2017/02/18 04:30:34 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.13 2017/02/18 02:28:21 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.14 2017/02/18 04:30:34 kamil Exp $");
 
 #include 
 #include 
@@ -209,8 +209,8 @@ ATF_TC_BODY(dbregs_print, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("State of the debug registers:\n");
-	for (i = 0; i < __arraycount(r.dbregs); i++)
-		printf("r[%zu]=%#lx\n", i, r.dbregs[i]);
+	for (i = 0; i < __arraycount(r.dr); i++)
+		printf("r[%zu]=%#lx\n", i, r.dr[i]);
 
 	printf("Before resuming the child process where it left off and "
 	"without signal to be sent\n");
@@ -251,8 +251,8 @@ ATF_TC_BODY(dbregs_preserve_dr0, tc)
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
 	len);
-	ATF_REQUIRE_EQ(__arraycount(r1.dbregs), len);
-	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), 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);
@@ -277,15 +277,15 @@ ATF_TC_BODY(dbregs_preserve_dr0, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("State of the debug registers (r1):\n");
-	for (i = 0; i < __arraycount(r1.dbregs); i++)
-		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
 
-	r1.dbregs[0] = (long)(intptr_t)
-	printf("Set DR0 (r1.dbregs[0]) to new value %#lx\n", r1.dbregs[0]);
+	r1.dr[0] = (long)(intptr_t)
+	printf("Set DR0 (r1.dr[0]) to new value %#lx\n", r1.dr[0]);
 
 	printf("New state of the debug registers (r1):\n");
-	for (i = 0; i < __arraycount(r1.dbregs); i++)
-		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
 
 	printf("Call SETDBREGS for the child process (r1)\n");
 	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
@@ -335,8 +335,8 @@ ATF_TC_BODY(dbregs_preserve_dr1, tc)
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
 	len);
-	ATF_REQUIRE_EQ(__arraycount(r1.dbregs), len);
-	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), 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);
@@ -361,15 +361,15 @@ ATF_TC_BODY(dbregs_preserve_dr1, tc)
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
 
 	printf("State of the debug registers (r1):\n");
-	for (i = 0; i < __arraycount(r1.dbregs); i++)
-		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
 
-	r1.dbregs[1] = (long)(intptr_t)
-	printf("Set DR1 (r1.dbregs[1]) to new value %#lx\n", r1.dbregs[1]);
+	r1.dr[1] = (long)(intptr_t)
+	printf("Set DR1 (r1.dr[1]) to new value %#lx\n", r1.dr[1]);
 
 	printf("New state of the debug registers (r1):\n");
-	for (i = 0; i < __arraycount(r1.dbregs); i++)
-		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+	for (i = 0; i < __arraycount(r1.dr); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dr[i]);
 
 	printf("Call SETDBREGS for the child process (r1)\n");
 	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
@@ -419,8 +419,8 @@ ATF_TC_BODY(dbregs_preserve_dr2, tc)
 
 	printf("Assert that known number of Debug Registers (%zu) is valid\n",
 	len);
-	ATF_REQUIRE_EQ(__arraycount(r1.dbregs), len);
-	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), 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);
@@ -445,15 +445,15 @@ ATF_TC_BODY(dbregs_preserve_dr2, tc)
 	

CVS commit: src/tests/kernel/arch/amd64

2017-02-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 18 02:28:21 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Fix dbregs_dr[0123]_trap_variable in arch/amd64/t_ptrace_wait*

Add missing PT_CONTINUE between two wait(2)-like calls.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.12 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.13
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.12	Thu Feb 16 15:57:45 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sat Feb 18 02:28:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.12 2017/02/16 15:57:45 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.13 2017/02/18 02:28:21 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.12 2017/02/16 15:57:45 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.13 2017/02/18 02:28:21 kamil Exp $");
 
 #include 
 #include 
@@ -1392,6 +1392,9 @@ ATF_TC_BODY(dbregs_dr0_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Call CONTINUE for the child process\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, , 0), child);
 
@@ -1503,6 +1506,9 @@ ATF_TC_BODY(dbregs_dr1_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Call CONTINUE for the child process\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, , 0), child);
 
@@ -1614,6 +1620,9 @@ ATF_TC_BODY(dbregs_dr2_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Call CONTINUE for the child process\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, , 0), child);
 
@@ -1725,6 +1734,9 @@ ATF_TC_BODY(dbregs_dr3_trap_variable, tc
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Call CONTINUE for the child process\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, , 0), child);
 



CVS commit: src/tests/kernel/arch/amd64

2017-02-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 18 02:28:21 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Fix dbregs_dr[0123]_trap_variable in arch/amd64/t_ptrace_wait*

Add missing PT_CONTINUE between two wait(2)-like calls.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2017-01-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 18 05:14:34 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Use siginfo_t to validate tests/kernel/arch/amd64/t_ptrace_wait*

This change makes sure that the fired expected watchpoint with expected
property. It's done with PT_GET_SIGINFO and checking SIGTRAP codes.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.10 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.11
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.10	Mon Jan 16 21:35:59 2017
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Wed Jan 18 05:14:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.10 2017/01/16 21:35:59 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.11 2017/01/18 05:14:34 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.10 2017/01/16 21:35:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.11 2017/01/18 05:14:34 kamil Exp $");
 
 #include 
 #include 
@@ -366,6 +366,8 @@ ATF_TC_BODY(watchpoint_trap_code0, tc)
 	struct ptrace_watchpoint pw;
 	int len = sizeof(pw);
 	int watchme = 1234;
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
 
 	printf("Before forking process PID=%d\n", getpid());
 	ATF_REQUIRE((child = fork()) != -1);
@@ -418,6 +420,20 @@ ATF_TC_BODY(watchpoint_trap_code0, tc)
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_HWWPT);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 0);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
 	pw.pw_md.md_address = NULL;
 	printf("Before writing watchpoint %d (disable it)\n", i);
 	ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, , len) != -1);
@@ -456,6 +472,8 @@ ATF_TC_BODY(watchpoint_trap_code1, tc)
 	struct ptrace_watchpoint pw;
 	int len = sizeof(pw);
 	int watchme = 1234;
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
 
 	printf("Before forking process PID=%d\n", getpid());
 	ATF_REQUIRE((child = fork()) != -1);
@@ -508,6 +526,20 @@ ATF_TC_BODY(watchpoint_trap_code1, tc)
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_HWWPT);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 1);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
 	pw.pw_md.md_address = NULL;
 	printf("Before writing watchpoint %d (disable it)\n", i);
 	ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, , len) != -1);
@@ -546,6 +578,8 @@ ATF_TC_BODY(watchpoint_trap_code2, tc)
 	struct ptrace_watchpoint pw;
 	int len = sizeof(pw);
 	int watchme = 1234;
+	struct ptrace_siginfo info;
+	memset(, 0, sizeof(info));
 
 	printf("Before forking process PID=%d\n", getpid());
 	ATF_REQUIRE((child = fork()) != -1);
@@ -598,6 +632,20 @@ ATF_TC_BODY(watchpoint_trap_code2, tc)
 
 	validate_status_stopped(status, SIGTRAP);
 
+	printf("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	ATF_REQUIRE(ptrace(PT_GET_SIGINFO, child, , 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);
+
+	printf("Before checking siginfo_t\n");
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_HWWPT);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap2, 2);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_trap3, X86_HW_WATCHPOINT_EVENT_FIRED);
+
 	pw.pw_md.md_address = NULL;
 	printf("Before writing watchpoint %d (disable it)\n", i);
 	ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, , len) != -1);
@@ -636,6 +684,8 @@ 

CVS commit: src/tests/kernel/arch/amd64

2017-01-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 18 05:14:34 UTC 2017

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Use siginfo_t to validate tests/kernel/arch/amd64/t_ptrace_wait*

This change makes sure that the fired expected watchpoint with expected
property. It's done with PT_GET_SIGINFO and checking SIGTRAP codes.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 15 12:15:20 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add ATF tests for hardware assisted watchpoints on amd64

Addedd tests:
 - watchpoint_count
 - watchpoint_read
 - watchpoint_write_unmodified
 - watchpoint_trap_code[0123]
 - watchpoint_trap_data_write[0123]
 - watchpoint_trap_data_rw[0123]

These code will be reused later for i386 and moved to a common place like
tests/kernel/arch/x86.

These tests are x86 specific only. The same API but different private
ptrace_watchpoint MD part has to be used on other ports.

All tests pass on amd64.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 15 12:15:20 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add ATF tests for hardware assisted watchpoints on amd64

Addedd tests:
 - watchpoint_count
 - watchpoint_read
 - watchpoint_write_unmodified
 - watchpoint_trap_code[0123]
 - watchpoint_trap_data_write[0123]
 - watchpoint_trap_data_rw[0123]

These code will be reused later for i386 and moved to a common place like
tests/kernel/arch/x86.

These tests are x86 specific only. The same API but different private
ptrace_watchpoint MD part has to be used on other ports.

All tests pass on amd64.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.7 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.8
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.7	Tue Dec 13 13:09:00 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Thu Dec 15 12:15:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.7 2016/12/13 13:09:00 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.8 2016/12/15 12:15:20 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.7 2016/12/13 13:09:00 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.8 2016/12/15 12:15:20 kamil Exp $");
 
 #include 
 #include 
@@ -37,6 +37,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.7 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -137,6 +138,1229 @@ ATF_TC_BODY(regs1, tc)
 }
 #endif
 
+#if defined(__HAVE_PTRACE_WATCHPOINTS)
+ATF_TC(watchpoint_count);
+ATF_TC_HEAD(watchpoint_count, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Call PT_COUNT_WATCHPOINTS and assert four available watchpoints");
+}
+
+ATF_TC_BODY(watchpoint_count, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	int N;
+
+	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 exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETREGS for the child process\n");
+	ATF_REQUIRE((N = ptrace(PT_COUNT_WATCHPOINTS, child, NULL, 0)) != -1);
+	printf("Reported %d watchpoints\n", N);
+
+	ATF_REQUIRE_EQ_MSG(N, 4, "Expected 4 hw watchpoints - got %d", N);
+
+	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, , 0), child);
+
+	validate_status_exited(status, exitval);
+
+	printf("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+#endif
+
+#if defined(__HAVE_PTRACE_WATCHPOINTS)
+ATF_TC(watchpoint_read);
+ATF_TC_HEAD(watchpoint_read, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Call PT_COUNT_WATCHPOINTS and assert four available watchpoints");
+}
+
+ATF_TC_BODY(watchpoint_read, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	int i, N;
+	struct ptrace_watchpoint pw;
+	int len = sizeof(pw);
+
+	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 exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETREGS for the child process\n");
+	ATF_REQUIRE((N = ptrace(PT_COUNT_WATCHPOINTS, child, NULL, 0)) != -1);
+
+	ATF_REQUIRE_EQ_MSG(N, 4, "Expected 4 hw watchpoints - got %d", N);
+
+	for (i = 0; i < N; i++) {
+		printf("Before reading 

CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 13:09:00 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Remove dbregs* in arch/amd64/t_ptrace_wait*

CPU Debug Registers won't be exposed as is to userland.

Hardware Watchpoints will be exported to userland dedicated interface
through the ptrace(2) interface.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.6 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.7
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.6	Tue Dec 13 13:04:18 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Tue Dec 13 13:09:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.6 2016/12/13 13:04:18 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.7 2016/12/13 13:09:00 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.6 2016/12/13 13:04:18 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.7 2016/12/13 13:09:00 kamil Exp $");
 
 #include 
 #include 
@@ -54,36 +54,6 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.6 
 #include "../../t_ptrace_wait.h"
 
 
-union u {
-	long raw;
-	struct {
-		long local_dr0_breakpoint : 1;	/* 0 */
-		long global_dr0_breakpoint : 1;	/* 1 */
-		long local_dr1_breakpoint : 1;	/* 2 */
-		long global_dr1_breakpoint : 1;	/* 3 */
-		long local_dr2_breakpoint : 1;	/* 4 */
-		long global_dr2_breakpoint : 1;	/* 5 */
-		long local_dr3_breakpoint : 1;	/* 6 */
-		long global_dr3_breakpoint : 1;	/* 7 */
-		long local_exact_breakpt : 1;	/* 8 */
-		long global_exact_breakpt : 1;	/* 9 */
-		long reserved_10 : 1;		/* 10 */
-		long rest_trans_memory : 1;	/* 11 */
-		long reserved_12 : 1;		/* 12 */
-		long general_detect_enable : 1;	/* 13 */
-		long reserved_14 : 1;		/* 14 */
-		long reserved_15 : 1;		/* 15 */
-		long condition_dr0 : 2;		/* 16-17 */
-		long len_dr0 : 2;		/* 18-19 */
-		long condition_dr1 : 2;		/* 20-21 */
-		long len_dr1 : 2;		/* 22-23 */
-		long condition_dr2 : 2;		/* 24-25 */
-		long len_dr2 : 2;		/* 26-27 */
-		long condition_dr3 : 2;		/* 28-29 */
-		long len_dr3 : 2;		/* 30-31 */
-	} bits;
-};
-
 #if defined(HAVE_GPREGS)
 ATF_TC(regs1);
 ATF_TC_HEAD(regs1, tc)
@@ -167,1617 +137,12 @@ ATF_TC_BODY(regs1, tc)
 }
 #endif
 
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_print);
-ATF_TC_HEAD(dbregs_print, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	"Verify plain PT_GETDBREGS with printing Debug Registers");
-}
-
-ATF_TC_BODY(dbregs_print, tc)
-{
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	struct dbreg r;
-	size_t i;
-
-	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 exiting of the child process\n");
-		_exit(exitval);
-	}
-	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, , 0), child);
-
-	validate_status_stopped(status, sigval);	
-
-	printf("Call GETDBREGS for the child process\n");
-	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
-
-	printf("State of the debug registers:\n");
-	for (i = 0; i < __arraycount(r.dbregs); i++)
-		printf("r[%zu]=%#lx\n", i, r.dbregs[i]);
-
-	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, , 0), child);
-
-	validate_status_exited(status, exitval);
-
-	printf("Before calling %s() for the child\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
-}
-#endif
-
-#if defined(HAVE_DBREGS)
-ATF_TC(dbregs_preserve_dr0);
-ATF_TC_HEAD(dbregs_preserve_dr0, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	"Verify that setting DR0 is preserved across ptrace(2) calls");
-}
-
-ATF_TC_BODY(dbregs_preserve_dr0, tc)
-{
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	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;
-	int watchme;
-
-	printf("Assert that known number of Debug Registers (%zu) is valid\n",
-	len);
-	

CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 13:09:00 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Remove dbregs* in arch/amd64/t_ptrace_wait*

CPU Debug Registers won't be exposed as is to userland.

Hardware Watchpoints will be exported to userland dedicated interface
through the ptrace(2) interface.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 13:04:18 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add regs1 in arch/amd64/t_ptrace_wait*

regs1:
Call PT_GETREGS and iterate over General Purpose registers

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 13:04:18 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add regs1 in arch/amd64/t_ptrace_wait*

regs1:
Call PT_GETREGS and iterate over General Purpose registers

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.5 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.6
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.5	Wed Dec  7 22:24:44 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Tue Dec 13 13:04:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.5 2016/12/07 22:24:44 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.6 2016/12/13 13:04:18 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.5 2016/12/07 22:24:44 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.6 2016/12/13 13:04:18 kamil Exp $");
 
 #include 
 #include 
@@ -84,6 +84,88 @@ union u {
 	} bits;
 };
 
+#if defined(HAVE_GPREGS)
+ATF_TC(regs1);
+ATF_TC_HEAD(regs1, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Call PT_GETREGS and iterate over General Purpose registers");
+}
+
+ATF_TC_BODY(regs1, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	struct reg r;
+
+	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 exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETREGS for the child process\n");
+	ATF_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1);
+
+	printf("RAX=%#" PRIxREGISTER "\n", r.regs[_REG_RAX]);
+	printf("RBX=%#" PRIxREGISTER "\n", r.regs[_REG_RBX]);
+	printf("RCX=%#" PRIxREGISTER "\n", r.regs[_REG_RCX]);
+	printf("RDX=%#" PRIxREGISTER "\n", r.regs[_REG_RDX]);
+
+	printf("RDI=%#" PRIxREGISTER "\n", r.regs[_REG_RDI]);
+	printf("RSI=%#" PRIxREGISTER "\n", r.regs[_REG_RSI]);
+
+	printf("GS=%#" PRIxREGISTER "\n", r.regs[_REG_GS]);
+	printf("FS=%#" PRIxREGISTER "\n", r.regs[_REG_FS]);
+	printf("ES=%#" PRIxREGISTER "\n", r.regs[_REG_ES]);
+	printf("DS=%#" PRIxREGISTER "\n", r.regs[_REG_DS]);
+	printf("CS=%#" PRIxREGISTER "\n", r.regs[_REG_CS]);
+	printf("SS=%#" PRIxREGISTER "\n", r.regs[_REG_SS]);
+
+	printf("RSP=%#" PRIxREGISTER "\n", r.regs[_REG_RSP]);
+	printf("RIP=%#" PRIxREGISTER "\n", r.regs[_REG_RIP]);
+
+	printf("RFLAGS=%#" PRIxREGISTER "\n", r.regs[_REG_RFLAGS]);
+
+	printf("R8=%#" PRIxREGISTER "\n", r.regs[_REG_R8]);
+	printf("R9=%#" PRIxREGISTER "\n", r.regs[_REG_R9]);
+	printf("R10=%#" PRIxREGISTER "\n", r.regs[_REG_R10]);
+	printf("R11=%#" PRIxREGISTER "\n", r.regs[_REG_R11]);
+	printf("R12=%#" PRIxREGISTER "\n", r.regs[_REG_R12]);
+	printf("R13=%#" PRIxREGISTER "\n", r.regs[_REG_R13]);
+	printf("R14=%#" PRIxREGISTER "\n", r.regs[_REG_R14]);
+	printf("R15=%#" PRIxREGISTER "\n", r.regs[_REG_R15]);
+
+	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, , 0), child);
+
+	validate_status_exited(status, exitval);
+
+	printf("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+#endif
 
 #if defined(HAVE_DBREGS)
 ATF_TC(dbregs_print);
@@ -1673,6 +1755,8 @@ ATF_TP_ADD_TCS(tp)
 	setvbuf(stdout, NULL, _IONBF, 0);
 	setvbuf(stderr, NULL, _IONBF, 0);
 
+	ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1);
+
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_print);
 
 	ATF_TP_ADD_TC_HAVE_DBREGS(tp, dbregs_preserve_dr0);



CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 12:59:46 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: Makefile

Log Message:
Define in CPPFLAGS symbol _KERNTYPES in order to get PRIxREGISTER

This type will be used in t_ptrace_wait* for the printf(3) function.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/arch/amd64/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/Makefile
diff -u src/tests/kernel/arch/amd64/Makefile:1.1 src/tests/kernel/arch/amd64/Makefile:1.2
--- src/tests/kernel/arch/amd64/Makefile:1.1	Fri Dec  2 05:54:15 2016
+++ src/tests/kernel/arch/amd64/Makefile	Tue Dec 13 12:59:46 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2016/12/02 05:54:15 kamil Exp $
+# $NetBSD: Makefile,v 1.2 2016/12/13 12:59:46 kamil Exp $
 
 NOMAN=		# defined
 
@@ -13,4 +13,6 @@ TESTS_C+=	t_ptrace_wait6
 TESTS_C+=	t_ptrace_waitid
 TESTS_C+=	t_ptrace_waitpid
 
+CPPFLAGS+=	-D_KERNTYPES
+
 .include 



CVS commit: src/tests/kernel/arch/amd64

2016-12-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 13 12:59:46 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: Makefile

Log Message:
Define in CPPFLAGS symbol _KERNTYPES in order to get PRIxREGISTER

This type will be used in t_ptrace_wait* for the printf(3) function.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/arch/amd64/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec  7 22:24:44 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Stop using atf_utils_fork() in tests/kernel/arch/amd64/t_ptrace_wait.c

Switch from:
child = atf_utils_fork();
to:
ATF_REQUIRE((child = fork()) != -1);

Prefer the latter as working as intended and not outputing to files with
danger to overwrite files' content after each fork in test-suite.

Discussed with Christos Zoulas.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.4 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.5
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.4	Sun Dec  4 03:38:58 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Wed Dec  7 22:24:44 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.4 2016/12/04 03:38:58 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.5 2016/12/07 22:24:44 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.4 2016/12/04 03:38:58 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.5 2016/12/07 22:24:44 kamil Exp $");
 
 #include 
 #include 
@@ -105,7 +105,7 @@ ATF_TC_BODY(dbregs_print, tc)
 	size_t i;
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -173,7 +173,7 @@ ATF_TC_BODY(dbregs_preserve_dr0, tc)
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -257,7 +257,7 @@ ATF_TC_BODY(dbregs_preserve_dr1, tc)
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -341,7 +341,7 @@ ATF_TC_BODY(dbregs_preserve_dr2, tc)
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -425,7 +425,7 @@ ATF_TC_BODY(dbregs_preserve_dr3, tc)
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -510,7 +510,7 @@ ATF_TC_BODY(dbregs_preserve_dr0_yield, t
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -600,7 +600,7 @@ ATF_TC_BODY(dbregs_preserve_dr1_yield, t
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -690,7 +690,7 @@ ATF_TC_BODY(dbregs_preserve_dr2_yield, t
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -780,7 +780,7 @@ ATF_TC_BODY(dbregs_preserve_dr3_yield, t
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = atf_utils_fork();
+	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);
@@ -870,7 +870,7 @@ ATF_TC_BODY(dbregs_preserve_dr0_continue
 	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
 
 	printf("Before forking process PID=%d\n", getpid());
-	child = 

CVS commit: src/tests/kernel/arch/amd64

2016-12-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec  7 22:24:44 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Stop using atf_utils_fork() in tests/kernel/arch/amd64/t_ptrace_wait.c

Switch from:
child = atf_utils_fork();
to:
ATF_REQUIRE((child = fork()) != -1);

Prefer the latter as working as intended and not outputing to files with
danger to overwrite files' content after each fork in test-suite.

Discussed with Christos Zoulas.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Dec  4 03:38:58 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add dbregs_dr[0123]_trap_variable in arch/amd64/t_ptrace_wait*

Add new preliminary tests for testing that CPU Debug Registers can be used
to trap on a variable (write operation).

dbregs_dr0_trap_variable:
Verify that setting trap with DR0 triggers SIGTRAP

dbregs_dr1_trap_variable:
Verify that setting trap with DR1 triggers SIGTRAP

dbregs_dr2_trap_variable:
Verify that setting trap with DR2 triggers SIGTRAP

dbregs_dr3_trap_variable:
Verify that setting trap with DR3 triggers SIGTRAP

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.3 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.4
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.3	Sat Dec  3 01:41:15 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sun Dec  4 03:38:58 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.3 2016/12/03 01:41:15 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.4 2016/12/04 03:38:58 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.3 2016/12/03 01:41:15 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.4 2016/12/04 03:38:58 kamil Exp $");
 
 #include 
 #include 
@@ -53,6 +53,38 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.3 
 
 #include "../../t_ptrace_wait.h"
 
+
+union u {
+	long raw;
+	struct {
+		long local_dr0_breakpoint : 1;	/* 0 */
+		long global_dr0_breakpoint : 1;	/* 1 */
+		long local_dr1_breakpoint : 1;	/* 2 */
+		long global_dr1_breakpoint : 1;	/* 3 */
+		long local_dr2_breakpoint : 1;	/* 4 */
+		long global_dr2_breakpoint : 1;	/* 5 */
+		long local_dr3_breakpoint : 1;	/* 6 */
+		long global_dr3_breakpoint : 1;	/* 7 */
+		long local_exact_breakpt : 1;	/* 8 */
+		long global_exact_breakpt : 1;	/* 9 */
+		long reserved_10 : 1;		/* 10 */
+		long rest_trans_memory : 1;	/* 11 */
+		long reserved_12 : 1;		/* 12 */
+		long general_detect_enable : 1;	/* 13 */
+		long reserved_14 : 1;		/* 14 */
+		long reserved_15 : 1;		/* 15 */
+		long condition_dr0 : 2;		/* 16-17 */
+		long len_dr0 : 2;		/* 18-19 */
+		long condition_dr1 : 2;		/* 20-21 */
+		long len_dr1 : 2;		/* 22-23 */
+		long condition_dr2 : 2;		/* 24-25 */
+		long len_dr2 : 2;		/* 26-27 */
+		long condition_dr3 : 2;		/* 28-29 */
+		long len_dr3 : 2;		/* 30-31 */
+	} bits;
+};
+
+
 #if defined(HAVE_DBREGS)
 ATF_TC(dbregs_print);
 ATF_TC_HEAD(dbregs_print, tc)
@@ -89,7 +121,7 @@ ATF_TC_BODY(dbregs_print, tc)
 	printf("Before calling %s() for the child\n", TWAIT_FNAME);
 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
 
-	validate_status_stopped(status, sigval);
+	validate_status_stopped(status, sigval);	
 
 	printf("Call GETDBREGS for the child process\n");
 	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
@@ -1192,6 +1224,450 @@ ATF_TC_BODY(dbregs_preserve_dr3_continue
 }
 #endif
 
+#if defined(HAVE_DBREGS)
+ATF_TC(dbregs_dr0_trap_variable);
+ATF_TC_HEAD(dbregs_dr0_trap_variable, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that setting trap with DR0 triggers SIGTRAP");
+}
+
+ATF_TC_BODY(dbregs_dr0_trap_variable, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	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;
+
+	dr7.raw = 0;
+	dr7.bits.global_dr0_breakpoint = 1;
+	dr7.bits.condition_dr0 = 3;	/* 0b11 -- break on data write */
+	dr7.bits.len_dr0 = 3;		/* 0b11 -- 4 bytes */
+
+	printf("Assert that known number of Debug Registers (%zu) is valid\n",
+	len);
+	ATF_REQUIRE_EQ(__arraycount(r1.dbregs), len);
+	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
+
+	printf("Before forking process PID=%d\n", getpid());
+	child = atf_utils_fork();
+	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);
+
+		watchme = 1;
+
+		printf("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		printf("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for 

CVS commit: src/tests/kernel/arch/amd64

2016-12-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Dec  4 03:38:58 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add dbregs_dr[0123]_trap_variable in arch/amd64/t_ptrace_wait*

Add new preliminary tests for testing that CPU Debug Registers can be used
to trap on a variable (write operation).

dbregs_dr0_trap_variable:
Verify that setting trap with DR0 triggers SIGTRAP

dbregs_dr1_trap_variable:
Verify that setting trap with DR1 triggers SIGTRAP

dbregs_dr2_trap_variable:
Verify that setting trap with DR2 triggers SIGTRAP

dbregs_dr3_trap_variable:
Verify that setting trap with DR3 triggers SIGTRAP

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Dec  3 01:41:15 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Define new tests for CPU Debug Registers in t_ptrace_wait{,3,4,6,id,pid}

Rename dbregs1 to dbregs_print
Rename dbregs[2345] to dbregs_preserve_dr[0123]

Add new tests dbregs_preserve_dr[0123]_yield.

dbregs_preserve_dr0_yield:
 Verify that setting DR0 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr1_yield:
 Verify that setting DR1 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr2_yield:
 Verify that setting DR2 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr3_yield:
 Verify that setting DR3 is preserved across ptrace(2) calls with
 scheduler yield

Add new tests dbregs_preserve_dr[0123]_continued.

dbregs_preserve_dr0_continued:
Verify that setting DR0 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr1_continued:
Verify that setting DR1 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr2_continued:
Verify that setting DR2 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr3_continued:
Verify that setting DR3 is preserved across ptrace(2) calls and with
continued child

Use more meaningful names for these tests as they are MD specific and
testing precise functionality. Also there will be a growing number of
tests in this category and prefixing everything with plain dbregs and
trailing with a number cannot be verbose.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.2 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.3
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.2	Fri Dec  2 06:49:00 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Sat Dec  3 01:41:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.2 2016/12/02 06:49:00 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.3 2016/12/03 01:41:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 2016/12/02 06:49:00 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.3 2016/12/03 01:41:15 kamil Exp $");
 
 #include 
 #include 
@@ -39,6 +39,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -53,14 +54,14 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 
 #include "../../t_ptrace_wait.h"
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs1);
-ATF_TC_HEAD(dbregs1, tc)
+ATF_TC(dbregs_print);
+ATF_TC_HEAD(dbregs_print, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Verify plain PT_GETDBREGS with printing Debug Registers");
 }
 
-ATF_TC_BODY(dbregs1, tc)
+ATF_TC_BODY(dbregs_print, tc)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -112,14 +113,14 @@ ATF_TC_BODY(dbregs1, tc)
 #endif
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs2);
-ATF_TC_HEAD(dbregs2, tc)
+ATF_TC(dbregs_preserve_dr0);
+ATF_TC_HEAD(dbregs_preserve_dr0, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Verify that setting DR0 is preserved across ptrace(2) calls");
 }
 
-ATF_TC_BODY(dbregs2, tc)
+ATF_TC_BODY(dbregs_preserve_dr0, tc)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -196,14 +197,14 @@ ATF_TC_BODY(dbregs2, tc)
 #endif
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs3);
-ATF_TC_HEAD(dbregs3, tc)
+ATF_TC(dbregs_preserve_dr1);
+ATF_TC_HEAD(dbregs_preserve_dr1, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Verify that setting DR1 is preserved across ptrace(2) calls");
 }
 
-ATF_TC_BODY(dbregs3, tc)
+ATF_TC_BODY(dbregs_preserve_dr1, tc)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -280,14 +281,14 @@ ATF_TC_BODY(dbregs3, tc)
 #endif
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs4);
-ATF_TC_HEAD(dbregs4, tc)
+ATF_TC(dbregs_preserve_dr2);
+ATF_TC_HEAD(dbregs_preserve_dr2, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Verify that setting DR2 is preserved across ptrace(2) calls");
 }
 
-ATF_TC_BODY(dbregs4, tc)
+ATF_TC_BODY(dbregs_preserve_dr2, tc)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -364,14 +365,14 @@ ATF_TC_BODY(dbregs4, tc)
 #endif
 
 #if defined(HAVE_DBREGS)
-ATF_TC(dbregs5);
-ATF_TC_HEAD(dbregs5, tc)
+ATF_TC(dbregs_preserve_dr3);
+ATF_TC_HEAD(dbregs_preserve_dr3, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Verify that setting DR3 is preserved across ptrace(2) calls");
 }
 
-ATF_TC_BODY(dbregs5, tc)
+ATF_TC_BODY(dbregs_preserve_dr3, tc)
 {
 	const int exitval = 5;
 	const int sigval = SIGSTOP;
@@ -447,16 +448,771 @@ ATF_TC_BODY(dbregs5, tc)
 }
 #endif
 
+#if 

CVS commit: src/tests/kernel/arch/amd64

2016-12-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Dec  3 01:41:15 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Define new tests for CPU Debug Registers in t_ptrace_wait{,3,4,6,id,pid}

Rename dbregs1 to dbregs_print
Rename dbregs[2345] to dbregs_preserve_dr[0123]

Add new tests dbregs_preserve_dr[0123]_yield.

dbregs_preserve_dr0_yield:
 Verify that setting DR0 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr1_yield:
 Verify that setting DR1 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr2_yield:
 Verify that setting DR2 is preserved across ptrace(2) calls with
 scheduler yield

dbregs_preserve_dr3_yield:
 Verify that setting DR3 is preserved across ptrace(2) calls with
 scheduler yield

Add new tests dbregs_preserve_dr[0123]_continued.

dbregs_preserve_dr0_continued:
Verify that setting DR0 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr1_continued:
Verify that setting DR1 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr2_continued:
Verify that setting DR2 is preserved across ptrace(2) calls and with
continued child

dbregs_preserve_dr3_continued:
Verify that setting DR3 is preserved across ptrace(2) calls and with
continued child

Use more meaningful names for these tests as they are MD specific and
testing precise functionality. Also there will be a growing number of
tests in this category and prefixing everything with plain dbregs and
trailing with a number cannot be verbose.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  2 06:49:00 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs[2345] in MD arch/amd64/ t_ptrace_wait{,3,4,6,id,pid}

dbregs2:
Verify that setting DR0 is preserved across ptrace(2) calls

dbregs3:
Verify that setting DR1 is preserved across ptrace(2) calls

dbregs4:
Verify that setting DR2 is preserved across ptrace(2) calls

dbregs5:
Verify that setting DR3 is preserved across ptrace(2) calls

These tests are deliberately fine-grained as they are expected to penetrate
precisely each functional aspect of CPU Debug Registers on amd64 one after
another.

These tests (and MI ones) might be generated or merged with helper
functions, however in order to copy-and-paste them out of a test-suite and
quickly port to other platform (in order to compare results) it's useful to
keep them as stand-alone as they are.

Code from these tests might be shared with other ports in future, for the
same reason keep them currently as they are.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/kernel/arch/amd64

2016-12-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  2 06:49:00 UTC 2016

Modified Files:
src/tests/kernel/arch/amd64: t_ptrace_wait.c

Log Message:
Add new tests dbregs[2345] in MD arch/amd64/ t_ptrace_wait{,3,4,6,id,pid}

dbregs2:
Verify that setting DR0 is preserved across ptrace(2) calls

dbregs3:
Verify that setting DR1 is preserved across ptrace(2) calls

dbregs4:
Verify that setting DR2 is preserved across ptrace(2) calls

dbregs5:
Verify that setting DR3 is preserved across ptrace(2) calls

These tests are deliberately fine-grained as they are expected to penetrate
precisely each functional aspect of CPU Debug Registers on amd64 one after
another.

These tests (and MI ones) might be generated or merged with helper
functions, however in order to copy-and-paste them out of a test-suite and
quickly port to other platform (in order to compare results) it's useful to
keep them as stand-alone as they are.

Code from these tests might be shared with other ports in future, for the
same reason keep them currently as they are.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/arch/amd64/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/arch/amd64/t_ptrace_wait.c
diff -u src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.1 src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.2
--- src/tests/kernel/arch/amd64/t_ptrace_wait.c:1.1	Fri Dec  2 05:54:15 2016
+++ src/tests/kernel/arch/amd64/t_ptrace_wait.c	Fri Dec  2 06:49:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.1 2016/12/02 05:54:15 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.2 2016/12/02 06:49:00 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.1 2016/12/02 05:54:15 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 2016/12/02 06:49:00 kamil Exp $");
 
 #include 
 #include 
@@ -111,12 +111,352 @@ ATF_TC_BODY(dbregs1, tc)
 }
 #endif
 
+#if defined(HAVE_DBREGS)
+ATF_TC(dbregs2);
+ATF_TC_HEAD(dbregs2, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that setting DR0 is preserved across ptrace(2) calls");
+}
+
+ATF_TC_BODY(dbregs2, tc)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	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;
+	int watchme;
+
+	printf("Assert that known number of Debug Registers (%zu) is valid\n",
+	len);
+	ATF_REQUIRE_EQ(__arraycount(r1.dbregs), len);
+	ATF_REQUIRE_EQ(__arraycount(r2.dbregs), len);
+
+	printf("Before forking process PID=%d\n", getpid());
+	child = atf_utils_fork();
+	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 exiting of the child process\n");
+		_exit(exitval);
+	}
+	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, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	printf("Call GETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("State of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dbregs); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+
+	r1.dbregs[0] = (long)(intptr_t)
+	printf("Set DR0 (r1.dbregs[0]) to new value %#lx\n", r1.dbregs[0]);
+
+	printf("New state of the debug registers (r1):\n");
+	for (i = 0; i < __arraycount(r1.dbregs); i++)
+		printf("r1[%zu]=%#lx\n", i, r1.dbregs[i]);
+
+	printf("Call SETDBREGS for the child process (r1)\n");
+	ATF_REQUIRE(ptrace(PT_SETDBREGS, child, , 0) != -1);
+
+	printf("Call GETDBREGS for the child process (r2)\n");
+	ATF_REQUIRE(ptrace(PT_GETDBREGS, child, , 0) != -1);
+
+	printf("Assert that (r1) and (r2) are the same\n");
+	ATF_REQUIRE(memcmp(, , 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);
+
+	printf("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_exited(status, exitval);
+
+	printf("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+#endif
+
+#if defined(HAVE_DBREGS)
+ATF_TC(dbregs3);
+ATF_TC_HEAD(dbregs3, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Verify that setting DR1 is preserved across ptrace(2) calls");
+}
+
+ATF_TC_BODY(dbregs3, tc)
+{
+	const int