1ARCH_PRCTL(2)              Linux Programmer's Manual             ARCH_PRCTL(2)
2
3
4

NAME

6       arch_prctl - set architecture-specific thread state
7

SYNOPSIS

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

DESCRIPTION

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 both x86 and x86-64 are:
22
23       ARCH_SET_CPUID (since Linux 4.12)
24              Enable (addr != 0) or disable (addr == 0) the cpuid  instruction
25              for  the current thread.  The instruction is enabled by default.
26              If disabled, any execution of a cpuid instruction  will  instead
27              generate  a SIGSEGV signal.  This feature can be used to emulate
28              cpuid results that differ  from  what  the  underlying  hardware
29              would have produced (e.g., in a paravirtualization setting).
30
31              The  ARCH_SET_CPUID  setting  is  preserved  across  fork(2) and
32              clone(2) but reset to  the  default  (i.e.,  cpuid  enabled)  on
33              execve(2).
34
35       ARCH_GET_CPUID (since Linux 4.12)
36              Return  the setting of the flag manipulated by ARCH_SET_CPUID as
37              the result of the system call (1 for enabled, 0  for  disabled).
38              addr is ignored.
39
40       Subfunctions for x86-64 only are:
41
42       ARCH_SET_FS
43              Set the 64-bit base for the FS register to addr.
44
45       ARCH_GET_FS
46              Return  the 64-bit base value for the FS register of the current
47              thread in the unsigned long pointed to by addr.
48
49       ARCH_SET_GS
50              Set the 64-bit base for the GS register to addr.
51
52       ARCH_GET_GS
53              Return the 64-bit base value for the GS register of the  current
54              thread in the unsigned long pointed to by addr.
55

RETURN VALUE

57       On success, arch_prctl() returns 0; on error, -1 is returned, and errno
58       is set to indicate the error.
59

ERRORS

61       EFAULT addr points to an unmapped address or  is  outside  the  process
62              address space.
63
64       EINVAL code is not a valid subcommand.
65
66       EPERM  addr is outside the process address space.
67
68       ENODEV ARCH_SET_CPUID  was  requested, but the underlying hardware does
69              not support CPUID faulting.
70

CONFORMING TO

72       arch_prctl() is a Linux/x86-64 extension and should not be used in pro‐
73       grams intended to be portable.
74

NOTES

76       arch_prctl() is supported only on Linux/x86-64 for 64-bit programs cur‐
77       rently.
78
79       The 64-bit base changes when a new 32-bit segment selector is loaded.
80
81       ARCH_SET_GS is disabled in some kernels.
82
83       Context switches for 64-bit segment bases are rather expensive.  As  an
84       optimization,  if  a  32-bit TLS base address is used, arch_prctl() may
85       use a real TLS entry as if set_thread_area(2) had been called,  instead
86       of  manipulating  the  segment  base  register directly.  Memory in the
87       first 2 GB of address space can be allocated by using mmap(2) with  the
88       MAP_32BIT flag.
89
90       Because  of  the  aforementioned  optimization,  using arch_prctl() and
91       set_thread_area(2) in the same thread is dangerous, as they  may  over‐
92       write each other's TLS entries.
93
94       As  of  version 2.7, glibc provides no prototype for arch_prctl().  You
95       have to declare it yourself for now.  This may be fixed in future glibc
96       versions.
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

SEE ALSO

102       mmap(2), modify_ldt(2), prctl(2), set_thread_area(2)
103
104       AMD X86-64 Programmer's manual
105

COLOPHON

107       This page is part of release 5.07 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                             2020-04-11                     ARCH_PRCTL(2)
Impressum