OSDN Git Service

f7dcda172542ec55eea79737a61fa22482357083
[linuxjm/LDP_man-pages.git] / release / man3 / pthread_attr_setguardsize.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH PTHREAD_ATTR_SETGUARDSIZE 3 2008\-10\-24 Linux "Linux Programmer's Manual"
32 .SH 名前
33 pthread_attr_setguardsize, pthread_attr_getguardsize \-
34 スレッド属性オブジェクトの guard size 属性の設定/取得を行う
35 .SH 書式
36 .nf
37 \fB#include <pthread.h>\fP
38
39 \fBint pthread_attr_setguardsize(pthread_attr_t *\fP\fIattr\fP\fB, size_t \fP\fIguardsize\fP\fB);\fP
40 \fBint pthread_attr_getguardsize(pthread_attr_t *\fP\fIattr\fP\fB, size_t *\fP\fIguardsize\fP\fB);\fP
41 .sp
42 \fI\-pthread\fP でコンパイルしてリンクする。
43 .fi
44 .SH 説明
45 \fBpthread_attr_setguardsize\fP() 関数は、
46 \fIattr\fP が参照するスレッド属性オブジェクトの guard size 属性を
47 \fIguardsize\fP で指定された値に設定する。
48
49 \fIguardsize\fP が 0 より大きい場合、
50 \fIattr\fP を使って新しく作成された各スレッドに対して、
51 システムはスレッドのスタックの末尾に少なくとも \fIguardsize\fP バイトの
52 追加領域を割り当てる。この追加領域はスタックに対するガード領域として
53 機能する (ただし「バグ」の節も参照)。
54
55 \fIguardsize\fP が 0 の場合、
56 \fIattr\fP を使って新しく作成されたスレッドはガード領域を持たない。
57
58 デフォルトの guard size はシステムのページサイズと同じである。
59
60 (\fBpthread_attr_setstack\fP(3) や \fBpthread_attr_setstackaddr\fP(3)を使って)
61 \fIattr\fP でスタックアドレス属性が設定されている場合には、呼び出し側がそ
62 のスレッドのスタックを割り当てていることを意味するので、guard size 属性
63 は無視される (すなわち、システムによるガード領域の作成は行われない)。
64 この場合、スタックオーバーフローが起こらないように対処するのはアプリ
65 ケーション側の責任となる (おそらく \fBmprotect\fP(2) を使って、割り当て
66 られたスタックの最後に手動でガード領域を定義することになるだろう)。
67
68 \fBpthread_attr_getguardsize\fP() は、
69 スレッド属性オブジェクト \fIattr\fP の guard size 属性を
70 \fIguardsize\fP が指すバッファに入れて返す。
71 .SH 返り値
72 成功すると、これらの関数は 0 を返す。
73 エラーの場合、0 以外のエラー番号を返す。
74 .SH エラー
75 POSIX.1\-2001 では、エラー \fBEINVAL\fP が
76  \fIattr\fP か \fIguardsize\fP が無効な場合に対して規定されている。
77 Linux では、これらの関数は常に成功する
78 (ただし、移植性や将来も動作することを保証したいアプリケーションでは
79 正のエラーの返り値を処理するようにすべきである)。
80 .SH バージョン
81 これらの関数は glibc バージョン 2.1 以降で提供されている。
82 .SH 準拠
83 POSIX.1\-2001.
84 .SH 注意
85 ガード領域は、読み出し/書き込みアクセスが行われないように保護がかけ
86 られた仮想メモリページで構成で構成される。スレッドがスタックをガード
87 領域までオーバーフローさせた場合、ほとんどのハードウェアアーキテクチャ
88 では、スレッドに \fBSIGSEGV\fP シグナルが送られ、オーバーフローが発生した
89 ことが通知される。ガード領域はページ境界から開始され、ガード領域の
90 大きさはスレッド作成時に内部的にシステムのページサイズに切り上げられる
91 (その場合も \fBpthread_attr_getguardsize\fP() では
92 \fBpthread_attr_setguardsize\fP() で設定された guard size が返される)。
93
94 多くのスレッドを作成するアプリケーションで、かつ、スタックオーバーフロー
95 が決して発生しないことが分かっている場合には、guard size を 0 に設定
96 することで、メモリを節約できることもある。
97
98 スレッドがスタックに大きなデータ構造を割り当てる場合には、
99 スタックオーバーフローを検出するためには、デフォルトサイズよりも
100 大きな guard size を選ぶ必要があるかもしれない。
101 .SH バグ
102 glibc 2.8 の時点では、 NPTL スレッド実装ではガード領域はスタックサイズ
103 で割り当てられる領域の中に含まれている。一方、POSIX.1 では、スタックの
104 末尾に追加の領域を割り当てることが求められている。
105 (このため、ガード領域が大きすぎて、
106 実際のスタック用の場所がなくなってしまう場合、
107 \fBpthread_create\fP(3) で \fBEINVAL\fP エラーが発生することになる。)
108
109 .\" glibc includes the guardsize within the allocated stack size,
110 .\" which looks pretty clearly to be in violation of POSIX.
111 .\"
112 .\" Filed bug, 22 Oct 2008:
113 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6973
114 .\"
115 .\" Older reports:
116 .\" https//bugzilla.redhat.com/show_bug.cgi?id=435337
117 .\" Reportedly, LinuxThreads did the right thing, allocating
118 .\" extra space at the end of the stack:
119 .\" http://sourceware.org/ml/libc-alpha/2008-05/msg00086.html
120 廃止予定の LinuxThreads 実装では、
121 POSIX.1 で求められている通りの動作で、
122 ガード領域がスタックの末尾に追加の領域が割り当てられる。
123 .SH 例
124 \fBpthread_getattr_np\fP(3) を参照。
125 .SH 関連項目
126 \fBmmap\fP(2), \fBmprotect\fP(2), \fBpthread_attr_init\fP(3),
127 \fBpthread_attr_setstack\fP(3), \fBpthread_attr_setstacksize\fP(3),
128 \fBpthread_create\fP(3), \fBpthreads\fP(7)
129 .SH この文書について
130 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
131 である。プロジェクトの説明とバグ報告に関する情報は
132 http://www.kernel.org/doc/man\-pages/ に書かれている。