]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright (C) 2003 Free Software Foundation, Inc. |
14620a25 | 2 | .\" Copyright (C) 2015 Andrew Lutomirski |
86d38ba3 | 3 | .\" Author: Kent Yoder |
2297bf0e | 4 | .\" |
fd0fc519 | 5 | .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE) |
fea681da | 6 | .\" This file is distributed according to the GNU General Public License. |
fd0fc519 | 7 | .\" %%%LICENSE_END |
fea681da | 8 | .\" |
b8efb414 | 9 | .TH SET_THREAD_AREA 2 2016-10-08 "Linux" "Linux Programmer's Manual" |
fea681da | 10 | .SH NAME |
84e98441 | 11 | get_thread_area, set_thread_area \- set a GDT entry for thread-local storage |
47297adb | 12 | .SH SYNOPSIS |
52078966 | 13 | .nf |
fea681da | 14 | .B #include <linux/unistd.h> |
fea681da | 15 | .B #include <asm/ldt.h> |
52078966 | 16 | |
14620a25 | 17 | .BI "int get_thread_area(struct user_desc *" u_info ); |
b9f02710 | 18 | .BI "int set_thread_area(struct user_desc *" u_info ); |
52078966 | 19 | .fi |
14620a25 | 20 | |
52078966 MK |
21 | .IR Note : |
22 | There are no glibc wrappers for these system calls; see NOTES. | |
23 | .SH DESCRIPTION | |
24 | Linux dedicates three global descriptor table (GDT) entries for | |
25 | thread-local storage. | |
26 | For more information about the GDT, see the | |
27 | Intel Software Developer's Manual or the AMD Architecture Programming Manual. | |
28 | ||
29 | Both of these system calls take an argument that is a pointer | |
30 | to a structure of the following type: | |
31 | ||
758b35da | 32 | .nf |
52078966 | 33 | .in +4n |
14620a25 AL |
34 | struct user_desc { |
35 | unsigned int entry_number; | |
36 | unsigned long base_addr; | |
37 | unsigned int limit; | |
38 | unsigned int seg_32bit:1; | |
39 | unsigned int contents:2; | |
40 | unsigned int read_exec_only:1; | |
41 | unsigned int limit_in_pages:1; | |
42 | unsigned int seg_not_present:1; | |
43 | unsigned int useable:1; | |
44 | }; | |
14620a25 | 45 | .in |
758b35da | 46 | .fi |
45c99e3e | 47 | |
14620a25 AL |
48 | .BR get_thread_area () |
49 | reads the GDT entry indicated by | |
50 | .I u_info\->entry_number | |
51 | and fills in the rest of the fields in | |
52078966 | 52 | .IR u_info . |
14620a25 | 53 | |
e511ffb6 | 54 | .BR set_thread_area () |
14620a25 AL |
55 | sets a TLS entry in the GDT. |
56 | .PP | |
fea681da | 57 | The TLS array entry set by |
e511ffb6 | 58 | .BR set_thread_area () |
fea681da | 59 | corresponds to the value of |
94e9d9fe | 60 | .I u_info\->entry_number |
c13182ef MK |
61 | passed in by the user. |
62 | If this value is in bounds, | |
e511ffb6 | 63 | .BR set_thread_area () |
14620a25 | 64 | writes the TLS descriptor pointed to by |
fea681da MK |
65 | .I u_info |
66 | into the thread's TLS array. | |
67 | .PP | |
68 | When | |
e511ffb6 | 69 | .BR set_thread_area () |
fea681da MK |
70 | is passed an |
71 | .I entry_number | |
ed26cc5a | 72 | of \-1, it searches for a free TLS entry. |
c13182ef | 73 | If |
e511ffb6 | 74 | .BR set_thread_area () |
c13182ef | 75 | finds a free TLS entry, the value of |
94e9d9fe | 76 | .I u_info\->entry_number |
fea681da | 77 | is set upon return to show which entry was changed. |
14620a25 AL |
78 | .PP |
79 | A | |
80 | .I user_desc | |
81 | is considered "empty" if | |
82 | .I read_exec_only | |
83 | and | |
84 | .I seg_not_present | |
52078966 MK |
85 | are set to 1 and all of the other fields are 0. |
86 | If an "empty" descriptor is passed to | |
14620a25 | 87 | .BR set_thread_area, |
52078966 MK |
88 | the corresponding TLS entry will be cleared. |
89 | See BUGS for additional details. | |
14620a25 | 90 | .PP |
52078966 | 91 | Since Linux 3.19, |
14620a25 AL |
92 | .BR set_thread_area () |
93 | cannot be used to write non-present segments, 16-bit segments, or code | |
94 | segments, although clearing a segment is still acceptable. | |
47297adb | 95 | .SH RETURN VALUE |
52078966 MK |
96 | These system calls |
97 | return 0 on success, and \-1 on failure, with | |
fea681da MK |
98 | .I errno |
99 | set appropriately. | |
47297adb | 100 | .SH ERRORS |
fea681da | 101 | .TP |
fea681da | 102 | .B EFAULT |
a8d55537 | 103 | \fIu_info\fP is an invalid pointer. |
fea681da | 104 | .TP |
52078966 MK |
105 | .B EINVAL |
106 | \fIu_info\->entry_number\fP is out of bounds. | |
107 | .TP | |
14620a25 | 108 | .B ENOSYS |
bf7bc8b8 | 109 | .BR get_thread_area () |
14620a25 | 110 | or |
bf7bc8b8 | 111 | .BR set_thread_area () |
52078966 MK |
112 | was invoked as a 64-bit system call. |
113 | .TP | |
114 | .B ESRCH | |
115 | .RB ( set_thread_area ()) | |
116 | A free TLS entry could not be located. | |
47297adb | 117 | .SH VERSIONS |
e511ffb6 | 118 | .BR set_thread_area () |
fea681da | 119 | first appeared in Linux 2.5.29. |
52078966 MK |
120 | .BR get_thread_area () |
121 | first appeared in Linux 2.5.32. | |
47297adb | 122 | .SH CONFORMING TO |
a1d5f77c | 123 | .BR set_thread_area () |
8382f16d | 124 | is Linux-specific and should not be used in programs that are intended |
a1d5f77c | 125 | to be portable. |
52078966 MK |
126 | .SH NOTES |
127 | Glibc does not provide wrappers for these system calls, | |
128 | since they are generally intended for use only by threading libraries. | |
129 | In the unlikely event that you want to call them directly, use | |
130 | .BR syscall (2). | |
131 | .PP | |
132 | .BR arch_prctl (2) | |
133 | can interfere with | |
bf7bc8b8 | 134 | .BR set_thread_area (). |
52078966 MK |
135 | See |
136 | .BR arch_prctl (2) | |
137 | for more details. | |
138 | This is not normally a problem, as | |
139 | .BR arch_prctl (2) | |
140 | is normally used only by 64-bit programs. | |
14620a25 | 141 | .SH BUGS |
ed26cc5a MK |
142 | On 64-bit kernels before Linux 3.19, |
143 | .\" commit e30ab185c490e9a9381385529e0fd32f0a399495 | |
144 | one of the padding bits in | |
52078966 | 145 | .IR user_desc , |
ed26cc5a MK |
146 | if set, would prevent the descriptor from being considered empty (see |
147 | .BR modify_ldt (2)). | |
14620a25 | 148 | As a result, the only reliable way to clear a TLS entry is to use |
52078966 MK |
149 | .BR memset (3) |
150 | to zero the entire | |
14620a25 AL |
151 | .I user_desc |
152 | structure, including padding bits, and then to set the | |
153 | .I read_exec_only | |
154 | and | |
155 | .I seg_not_present | |
52078966 MK |
156 | bits. |
157 | On Linux 3.19, a | |
14620a25 AL |
158 | .I user_desc |
159 | consisting entirely of zeros except for | |
160 | .I entry_number | |
161 | will also be interpreted as a request to clear a TLS entry, but this | |
162 | behaved differently on older kernels. | |
163 | .PP | |
164 | Prior to Linux 3.19, the DS and ES segment registers must not reference | |
165 | TLS entries. | |
47297adb | 166 | .SH SEE ALSO |
14620a25 AL |
167 | .BR arch_prctl (2), |
168 | .BR modify_ldt (2) |