]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/set_thread_area.2
dl_iterate_phdr.3: ffix
[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.\"
6d322d5f 9.TH SET_THREAD_AREA 2 2015-02-21 "Linux" "Linux Programmer's Manual"
fea681da 10.SH NAME
14620a25 11set_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
32.in +4n
14620a25
AL
33struct user_desc {
34 unsigned int entry_number;
35 unsigned long base_addr;
36 unsigned int limit;
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;
43};
14620a25 44.in
45c99e3e 45
14620a25
AL
46.BR get_thread_area ()
47reads the GDT entry indicated by
48.I u_info\->entry_number
49and fills in the rest of the fields in
52078966 50.IR u_info .
14620a25 51
e511ffb6 52.BR set_thread_area ()
14620a25
AL
53sets a TLS entry in the GDT.
54.PP
fea681da 55The TLS array entry set by
e511ffb6 56.BR set_thread_area ()
fea681da 57corresponds to the value of
94e9d9fe 58.I u_info\->entry_number
c13182ef
MK
59passed in by the user.
60If this value is in bounds,
e511ffb6 61.BR set_thread_area ()
14620a25 62writes the TLS descriptor pointed to by
fea681da
MK
63.I u_info
64into the thread's TLS array.
65.PP
66When
e511ffb6 67.BR set_thread_area ()
fea681da
MK
68is passed an
69.I entry_number
ed26cc5a 70of \-1, it searches for a free TLS entry.
c13182ef 71If
e511ffb6 72.BR set_thread_area ()
c13182ef 73finds a free TLS entry, the value of
94e9d9fe 74.I u_info\->entry_number
fea681da 75is set upon return to show which entry was changed.
14620a25
AL
76.PP
77A
78.I user_desc
79is considered "empty" if
80.I read_exec_only
81and
82.I seg_not_present
52078966
MK
83are set to 1 and all of the other fields are 0.
84If an "empty" descriptor is passed to
14620a25 85.BR set_thread_area,
52078966
MK
86the corresponding TLS entry will be cleared.
87See BUGS for additional details.
14620a25 88.PP
52078966 89Since Linux 3.19,
14620a25
AL
90.BR set_thread_area ()
91cannot be used to write non-present segments, 16-bit segments, or code
92segments, although clearing a segment is still acceptable.
47297adb 93.SH RETURN VALUE
52078966
MK
94These system calls
95return 0 on success, and \-1 on failure, with
fea681da
MK
96.I errno
97set appropriately.
47297adb 98.SH ERRORS
fea681da 99.TP
fea681da 100.B EFAULT
a8d55537 101\fIu_info\fP is an invalid pointer.
fea681da 102.TP
52078966
MK
103.B EINVAL
104\fIu_info\->entry_number\fP is out of bounds.
105.TP
14620a25
AL
106.B ENOSYS
107.BR get_thread_area (2)
108or
109.BR set_thread_area (2)
52078966
MK
110was invoked as a 64-bit system call.
111.TP
112.B ESRCH
113.RB ( set_thread_area ())
114A free TLS entry could not be located.
47297adb 115.SH VERSIONS
e511ffb6 116.BR set_thread_area ()
fea681da 117first appeared in Linux 2.5.29.
52078966
MK
118.BR get_thread_area ()
119first appeared in Linux 2.5.32.
47297adb 120.SH CONFORMING TO
a1d5f77c 121.BR set_thread_area ()
8382f16d 122is Linux-specific and should not be used in programs that are intended
a1d5f77c 123to be portable.
52078966
MK
124.SH NOTES
125Glibc does not provide wrappers for these system calls,
126since they are generally intended for use only by threading libraries.
127In the unlikely event that you want to call them directly, use
128.BR syscall (2).
129.PP
130.BR arch_prctl (2)
131can interfere with
132.BR set_thread_area (2).
133See
134.BR arch_prctl (2)
135for more details.
136This is not normally a problem, as
137.BR arch_prctl (2)
138is normally used only by 64-bit programs.
14620a25 139.SH BUGS
ed26cc5a
MK
140On 64-bit kernels before Linux 3.19,
141.\" commit e30ab185c490e9a9381385529e0fd32f0a399495
142one of the padding bits in
52078966 143.IR user_desc ,
ed26cc5a
MK
144if set, would prevent the descriptor from being considered empty (see
145.BR modify_ldt (2)).
14620a25 146As a result, the only reliable way to clear a TLS entry is to use
52078966
MK
147.BR memset (3)
148to zero the entire
14620a25
AL
149.I user_desc
150structure, including padding bits, and then to set the
151.I read_exec_only
152and
153.I seg_not_present
52078966
MK
154bits.
155On Linux 3.19, a
14620a25
AL
156.I user_desc
157consisting entirely of zeros except for
158.I entry_number
159will also be interpreted as a request to clear a TLS entry, but this
160behaved differently on older kernels.
161.PP
162Prior to Linux 3.19, the DS and ES segment registers must not reference
163TLS entries.
47297adb 164.SH SEE ALSO
14620a25
AL
165.BR arch_prctl (2),
166.BR modify_ldt (2)