1SIGALTSTACK(P) POSIX Programmer's Manual SIGALTSTACK(P)
2
3
4
6 sigaltstack - set and get signal alternate stack context
7
9 #include <signal.h>
10
11 int sigaltstack(const stack_t *restrict ss, stack_t *restrict oss);
12
13
15 The sigaltstack() function allows a process to define and examine the
16 state of an alternate stack for signal handlers for the current thread.
17 Signals that have been explicitly declared to execute on the alternate
18 stack shall be delivered on the alternate stack.
19
20 If ss is not a null pointer, it points to a stack_t structure that
21 specifies the alternate signal stack that shall take effect upon return
22 from sigaltstack(). The ss_flags member specifies the new stack state.
23 If it is set to SS_DISABLE, the stack is disabled and ss_sp and ss_size
24 are ignored. Otherwise, the stack shall be enabled, and the ss_sp and
25 ss_size members specify the new address and size of the stack.
26
27 The range of addresses starting at ss_sp up to but not including ss_sp+
28 ss_size is available to the implementation for use as the stack. This
29 function makes no assumptions regarding which end is the stack base and
30 in which direction the stack grows as items are pushed.
31
32 If oss is not a null pointer, on successful completion it shall point
33 to a stack_t structure that specifies the alternate signal stack that
34 was in effect prior to the call to sigaltstack(). The ss_sp and
35 ss_size members specify the address and size of that stack. The
36 ss_flags member specifies the stack's state, and may contain one of the
37 following values:
38
39 SS_ONSTACK
40 The process is currently executing on the alternate signal
41 stack. Attempts to modify the alternate signal stack while the
42 process is executing on it fail. This flag shall not be modified
43 by processes.
44
45 SS_DISABLE
46 The alternate signal stack is currently disabled.
47
48
49 The value SIGSTKSZ is a system default specifying the number of bytes
50 that would be used to cover the usual case when manually allocating an
51 alternate stack area. The value MINSIGSTKSZ is defined to be the mini‐
52 mum stack size for a signal handler. In computing an alternate stack
53 size, a program should add that amount to its stack requirements to
54 allow for the system implementation overhead. The constants SS_ONSTACK,
55 SS_DISABLE, SIGSTKSZ, and MINSIGSTKSZ are defined in <signal.h>.
56
57 After a successful call to one of the exec functions, there are no
58 alternate signal stacks in the new process image.
59
60 In some implementations, a signal (whether or not indicated to execute
61 on the alternate stack) shall always execute on the alternate stack if
62 it is delivered while another signal is being caught using the alter‐
63 nate stack.
64
65 Use of this function by library threads that are not bound to kernel-
66 scheduled entities results in undefined behavior.
67
69 Upon successful completion, sigaltstack() shall return 0; otherwise, it
70 shall return -1 and set errno to indicate the error.
71
73 The sigaltstack() function shall fail if:
74
75 EINVAL The ss argument is not a null pointer, and the ss_flags member
76 pointed to by ss contains flags other than SS_DISABLE.
77
78 ENOMEM The size of the alternate stack area is less than MINSIGSTKSZ.
79
80 EPERM An attempt was made to modify an active stack.
81
82
83 The following sections are informative.
84
86 Allocating Memory for an Alternate Stack
87 The following example illustrates a method for allocating memory for an
88 alternate stack.
89
90
91 #include <signal.h>
92 ...
93 if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
94 /* Error return. */
95 sigstk.ss_size = SIGSTKSZ;
96 sigstk.ss_flags = 0;
97 if (sigaltstack(&sigstk,(stack_t *)0) < 0)
98 perror("sigaltstack");
99
101 On some implementations, stack space is automatically extended as
102 needed. On those implementations, automatic extension is typically not
103 available for an alternate stack. If the stack overflows, the behavior
104 is undefined.
105
107 None.
108
110 None.
111
113 Signal Concepts , sigaction() , sigsetjmp() , the Base Definitions vol‐
114 ume of IEEE Std 1003.1-2001, <signal.h>
115
117 Portions of this text are reprinted and reproduced in electronic form
118 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
119 -- Portable Operating System Interface (POSIX), The Open Group Base
120 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
121 Electrical and Electronics Engineers, Inc and The Open Group. In the
122 event of any discrepancy between this version and the original IEEE and
123 The Open Group Standard, the original IEEE and The Open Group Standard
124 is the referee document. The original Standard can be obtained online
125 at http://www.opengroup.org/unix/online.html .
126
127
128
129IEEE/The Open Group 2003 SIGALTSTACK(P)