• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Test that the stack correctly dies after a setcontext(2) call. */
2 
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <ucontext.h>
7 
8 static volatile int *sp;
9 
sighandler(int sig,siginfo_t * sip,ucontext_t * ucp)10 static void sighandler(int sig, siginfo_t *sip, ucontext_t *ucp)
11 {
12    sp = (int *) &ucp->uc_mcontext.gregs[0];
13 }
14 
main(void)15 int main(void)
16 {
17    struct sigaction sa;
18    /* Always-null value that is used to prevent any possible compiler
19       optimizations. */
20    volatile int zero = 0;
21 
22    /* Setup a signal handler. */
23    sa.sa_handler = sighandler;
24    sa.sa_flags = SA_SIGINFO;
25    if (sigfillset(&sa.sa_mask)) {
26       perror("sigfillset");
27       return 1;
28    }
29    if (sigaction(SIGUSR1, &sa, NULL)) {
30       perror("sigaction");
31       return 1;
32    }
33 
34    /* Raise a signal. */
35    raise(SIGUSR1);
36 
37    /* Value pointed by sp should be at this point uninitialized. */
38    if (*sp && zero)
39       assert(0);
40 
41    return 0;
42 }
43 
44