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

2024-05-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  6 12:11:03 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-05-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  6 12:11:03 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.10 src/tests/lib/libc/setjmp/t_sigstack.c:1.11
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.10	Mon May  6 06:58:00 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon May  6 12:11:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.10 2024/05/06 06:58:00 skrll Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.11 2024/05/06 12:11:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.10 2024/05/06 06:58:00 skrll Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.11 2024/05/06 12:11:03 riastradh Exp $");
 
 #include 
 #include 
@@ -83,6 +83,7 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	 *
 	 *	aarch64
 	 *	alpha
+	 *	arm
 	 *	i386
 	 *	m68k
 	 *	or1k



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

2024-05-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon May  6 06:58:00 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
arm has been fixed


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.9 src/tests/lib/libc/setjmp/t_sigstack.c:1.10
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.9	Thu Apr  4 00:46:42 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon May  6 06:58:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.9 2024/04/04 00:46:42 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.10 2024/05/06 06:58:00 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.9 2024/04/04 00:46:42 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.10 2024/05/06 06:58:00 skrll Exp $");
 
 #include 
 #include 
@@ -92,7 +92,7 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	 *	vax
 	 *	x86_64
 	 */
-#if defined __arm__ || defined __hppa__ || \
+#if defined __hppa__ || \
 defined __ia64__ || defined __mips__ || defined __sh3__ || \
 defined __sparc__ || defined __sparc64__
 	if (nentries > 0)



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

2024-05-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon May  6 06:58:00 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
arm has been fixed


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 19:43:27 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Fix fencepost error.

Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.6 src/tests/lib/libc/setjmp/t_sigstack.c:1.7
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.6	Mon Feb 19 13:34:48 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 19:43:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.6 2024/02/19 13:34:48 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.7 2024/02/19 19:43:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.6 2024/02/19 13:34:48 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.7 2024/02/19 19:43:27 riastradh Exp $");
 
 #include 
 #include 
@@ -91,7 +91,7 @@ on_sigusr1(int signo, siginfo_t *si, voi
 #endif
 	for (ssp = [0]; ssp < [__arraycount(ss)]; ssp++) {
 		ATF_REQUIRE_MSG((sp < ssp->ss_sp ||
-			sp > (void *)((char *)ssp->ss_sp + ssp->ss_size)),
+			sp >= (void *)((char *)ssp->ss_sp + ssp->ss_size)),
 		"%s failed to restore stack"
 		" before allowing signal on entry %u --"
 		" interrupted stack pointer %p lies in sigaltstack %zd"



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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 19:43:27 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Fix fencepost error.

Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.

PR lib/57946


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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 13:34:48 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Use a sigaltstack per handler entry.

longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack.  So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.

With this change, the test now passes on aarch64.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.5 src/tests/lib/libc/setjmp/t_sigstack.c:1.6
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.5	Mon Feb 19 12:41:27 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 13:34:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.5 2024/02/19 12:41:27 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.6 2024/02/19 13:34:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.5 2024/02/19 12:41:27 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.6 2024/02/19 13:34:48 riastradh Exp $");
 
 #include 
 #include 
@@ -37,7 +37,7 @@ __RCSID("$NetBSD: t_sigstack.c,v 1.5 202
 
 #include "h_macros.h"
 
-struct sigaltstack ss;
+struct sigaltstack ss[3];
 jmp_buf jmp;
 sigjmp_buf sigjmp;
 unsigned nentries;
@@ -50,28 +50,33 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	ucontext_t *uc = ctx;
 	void *sp = (void *)(uintptr_t)_UC_MACHINE_SP(uc);
 	void *fp = __builtin_frame_address(0);
+	struct sigaltstack *ssp;
+
+	/*
+	 * Ensure we haven't re-entered the signal handler too many
+	 * times.  We should enter only twice.
+	 */
+	ATF_REQUIRE_MSG(nentries < 2,
+	"%u recursive signal handler entries is too many in this test",
+	nentries + 1);
 
 	/*
 	 * Ensure that the signal handler was called in the alternate
 	 * signal stack.
 	 */
-	ATF_REQUIRE_MSG(fp >= ss.ss_sp,
-	"sigaltstack failed to take effect on entry %u --"
-	" signal handler's frame pointer %p doesn't lie in sigaltstack"
-	" [%p, %p), size 0x%zx",
-	nentries,
-	fp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
-	ATF_REQUIRE_MSG(fp < (void *)((char *)ss.ss_sp + ss.ss_size),
+	ssp = [nentries];
+	ATF_REQUIRE_MSG((fp >= ssp->ss_sp &&
+		fp < (void *)((char *)ssp->ss_sp + ssp->ss_size)),
 	"sigaltstack failed to take effect on entry %u --"
 	" signal handler's frame pointer %p doesn't lie in sigaltstack"
 	" [%p, %p), size 0x%zx",
 	nentries,
-	fp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
+	fp, ssp->ss_sp, (char *)ssp->ss_sp + ssp->ss_size, ssp->ss_size);
 
 	/*
 	 * Ensure that if we enter the signal handler, we are entering
-	 * it from the original stack, not from the alternate signal
-	 * stack.
+	 * it from the original stack, not from any of the alternate
+	 * signal stacks.
 	 *
 	 * On some architectures, this is broken.  Those that appear to
 	 * get this right are:
@@ -84,13 +89,19 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	if (nentries > 0)
 		atf_tc_expect_fail("PR lib/57946");
 #endif
-	ATF_REQUIRE_MSG((sp < ss.ss_sp ||
-		sp > (void *)((char *)ss.ss_sp + ss.ss_size)),
-	"%s failed to restore stack before allowing signal on entry %u--"
-	" interrupted stack pointer %p lies in sigaltstack"
-	" [%p, %p), size 0x%zx",
-	nentries,
-	bailname, sp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
+	for (ssp = [0]; ssp < [__arraycount(ss)]; ssp++) {
+		ATF_REQUIRE_MSG((sp < ssp->ss_sp ||
+			sp > (void *)((char *)ssp->ss_sp + ssp->ss_size)),
+		"%s failed to restore stack"
+		" before allowing signal on entry %u --"
+		" interrupted stack pointer %p lies in sigaltstack %zd"
+		" [%p, %p), size 0x%zx",
+		bailname,
+		nentries,
+		sp, ssp - ss,
+		ssp->ss_sp, (char *)ssp->ss_sp + ssp->ss_size,
+		ssp->ss_size);
+	}
 
 	/*
 	 * First time through, we want to test whether longjmp restores
@@ -104,6 +115,15 @@ on_sigusr1(int signo, siginfo_t *si, voi
 		RL(raise(SIGUSR1));
 
 	/*
+	 * Set up the next sigaltstack.  We can't reuse the current one
+	 * for the next signal handler re-entry until the system clears
+	 * the SS_ONSTACK process state -- which normal return from
+	 * signal 

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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 13:34:48 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Use a sigaltstack per handler entry.

longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack.  So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.

With this change, the test now passes on aarch64.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:41:27 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Note aarch64 seems to DTRT.

But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.4 src/tests/lib/libc/setjmp/t_sigstack.c:1.5
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.4	Mon Feb 19 12:41:19 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 12:41:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.4 2024/02/19 12:41:19 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.5 2024/02/19 12:41:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.4 2024/02/19 12:41:19 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.5 2024/02/19 12:41:27 riastradh Exp $");
 
 #include 
 #include 
@@ -76,7 +76,7 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	 * On some architectures, this is broken.  Those that appear to
 	 * get this right are:
 	 *
-	 *	alpha, m68k, or1k, powerpc, powerpc64, riscv, vax
+	 *	aarch64, alpha, m68k, or1k, powerpc, powerpc64, riscv, vax
 	 */
 #if defined __arm__ || defined __hppa__ || defined __i386__ || \
 defined __ia64__ || defined __mips__ || defined __sh3__ || \



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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:41:19 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Print which entry failed.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.3 src/tests/lib/libc/setjmp/t_sigstack.c:1.4
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.3	Mon Feb 19 12:29:48 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 12:41:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.3 2024/02/19 12:29:48 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.4 2024/02/19 12:41:19 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.3 2024/02/19 12:29:48 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.4 2024/02/19 12:41:19 riastradh Exp $");
 
 #include 
 #include 
@@ -56,14 +56,16 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	 * signal stack.
 	 */
 	ATF_REQUIRE_MSG(fp >= ss.ss_sp,
-	"sigaltstack failed to take effect --"
+	"sigaltstack failed to take effect on entry %u --"
 	" signal handler's frame pointer %p doesn't lie in sigaltstack"
 	" [%p, %p), size 0x%zx",
+	nentries,
 	fp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
 	ATF_REQUIRE_MSG(fp < (void *)((char *)ss.ss_sp + ss.ss_size),
-	"sigaltstack failed to take effect --"
+	"sigaltstack failed to take effect on entry %u --"
 	" signal handler's frame pointer %p doesn't lie in sigaltstack"
 	" [%p, %p), size 0x%zx",
+	nentries,
 	fp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
 
 	/*
@@ -84,9 +86,10 @@ on_sigusr1(int signo, siginfo_t *si, voi
 #endif
 	ATF_REQUIRE_MSG((sp < ss.ss_sp ||
 		sp > (void *)((char *)ss.ss_sp + ss.ss_size)),
-	"%s failed to restore stack before allowing signal --"
+	"%s failed to restore stack before allowing signal on entry %u--"
 	" interrupted stack pointer %p lies in sigaltstack"
 	" [%p, %p), size 0x%zx",
+	nentries,
 	bailname, sp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
 
 	/*



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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:41:27 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Note aarch64 seems to DTRT.

But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:41:19 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3) t_sigstack: Print which entry failed.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:29:48 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3): Test signal mask vs stack restore with siglongjmp too.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.2 src/tests/lib/libc/setjmp/t_sigstack.c:1.3
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.2	Mon Feb 19 04:33:21 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 12:29:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.2 2024/02/19 04:33:21 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.3 2024/02/19 12:29:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.2 2024/02/19 04:33:21 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.3 2024/02/19 12:29:48 riastradh Exp $");
 
 #include 
 #include 
@@ -39,7 +39,10 @@ __RCSID("$NetBSD: t_sigstack.c,v 1.2 202
 
 struct sigaltstack ss;
 jmp_buf jmp;
+sigjmp_buf sigjmp;
 unsigned nentries;
+const char *bailname;
+void (*bailfn)(void) __dead;
 
 static void
 on_sigusr1(int signo, siginfo_t *si, void *ctx)
@@ -81,10 +84,10 @@ on_sigusr1(int signo, siginfo_t *si, voi
 #endif
 	ATF_REQUIRE_MSG((sp < ss.ss_sp ||
 		sp > (void *)((char *)ss.ss_sp + ss.ss_size)),
-	"longjmp failed to restore stack before allowing signal --"
+	"%s failed to restore stack before allowing signal --"
 	" interrupted stack pointer %p lies in sigaltstack"
 	" [%p, %p), size 0x%zx",
-	sp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
+	bailname, sp, ss.ss_sp, (char *)ss.ss_sp + ss.ss_size, ss.ss_size);
 
 	/*
 	 * First time through, we want to test whether longjmp restores
@@ -100,19 +103,17 @@ on_sigusr1(int signo, siginfo_t *si, voi
 	/*
 	 * Jump back to the original context.
 	 */
-	longjmp(jmp, 1);
+	(*bailfn)();
 }
 
-ATF_TC(setjmp);
-ATF_TC_HEAD(setjmp, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	"Test longjmp restores stack first, then signal mask");
-}
-ATF_TC_BODY(setjmp, tc)
+static void
+go(const char *name, void (*fn)(void) __dead)
 {
 	struct sigaction sa;
 
+	bailname = name;
+	bailfn = fn;
+
 	/*
 	 * Allocate a stack for the signal handler to run in, and
 	 * configure the system to use it.
@@ -145,6 +146,33 @@ ATF_TC_BODY(setjmp, tc)
 	RL(sigaction(SIGUSR1, , NULL));
 
 	/*
+	 * Raise the signal to enter the signal handler the first time.
+	 */
+	RL(raise(SIGUSR1));
+
+	/*
+	 * If we ever reach this point, something went seriously wrong.
+	 */
+	atf_tc_fail("unreachable");
+}
+
+static void __dead
+bail_longjmp(void)
+{
+
+	longjmp(jmp, 1);
+}
+
+ATF_TC(setjmp);
+ATF_TC_HEAD(setjmp, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Test longjmp restores stack first, then signal mask");
+}
+ATF_TC_BODY(setjmp, tc)
+{
+
+	/*
 	 * Set up a return point for the signal handler: when the
 	 * signal handler does longjmp(jmp, 1), it comes flying out of
 	 * here.
@@ -153,21 +181,46 @@ ATF_TC_BODY(setjmp, tc)
 		return;
 
 	/*
-	 * Raise the signal to enter the signal handler the first time.
+	 * Run the test with longjmp.
 	 */
-	RL(raise(SIGUSR1));
+	go("longjmp", _longjmp);
+}
+
+static void __dead
+bail_siglongjmp(void)
+{
+
+	siglongjmp(sigjmp, 1);
+}
+
+ATF_TC(sigsetjmp);
+ATF_TC_HEAD(sigsetjmp, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Test siglongjmp restores stack first, then signal mask");
+}
+ATF_TC_BODY(sigsetjmp, tc)
+{
 
 	/*
-	 * If we ever reach this point, something went seriously wrong.
+	 * Set up a return point for the signal handler: when the
+	 * signal handler does siglongjmp(sigjmp, 1), it comes flying
+	 * out of here.
 	 */
-	atf_tc_fail("unreachable");
+	if (sigsetjmp(sigjmp, /*savesigmask*/1) == 1)
+		return;
+
+	/*
+	 * Run the test with siglongjmp.
+	 */
+	go("siglongjmp", _siglongjmp);
 }
 
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, setjmp);
-//	ATF_TP_ADD_TC(tp, sigsetjmp);
+	ATF_TP_ADD_TC(tp, sigsetjmp);
 
 	return atf_no_error();
 }



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

2024-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 12:29:48 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3): Test signal mask vs stack restore with siglongjmp too.

PR lib/57946


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp

2024-02-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 04:33:21 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3): Paranoia: more error checking in PR lib/57946 test.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/setjmp/t_sigstack.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/setjmp/t_sigstack.c
diff -u src/tests/lib/libc/setjmp/t_sigstack.c:1.1 src/tests/lib/libc/setjmp/t_sigstack.c:1.2
--- src/tests/lib/libc/setjmp/t_sigstack.c:1.1	Mon Feb 19 04:30:39 2024
+++ src/tests/lib/libc/setjmp/t_sigstack.c	Mon Feb 19 04:33:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sigstack.c,v 1.1 2024/02/19 04:30:39 riastradh Exp $	*/
+/*	$NetBSD: t_sigstack.c,v 1.2 2024/02/19 04:33:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_sigstack.c,v 1.1 2024/02/19 04:30:39 riastradh Exp $");
+__RCSID("$NetBSD: t_sigstack.c,v 1.2 2024/02/19 04:33:21 riastradh Exp $");
 
 #include 
 #include 
@@ -140,7 +140,7 @@ ATF_TC_BODY(setjmp, tc)
 	 */
 	memset(, 0, sizeof(sa));
 	sa.sa_sigaction = _sigusr1;
-	sigemptyset(_mask);
+	RL(sigemptyset(_mask));
 	sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
 	RL(sigaction(SIGUSR1, , NULL));
 
@@ -155,7 +155,7 @@ ATF_TC_BODY(setjmp, tc)
 	/*
 	 * Raise the signal to enter the signal handler the first time.
 	 */
-	raise(SIGUSR1);
+	RL(raise(SIGUSR1));
 
 	/*
 	 * If we ever reach this point, something went seriously wrong.



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

2024-02-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 19 04:33:21 UTC 2024

Modified Files:
src/tests/lib/libc/setjmp: t_sigstack.c

Log Message:
longjmp(3): Paranoia: more error checking in PR lib/57946 test.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/setjmp/t_sigstack.c

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