Re: CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Date:Mon, 1 Aug 2022 18:55:15 +0300
From:Valery Ushakov 
Message-ID:  

  | The test uses __clone(), not clone() and a followup fix made __clone()
  | visible under plain _NETBSD_SOURCE again - which is the right thing,
  | IMO.  So this change is not necessary (the test only uses __clone()).

Yes, I saw, but the test really should be using clone() - that"s
the thing which needs to work (for those odd apps which use it).

kre


Re: CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Valery Ushakov
On Mon, Aug 01, 2022 at 15:48:40 +, Robert Elz wrote:

> Module Name:  src
> Committed By: kre
> Date: Mon Aug  1 15:48:40 UTC 2022
> 
> Modified Files:
>   src/tests/lib/libc/sys: Makefile
> 
> Log Message:
> Provide _GNU_SOURCE for t_clone now that is required to make clone()
> visible.

The test uses __clone(), not clone() and a followup fix made __clone()
visible under plain _NETBSD_SOURCE again - which is the right thing,
IMO.  So this change is not necessary (the test only uses __clone()).

-uwe


CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Aug  1 15:48:40 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/tests/lib/libc/sys/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/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.71 src/tests/lib/libc/sys/Makefile:1.72
--- src/tests/lib/libc/sys/Makefile:1.71	Wed Apr  6 10:02:55 2022
+++ src/tests/lib/libc/sys/Makefile	Mon Aug  1 15:48:39 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.71 2022/04/06 10:02:55 gson Exp $
+# $NetBSD: Makefile,v 1.72 2022/08/01 15:48:39 kre Exp $
 
 MKMAN=	no
 
@@ -120,6 +120,7 @@ CPPFLAGS.t_futex_robust.c	+= -I${.CURDIR
 
 CPPFLAGS.t_timerfd.c		+= -I${.CURDIR}/../gen
 
+CPPFLAGE.t_clone.c		+= -D_NETBSD_SOURCE -D_GNU_SOURCE
 CPPFLAGS.t_lwp_create.c		+= -D_KERNTYPES
 CPPFLAGS.t_ptrace_sigchld.c	+= -D__TEST_FENV
 CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES -D__TEST_FENV



CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Aug  1 15:48:40 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/tests/lib/libc/sys/Makefile

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



CVS commit: src/tests/lib/libc/sys

2022-06-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun  9 17:39:21 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
There are two hard problems in computer science cache invalidation, naming
and off-by-one errors.

Fix a naming and off-by-one bug... Thanks to Tom Lane for spotting my typo.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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



CVS commit: src/tests/lib/libc/sys

2022-06-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun  9 17:39:21 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
There are two hard problems in computer science cache invalidation, naming
and off-by-one errors.

Fix a naming and off-by-one bug... Thanks to Tom Lane for spotting my typo.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.7
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6	Tue Jun  7 05:39:16 2022
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Thu Jun  9 17:39:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.6 2022/06/07 05:39:16 skrll Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.7 2022/06/09 17:39:21 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -208,7 +208,7 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	DPRINTF("Before resuming the child process where it left off and "
 	"without signal to be sent\n");
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__hppa___) || \
+#if defined(__aarch64__) || defined(__arm__) || defined(__hppa__) || \
 defined(__powerpc__) || defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented



CVS commit: src/tests/lib/libc/sys

2022-06-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jun  7 05:39:16 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
PR/56865: hppa: t_ptrace_core_wait test doesn't know it must advance PC after 
breakpoint

Add __hppa__ to the list of architectures that need to advance to the 
instruction
after the breakpoint

Thanks to Tom Lane for the fix.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5	Sat Mar 26 16:22:50 2022
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Tue Jun  7 05:39:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.5 2022/03/26 16:22:50 martin Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.6 2022/06/07 05:39:16 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -208,8 +208,8 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	DPRINTF("Before resuming the child process where it left off and "
 	"without signal to be sent\n");
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \
-defined(__sh3__) || defined(sparc)
+#if defined(__aarch64__) || defined(__arm__) || defined(__hppa___) || \
+defined(__powerpc__) || defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2022-06-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jun  7 05:39:16 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
PR/56865: hppa: t_ptrace_core_wait test doesn't know it must advance PC after 
breakpoint

Add __hppa__ to the list of architectures that need to advance to the 
instruction
after the breakpoint

Thanks to Tom Lane for the fix.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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



CVS commit: src/tests/lib/libc/sys

2022-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun  4 23:09:18 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
tests/lib/libc: Test mmap(2) with bad hints.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_mmap.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/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.17 src/tests/lib/libc/sys/t_mmap.c:1.18
--- src/tests/lib/libc/sys/t_mmap.c:1.17	Wed Apr  6 10:02:55 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Sat Jun  4 23:09:18 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.18 2022/06/04 23:09:18 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.18 2022/06/04 23:09:18 riastradh Exp $");
 
 #include 
 #include 
@@ -619,6 +619,71 @@ ATF_TC_BODY(mmap_va0, tc)
 	map_check(map, val);
 }
 
+static void
+test_mmap_hint(uintptr_t hintaddr)
+{
+	void *hint = (void *)hintaddr;
+	void *map1 = MAP_FAILED, *map2 = MAP_FAILED, *map3 = MAP_FAILED;
+
+	map1 = mmap(hint, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map1 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap1 hint=%p: errno=%d", hint, errno);
+		goto out;
+	}
+	map2 = mmap(map1, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map2 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap2 hint=%p map1=%p failed: errno=%d",
+		hint, map1, errno);
+		goto out;
+	}
+	map3 = mmap(hint, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map3 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap3 hint=%p map1=%p failed: errno=%d",
+		hint, map1, errno);
+		goto out;
+	}
+out:
+	if (map3 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map3, page) == 0, "munmap3 %p hint=%p",
+		map3, hint);
+	}
+	if (map2 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map2, page) == 0, "munmap2 %p hint=%p",
+		map2, hint);
+	}
+	if (map1 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map1, page) == 0, "munmap1 %p hint=%p",
+		map1, hint);
+	}
+}
+
+ATF_TC(mmap_hint);
+ATF_TC_HEAD(mmap_hint, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test mmap with hints");
+}
+ATF_TC_BODY(mmap_hint, tc)
+{
+	static const int minaddress_mib[] = { CTL_VM, VM_MINADDRESS };
+	static const int maxaddress_mib[] = { CTL_VM, VM_MAXADDRESS };
+	long minaddress, maxaddress;
+	size_t minaddresssz = sizeof(minaddress);
+	size_t maxaddresssz = sizeof(maxaddress);
+
+	ATF_REQUIRE_MSG(sysctl(minaddress_mib, __arraycount(minaddress_mib),
+		, , NULL, 0) == 0,
+	"sysctl vm.minaddress: errno=%d", errno);
+	ATF_REQUIRE_MSG(sysctl(maxaddress_mib, __arraycount(maxaddress_mib),
+		, , NULL, 0) == 0,
+	"sysctl vm.maxaddress: errno=%d", errno);
+
+	test_mmap_hint(0);
+	test_mmap_hint(-1);
+	test_mmap_hint(page);
+	test_mmap_hint(minaddress);
+	test_mmap_hint(maxaddress);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	page = sysconf(_SC_PAGESIZE);
@@ -634,6 +699,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, mmap_truncate);
 	ATF_TP_ADD_TC(tp, mmap_truncate_signal);
 	ATF_TP_ADD_TC(tp, mmap_va0);
+	ATF_TP_ADD_TC(tp, mmap_hint);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2022-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun  4 23:09:18 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
tests/lib/libc: Test mmap(2) with bad hints.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_mmap.c

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



CVS commit: src/tests/lib/libc/sys

2022-04-06 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Wed Apr  6 10:02:55 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile t_mmap.c

Log Message:
Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_mmap.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/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.70 src/tests/lib/libc/sys/Makefile:1.71
--- src/tests/lib/libc/sys/Makefile:1.70	Mon Nov  1 14:33:41 2021
+++ src/tests/lib/libc/sys/Makefile	Wed Apr  6 10:02:55 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.70 2021/11/01 14:33:41 hannken Exp $
+# $NetBSD: Makefile,v 1.71 2022/04/06 10:02:55 gson Exp $
 
 MKMAN=	no
 
@@ -97,6 +97,7 @@ SRCS.t_mprotect=	t_mprotect.c ${SRCS_EXE
 
 LDADD.t_eventfd+=	-lpthread
 LDADD.t_getpid+=	-lpthread
+LDADD.t_mmap+=		-lpthread
 LDADD.t_timerfd+=	-lpthread
 
 LDADD.t_ptrace_sigchld+=	-pthread -lm

Index: src/tests/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.16 src/tests/lib/libc/sys/t_mmap.c:1.17
--- src/tests/lib/libc/sys/t_mmap.c:1.16	Tue Apr  5 15:59:22 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Wed Apr  6 10:02:55 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $");
 
 #include 
 #include 
@@ -74,6 +74,7 @@ __RCSID("$NetBSD: t_mmap.c,v 1.16 2022/0
 #include 
 #include 
 #include 
+#include 
 
 static long	page = 0;
 static char	path[] = "mmap";
@@ -413,6 +414,65 @@ ATF_TC_CLEANUP(mmap_prot_3, tc)
 	(void)unlink(path);
 }
 
+ATF_TC(mmap_reprotect_race);
+
+ATF_TC_HEAD(mmap_reprotect_race, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test for the race condition of PR 52239");
+}
+
+const int mmap_reprotect_race_npages = 13;
+const int mmap_reprotect_iterations = 100;
+
+static void *
+mmap_reprotect_race_thread(void *arg)
+{
+	int i, r;
+	void *p;
+
+	for (i = 0; i < mmap_reprotect_iterations; i++) {
+		/* Get some unrelated memory */
+		p = mmap(0, mmap_reprotect_race_npages * page,
+			 PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+		ATF_REQUIRE(p);
+		r = munmap(p, mmap_reprotect_race_npages * page);
+		ATF_REQUIRE(r == 0);
+	}
+	return 0;
+}
+
+ATF_TC_BODY(mmap_reprotect_race, tc)
+{
+	pthread_t thread;
+	void *p, *q;
+	int i, r;
+
+	r = pthread_create(, 0, mmap_reprotect_race_thread, 0);
+	ATF_REQUIRE(r == 0);
+
+	for (i = 0; i < mmap_reprotect_iterations; i++) {
+		/* Get a placeholder region */
+		p = mmap(0, mmap_reprotect_race_npages * page,
+			 PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (p == MAP_FAILED)
+			atf_tc_fail("mmap: %s", strerror(errno));
+
+		/* Upgrade placeholder to read/write access */
+		q = mmap(p, mmap_reprotect_race_npages * page,
+			 PROT_READ|PROT_WRITE,
+			 MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
+		if (q == MAP_FAILED)
+			atf_tc_fail("update mmap: %s", strerror(errno));
+		ATF_REQUIRE(q == p);
+
+		/* Free it */
+		r = munmap(q, mmap_reprotect_race_npages * page);
+		if (r != 0)
+			atf_tc_fail("munmap: %s", strerror(errno));
+	}
+	pthread_join(thread, NULL);
+}
+
 ATF_TC_WITH_CLEANUP(mmap_truncate);
 ATF_TC_HEAD(mmap_truncate, tc)
 {
@@ -570,6 +630,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, mmap_prot_1);
 	ATF_TP_ADD_TC(tp, mmap_prot_2);
 	ATF_TP_ADD_TC(tp, mmap_prot_3);
+	ATF_TP_ADD_TC(tp, mmap_reprotect_race);
 	ATF_TP_ADD_TC(tp, mmap_truncate);
 	ATF_TP_ADD_TC(tp, mmap_truncate_signal);
 	ATF_TP_ADD_TC(tp, mmap_va0);



CVS commit: src/tests/lib/libc/sys

2022-04-06 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Wed Apr  6 10:02:55 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile t_mmap.c

Log Message:
Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_mmap.c

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



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 15:59:22 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
In the mmap_err test case, mmap the address, not the address of the address.
Should fix PR kern/56780.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_mmap.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/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.15 src/tests/lib/libc/sys/t_mmap.c:1.16
--- src/tests/lib/libc/sys/t_mmap.c:1.15	Tue Apr  5 13:09:54 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Tue Apr  5 15:59:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $");
 
 #include 
 #include 
@@ -215,7 +215,7 @@ ATF_TC_HEAD(mmap_err, tc)
 
 ATF_TC_BODY(mmap_err, tc)
 {
-	size_t addr = SIZE_MAX;
+	void *addr = (void *)-1;
 	void *map;
 
 	errno = 0;
@@ -225,7 +225,7 @@ ATF_TC_BODY(mmap_err, tc)
 	ATF_REQUIRE(errno == EBADF);
 
 	errno = 0;
-	map = mmap(, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
+	map = mmap(addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
 
 	ATF_REQUIRE(map == MAP_FAILED);
 	ATF_REQUIRE_MSG(errno == EINVAL, "errno %d != EINVAL", errno);



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 15:59:22 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
In the mmap_err test case, mmap the address, not the address of the address.
Should fix PR kern/56780.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_mmap.c

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



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 13:09:54 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
When the t_mmap:mmap_err test fails due to errno not having the expected
value of EINVAL, print the actual value.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_mmap.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/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.14 src/tests/lib/libc/sys/t_mmap.c:1.15
--- src/tests/lib/libc/sys/t_mmap.c:1.14	Fri Jun 26 07:50:11 2020
+++ src/tests/lib/libc/sys/t_mmap.c	Tue Apr  5 13:09:54 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $ */
+/* $NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $");
 
 #include 
 #include 
@@ -228,7 +228,7 @@ ATF_TC_BODY(mmap_err, tc)
 	map = mmap(, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
 
 	ATF_REQUIRE(map == MAP_FAILED);
-	ATF_REQUIRE(errno == EINVAL);
+	ATF_REQUIRE_MSG(errno == EINVAL, "errno %d != EINVAL", errno);
 
 	errno = 0;
 	map = mmap(NULL, page, PROT_READ, MAP_ANON|MAP_PRIVATE, INT_MAX, 0);



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 13:09:54 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
When the t_mmap:mmap_err test fails due to errno not having the expected
value of EINVAL, print the actual value.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_mmap.c

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



CVS commit: src/tests/lib/libc/sys

2022-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 26 16:22:50 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.4 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.4	Sat Jul 24 08:39:54 2021
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Sat Mar 26 16:22:50 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.4 2021/07/24 08:39:54 rin Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.5 2022/03/26 16:22:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -209,7 +209,7 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	"without signal to be sent\n");
 
 #if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \
-defined(__sh3__)
+defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2022-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 26 16:22:50 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.h

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



CVS commit: src/tests/lib/libc/sys

2022-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 18 23:35:37 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
getrandom(2): Fix return value checks in automatic tests.

The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_getrandom.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/lib/libc/sys/t_getrandom.c
diff -u src/tests/lib/libc/sys/t_getrandom.c:1.3 src/tests/lib/libc/sys/t_getrandom.c:1.4
--- src/tests/lib/libc/sys/t_getrandom.c:1.3	Tue Aug 25 01:37:38 2020
+++ src/tests/lib/libc/sys/t_getrandom.c	Fri Mar 18 23:35:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $	*/
+/*	$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $");
+__RCSID("$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $");
+
+#include 
 
 #include 
 
@@ -89,7 +91,8 @@ ATF_TC_BODY(getrandom_default, tc)
 	if (n == -1) {
 		ATF_CHECK_EQ(errno, EINTR);
 	} else {
-		ATF_CHECK_EQ((size_t)n, sizeof buf);
+		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 	}
@@ -111,7 +114,8 @@ ATF_TC_BODY(getrandom_nonblock, tc)
 	if (n == -1) {
 		ATF_CHECK_EQ(errno, EAGAIN);
 	} else {
-		ATF_CHECK_EQ((size_t)n, sizeof buf);
+		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 	}
@@ -130,7 +134,8 @@ ATF_TC_BODY(getrandom_insecure, tc)
 	memset(buf, 0, sizeof buf);
 	n = getrandom(buf, sizeof buf, GRND_INSECURE);
 	ATF_CHECK(n != -1);
-	ATF_CHECK_EQ((size_t)n, sizeof buf);
+	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 }
@@ -149,7 +154,8 @@ ATF_TC_BODY(getrandom_insecure_nonblock,
 	memset(buf, 0, sizeof buf);
 	n = getrandom(buf, sizeof buf, GRND_INSECURE|GRND_NONBLOCK);
 	ATF_CHECK(n != -1);
-	ATF_CHECK_EQ((size_t)n, sizeof buf);
+	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 }



CVS commit: src/tests/lib/libc/sys

2022-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 18 23:35:37 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
getrandom(2): Fix return value checks in automatic tests.

The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_getrandom.c

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



CVS commit: src/tests/lib/libc/sys

2022-02-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 20 15:21:14 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_eventfd.c t_timerfd.c

Log Message:
Validate basic fcntl(2) behavior for eventfd and timerfd.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_eventfd.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_timerfd.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/lib/libc/sys/t_eventfd.c
diff -u src/tests/lib/libc/sys/t_eventfd.c:1.2 src/tests/lib/libc/sys/t_eventfd.c:1.3
--- src/tests/lib/libc/sys/t_eventfd.c:1.2	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/t_eventfd.c	Sun Feb 20 15:21:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */
+/* $NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,11 +29,12 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $");
+__RCSID("$NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $");
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -776,6 +777,44 @@ ATF_TC_BODY(eventfd_bufsize, tc)
 
 /*/
 
+ATF_TC(eventfd_fcntl);
+ATF_TC_HEAD(eventfd_fcntl, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"validates fcntl behavior");
+}
+ATF_TC_BODY(eventfd_fcntl, tc)
+{
+	int efd;
+	int val;
+
+	ATF_REQUIRE((efd = eventfd(1, 0)) >= 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) == 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFL, O_NONBLOCK) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) != 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+
+	ATF_REQUIRE(ioctl(efd, FIONREAD, ) == 0);
+	ATF_REQUIRE(val == sizeof(eventfd_t));
+
+	ATF_REQUIRE(ioctl(efd, FIONWRITE, ) == 0);
+	ATF_REQUIRE(val == 0);
+
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(efd, FIONSPACE, ) == -1);
+	(void)close(efd);
+
+	ATF_REQUIRE((efd = eventfd(1, EFD_NONBLOCK | EFD_CLOEXEC)) >= 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFD, 0) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFD, FD_CLOEXEC) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+	(void)close(efd);
+}
+
+/*/
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, eventfd_normal);
@@ -785,6 +824,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_immed);
 	ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_block);
 	ATF_TP_ADD_TC(tp, eventfd_restart);
+	ATF_TP_ADD_TC(tp, eventfd_fcntl);
 
 	return atf_no_error();
 }

Index: src/tests/lib/libc/sys/t_timerfd.c
diff -u src/tests/lib/libc/sys/t_timerfd.c:1.3 src/tests/lib/libc/sys/t_timerfd.c:1.4
--- src/tests/lib/libc/sys/t_timerfd.c:1.3	Mon Nov  1 14:33:41 2021
+++ src/tests/lib/libc/sys/t_timerfd.c	Sun Feb 20 15:21:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -608,6 +609,45 @@ ATF_TC_BODY(timerfd_restart, tc)
 
 /*/
 
+ATF_TC(timerfd_fcntl);
+ATF_TC_HEAD(timerfd_fcntl, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"validates fcntl behavior");
+}
+
+ATF_TC_BODY(timerfd_fcntl, tc)
+{
+	int tfd;
+	int val;
+
+	ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC, 0)) >= 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) == 0);
+	ATF_REQUIRE(fcntl(tfd, F_SETFL, O_NONBLOCK) == 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) != 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) == 0);
+
+	/* If the timer hasn't fired, there is no readable data. */
+	ATF_REQUIRE(ioctl(tfd, FIONREAD, ) == 0);
+	ATF_REQUIRE(val == 0);
+
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONWRITE, ) == -1);
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONSPACE, ) == -1);
+	(void)close(tfd);
+
+	ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC,
+	  TFD_NONBLOCK | TFD_CLOEXEC)) >= 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+	ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) != 0);
+	ATF_REQUIRE(fcntl(tfd, F_SETFD, 0) == 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFD) & 

CVS commit: src/tests/lib/libc/sys

2022-02-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 20 15:21:14 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_eventfd.c t_timerfd.c

Log Message:
Validate basic fcntl(2) behavior for eventfd and timerfd.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_eventfd.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_timerfd.c

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



CVS commit: src/tests/lib/libc/sys

2021-11-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov  1 14:33:42 UTC 2021

Modified Files:
src/tests/lib/libc/sys: Makefile t_timerfd.c

Log Message:
Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_timerfd.c

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



CVS commit: src/tests/lib/libc/sys

2021-11-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov  1 14:33:42 UTC 2021

Modified Files:
src/tests/lib/libc/sys: Makefile t_timerfd.c

Log Message:
Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_timerfd.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/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.69 src/tests/lib/libc/sys/Makefile:1.70
--- src/tests/lib/libc/sys/Makefile:1.69	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/Makefile	Mon Nov  1 14:33:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.69 2021/09/19 15:51:28 thorpej Exp $
+# $NetBSD: Makefile,v 1.70 2021/11/01 14:33:41 hannken Exp $
 
 MKMAN=	no
 
@@ -117,6 +117,8 @@ LDADD.t_posix_fadvise+= ${LIBRUMPBASE}
 CPPFLAGS.t_futex_ops.c		+= -I${.CURDIR}/../../../../lib
 CPPFLAGS.t_futex_robust.c	+= -I${.CURDIR}/../../../../lib
 
+CPPFLAGS.t_timerfd.c		+= -I${.CURDIR}/../gen
+
 CPPFLAGS.t_lwp_create.c		+= -D_KERNTYPES
 CPPFLAGS.t_ptrace_sigchld.c	+= -D__TEST_FENV
 CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES -D__TEST_FENV

Index: src/tests/lib/libc/sys/t_timerfd.c
diff -u src/tests/lib/libc/sys/t_timerfd.c:1.2 src/tests/lib/libc/sys/t_timerfd.c:1.3
--- src/tests/lib/libc/sys/t_timerfd.c:1.2	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/t_timerfd.c	Mon Nov  1 14:33:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $");
 
 #include 
 #include 
@@ -47,6 +47,8 @@ __RCSID("$NetBSD: t_timerfd.c,v 1.2 2021
 
 #include 
 
+#include "isqemu.h"
+
 struct helper_context {
 	int	fd;
 
@@ -70,6 +72,26 @@ wait_barrier(struct helper_context * con
 	return rv == 0 || rv == PTHREAD_BARRIER_SERIAL_THREAD;
 }
 
+static bool
+check_value_against_bounds(uint64_t value, uint64_t lower, uint64_t upper)
+{
+
+	/*
+	 * If running under QEMU make sure the upper bound is large
+	 * enough for the effect of kern/43997
+	 */
+	if (isQEMU()) {
+		upper *= 4;
+	}
+
+	if (value < lower || value > upper) {
+		printf("val %" PRIu64 " not in [ %" PRIu64 ", %" PRIu64 " ]\n",
+		value, lower, upper);
+	}
+
+	return value >= lower && value <= upper;
+}
+
 /*/
 
 static int
@@ -169,10 +191,10 @@ ATF_TC_BODY(timerfd_block, tc)
 	ATF_REQUIRE(timerfd_settime(fd, 0, , NULL) == 0);
 	ATF_REQUIRE(timerfd_read(fd, ) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0);
-	ATF_REQUIRE(val == 1);
+	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(, , );
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }
@@ -203,10 +225,11 @@ ATF_TC_BODY(timerfd_repeating, tc)
 	ATF_REQUIRE(sleep(1) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0);
 	ATF_REQUIRE(timerfd_read(fd, ) == 0);
-	ATF_REQUIRE(val >= 3 && val <= 5);	/* allow some slop */
+	/* allow some slop */
+	ATF_REQUIRE(check_value_against_bounds(val, 3, 5));
 
 	timespecsub(, , );
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }
@@ -237,10 +260,10 @@ ATF_TC_BODY(timerfd_abstime, tc)
 	ATF_REQUIRE(timerfd_settime(fd, TFD_TIMER_ABSTIME, , NULL) == 0);
 	ATF_REQUIRE(timerfd_read(fd, ) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0);
-	ATF_REQUIRE(val == 1);
+	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(, , );
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }



CVS commit: src/tests/lib/libc/sys

2021-10-21 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 21 17:02:38 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_syscall_wait.h

Log Message:
Skip the lib/libc/sys/t_ptrace_waitid:syscall_signal_on_sce test case
with a reference to PR lib/55087.  Marking it as an expected failure
would be more appropriate, but that doesn't work for test cases that
fail by timing out.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_syscall_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_syscall_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.2
--- src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.1	Mon May  4 21:21:30 2020
+++ src/tests/lib/libc/sys/t_ptrace_syscall_wait.h	Thu Oct 21 17:02:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_syscall_wait.h,v 1.1 2020/05/04 21:21:30 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_syscall_wait.h,v 1.2 2021/10/21 17:02:37 gson Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -55,11 +55,13 @@ syscall_body(const char *op)
 
 	memset(, 0, sizeof(info));
 
-#if defined(TWAIT_HAVE_STATUS)
 	if (strstr(op, "signal") != NULL) {
+#if defined(TWAIT_HAVE_STATUS)
 		atf_tc_expect_fail("XXX: behavior under investigation");
-	}
+#else
+		atf_tc_skip("PR lib/55087");
 #endif
+	}
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);



CVS commit: src/tests/lib/libc/sys

2021-10-21 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 21 17:02:38 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_syscall_wait.h

Log Message:
Skip the lib/libc/sys/t_ptrace_waitid:syscall_signal_on_sce test case
with a reference to PR lib/55087.  Marking it as an expected failure
would be more appropriate, but that doesn't work for test cases that
fail by timing out.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_syscall_wait.h

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



CVS commit: src/tests/lib/libc/sys

2021-10-14 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 14 13:50:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_register_wait.h

Log Message:
Remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_register_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_register_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.4
--- src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.3	Mon May 11 12:17:57 2020
+++ src/tests/lib/libc/sys/t_ptrace_register_wait.h	Thu Oct 14 13:50:36 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: t_ptrace_register_wait.h,v 1.3 2020/05/11 12:17:57 kamil Exp $   */
+/*  $NetBSD: t_ptrace_register_wait.h,v 1.4 2021/10/14 13:50:36 gson Exp $   */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@ access_regs(const char *regset, const ch
 #if defined(HAVE_FPREGS)
 	struct fpreg fpr;
 #endif
-	
+
 #if !defined(HAVE_GPREGS)
 	if (strcmp(regset, "regs") == 0)
 		atf_tc_fail("Impossible test scenario!");



CVS commit: src/tests/lib/libc/sys

2021-10-14 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 14 13:50:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_register_wait.h

Log Message:
Remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_register_wait.h

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



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 15:50:06 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
  space is avaiable.

This will be cloned for a forthcoming kevent test case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_poll.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/lib/libc/sys/t_poll.c
diff -u src/tests/lib/libc/sys/t_poll.c:1.6 src/tests/lib/libc/sys/t_poll.c:1.7
--- src/tests/lib/libc/sys/t_poll.c:1.6	Sat Oct  2 14:41:36 2021
+++ src/tests/lib/libc/sys/t_poll.c	Sat Oct  2 15:50:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_poll.c,v 1.6 2021/10/02 14:41:36 thorpej Exp $	*/
+/*	$NetBSD: t_poll.c,v 1.7 2021/10/02 15:50:06 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -252,6 +253,104 @@ fifo_support(void)
 	}
 }
 
+ATF_TC_WITH_CLEANUP(fifo_inout);
+ATF_TC_HEAD(fifo_inout, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Check POLLIN/POLLOUT behavior with fifos");
+}
+
+ATF_TC_BODY(fifo_inout, tc)
+{
+	struct pollfd pfd[2];
+	char *buf;
+	int rfd, wfd;
+	long pipe_buf;
+
+	fifo_support();
+
+	ATF_REQUIRE(mkfifo(fifo_path, 0600) == 0);
+	ATF_REQUIRE((rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)) >= 0);
+	ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY | O_NONBLOCK)) >= 0);
+
+	/* Get the maximum atomic pipe write size. */
+	pipe_buf = fpathconf(wfd, _PC_PIPE_BUF);
+	ATF_REQUIRE(pipe_buf > 1);
+
+	buf = malloc(pipe_buf);
+	ATF_REQUIRE(buf != NULL);
+
+	memset(, 0, sizeof(pfd));
+	pfd[0].fd = rfd;
+	pfd[0].events = POLLIN | POLLRDNORM;
+	pfd[1].fd = wfd;
+	pfd[1].events = POLLOUT | POLLWRNORM;
+
+	/* We expect the FIFO to be writable but not readable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == 0);
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	/* Write a single byte of data into the FIFO. */
+	ATF_REQUIRE(write(wfd, buf, 1) == 1);
+
+	/* We expect the FIFO to be readable and writable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 2);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	/* Read that single byte back out. */
+	ATF_REQUIRE(read(rfd, buf, 1) == 1);
+
+	/*
+	 * Write data into the FIFO until it is full, which is
+	 * defined as insufficient buffer space to hold a the
+	 * maximum atomic pipe write size.
+	 */
+	while (write(wfd, buf, pipe_buf) != -1) {
+		continue;
+	}
+	ATF_REQUIRE(errno == EAGAIN);
+
+	/* We expect the FIFO to be readble but not writable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == 0);
+
+	/* Read a single byte of data from the FIFO. */
+	ATF_REQUIRE(read(rfd, buf, 1) == 1);
+
+	/*
+	 * Because we have read only a single byte out, there will
+	 * be insufficient space for a pipe_buf-sized message, so
+	 * the FIFO should still not be writable.
+	 */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == 0);
+
+	/*
+	 * Now read all of the data out of the FIFO and ensure that
+	 * we get back to the initial state.
+	 */
+	while (read(rfd, buf, pipe_buf) != -1) {
+		continue;
+	}
+	ATF_REQUIRE(errno == EAGAIN);
+
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == 0);
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	(void)close(wfd);
+	(void)close(rfd);
+}
+
+ATF_TC_CLEANUP(fifo_inout, tc)
+{
+	(void)unlink(fifo_path);
+}
+
 ATF_TC_WITH_CLEANUP(fifo_hup1);
 ATF_TC_HEAD(fifo_hup1, tc)
 {
@@ -354,6 +453,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, basic);
 	ATF_TP_ADD_TC(tp, err);
 
+	ATF_TP_ADD_TC(tp, fifo_inout);
 	ATF_TP_ADD_TC(tp, fifo_hup1);
 	ATF_TP_ADD_TC(tp, fifo_hup2);
 



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 15:50:06 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
  space is avaiable.

This will be cloned for a forthcoming kevent test case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_poll.c

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



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 14:41:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_poll.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/lib/libc/sys/t_poll.c
diff -u src/tests/lib/libc/sys/t_poll.c:1.5 src/tests/lib/libc/sys/t_poll.c:1.6
--- src/tests/lib/libc/sys/t_poll.c:1.5	Sat Oct  2 02:07:41 2021
+++ src/tests/lib/libc/sys/t_poll.c	Sat Oct  2 14:41:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_poll.c,v 1.5 2021/10/02 02:07:41 thorpej Exp $	*/
+/*	$NetBSD: t_poll.c,v 1.6 2021/10/02 14:41:36 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -278,6 +278,18 @@ ATF_TC_BODY(fifo_hup1, tc)
 
 	ATF_REQUIRE(poll(, 1, 0) == 1);
 	ATF_REQUIRE((pfd.revents & POLLHUP) != 0);
+
+	/*
+	 * Check that POLLHUP is cleared when a writer re-connects.
+	 * Since the writer will not put any data into the FIFO, we
+	 * expect no events.
+	 */
+	memset(, 0, sizeof(pfd));
+	pfd.fd = rfd;
+	pfd.events = POLLIN;
+
+	ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY)) >= 0);
+	ATF_REQUIRE(poll(, 1, 0) == 0);
 }
 
 ATF_TC_CLEANUP(fifo_hup1, tc)



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 14:41:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_poll.c

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



Re: CVS commit: src/tests/lib/libc/sys

2020-06-22 Thread Rin Okuyama

Committed. Thank you for your comment!

rin

On 2020/06/22 20:09, Kamil Rytarowski wrote:

On 22.06.2020 04:51, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Jun 22 02:51:07 UTC 2020

Modified Files:
src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h

Log Message:
Turn trigger_fpe() back to integer division by zero for a while
until QEMU bug #1668041 is fixed:

https://bugs.launchpad.net/qemu/+bug/1668041

by which floating-point division by zero is not trapped correctly
both on amd64 and i386.

Skip *_crash_fpe tests on powerpc, where integer division by zero
is never trapped.




The intention of this test is just detecting SIGFPE. If the si_code
value is various on different architectures (like one traps on integers
other one on floats), we shall just drop the asserts for si_code and
adapt the trigger_fpe() function to cover promptly more ports.

The qemu bug should be fixed nonetheless.




Re: CVS commit: src/tests/lib/libc/sys

2020-06-22 Thread Kamil Rytarowski
On 22.06.2020 04:51, Rin Okuyama wrote:
> Module Name:  src
> Committed By: rin
> Date: Mon Jun 22 02:51:07 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h
> 
> Log Message:
> Turn trigger_fpe() back to integer division by zero for a while
> until QEMU bug #1668041 is fixed:
> 
> https://bugs.launchpad.net/qemu/+bug/1668041
> 
> by which floating-point division by zero is not trapped correctly
> both on amd64 and i386.
> 
> Skip *_crash_fpe tests on powerpc, where integer division by zero
> is never trapped.
> 


The intention of this test is just detecting SIGFPE. If the si_code
value is various on different architectures (like one traps on integers
other one on floats), we shall just drop the asserts for si_code and
adapt the trigger_fpe() function to cover promptly more ports.

The qemu bug should be fixed nonetheless.




signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-06-17 Thread Rin Okuyama

On 2020/06/17 17:42, Rin Okuyama wrote:

Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64
at least.


Here, powerpc means powerpc/oea, more specifically Mac mini G4.

At the moment, fenv.h doesn't work correctly on booke and ibm4xx, where FPU
is emulated in software. For some processors of oea, m[ft]msr instructions
used in fenv.h may be privileged, and need similar care as booke/ibm4xx.

Thanks,
rin


Re: CVS commit: src/tests/lib/libc/sys

2020-06-06 Thread Andrew Doran
On Sat, Jun 06, 2020 at 06:11:21PM +, Jason R Thorpe wrote:

> Module Name:  src
> Committed By: thorpej
> Date: Sat Jun  6 18:11:21 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_lwp_create.c
> 
> Log Message:
> Add a test case to ensure that _lwp_create() fails with the
> expected error code when a bad new-lwp-id pointer is passed.

Was thinking of just this yesterday - thanks!  It's a fragile bit of code
and has been fixed 3x already this year.

Andrew


Re: CVS commit: src/tests/lib/libc/sys

2020-05-15 Thread Kamil Rytarowski
On 15.05.2020 00:43, Taylor R Campbell wrote:
>> Date: Thu, 14 May 2020 23:36:28 +0200
>> From: Kamil Rytarowski 
>>
>> If a signal would not reach the child process (as it is ignored or
>> masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
>> checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
>> Race free signals could be maybe possible, but with some design rethinking.
> 
> I don't understand -- are you saying that if I mask SIGCHLD, e.g. with
> sigprocmask(SIG_BLOCK), then because sigprop[SIGCHLD] has SA_IGNORE
> set, any SIGCHLD signals will be discarded while I have it masked?
> 

That's it. But it will be discarded only when there is no SIGCHLD signal
handler installed. That's the case in the test.

A debugger catches regular signals only (except crash related ones) when
they reach the debuggee,

> This can't be right, so either I misunderstood what you're saying, or
> something else is afoot with the test that is making it flaky, or
> there's a bug in the kernel.
> 

It's a design.

If we install a signal handler for SIGCHLD in the traced the test is
very stable and we note SIGCHLD always, so there is no bug.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Taylor R Campbell
> Date: Thu, 14 May 2020 23:36:28 +0200
> From: Kamil Rytarowski 
> 
> If a signal would not reach the child process (as it is ignored or
> masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
> checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
> Race free signals could be maybe possible, but with some design rethinking.

I don't understand -- are you saying that if I mask SIGCHLD, e.g. with
sigprocmask(SIG_BLOCK), then because sigprop[SIGCHLD] has SA_IGNORE
set, any SIGCHLD signals will be discarded while I have it masked?

This can't be right, so either I misunderstood what you're saying, or
something else is afoot with the test that is making it flaky, or
there's a bug in the kernel.


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Joerg Sonnenberger
On Thu, May 14, 2020 at 11:36:28PM +0200, Kamil Rytarowski wrote:
> On 14.05.2020 23:02, Joerg Sonnenberger wrote:
> > On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
> >> Module Name:   src
> >> Committed By:  kamil
> >> Date:  Thu May 14 19:21:35 UTC 2020
> >>
> >> Modified Files:
> >>src/tests/lib/libc/sys: t_ptrace_fork_wait.h
> >>
> >> Log Message:
> >> Ignore interception of the SIGCHLD signals.
> >>
> >> SIGCHLD once blocked is discarded by the kernel as it has the
> >> SA_IGNORE property. During the fork(2) operation all signals can be
> >> shortly blocked and missed (unless there is a registered signal
> >> handler in the traced child). This leads to a race in this test if
> >> there would be an intention to catch SIGCHLD.
> > 
> > This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
> > affect whether the signal handler is called, only when. Temporarily
> > masking a signal is different from setting it to SIG_IGN.
> > 
> > Joerg
> > 
> 
> I was looking into it and as there is no signal handler for SIGCHLD, the
> signal is discarded.

Sure, but that doesn't really have anything to do with signal blocking.
That's the part that is confusing.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Kamil Rytarowski
On 14.05.2020 23:02, Joerg Sonnenberger wrote:
> On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
>> Module Name: src
>> Committed By:kamil
>> Date:Thu May 14 19:21:35 UTC 2020
>>
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_fork_wait.h
>>
>> Log Message:
>> Ignore interception of the SIGCHLD signals.
>>
>> SIGCHLD once blocked is discarded by the kernel as it has the
>> SA_IGNORE property. During the fork(2) operation all signals can be
>> shortly blocked and missed (unless there is a registered signal
>> handler in the traced child). This leads to a race in this test if
>> there would be an intention to catch SIGCHLD.
> 
> This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
> affect whether the signal handler is called, only when. Temporarily
> masking a signal is different from setting it to SIG_IGN.
> 
> Joerg
> 

I was looking into it and as there is no signal handler for SIGCHLD, the
signal is discarded.

Another approach to fix the race would be to:

1. Add SIGCHLD signal handler in the traced child.
2. Explicitly masking SIGCHLD in the traced child.

If a signal would not reach the child process (as it is ignored or
masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
Race free signals could be maybe possible, but with some design rethinking.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Joerg Sonnenberger
On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
> Module Name:  src
> Committed By: kamil
> Date: Thu May 14 19:21:35 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_fork_wait.h
> 
> Log Message:
> Ignore interception of the SIGCHLD signals.
> 
> SIGCHLD once blocked is discarded by the kernel as it has the
> SA_IGNORE property. During the fork(2) operation all signals can be
> shortly blocked and missed (unless there is a registered signal
> handler in the traced child). This leads to a race in this test if
> there would be an intention to catch SIGCHLD.

This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
affect whether the signal handler is called, only when. Temporarily
masking a signal is different from setting it to SIG_IGN.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Robert Elz
Date:Mon, 11 May 2020 13:47:45 +0200
From:Kamil Rytarowski 
Message-ID:  <54178983-82d1-df3d-fd54-549a6c73f...@gmx.com>

  | The only purpose of the test is to check whether misaligned program
  | counter can crash the kernel (it can for NetBSD/sparc). Later, if a
  | process dies or runs is not important, thus it is being killed.

That's all fine.

  | A process can disappear after dying and before reappearing as a zombie.

There's a state between running and dead (zombie), that's correct - but
it really doesn't matter, once the process ceases to be alive, it is beyond
killing any more.

  | This is not a bug, but a predicted race.

Yes, that's what I said, and that's fine too.

  | Doing the kill once (and missing the process) is still possibly enough,
  | but correcting it with SIGKILL does not cost.

No, there is no problem with doing the SIGKILL, but if fails for the
above reason, there's absolutely no point trying again.  The process is
gone, it isn't coming back.   It doesn't need killing.

But even if there was a reason to try again (there isn't), one more
attempt would do - inserting an infinite loop is folly.

But I see that you have fixed it, that's good, what's there now looks
much better.   Thanks.

kre




Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Kamil Rytarowski
On 11.05.2020 13:35, Robert Elz wrote:
> Date:Mon, 11 May 2020 11:03:15 +
> From:"Kamil Rytarowski" 
> Message-ID:  <2020050315.54b13f...@cvs.netbsd.org>
> 
>   | Do not fail when trying to kill a dying process
>   |
>   | A dying process can disappear for a while. Rather than aborting, retry
>   | sending SIGKILL to it.
> 
> I don't understand this ... a process should never be able to
> disappear and then reappear (not in any way).   If a SIGKILL (or
> ptrace(PT_KILL) fails with a "no such process" error, then repeating
> it won't (or shouldn't) help - if it does, there's a kernel bug that
> needs fixing (and it is OK for the test to fail until that happens.)
> 
> Further, if the reason for this failure is that the process is
> dying, you probably never needed the kill in the first place (and
> no, I don't mean it should be deleted - the parent is unlikely to
> know the state of the child, so killing it, if that is what is needed
> is the right thing to do ... just that if the kill fails because you
> were too late issuing it, it isn't an error, just a race that you lost,
> and certainly shouldn't be repeated).
> 
> But more than that, adding an infinite loop to the test, where you keep
> doing the kill forever until it succeeds, or errno somehow stops being
> ESRCH looks like a recipe for disaster.
> 
> Just do the kill once, ignore the error if it is ESRCH (and probably
> also ECHILD) report other errors as failures.
> 
> kre
> 

The only purpose of the test is to check whether misaligned program
counter can crash the kernel (it can for NetBSD/sparc). Later, if a
process dies or runs is not important, thus it is being killed.

A process can disappear after dying and before reappearing as a zombie.
This is not a bug, but a predicted race. We already discussed it in the
past, whether to return the same process multiple times or overlook it
for a while during the transition dying->zombie. Once an entity died it
disappeared so the same is true for a process.

Doing the kill once (and missing the process) is still possibly enough,
but correcting it with SIGKILL does not cost.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Robert Elz
Date:Mon, 11 May 2020 11:03:15 +
From:"Kamil Rytarowski" 
Message-ID:  <2020050315.54b13f...@cvs.netbsd.org>

  | Do not fail when trying to kill a dying process
  |
  | A dying process can disappear for a while. Rather than aborting, retry
  | sending SIGKILL to it.

I don't understand this ... a process should never be able to
disappear and then reappear (not in any way).   If a SIGKILL (or
ptrace(PT_KILL) fails with a "no such process" error, then repeating
it won't (or shouldn't) help - if it does, there's a kernel bug that
needs fixing (and it is OK for the test to fail until that happens.)

Further, if the reason for this failure is that the process is
dying, you probably never needed the kill in the first place (and
no, I don't mean it should be deleted - the parent is unlikely to
know the state of the child, so killing it, if that is what is needed
is the right thing to do ... just that if the kill fails because you
were too late issuing it, it isn't an error, just a race that you lost,
and certainly shouldn't be repeated).

But more than that, adding an infinite loop to the test, where you keep
doing the kill forever until it succeeds, or errno somehow stops being
ESRCH looks like a recipe for disaster.

Just do the kill once, ignore the error if it is ESRCH (and probably
also ECHILD) report other errors as failures.

kre



Re: CVS commit: src/tests/lib/libc/sys

2020-04-24 Thread Kamil Rytarowski
On 24.04.2020 05:25, Jason R Thorpe wrote:
> Module Name:  src
> Committed By: thorpej
> Date: Fri Apr 24 03:25:20 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h
> 
> Log Message:
> Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP
> process is the PID, not 1.
> 

Thanks. These tests shall not rely on specific LWP numbers and I will
remove the asserts.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-03-07 Thread Christos Zoulas
In article <5e528f7a-147a-23e7-46da-6b02d76e5...@gmx.com>,
Kamil Rytarowski   wrote:
>-=-=-=-=-=-
>-=-=-=-=-=-
>
>On 07.03.2020 15:53, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Sat Mar  7 14:53:14 UTC 2020
>> 
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h
>> 
>> Log Message:
>> Try to fix the build. This is why all those inlines should really be in a
>> separate file as regular function. The code is too large and hard to manage
>> this way, and only increases in complexity as time goes by.
>> 
>> 
>
>What build configuration was broken?

All of the evbarm ones since t_ptrace_sigchld.c was not including ieefp.h
http://releng.netbsd.org/builds/HEAD/202003070040Z/evbarm-earmhfeb.build.failed

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-03-07 Thread Kamil Rytarowski
On 07.03.2020 15:53, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Sat Mar  7 14:53:14 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h
> 
> Log Message:
> Try to fix the build. This is why all those inlines should really be in a
> separate file as regular function. The code is too large and hard to manage
> this way, and only increases in complexity as time goes by.
> 
> 

What build configuration was broken?



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-02-18 Thread Kamil Rytarowski
On 18.02.2020 16:57, Christos Zoulas wrote:
> In article <20200213152742.081a9f...@cvs.netbsd.org>,
> MichaŠ Górny   wrote:
>> -=-=-=-=-=-
>>
>> Module Name: src
>> Committed By:mgorny
>> Date:Thu Feb 13 15:27:41 UTC 2020
>>
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_wait.c
>>
>> Log Message:
>> Enable combined breakpoint, watchpoint and signal tests
> 
> Let's split this file up. The name does not reflect anymore what this
> is testing and it has become more than 9000 lines long. Because of the
> complexity it keeps breaking the build and because of the size it makes
> fixing it awkward. Kamil/Michal, can you please work on this?
> [ for example the llvm builds are currently broken ]
> 
> Thanks,
> 
> christos
> 

I will do it.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-02-18 Thread Christos Zoulas
In article <20200213152742.081a9f...@cvs.netbsd.org>,
MichaŠ Górny   wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  mgorny
>Date:  Thu Feb 13 15:27:41 UTC 2020
>
>Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c
>
>Log Message:
>Enable combined breakpoint, watchpoint and signal tests

Let's split this file up. The name does not reflect anymore what this
is testing and it has become more than 9000 lines long. Because of the
complexity it keeps breaking the build and because of the size it makes
fixing it awkward. Kamil/Michal, can you please work on this?
[ for example the llvm builds are currently broken ]

Thanks,

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Christos Zoulas
In article <20200213114904.ga30...@bec.de>,
Joerg Sonnenberger   wrote:
>On Thu, Feb 13, 2020 at 10:50:19AM +0100, Joerg Sonnenberger wrote:
>> On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
>> > Module Name:   src
>> > Committed By:  christos
>> > Date:  Thu Feb 13 02:53:46 UTC 2020
>> > 
>> > Modified Files:
>> >src/tests/lib/libc/sys: t_ptrace_x86_wait.h
>> > 
>> > Log Message:
>> > Turn off optimization on a function which contains constant labels.
>> > The optimizer splits it and we end up with 2 copies and duplicate symbols.
>> 
>> Why not just turn them into local labels instead?
>
>Alternatively, suffixing them with %= would create unique labels.

I was looking for that :-)

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Christos Zoulas
In article <20200213095019.ga28...@bec.de>,
Joerg Sonnenberger   wrote:
>On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Thu Feb 13 02:53:46 UTC 2020
>> 
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_x86_wait.h
>> 
>> Log Message:
>> Turn off optimization on a function which contains constant labels.
>> The optimizer splits it and we end up with 2 copies and duplicate symbols.
>
>Why not just turn them into local labels instead?

You mean 1f etc? I was not sure if that would work in the symbol defined case.

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Joerg Sonnenberger
On Thu, Feb 13, 2020 at 10:50:19AM +0100, Joerg Sonnenberger wrote:
> On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
> > Module Name:src
> > Committed By:   christos
> > Date:   Thu Feb 13 02:53:46 UTC 2020
> > 
> > Modified Files:
> > src/tests/lib/libc/sys: t_ptrace_x86_wait.h
> > 
> > Log Message:
> > Turn off optimization on a function which contains constant labels.
> > The optimizer splits it and we end up with 2 copies and duplicate symbols.
> 
> Why not just turn them into local labels instead?

Alternatively, suffixing them with %= would create unique labels.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Joerg Sonnenberger
On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Thu Feb 13 02:53:46 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_x86_wait.h
> 
> Log Message:
> Turn off optimization on a function which contains constant labels.
> The optimizer splits it and we end up with 2 copies and duplicate symbols.

Why not just turn them into local labels instead?

Joerg


CVS commit: src/tests/lib/libc/sys

2019-11-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Nov 12 18:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h

Log Message:
Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by , tested and tweaked by myself.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_ptrace_wait.h

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



CVS commit: src/tests/lib/libc/sys

2019-11-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Nov 12 18:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h

Log Message:
Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by , tested and tweaked by myself.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_ptrace_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.140 src/tests/lib/libc/sys/t_ptrace_wait.c:1.141
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.140	Mon Oct 21 18:36:08 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Nov 12 18:18:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $");
 
 #include 
 #include 
@@ -5478,7 +5478,7 @@ trace_threads(bool trace_create, bool tr
 	lwpid_t lid;
 
 	/* Track created and exited threads */
-	bool traced_lwps[__arraycount(t)];
+	struct lwp_event_count traced_lwps[__arraycount(t)] = {{0, 0}};
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
@@ -5541,8 +5541,6 @@ trace_threads(bool trace_create, bool tr
 	"without signal to be sent\n");
 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
-	memset(traced_lwps, 0, sizeof(traced_lwps));
-
 	for (n = 0; n < (trace_create ? __arraycount(t) : 0); n++) {
 		DPRINTF("Before calling %s() for the child - expected stopped "
 		"SIGTRAP\n", TWAIT_FNAME);
@@ -5574,7 +5572,7 @@ trace_threads(bool trace_create, bool tr
 		lid = state.pe_lwp;
 		DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
 
-		traced_lwps[lid - 1] = true;
+		*FIND_EVENT_COUNT(traced_lwps, lid) += 1;
 
 		DPRINTF("Before resuming the child process where it left off "
 		"and without signal to be sent\n");
@@ -5613,8 +5611,9 @@ trace_threads(bool trace_create, bool tr
 		DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid);
 
 		if (trace_create) {
-			ATF_REQUIRE(traced_lwps[lid - 1] == true);
-			traced_lwps[lid - 1] = false;
+			int *count = FIND_EVENT_COUNT(traced_lwps, lid);
+			ATF_REQUIRE_EQ(*count, 1);
+			*count = 0;
 		}
 
 		DPRINTF("Before resuming the child process where it left off "
@@ -7738,7 +7737,8 @@ ATF_TC_BODY(thread_concurrent_signals, t
 	const int sigval = SIGSTOP;
 	pid_t child, wpid;
 	int status;
-	int signal_counts[THREAD_CONCURRENT_SIGNALS_NUM] = {0};
+	struct lwp_event_count signal_counts[THREAD_CONCURRENT_SIGNALS_NUM]
+	= {{0, 0}};
 	unsigned int i;
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -7816,21 +7816,16 @@ ATF_TC_BODY(thread_concurrent_signals, t
 		"lwp=%d, expected %d, got %d", info.psi_lwpid,
 		expected_sig, WSTOPSIG(status));
 
-		/* We assume that LWPs will be given successive numbers starting
-		 * from 2.
-		 */
-		ATF_REQUIRE(info.psi_lwpid >= 2);
-		ATF_REQUIRE((unsigned int)info.psi_lwpid <
-		__arraycount(signal_counts)+2);
-		signal_counts[info.psi_lwpid-2]++;
+		*FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1;
 
 		DPRINTF("Before resuming the child process\n");
 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 	}
 
 	for (i = 0; i < __arraycount(signal_counts); i++)
-		ATF_CHECK_EQ_MSG(signal_counts[i], 1, "signal_counts[%d]=%d",
-		i, signal_counts[i]);
+		ATF_CHECK_EQ_MSG(signal_counts[i].lec_count, 1,
+		"signal_counts[%d].lec_count=%d; lec_lwp=%d",
+		i, signal_counts[i].lec_count, signal_counts[i].lec_lwp);
 
 	validate_status_exited(status, exitval);
 }

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.17 src/tests/lib/libc/sys/t_ptrace_wait.h:1.18
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.17	Sat May 25 03:22:53 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Tue Nov 12 18:18:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.17 2019/05/25 03:22:53 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.18 2019/11/12 18:18:04 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -674,6 +674,30 @@ trigger_bus(void)
 	*p = 'a';
 }
 
+struct lwp_event_count {
+	lwpid_t lec_lwp;
+	int lec_count;
+};
+
+static int *
+find_event_count(struct lwp_event_count list[], lwpid_t lwp, size_t max_lwps)
+{
+	size_t i;
+
+	for (i = 0; i < max_lwps; i++) {
+		

CVS commit: src/tests/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:36:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.139 src/tests/lib/libc/sys/t_ptrace_wait.c:1.140
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.139	Mon Oct 21 18:31:40 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Oct 21 18:36:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $");
 
 #include 
 #include 
@@ -121,10 +121,6 @@ static int debug = 0;
 	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
-#ifndef TEST_LWP_ENABLED
-#define TEST_LWP_ENABLED 1
-#endif
-
 /// 
 
 static void
@@ -5484,11 +5480,6 @@ trace_threads(bool trace_create, bool tr
 	/* Track created and exited threads */
 	bool traced_lwps[__arraycount(t)];
 
-#if !TEST_LWP_ENABLED
-	if (trace_create || trace_exit)
-		atf_tc_skip("PR kern/51995");
-#endif
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {



CVS commit: src/tests/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:36:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:31:40 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:31:40 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.138 src/tests/lib/libc/sys/t_ptrace_wait.c:1.139
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.138	Mon Oct 21 17:07:00 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Oct 21 18:31:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.138 2019/10/21 17:07:00 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.138 2019/10/21 17:07:00 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $");
 
 #include 
 #include 
@@ -121,10 +121,6 @@ static int debug = 0;
 	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
-#ifndef TEST_VFORK_ENABLED
-#define TEST_VFORK_ENABLED 1
-#endif
-
 #ifndef TEST_LWP_ENABLED
 #define TEST_LWP_ENABLED 1
 #endif
@@ -3269,7 +3265,6 @@ FORK_TEST(fork15, "fork", true, false, t
 FORK_TEST(fork16, "fork", true, true, true, true)
 #endif
 
-#if TEST_VFORK_ENABLED
 FORK_TEST(vfork1, "vfork", false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 FORK_TEST(vfork2, "vfork", false, true, false, false)
@@ -3294,7 +3289,6 @@ FORK_TEST(vfork14, "vfork", true, true, 
 FORK_TEST(vfork15, "vfork", true, false, true, true)
 FORK_TEST(vfork16, "vfork", true, true, true, true)
 #endif
-#endif
 
 FORK_TEST(posix_spawn1, "spawn", false, false, false, false)
 FORK_TEST(posix_spawn2, "spawn", false, true, false, false)
@@ -3497,22 +3491,17 @@ ATF_TC_BODY(name, tc)			\
 
 FORK_DETACH_FORKER(posix_spawn_detach_spawner, "spawn", false)
 FORK_DETACH_FORKER(fork_detach_forker, "fork", false)
-#if TEST_VFORK_ENABLED
 FORK_DETACH_FORKER(vfork_detach_vforker, "vfork", false)
 FORK_DETACH_FORKER(vfork_detach_vforkerdone, "vforkdone", false)
-#endif
 
 FORK_DETACH_FORKER(posix_spawn_kill_spawner, "spawn", true)
 FORK_DETACH_FORKER(fork_kill_forker, "fork", true)
-#if TEST_VFORK_ENABLED
 FORK_DETACH_FORKER(vfork_kill_vforker, "vfork", true)
 FORK_DETACH_FORKER(vfork_kill_vforkerdone, "vforkdone", true)
 #endif
-#endif
 
 /// 
 
-#if TEST_VFORK_ENABLED
 static void
 traceme_vfork_fork_body(pid_t (*fn)(void))
 {
@@ -3571,7 +3560,6 @@ ATF_TC_BODY(name, tc)			\
 
 TRACEME_VFORK_FORK_TEST(traceme_vfork_fork, fork)
 TRACEME_VFORK_FORK_TEST(traceme_vfork_vfork, vfork)
-#endif
 
 /// 
 
@@ -6126,13 +6114,11 @@ FORK2_TEST(posix_spawn_singalmasked, "sp
 FORK2_TEST(posix_spawn_singalignored, "spawn", false, true)
 FORK2_TEST(fork_singalmasked, "fork", true, false)
 FORK2_TEST(fork_singalignored, "fork", false, true)
-#if TEST_VFORK_ENABLED
 FORK2_TEST(vfork_singalmasked, "vfork", true, false)
 FORK2_TEST(vfork_singalignored, "vfork", false, true)
 FORK2_TEST(vforkdone_singalmasked, "vforkdone", true, false)
 FORK2_TEST(vforkdone_singalignored, "vforkdone", false, true)
 #endif
-#endif
 
 /// 
 
@@ -6991,7 +6977,6 @@ CLONE_TEST(clone_files8, CLONE_FILES, tr
 //CLONE_TEST(clone_sighand8, CLONE_SIGHAND, true, true, true)
 #endif
 
-#if TEST_VFORK_ENABLED
 CLONE_TEST(clone_vfork1, CLONE_VFORK, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 CLONE_TEST(clone_vfork2, CLONE_VFORK, true, false, false)
@@ -7004,7 +6989,6 @@ CLONE_TEST(clone_vfork6, CLONE_VFORK, tr
 CLONE_TEST(clone_vfork7, CLONE_VFORK, false, true, true)
 CLONE_TEST(clone_vfork8, CLONE_VFORK, true, true, true)
 #endif
-#endif
 
 /// 
 
@@ -7367,15 +7351,12 @@ CLONE_TEST2(clone_files_signalignored, C
 CLONE_TEST2(clone_files_signalmasked, CLONE_FILES, false, true)
 //CLONE_TEST2(clone_sighand_signalignored, CLONE_SIGHAND, true, false) // XXX
 //CLONE_TEST2(clone_sighand_signalmasked, CLONE_SIGHAND, false, true)  // XXX
-#if TEST_VFORK_ENABLED
 CLONE_TEST2(clone_vfork_signalignored, CLONE_VFORK, true, false)
 CLONE_TEST2(clone_vfork_signalmasked, CLONE_VFORK, false, true)
 #endif
-#endif
 
 /// 
 
-#if TEST_VFORK_ENABLED
 #if defined(TWAIT_HAVE_PID)
 static void
 traceme_vfork_clone_body(int 

CVS commit: src/tests/lib/libc/sys

2019-10-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 09:42:15 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.136 src/tests/lib/libc/sys/t_ptrace_wait.c:1.137
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.136	Sun Oct 13 04:05:39 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sun Oct 13 09:42:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.136 2019/10/13 04:05:39 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.137 2019/10/13 09:42:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.136 2019/10/13 04:05:39 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.137 2019/10/13 09:42:15 kamil Exp $");
 
 #include 
 #include 
@@ -5458,12 +5458,15 @@ TRACEME_EXEC(traceme_signalignored_exec,
 #define TRACE_THREADS_NUM 100
 
 static volatile int done;
+pthread_mutex_t trace_threads_mtx = PTHREAD_MUTEX_INITIALIZER;
 
 static void *
 trace_threads_cb(void *arg __unused)
 {
 
+	pthread_mutex_lock(_threads_mtx);
 	done++;
+	pthread_mutex_unlock(_threads_mtx);
 
 	while (done < TRACE_THREADS_NUM)
 		sched_yield();



CVS commit: src/tests/lib/libc/sys

2019-10-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 09:42:15 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 04:05:39 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Enable TEST_LWP_ENABLED in t_ptrace_wait*

The LWP events (created, exited) are now reliable in my local tests.

PR kern/51420
PR kern/51995


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.135 src/tests/lib/libc/sys/t_ptrace_wait.c:1.136
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.135	Sun Oct 13 04:00:12 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sun Oct 13 04:05:39 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.135 2019/10/13 04:00:12 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.136 2019/10/13 04:05:39 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.135 2019/10/13 04:00:12 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.136 2019/10/13 04:05:39 kamil Exp $");
 
 #include 
 #include 
@@ -126,7 +126,7 @@ static int debug = 0;
 #endif
 
 #ifndef TEST_LWP_ENABLED
-#define TEST_LWP_ENABLED 0
+#define TEST_LWP_ENABLED 1
 #endif
 
 /// 



CVS commit: src/tests/lib/libc/sys

2019-10-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 04:05:39 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Enable TEST_LWP_ENABLED in t_ptrace_wait*

The LWP events (created, exited) are now reliable in my local tests.

PR kern/51420
PR kern/51995


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 04:00:12 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Bump the number of threads in LWP t_ptrace_wait*() tests from to 100

This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:

 - trace_thread_nolwpevents
 - trace_thread_lwpexit
 - trace_thread_lwpcreate
 - trace_thread_lwpcreate_and_exit


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 04:00:12 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Bump the number of threads in LWP t_ptrace_wait*() tests from to 100

This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:

 - trace_thread_nolwpevents
 - trace_thread_lwpexit
 - trace_thread_lwpcreate
 - trace_thread_lwpcreate_and_exit


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.134 src/tests/lib/libc/sys/t_ptrace_wait.c:1.135
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.134	Wed Oct  2 23:15:09 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sun Oct 13 04:00:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.134 2019/10/02 23:15:09 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.135 2019/10/13 04:00:12 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.134 2019/10/02 23:15:09 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.135 2019/10/13 04:00:12 kamil Exp $");
 
 #include 
 #include 
@@ -5455,6 +5455,8 @@ TRACEME_EXEC(traceme_signalignored_exec,
 
 /// 
 
+#define TRACE_THREADS_NUM 100
+
 static volatile int done;
 
 static void *
@@ -5463,8 +5465,8 @@ trace_threads_cb(void *arg __unused)
 
 	done++;
 
-	while (done < 3)
-		continue;
+	while (done < TRACE_THREADS_NUM)
+		sched_yield();
 
 	return NULL;
 }
@@ -5483,7 +5485,7 @@ trace_threads(bool trace_create, bool tr
 	const int elen = sizeof(event);
 	struct ptrace_siginfo info;
 
-	pthread_t t[3];
+	pthread_t t[TRACE_THREADS_NUM];
 	int rv;
 	size_t n;
 	lwpid_t lid;



CVS commit: src/tests/lib/libc/sys

2019-10-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct  2 23:15:09 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove ATF t_ptrace_wait test suspend1

The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.133 src/tests/lib/libc/sys/t_ptrace_wait.c:1.134
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.133	Tue Oct  1 22:26:38 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed Oct  2 23:15:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.133 2019/10/01 22:26:38 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.134 2019/10/02 23:15:09 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.133 2019/10/01 22:26:38 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.134 2019/10/02 23:15:09 kamil Exp $");
 
 #include 
 #include 
@@ -6354,133 +6354,6 @@ lwp_main_stop(void *arg)
 	_lwp_exit();
 }
 
-ATF_TC(suspend1);
-ATF_TC_HEAD(suspend1, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	"Verify that a thread can be suspended by a debugger and later "
-	"resumed by a tracee");
-}
-
-ATF_TC_BODY(suspend1, tc)
-{
-	const int exitval = 5;
-	const int sigval = SIGSTOP;
-	pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-	int status;
-#endif
-	ucontext_t uc;
-	lwpid_t lid;
-	static const size_t ssize = 16*1024;
-	void *stack;
-	struct ptrace_lwpinfo pl;
-	struct ptrace_siginfo psi;
-	volatile int go = 0;
-
-	DPRINTF("Before forking process PID=%d\n", getpid());
-	SYSCALL_REQUIRE((child = fork()) != -1);
-	if (child == 0) {
-		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
-		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-		DPRINTF("Before raising %s from child\n", strsignal(sigval));
-		FORKEE_ASSERT(raise(sigval) == 0);
-
-		DPRINTF("Before allocating memory for stack in child\n");
-		FORKEE_ASSERT((stack = malloc(ssize)) != NULL);
-
-		DPRINTF("Before making context for new lwp in child\n");
-		_lwp_makecontext(, lwp_main_stop, NULL, NULL, stack, ssize);
-
-		DPRINTF("Before creating new in child\n");
-		FORKEE_ASSERT(_lwp_create(, 0, ) == 0);
-
-		while (go == 0)
-			continue;
-
-		raise(SIGINT);
-
-		FORKEE_ASSERT(_lwp_continue(lid) == 0);
-
-		DPRINTF("Before waiting for lwp %d to exit\n", lid);
-		FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0);
-
-		DPRINTF("Before verifying that reported %d and running lid %d "
-		"are the same\n", lid, the_lwp_id);
-		FORKEE_ASSERT_EQ(lid, the_lwp_id);
-
-		DPRINTF("Before exiting of the child process\n");
-		_exit(exitval);
-	}
-	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
-
-	validate_status_stopped(status, sigval);
-
-	DPRINTF("Before resuming the child process where it left off and "
-	"without signal to be sent\n");
-	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
-	DPRINTF("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);
-
-	DPRINTF("Before reading siginfo and lwpid_t\n");
-	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(psi)) != -1);
-
-	DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid);
-	SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1);
-
-DPRINTF("Write new go to tracee (PID=%d) from tracer (PID=%d)\n",
-	child, getpid());
-	SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, __UNVOLATILE(), 1) != -1);
-
-	DPRINTF("Before resuming the child process where it left off and "
-	"without signal to be sent\n");
-	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
-	DPRINTF("Before calling %s() for the child - expected stopped "
-	"SIGINT\n", TWAIT_FNAME);
-	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
-
-	validate_status_stopped(status, SIGINT);
-
-	pl.pl_lwpid = 0;
-
-	SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, , sizeof(pl)) != -1);
-	while (pl.pl_lwpid != 0) {
-
-		SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, , sizeof(pl)) != -1);
-		switch (pl.pl_lwpid) {
-		case 1:
-			ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL);
-			break;
-		case 2:
-			ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SUSPENDED);
-			break;
-		}
-	}
-
-	DPRINTF("Before resuming the child process where it left off and "
-	"without signal to be sent\n");
-	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, 

CVS commit: src/tests/lib/libc/sys

2019-10-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct  2 23:15:09 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove ATF t_ptrace_wait test suspend1

The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Oct  1 22:26:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests

Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Oct  1 22:26:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests

Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.132 src/tests/lib/libc/sys/t_ptrace_wait.c:1.133
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.132	Tue Oct  1 21:13:30 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Oct  1 22:26:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.132 2019/10/01 21:13:30 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.133 2019/10/01 22:26:38 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.132 2019/10/01 21:13:30 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.133 2019/10/01 22:26:38 kamil Exp $");
 
 #include 
 #include 
@@ -140,7 +140,10 @@ traceme_raise(int sigval)
 	int status;
 #endif
 
+	ptrace_state_t state, zero_state;
+	const int slen = sizeof(state);
 	struct ptrace_siginfo info;
+	memset(_state, 0, sizeof(zero_state));
 	memset(, 0, sizeof(info));
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -170,6 +173,9 @@ traceme_raise(int sigval)
 	switch (sigval) {
 	case SIGKILL:
 		validate_status_signaled(status, sigval, 0);
+		SYSCALL_REQUIRE(
+		ptrace(PT_GET_PROCESS_STATE, child, , slen) == -1);
+
 		break;
 	default:
 		validate_status_stopped(status, sigval);
@@ -188,6 +194,11 @@ traceme_raise(int sigval)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
 
+		DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error");
+		SYSCALL_REQUIRE(
+		ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
+		ATF_REQUIRE(memcmp(, _state, slen) == 0);
+
 		DPRINTF("Before resuming the child process where it left off "
 		"and without signal to be sent\n");
 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);



CVS commit: src/tests/lib/libc/sys

2019-10-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Oct  1 21:13:30 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add a few static asserts in t_ptrace_wait.c for conditions that must be kept

Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/tests/lib/libc/sys/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/lib/libc/sys

2019-10-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Oct  1 21:13:30 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add a few static asserts in t_ptrace_wait.c for conditions that must be kept

Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.131 src/tests/lib/libc/sys/t_ptrace_wait.c:1.132
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.131	Mon Jul  1 02:04:37 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Oct  1 21:13:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.131 2019/07/01 02:04:37 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.132 2019/10/01 21:13:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.131 2019/07/01 02:04:37 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.132 2019/10/01 21:13:30 kamil Exp $");
 
 #include 
 #include 
@@ -41,6 +41,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.13
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -73,6 +74,20 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.13
 
 #include 
 
+/* Assumptions in the kernel code that must be kept. */
+static_assert(sizeof(((struct ptrace_state *)0)->pe_report_event) ==
+sizeof(((siginfo_t *)0)->si_pe_report_event),
+"pe_report_event and si_pe_report_event must be of the same size");
+static_assert(sizeof(((struct ptrace_state *)0)->pe_other_pid) ==
+sizeof(((siginfo_t *)0)->si_pe_other_pid),
+"pe_other_pid and si_pe_other_pid must be of the same size");
+static_assert(sizeof(((struct ptrace_state *)0)->pe_lwp) ==
+sizeof(((siginfo_t *)0)->si_pe_lwp),
+"pe_lwp and si_pe_lwp must be of the same size");
+static_assert(sizeof(((struct ptrace_state *)0)->pe_other_pid) ==
+sizeof(((struct ptrace_state *)0)->pe_lwp),
+"pe_other_pid and pe_lwp must be of the same size");
+
 #include "h_macros.h"
 
 #include "t_ptrace_wait.h"



CVS commit: src/tests/lib/libc/sys

2019-07-13 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Sat Jul 13 12:44:02 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_getitimer.c

Log Message:
In the setitimer_old test case, allow for time passing between the two
setitimer() calls.  Should fix PR kern/54370.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_getitimer.c

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



CVS commit: src/tests/lib/libc/sys

2019-07-13 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Sat Jul 13 12:44:02 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_getitimer.c

Log Message:
In the setitimer_old test case, allow for time passing between the two
setitimer() calls.  Should fix PR kern/54370.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_getitimer.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/lib/libc/sys/t_getitimer.c
diff -u src/tests/lib/libc/sys/t_getitimer.c:1.2 src/tests/lib/libc/sys/t_getitimer.c:1.3
--- src/tests/lib/libc/sys/t_getitimer.c:1.2	Thu Mar 22 18:20:46 2012
+++ src/tests/lib/libc/sys/t_getitimer.c	Sat Jul 13 12:44:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getitimer.c,v 1.2 2012/03/22 18:20:46 christos Exp $ */
+/* $NetBSD: t_getitimer.c,v 1.3 2019/07/13 12:44:02 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_getitimer.c,v 1.2 2012/03/22 18:20:46 christos Exp $");
+__RCSID("$NetBSD: t_getitimer.c,v 1.3 2019/07/13 12:44:02 gson Exp $");
 
 #include 
 
@@ -175,11 +175,13 @@ ATF_TC_BODY(setitimer_old, tc)
 	struct itimerval it, ot;
 
 	/*
-	 * Make two calls; the second one
-	 * should store the old values.
+	 * Make two calls; the second one should store the old
+	 * timer value which should be the same as that set in
+	 * the first call, or slightly less due to time passing
+	 * between the two calls.
 	 */
 	it.it_value.tv_sec = 4;
-	it.it_value.tv_usec = 3;
+	it.it_value.tv_usec = 99;
 
 	it.it_interval.tv_sec = 0;
 	it.it_interval.tv_usec = 0;
@@ -194,7 +196,8 @@ ATF_TC_BODY(setitimer_old, tc)
 
 	ATF_REQUIRE(setitimer(ITIMER_REAL, , ) == 0);
 
-	if (ot.it_value.tv_sec != 4 || ot.it_value.tv_usec != 3)
+	/* Check seconds only as microseconds may have decremented */
+	if (ot.it_value.tv_sec != 4)
 		atf_tc_fail("setitimer(2) did not store old values");
 }
 



Re: CVS commit: src/tests/lib/libc/sys

2019-07-01 Thread Kamil Rytarowski
On 01.07.2019 14:59, Robert Elz wrote:
> Date:Mon, 1 Jul 2019 11:55:57 +0200
> From:Joerg Sonnenberger 
> Message-ID:  <20190701095557.ga55...@bec.de>
> 
>   | On Mon, Jul 01, 2019 at 02:04:38AM +, Kamil Rytarowski wrote:
> 
>   | > Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
>   | > signedness bit shifts.
>   |
>   | This change makes no sense.
> 
> Certainly the size_t cast is pointless ... and I have no idea what
> the comment in the commit message about bit shifts is about, this is
> (was) a simple comparison of an unsigned with a signed, which the
> cast to ssize_t turns into a signed comparison, which is as it should be.
> There are no bit shifts.
> 
> kre
> 
> 

OK, it was cast of 32bit value to ssize_t that can be 64bit.

The original type is uint32_t, not int32_t, so intermediate cast is not
needed.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2019-07-01 Thread Robert Elz
Date:Mon, 1 Jul 2019 11:55:57 +0200
From:Joerg Sonnenberger 
Message-ID:  <20190701095557.ga55...@bec.de>

  | On Mon, Jul 01, 2019 at 02:04:38AM +, Kamil Rytarowski wrote:

  | > Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
  | > signedness bit shifts.
  |
  | This change makes no sense.

Certainly the size_t cast is pointless ... and I have no idea what
the comment in the commit message about bit shifts is about, this is
(was) a simple comparison of an unsigned with a signed, which the
cast to ssize_t turns into a signed comparison, which is as it should be.
There are no bit shifts.

kre




Re: CVS commit: src/tests/lib/libc/sys

2019-07-01 Thread Joerg Sonnenberger
On Mon, Jul 01, 2019 at 02:04:38AM +, Kamil Rytarowski wrote:
> Module Name:  src
> Committed By: kamil
> Date: Mon Jul  1 02:04:38 UTC 2019
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c
> 
> Log Message:
> Avoid GCC warning on NetBSD/i386
> 
> Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
> signedness bit shifts.

This change makes no sense.

Joerg


CVS commit: src/tests/lib/libc/sys

2019-06-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jul  1 02:04:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Avoid GCC warning on NetBSD/i386

Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
signedness bit shifts.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.130 src/tests/lib/libc/sys/t_ptrace_wait.c:1.131
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.130	Sun Jun 30 21:20:04 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Jul  1 02:04:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.131 2019/07/01 02:04:37 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.131 2019/07/01 02:04:37 kamil Exp $");
 
 #include 
 #include 
@@ -7706,7 +7706,7 @@ static ssize_t core_find_note(const char
 			note_hdr.n_namesz <= sizeof(name_buf)) {
 SYSCALL_REQUIRE(pread(core_fd, name_buf,
 note_hdr.n_namesz, offset)
-== note_hdr.n_namesz);
+== (ssize_t)(size_t)note_hdr.n_namesz);
 
 if (!strncmp(note_name, name_buf, name_len) &&
 note_hdr.n_type == note_type)



CVS commit: src/tests/lib/libc/sys

2019-06-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jul  1 02:04:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Avoid GCC warning on NetBSD/i386

Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
signedness bit shifts.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-30 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Sun Jun 30 21:20:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: Makefile t_ptrace_wait.c

Log Message:
Add a test for verifying procinfo note inside coredumps.

Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it.  The test finds procinfo note
and checks its contents.

The core dump is processed through libelf.  However, it only provides
for finding all note segments (or sections?).  I had to implement
finding and processing individual notes myself.  I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.129 -r1.130 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-30 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Sun Jun 30 21:20:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: Makefile t_ptrace_wait.c

Log Message:
Add a test for verifying procinfo note inside coredumps.

Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it.  The test finds procinfo note
and checks its contents.

The core dump is processed through libelf.  However, it only provides
for finding all note segments (or sections?).  I had to implement
finding and processing individual notes myself.  I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.129 -r1.130 src/tests/lib/libc/sys/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/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.56 src/tests/lib/libc/sys/Makefile:1.57
--- src/tests/lib/libc/sys/Makefile:1.56	Fri Apr 26 20:41:10 2019
+++ src/tests/lib/libc/sys/Makefile	Sun Jun 30 21:20:04 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.56 2019/04/26 20:41:10 maya Exp $
+# $NetBSD: Makefile,v 1.57 2019/06/30 21:20:04 mgorny Exp $
 
 MKMAN=	no
 
@@ -88,12 +88,12 @@ SRCS.t_mprotect=	t_mprotect.c ${SRCS_EXE
 
 LDADD.t_getpid+=-lpthread
 
-LDADD.t_ptrace_wait+=		-pthread -lm
-LDADD.t_ptrace_wait3+=		-pthread -lm
-LDADD.t_ptrace_wait4+=		-pthread -lm
-LDADD.t_ptrace_wait6+=		-pthread -lm
-LDADD.t_ptrace_waitid+=		-pthread -lm
-LDADD.t_ptrace_waitpid+=	-pthread -lm
+LDADD.t_ptrace_wait+=		-pthread -lm -lelf
+LDADD.t_ptrace_wait3+=		-pthread -lm -lelf
+LDADD.t_ptrace_wait4+=		-pthread -lm -lelf
+LDADD.t_ptrace_wait6+=		-pthread -lm -lelf
+LDADD.t_ptrace_waitid+=		-pthread -lm -lelf
+LDADD.t_ptrace_waitpid+=	-pthread -lm -lelf
 
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.129 src/tests/lib/libc/sys/t_ptrace_wait.c:1.130
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.129	Wed Jun 26 12:30:13 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sun Jun 30 21:20:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.129 2019/06/26 12:30:13 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,10 +27,11 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.129 2019/06/26 12:30:13 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +44,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,6 +68,9 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12
 #include 
 #endif
 
+#include 
+#include 
+
 #include 
 
 #include "h_macros.h"
@@ -7639,6 +7644,180 @@ USER_VA0_DISABLE(user_va0_disable_pt_det
 
 /// 
 
+/*
+ * Parse the core file and find the requested note.  If the reading or parsing
+ * fails, the test is failed.  If the note is found, it is read onto buf, up to
+ * buf_len.  The actual length of the note is returned (which can be greater
+ * than buf_len, indicating that it has been truncated).  If the note is not
+ * found, -1 is returned.
+ */
+static ssize_t core_find_note(const char *core_path,
+const char *note_name, uint64_t note_type, void *buf, size_t buf_len)
+{
+	int core_fd;
+	Elf *core_elf;
+	size_t core_numhdr, i;
+	ssize_t ret = -1;
+	/* note: we assume note name will be null-terminated */
+	size_t name_len = strlen(note_name) + 1;
+
+	SYSCALL_REQUIRE((core_fd = open(core_path, O_RDONLY)) != -1);
+	SYSCALL_REQUIRE(elf_version(EV_CURRENT) != EV_NONE);
+	SYSCALL_REQUIRE((core_elf = elf_begin(core_fd, ELF_C_READ, NULL)));
+
+	SYSCALL_REQUIRE(elf_getphnum(core_elf, _numhdr) != 0);
+	for (i = 0; i < core_numhdr && ret == -1; i++) {
+		GElf_Phdr core_hdr;
+		size_t offset;
+		SYSCALL_REQUIRE(gelf_getphdr(core_elf, i, _hdr));
+		if (core_hdr.p_type != PT_NOTE)
+		continue;
+
+		for (offset = core_hdr.p_offset;
+		offset < core_hdr.p_offset + core_hdr.p_filesz;) {
+			Elf64_Nhdr note_hdr;
+			char name_buf[64];
+
+			switch (gelf_getclass(core_elf)) {
+			case ELFCLASS64:
+SYSCALL_REQUIRE(pread(core_fd, _hdr,
+sizeof(note_hdr), offset)
+== sizeof(note_hdr));
+offset += sizeof(note_hdr);
+break;
+			case ELFCLASS32:
+{
+Elf32_Nhdr tmp_hdr;
+SYSCALL_REQUIRE(pread(core_fd, _hdr,
+sizeof(tmp_hdr), offset)
+== sizeof(tmp_hdr));
+offset += sizeof(tmp_hdr);
+note_hdr.n_namesz = tmp_hdr.n_namesz;
+

CVS commit: src/tests/lib/libc/sys

2019-06-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 18 21:14:26 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Allow to conditionally enable LWP ATF tests in t_ptrace_wait*

By default the tests are disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.127 src/tests/lib/libc/sys/t_ptrace_wait.c:1.128
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.127	Thu Jun 13 20:26:06 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Jun 18 21:14:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.127 2019/06/13 20:26:06 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.128 2019/06/18 21:14:26 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.127 2019/06/13 20:26:06 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.128 2019/06/18 21:14:26 kamil Exp $");
 
 #include 
 #include 
@@ -103,6 +103,10 @@ static int debug = 0;
 #define TEST_VFORK_ENABLED 1
 #endif
 
+#ifndef TEST_LWP_ENABLED
+#define TEST_LWP_ENABLED 0
+#endif
+
 /// 
 
 static void
@@ -5454,8 +5458,10 @@ trace_threads(bool trace_create, bool tr
 	/* Track created and exited threads */
 	bool traced_lwps[__arraycount(t)];
 
+#if !TEST_LWP_ENABLED
 	if (trace_create || trace_exit)
 		atf_tc_skip("PR kern/51995");
+#endif
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);



CVS commit: src/tests/lib/libc/sys

2019-06-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 18 21:14:26 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Allow to conditionally enable LWP ATF tests in t_ptrace_wait*

By default the tests are disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jun 13 20:26:06 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Enable vfork(2) ATF tests in t_ptrace_wait*

The racing issues are gone in my local setup.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.126 src/tests/lib/libc/sys/t_ptrace_wait.c:1.127
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.126	Wed Jun 12 17:07:11 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Jun 13 20:26:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.127 2019/06/13 20:26:06 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.127 2019/06/13 20:26:06 kamil Exp $");
 
 #include 
 #include 
@@ -100,7 +100,7 @@ static int debug = 0;
 while (/*CONSTCOND*/0)
 
 #ifndef TEST_VFORK_ENABLED
-#define TEST_VFORK_ENABLED 0
+#define TEST_VFORK_ENABLED 1
 #endif
 
 /// 



CVS commit: src/tests/lib/libc/sys

2019-06-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jun 13 20:26:06 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Enable vfork(2) ATF tests in t_ptrace_wait*

The racing issues are gone in my local setup.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jun 12 17:07:11 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork

New tests:
 - posix_spawn_detach_spawner
 - posix_spawn_kill_spawner
 - posix_spawn_singalmasked
 - posix_spawn_singalignored

All test pass.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.125 src/tests/lib/libc/sys/t_ptrace_wait.c:1.126
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.125	Tue Jun 11 23:30:05 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed Jun 12 17:07:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.125 2019/06/11 23:30:05 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.125 2019/06/11 23:30:05 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.126 2019/06/12 17:07:11 kamil Exp $");
 
 #include 
 #include 
@@ -3195,7 +3195,7 @@ ATF_TC_HEAD(name, tc)			\
 {	\
 	atf_tc_set_md_var(tc, "descr", "Verify " fun "() "		\
 	"called with 0%s%s%s%s in EVENT_MASK",			\
-	tspawn ? "|PTRACE_FORK" : "",\
+	tspawn ? "|PTRACE_POSIX_SPAWN" : "",			\
 	tfork ? "|PTRACE_FORK" : "",\
 	tvfork ? "|PTRACE_VFORK" : "",\
 	tvforkdone ? "|PTRACE_VFORK_DONE" : "");			\
@@ -3282,11 +3282,10 @@ FORK_TEST(posix_spawn16, "spawn", true, 
 
 #if defined(TWAIT_HAVE_PID)
 static void
-fork_detach_forker_body(bool detachfork, bool detachvfork,
-bool detachvforkdone, bool kill_process)
+fork_detach_forker_body(const char *fn, bool kill_process)
 {
 	const int exitval = 5;
-	const int exitval2 = 15;
+	const int exitval2 = 0; /* Matches exit value from /bin/echo */
 	const int sigval = SIGSTOP;
 	pid_t child, child2 = 0, wpid;
 #if defined(TWAIT_HAVE_STATUS)
@@ -3297,17 +3296,9 @@ fork_detach_forker_body(bool detachfork,
 	ptrace_event_t event;
 	const int elen = sizeof(event);
 
-	pid_t (*fn)(void);
 	int op;
 
-	ATF_REQUIRE((detachfork && !detachvfork && !detachvforkdone) ||
-	(!detachfork && detachvfork && !detachvforkdone) ||
-	(!detachfork && !detachvfork && detachvforkdone));
-
-	if (detachfork)
-		fn = fork;
-	else
-		fn = vfork;
+	char * const arg[] = { __UNCONST("/bin/echo"), NULL };
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
@@ -3318,10 +3309,19 @@ fork_detach_forker_body(bool detachfork,
 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
 		FORKEE_ASSERT(raise(sigval) == 0);
 
-		FORKEE_ASSERT((child2 = (fn)()) != -1);
+		if (strcmp(fn, "spawn") == 0) {
+			FORKEE_ASSERT_EQ(posix_spawn(,
+			arg[0], NULL, NULL, arg, NULL), 0);
+		} else  {
+			if (strcmp(fn, "fork") == 0) {
+FORKEE_ASSERT((child2 = fork()) != -1);
+			} else {
+FORKEE_ASSERT((child2 = vfork()) != -1);
+			}
 
-		if (child2 == 0)
-			_exit(exitval2);
+			if (child2 == 0)
+_exit(exitval2);
+		}
 
 		FORKEE_REQUIRE_SUCCESS
 		(wpid = TWAIT_GENERIC(child2, , 0), child2);
@@ -3339,7 +3339,8 @@ fork_detach_forker_body(bool detachfork,
 	validate_status_stopped(status, sigval);
 
 	DPRINTF("Set EVENT_MASK for the child %d\n", child);
-	event.pe_set_event = PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE;
+	event.pe_set_event = PTRACE_POSIX_SPAWN | PTRACE_FORK | PTRACE_VFORK
+		| PTRACE_VFORK_DONE;
 	SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1);
 
 	DPRINTF("Before resuming the child process where it left off and "
@@ -3353,13 +3354,21 @@ fork_detach_forker_body(bool detachfork,
 
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
-	op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+
+	if (strcmp(fn, "spawn") == 0)
+		op = PTRACE_POSIX_SPAWN;
+	else if (strcmp(fn, "fork") == 0)
+		op = PTRACE_FORK;
+	else
+		op = PTRACE_VFORK;
+
 	ATF_REQUIRE_EQ(state.pe_report_event & op, op);
 
 	child2 = state.pe_other_pid;
 	DPRINTF("Reported ptrace event with forkee %d\n", child2);
 
-	if (detachfork || detachvfork)
+	if (strcmp(fn, "spawn") == 0 || strcmp(fn, "fork") == 0 ||
+	strcmp(fn, "vfork") == 0)
 		op = kill_process ? PT_KILL : PT_DETACH;
 	else
 		op = PT_CONTINUE;
@@ -3373,7 +3382,13 @@ fork_detach_forker_body(bool detachfork,
 
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_PROCESS_STATE, child2, , slen) != -1);
-	op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+	if (strcmp(fn, "spawn") == 0)
+		op = PTRACE_POSIX_SPAWN;
+	else if (strcmp(fn, "fork") == 0)
+		op = PTRACE_FORK;
+	else
+		op = PTRACE_VFORK;
+	
 	ATF_REQUIRE_EQ(state.pe_report_event 

CVS commit: src/tests/lib/libc/sys

2019-06-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jun 12 17:07:11 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork

New tests:
 - posix_spawn_detach_spawner
 - posix_spawn_kill_spawner
 - posix_spawn_singalmasked
 - posix_spawn_singalignored

All test pass.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 11 23:30:05 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new PTRACE_POSIX_SPAWN tests in ptrace(3)

Add test:
 - eventmask_preserved_posix_spawn
 - fork9..fork16
 - vfork9..vfork16
 - posix_spawn1..16

New tests verify semantics of PTRACE_POSIX_SPAWN.

All tests pass.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.124 src/tests/lib/libc/sys/t_ptrace_wait.c:1.125
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.124	Mon Jun 10 22:16:06 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Jun 11 23:30:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.125 2019/06/11 23:30:05 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.125 2019/06/11 23:30:05 kamil Exp $");
 
 #include 
 #include 
@@ -2947,6 +2947,8 @@ eventmask_preserved(int event)
 	ptrace(PT_SET_EVENT_MASK, child, _event, len) != -1);
 	SYSCALL_REQUIRE(
 	ptrace(PT_GET_EVENT_MASK, child, _event, len) != -1);
+	DPRINTF("set_event=%#x get_event=%#x\n", set_event.pe_set_event,
+	get_event.pe_set_event);
 	ATF_REQUIRE(memcmp(_event, _event, len) == 0);
 
 	DPRINTF("Before resuming the child process where it left off and "
@@ -2982,15 +2984,16 @@ EVENTMASK_PRESERVED(eventmask_preserved_
 EVENTMASK_PRESERVED(eventmask_preserved_vfork_done, PTRACE_VFORK_DONE)
 EVENTMASK_PRESERVED(eventmask_preserved_lwp_create, PTRACE_LWP_CREATE)
 EVENTMASK_PRESERVED(eventmask_preserved_lwp_exit, PTRACE_LWP_EXIT)
+EVENTMASK_PRESERVED(eventmask_preserved_posix_spawn, PTRACE_POSIX_SPAWN)
 
 /// 
 
 static void
-fork_body(pid_t (*fn)(void), bool spawn, bool trackfork, bool trackvfork,
+fork_body(const char *fn, bool trackspawn, bool trackfork, bool trackvfork,
 bool trackvforkdone)
 {
 	const int exitval = 5;
-	const int exitval2 = 15;
+	const int exitval2 = 0; /* This matched exit status from /bin/echo */
 	const int sigval = SIGSTOP;
 	pid_t child, child2 = 0, wpid;
 #if defined(TWAIT_HAVE_STATUS)
@@ -3003,9 +3006,6 @@ fork_body(pid_t (*fn)(void), bool spawn,
 
 	char * const arg[] = { __UNCONST("/bin/echo"), NULL };
 
-	if (spawn)
-		atf_tc_skip("posix_spawn() is not supported");
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -3015,11 +3015,15 @@ fork_body(pid_t (*fn)(void), bool spawn,
 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
 		FORKEE_ASSERT(raise(sigval) == 0);
 
-		if (spawn) {
+		if (strcmp(fn, "spawn") == 0) {
 			FORKEE_ASSERT_EQ(posix_spawn(,
 			arg[0], NULL, NULL, arg, NULL), 0);
-		} else if (fn == fork || fn == vfork) {
-			FORKEE_ASSERT((child2 = (fn)()) != -1);
+		} else {
+			if (strcmp(fn, "fork") == 0) {
+FORKEE_ASSERT((child2 = fork()) != -1);
+			} else if (strcmp(fn, "vfork") == 0) {
+FORKEE_ASSERT((child2 = vfork()) != -1);
+			}
 
 			if (child2 == 0)
 _exit(exitval2);
@@ -3039,11 +3043,14 @@ fork_body(pid_t (*fn)(void), bool spawn,
 
 	validate_status_stopped(status, sigval);
 
-	DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n",
+	DPRINTF("Set 0%s%s%s%s in EVENT_MASK for the child %d\n",
+	trackspawn ? "|PTRACE_POSIX_SPAWN" : "",
 	trackfork ? "|PTRACE_FORK" : "",
 	trackvfork ? "|PTRACE_VFORK" : "",
 	trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child);
 	event.pe_set_event = 0;
+	if (trackspawn)
+		event.pe_set_event |= PTRACE_POSIX_SPAWN;
 	if (trackfork)
 		event.pe_set_event |= PTRACE_FORK;
 	if (trackvfork)
@@ -3057,7 +3064,9 @@ fork_body(pid_t (*fn)(void), bool spawn,
 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
 #if defined(TWAIT_HAVE_PID)
-	if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) {
+	if ((trackspawn && strcmp(fn, "spawn") == 0) ||
+	(trackfork && strcmp(fn, "fork") == 0) ||
+	(trackvfork && strcmp(fn, "vfork") == 0)) {
 		DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
 		child);
 		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0),
@@ -3067,11 +3076,16 @@ fork_body(pid_t (*fn)(void), bool spawn,
 
 		SYSCALL_REQUIRE(
 		ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
-		if (trackfork && fn == fork) {
+		if (trackspawn && strcmp(fn, "spawn") == 0) {
+			ATF_REQUIRE_EQ(
+			state.pe_report_event & PTRACE_POSIX_SPAWN,
+			   PTRACE_POSIX_SPAWN);
+		}
+		if (trackfork && 

CVS commit: src/tests/lib/libc/sys

2019-06-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 11 23:30:05 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new PTRACE_POSIX_SPAWN tests in ptrace(3)

Add test:
 - eventmask_preserved_posix_spawn
 - fork9..fork16
 - vfork9..vfork16
 - posix_spawn1..16

New tests verify semantics of PTRACE_POSIX_SPAWN.

All tests pass.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-10 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 10 22:16:06 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add posix_spawn(3) ATF tests in t_ptrace_wait*

New tests verify whether forking process reports forking events to a
debugger.

Right now there is no support in the kernel for this system.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-10 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 10 22:16:06 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add posix_spawn(3) ATF tests in t_ptrace_wait*

New tests verify whether forking process reports forking events to a
debugger.

Right now there is no support in the kernel for this system.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.123 src/tests/lib/libc/sys/t_ptrace_wait.c:1.124
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.123	Mon Jun 10 21:18:04 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Jun 10 22:16:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.123 2019/06/10 21:18:04 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.123 2019/06/10 21:18:04 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.124 2019/06/10 22:16:06 kamil Exp $");
 
 #include 
 #include 
@@ -46,6 +46,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2985,7 +2986,7 @@ EVENTMASK_PRESERVED(eventmask_preserved_
 /// 
 
 static void
-fork_body(pid_t (*fn)(void), bool trackfork, bool trackvfork,
+fork_body(pid_t (*fn)(void), bool spawn, bool trackfork, bool trackvfork,
 bool trackvforkdone)
 {
 	const int exitval = 5;
@@ -3000,6 +3001,11 @@ fork_body(pid_t (*fn)(void), bool trackf
 	ptrace_event_t event;
 	const int elen = sizeof(event);
 
+	char * const arg[] = { __UNCONST("/bin/echo"), NULL };
+
+	if (spawn)
+		atf_tc_skip("posix_spawn() is not supported");
+
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -3009,11 +3015,15 @@ fork_body(pid_t (*fn)(void), bool trackf
 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
 		FORKEE_ASSERT(raise(sigval) == 0);
 
-		FORKEE_ASSERT((child2 = (fn)()) != -1);
-
-		if (child2 == 0)
-			_exit(exitval2);
+		if (spawn) {
+			FORKEE_ASSERT_EQ(posix_spawn(,
+			arg[0], NULL, NULL, arg, NULL), 0);
+		} else if (fn == fork || fn == vfork) {
+			FORKEE_ASSERT((child2 = (fn)()) != -1);
 
+			if (child2 == 0)
+_exit(exitval2);
+		}
 		FORKEE_REQUIRE_SUCCESS
 		(wpid = TWAIT_GENERIC(child2, , 0), child2);
 
@@ -3158,7 +3168,7 @@ fork_body(pid_t (*fn)(void), bool trackf
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
 
-#define FORK_TEST(name,fun,tfork,tvfork,tvforkdone)			\
+#define FORK_TEST(name,fun,spawn,tfork,tvfork,tvforkdone)		\
 ATF_TC(name);\
 ATF_TC_HEAD(name, tc)			\
 {	\
@@ -3172,37 +3182,51 @@ ATF_TC_HEAD(name, tc)			\
 ATF_TC_BODY(name, tc)			\
 {	\
 	\
-	fork_body(fun, tfork, tvfork, tvforkdone);			\
+	fork_body(fun, spawn, tfork, tvfork, tvforkdone);		\
 }
 
-FORK_TEST(fork1, fork, false, false, false)
+FORK_TEST(fork1, fork, false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork2, fork, true, false, false)
-FORK_TEST(fork3, fork, false, true, false)
-FORK_TEST(fork4, fork, true, true, false)
+FORK_TEST(fork2, fork, false, true, false, false)
+FORK_TEST(fork3, fork, false, false, true, false)
+FORK_TEST(fork4, fork, false, true, true, false)
 #endif
-FORK_TEST(fork5, fork, false, false, true)
+FORK_TEST(fork5, fork, false, false, false, true)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork6, fork, true, false, true)
-FORK_TEST(fork7, fork, false, true, true)
-FORK_TEST(fork8, fork, true, true, true)
+FORK_TEST(fork6, fork, false, true, false, true)
+FORK_TEST(fork7, fork, false, false, true, true)
+FORK_TEST(fork8, fork, false, true, true, true)
 #endif
 
 #if TEST_VFORK_ENABLED
-FORK_TEST(vfork1, vfork, false, false, false)
+FORK_TEST(vfork1, vfork, false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork2, vfork, true, false, false)
-FORK_TEST(vfork3, vfork, false, true, false)
-FORK_TEST(vfork4, vfork, true, true, false)
+FORK_TEST(vfork2, vfork, false, true, false, false)
+FORK_TEST(vfork3, vfork, false, false, true, false)
+FORK_TEST(vfork4, vfork, false, true, true, false)
 #endif
-FORK_TEST(vfork5, vfork, false, false, true)
+FORK_TEST(vfork5, vfork, false, false, false, true)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork6, vfork, true, false, true)
-FORK_TEST(vfork7, vfork, false, true, true)
-FORK_TEST(vfork8, vfork, true, true, true)
+FORK_TEST(vfork6, vfork, false, true, false, true)
+FORK_TEST(vfork7, vfork, false, false, true, true)
+FORK_TEST(vfork8, vfork, false, true, true, true)
 

CVS commit: src/tests/lib/libc/sys

2019-06-10 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 10 21:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add more verbosity to debug messages in t_ptrace_wait

Log func() file:line for each debug message.

Most messages are similar one with the other and this change allows easier
navigation in the code.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.122 src/tests/lib/libc/sys/t_ptrace_wait.c:1.123
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.122	Sat May 25 03:25:08 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Jun 10 21:18:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.122 2019/05/25 03:25:08 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.123 2019/06/10 21:18:04 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.122 2019/05/25 03:25:08 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.123 2019/06/10 21:18:04 kamil Exp $");
 
 #include 
 #include 
@@ -94,7 +94,8 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12
 static int debug = 0;
 
 #define DPRINTF(a, ...)	do  \
-	if (debug) printf(a,  ##__VA_ARGS__); \
+	if (debug) \
+	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
 #ifndef TEST_VFORK_ENABLED



CVS commit: src/tests/lib/libc/sys

2019-06-10 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 10 21:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add more verbosity to debug messages in t_ptrace_wait

Log func() file:line for each debug message.

Most messages are similar one with the other and this change allows easier
navigation in the code.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/tests/lib/libc/sys/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/lib/libc/sys

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 12:17:42 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_x86_wait.h

Log Message:
Fix alignment of SSE filling data


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

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



CVS commit: src/tests/lib/libc/sys

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 12:17:42 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_x86_wait.h

Log Message:
Fix alignment of SSE filling data


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_x86_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.14 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.15
--- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.14	Tue Jun  4 12:17:05 2019
+++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h	Tue Jun  4 12:17:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_x86_wait.h,v 1.14 2019/06/04 12:17:05 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_x86_wait.h,v 1.15 2019/06/04 12:17:42 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -2600,7 +2600,7 @@ static __inline void get_xmm_regs(void* 
 {
 	const struct {
 		uint64_t a, b;
-	} fill = {0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F};
+	} fill __aligned(16) = {0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F};
 
 	__asm__ __volatile__(
 		/* fill registers with clobber pattern */



CVS commit: src/tests/lib/libc/sys

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 12:17:05 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_amd64_wait.h t_ptrace_i386_wait.h
t_ptrace_x86_wait.h

Log Message:
Add more debug to register writing tests


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/t_ptrace_amd64_wait.h
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_ptrace_i386_wait.h
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_amd64_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.10 src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.11
--- src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.10	Fri May 10 16:24:35 2019
+++ src/tests/lib/libc/sys/t_ptrace_amd64_wait.h	Tue Jun  4 12:17:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_amd64_wait.h,v 1.10 2019/05/10 16:24:35 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_amd64_wait.h,v 1.11 2019/06/04 12:17:05 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -262,6 +262,7 @@ ATF_TC_BODY(x86_64_regs_gp_write, tc)
 			:
 		);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT_EQ(v_rax, rax);
 		FORKEE_ASSERT_EQ(v_rbx, rbx);
 		FORKEE_ASSERT_EQ(v_rcx, rcx);
@@ -462,6 +463,7 @@ ATF_TC_BODY(x86_64_regs_r8_write, tc)
 			: "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
 		);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT_EQ(v_r8[0], r8[0]);
 		FORKEE_ASSERT_EQ(v_r8[1], r8[1]);
 		FORKEE_ASSERT_EQ(v_r8[2], r8[2]);

Index: src/tests/lib/libc/sys/t_ptrace_i386_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_i386_wait.h:1.8 src/tests/lib/libc/sys/t_ptrace_i386_wait.h:1.9
--- src/tests/lib/libc/sys/t_ptrace_i386_wait.h:1.8	Fri May 10 16:24:35 2019
+++ src/tests/lib/libc/sys/t_ptrace_i386_wait.h	Tue Jun  4 12:17:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_i386_wait.h,v 1.8 2019/05/10 16:24:35 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_i386_wait.h,v 1.9 2019/06/04 12:17:05 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -226,6 +226,7 @@ ATF_TC_BODY(i386_regs_gp_write, tc)
 			:
 		);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT_EQ(v_eax, eax);
 		FORKEE_ASSERT_EQ(v_ebx, ebx);
 		FORKEE_ASSERT_EQ(v_ecx, ecx);
@@ -393,6 +394,7 @@ ATF_TC_BODY(i386_regs_ebp_esp_write, tc)
 			:
 		);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT_EQ(v_esp, esp);
 		FORKEE_ASSERT_EQ(v_ebp, ebp);
 

Index: src/tests/lib/libc/sys/t_ptrace_x86_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.13 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.14
--- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.13	Fri May 10 18:07:10 2019
+++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h	Tue Jun  4 12:17:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_x86_wait.h,v 1.13 2019/05/10 18:07:10 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_x86_wait.h,v 1.14 2019/06/04 12:17:05 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -2387,6 +2387,7 @@ ATF_TC_BODY(x86_regs_mm_write, tc)
 		DPRINTF("Before running assembly from child\n");
 		get_mm_regs(v_mm);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT_EQ(v_mm[0], mm[0]);
 		FORKEE_ASSERT_EQ(v_mm[1], mm[1]);
 		FORKEE_ASSERT_EQ(v_mm[2], mm[2]);
@@ -2724,6 +2725,7 @@ ATF_TC_BODY(x86_regs_xmm_write, tc)
 		DPRINTF("Before running assembly from child\n");
 		get_xmm_regs(v_xmm);
 
+		DPRINTF("Before comparing results\n");
 		FORKEE_ASSERT(!memcmp(_xmm[0], [0], sizeof(*xmm)));
 		FORKEE_ASSERT(!memcmp(_xmm[1], [1], sizeof(*xmm)));
 		FORKEE_ASSERT(!memcmp(_xmm[2], [2], sizeof(*xmm)));



CVS commit: src/tests/lib/libc/sys

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 12:17:05 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_amd64_wait.h t_ptrace_i386_wait.h
t_ptrace_x86_wait.h

Log Message:
Add more debug to register writing tests


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/t_ptrace_amd64_wait.h
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_ptrace_i386_wait.h
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

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



CVS commit: src/tests/lib/libc/sys

2019-05-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat May 25 03:25:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new user_va0_disable* tests in t_ptrace_wait*

Add tests:
 - user_va0_disable_pt_continue
 - user_va0_disable_pt_syscall
 - user_va0_disable_pt_detach

Assert that setting PC to 0x0 in PT_CONTINUE/PT_SYSCALL/PT_DETACH for
vm.user_va0_disable==0 is disallowed.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/tests/lib/libc/sys/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/lib/libc/sys

2019-05-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat May 25 03:25:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new user_va0_disable* tests in t_ptrace_wait*

Add tests:
 - user_va0_disable_pt_continue
 - user_va0_disable_pt_syscall
 - user_va0_disable_pt_detach

Assert that setting PC to 0x0 in PT_CONTINUE/PT_SYSCALL/PT_DETACH for
vm.user_va0_disable==0 is disallowed.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/tests/lib/libc/sys/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/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.121 src/tests/lib/libc/sys/t_ptrace_wait.c:1.122
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.121	Thu May  9 13:07:35 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sat May 25 03:25:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.121 2019/05/09 13:07:35 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.122 2019/05/25 03:25:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.121 2019/05/09 13:07:35 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.122 2019/05/25 03:25:08 kamil Exp $");
 
 #include 
 #include 
@@ -7438,6 +7438,94 @@ TRACEME_VFORK_CLONE_TEST(traceme_vfork_c
 
 /// 
 
+static void
+user_va0_disable(int operation)
+{
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	const int sigval = SIGSTOP;
+	int rv;
+
+	struct ptrace_siginfo info;
+
+	if (get_user_va0_disable() == 0)
+		atf_tc_skip("vm.user_va0_disable is set to 0");
+
+	memset(, 0, sizeof(info));
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = fork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		/* NOTREACHED */
+		FORKEE_ASSERTX(0 && "This shall not be reached");
+		__unreachable();
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for "
+		"child\n");
+	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, ,
+		sizeof(info)) != -1);
+
+	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	DPRINTF("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, SI_LWP);
+
+	DPRINTF("Before resuming the child process in PC=0x0 "
+	"and without signal to be sent\n");
+	errno = 0;
+	rv = ptrace(operation, child, (void *)0, 0);
+	ATF_REQUIRE_EQ(errno, EINVAL);
+	ATF_REQUIRE_EQ(rv, -1);
+
+	SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+	validate_status_signaled(status, SIGKILL, 0);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+
+#define USER_VA0_DISABLE(test, operation)\
+ATF_TC(test);\
+ATF_TC_HEAD(test, tc)			\
+{	\
+	atf_tc_set_md_var(tc, "descr",	\
+	"Verify behavior of " #operation " with PC set to 0x0");	\
+}	\
+	\
+ATF_TC_BODY(test, tc)			\
+{	\
+	\
+	user_va0_disable(operation);	\
+}
+
+USER_VA0_DISABLE(user_va0_disable_pt_continue, PT_CONTINUE)
+USER_VA0_DISABLE(user_va0_disable_pt_syscall, PT_SYSCALL)
+USER_VA0_DISABLE(user_va0_disable_pt_detach, PT_DETACH)
+
+/// 
+
 #include "t_ptrace_amd64_wait.h"
 #include "t_ptrace_i386_wait.h"
 #include "t_ptrace_x86_wait.h"
@@ -7886,6 +7974,10 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_vfork);
 #endif
 
+	ATF_TP_ADD_TC(tp, user_va0_disable_pt_continue);
+	ATF_TP_ADD_TC(tp, user_va0_disable_pt_syscall);
+	ATF_TP_ADD_TC(tp, user_va0_disable_pt_detach);
+
 	ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_I386();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_X86();



CVS commit: src/tests/lib/libc/sys

2019-05-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat May 25 03:22:53 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
Add get_user_va0_disable() in t_ptrace_wait.h

Add a utility function to check vm.user_va0_disable.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_ptrace_wait.h

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



CVS commit: src/tests/lib/libc/sys

2019-05-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat May 25 03:22:53 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
Add get_user_va0_disable() in t_ptrace_wait.h

Add a utility function to check vm.user_va0_disable.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_ptrace_wait.h

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

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.16 src/tests/lib/libc/sys/t_ptrace_wait.h:1.17
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.16	Thu Apr 25 19:15:23 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Sat May 25 03:22:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.16 2019/04/25 19:15:23 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.17 2019/05/25 03:22:53 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -553,6 +553,26 @@ can_we_set_dbregs(void)
 #endif
 
 static bool __used
+get_user_va0_disable(void)
+{
+	static int user_va0_disable = -1;
+	size_t user_va0_disable_len = sizeof(user_va0_disable);
+
+	if (user_va0_disable == -1) {
+		if (sysctlbyname("vm.user_va0_disable",
+			_va0_disable, _va0_disable_len, NULL, 0)
+			== -1) {
+			return true;
+		}
+	}
+
+	if (user_va0_disable > 0)
+		return true;
+	else
+		return false;
+}
+
+static bool __used
 can_we_write_to_text(pid_t pid)
 {
 	int mib[3];



  1   2   >