FreeBSD _umtx_op: fix bad wrapper for robust lists
[valgrind.git] / none / tests / sigstackgrowth.c
blob7b0bbe07b318c17261a05a60f54e1c093fbd3586
1 #include <signal.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <unistd.h>
7 /* What does this test do? It checks that valgrind's signal frame
8 building mechanism can create at least 4MB of signal delivery
9 frames, hence that it can actually expand the stack by that much
10 when delivering signals. A fair-enough thing to want to test.
12 It does this by getting into the signal handler, and then
13 recursively invoking the handler by sending itself the signal
14 again, until the stack has grown to 4MB from the starting frame
15 (main).
17 Consequence is: it is essential that we do not disable delivery of
18 further signals within the handler itself, else the kernel will
19 wait till the handler exits before delivering the next signal, the
20 frame will be cleared, the stack will never grow, and we'll be in
21 an infinite loop.
23 Hence we *must* give the SA_NODEFER flag when setting up the
24 handler.
27 static char *deep;
29 #define SIZE (4*1024*1024)
31 static void handler(int sig)
33 char here;
35 if (&here < deep) {
36 printf("PASSED\n");
37 exit(0);
40 kill(getpid(), SIGUSR1);
43 int main()
45 struct sigaction sa;
47 char here;
48 deep = &here - SIZE;
50 sa.sa_handler = handler;
51 #if defined(SA_NODEFER)
52 sa.sa_flags = SA_NODEFER;
53 #endif
54 sigemptyset(&sa.sa_mask);
56 sigaction(SIGUSR1, &sa, NULL);
58 kill(getpid(), SIGUSR1);
60 printf("FAILED\n");
61 exit(1);