| 1 |
/* COVERAGE: sigaltstack */ |
| 2 |
|
| 3 |
#define _BSD_SOURCE |
| 4 |
#define _DEFAULT_SOURCE |
| 5 |
#include <unistd.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include <signal.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
// To test for glibc support for sigaltstack(): |
| 11 |
#define GLIBC_SUPPORT \ |
| 12 |
(_BSD_SOURCE || _XOPEN_SOURCE >= 500 || \ |
| 13 |
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED \ |
| 14 |
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L) |
| 15 |
|
| 16 |
static void |
| 17 |
sig_act_handler(int signo) |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
int main() |
| 22 |
{ |
| 23 |
#ifdef GLIBC_SUPPORT |
| 24 |
stack_t ss; |
| 25 |
struct sigaction act, oact; |
| 26 |
sigset_t mask; |
| 27 |
|
| 28 |
ss.ss_sp = malloc(SIGSTKSZ); |
| 29 |
ss.ss_size = SIGSTKSZ; |
| 30 |
ss.ss_flags = SS_ONSTACK; |
| 31 |
|
| 32 |
/* Set up an alternate signal stack. */ |
| 33 |
sigaltstack(&ss, NULL); |
| 34 |
// Notice we can't test for an exact ss_size, since SIGSTKSZ might |
| 35 |
// vary on different architectures. |
| 36 |
//staptest// sigaltstack ({ss_sp=XXXX, ss_flags=SS_ONSTACK, ss_size=NNNN}, 0x0) = 0 |
| 37 |
|
| 38 |
/* Set up the signal handler for 'SIGALRM'. Notice the SA_ONSTACK |
| 39 |
* flag, which tells the system to use the alternate signal |
| 40 |
* stack. Also note that glibc on some platforms likes to add in |
| 41 |
* the SA_RESTORER flag. */ |
| 42 |
memset(&act, 0, sizeof(act)); |
| 43 |
act.sa_flags = SA_ONSTACK; |
| 44 |
act.sa_handler = (void (*)())sig_act_handler; |
| 45 |
sigaction(SIGALRM, &act, &oact); |
| 46 |
#ifdef __ia64__ |
| 47 |
//staptest// rt_sigaction (SIGALRM, {XXXX, SA_ONSTACK, \[EMPTY\]}, XXXX, 8) = 0 |
| 48 |
#else |
| 49 |
//staptest// rt_sigaction (SIGALRM, {XXXX, SA_ONSTACK[[[[|SA_RESTORER]]]]?, XXXX, \[EMPTY\]}, XXXX, 8) = 0 |
| 50 |
#endif |
| 51 |
|
| 52 |
alarm(5); |
| 53 |
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) |
| 54 |
//staptest// setitimer (ITIMER_REAL, \[0.000000,5.000000\], XXXX) = NNNN |
| 55 |
#else |
| 56 |
//staptest// alarm (5) = NNNN |
| 57 |
#endif |
| 58 |
|
| 59 |
sigemptyset(&mask); |
| 60 |
sigsuspend(&mask); |
| 61 |
//staptest// rt_sigsuspend (\[EMPTY\], 8) = NNNN |
| 62 |
|
| 63 |
alarm(0); |
| 64 |
#if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) |
| 65 |
//staptest// setitimer (ITIMER_REAL, \[0.000000,0.000000\], XXXX) = NNNN |
| 66 |
#else |
| 67 |
//staptest// alarm (0) = NNNN |
| 68 |
#endif |
| 69 |
|
| 70 |
/* Limit testing. */ |
| 71 |
sigaltstack((stack_t *)-1, NULL); |
| 72 |
#ifdef __s390__ |
| 73 |
//staptest// sigaltstack (0x[7]?[f]+, 0x0) = NNNN |
| 74 |
#else |
| 75 |
//staptest// sigaltstack (0x[f]+, 0x0) = NNNN |
| 76 |
#endif |
| 77 |
|
| 78 |
sigaltstack(NULL, (stack_t *)-1); |
| 79 |
#ifdef __s390__ |
| 80 |
//staptest// sigaltstack (0x0, 0x[7]?[f]+) = NNNN |
| 81 |
#else |
| 82 |
//staptest// sigaltstack (0x0, 0x[f]+) = NNNN |
| 83 |
#endif |
| 84 |
#endif |
| 85 |
return 0; |
| 86 |
} |