ARCH_PRCTL(2) | Linux Programmer's Manual | ARCH_PRCTL(2) |
arch_prctl - アーキテクチャー固有のスレッド状態を設定する
#include <asm/prctl.h> #include <sys/prctl.h>
int arch_prctl(int code, unsigned long addr); int arch_prctl(int code, unsigned long *addr);
arch_prctl() はアーキテクチャー固有のプロセス状態またはスレッド状態を設定する。 code は副機能を選択し、引数 addr を副機能に渡す。 addr は、"set" 操作では unsigned long として、"get" 操作では unsigned long * として解釈される。
x86 と x86-64 の両方での使える副機能は以下の通り:
成功すると、 arch_prctl() は 0 を返す。エラーの場合、-1 を返し、 errno をエラーを示す値に設定する。
arch_prctl() は Linux/x86-64 拡張であり、移植性を意図したプログラムでは使うべきでない。
arch_prctl() は現在のところ Linux/x86-64 上の 64 ビットプログラムでのみサポートされている。
新しい 32 ビットセグメントセレクタがロードされた場合、 64 ビットベースは変更される。
ARCH_SET_GS が無効にされているカーネルもある。
Context switches for 64-bit segment bases are rather expensive. As an optimization, if a 32-bit TLS base address is used, arch_prctl() may use a real TLS entry as if set_thread_area(2) had been called, instead of manipulating the segment base register directly. Memory in the first 2 GB of address space can be allocated by using mmap(2) with the MAP_32BIT flag.
Because of the aforementioned optimization, using arch_prctl() and set_thread_area(2) in the same thread is dangerous, as they may overwrite each other's TLS entries.
バージョン 2.7 時点では、glibc には arch_prctl() のプロトタイプがない。 今のところユーザーは自分自身で宣言する必要がある。 これは将来の glibc のバージョンで修正されるかもしれない。
FS may be already used by the threading library. Programs that use ARCH_SET_FS directly are very likely to crash.
mmap(2), modify_ldt(2), prctl(2), set_thread_area(2)
AMD X86-64 Programmer's manual
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-04-11 | Linux |