.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2012-05-03, Akihiro MOTOKI .\" .TH PTHREAD_ATTR_SETGUARDSIZE 3 2020\-06\-09 Linux "Linux Programmer's Manual" .SH 名前 pthread_attr_setguardsize, pthread_attr_getguardsize \- スレッド属性オブジェクトの guard size 属性の設定/取得を行う .SH 書式 .nf \fB#include \fP .PP \fBint pthread_attr_setguardsize(pthread_attr_t *\fP\fIattr\fP\fB, size_t \fP\fIguardsize\fP\fB);\fP \fBint pthread_attr_getguardsize(const pthread_attr_t *\fP\fIattr\fP\fB,\fP \fB size_t *\fP\fIguardsize\fP\fB);\fP .PP \fI\-pthread\fP でコンパイルしてリンクする。 .fi .SH 説明 \fBpthread_attr_setguardsize\fP() 関数は、 \fIattr\fP が参照するスレッド属性オブジェクトの guard size 属性を \fIguardsize\fP で指定された値に設定する。 .PP \fIguardsize\fP が 0 より大きい場合、 \fIattr\fP を使って新しく作成された各スレッドに対して、 システムはスレッドのスタックの末尾に少なくとも \fIguardsize\fP バイトの 追加領域を割り当てる。この追加領域はスタックに対するガード領域として 機能する (ただし「バグ」の節も参照)。 .PP \fIguardsize\fP が 0 の場合、 \fIattr\fP を使って新しく作成されたスレッドはガード領域を持たない。 .PP デフォルトの guard size はシステムのページサイズと同じである。 .PP (\fBpthread_attr_setstack\fP(3) や \fBpthread_attr_setstackaddr\fP(3)を使って) \fIattr\fP でスタックアドレス属性が設定されている場合には、呼び出し側がそ のスレッドのスタックを割り当てていることを意味するので、guard size 属性 は無視される (すなわち、システムによるガード領域の作成は行われない)。 この場合、スタックオーバーフローが起こらないように対処するのはアプリ ケーション側の責任となる (おそらく \fBmprotect\fP(2) を使って、割り当て られたスタックの最後に手動でガード領域を定義することになるだろう)。 .PP \fBpthread_attr_getguardsize\fP() は、 スレッド属性オブジェクト \fIattr\fP の guard size 属性を \fIguardsize\fP が指すバッファーに入れて返す。 .SH 返り値 成功すると、これらの関数は 0 を返す。 エラーの場合、0 以外のエラー番号を返す。 .SH エラー POSIX.1 では、エラー \fBEINVAL\fP が \fIattr\fP か \fIguardsize\fP が無効な場合に対して規定されている。 Linux では、これらの関数は常に成功する (ただし、移植性や将来も動作することを保証したいアプリケーションでは 正のエラーの返り値を処理するようにすべきである)。 .SH バージョン これらの関数は glibc バージョン 2.1 以降で提供されている。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw28 lb lb l l l. インターフェース 属性 値 T{ \fBpthread_attr_setguardsize\fP(), \fBpthread_attr_getguardsize\fP() T} Thread safety MT\-Safe .TE .SH 準拠 POSIX.1\-2001, POSIX.1\-2008. .SH 注意 ガード領域は、読み出し/書き込みアクセスが行われないように保護がかけ られた仮想メモリーページで構成で構成される。スレッドがスタックをガード 領域までオーバーフローさせた場合、ほとんどのハードウェアアーキテクチャー では、スレッドに \fBSIGSEGV\fP シグナルが送られ、オーバーフローが発生した ことが通知される。ガード領域はページ境界から開始され、ガード領域の 大きさはスレッド作成時に内部的にシステムのページサイズに切り上げられる (その場合も \fBpthread_attr_getguardsize\fP() では \fBpthread_attr_setguardsize\fP() で設定された guard size が返される)。 .PP 多くのスレッドを作成するアプリケーションで、かつ、スタックオーバーフロー が決して発生しないことが分かっている場合には、guard size を 0 に設定 することで、メモリーを節約できることもある。 .PP スレッドがスタックに大きなデータ構造を割り当てる場合には、 スタックオーバーフローを検出するためには、デフォルトサイズよりも 大きな guard size を選ぶ必要があるかもしれない。 .SH バグ glibc 2.8 の時点では、 NPTL スレッド実装ではガード領域はスタックサイズ で割り当てられる領域の中に含まれている。一方、POSIX.1 では、スタックの 末尾に追加の領域を割り当てることが求められている。 (このため、ガード領域が大きすぎて、 実際のスタック用の場所がなくなってしまう場合、 \fBpthread_create\fP(3) で \fBEINVAL\fP エラーが発生することになる。) .PP .\" glibc includes the guardsize within the allocated stack size, .\" which looks pretty clearly to be in violation of POSIX. .\" .\" Filed bug, 22 Oct 2008: .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6973 .\" .\" Older reports: .\" https//bugzilla.redhat.com/show_bug.cgi?id=435337 .\" Reportedly, LinuxThreads did the right thing, allocating .\" extra space at the end of the stack: .\" http://sourceware.org/ml/libc-alpha/2008-05/msg00086.html 廃止予定の LinuxThreads 実装では、 POSIX.1 で求められている通りの動作で、 ガード領域がスタックの末尾に追加の領域が割り当てられる。 .SH 例 \fBpthread_getattr_np\fP(3) を参照。 .SH 関連項目 \fBmmap\fP(2), \fBmprotect\fP(2), \fBpthread_attr_init\fP(3), \fBpthread_attr_setstack\fP(3), \fBpthread_attr_setstacksize\fP(3), \fBpthread_create\fP(3), \fBpthreads\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。