2 .\" Copyright (c) 2001, Michael Kerrisk (mtk.manpages@gmail.com)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" aeb, various minor fixes
26 .\" Japanese Version Copyright (c) 2001 Yuichi SATO
27 .\" all rights reserved.
28 .\" Translated 2001-11-04, Yuichi SATO <ysato@h4.dion.ne.jp>
29 .\" Updated 2001-12-09, Yuichi SATO
30 .\" Updated 2005-11-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
31 .\" Updated 2006-01-04, Akihiro MOTOKI, Catch up to LDP 2.20
33 .\"WORD: alternate signal stack 代替シグナルスタック
34 .\"WORD: establish (スタックの) 確立
36 .TH SIGALTSTACK 2 2010-09-26 "Linux" "Linux Programmer's Manual"
39 .\"O sigaltstack \- set and/or get signal stack context
40 sigaltstack \- シグナルスタックのコンテキストを設定・取得する
43 .B #include <signal.h>
45 .BI "int sigaltstack(const stack_t *" ss ", stack_t *" oss );
48 .\"O Feature Test Macro Requirements for glibc (see
49 .\"O .BR feature_test_macros (7)):
51 .RB ( feature_test_macros (7)
59 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
60 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
62 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
63 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
69 .\"O .BR sigaltstack ()
70 .\"O allows a process to define a new alternate
71 .\"O signal stack and/or retrieve the state of an existing
72 .\"O alternate signal stack.
73 .\"O An alternate signal stack is used during the
74 .\"O execution of a signal handler if the establishment of that handler (see
75 .\"O .BR sigaction (2))
79 プロセスは新しい代替シグナルスタックを定義したり、
80 既存の代替シグナルスタックの状態を取得できる。
81 シグナルハンドラが代替シグナルスタックを要求するように設定されていると
83 参照)、ハンドラの実行中はそのシグナルスタックが使われる。
85 .\"O The normal sequence of events for using an alternate signal stack
86 .\"O is the following:
87 代替シグナルスタックを使う際の一般的な手順は、以下の通りである:
90 .\"O Allocate an area of memory to be used for the alternate
92 代替シグナルスタックで使うメモリ領域を確保する。
96 .\"O .BR sigaltstack ()
97 .\"O to inform the system of the existence and
98 .\"O location of the alternate signal stack.
101 代替シグナルスタックの存在と場所をシステムに知らせる。
104 .\"O When establishing a signal handler using
105 .\"O .BR sigaction (2),
106 .\"O inform the system that the signal handler should be executed
107 .\"O on the alternate signal stack by
108 .\"O specifying the \fBSA_ONSTACK\fP flag.
111 \fBSA_ONSTACK\fP フラグを指定することにより、
112 そのシグナルハンドラを代替シグナルスタック上で実行することを
115 .\"O The \fIss\fP argument is used to specify a new
116 .\"O alternate signal stack, while the \fIoss\fP argument
117 .\"O is used to retrieve information about the currently
118 .\"O established signal stack.
119 \fIss\fP 引き数は、新しいシグナルスタックを指定するために使う。
120 また \fIoss\fP 引き数は、現在確立されている
121 シグナルスタックの情報を取得するために使う。
122 .\"O If we are interested in performing just one
123 .\"O of these tasks then the other argument can be specified as NULL.
124 .\"O Each of these arguments is a structure of the following type:
125 この操作のうち 1 つだけを実行させるには、
126 使用しない引き数を NULL に指定すればよい。
127 引き数となる構造体は、以下のような型である:
132 .\"O void *ss_sp; /* Base address of stack */
133 void *ss_sp; /* スタックのベースアドレス */
134 .\"O int ss_flags; /* Flags */
135 int ss_flags; /* フラグ */
136 .\"O size_t ss_size; /* Number of bytes in stack */
137 size_t ss_size; /* スタックのバイト数 */
142 .\"O To establish a new alternate signal stack,
143 .\"O \fIss.ss_flags\fP is set to zero, and \fIss.ss_sp\fP and
144 .\"O \fIss.ss_size\fP specify the starting address and size of
146 新規の代替シグナルスタックを確立するには、
147 \fIss.ss_flags\fP を 0 に設定し、
148 \fIss.ss_sp\fP と \fIss.ss_size\fP に
149 スタックの開始アドレスとスタックサイズを指定する。
150 .\"O The constant \fBSIGSTKSZ\fP is defined to be large enough
151 .\"O to cover the usual size requirements for an alternate signal stack,
152 .\"O and the constant \fBMINSIGSTKSZ\fP defines the minimum
153 .\"O size required to execute a signal handler.
154 定数 \fBSIGSTKSZ\fP は、代替シグナルスタックが通常必要する
156 また定数 \fBMINSIGSTKSZ\fP は、
157 シグナルハンドラの実行に必要な最小サイズに定義されている。
159 .\"O When a signal handler is invoked on the alternate stack,
160 .\"O the kernel automatically aligns the address given in \fIss.ss_sp\fP
161 .\"O to a suitable address boundary for the underlying hardware architecture.
162 代替スタックでシグナルハンドラが起動された場合には、
163 カーネルにより自動的に、\fIss.ss_sp\fP で指定されたアドレスは
164 動作しているハードウェアアーキテクチャに適したアドレス境界に
167 .\"O To disable an existing stack, specify \fIss.ss_flags\fP
168 .\"O as \fBSS_DISABLE\fP.
169 .\"O In this case, the remaining fields
170 .\"O in \fIss\fP are ignored.
172 \fIss.ss_flags\fP を \fBSS_DISABLE\fP に指定する。
173 この場合、\fIss\fP の他のフィールドは無視される。
175 .\"O If \fIoss\fP is not NULL, then it is used to return information about
176 .\"O the alternate signal stack which was in effect prior to the
178 .\"O .BR sigaltstack ().
179 \fIoss\fP が NULL 以外の場合、
180 \fIoss\fP に代替シグナルスタックの情報が返される。
184 .\"O The \fIoss.ss_sp\fP and \fIoss.ss_size\fP fields return the starting
185 .\"O address and size of that stack.
186 .\"O The \fIoss.ss_flags\fP may return either of the following values:
187 \fIoss.ss_sp\fP と \fIoss.ss_size\fP フィールドに
188 スタックの開始アドレスとスタックサイズが返される。
189 \fIoss.ss_flags\fP には以下のどちらかの値が返される:
192 .\"O The process is currently executing on the alternate signal stack.
193 .\"O (Note that it is not possible
194 .\"O to change the alternate signal stack if the process is
195 .\"O currently executing on it.)
196 プロセスが代替シグナルスタック上で実行されている
197 (プロセスが既にそのシグナルスタック上で実行されている場合は、
198 それと同じシグナルスタックには変更できない点に注意すること)。
201 .\"O The alternate signal stack is currently disabled.
202 代替シグナルスタックが現在無効になっている。
203 .\"O .SH "RETURN VALUE"
205 .\"O .BR sigaltstack ()
206 .\"O returns 0 on success, or \-1 on failure with
207 .\"O \fIerrno\fP set to indicate the error.
211 エラーを示す値に \fIerrno\fP を設定する。
216 .\"O Either \fIss\fP or \fIoss\fP is not NULL and points to an area
217 .\"O outside of the process's address space.
218 \fIss\fP または \fIoss\fP のどちらが、NULL 以外で、
219 かつプロセスのアドレス空間の外を指している。
222 .\"O \fIss\fP is not NULL and the \fIss_flags\fP field contains
223 .\"O a nonzero value other than
224 .\"O .BR SS_DISABLE .
225 \fIss\fP が NULL 以外で、\fIss_flags\fP フィールドが
230 .\"O The specified size of the new alternate signal stack
231 .\"O (\fIss.ss_size\fP) was less than \fBMINSTKSZ\fP.
232 新しい代替シグナルスタック (\fIss.ss_size\fP) に指定したサイズが
233 \fBMINSTKSZ\fP より小さい。
236 .\"O An attempt was made to change the alternate signal stack while
237 .\"O it was active (i.e., the process was already executing
238 .\"O on the current alternate signal stack).
239 代替シグナルスタックが有効であるときに変更を行おうとした
240 (つまり、プロセスが既に現在の代替シグナルスタック上で実行されていた)。
241 .\"O .SH "CONFORMING TO"
243 SUSv2, SVr4, POSIX.1-2001.
246 .\"O The most common usage of an alternate signal stack is to handle the
248 .\"O signal that is generated if the space available for the
249 .\"O normal process stack is exhausted: in this case, a signal handler for
251 .\"O cannot be invoked on the process stack; if we wish to handle it,
252 .\"O we must use an alternate signal stack.
253 代替シグナルスタックを使用する最もよくある場面は、
257 はプロセスの通常のスタックが利用できる空間が使い果たされた際に
260 用のシグナルハンドラをプロセスのスタック上では起動することができない。
261 そのため、このシグナルを扱おうとする場合には、
262 代替シグナルスタックを使用しなければならない。
264 .\"O Establishing an alternate signal stack is useful if a process
265 .\"O expects that it may exhaust its standard stack.
266 プロセスが標準のシグナルスタックを使い果たすことが予想される場合は、
267 代替シグナルスタックを確立すると便利である。
268 .\"O This may occur, for example, because the stack grows so large
269 .\"O that it encounters the upwardly growing heap, or it reaches a
270 .\"O limit established by a call to \fBsetrlimit(RLIMIT_STACK, &rlim)\fP.
272 下位アドレス方向に非常にたくさん積まれてしまうことで、
273 最下位アドレスから上位アドレス方向に積まれるヒープとぶつかってしまう場合や、
274 \fBsetrlimit(RLIMIT_STACK, &rlim)\fP の呼び出しで確立された
275 制限に達してしまった場合に、この様な事が起こる。
276 .\"O If the standard stack is exhausted, the kernel sends
277 .\"O the process a \fBSIGSEGV\fP signal.
278 .\"O In these circumstances the only way to catch this signal is
279 .\"O on an alternate signal stack.
281 カーネルはプロセスに \fBSIGSEGV\fP シグナルを送る。
282 このような状況では、代替シグナルスタック上でしかシグナルをキャッチできない。
284 .\"O On most hardware architectures supported by Linux, stacks grow
286 .\"O .BR sigaltstack ()
287 .\"O automatically takes account
288 .\"O of the direction of stack growth.
289 Linux がサポートする多くのハードウェアアーキテクチャでは、
292 はスタックが積まれる方向を自動的に決定する。
294 .\"O Functions called from a signal handler executing on an alternate
295 .\"O signal stack will also use the alternate signal stack.
296 .\"O (This also applies to any handlers invoked for other signals while
297 .\"O the process is executing on the alternate signal stack.)
298 .\"O Unlike the standard stack, the system does not
299 .\"O automatically extend the alternate signal stack.
300 .\"O Exceeding the allocated size of the alternate signal stack will
301 .\"O lead to unpredictable results.
303 シグナルハンドラから呼ばれる関数も、代替シグナルハンドラを使う
304 (プロセスが代替シグナルスタック上で実行されている場合、
305 他のシグナルで呼び出されるハンドラもこの代替シグナルハンドラを使う)。
307 システムは代替シグナルスタックを自動的に拡張しない。
308 代替シグナルスタック用に確保したサイズを越えた場合、
311 .\"O A successful call to
313 .\"O removes any existing alternate
315 .\"O A child process created via
317 .\"O inherits a copy of its parent's alternate signal stack settings.
320 既存の全ての代替シグナルスタックが削除される。
322 経由で作成された子プロセスは、親プロセスの代替シグナルスタックの
325 .\"O .BR sigaltstack ()
326 .\"O supersedes the older
329 .\"O For backward compatibility, glibc also provides
330 .\"O .BR sigstack ().
331 .\"O All new applications should be written using
332 .\"O .BR sigaltstack ().
337 過去プログラムとの互換性のため、glibc では
348 .\"O It used a slightly
349 .\"O different struct, and had the major disadvantage that the caller
350 .\"O had to know the direction of stack growth.
354 この関数は少し異なった構造体を使っており、
355 呼び出した側がスタックの積まれる方向を知っていなければならないという
359 .\"O The following code segment demonstrates the use of
360 .\"O .BR sigaltstack ():
369 ss.ss_sp = malloc(SIGSTKSZ);
370 if (ss.ss_sp == NULL)
371 .\"O /* Handle error */;
373 ss.ss_size = SIGSTKSZ;
375 if (sigaltstack(&ss, NULL) == \-1)
376 .\"O /* Handle error */;