Provided by: manpages-ja-dev_0.5.0.0.20131015+dfsg-2_all 

名前
prctl - プロセスの操作を行なう
書式
#include <sys/prctl.h>
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
説明
prctl() の動作は最初の引き数によって決定される (この値は <linux/prctl.h> に定義されている)。 残りの引き
数は最初の引き数によって変化する。 一番目の引き数として以下のものを指定できる:
PR_CAPBSET_READ (Linux 2.6.25 以降)
で指定されたケーパビリティが呼び出したスレッドのケーパビリティ バインディングセット (capability
bounding set) に含まれている場合、 (関数の返り値として) 1 を返し、そうでない場合 0 を返す (ケーパ
ビリティ定数は <linux/capability.h> で定義されている)。 ケーパビリティバウンディングセットは、
execve(2) を呼び出した際に、ファイルの許可 (permitted) ケーパビリティの中で そのプロセスが獲得でき
るケーパビリティを指示するものである。
arg2 に指定されたケーパビリティが有効でない場合、 呼び出しはエラー EINVAL で失敗する。
PR_CAPBSET_DROP (Linux 2.6.25 以降)
呼び出したスレッドがケーパビリティ CAP_SETPCAP を持っている場合、 呼び出したスレッドのケーパビリ
ティバウンディングセットから arg2 で指定されたケーパビリティを外す。 呼び出したスレッドの子プロセ
スは変更後のバウンディングセットを 継承する。
呼び出したスレッドが CAP_SETPCAP を持っていない場合、呼び出しはエラー EPERM で失敗する。 arg2 に指
定されたケーパビリティが有効でない場合、 EINVAL で失敗する。 ファイルケーパビリティがカーネルで有
効になっていない場合 (この場合にはバウンディングセットがサポートされない)、 EINVAL で失敗する。
PR_SET_DUMPABLE (Linux 2.3.20 以降)
(Linux 2.3.20 以降) デフォルトの振る舞いではコアダンプを引き起こすよう なシグナルを受信したとき
に、 コアダンプするかどうかを決定するフラグを 設定する (通常このフラグは、デフォルトではセットされ
ているが、 set-user-ID あるいは set-group-ID プログラムが実行されたり、 さまざまな システムコール
によってプロセスの UID や GID が操作されたときに クリアさ れる)。 2.6.12 以前のカーネルでは、 arg2
は 0 (プロセスはダンプ不可) あるいは 1 (プロセスはダンプ可能) の どちらかでなければならない。
2.6.13 から 2.6.17 までのカーネルでは、値 2 も認められていた。 この値を 指定すると、通常はダンプさ
れないバイナリが root だけが 読み込み可能な形 でダンプされた。 セキュリティ上の理由から、この機能
は削除された (proc(5) の /proc/sys/fs/suid_dumpable の説明も参照)。 ダンプ不可のプロセスを
ptrace(2) PTRACE_ATTACH 経由で接続すること はできない。
PR_GET_DUMPABLE (Linux 2.3.20 以降)
(Linux 2.3.20 以降) 呼び出し元プロセスにおけるダンプ可能フラグの 現在の状態を (関数の返り値とし
て) 返す。
PR_SET_ENDIAN (Linux 2.6.18 以降、PowerPC のみ)
呼び出し元プロセスのエンディアン設定 (endian-ness) を arg2 で指定された値に設定する。 指定できる値
は PR_ENDIAN_BIG, PR_ENDIAN_LITTLE, PR_ENDIAN_PPC_LITTLE (PowerPC 擬似リトルエンディアン) のいず
れか一つである。
PR_GET_ENDIAN (Linux 2.6.18 以降、PowerPC のみ)
呼び出し元プロセスのエンディアン設定 (endian-ness) を (int *) arg2 が指す場所に格納して返す。
PR_SET_FPEMU (Linux 2.4.18 以降, 2.5.9, ia64 のみ)
浮動小数点エミュレーション (floating-point emulation) 制御ビットを arg2 で指定された値に設定する。
指定できる値は PR_FPEMU_NOPRINT (浮動小数点命令アクセスを黙って エミュレートする) か
PR_FPEMU_SIGFPE (浮動小数点命令をエミュレートせず、 代わりに SIGFPE を送る) である。
PR_GET_FPEMU (Linux 2.4.18 以降, 2.5.9, ia64 のみ)
浮動小数点エミュレーション制御ビットの値を (int *) arg2 が指す場所に格納して返す。
PR_SET_FPEXC (Linux 2.4.21 および 2.5.32 以降、PowerPC のみ)
浮動小数点例外モード (floating-point exception mode) を arg2 で指定された値に設定する。 指定できる
のは以下の値である: PR_FP_EXC_SW_ENABLE (FPEXC で浮動小数点例外を有効にする)、 PR_FP_EXC_DIV (0 除
算)、 PR_FP_EXC_OVF (オーバーフロー)、 PR_FP_EXC_UND (アンダーフロー)、 PR_FP_EXC_RES (不正確な結
果 (inexact result))、 PR_FP_EXC_INV (不正な命令 (invalid operation))、 PR_FP_EXC_DISABLED (浮動小
数点例外を無効にする)、 PR_FP_EXC_NONRECOV (async nonrecoverable exception mode)、 PR_FP_EXC_ASYNC
(async recoverable exception mode)、 PR_FP_EXC_PRECISE (precise exception mode)。
PR_GET_FPEXC(Linux 2.4.21 および 2.5.32 以降、PowerPC のみ)
浮動小数点例外モードの値を (int *) arg2 が指す場所に格納して返す。
PR_SET_KEEPCAPS (Linux 2.2.18 以降)
スレッドの「ケーパビリティ保持」フラグを設定する。 このフラグは、スレッドの実 UID、実効 UID、保存
set-user-ID のうち少なく とも一つが 0 であった状態から、これら全てが 0 以外に変更されたとき、 ス
レッドの許可ケーパビリティ集合がクリアされるかどうかを決定する。 デフォルトでは、このような変更が
行われた場合、許可ケーパビリティセット はクリアされる。「ケーパビリティ保持」フラグを設定すると、
許可ケーパビリティセットはクリアされなくなる。 arg2 は 0 (許可ケーパビリティをクリアする) か 1 (許
可ケーパビリティ を保持する) の どちらかでなければならない。 (このような ID の変更が行われた場
合、「ケーパビリティ保持」フラグの設定 に関わらず、スレッドの実効ケーパビリティセットは常にクリア
される。) execve(2) が呼び出されると、「ケーパビリティ保持」フラグは 0 にリセットされる。
PR_GET_KEEPCAPS (Linux 2.2.18 以降)
呼び出し元スレッドにおける「ケーパビリティ保持」フラグの 現在の状態を (関数の返り値として) 返す。
PR_SET_NAME (Linux 2.6.9 以降)
呼び出し元プロセスのプロセス名を (char *) arg2 が指す場所に格納された値を使って設定する。 名前は最
大で 16 バイトであり、 それより少ないバイト数の場合は NULL で終端すべきである。
PR_GET_NAME (Linux 2.6.11 以降)
呼び出し元プロセスのプロセス名を (char *) arg2 が指す場所に格納して返す。 バッファは最大で 16 バイ
トを格納できるようにすべきである。 返される文字列は、長さが 16 バイトより短い場合は NULL 終端され
る。
PR_SET_PDEATHSIG (Linux 2.1.57 以降)
親プロセス死亡シグナル (parent process death signal) を arg2 に設定 する (設定できるシグナル値の範
囲は 1..maxsig であり、0 は通知の解除であ る)。 呼び出し元プロセスの親プロセスが死んだ際に、ここで
設定した値が シ グナルとして通知される。この値は fork(2) の子プロセスでは解除される。 (Linux
2.5.36 以降および 2.6.23 以降では) set-user-ID もしくは set-group-ID されたバイナリを実行した場合
にも、このフラグは解除される。
PR_GET_PDEATHSIG (Linux 2.3.15 以降)
親プロセス死亡シグナルの現在の値を (int *) arg2 が指す場所に格納して返す。
PR_SET_SECCOMP (Linux 2.6.23 以降)
呼び出したスレッドの secure computing モードを設定する。 現在の実装では、 arg2 は 1 にしなければな
らない。 secure computing モードを 1 に設定すると、 そのスレッドが呼び出しを許可されるシステムコー
ルは read(2), write(2), _exit(2), sigreturn(2) だけになる。 それ以外のシステムコールを呼び出す
と、シグナル SIGKILL が配送される。 パイプやソケットから読み込んだ、信頼できないバイトコードを実行
する 必要がある大量の演算を行うアプリケーションにおいて、 secure computing モードは役立つ。 この操
作は利用できるのは、カーネルが CONFIG_SECCOMP を有効にして 作成されている場合だけである。
PR_GET_SECCOMP (Linux 2.6.23 以降)
呼び出したスレッドの secure computing モードを返す。 現在の実装 (モードは 1 固定) はあまり役に立た
ないが、 将来他のモードが実装されると役立つようになるかもしれない。 呼び出したスレッドが secure
computing モードでなかった場合、 この操作は 0 を返す。 呼び出したスレッドが secure computing モー
ドの場合、 prctl() を呼び出すとシグナル SIGKILL がそのプロセスに送信される。 この操作が利用できる
のは、カーネルが CONFIG_SECCOMP を有効にして 作成されている場合だけである。
PR_SET_SECUREBITS (Linux 2.6.26 以降)
呼び出したスレッドの "securebits" フラグを arg2 で渡された値に設定する。 capabilities(7) 参照。
PR_GET_SECUREBITS (Linux 2.6.26 以降)
呼び出したスレッドの "securebits" フラグを (関数の返り値として) 返す。 capabilities(7) 参照。
PR_SET_TIMING (Linux 2.6.0-test4 以降)
(通常の、伝統的に使われてきた) 統計的なプロセスタイミングを使用するか、 正確なタイムスタンプに基づ
くプロセスタイミングを使用するかを設定する。 arg2 に指定できる値は PR_TIMING_STATISTICAL か
PR_TIMING_TIMESTAMP である。 PR_TIMING_TIMESTAMP は現在のところ実 装されていない (このモードに設定
しようとするとエラー EINVAL が起こる ことだろう)。
PR_GET_TIMING (Linux 2.6.0-test4 以降)
現在使用中のプロセスタイミングを決める方法を返す。
PR_TASK_PERF_EVENTS_DISABLE (Linux 2.6.31 以降)
Disable all performance counters attached to the calling process, regardless of whether the
counters were created by this process or another process. Performance counters created by the
calling process for other processes are unaffected. For more information on performance counters,
see the kernel source file tools/perf/design.txt.
Originally called PR_TASK_PERF_COUNTERS_DISABLE; renamed (with same numerical value) in Linux
2.6.32.
PR_TASK_PERF_EVENTS_ENABLE (Linux 2.6.31 以降)
The converse of PR_TASK_PERF_EVENTS_DISABLE; enable performance counters attached to the calling
process.
Originally called PR_TASK_PERF_COUNTERS_ENABLE; renamed in Linux 2.6.32.
PR_SET_TSC (Linux 2.6.26 以降, x86 のみ)
そのプロセスがタイムスタンプ・カウンタを読み出せるかを決定する フラグの状態を設定する。 読み出しを
許可する場合は arg2 に PR_TSC_ENABLE を、そのプロセスがタイムスタンプ・カウンタを読み出そうとした
際に SIGSEGV を発生させる場合には PR_TSC_SIGSEGV を渡す。
PR_GET_TSC (Linux 2.6.26 以降, x86 のみ)
そのプロセスがタイムスタンプ・カウンタを読み出せるかを決定する フラグの状態を (int *) arg2 が指す
場所に格納して返す。
PR_SET_UNALIGN
(ia64 では Linux 2.3.48 以降; parisc では Linux 2.6.15 以降; PowerPC では Linux 2.6.18 以降; Alpha
では Linux 2.6.22 以降; これらのアーキテクチャのみ) unaligned アクセス制御ビットを arg2 で指定さ
れた値に設定する。 指定できる値は PR_UNALIGN_NOPRINT (unaligned なユーザアクセスを黙って 修正する)
か PR_UNALIGN_SIGBUS (unaligned なユーザアクセスがあった場合 SIGBUS を生成する) である。
PR_GET_UNALIGN
(バージョンとアーキテクチャの情報は PR_SET_UNALIGN 参照) unaligned アクセス制御ビットの値を
(int *) arg2 が指す場所に格納して返す。
PR_MCE_KILL (Linux 2.6.32 以降)
Set the machine check memory corruption kill policy for the current thread. If arg2 is
PR_MCE_KILL_CLEAR, clear the thread memory corruption kill policy and use the system-wide default.
(The system-wide default is defined by /proc/sys/vm/memory_failure_early_kill; see proc(5).) If
arg2 is PR_MCE_KILL_SET, use a thread-specific memory corruption kill policy. In this case, arg3
defines whether the policy is early kill (PR_MCE_KILL_EARLY), late kill (PR_MCE_KILL_LATE), or the
system-wide default (PR_MCE_KILL_DEFAULT). Early kill means that the thread receives a SIGBUS
signal as soon as hardware memory corruption is detected inside its address space. In late kill
mode, the process is only killed when it accesses a corrupted page. See sigaction(2) for more
information on the SIGBUS signal. The policy is inherited by children. The remaining unused
prctl() arguments must be zero for future compatibility.
PR_MCE_KILL_GET (Linux 2.6.32 以降)
Return the current per-process machine check kill policy. All unused prctl() arguments must be
zero.
PR_SET_MM (Linux 3.3 以降)
Modify certain kernel memory map descriptor fields of the calling process. Usually these fields
are set by the kernel and dynamic loader (see ld.so(8) for more information) and a regular
application should not use this feature. However, there are cases, such as self-modifying
programs, where a program might find it useful to change its own memory map. This feature is
available only if the kernel is built with the CONFIG_CHECKPOINT_RESTORE option enabled. The
calling process must have the CAP_SYS_RESOURCE capability. The value in arg2 is one of the
options below, while arg3 provides a new value for the option.
PR_SET_MM_START_CODE
Set the address above which the program text can run. The corresponding memory area must
be readable and executable, but not writable or sharable (see mprotect(2) and mmap(2) for
more information).
PR_SET_MM_END_CODE
Set the address below which the program text can run. The corresponding memory area must
be readable and executable, but not writable or sharable.
PR_SET_MM_START_DATA
Set the address above which initialized and uninitialized (bss) data are placed. The
corresponding memory area must be readable and writable, but not executable or sharable.
PR_SET_MM_END_DATA
Set the address below which initialized and uninitialized (bss) data are placed. The
corresponding memory area must be readable and writable, but not executable or sharable.
PR_SET_MM_START_STACK
Set the start address of the stack. The corresponding memory area must be readable and
writable.
PR_SET_MM_START_BRK
Set the address above which the program heap can be expanded with brk(2) call. The address
must be greater than the ending address of the current program data segment. In addition,
the combined size of the resulting heap and the size of the data segment can't exceed the
RLIMIT_DATA resource limit (see setrlimit(2)).
PR_SET_MM_BRK
Set the current brk(2) value. The requirements for the address are the same as for the
PR_SET_MM_START_BRK option.
返り値
成功すると、 PR_GET_DUMPABLE, PR_GET_KEEPCAPS, PR_CAPBSET_READ, PR_GET_TIMING, PR_GET_SECUREBITS,
PR_MCE_KILL_GET, PR_GET_SECCOMP は上述の負でない値を返す (なお、 PR_GET_SECCOMP は返らない場合もある)。
option が他の値の場合は 成功時に 0 を返す。 エラーの場合、-1 を返し、 errno に適切な値を設定する。
エラー
EFAULT arg2 が不正なアドレスである。
EINVAL option の値が理解できない。
EINVAL option is PR_MCE_KILL or PR_MCE_KILL_GET or PR_SET_MM, and unused prctl() arguments were not
specified as zero.
EINVAL arg2 が指定された option で有効な値ではない。
EINVAL option が PR_SET_SECCOMP か PR_GET_SECCOMP だが、カーネルが CONFIG_SECCOMP を有効にして作成されて
いなかった。
EINVAL option is PR_SET_MM, and one of the following is true
* arg4 or arg5 is nonzero;
* arg3 is greater than TASK_SIZE (the limit on the size of the user address space for this
architecture);
* arg2 is PR_SET_MM_START_CODE, PR_SET_MM_END_CODE, PR_SET_MM_START_DATA, PR_SET_MM_END_DATA, or
PR_SET_MM_START_STACK, and the permissions of the corresponding memory area are not as
required;
* arg2 is PR_SET_MM_START_BRK or PR_SET_MM_BRK, and arg3 is less than or equal to the end of the
data segment or specifies a value that would cause the RLIMIT_DATA resource limit to be
exceeded.
EPERM option が PR_SET_SECUREBITS で、呼び出し元がケーパビリティ CAP_SETPCAP を持っていない。 また
は、"locked" フラグを解除しようとした。 または、locked フラグがセットされているフラグをセットしよ
うとした (capabilities(7) 参照)。
EPERM option が PR_SET_KEEPCAPS で、呼び出し元のフラグ SECURE_KEEP_CAPS_LOCKED がセットされている
(capabilities(7) 参照)。
EPERM option が PR_CAPBSET_DROP で、呼び出し元がケーパビリティ CAP_SETPCAP を持っていない。
EPERM option が PR_SET_MM で、呼び出し元がケーパビリティ CAP_SYS_RESOURCE を持っていない。
バージョン
prctl() システムコールは Linux 2.1.57 で導入された。
準拠
このコールは Linux 特有である。 IRIX には prctl() システム・コールがあるが (MIPS アーキテクチャにおいて
irix_prctl として Linux 2.1.44 で同様に導入された)、 そのプロトタイプは
ptrdiff_t prctl(int option, int arg2, int arg3);
である。ユーザー当りのプロセス最大数を取得するオプション、 プロセスの使用できる最大プロッサー数を取得する
オプション、 現在特定のプロセスが停止(block)させられているかどうか調べるオプション、 スタックサイズの最大
値の取得や設定を行なうオプションなどがある。
関連項目
signal(2), core(5)
この文書について
この man ページは Linux man-pages プロジェクトのリリース 3.40 の一部 である。プロジェクトの説明とバグ報告
に関する情報は http://www.kernel.org/doc/man-pages/ に書かれている。
Linux 2012-04-23 PRCTL(2)