]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2003 Andi Kleen |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
4784c377 | 24 | .\" |
1d767b55 | 25 | .TH ARCH_PRCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual" |
fea681da | 26 | .SH NAME |
498c6aa6 | 27 | arch_prctl \- set architecture-specific thread state |
fea681da | 28 | .SH SYNOPSIS |
498c6aa6 | 29 | .nf |
fea681da | 30 | .B #include <asm/prctl.h> |
fea681da | 31 | .B #include <sys/prctl.h> |
ceb7e590 | 32 | .PP |
52e87bbe | 33 | .BI "int arch_prctl(int " code ", unsigned long " addr ); |
498c6aa6 MK |
34 | .BI "int arch_prctl(int " code ", unsigned long *" addr ); |
35 | .fi | |
632d1152 GC |
36 | .PP |
37 | .IR Note : | |
38 | There is no glibc wrapper for this system call; see NOTES. | |
fea681da | 39 | .SH DESCRIPTION |
e511ffb6 | 40 | .BR arch_prctl () |
6fac0412 | 41 | sets architecture-specific process or thread state. |
fea681da MK |
42 | .I code |
43 | selects a subfunction | |
44 | and passes argument | |
c13182ef | 45 | .I addr |
498c6aa6 MK |
46 | to it; |
47 | .I addr | |
48 | is interpreted as either an | |
49 | .I "unsigned long" | |
50 | for the "set" operations, or as an | |
5049da5b | 51 | .IR "unsigned long\ *" , |
498c6aa6 | 52 | for the "get" operations. |
dd3568a1 | 53 | .PP |
8005280b KF |
54 | Subfunctions for both x86 and x86-64 are: |
55 | .TP | |
56 | .BR ARCH_SET_CPUID " (since Linux 4.12)" | |
96ef1406 MK |
57 | .\" commit e9ea1e7f53b852147cbd568b0568c7ad97ec21a3 |
58 | Enable | |
59 | .RI ( "addr != 0" ) | |
60 | or disable | |
61 | .RI ( "addr == 0" ) | |
62 | the | |
8005280b | 63 | .I cpuid |
6b3561b8 | 64 | instruction for the calling thread. |
5c47b28d MK |
65 | The instruction is enabled by default. |
66 | If disabled, any execution of a | |
8005280b KF |
67 | .I cpuid |
68 | instruction will instead generate a | |
69 | .B SIGSEGV | |
5c47b28d MK |
70 | signal. |
71 | This feature can be used to emulate | |
8005280b KF |
72 | .I cpuid |
73 | results that differ from what the underlying | |
96ef1406 MK |
74 | hardware would have produced (e.g., in a paravirtualization setting). |
75 | .IP | |
76 | The | |
77 | .BR ARCH_SET_CPUID | |
78 | setting is preserved across | |
8005280b KF |
79 | .BR fork (2) |
80 | and | |
81 | .BR clone (2) | |
d7695b17 | 82 | but reset to the default (i.e., |
8005280b KF |
83 | .I cpuid |
84 | enabled) on | |
96ef1406 | 85 | .BR execve (2). |
8005280b KF |
86 | .TP |
87 | .BR ARCH_GET_CPUID " (since Linux 4.12)" | |
88 | Return the setting of the flag manipulated by | |
89 | .B ARCH_SET_CPUID | |
90 | as the result of the system call (1 for enabled, 0 for disabled). | |
91 | .I addr | |
92 | is ignored. | |
8005280b KF |
93 | .TP |
94 | Subfunctions for x86-64 only are: | |
fea681da MK |
95 | .TP |
96 | .B ARCH_SET_FS | |
d4725a0e | 97 | Set the 64-bit base for the |
fea681da MK |
98 | .I FS |
99 | register to | |
100 | .IR addr . | |
101 | .TP | |
102 | .B ARCH_GET_FS | |
d4725a0e | 103 | Return the 64-bit base value for the |
fea681da | 104 | .I FS |
6b3561b8 | 105 | register of the calling thread in the |
fea681da | 106 | .I unsigned long |
40725279 | 107 | pointed to by |
498c6aa6 | 108 | .IR addr . |
fea681da MK |
109 | .TP |
110 | .B ARCH_SET_GS | |
d4725a0e | 111 | Set the 64-bit base for the |
fea681da MK |
112 | .I GS |
113 | register to | |
114 | .IR addr . | |
115 | .TP | |
116 | .B ARCH_GET_GS | |
d4725a0e | 117 | Return the 64-bit base value for the |
fea681da | 118 | .I GS |
6b3561b8 | 119 | register of the calling thread in the |
fea681da | 120 | .I unsigned long |
40725279 | 121 | pointed to by |
498c6aa6 | 122 | .IR addr . |
3961a41b | 123 | .SH RETURN VALUE |
498c6aa6 | 124 | On success, |
3961a41b MK |
125 | .BR arch_prctl () |
126 | returns 0; on error, \-1 is returned, and | |
127 | .I errno | |
128 | is set to indicate the error. | |
a1d5f77c MK |
129 | .SH ERRORS |
130 | .TP | |
131 | .B EFAULT | |
132 | .I addr | |
133 | points to an unmapped address or is outside the process address space. | |
134 | .TP | |
135 | .B EINVAL | |
136 | .I code | |
137 | is not a valid subcommand. | |
138 | .TP | |
139 | .B EPERM | |
140 | .I addr | |
141 | is outside the process address space. | |
8005280b KF |
142 | .TP |
143 | .B ENODEV | |
144 | .B ARCH_SET_CPUID | |
145 | was requested, but the underlying hardware does not support CPUID faulting. | |
a1d5f77c MK |
146 | .\" .SH AUTHOR |
147 | .\" Man page written by Andi Kleen. | |
47297adb | 148 | .SH CONFORMING TO |
a1d5f77c MK |
149 | .BR arch_prctl () |
150 | is a Linux/x86-64 extension and should not be used in programs intended | |
151 | to be portable. | |
fea681da | 152 | .SH NOTES |
31e9a9ec | 153 | .BR arch_prctl () |
33a0ccb2 | 154 | is supported only on Linux/x86-64 for 64-bit programs currently. |
ceb7e590 | 155 | .PP |
d4725a0e | 156 | The 64-bit base changes when a new 32-bit segment selector is loaded. |
ceb7e590 | 157 | .PP |
fea681da MK |
158 | .B ARCH_SET_GS |
159 | is disabled in some kernels. | |
ceb7e590 | 160 | .PP |
d4725a0e | 161 | Context switches for 64-bit segment bases are rather expensive. |
14620a25 | 162 | As an optimization, if a 32-bit TLS base address is used, |
bf7bc8b8 | 163 | .BR arch_prctl () |
14620a25 | 164 | may use a real TLS entry as if |
fea681da | 165 | .BR set_thread_area (2) |
5c3f9e21 | 166 | had been called, instead of manipulating the segment base register directly. |
ee8655b5 | 167 | Memory in the first 2\ GB of address space can be allocated by using |
fea681da MK |
168 | .BR mmap (2) |
169 | with the | |
49363fa6 | 170 | .B MAP_32BIT |
fea681da | 171 | flag. |
ceb7e590 | 172 | .PP |
ef8db991 | 173 | Because of the aforementioned optimization, using |
bf7bc8b8 | 174 | .BR arch_prctl () |
14620a25 AL |
175 | and |
176 | .BR set_thread_area (2) | |
177 | in the same thread is dangerous, as they may overwrite each other's | |
178 | TLS entries. | |
ceb7e590 | 179 | .PP |
16cc03ca GC |
180 | Glibc does not provide a wrapper for this system call; call it using |
181 | .BR syscall (2). | |
ceb7e590 | 182 | .PP |
c13182ef | 183 | .I FS |
5c3f9e21 | 184 | may be already used by the threading library. |
ef8db991 | 185 | Programs that use |
5c3f9e21 | 186 | .B ARCH_SET_FS |
14620a25 | 187 | directly are very likely to crash. |
47297adb | 188 | .SH SEE ALSO |
fea681da MK |
189 | .BR mmap (2), |
190 | .BR modify_ldt (2), | |
191 | .BR prctl (2), | |
192 | .BR set_thread_area (2) | |
ceb7e590 | 193 | .PP |
fea681da | 194 | AMD X86-64 Programmer's manual |