OSDN Git Service

Update README
[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 .\"
32 .\" Japanese Version Copyright (c) 2012  Akihiro MOTOKI
33 .\"         all rights reserved.
34 .\" Translated 2012-05-03, Akihiro MOTOKI <amotoki@gmail.com>
35 .\"
36 .TH PTHREAD_ATTR_SETGUARDSIZE 3 2014\-05\-28 Linux "Linux Programmer's Manual"
37 .SH 名前
38 pthread_attr_setguardsize, pthread_attr_getguardsize \-
39 スレッド属性オブジェクトの guard size 属性の設定/取得を行う
40 .SH 書式
41 .nf
42 \fB#include <pthread.h>\fP
43
44 \fBint pthread_attr_setguardsize(pthread_attr_t *\fP\fIattr\fP\fB, size_t \fP\fIguardsize\fP\fB);\fP
45 \fBint pthread_attr_getguardsize(const pthread_attr_t *\fP\fIattr\fP\fB, size_t *\fP\fIguardsize\fP\fB);\fP
46 .sp
47 \fI\-pthread\fP でコンパイルしてリンクする。
48 .fi
49 .SH 説明
50 \fBpthread_attr_setguardsize\fP() 関数は、
51 \fIattr\fP が参照するスレッド属性オブジェクトの guard size 属性を
52 \fIguardsize\fP で指定された値に設定する。
53
54 \fIguardsize\fP が 0 より大きい場合、
55 \fIattr\fP を使って新しく作成された各スレッドに対して、
56 システムはスレッドのスタックの末尾に少なくとも \fIguardsize\fP バイトの
57 追加領域を割り当てる。この追加領域はスタックに対するガード領域として
58 機能する (ただし「バグ」の節も参照)。
59
60 \fIguardsize\fP が 0 の場合、
61 \fIattr\fP を使って新しく作成されたスレッドはガード領域を持たない。
62
63 デフォルトの guard size はシステムのページサイズと同じである。
64
65 (\fBpthread_attr_setstack\fP(3) や \fBpthread_attr_setstackaddr\fP(3)を使って)
66 \fIattr\fP でスタックアドレス属性が設定されている場合には、呼び出し側がそ
67 のスレッドのスタックを割り当てていることを意味するので、guard size 属性
68 は無視される (すなわち、システムによるガード領域の作成は行われない)。
69 この場合、スタックオーバーフローが起こらないように対処するのはアプリ
70 ケーション側の責任となる (おそらく \fBmprotect\fP(2) を使って、割り当て
71 られたスタックの最後に手動でガード領域を定義することになるだろう)。
72
73 \fBpthread_attr_getguardsize\fP() は、
74 スレッド属性オブジェクト \fIattr\fP の guard size 属性を
75 \fIguardsize\fP が指すバッファーに入れて返す。
76 .SH 返り値
77 成功すると、これらの関数は 0 を返す。
78 エラーの場合、0 以外のエラー番号を返す。
79 .SH エラー
80 POSIX.1\-2001 では、エラー \fBEINVAL\fP が
81  \fIattr\fP か \fIguardsize\fP が無効な場合に対して規定されている。
82 Linux では、これらの関数は常に成功する
83 (ただし、移植性や将来も動作することを保証したいアプリケーションでは
84 正のエラーの返り値を処理するようにすべきである)。
85 .SH バージョン
86 これらの関数は glibc バージョン 2.1 以降で提供されている。
87 .SH 属性
88 .SS "マルチスレッディング (pthreads(7) 参照)"
89 関数 \fBpthread_attr_setguardsize\fP() と \fBpthread_attr_getguardsize\fP()
90 はスレッドセーフである。
91 .SH 準拠
92 POSIX.1\-2001.
93 .SH 注意
94 ガード領域は、読み出し/書き込みアクセスが行われないように保護がかけ
95 られた仮想メモリーページで構成で構成される。スレッドがスタックをガード
96 領域までオーバーフローさせた場合、ほとんどのハードウェアアーキテクチャー
97 では、スレッドに \fBSIGSEGV\fP シグナルが送られ、オーバーフローが発生した
98 ことが通知される。ガード領域はページ境界から開始され、ガード領域の
99 大きさはスレッド作成時に内部的にシステムのページサイズに切り上げられる
100 (その場合も \fBpthread_attr_getguardsize\fP() では
101 \fBpthread_attr_setguardsize\fP() で設定された guard size が返される)。
102
103 多くのスレッドを作成するアプリケーションで、かつ、スタックオーバーフロー
104 が決して発生しないことが分かっている場合には、guard size を 0 に設定
105 することで、メモリーを節約できることもある。
106
107 スレッドがスタックに大きなデータ構造を割り当てる場合には、
108 スタックオーバーフローを検出するためには、デフォルトサイズよりも
109 大きな guard size を選ぶ必要があるかもしれない。
110 .SH バグ
111 glibc 2.8 の時点では、 NPTL スレッド実装ではガード領域はスタックサイズ
112 で割り当てられる領域の中に含まれている。一方、POSIX.1 では、スタックの
113 末尾に追加の領域を割り当てることが求められている。
114 (このため、ガード領域が大きすぎて、
115 実際のスタック用の場所がなくなってしまう場合、
116 \fBpthread_create\fP(3) で \fBEINVAL\fP エラーが発生することになる。)
117
118 .\" glibc includes the guardsize within the allocated stack size,
119 .\" which looks pretty clearly to be in violation of POSIX.
120 .\"
121 .\" Filed bug, 22 Oct 2008:
122 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6973
123 .\"
124 .\" Older reports:
125 .\" https//bugzilla.redhat.com/show_bug.cgi?id=435337
126 .\" Reportedly, LinuxThreads did the right thing, allocating
127 .\" extra space at the end of the stack:
128 .\" http://sourceware.org/ml/libc-alpha/2008-05/msg00086.html
129 廃止予定の LinuxThreads 実装では、
130 POSIX.1 で求められている通りの動作で、
131 ガード領域がスタックの末尾に追加の領域が割り当てられる。
132 .SH 例
133 \fBpthread_getattr_np\fP(3) を参照。
134 .SH 関連項目
135 \fBmmap\fP(2), \fBmprotect\fP(2), \fBpthread_attr_init\fP(3),
136 \fBpthread_attr_setstack\fP(3), \fBpthread_attr_setstacksize\fP(3),
137 \fBpthread_create\fP(3), \fBpthreads\fP(7)
138 .SH この文書について
139 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
140 である。プロジェクトの説明とバグ報告に関する情報は
141 http://www.kernel.org/doc/man\-pages/ に書かれている。