summaryrefslogtreecommitdiff
path: root/memcheck/tests/sigprocmask.c
blob: 05eb87a51584b4f0781527e13f4509231d0f821e (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include <signal.h>
#include <stdio.h>
#if !defined(_AIX)
# include <sys/syscall.h>
#endif
#include <unistd.h>

// Reg test for bug #93328: we were using too-big sigset types, and thus
// trashing memory when we wrote out the 'oldset' param from sigprocmask().

int main(void)
{
#if defined(__NR_sigprocmask)        \
    && !defined(__powerpc64__)       \
    && !defined(_AIX)                \
    && !defined(__arm__)

   // arm-linux uses rt_sigprocmask, so no sigset mangling takes place

   int x[6], *s, *os, i;

   x[0] = 0x11111111;
   x[1] = 0x89abcdef;
   x[2] = 0x22222222;
   x[3] = 0x33333333;
   x[4] = 0x0;
   x[5] = 0x44444444;

   s  = &x[1];
   os = &x[4];

   // Make sure the system is in a known state with no signals
   // blocked as perl has been known to leave some signals blocked
   // when starting child processes which can cause failures in
   // this test unless we reset things here.
   syscall(__NR_sigprocmask, SIG_SETMASK, os, NULL);

   fprintf(stderr, "before\n");
   for (i = 0; i < 6; i++) {
      fprintf(stderr, "%x ", x[i]);
   }
   fprintf(stderr, "\n");

   syscall(__NR_sigprocmask, SIG_BLOCK, s, os);

   fprintf(stderr, "after1\n");
   for (i = 0; i < 6; i++) {
      fprintf(stderr, "%x ", x[i]);
   }
   fprintf(stderr, "\n");
   
   syscall(__NR_sigprocmask, SIG_BLOCK, s, os);

   fprintf(stderr, "after2\n");
   for (i = 0; i < 6; i++) {
      fprintf(stderr, "%x ", x[i]);
   }
   fprintf(stderr, "\n");

#else

   fprintf(stderr, "__NR_sigprocmask not supported on this platform\n");

#endif

   return(0);
}