]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/arch_prctl.2
alloc_hugepages.2: Use syscall(SYS_...); for system calls without a wrapper
[thirdparty/man-pages.git] / man2 / arch_prctl.2
CommitLineData
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 27arch_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 :
38There is no glibc wrapper for this system call; see NOTES.
fea681da 39.SH DESCRIPTION
e511ffb6 40.BR arch_prctl ()
6fac0412 41sets architecture-specific process or thread state.
fea681da
MK
42.I code
43selects a subfunction
44and passes argument
c13182ef 45.I addr
498c6aa6
MK
46to it;
47.I addr
48is interpreted as either an
49.I "unsigned long"
50for the "set" operations, or as an
5049da5b 51.IR "unsigned long\ *" ,
498c6aa6 52for the "get" operations.
dd3568a1 53.PP
8005280b
KF
54Subfunctions for both x86 and x86-64 are:
55.TP
56.BR ARCH_SET_CPUID " (since Linux 4.12)"
96ef1406
MK
57.\" commit e9ea1e7f53b852147cbd568b0568c7ad97ec21a3
58Enable
59.RI ( "addr != 0" )
60or disable
61.RI ( "addr == 0" )
62the
8005280b 63.I cpuid
6b3561b8 64instruction for the calling thread.
5c47b28d
MK
65The instruction is enabled by default.
66If disabled, any execution of a
8005280b
KF
67.I cpuid
68instruction will instead generate a
69.B SIGSEGV
5c47b28d
MK
70signal.
71This feature can be used to emulate
8005280b
KF
72.I cpuid
73results that differ from what the underlying
96ef1406
MK
74hardware would have produced (e.g., in a paravirtualization setting).
75.IP
76The
77.BR ARCH_SET_CPUID
78setting is preserved across
8005280b
KF
79.BR fork (2)
80and
81.BR clone (2)
d7695b17 82but reset to the default (i.e.,
8005280b
KF
83.I cpuid
84enabled) on
96ef1406 85.BR execve (2).
8005280b
KF
86.TP
87.BR ARCH_GET_CPUID " (since Linux 4.12)"
88Return the setting of the flag manipulated by
89.B ARCH_SET_CPUID
90as the result of the system call (1 for enabled, 0 for disabled).
91.I addr
92is ignored.
8005280b
KF
93.TP
94Subfunctions for x86-64 only are:
fea681da
MK
95.TP
96.B ARCH_SET_FS
d4725a0e 97Set the 64-bit base for the
fea681da
MK
98.I FS
99register to
100.IR addr .
101.TP
102.B ARCH_GET_FS
d4725a0e 103Return the 64-bit base value for the
fea681da 104.I FS
6b3561b8 105register of the calling thread in the
fea681da 106.I unsigned long
40725279 107pointed to by
498c6aa6 108.IR addr .
fea681da
MK
109.TP
110.B ARCH_SET_GS
d4725a0e 111Set the 64-bit base for the
fea681da
MK
112.I GS
113register to
114.IR addr .
115.TP
116.B ARCH_GET_GS
d4725a0e 117Return the 64-bit base value for the
fea681da 118.I GS
6b3561b8 119register of the calling thread in the
fea681da 120.I unsigned long
40725279 121pointed to by
498c6aa6 122.IR addr .
3961a41b 123.SH RETURN VALUE
498c6aa6 124On success,
3961a41b
MK
125.BR arch_prctl ()
126returns 0; on error, \-1 is returned, and
127.I errno
128is set to indicate the error.
a1d5f77c
MK
129.SH ERRORS
130.TP
131.B EFAULT
132.I addr
133points to an unmapped address or is outside the process address space.
134.TP
135.B EINVAL
136.I code
137is not a valid subcommand.
138.TP
139.B EPERM
140.I addr
141is outside the process address space.
8005280b
KF
142.TP
143.B ENODEV
144.B ARCH_SET_CPUID
145was 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 ()
150is a Linux/x86-64 extension and should not be used in programs intended
151to be portable.
fea681da 152.SH NOTES
31e9a9ec 153.BR arch_prctl ()
33a0ccb2 154is supported only on Linux/x86-64 for 64-bit programs currently.
ceb7e590 155.PP
d4725a0e 156The 64-bit base changes when a new 32-bit segment selector is loaded.
ceb7e590 157.PP
fea681da
MK
158.B ARCH_SET_GS
159is disabled in some kernels.
ceb7e590 160.PP
d4725a0e 161Context switches for 64-bit segment bases are rather expensive.
14620a25 162As an optimization, if a 32-bit TLS base address is used,
bf7bc8b8 163.BR arch_prctl ()
14620a25 164may use a real TLS entry as if
fea681da 165.BR set_thread_area (2)
5c3f9e21 166had been called, instead of manipulating the segment base register directly.
ee8655b5 167Memory in the first 2\ GB of address space can be allocated by using
fea681da
MK
168.BR mmap (2)
169with the
49363fa6 170.B MAP_32BIT
fea681da 171flag.
ceb7e590 172.PP
ef8db991 173Because of the aforementioned optimization, using
bf7bc8b8 174.BR arch_prctl ()
14620a25
AL
175and
176.BR set_thread_area (2)
177in the same thread is dangerous, as they may overwrite each other's
178TLS entries.
ceb7e590 179.PP
16cc03ca
GC
180Glibc does not provide a wrapper for this system call; call it using
181.BR syscall (2).
ceb7e590 182.PP
c13182ef 183.I FS
5c3f9e21 184may be already used by the threading library.
ef8db991 185Programs that use
5c3f9e21 186.B ARCH_SET_FS
14620a25 187directly 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 194AMD X86-64 Programmer's manual