File: signal.c

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (313 lines) | stat: -rw-r--r-- 8,163 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* COVERAGE: signal tgkill tkill sigprocmask sigaction */
/* COVERAGE: sigpending sigsuspend */

#define _GNU_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/syscall.h>

// For signal()/sigprocmask()/sigpending()/sigsuspend(), glibc
// substitutes the 'rt_*' versions.  To ensure we're calling the right
// syscalls, we have to create our own syscall wrappers. For other
// syscalls tested here (like tgkill), there are no glibc syscall
// wrappers.

typedef void (*sighandler_t)(int);

#ifdef SYS_signal
static inline sighandler_t __signal(int signum, sighandler_t handler)
{
    return (sighandler_t)syscall(SYS_signal, signum, handler);
}
#endif

#ifdef SYS_sigprocmask
static inline int __sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
{
    return syscall(SYS_sigprocmask, how, set, oldset);
}
#endif

#ifdef SYS_sigaction
static inline int
__sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
{
    return syscall(SYS_sigaction, signum, act, oldact);
}
#endif

#ifdef SYS_tgkill
static inline int __tgkill(int tgid, int tid, int sig)
{
    return syscall(SYS_tgkill, tgid, tid, sig);
}
#endif

#ifdef SYS_tkill
static inline int __tkill(int tid, int sig)
{
    return syscall(SYS_tkill, tid, sig);
}
#endif

#ifdef SYS_sigpending
static inline int __sigpending(sigset_t *set)
{
    return syscall(SYS_sigpending, set);
}
#endif

#ifdef SYS_sigsuspend
// Notice that the sigsuspend() syscall takes an unsigned long, not a
// pointer to a sigset_t. The rt_sigsuspend() syscall (which glibc
// uses) takes a pointer to a sigset_t.

// This gets more complicated by the fact that there are
// architecture-specific versions of sys_sigsuspend:
//
// #ifdef CONFIG_OLD_SIGSUSPEND
// asmlinkage long sys_sigsuspend(old_sigset_t mask);
// #endif
// #ifdef CONFIG_OLD_SIGSUSPEND3
// asmlinkage long sys_sigsuspend(int unused1, int unused2, old_sigset_t mask);
// #endif
#if defined(__arm__) || defined(__s390__) || defined(__i386__) \
    || defined(__aarch64__)
#define CONFIG_OLD_SIGSUSPEND3
#endif

static inline int __sigsuspend(unsigned long mask)
{
#if defined(CONFIG_OLD_SIGSUSPEND3)
    return syscall(SYS_sigsuspend, 0, 0, mask);
#else
    return syscall(SYS_sigsuspend, mask);
#endif
}
#endif

static void 
sig_act_handler(int signo)
{
}

int main()
{
  sigset_t mask, mask2;
  struct sigaction sa;
  pid_t pid;
  unsigned long old_mask;

#ifdef SYS_signal
  __signal(SIGUSR1, SIG_IGN);
  //staptest// signal (SIGUSR1, SIG_IGN)

  __signal(SIGUSR1, SIG_DFL);
  //staptest// signal (SIGUSR1, SIG_DFL) = 1

  __signal(SIGUSR1, sig_act_handler);
  //staptest// signal (SIGUSR1, XXXX) = 0

  __signal(-1, sig_act_handler);
  //staptest// signal (0x[f]+, XXXX) = NNNN

  __signal(SIGUSR1, (sighandler_t)-1);
#ifdef __s390__
  //staptest// signal (SIGUSR1, 0x[7]?[f]+) = NNNN
#else
  //staptest// signal (SIGUSR1, 0x[f]+) = NNNN
#endif
#endif

  sigemptyset(&mask);
  sigaddset(&mask, SIGUSR2);

#ifdef SYS_sigprocmask
  __sigprocmask(SIG_BLOCK, &mask, NULL);
  /* sigprocmask is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
  //staptest// sigprocmask (SIG_BLOCK, XXXX, 0x0+) = 0
#endif

  __sigprocmask(SIG_UNBLOCK, &mask, NULL);
  /* sigprocmask is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
  //staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x0+) = 0
#endif

  __sigprocmask(-1, &mask, NULL);
  /* sigprocmask is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
  //staptest// sigprocmask (0x[f]+, XXXX, 0x0+) = -NNNN
#endif

  __sigprocmask(SIG_UNBLOCK, (sigset_t *)-1, NULL);
  /* sigprocmask is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
#ifdef __s390__
  //staptest// sigprocmask (SIG_UNBLOCK, 0x[7]?[f]+, 0x0+) = -NNNN (EFAULT)
#else
  //staptest// sigprocmask (SIG_UNBLOCK, 0x[f]+, 0x0+) = -NNNN (EFAULT)
#endif
#endif

  __sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)-1);
  /* sigprocmask is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
#ifdef __s390__
  //staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x[7]?[f]+) = -NNNN (EFAULT)
#else
  //staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x[f]+) = -NNNN (EFAULT)
#endif
#endif

#endif

  memset(&sa, 0, sizeof(sa));
  sigfillset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;

#ifdef SYS_sigaction
  __sigaction(SIGUSR1, &sa, NULL);
  /* sigaction is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
  //staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x0+) = 0
#endif

  __sigaction(-1, &sa, NULL);
  /* sigaction is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
  //staptest// sigaction (0x[f]+, {SIG_IGN}, 0x0+) = NNNN
#endif

  __sigaction(SIGUSR1, (struct sigaction *)-1, NULL);
  /* sigaction is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
#ifdef __s390__
  //staptest// sigaction (SIGUSR1, \{0x[7]?[f]+\}, 0x0+) = -NNNN (EFAULT)
#else
  //staptest// sigaction (SIGUSR1, \{0x[f]+\}, 0x0+) = -NNNN (EFAULT)
#endif
#endif

  __sigaction(SIGUSR1, &sa, (struct sigaction *)-1);
  /* sigaction is unimplemented on powerpc64 */
#ifdef __powerpc64__
  //staptest// ni_syscall () = -38 (ENOSYS)
#else
#ifdef __s390__
  //staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x[7]?[f]+) = -NNNN (EFAULT)
#else
  //staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x[f]+) = -NNNN (EFAULT)
#endif
#endif
#endif

#ifdef SYS_tgkill
  __tgkill(1234, 5678, 0);
  //staptest// tgkill (1234, 5678, SIG_0) = NNNN

  __tgkill(-1, 5678, 0);
  //staptest// tgkill (-1, 5678, SIG_0) = NNNN

  __tgkill(1234, -1, 0);
  //staptest// tgkill (1234, -1, SIG_0) = NNNN

  __tgkill(1234, 5678, -1);
  //staptest// tgkill (1234, 5678, 0x[f]+) = NNNN
#endif

#ifdef SYS_tkill
  pid = getpid();

  __tkill(pid, 0);
  //staptest// tkill (NNNN, SIG_0) = 0

  __tkill(-1, SIGHUP);
  //staptest// tkill (-1, SIGHUP) = NNNN

  __tkill(-1, -1);
  //staptest// tkill (-1, 0x[f]+) = NNNN
#endif

#ifdef SYS_sigpending
  sigemptyset(&mask);
  __sigpending(&mask);
  //staptest// [[[[sigpending (XXXX)!!!!ni_syscall ()]]]] = NNNN

  __sigpending((sigset_t *) 0);
  //staptest// [[[[sigpending (0x0)!!!!ni_syscall ()]]]] = NNNN

  __sigpending((sigset_t *)-1);
#ifdef __s390__
  //staptest// sigpending (0x[7]?[f]+) = -NNNN (EFAULT)
#else
  //staptest// [[[[sigpending (0x[f]+)!!!!ni_syscall ()]]]] = NNNN
#endif
#endif

  /* If we have SYS_sigaction (but not on powerpc where it isn't
   * implemented) and SYS_sigprocmask, we can do SYS_sigsuspend
   * tests. We set up a signal handler for SIGALRM, then send a
   * SIGALRM using alarm(). */
#if defined(SYS_sigsuspend) && defined(SYS_sigaction) \
    && !defined(__powerpc64__) && defined(SYS_sigprocmask)
  sigemptyset(&mask2);

  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = sig_act_handler;
  __sigaction(SIGALRM, &sa, NULL);
  //staptest// sigaction (SIGALRM, {XXXX, 0x0, 0x0, \[EMPTY\]}, 0x0+) = 0

  __sigprocmask(SIG_UNBLOCK, &mask2, NULL);
  //staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x0) = 0

  // Create a sigsset_t with SIGUSR1 in it (just so we have something
  // to display), then convert it to an unsigned long, which is what
  // sigsuspend() wants.
  sigemptyset(&mask);
  sigaddset(&mask, SIGUSR1);
  memcpy(&old_mask, &mask, sizeof(old_mask));

  alarm(5);
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__)
  //staptest// setitimer (ITIMER_REAL, \[0.000000,5.000000\], XXXX) = NNNN
#else
  //staptest// alarm (5) = NNNN
#endif

  __sigsuspend(old_mask);
  //staptest// sigsuspend (\[SIGUSR1\]) = NNNN

  alarm(0);
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__)
  //staptest// setitimer (ITIMER_REAL, \[0.000000,0.000000\], XXXX) = NNNN
#else
  //staptest// alarm (0) = NNNN
#endif

  // Calling sigsuspend() with -1 waits forever, since that blocks all
  // signals. 
  //__sigsuspend((unsigned long)-1);
#endif

  return 0;
}