5 #include "tests/sys_mman.h"
7 void sig_handler(int sig
){
9 fprintf(stderr
, "caught signal, local var is on %#" PRIxPTR
"\n",
13 int main(int argv
, char** argc
) {
17 static const int size
= SIGSTKSZ
*2;
18 // We give EXEC permissions because this won't work on ppc32 unless you
19 // ask for an alt stack with EXEC permissions,
20 // since signal returning requires execution of code on the stack.
21 char *stk
= (char *)mmap(0, size
, PROT_READ
|PROT_WRITE
|PROT_EXEC
,
22 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
25 sigstk
.ss_size
= size
;
27 fprintf(stderr
, "calling sigaltstack, stack base is %#" PRIxPTR
"\n",
28 (uintptr_t)sigstk
.ss_sp
);
29 if (sigaltstack(&sigstk
,0)<0) perror("sigaltstack");
31 fprintf(stderr
,"setting sigaction\n");
32 act
.sa_flags
=SA_ONSTACK
;
33 act
.sa_handler
=&sig_handler
;
34 sigemptyset(&act
.sa_mask
);
35 res
= sigaction(SIGUSR1
,&act
,0);
36 fprintf(stderr
, "res = %d\n", res
);
37 fprintf(stderr
, "raising the signal\n");
40 /* Loop long enough so valgrind has a forced context switch and
41 actually delivers the signal before the thread exits. */
42 for (i
= 0; i
< 1000000; i
++) ;
44 fprintf(stderr
, "done\n");