File: context_link2.c

package info (click to toggle)
valgrind 1%3A3.16.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 158,568 kB
  • sloc: ansic: 746,130; exp: 26,134; xml: 22,708; asm: 13,570; cpp: 7,691; makefile: 6,177; perl: 5,965; sh: 5,665; javascript: 929
file content (48 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Test of correct simulation for uc->uc_link in a signal handler. */

#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <ucontext.h>

static void sighandler(int sig, siginfo_t *sip, void *arg)
{
   ucontext_t uc2;

   /* Current uc_link value has to be equal to (ucontext_t *) arg. */
   getcontext(&uc2);
   assert(uc2.uc_link == arg);
}

int main(void)
{
   ucontext_t uc;
   struct sigaction sa;

   /* Current uc_link value has to be NULL. */
   if (getcontext(&uc)) {
      perror("getcontext");
      return 1;
   }
   assert(!uc.uc_link);

   sa.sa_sigaction = sighandler;
   sa.sa_flags = SA_SIGINFO;
   if (sigfillset(&sa.sa_mask)) {
      perror("sigfillset");
      return 1;
   }
   if (sigaction(SIGUSR1, &sa, NULL)) {
      perror("sigaction");
      return 1;
   }

   raise(SIGUSR1);

   /* Current uc_link value has to be NULL. */
   getcontext(&uc);
   assert(!uc.uc_link);

   return 0;
}