]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/set_thread_area.2
mdoc.7: wfix
[thirdparty/man-pages.git] / man2 / set_thread_area.2
CommitLineData
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 11get_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 :
22There are no glibc wrappers for these system calls; see NOTES.
23.SH DESCRIPTION
24Linux dedicates three global descriptor table (GDT) entries for
25thread-local storage.
26For more information about the GDT, see the
27Intel Software Developer's Manual or the AMD Architecture Programming Manual.
28
29Both of these system calls take an argument that is a pointer
30to a structure of the following type:
31
758b35da 32.nf
52078966 33.in +4n
14620a25
AL
34struct 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 ()
49reads the GDT entry indicated by
50.I u_info\->entry_number
51and fills in the rest of the fields in
52078966 52.IR u_info .
14620a25 53
e511ffb6 54.BR set_thread_area ()
14620a25
AL
55sets a TLS entry in the GDT.
56.PP
fea681da 57The TLS array entry set by
e511ffb6 58.BR set_thread_area ()
fea681da 59corresponds to the value of
94e9d9fe 60.I u_info\->entry_number
c13182ef
MK
61passed in by the user.
62If this value is in bounds,
e511ffb6 63.BR set_thread_area ()
14620a25 64writes the TLS descriptor pointed to by
fea681da
MK
65.I u_info
66into the thread's TLS array.
67.PP
68When
e511ffb6 69.BR set_thread_area ()
fea681da
MK
70is passed an
71.I entry_number
ed26cc5a 72of \-1, it searches for a free TLS entry.
c13182ef 73If
e511ffb6 74.BR set_thread_area ()
c13182ef 75finds a free TLS entry, the value of
94e9d9fe 76.I u_info\->entry_number
fea681da 77is set upon return to show which entry was changed.
14620a25
AL
78.PP
79A
80.I user_desc
81is considered "empty" if
82.I read_exec_only
83and
84.I seg_not_present
52078966
MK
85are set to 1 and all of the other fields are 0.
86If an "empty" descriptor is passed to
14620a25 87.BR set_thread_area,
52078966
MK
88the corresponding TLS entry will be cleared.
89See BUGS for additional details.
14620a25 90.PP
52078966 91Since Linux 3.19,
14620a25
AL
92.BR set_thread_area ()
93cannot be used to write non-present segments, 16-bit segments, or code
94segments, although clearing a segment is still acceptable.
47297adb 95.SH RETURN VALUE
52078966
MK
96These system calls
97return 0 on success, and \-1 on failure, with
fea681da
MK
98.I errno
99set 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 110or
bf7bc8b8 111.BR set_thread_area ()
52078966
MK
112was invoked as a 64-bit system call.
113.TP
114.B ESRCH
115.RB ( set_thread_area ())
116A free TLS entry could not be located.
47297adb 117.SH VERSIONS
e511ffb6 118.BR set_thread_area ()
fea681da 119first appeared in Linux 2.5.29.
52078966
MK
120.BR get_thread_area ()
121first appeared in Linux 2.5.32.
47297adb 122.SH CONFORMING TO
a1d5f77c 123.BR set_thread_area ()
8382f16d 124is Linux-specific and should not be used in programs that are intended
a1d5f77c 125to be portable.
52078966
MK
126.SH NOTES
127Glibc does not provide wrappers for these system calls,
128since they are generally intended for use only by threading libraries.
129In the unlikely event that you want to call them directly, use
130.BR syscall (2).
131.PP
132.BR arch_prctl (2)
133can interfere with
bf7bc8b8 134.BR set_thread_area ().
52078966
MK
135See
136.BR arch_prctl (2)
137for more details.
138This is not normally a problem, as
139.BR arch_prctl (2)
140is normally used only by 64-bit programs.
14620a25 141.SH BUGS
ed26cc5a
MK
142On 64-bit kernels before Linux 3.19,
143.\" commit e30ab185c490e9a9381385529e0fd32f0a399495
144one of the padding bits in
52078966 145.IR user_desc ,
ed26cc5a
MK
146if set, would prevent the descriptor from being considered empty (see
147.BR modify_ldt (2)).
14620a25 148As a result, the only reliable way to clear a TLS entry is to use
52078966
MK
149.BR memset (3)
150to zero the entire
14620a25
AL
151.I user_desc
152structure, including padding bits, and then to set the
153.I read_exec_only
154and
155.I seg_not_present
52078966
MK
156bits.
157On Linux 3.19, a
14620a25
AL
158.I user_desc
159consisting entirely of zeros except for
160.I entry_number
161will also be interpreted as a request to clear a TLS entry, but this
162behaved differently on older kernels.
163.PP
164Prior to Linux 3.19, the DS and ES segment registers must not reference
165TLS entries.
47297adb 166.SH SEE ALSO
14620a25
AL
167.BR arch_prctl (2),
168.BR modify_ldt (2)