sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 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 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 10 | static void sighandler(int sig, siginfo_t *sip, void *arg) |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 11 | { |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 12 | ucontext_t *ucp = (ucontext_t *) arg; |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 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. */ |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 24 | sa.sa_sigaction = sighandler; |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 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 | |