Implement sigaltstack. Most of the logic is copied more-or-less
verbatim from the Linux kernel sources, which has to be a good thing.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@309 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/tests/sigaltstack.c b/tests/sigaltstack.c
new file mode 100644
index 0000000..8f31e68
--- /dev/null
+++ b/tests/sigaltstack.c
@@ -0,0 +1,38 @@
+
+
+#include <stdio.h>
+#include <malloc.h>
+#include <signal.h>
+
+void sig_handler(int sig){
+ int var;
+ fprintf(stderr, "caught signal, local var is on %p\n", &var);
+}
+
+
+int main(int argv, char** argc) {
+ int res, i;
+ stack_t sigstk;
+ struct sigaction act;
+ sigstk.ss_sp = (char *)malloc(SIGSTKSZ);
+
+ sigstk.ss_size = SIGSTKSZ;
+ sigstk.ss_flags = 0;
+ fprintf(stderr, "calling sigaltstack, stack base is %p\n", sigstk.ss_sp);
+ if (sigaltstack(&sigstk,0)<0) perror("sigaltstack");
+
+ fprintf(stderr,"setting sigaction\n");
+ act.sa_flags=SA_ONSTACK;
+ act.sa_handler=&sig_handler;
+ res = sigaction(SIGUSR1,&act,0);
+ fprintf(stderr, "res = %d\n", res);
+ fprintf(stderr, "raising the signal\n");
+ raise(SIGUSR1);
+
+ /* Loop long enough so valgrind has a forced context switch and
+ actually delivers the signal before the thread exits. */
+ for (i = 0; i < 1000000; i++) ;
+
+ fprintf(stderr, "done\n");
+ return 0;
+}