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>
10 #include <sys/prctl.h>
11
12 int arch_prctl(int code, unsigned long addr);
13 int arch_prctl(int code, unsigned long *addr);
14
16 arch_prctl() sets architecture-specific process or thread state. code
17 selects a subfunction and passes argument addr to it; addr is inter‐
18 preted as either an unsigned long for the "set" operations, or as an
19 unsigned long *, for the "get" operations.
20
21 Subfunctions for x86-64 are:
22
23 ARCH_SET_FS
24 Set the 64-bit base for the FS register to addr.
25
26 ARCH_GET_FS
27 Return the 64-bit base value for the FS register of the current
28 thread in the unsigned long pointed to by addr.
29
30 ARCH_SET_GS
31 Set the 64-bit base for the GS register to addr.
32
33 ARCH_GET_GS
34 Return the 64-bit base value for the GS register of the current
35 thread in the unsigned long pointed to by addr.
36
38 On success, arch_prctl() returns 0; on error, -1 is returned, and errno
39 is set to indicate the error.
40
42 EFAULT addr points to an unmapped address or is outside the process
43 address space.
44
45 EINVAL code is not a valid subcommand.
46
47 EPERM addr is outside the process address space.
48
50 arch_prctl() is a Linux/x86-64 extension and should not be used in pro‐
51 grams intended to be portable.
52
54 arch_prctl() is supported only on Linux/x86-64 for 64-bit programs cur‐
55 rently.
56
57 The 64-bit base changes when a new 32-bit segment selector is loaded.
58
59 ARCH_SET_GS is disabled in some kernels.
60
61 Context switches for 64-bit segment bases are rather expensive. As an
62 optimization, if a 32-bit TLS base address is used, arch_prctl() may
63 use a real TLS entry as if set_thread_area(2) had been called, instead
64 of manipulating the segment base register directly. Memory in the
65 first 2 GB of address space can be allocated by using mmap(2) with the
66 MAP_32BIT flag.
67
68 Because of the aforementioned optimization, using arch_prctl() and
69 set_thread_area(2) in the same thread is dangerous, as they may over‐
70 write each other's TLS entries.
71
72 As of version 2.7, glibc provides no prototype for arch_prctl(). You
73 have to declare it yourself for now. This may be fixed in future glibc
74 versions.
75
76 FS may be already used by the threading library. Programs that use
77 ARCH_SET_FS directly are very likely to crash.
78
80 mmap(2), modify_ldt(2), prctl(2), set_thread_area(2)
81
82 AMD X86-64 Programmer's manual
83
85 This page is part of release 5.02 of the Linux man-pages project. A
86 description of the project, information about reporting bugs, and the
87 latest version of this page, can be found at
88 https://www.kernel.org/doc/man-pages/.
89
90
91
92Linux 2017-09-15 ARCH_PRCTL(2)