Home | History | Annotate | Download | only in solaris
      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 
     10 static void sighandler(int sig, siginfo_t *sip, void *arg)
     11 {
     12    ucontext_t *ucp = (ucontext_t *) arg;
     13    sp = (int *) &ucp->uc_mcontext.gregs[0];
     14 }
     15 
     16 int main(void)
     17 {
     18    struct sigaction sa;
     19    /* Always-null value that is used to prevent any possible compiler
     20       optimizations. */
     21    volatile int zero = 0;
     22 
     23    /* Setup a signal handler. */
     24    sa.sa_sigaction = sighandler;
     25    sa.sa_flags = SA_SIGINFO;
     26    if (sigfillset(&sa.sa_mask)) {
     27       perror("sigfillset");
     28       return 1;
     29    }
     30    if (sigaction(SIGUSR1, &sa, NULL)) {
     31       perror("sigaction");
     32       return 1;
     33    }
     34 
     35    /* Raise a signal. */
     36    raise(SIGUSR1);
     37 
     38    /* Value pointed by sp should be at this point uninitialized. */
     39    if (*sp && zero)
     40       assert(0);
     41 
     42    return 0;
     43 }
     44 
     45