prctlのヘルプ・マニュアル
日本語 英語
prctl --help
man prctl
PRCTL(2) Linux Programmer’s Manual PRCTL(2)
名前
prctl - プロセスの操作を行なう
書式
#include
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
説明
prctl() の 動 作 は 最 初 の 引 き 数 に よ っ て決定される (この値は
に定義されている)。残りの引き数は最初の引き数によって変
化する。一番目の引き数として以下のものを指定できる:
PR_CAPBSET_READ (Linux 2.6.25 以降)
で指定されたケーパビリティが呼び出したスレッドのケーパビリティバ
インディングセット (capability bounding set) に含まれている場 合
、 (関数の返り値として) 1 を返し、そうでない場合 0 を返す (ケー
パビリティ定数は で定義されている)。ケー パ
ビ リティバウンディングセットは、 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 の説明も参照)。
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 non-recoverable 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 (ケーパ
ビリティを保持する) のどちらかでなければならない。 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) の 子
プロセスでは解除される。
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_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_SIG-
BUS (unaligned なユーザアクセスがあった場合 SIGBUS を生成する)
である。
PR_GET_UNALIGN
(バージョンとアーキテクチャ の 情 報 は PR_SET_UNALIGN 参 照)
unaligned アクセス制御ビットの値を (int *) arg2 が指す場所に格納
して返す。
返り値
成 功 す る と 、 PR_GET_DUMPABLE, PR_GET_KEEPCAPS, PR_CAPBSET_READ,
PR_GET_TIMING, PR_GET_SECUREBITS, PR_GET_SECCOMP は上述の負でない値を返
す (PR_GET_SECCOMP は返らない場合もある)。 option が他の値の場合は成 功
時に 0 を返す。エラーの場合、-1 を返し、 errno に適切な値を設定する。
エラー
EFAULT arg2 が不正なアドレスである。
EINVAL option の値が理解できない。
EINVAL arg2 が指定された option で有効な値ではない。
EINVAL option が PR_SET_SECCOMP か PR_GET_SECCOMP だが、カーネルが CON-
FIG_SECCOMP を有効にして作成されていなかった。
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 を持っていない。
バージョン
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)
Linux 2008-07-16 PRCTL(2)
PRCTL(2) Linux Programmer’s Manual PRCTL(2)
NAME
prctl - operations on a process
SYNOPSIS
#include
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
DESCRIPTION
prctl() is called with a first argument describing what to do (with
values defined in ), and further arguments with a sig-
nificance depending on the first one. The first argument can be:
PR_CAPBSET_READ (since Linux 2.6.25)
Return (as the function result) 1 if the capability specified in
arg2 is in the calling thread’s capability bounding set, or 0 if
it is not. (The capability constants are defined in
.) The capability bounding set dictates
whether the process can receive the capability through a file’s
permitted capability set on a subsequent call to execve(2).
If the capability specified in arg2 is not valid, then the call
fails with the error EINVAL.
PR_CAPBSET_DROP (since Linux 2.6.25)
If the calling thread has the CAP_SETPCAP capability, then drop
the capability specified by arg2 from the calling thread’s capa-
bility bounding set. Any children of the calling thread will
inherit the newly reduced bounding set.
The call fails with the error: EPERM if the calling thread does
not have the CAP_SETPCAP; EINVAL if arg2 does not represent a
valid capability; or EINVAL if file capabilities are not enabled
in the kernel, in which case bounding sets are not supported.
PR_SET_DUMPABLE (since Linux 2.3.20)
Set the state of the flag determining whether core dumps are
produced for this process upon delivery of a signal whose
default behavior is to produce a core dump. (Normally this flag
is set for a process by default, but it is cleared when a set-
user-ID or set-group-ID program is executed and also by various
system calls that manipulate process UIDs and GIDs). In kernels
up to and including 2.6.12, arg2 must be either 0 (process is
not dumpable) or 1 (process is dumpable). Between kernels
2.6.13 and 2.6.17, the value 2 was also permitted, which caused
any binary which normally would not be dumped to be dumped read-
able by root only; for security reasons, this feature has been
removed. (See also the description of
/proc/sys/fs/suid_dumpable in proc(5).)
PR_GET_DUMPABLE (since Linux 2.3.20)
Return (as the function result) the current state of the calling
process’s dumpable flag.
PR_SET_ENDIAN (since Linux 2.6.18, PowerPC only)
Set the endian-ness of the calling process to the value given in
arg2, which should be one of the following: PR_ENDIAN_BIG,
PR_ENDIAN_LITTLE, or PR_ENDIAN_PPC_LITTLE (PowerPC pseudo little
endian).
PR_GET_ENDIAN (since Linux 2.6.18, PowerPC only)
Return the endian-ness of the calling process, in the location
pointed to by (int *) arg2.
PR_SET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
Set floating-point emulation control bits to arg2. Pass
PR_FPEMU_NOPRINT to silently emulate fp operations accesses, or
PR_FPEMU_SIGFPE to not emulate fp operations and send SIGFPE
instead.
PR_GET_FPEMU (since Linux 2.4.18, 2.5.9, only on ia64)
Return floating-point emulation control bits, in the location
pointed to by (int *) arg2.
PR_SET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
Set floating-point exception mode to arg2. Pass
PR_FP_EXC_SW_ENABLE to use FPEXC for FP exception enables,
PR_FP_EXC_DIV for floating-point divide by zero, PR_FP_EXC_OVF
for floating-point overflow, PR_FP_EXC_UND for floating-point
underflow, PR_FP_EXC_RES for floating-point inexact result,
PR_FP_EXC_INV for floating-point invalid operation,
PR_FP_EXC_DISABLED for FP exceptions disabled, PR_FP_EXC_NONRE-
COV for async non-recoverable exception mode, PR_FP_EXC_ASYNC
for async recoverable exception mode, PR_FP_EXC_PRECISE for pre-
cise exception mode.
PR_GET_FPEXC (since Linux 2.4.21, 2.5.32, only on PowerPC)
Return floating-point exception mode, in the location pointed to
by (int *) arg2.
PR_SET_KEEPCAPS (since Linux 2.2.18)
Set the state of the thread’s "keep capabilities" flag, which
determines whether the threads’s effective and permitted capa-
bility sets are cleared when a change is made to the threads’s
user IDs such that the threads’s real UID, effective UID, and
saved set-user-ID all become non-zero when at least one of them
previously had the value 0. (By default, these credential sets
are cleared). arg2 must be either 0 (capabilities are cleared)
or 1 (capabilities are kept). This value will be reset to 0 on
subsequent calls to execve(2).
PR_GET_KEEPCAPS (since Linux 2.2.18)
Return (as the function result) the current state of the calling
threads’s "keep capabilities" flag.
PR_SET_NAME (since Linux 2.6.9)
Set the process name for the calling process, using the value in
the location pointed to by (char *) arg2. The name can be up to
16 bytes long, and should be null terminated if it contains
fewer bytes.
PR_GET_NAME (since Linux 2.6.11)
Return the process name for the calling process, in the buffer
pointed to by (char *) arg2. The buffer should allow space for
up to 16 bytes; the returned string will be null terminated if
it is shorter than that.
PR_SET_PDEATHSIG (since Linux 2.1.57)
Set the parent process death signal of the calling process to
arg2 (either a signal value in the range 1..maxsig, or 0 to
clear). This is the signal that the calling process will get
when its parent dies. This value is cleared for the child of a
fork(2).
PR_GET_PDEATHSIG (since Linux 2.3.15)
Return the current value of the parent process death signal, in
the location pointed to by (int *) arg2.
PR_SET_SECCOMP (since Linux 2.6.23)
Set the secure computing mode for the calling thread. In the
current implementation, arg2 must be 1. After the secure
computing mode has been set to 1, the only system calls that the
thread is permitted to make are read(2), write(2), _exit(2), and
sigreturn(2). Other system calls result in the delivery of a
SIGKILL signal. Secure computing mode is useful for number-
crunching applications that may need to execute untrusted byte
code, perhaps obtained by reading from a pipe or socket. This
operation is only available if the kernel is configured with
CONFIG_SECCOMP enabled.
PR_GET_SECCOMP (since Linux 2.6.23)
Return the secure computing mode of the calling thread. Not
very useful for the current implementation (mode equals 1), but
may be useful for other possible future modes: if the caller is
not in secure computing mode, this operation returns 0; if the
caller is in secure computing mode, then the prctl() call will
cause a SIGKILL signal to be sent to the process. This opera-
tion is only available if the kernel is configured with CON-
FIG_SECCOMP enabled.
PR_SET_SECUREBITS (since Linux 2.6.26)
Set the "securebits" flags of the calling thread to the value
supplied in arg2. See capabilities(7).
PR_GET_SECUREBITS (since Linux 2.6.26)
Return (as the function result) the "securebits" flags of the
calling thread. See capabilities(7).
PR_SET_TIMING (since Linux 2.6.0-test4)
Set whether to use (normal, traditional) statistical process
timing or accurate timestamp based process timing, by passing
PR_TIMING_STATISTICAL or PR_TIMING_TIMESTAMP to arg2. PR_TIM-
ING_TIMESTAMP is not currently implemented (attempting to set
this mode will yield the error EINVAL).
PR_GET_TIMING (since Linux 2.6.0-test4)
Return (as the function result) which process timing method is
currently in use.
PR_SET_TSC (since Linux 2.6.26, x86 only)
Set the state of the flag determining whether the timestamp
counter can be read by the process. Pass PR_TSC_ENABLE to arg2
to allow it to be read, or PR_TSC_SIGSEGV to generate a SIGSEGV
when the process tries to read the timestamp counter.
PR_GET_TSC (since Linux 2.6.26, x86 only)
Return the state of the flag determining whether the timestamp
counter can be read, in the location pointed to by (int *) arg2.
PR_SET_UNALIGN
(Only on: ia64, since Linux 2.3.48; parisc, since Linux 2.6.15;
PowerPC, since Linux 2.6.18; Alpha, since Linux 2.6.22) Set
unaligned access control bits to arg2. Pass PR_UNALIGN_NOPRINT
to silently fix up unaligned user accesses, or PR_UNALIGN_SIGBUS
to generate SIGBUS on unaligned user access.
PR_GET_UNALIGN
(see PR_SET_UNALIGN for information on versions and architec-
tures) Return unaligned access control bits, in the location
pointed to by (int *) arg2.
RETURN VALUE
On success, PR_GET_DUMPABLE, PR_GET_KEEPCAPS, PR_CAPBSET_READ,
PR_GET_TIMING, PR_GET_SECUREBITS, and (if it returns) PR_GET_SECCOMP
return the non-negative values described above. All other option val-
ues return 0 on success. On error, -1 is returned, and errno is set
appropriately.
ERRORS
EFAULT arg2 is an invalid address.
EINVAL The value of option is not recognized.
EINVAL arg2 is not valid value for this option.
EINVAL option is PR_SET_SECCOMP or PR_SET_SECCOMP, and the kernel was
not configured with CONFIG_SECCOMP.
EPERM option is PR_SET_SECUREBITS, and the caller does not have the
CAP_SETPCAP capability, or tried to unset a "locked" flag, or
tried to set a flag whose corresponding locked flag was set (see
capabilities(7)).
EPERM option is PR_SET_KEEPCAPS, and the callers’s
SECURE_KEEP_CAPS_LOCKED flag is set (see capabilities(7)).
EPERM option is PR_CAPBSET_DROP, and the caller does not have the
CAP_SETPCAP capability.
VERSIONS
The prctl() system call was introduced in Linux 2.1.57.
CONFORMING TO
This call is Linux-specific. IRIX has a prctl() system call (also
introduced in Linux 2.1.44 as irix_prctl on the MIPS architecture),
with prototype
ptrdiff_t prctl(int option, int arg2, int arg3);
and options to get the maximum number of processes per user, get the
maximum number of processors the calling process can use, find out
whether a specified process is currently blocked, get or set the maxi-
mum stack size, etc.
SEE ALSO
signal(2), core(5)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-07-16 PRCTL(2)