termios.3: SPARC architecture has 4 different Bnnn constants
[man-pages.git] / man2 / arch_prctl.2
blob98241676174bda874eaa8642cc5b5409b45a5619
1 .\" Copyright (C) 2003 Andi Kleen
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH ARCH_PRCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 arch_prctl \- set architecture-specific thread state
28 .SH SYNOPSIS
29 .nf
30 .BR "#include <asm/prctl.h>" "        /* Definition of " ARCH_* " constants */"
31 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
32 .B #include <unistd.h>
33 .PP
34 .BI "int syscall(SYS_arch_prctl, int " code ", unsigned long " addr );
35 .BI "int syscall(SYS_arch_prctl, int " code ", unsigned long *" addr );
36 .fi
37 .PP
38 .IR Note :
39 glibc provides no wrapper for
40 .BR arch_prctl (),
41 necessitating the use of
42 .BR syscall (2).
43 .SH DESCRIPTION
44 .BR arch_prctl ()
45 sets architecture-specific process or thread state.
46 .I code
47 selects a subfunction
48 and passes argument
49 .I addr
50 to it;
51 .I addr
52 is interpreted as either an
53 .I "unsigned long"
54 for the "set" operations, or as an
55 .IR "unsigned long\ *" ,
56 for the "get" operations.
57 .PP
58 Subfunctions for both x86 and x86-64 are:
59 .TP
60 .BR ARCH_SET_CPUID " (since Linux 4.12)"
61 .\" commit e9ea1e7f53b852147cbd568b0568c7ad97ec21a3
62 Enable
63 .RI ( "addr != 0" )
64 or disable
65 .RI ( "addr == 0" )
66 the
67 .I cpuid
68 instruction for the calling thread.
69 The instruction is enabled by default.
70 If disabled, any execution of a
71 .I cpuid
72 instruction will instead generate a
73 .B SIGSEGV
74 signal.
75 This feature can be used to emulate
76 .I cpuid
77 results that differ from what the underlying
78 hardware would have produced (e.g., in a paravirtualization setting).
79 .IP
80 The
81 .BR ARCH_SET_CPUID
82 setting is preserved across
83 .BR fork (2)
84 and
85 .BR clone (2)
86 but reset to the default (i.e.,
87 .I cpuid
88 enabled) on
89 .BR execve (2).
90 .TP
91 .BR ARCH_GET_CPUID " (since Linux 4.12)"
92 Return the setting of the flag manipulated by
93 .B ARCH_SET_CPUID
94 as the result of the system call (1 for enabled, 0 for disabled).
95 .I addr
96 is ignored.
97 .TP
98 Subfunctions for x86-64 only are:
99 .TP
100 .B ARCH_SET_FS
101 Set the 64-bit base for the
102 .I FS
103 register to
104 .IR addr .
106 .B ARCH_GET_FS
107 Return the 64-bit base value for the
108 .I FS
109 register of the calling thread in the
110 .I unsigned long
111 pointed to by
112 .IR addr .
114 .B ARCH_SET_GS
115 Set the 64-bit base for the
116 .I GS
117 register to
118 .IR addr .
120 .B ARCH_GET_GS
121 Return the 64-bit base value for the
122 .I GS
123 register of the calling thread in the
124 .I unsigned long
125 pointed to by
126 .IR addr .
127 .SH RETURN VALUE
128 On success,
129 .BR arch_prctl ()
130 returns 0; on error, \-1 is returned, and
131 .I errno
132 is set to indicate the error.
133 .SH ERRORS
135 .B EFAULT
136 .I addr
137 points to an unmapped address or is outside the process address space.
139 .B EINVAL
140 .I code
141 is not a valid subcommand.
143 .B EPERM
144 .I addr
145 is outside the process address space.
147 .B ENODEV
148 .B ARCH_SET_CPUID
149 was requested, but the underlying hardware does not support CPUID faulting.
150 .\" .SH AUTHOR
151 .\" Man page written by Andi Kleen.
152 .SH CONFORMING TO
153 .BR arch_prctl ()
154 is a Linux/x86-64 extension and should not be used in programs intended
155 to be portable.
156 .SH NOTES
157 .BR arch_prctl ()
158 is supported only on Linux/x86-64 for 64-bit programs currently.
160 The 64-bit base changes when a new 32-bit segment selector is loaded.
162 .B ARCH_SET_GS
163 is disabled in some kernels.
165 Context switches for 64-bit segment bases are rather expensive.
166 As an optimization, if a 32-bit TLS base address is used,
167 .BR arch_prctl ()
168 may use a real TLS entry as if
169 .BR set_thread_area (2)
170 had been called, instead of manipulating the segment base register directly.
171 Memory in the first 2\ GB of address space can be allocated by using
172 .BR mmap (2)
173 with the
174 .B MAP_32BIT
175 flag.
177 Because of the aforementioned optimization, using
178 .BR arch_prctl ()
180 .BR set_thread_area (2)
181 in the same thread is dangerous, as they may overwrite each other's
182 TLS entries.
184 .I FS
185 may be already used by the threading library.
186 Programs that use
187 .B ARCH_SET_FS
188 directly are very likely to crash.
189 .SH SEE ALSO
190 .BR mmap (2),
191 .BR modify_ldt (2),
192 .BR prctl (2),
193 .BR set_thread_area (2)
195 AMD X86-64 Programmer's manual