summaryrefslogtreecommitdiffstats
path: root/upstream/archlinux/man3p/sigaltstack.3p
blob: f9aac8f65c84856a6b47e9846f35b2aa8185b8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
'\" et
.TH SIGALTSTACK "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
sigaltstack
\(em set and get signal alternate stack context
.SH SYNOPSIS
.LP
.nf
#include <signal.h>
.P
int sigaltstack(const stack_t *restrict \fIss\fP, stack_t *restrict \fIoss\fP);
.fi
.SH DESCRIPTION
The
\fIsigaltstack\fR()
function allows a process to define and examine the state of an
alternate stack for signal handlers for the current thread. Signals
that have been explicitly declared to execute on the alternate stack
shall be delivered on the alternate stack.
.P
If
.IR ss
is not a null pointer, it points to a
.BR stack_t
structure that specifies the alternate signal stack that shall take
effect upon return from
\fIsigaltstack\fR().
The
.IR ss_flags
member specifies the new stack state. If it is set to SS_DISABLE, the
stack is disabled and
.IR ss_sp
and
.IR ss_size
are ignored. Otherwise, the stack shall be enabled, and the
.IR ss_sp
and
.IR ss_size
members specify the new address and size of the stack.
.P
The range of addresses starting at
.IR ss_sp
up to but not including
.IR ss_sp +\c
.IR ss_size
is available to the implementation for use as the stack. This function
makes no assumptions regarding which end is the stack base and in which
direction the stack grows as items are pushed.
.P
If
.IR oss
is not a null pointer, upon successful completion it shall point to a
.BR stack_t
structure that specifies the alternate signal stack that was in effect
prior to the call to
\fIsigaltstack\fR().
The
.IR ss_sp
and
.IR ss_size
members specify the address and size of that stack. The
.IR ss_flags
member specifies the stack's state, and may contain one of the
following values:
.IP SS_ONSTACK 12
The process is currently executing on the alternate signal stack.
Attempts to modify the alternate signal stack while the process is
executing on it fail. This flag shall not be modified by processes.
.IP SS_DISABLE 12
The alternate signal stack is currently disabled.
.P
The value SIGSTKSZ is a system default specifying the number of bytes
that would be used to cover the usual case when manually allocating an
alternate stack area. The value MINSIGSTKSZ is defined to be the
minimum stack size for
a signal handler. In computing an alternate stack size, a program
should add that amount to its stack requirements to allow for the
system implementation overhead. The constants SS_ONSTACK, SS_DISABLE,
SIGSTKSZ, and MINSIGSTKSZ are
defined in
.IR <signal.h> .
.P
After a successful call to one of the
.IR exec
functions, there are no alternate signal stacks in the new process
image.
.P
In some implementations, a signal (whether or not indicated to execute
on the alternate stack) shall always execute on the alternate stack if
it is delivered while another signal is being caught using the
alternate stack.
.P
Use of this function by library threads that are not bound to
kernel-scheduled entities results in undefined behavior.
.SH "RETURN VALUE"
Upon successful completion,
\fIsigaltstack\fR()
shall return 0; otherwise, it shall return \-1 and set
.IR errno
to indicate the error.
.SH ERRORS
The
\fIsigaltstack\fR()
function shall fail if:
.TP
.BR EINVAL
The
.IR ss
argument is not a null pointer, and the
.IR ss_flags
member pointed to by
.IR ss
contains flags other than SS_DISABLE.
.TP
.BR ENOMEM
The size of the alternate stack area is less than MINSIGSTKSZ.
.TP
.BR EPERM
An attempt was made to modify an active stack.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Allocating Memory for an Alternate Stack"
.P
The following example illustrates a method for allocating memory for an
alternate stack.
.sp
.RS 4
.nf

#include <signal.h>
\&...
if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
    /* Error return. */
sigstk.ss_size = SIGSTKSZ;
sigstk.ss_flags = 0;
if (sigaltstack(&sigstk,(stack_t *)0) < 0)
    perror("sigaltstack");
.fi
.P
.RE
.SH "APPLICATION USAGE"
On some implementations, stack space is automatically extended as
needed. On those implementations, automatic extension is typically not
available for an alternate stack. If the stack overflows, the
behavior is undefined.
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.4" ", " "Signal Concepts",
.IR "\fIexec\fR\^",
.IR "\fIsigaction\fR\^(\|)",
.IR "\fIsigsetjmp\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<signal.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .