mc_translate.c: enable further uses of DLexpensive for scalar EQ/NE comparisons
[valgrind.git] / none / tests / sigstackgrowth.c
blob3f687961cdf848b2349079e67c9666ab5539fb04
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 sa.sa_flags = SA_NODEFER;
52 sigemptyset(&sa.sa_mask);
54 sigaction(SIGUSR1, &sa, NULL);
56 kill(getpid(), SIGUSR1);
58 printf("FAILED\n");
59 exit(1);