blob: 526a99aa5b6dbefc0494162cf567e05b0b6e49f7 [file] [log] [blame]
sewardj2342c972002-05-22 23:34:20 +00001
2
3#include <stdio.h>
mueller535cc6e2004-01-03 14:18:02 +00004#include <stdlib.h>
sewardj2342c972002-05-22 23:34:20 +00005#include <signal.h>
njn83b62cb2009-04-15 03:12:43 +00006#include "tests/sys_mman.h"
sewardj2342c972002-05-22 23:34:20 +00007
8void sig_handler(int sig){
9 int var;
10 fprintf(stderr, "caught signal, local var is on %p\n", &var);
11}
12
sewardj2342c972002-05-22 23:34:20 +000013int main(int argv, char** argc) {
14 int res, i;
15 stack_t sigstk;
16 struct sigaction act;
florian017d8f52015-03-23 17:13:04 +000017 static const int size = SIGSTKSZ*2;
njn09ef4082005-11-17 19:38:09 +000018 // We give EXEC permissions because this won't work on ppc32 unless you
njnb67c6ce2005-11-17 19:47:37 +000019 // ask for an alt stack with EXEC permissions,
sewardj7c68e982005-11-17 19:44:27 +000020 // since signal returning requires execution of code on the stack.
sewardj89551b32005-11-17 13:04:46 +000021 char *stk = (char *)mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC,
njn83b62cb2009-04-15 03:12:43 +000022 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
fitzhardingef0f911c2003-11-09 09:51:33 +000023 sigstk.ss_sp = stk;
sewardj2342c972002-05-22 23:34:20 +000024
fitzhardingef0f911c2003-11-09 09:51:33 +000025 sigstk.ss_size = size;
sewardj2342c972002-05-22 23:34:20 +000026 sigstk.ss_flags = 0;
27 fprintf(stderr, "calling sigaltstack, stack base is %p\n", sigstk.ss_sp);
28 if (sigaltstack(&sigstk,0)<0) perror("sigaltstack");
29
30 fprintf(stderr,"setting sigaction\n");
31 act.sa_flags=SA_ONSTACK;
32 act.sa_handler=&sig_handler;
fitzhardinge98abfc72003-12-16 02:05:15 +000033 sigemptyset(&act.sa_mask);
sewardj2342c972002-05-22 23:34:20 +000034 res = sigaction(SIGUSR1,&act,0);
35 fprintf(stderr, "res = %d\n", res);
36 fprintf(stderr, "raising the signal\n");
37 raise(SIGUSR1);
38
39 /* Loop long enough so valgrind has a forced context switch and
40 actually delivers the signal before the thread exits. */
41 for (i = 0; i < 1000000; i++) ;
42
43 fprintf(stderr, "done\n");
44 return 0;
45}