1ARCH_PRCTL(2) Linux Programmer's Manual ARCH_PRCTL(2)
2
3
4
6 arch_prctl - set architecture-specific thread state
7
9 #include <asm/prctl.h> /* Definition of ARCH_* constants */
10 #include <sys/syscall.h> /* Definition of SYS_* constants */
11 #include <unistd.h>
12
13 int syscall(SYS_arch_prctl, int code, unsigned long addr);
14 int syscall(SYS_arch_prctl, int code, unsigned long *addr);
15
16 Note: glibc provides no wrapper for arch_prctl(), necessitating the use
17 of syscall(2).
18
20 arch_prctl() sets architecture-specific process or thread state. code
21 selects a subfunction and passes argument addr to it; addr is inter‐
22 preted as either an unsigned long for the "set" operations, or as an
23 unsigned long *, for the "get" operations.
24
25 Subfunctions for both x86 and x86-64 are:
26
27 ARCH_SET_CPUID (since Linux 4.12)
28 Enable (addr != 0) or disable (addr == 0) the cpuid instruction
29 for the calling thread. The instruction is enabled by default.
30 If disabled, any execution of a cpuid instruction will instead
31 generate a SIGSEGV signal. This feature can be used to emulate
32 cpuid results that differ from what the underlying hardware
33 would have produced (e.g., in a paravirtualization setting).
34
35 The ARCH_SET_CPUID setting is preserved across fork(2) and
36 clone(2) but reset to the default (i.e., cpuid enabled) on ex‐
37 ecve(2).
38
39 ARCH_GET_CPUID (since Linux 4.12)
40 Return the setting of the flag manipulated by ARCH_SET_CPUID as
41 the result of the system call (1 for enabled, 0 for disabled).
42 addr is ignored.
43
44 Subfunctions for x86-64 only are:
45
46 ARCH_SET_FS
47 Set the 64-bit base for the FS register to addr.
48
49 ARCH_GET_FS
50 Return the 64-bit base value for the FS register of the calling
51 thread in the unsigned long pointed to by addr.
52
53 ARCH_SET_GS
54 Set the 64-bit base for the GS register to addr.
55
56 ARCH_GET_GS
57 Return the 64-bit base value for the GS register of the calling
58 thread in the unsigned long pointed to by addr.
59
61 On success, arch_prctl() returns 0; on error, -1 is returned, and errno
62 is set to indicate the error.
63
65 EFAULT addr points to an unmapped address or is outside the process ad‐
66 dress space.
67
68 EINVAL code is not a valid subcommand.
69
70 ENODEV ARCH_SET_CPUID was requested, but the underlying hardware does
71 not support CPUID faulting.
72
73 EPERM addr is outside the process address space.
74
76 arch_prctl() is a Linux/x86-64 extension and should not be used in pro‐
77 grams intended to be portable.
78
80 arch_prctl() is supported only on Linux/x86-64 for 64-bit programs cur‐
81 rently.
82
83 The 64-bit base changes when a new 32-bit segment selector is loaded.
84
85 ARCH_SET_GS is disabled in some kernels.
86
87 Context switches for 64-bit segment bases are rather expensive. As an
88 optimization, if a 32-bit TLS base address is used, arch_prctl() may
89 use a real TLS entry as if set_thread_area(2) had been called, instead
90 of manipulating the segment base register directly. Memory in the
91 first 2 GB of address space can be allocated by using mmap(2) with the
92 MAP_32BIT flag.
93
94 Because of the aforementioned optimization, using arch_prctl() and
95 set_thread_area(2) in the same thread is dangerous, as they may over‐
96 write each other's TLS entries.
97
98 FS may be already used by the threading library. Programs that use
99 ARCH_SET_FS directly are very likely to crash.
100
102 mmap(2), modify_ldt(2), prctl(2), set_thread_area(2)
103
104 AMD X86-64 Programmer's manual
105
107 This page is part of release 5.13 of the Linux man-pages project. A
108 description of the project, information about reporting bugs, and the
109 latest version of this page, can be found at
110 https://www.kernel.org/doc/man-pages/.
111
112
113
114Linux 2021-08-27 ARCH_PRCTL(2)