sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 1 | /* Test of correct simulation for uc->uc_link in a signal handler. */ |
| 2 | |
| 3 | #include <assert.h> |
| 4 | #include <signal.h> |
| 5 | #include <stdio.h> |
| 6 | #include <ucontext.h> |
| 7 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 8 | static void sighandler(int sig, siginfo_t *sip, void *arg) |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 9 | { |
| 10 | ucontext_t uc2; |
| 11 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 12 | /* Current uc_link value has to be equal to (ucontext_t *) arg. */ |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 13 | getcontext(&uc2); |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 14 | assert(uc2.uc_link == arg); |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | int main(void) |
| 18 | { |
| 19 | ucontext_t uc; |
| 20 | struct sigaction sa; |
| 21 | |
| 22 | /* Current uc_link value has to be NULL. */ |
| 23 | if (getcontext(&uc)) { |
| 24 | perror("getcontext"); |
| 25 | return 1; |
| 26 | } |
| 27 | assert(!uc.uc_link); |
| 28 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 29 | sa.sa_sigaction = sighandler; |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 30 | sa.sa_flags = SA_SIGINFO; |
| 31 | if (sigfillset(&sa.sa_mask)) { |
| 32 | perror("sigfillset"); |
| 33 | return 1; |
| 34 | } |
| 35 | if (sigaction(SIGUSR1, &sa, NULL)) { |
| 36 | perror("sigaction"); |
| 37 | return 1; |
| 38 | } |
| 39 | |
| 40 | raise(SIGUSR1); |
| 41 | |
| 42 | /* Current uc_link value has to be NULL. */ |
| 43 | getcontext(&uc); |
| 44 | assert(!uc.uc_link); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |