blob: 7979b73e06d6329a8b4b85c080a4181567c99d65 [file] [log] [blame]
sewardj8eb8bab2015-07-21 14:44:28 +00001/* 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 Hughesa0664b92017-04-18 17:46:52 -07008static void sighandler(int sig, siginfo_t *sip, void *arg)
sewardj8eb8bab2015-07-21 14:44:28 +00009{
10 ucontext_t uc2;
11
Elliott Hughesa0664b92017-04-18 17:46:52 -070012 /* Current uc_link value has to be equal to (ucontext_t *) arg. */
sewardj8eb8bab2015-07-21 14:44:28 +000013 getcontext(&uc2);
Elliott Hughesa0664b92017-04-18 17:46:52 -070014 assert(uc2.uc_link == arg);
sewardj8eb8bab2015-07-21 14:44:28 +000015}
16
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
Elliott Hughesa0664b92017-04-18 17:46:52 -070029 sa.sa_sigaction = sighandler;
sewardj8eb8bab2015-07-21 14:44:28 +000030 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