OSDN Git Service

404dc5469149eb9cd9ffd6d4b4ea9f8080f32082
[linuxjm/LDP_man-pages.git] / draft / man2 / sigaltstack.2
1 '\" t
2 .\" Copyright (c) 2001, Michael Kerrisk (mtk.manpages@gmail.com)
3 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" aeb, various minor fixes
25 .\"
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
32 .\"
33 .\"WORD:        alternate signal stack  代替シグナルスタック
34 .\"WORD:        establish       (スタックの) 確立
35 .\"
36 .TH SIGALTSTACK 2 2010-09-26 "Linux" "Linux Programmer's Manual"
37 .\"O .SH NAME
38 .SH 名前
39 .\"O sigaltstack \- set and/or get signal stack context
40 sigaltstack \- シグナルスタックのコンテキストを設定・取得する
41 .\"O .SH SYNOPSIS
42 .SH 書式
43 .B #include <signal.h>
44 .sp
45 .BI "int sigaltstack(const stack_t *" ss ", stack_t *" oss );
46 .sp
47 .in -4n
48 .\"O Feature Test Macro Requirements for glibc (see
49 .\"O .BR feature_test_macros (7)):
50 glibc 向けの機能検査マクロの要件
51 .RB ( feature_test_macros (7)
52 参照):
53 .in
54 .sp
55 .BR sigaltstack ():
56 .ad l
57 .RS 4
58 .PD 0
59 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
60 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
61 .br
62 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
63 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
64 .PD
65 .RE
66 .ad
67 .\"O .SH DESCRIPTION
68 .SH 説明
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))
76 .\"O requested it.
77 .BR sigaltstack ()
78 を使うと、
79 プロセスは新しい代替シグナルスタックを定義したり、
80 既存の代替シグナルスタックの状態を取得できる。
81 シグナルハンドラが代替シグナルスタックを要求するように設定されていると
82 .RB ( sigaction (2)
83 参照)、ハンドラの実行中はそのシグナルスタックが使われる。
84
85 .\"O The normal sequence of events for using an alternate signal stack
86 .\"O is the following:
87 代替シグナルスタックを使う際の一般的な手順は、以下の通りである:
88 .TP 3
89 1.
90 .\"O Allocate an area of memory to be used for the alternate
91 .\"O signal stack.
92 代替シグナルスタックで使うメモリ領域を確保する。
93 .TP
94 2.
95 .\"O Use
96 .\"O .BR sigaltstack ()
97 .\"O to inform the system of the existence and
98 .\"O location of the alternate signal stack.
99 .BR sigaltstack ()
100 を使って、
101 代替シグナルスタックの存在と場所をシステムに知らせる。
102 .TP
103 3.
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.
109 .BR sigaction (2)
110 を使ってシグナルハンドラを確立する際、
111 \fBSA_ONSTACK\fP フラグを指定することにより、
112 そのシグナルハンドラを代替シグナルスタック上で実行することを
113 システムに知らせる。
114 .P
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 引き数となる構造体は、以下のような型である:
128 .sp
129 .in +4n
130 .nf
131 typedef struct {
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;   /* スタックのバイト数 */
138 } stack_t;
139 .fi
140 .in
141
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
145 .\"O the stack.
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 は、代替シグナルスタックが通常必要する
155 サイズよりも充分大きく定義されている。
156 また定数 \fBMINSIGSTKSZ\fP は、
157 シグナルハンドラの実行に必要な最小サイズに定義されている。
158
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 動作しているハードウェアアーキテクチャに適したアドレス境界に
165 調整される。
166
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.
171 既存のスタックを無効にするには、
172 \fIss.ss_flags\fP を \fBSS_DISABLE\fP に指定する。
173 この場合、\fIss\fP の他のフィールドは無視される。
174
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
177 .\"O call to
178 .\"O .BR sigaltstack ().
179 \fIoss\fP が NULL 以外の場合、
180 \fIoss\fP に代替シグナルスタックの情報が返される。
181 これは (実質的に)
182 .BR sigaltstack ()
183 の呼び出しより先に行われる。
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 には以下のどちらかの値が返される:
190 .TP
191 .B SS_ONSTACK
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 それと同じシグナルスタックには変更できない点に注意すること)。
199 .TP
200 .B SS_DISABLE
201 .\"O The alternate signal stack is currently disabled.
202 代替シグナルスタックが現在無効になっている。
203 .\"O .SH "RETURN VALUE"
204 .SH 返り値
205 .\"O .BR sigaltstack ()
206 .\"O returns 0 on success, or \-1 on failure with
207 .\"O \fIerrno\fP set to indicate the error.
208 .BR sigaltstack ()
209 は成功した場合 0 を返す。
210 失敗した場合は \-1 を返して、
211 エラーを示す値に \fIerrno\fP を設定する。
212 .\"O .SH ERRORS
213 .SH エラー
214 .TP
215 .B EFAULT
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 かつプロセスのアドレス空間の外を指している。
220 .TP
221 .B EINVAL
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 フィールドが
226 .B SS_DISABLE
227 以外の 0 でない値になっている。
228 .TP
229 .B ENOMEM
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 より小さい。
234 .TP
235 .B EPERM
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"
242 .SH 準拠
243 SUSv2, SVr4, POSIX.1-2001.
244 .\"O .SH NOTES
245 .SH 注意
246 .\"O The most common usage of an alternate signal stack is to handle the
247 .\"O .B SIGSEGV
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
250 .\"O .B SIGSEGV
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 代替シグナルスタックを使用する最もよくある場面は、
254 .B SIGSEGV
255 シグナルを扱うときである。
256 .B SIGSEGV
257 はプロセスの通常のスタックが利用できる空間が使い果たされた際に
258 生成されるシグナルである。この場合には、
259 .B SIGSEGV
260 用のシグナルハンドラをプロセスのスタック上では起動することができない。
261 そのため、このシグナルを扱おうとする場合には、
262 代替シグナルスタックを使用しなければならない。
263 .P
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.
271 例えば、スタックが最上位アドレスから
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.
280 標準のスタックを使い果たしてしまうと、
281 カーネルはプロセスに \fBSIGSEGV\fP シグナルを送る。
282 このような状況では、代替シグナルスタック上でしかシグナルをキャッチできない。
283 .P
284 .\"O On most hardware architectures supported by Linux, stacks grow
285 .\"O downward.
286 .\"O .BR sigaltstack ()
287 .\"O automatically takes account
288 .\"O of the direction of stack growth.
289 Linux がサポートする多くのハードウェアアーキテクチャでは、
290 スタックは下位アドレス方向に積まれる。
291 .BR sigaltstack ()
292 はスタックが積まれる方向を自動的に決定する。
293 .P
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.
302 代替シグナルスタック上で実行されている
303 シグナルハンドラから呼ばれる関数も、代替シグナルハンドラを使う
304 (プロセスが代替シグナルスタック上で実行されている場合、
305 他のシグナルで呼び出されるハンドラもこの代替シグナルハンドラを使う)。
306 標準のスタックとは異なり、
307 システムは代替シグナルスタックを自動的に拡張しない。
308 代替シグナルスタック用に確保したサイズを越えた場合、
309 結果は予想できない。
310 .P
311 .\"O A successful call to
312 .\"O .BR execve (2)
313 .\"O removes any existing alternate
314 .\"O signal stack.
315 .\"O A child process created via
316 .\"O .BR fork (2)
317 .\"O inherits a copy of its parent's alternate signal stack settings.
318 .BR execve (2)
319 の呼び出しが成功すると、
320 既存の全ての代替シグナルスタックが削除される。
321 .BR fork (2)
322 経由で作成された子プロセスは、親プロセスの代替シグナルスタックの
323 設定のコピーを継承する。
324 .P
325 .\"O .BR sigaltstack ()
326 .\"O supersedes the older
327 .\"O .BR sigstack ()
328 .\"O call.
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 ().
333 .BR sigaltstack ()
334 は以前の
335 .BR sigstack ()
336 を置き換えるものである。
337 過去プログラムとの互換性のため、glibc では
338 .BR sigstack ()
339 も提供している。
340 新しいのアプリケーションは全て
341 .BR sigaltstack ()
342 を使って書くべきである。
343 .\"O .SS History
344 .SS 歴史
345 .\"O 4.2BSD had a
346 .\"O .BR sigstack ()
347 .\"O system call.
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.
351 4.2BSD には
352 .BR sigstack ()
353 システムコールがあった。
354 この関数は少し異なった構造体を使っており、
355 呼び出した側がスタックの積まれる方向を知っていなければならないという
356 大きな欠点があった。
357 .\"O .SH EXAMPLE
358 .SH 例
359 .\"O The following code segment demonstrates the use of
360 .\"O .BR sigaltstack ():
361 以下のコードで
362 .BR sigaltstack ()
363 の使用法の一部を示す:
364
365 .in +4n
366 .nf
367 stack_t ss;
368
369 ss.ss_sp = malloc(SIGSTKSZ);
370 if (ss.ss_sp == NULL)
371 .\"O     /* Handle error */;
372     /* ハンドルエラー */;
373 ss.ss_size = SIGSTKSZ;
374 ss.ss_flags = 0;
375 if (sigaltstack(&ss, NULL) == \-1)
376 .\"O     /* Handle error */;
377     /* ハンドルエラー */;
378 .fi
379 .in
380 .\"O .SH "SEE ALSO"
381 .SH 関連項目
382 .BR execve (2),
383 .BR setrlimit (2),
384 .BR sigaction (2),
385 .BR siglongjmp (3),
386 .BR sigsetjmp (3),
387 .BR signal (7)