sewardj | 2342c97 | 2002-05-22 23:34:20 +0000 | [diff] [blame] | 1 | |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <malloc.h> |
| 5 | #include <signal.h> |
| 6 | |
| 7 | void sig_handler(int sig){ |
| 8 | int var; |
| 9 | fprintf(stderr, "caught signal, local var is on %p\n", &var); |
| 10 | } |
| 11 | |
| 12 | |
| 13 | int main(int argv, char** argc) { |
| 14 | int res, i; |
| 15 | stack_t sigstk; |
| 16 | struct sigaction act; |
| 17 | sigstk.ss_sp = (char *)malloc(SIGSTKSZ); |
| 18 | |
| 19 | sigstk.ss_size = SIGSTKSZ; |
| 20 | sigstk.ss_flags = 0; |
| 21 | fprintf(stderr, "calling sigaltstack, stack base is %p\n", sigstk.ss_sp); |
| 22 | if (sigaltstack(&sigstk,0)<0) perror("sigaltstack"); |
| 23 | |
| 24 | fprintf(stderr,"setting sigaction\n"); |
| 25 | act.sa_flags=SA_ONSTACK; |
| 26 | act.sa_handler=&sig_handler; |
| 27 | res = sigaction(SIGUSR1,&act,0); |
| 28 | fprintf(stderr, "res = %d\n", res); |
| 29 | fprintf(stderr, "raising the signal\n"); |
| 30 | raise(SIGUSR1); |
| 31 | |
| 32 | /* Loop long enough so valgrind has a forced context switch and |
| 33 | actually delivers the signal before the thread exits. */ |
| 34 | for (i = 0; i < 1000000; i++) ; |
| 35 | |
| 36 | fprintf(stderr, "done\n"); |
| 37 | return 0; |
| 38 | } |