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 sighandler(int sig,siginfo_t * sip,ucontext_t * ucp)8static void sighandler(int sig, siginfo_t *sip, ucontext_t *ucp) 9 { 10 ucontext_t uc2; 11 12 /* Current uc_link value has to be equal to ucp. */ 13 getcontext(&uc2); 14 assert(uc2.uc_link == ucp); 15 } 16 main(void)17int 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 29 sa.sa_handler = sighandler; 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 49