1SIGALTSTACK(2) System Calls Manual SIGALTSTACK(2)
2
3
4
6 sigaltstack - set and/or get signal stack context
7
9 #include <sys/types.h>
10 #include <signal.h>
11
12 struct sigaltstack {
13 caddr_t ss_base;
14 int ss_size;
15 int ss_flags;
16 };
17
18 int
19 sigaltstack(ss, oss)
20 struct sigaltstack *ss;
21 struct sigaltstack *oss;
22
24 Sigaltstack allows users to define an alternate stack on which signals
25 are to be processed. If ss is non-zero, it specifies a pointer to and
26 the size of a signal stack on which to deliver signals, and tells the
27 system if the process is currently executing on that stack. When a
28 signal's action indicates its handler should execute on the signal
29 stack (specified with a sigaction(2) call), the system checks to see if
30 the process is currently executing on that stack. If the process is
31 not currently executing on the signal stack, the system arranges a
32 switch to the signal stack for the duration of the signal handler's
33 execution.
34
35 If SA_DISABLE is set in ss_flags, ss_base and ss_size are ignored and
36 the signal stack will be disabled. Trying to disable an active stack
37 will cause sigaltstack to return -1 with errno set to EINVAL. A dis‐
38 abled stack will cause all signals to be taken on the regular user
39 stack. If the stack is later re-enabled then all signals that were
40 specified to be processed on an alternate stack will resume doing so.
41
42 If oss is non-zero, the current signal stack state is returned. The
43 ss_flags field will contain the value SA_ONSTACK if the process is cur‐
44 rently on a signal stack and SA_DISABLE if the signal stack is cur‐
45 rently disabled.
46
48 The value SIGSTKSZ is defined to be the number of bytes/chars that
49 would be used to cover the usual case when allocating an alternate
50 stack area. The following code fragment is typically used to allocate
51 an alternate stack.
52
53 if ((sigstk.ss_base = malloc(SIGSTKSZ)) == NULL)
54 /* error return */
55 sigstk.ss_size = SIGSTKSZ;
56 sigstk.ss_flags = 0;
57 if (sigaltstack(&sigstk,0) < 0)
58 perror("sigaltstack");
59
60 An alternative approach is provided for programs with signal handlers
61 that require a specific amount of stack space other than the default
62 size. The value MINSIGSTKSZ is defined to be the number of bytes/chars
63 that is required by the operating system to implement the alternate
64 stack feature. In computing an alternate stack size, programs should
65 add MINSIGSTKSZ to their stack requirements to allow for the operating
66 system overhead.
67
68 Signal stacks are automatically adjusted for the direction of stack
69 growth and alignment requirements. Signal stacks may or may not be
70 protected by the hardware and are not ``grown'' automatically as is
71 done for the normal stack. If the stack overflows and this space is
72 not protected unpredictable results may occur.
73
75 Upon successful completion, a value of 0 is returned. Otherwise, a
76 value of -1 is returned and errno is set to indicate the error.
77
79 Sigaltstack will fail and the signal stack context will remain
80 unchanged if one of the following occurs.
81
82 EFAULT Either ss or oss points to memory that is not a
83 valid part of the process address space.
84
85 EINVAL An attempt was made to disable an active stack.
86
87 ENOMEM Size of alternate stack area is less than or equal
88 to MINSIGSTKSZ .
89
91 sigaction(2), setjmp(3)
92
94 The predecessor to sigaltstack, the sigstack system call, appeared in
95 4.2BSD.
96
97
98
994.4 Berkeley Distribution September 3, 1997 SIGALTSTACK(2)