summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2012-06-23 05:54:50 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2012-06-23 05:54:50 +0000
commitab0a3a02c44522e11b56b28c3c97ec7870d16de1 (patch)
tree67debd2b3fe3cb3d0190cde533b035b75caba03d /regress/sys
parent3464804fbf46e5570387cf5b05aaec0536c8927a (diff)
add (currently failing) stackjmp regress test
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/stackjmp/Makefile5
-rw-r--r--regress/sys/kern/stackjmp/stackjmp.c54
2 files changed, 59 insertions, 0 deletions
diff --git a/regress/sys/kern/stackjmp/Makefile b/regress/sys/kern/stackjmp/Makefile
new file mode 100644
index 00000000000..a67ea8fdecc
--- /dev/null
+++ b/regress/sys/kern/stackjmp/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2012/06/23 05:54:49 matthew Exp $
+
+PROG= stackjmp
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/stackjmp/stackjmp.c b/regress/sys/kern/stackjmp/stackjmp.c
new file mode 100644
index 00000000000..aa73c2d97a0
--- /dev/null
+++ b/regress/sys/kern/stackjmp/stackjmp.c
@@ -0,0 +1,54 @@
+/* $OpenBSD: stackjmp.c,v 1.1 2012/06/23 05:54:49 matthew Exp $ */
+#include <assert.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+static jmp_buf jb;
+static char buf[SIGSTKSZ];
+static volatile int handled;
+
+static int
+isaltstack()
+{
+ stack_t os;
+ assert(sigaltstack(NULL, &os) == 0);
+ return (os.ss_flags & SS_ONSTACK) != 0;
+}
+
+static void
+inthandler(int signo)
+{
+ assert(isaltstack());
+ handled = 1;
+ siglongjmp(jb, 1);
+}
+
+int
+main()
+{
+ struct sigaction sa;
+ stack_t stack;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = inthandler;
+ sa.sa_flags = SA_ONSTACK;
+ assert(sigaction(SIGINT, &sa, NULL) == 0);
+
+ memset(&stack, 0, sizeof(stack));
+ stack.ss_sp = buf;
+ stack.ss_size = sizeof(buf);
+ stack.ss_flags = 0;
+ assert(sigaltstack(&stack, NULL) == 0);
+
+ assert(!isaltstack());
+ sigsetjmp(jb, 1);
+ assert(!isaltstack());
+ if (!handled) {
+ kill(getpid(), SIGINT);
+ assert(0); /* Shouldn't reach here. */
+ }
+
+ return (0);
+}