]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/modify_ldt.2
user_namespaces.7: Minor rewordings of recently added text
[thirdparty/man-pages.git] / man2 / modify_ldt.2
1 .\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995.
2 .\" Copyright (c) 2015 Andrew Lutomirski
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MODIFY_LDT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 modify_ldt \- get or set a per-process LDT entry
28 .SH SYNOPSIS
29 .nf
30 .B #include <sys/types.h>
31 .PP
32 .BI "int modify_ldt(int " func ", void *" ptr ", unsigned long " bytecount );
33 .fi
34 .PP
35 .IR Note :
36 There is no glibc wrapper for this system call; see NOTES.
37 .SH DESCRIPTION
38 .BR modify_ldt ()
39 reads or writes the local descriptor table (LDT) for a process.
40 The LDT
41 is an array of segment descriptors that can be referenced by user code.
42 Linux allows processes to configure a per-process (actually per-mm) LDT.
43 For more information about the LDT, see the Intel Software Developer's
44 Manual or the AMD Architecture Programming Manual.
45 .PP
46 When
47 .I func
48 is 0,
49 .BR modify_ldt ()
50 reads the LDT into the memory pointed to by
51 .IR ptr .
52 The number of bytes read is the smaller of
53 .I bytecount
54 and the actual size of the LDT, although the kernel may act as though
55 the LDT is padded with additional trailing zero bytes.
56 On success,
57 .BR modify_ldt ()
58 will return the number of bytes read.
59 .PP
60 When
61 .I func
62 is 1 or 0x11,
63 .BR modify_ldt ()
64 modifies the LDT entry indicated by
65 .IR ptr\->entry_number .
66 .I ptr
67 points to a
68 .I user_desc
69 structure
70 and
71 .I bytecount
72 must equal the size of this structure.
73 .PP
74 The
75 .I user_desc
76 structure is defined in \fI<asm/ldt.h>\fP as:
77 .PP
78 .in +4n
79 .EX
80 struct user_desc {
81 unsigned int entry_number;
82 unsigned long base_addr;
83 unsigned int limit;
84 unsigned int seg_32bit:1;
85 unsigned int contents:2;
86 unsigned int read_exec_only:1;
87 unsigned int limit_in_pages:1;
88 unsigned int seg_not_present:1;
89 unsigned int useable:1;
90 };
91 .EE
92 .in
93 .PP
94 In Linux 2.4 and earlier, this structure was named
95 .IR modify_ldt_ldt_s .
96 .PP
97 The
98 .I contents
99 field is the segment type (data, expand-down data, non-conforming code, or
100 conforming code).
101 The other fields match their descriptions in the CPU manual, although
102 .BR modify_ldt ()
103 cannot set the hardware-defined "accessed" bit described in the CPU manual.
104 .PP
105 A
106 .I user_desc
107 is considered "empty" if
108 .I read_exec_only
109 and
110 .I seg_not_present
111 are set to 1 and all of the other fields are 0.
112 An LDT entry can be cleared by setting it to an "empty"
113 .I user_desc
114 or, if
115 .I func
116 is 1, by setting both
117 .I base
118 and
119 .I limit
120 to 0.
121 .PP
122 A conforming code segment (i.e., one with
123 .IR contents==3 )
124 will be rejected if
125 .I
126 func
127 is 1 or if
128 .I seg_not_present
129 is 0.
130 .PP
131 When
132 .I func
133 is 2,
134 .BR modify_ldt ()
135 will read zeros.
136 This appears to be a leftover from Linux 2.4.
137 .SH RETURN VALUE
138 On success,
139 .BR modify_ldt ()
140 returns either the actual number of bytes read (for reading)
141 or 0 (for writing).
142 On failure,
143 .BR modify_ldt ()
144 returns \-1 and sets
145 .I errno
146 to indicate the error.
147 .SH ERRORS
148 .TP
149 .B EFAULT
150 .I ptr
151 points outside the address space.
152 .TP
153 .B EINVAL
154 .I ptr
155 is 0,
156 or
157 .I func
158 is 1 and
159 .I bytecount
160 is not equal to the size of the structure
161 .IR user_desc ,
162 or
163 .I func
164 is 1 or 0x11 and the new LDT entry has invalid values.
165 .TP
166 .B ENOSYS
167 .I func
168 is neither 0, 1, 2, nor 0x11.
169 .SH CONFORMING TO
170 This call is Linux-specific and should not be used in programs intended
171 to be portable.
172 .SH NOTES
173 Glibc does not provide a wrapper for this system call; call it using
174 .BR syscall (2).
175 .PP
176 .BR modify_ldt ()
177 should not be used for thread-local storage, as it slows down context
178 switches and only supports a limited number of threads.
179 Threading libraries should use
180 .BR set_thread_area (2)
181 or
182 .BR arch_prctl (2)
183 instead, except on extremely old kernels that do not support those system
184 calls.
185 .PP
186 The normal use for
187 .BR modify_ldt ()
188 is to run legacy 16-bit or segmented 32-bit code.
189 Not all kernels allow 16-bit segments to be installed, however.
190 .PP
191 Even on 64-bit kernels,
192 .BR modify_ldt ()
193 cannot be used to create a long mode (i.e., 64-bit) code segment.
194 The undocumented field "lm" in
195 .IR user_desc
196 is not useful, and, despite its name,
197 does not result in a long mode segment.
198 .SH BUGS
199 On 64-bit kernels before Linux 3.19,
200 .\" commit e30ab185c490e9a9381385529e0fd32f0a399495
201 setting the "lm" bit in
202 .IR user_desc
203 prevents the descriptor from being considered empty.
204 Keep in mind that the
205 "lm" bit does not exist in the 32-bit headers, but these buggy kernels
206 will still notice the bit even when set in a 32-bit process.
207 .SH SEE ALSO
208 .BR arch_prctl (2),
209 .BR set_thread_area (2),
210 .BR vm86 (2)