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