From 6919b95f5992c9aefd39fddbacb3761523f50098 Mon Sep 17 00:00:00 2001 From: Joshua Elsasser Date: Tue, 22 Nov 2011 23:06:50 +0000 Subject: Add a test for forked processes inheriting their parent's signal stack. ok guenther@ --- regress/sys/kern/signal/Makefile | 4 +- regress/sys/kern/signal/sigaltstack_fork/Makefile | 6 ++ .../signal/sigaltstack_fork/sigaltstack_fork.c | 67 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 regress/sys/kern/signal/sigaltstack_fork/Makefile create mode 100644 regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c (limited to 'regress/sys/kern') diff --git a/regress/sys/kern/signal/Makefile b/regress/sys/kern/signal/Makefile index 65193ab4315..bcfd293e8ed 100644 --- a/regress/sys/kern/signal/Makefile +++ b/regress/sys/kern/signal/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.4 2008/06/10 18:04:31 hshoexer Exp $ +# $OpenBSD: Makefile,v 1.5 2011/11/22 23:06:48 joshe Exp $ -SUBDIR+= sigfpe siginfo_addr fpsig earlysig cansig +SUBDIR+= sigfpe siginfo_addr fpsig earlysig cansig sigaltstack_fork install: diff --git a/regress/sys/kern/signal/sigaltstack_fork/Makefile b/regress/sys/kern/signal/sigaltstack_fork/Makefile new file mode 100644 index 00000000000..f3510145632 --- /dev/null +++ b/regress/sys/kern/signal/sigaltstack_fork/Makefile @@ -0,0 +1,6 @@ + +# $OpenBSD: Makefile,v 1.1 2011/11/22 23:06:49 joshe Exp $ + +PROG= sigaltstack_fork + +.include diff --git a/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c b/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c new file mode 100644 index 00000000000..8b6237bdf9b --- /dev/null +++ b/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c @@ -0,0 +1,67 @@ +/* $OpenBSD: sigaltstack_fork.c,v 1.1 2011/11/22 23:06:49 joshe Exp $ */ + +/* + * Public domain. 2011, Joshua Elsasser + * + * Test if child processes inherit an alternate signal stack. + */ + +#include +#include + +#include +#include +#include +#include +#include + +void +check_stack(void *buf, const char *label) +{ + struct sigaltstack ss; + + bzero(&ss, sizeof(ss)); + if (sigaltstack(NULL, &ss) != 0) + err(1, "failed to get sigaltstack in parent"); + if (ss.ss_sp != buf || + ss.ss_size != SIGSTKSZ || + ss.ss_flags != 0) + errx(1, "bad sigaltstack value in %s: " + "buf=%p ss_sp=%p ss_size=%zu ss_flags=0x%x", + label, buf, ss.ss_sp, ss.ss_size, ss.ss_flags); +} + +int +main(int argc, char *argv[]) +{ + struct sigaltstack ss; + int status; + pid_t kid; + void *buf; + + if ((buf = malloc(SIGSTKSZ)) == NULL) + err(1, "malloc failed"); + + bzero(&ss, sizeof(ss)); + ss.ss_sp = buf; + ss.ss_size = SIGSTKSZ; + if (sigaltstack(&ss, NULL) != 0) + err(1, "failed to set sigaltstack"); + + check_stack(buf, "parent"); + + if ((kid = fork()) == -1) + err(1, "fork failed"); + + if (kid == 0) { + check_stack(buf, "child"); + _exit(0); + } + + if (waitpid(kid, &status, 0) != kid) + err(1, "waitpid failed"); + if (!WIFEXITED(status)) + errx(1, "child did not exit normally"); + + return (WEXITSTATUS(status)); +} -- cgit v1.2.3