1 .\" Copyright (C) 2003 Free Software Foundation, Inc.
2 .\" Copyright (C) 2015 Andrew Lutomirski
5 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
6 .\" This file is distributed according to the GNU General Public License.
9 .TH SET_THREAD_AREA 2 2015-02-21 "Linux" "Linux Programmer's Manual"
11 set_thread_area \- set a GDT entry for thread-local storage
14 .B #include <linux/unistd.h>
15 .B #include <asm/ldt.h>
17 .BI "int get_thread_area(struct user_desc *" u_info );
18 .BI "int set_thread_area(struct user_desc *" u_info );
22 There are no glibc wrappers for these system calls; see NOTES.
24 Linux dedicates three global descriptor table (GDT) entries for
26 For more information about the GDT, see the
27 Intel Software Developer's Manual or the AMD Architecture Programming Manual.
29 Both of these system calls take an argument that is a pointer
30 to a structure of the following type:
34 unsigned int entry_number;
35 unsigned long base_addr;
37 unsigned int seg_32bit:1;
38 unsigned int contents:2;
39 unsigned int read_exec_only:1;
40 unsigned int limit_in_pages:1;
41 unsigned int seg_not_present:1;
42 unsigned int useable:1;
46 .BR get_thread_area ()
47 reads the GDT entry indicated by
48 .I u_info\->entry_number
49 and fills in the rest of the fields in
52 .BR set_thread_area ()
53 sets a TLS entry in the GDT.
55 The TLS array entry set by
56 .BR set_thread_area ()
57 corresponds to the value of
58 .I u_info\->entry_number
59 passed in by the user.
60 If this value is in bounds,
61 .BR set_thread_area ()
62 writes the TLS descriptor pointed to by
64 into the thread's TLS array.
67 .BR set_thread_area ()
70 of \-1, it searches for a free TLS entry.
72 .BR set_thread_area ()
73 finds a free TLS entry, the value of
74 .I u_info\->entry_number
75 is set upon return to show which entry was changed.
79 is considered "empty" if
83 are set to 1 and all of the other fields are 0.
84 If an "empty" descriptor is passed to
86 the corresponding TLS entry will be cleared.
87 See BUGS for additional details.
90 .BR set_thread_area ()
91 cannot be used to write non-present segments, 16-bit segments, or code
92 segments, although clearing a segment is still acceptable.
95 return 0 on success, and \-1 on failure, with
101 \fIu_info\fP is an invalid pointer.
104 \fIu_info\->entry_number\fP is out of bounds.
107 .BR get_thread_area (2)
109 .BR set_thread_area (2)
110 was invoked as a 64-bit system call.
113 .RB ( set_thread_area ())
114 A free TLS entry could not be located.
116 .BR set_thread_area ()
117 first appeared in Linux 2.5.29.
118 .BR get_thread_area ()
119 first appeared in Linux 2.5.32.
121 .BR set_thread_area ()
122 is Linux-specific and should not be used in programs that are intended
125 Glibc does not provide wrappers for these system calls,
126 since they are generally intended for use only by threading libraries.
127 In the unlikely event that you want to call them directly, use
132 .BR set_thread_area (2).
136 This is not normally a problem, as
138 is normally used only by 64-bit programs.
140 On 64-bit kernels before Linux 3.19,
141 .\" commit e30ab185c490e9a9381385529e0fd32f0a399495
142 one of the padding bits in
144 if set, would prevent the descriptor from being considered empty (see
146 As a result, the only reliable way to clear a TLS entry is to use
150 structure, including padding bits, and then to set the
157 consisting entirely of zeros except for
159 will also be interpreted as a request to clear a TLS entry, but this
160 behaved differently on older kernels.
162 Prior to Linux 3.19, the DS and ES segment registers must not reference