| 1 |
/* COVERAGE: signal tgkill tkill sigprocmask sigaction */ |
| 2 |
/* COVERAGE: sigpending sigsuspend */ |
| 3 |
|
| 4 |
#define _GNU_SOURCE |
| 5 |
#include <sys/types.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include <signal.h> |
| 8 |
#include <string.h> |
| 9 |
#include <sys/syscall.h> |
| 10 |
|
| 11 |
// For signal()/sigprocmask()/sigpending()/sigsuspend(), glibc |
| 12 |
// substitutes the 'rt_*' versions. To ensure we're calling the right |
| 13 |
// syscalls, we have to create our own syscall wrappers. For other |
| 14 |
// syscalls tested here (like tgkill), there are no glibc syscall |
| 15 |
// wrappers. |
| 16 |
|
| 17 |
typedef void (*sighandler_t)(int); |
| 18 |
|
| 19 |
#ifdef SYS_signal |
| 20 |
static inline sighandler_t __signal(int signum, sighandler_t handler) |
| 21 |
{ |
| 22 |
return (sighandler_t)syscall(SYS_signal, signum, handler); |
| 23 |
} |
| 24 |
#endif |
| 25 |
|
| 26 |
#ifdef SYS_sigprocmask |
| 27 |
static inline int __sigprocmask(int how, const sigset_t *set, sigset_t *oldset) |
| 28 |
{ |
| 29 |
return syscall(SYS_sigprocmask, how, set, oldset); |
| 30 |
} |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifdef SYS_sigaction |
| 34 |
static inline int |
| 35 |
__sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) |
| 36 |
{ |
| 37 |
return syscall(SYS_sigaction, signum, act, oldact); |
| 38 |
} |
| 39 |
#endif |
| 40 |
|
| 41 |
#ifdef SYS_tgkill |
| 42 |
static inline int __tgkill(int tgid, int tid, int sig) |
| 43 |
{ |
| 44 |
return syscall(SYS_tgkill, tgid, tid, sig); |
| 45 |
} |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifdef SYS_tkill |
| 49 |
static inline int __tkill(int tid, int sig) |
| 50 |
{ |
| 51 |
return syscall(SYS_tkill, tid, sig); |
| 52 |
} |
| 53 |
#endif |
| 54 |
|
| 55 |
#ifdef SYS_sigpending |
| 56 |
static inline int __sigpending(sigset_t *set) |
| 57 |
{ |
| 58 |
return syscall(SYS_sigpending, set); |
| 59 |
} |
| 60 |
#endif |
| 61 |
|
| 62 |
#ifdef SYS_sigsuspend |
| 63 |
// Notice that the sigsuspend() syscall takes an unsigned long, not a |
| 64 |
// pointer to a sigset_t. The rt_sigsuspend() syscall (which glibc |
| 65 |
// uses) takes a pointer to a sigset_t. |
| 66 |
|
| 67 |
// This gets more complicated by the fact that there are |
| 68 |
// architecture-specific versions of sys_sigsuspend: |
| 69 |
// |
| 70 |
// #ifdef CONFIG_OLD_SIGSUSPEND |
| 71 |
// asmlinkage long sys_sigsuspend(old_sigset_t mask); |
| 72 |
// #endif |
| 73 |
// #ifdef CONFIG_OLD_SIGSUSPEND3 |
| 74 |
// asmlinkage long sys_sigsuspend(int unused1, int unused2, old_sigset_t mask); |
| 75 |
// #endif |
| 76 |
#if defined(__arm__) || defined(__s390__) || defined(__i386__) \ |
| 77 |
|| defined(__aarch64__) |
| 78 |
#define CONFIG_OLD_SIGSUSPEND3 |
| 79 |
#endif |
| 80 |
|
| 81 |
static inline int __sigsuspend(unsigned long mask) |
| 82 |
{ |
| 83 |
#if defined(CONFIG_OLD_SIGSUSPEND3) |
| 84 |
return syscall(SYS_sigsuspend, 0, 0, mask); |
| 85 |
#else |
| 86 |
return syscall(SYS_sigsuspend, mask); |
| 87 |
#endif |
| 88 |
} |
| 89 |
#endif |
| 90 |
|
| 91 |
static void |
| 92 |
sig_act_handler(int signo) |
| 93 |
{ |
| 94 |
} |
| 95 |
|
| 96 |
int main() |
| 97 |
{ |
| 98 |
sigset_t mask, mask2; |
| 99 |
struct sigaction sa; |
| 100 |
pid_t pid; |
| 101 |
unsigned long old_mask; |
| 102 |
|
| 103 |
#ifdef SYS_signal |
| 104 |
__signal(SIGUSR1, SIG_IGN); |
| 105 |
//staptest// signal (SIGUSR1, SIG_IGN) |
| 106 |
|
| 107 |
__signal(SIGUSR1, SIG_DFL); |
| 108 |
//staptest// signal (SIGUSR1, SIG_DFL) = 1 |
| 109 |
|
| 110 |
__signal(SIGUSR1, sig_act_handler); |
| 111 |
//staptest// signal (SIGUSR1, XXXX) = 0 |
| 112 |
|
| 113 |
__signal(-1, sig_act_handler); |
| 114 |
//staptest// signal (0x[f]+, XXXX) = NNNN |
| 115 |
|
| 116 |
__signal(SIGUSR1, (sighandler_t)-1); |
| 117 |
#ifdef __s390__ |
| 118 |
//staptest// signal (SIGUSR1, 0x[7]?[f]+) = NNNN |
| 119 |
#else |
| 120 |
//staptest// signal (SIGUSR1, 0x[f]+) = NNNN |
| 121 |
#endif |
| 122 |
#endif |
| 123 |
|
| 124 |
sigemptyset(&mask); |
| 125 |
sigaddset(&mask, SIGUSR2); |
| 126 |
|
| 127 |
#ifdef SYS_sigprocmask |
| 128 |
__sigprocmask(SIG_BLOCK, &mask, NULL); |
| 129 |
/* sigprocmask is unimplemented on powerpc64 */ |
| 130 |
#ifdef __powerpc64__ |
| 131 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 132 |
#else |
| 133 |
//staptest// sigprocmask (SIG_BLOCK, XXXX, 0x0+) = 0 |
| 134 |
#endif |
| 135 |
|
| 136 |
__sigprocmask(SIG_UNBLOCK, &mask, NULL); |
| 137 |
/* sigprocmask is unimplemented on powerpc64 */ |
| 138 |
#ifdef __powerpc64__ |
| 139 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 140 |
#else |
| 141 |
//staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x0+) = 0 |
| 142 |
#endif |
| 143 |
|
| 144 |
__sigprocmask(-1, &mask, NULL); |
| 145 |
/* sigprocmask is unimplemented on powerpc64 */ |
| 146 |
#ifdef __powerpc64__ |
| 147 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 148 |
#else |
| 149 |
//staptest// sigprocmask (0x[f]+, XXXX, 0x0+) = -NNNN |
| 150 |
#endif |
| 151 |
|
| 152 |
__sigprocmask(SIG_UNBLOCK, (sigset_t *)-1, NULL); |
| 153 |
/* sigprocmask is unimplemented on powerpc64 */ |
| 154 |
#ifdef __powerpc64__ |
| 155 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 156 |
#else |
| 157 |
#ifdef __s390__ |
| 158 |
//staptest// sigprocmask (SIG_UNBLOCK, 0x[7]?[f]+, 0x0+) = -NNNN (EFAULT) |
| 159 |
#else |
| 160 |
//staptest// sigprocmask (SIG_UNBLOCK, 0x[f]+, 0x0+) = -NNNN (EFAULT) |
| 161 |
#endif |
| 162 |
#endif |
| 163 |
|
| 164 |
__sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)-1); |
| 165 |
/* sigprocmask is unimplemented on powerpc64 */ |
| 166 |
#ifdef __powerpc64__ |
| 167 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 168 |
#else |
| 169 |
#ifdef __s390__ |
| 170 |
//staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 171 |
#else |
| 172 |
//staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x[f]+) = -NNNN (EFAULT) |
| 173 |
#endif |
| 174 |
#endif |
| 175 |
|
| 176 |
#endif |
| 177 |
|
| 178 |
memset(&sa, 0, sizeof(sa)); |
| 179 |
sigfillset(&sa.sa_mask); |
| 180 |
sa.sa_handler = SIG_IGN; |
| 181 |
|
| 182 |
#ifdef SYS_sigaction |
| 183 |
__sigaction(SIGUSR1, &sa, NULL); |
| 184 |
/* sigaction is unimplemented on powerpc64 */ |
| 185 |
#ifdef __powerpc64__ |
| 186 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 187 |
#else |
| 188 |
//staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x0+) = 0 |
| 189 |
#endif |
| 190 |
|
| 191 |
__sigaction(-1, &sa, NULL); |
| 192 |
/* sigaction is unimplemented on powerpc64 */ |
| 193 |
#ifdef __powerpc64__ |
| 194 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 195 |
#else |
| 196 |
//staptest// sigaction (0x[f]+, {SIG_IGN}, 0x0+) = NNNN |
| 197 |
#endif |
| 198 |
|
| 199 |
__sigaction(SIGUSR1, (struct sigaction *)-1, NULL); |
| 200 |
/* sigaction is unimplemented on powerpc64 */ |
| 201 |
#ifdef __powerpc64__ |
| 202 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 203 |
#else |
| 204 |
#ifdef __s390__ |
| 205 |
//staptest// sigaction (SIGUSR1, \{0x[7]?[f]+\}, 0x0+) = -NNNN (EFAULT) |
| 206 |
#else |
| 207 |
//staptest// sigaction (SIGUSR1, \{0x[f]+\}, 0x0+) = -NNNN (EFAULT) |
| 208 |
#endif |
| 209 |
#endif |
| 210 |
|
| 211 |
__sigaction(SIGUSR1, &sa, (struct sigaction *)-1); |
| 212 |
/* sigaction is unimplemented on powerpc64 */ |
| 213 |
#ifdef __powerpc64__ |
| 214 |
//staptest// ni_syscall () = -38 (ENOSYS) |
| 215 |
#else |
| 216 |
#ifdef __s390__ |
| 217 |
//staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 218 |
#else |
| 219 |
//staptest// sigaction (SIGUSR1, {SIG_IGN}, 0x[f]+) = -NNNN (EFAULT) |
| 220 |
#endif |
| 221 |
#endif |
| 222 |
#endif |
| 223 |
|
| 224 |
#ifdef SYS_tgkill |
| 225 |
__tgkill(1234, 5678, 0); |
| 226 |
//staptest// tgkill (1234, 5678, SIG_0) = NNNN |
| 227 |
|
| 228 |
__tgkill(-1, 5678, 0); |
| 229 |
//staptest// tgkill (-1, 5678, SIG_0) = NNNN |
| 230 |
|
| 231 |
__tgkill(1234, -1, 0); |
| 232 |
//staptest// tgkill (1234, -1, SIG_0) = NNNN |
| 233 |
|
| 234 |
__tgkill(1234, 5678, -1); |
| 235 |
//staptest// tgkill (1234, 5678, 0x[f]+) = NNNN |
| 236 |
#endif |
| 237 |
|
| 238 |
#ifdef SYS_tkill |
| 239 |
pid = getpid(); |
| 240 |
|
| 241 |
__tkill(pid, 0); |
| 242 |
//staptest// tkill (NNNN, SIG_0) = 0 |
| 243 |
|
| 244 |
__tkill(-1, SIGHUP); |
| 245 |
//staptest// tkill (-1, SIGHUP) = NNNN |
| 246 |
|
| 247 |
__tkill(-1, -1); |
| 248 |
//staptest// tkill (-1, 0x[f]+) = NNNN |
| 249 |
#endif |
| 250 |
|
| 251 |
#ifdef SYS_sigpending |
| 252 |
sigemptyset(&mask); |
| 253 |
__sigpending(&mask); |
| 254 |
//staptest// [[[[sigpending (XXXX)!!!!ni_syscall ()]]]] = NNNN |
| 255 |
|
| 256 |
__sigpending((sigset_t *) 0); |
| 257 |
//staptest// [[[[sigpending (0x0)!!!!ni_syscall ()]]]] = NNNN |
| 258 |
|
| 259 |
__sigpending((sigset_t *)-1); |
| 260 |
#ifdef __s390__ |
| 261 |
//staptest// sigpending (0x[7]?[f]+) = -NNNN (EFAULT) |
| 262 |
#else |
| 263 |
//staptest// [[[[sigpending (0x[f]+)!!!!ni_syscall ()]]]] = NNNN |
| 264 |
#endif |
| 265 |
#endif |
| 266 |
|
| 267 |
/* If we have SYS_sigaction (but not on powerpc where it isn't |
| 268 |
* implemented) and SYS_sigprocmask, we can do SYS_sigsuspend |
| 269 |
* tests. We set up a signal handler for SIGALRM, then send a |
| 270 |
* SIGALRM using alarm(). */ |
| 271 |
#if defined(SYS_sigsuspend) && defined(SYS_sigaction) \ |
| 272 |
&& !defined(__powerpc64__) && defined(SYS_sigprocmask) |
| 273 |
sigemptyset(&mask2); |
| 274 |
|
| 275 |
memset(&sa, 0, sizeof(sa)); |
| 276 |
sa.sa_handler = sig_act_handler; |
| 277 |
__sigaction(SIGALRM, &sa, NULL); |
| 278 |
//staptest// sigaction (SIGALRM, {XXXX, 0x0, 0x0, \[EMPTY\]}, 0x0+) = 0 |
| 279 |
|
| 280 |
__sigprocmask(SIG_UNBLOCK, &mask2, NULL); |
| 281 |
//staptest// sigprocmask (SIG_UNBLOCK, XXXX, 0x0) = 0 |
| 282 |
|
| 283 |
// Create a sigsset_t with SIGUSR1 in it (just so we have something |
| 284 |
// to display), then convert it to an unsigned long, which is what |
| 285 |
// sigsuspend() wants. |
| 286 |
sigemptyset(&mask); |
| 287 |
sigaddset(&mask, SIGUSR1); |
| 288 |
memcpy(&old_mask, &mask, sizeof(old_mask)); |
| 289 |
|
| 290 |
alarm(5); |
| 291 |
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) |
| 292 |
//staptest// setitimer (ITIMER_REAL, \[0.000000,5.000000\], XXXX) = NNNN |
| 293 |
#else |
| 294 |
//staptest// alarm (5) = NNNN |
| 295 |
#endif |
| 296 |
|
| 297 |
__sigsuspend(old_mask); |
| 298 |
//staptest// sigsuspend (\[SIGUSR1\]) = NNNN |
| 299 |
|
| 300 |
alarm(0); |
| 301 |
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) |
| 302 |
//staptest// setitimer (ITIMER_REAL, \[0.000000,0.000000\], XXXX) = NNNN |
| 303 |
#else |
| 304 |
//staptest// alarm (0) = NNNN |
| 305 |
#endif |
| 306 |
|
| 307 |
// Calling sigsuspend() with -1 waits forever, since that blocks all |
| 308 |
// signals. |
| 309 |
//__sigsuspend((unsigned long)-1); |
| 310 |
#endif |
| 311 |
|
| 312 |
return 0; |
| 313 |
} |