]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995. |
38f7c379 | 2 | .\" Copyright (c) 2015 Andrew Lutomirski |
fea681da | 3 | .\" |
1dd72f9c | 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) |
fea681da MK |
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 | |
c715f741 MK |
21 | .\" License along with this manual; if not, see |
22 | .\" <http://www.gnu.org/licenses/>. | |
6a8d8745 | 23 | .\" %%%LICENSE_END |
fea681da | 24 | .\" |
6b621d05 | 25 | .TH MODIFY_LDT 2 2020-02-09 "Linux" "Linux Programmer's Manual" |
fea681da | 26 | .SH NAME |
38f7c379 | 27 | modify_ldt \- get or set a per-process LDT entry |
fea681da | 28 | .SH SYNOPSIS |
16718a1c | 29 | .nf |
527d9933 | 30 | .B #include <sys/types.h> |
68e4db0a | 31 | .PP |
7acf749e | 32 | .BI "int modify_ldt(int " func ", void *" ptr ", unsigned long " bytecount ); |
16718a1c | 33 | .fi |
38f7c379 | 34 | .PP |
45c99e3e MK |
35 | .IR Note : |
36 | There is no glibc wrapper for this system call; see NOTES. | |
fea681da | 37 | .SH DESCRIPTION |
e511ffb6 | 38 | .BR modify_ldt () |
7acf749e MK |
39 | reads or writes the local descriptor table (LDT) for a process. |
40 | The LDT | |
38f7c379 AL |
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. | |
fea681da MK |
45 | .PP |
46 | When | |
47 | .I func | |
48 | is 0, | |
e511ffb6 | 49 | .BR modify_ldt () |
38f7c379 | 50 | reads the LDT into the memory pointed to by |
fea681da MK |
51 | .IR ptr . |
52 | The number of bytes read is the smaller of | |
53 | .I bytecount | |
38f7c379 | 54 | and the actual size of the LDT, although the kernel may act as though |
7acf749e MK |
55 | the LDT is padded with additional trailing zero bytes. |
56 | On success, | |
38f7c379 AL |
57 | .BR modify_ldt () |
58 | will return the number of bytes read. | |
fea681da MK |
59 | .PP |
60 | When | |
61 | .I func | |
38f7c379 | 62 | is 1 or 0x11, |
e511ffb6 | 63 | .BR modify_ldt () |
38f7c379 | 64 | modifies the LDT entry indicated by |
7acf749e | 65 | .IR ptr\->entry_number . |
fea681da MK |
66 | .I ptr |
67 | points to a | |
5a16bf48 MK |
68 | .I user_desc |
69 | structure | |
70 | and | |
fea681da MK |
71 | .I bytecount |
72 | must equal the size of this structure. | |
efeece04 | 73 | .PP |
5a16bf48 MK |
74 | The |
75 | .I user_desc | |
c84371c6 | 76 | structure is defined in \fI<asm/ldt.h>\fP as: |
e646a1ba | 77 | .PP |
088a639b | 78 | .in +4n |
e646a1ba | 79 | .EX |
5a16bf48 MK |
80 | struct user_desc { |
81 | unsigned int entry_number; | |
59b191dc | 82 | unsigned int base_addr; |
5a16bf48 MK |
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 | }; | |
b8302363 | 91 | .EE |
5a16bf48 MK |
92 | .in |
93 | .PP | |
94 | In Linux 2.4 and earlier, this structure was named | |
95 | .IR modify_ldt_ldt_s . | |
38f7c379 AL |
96 | .PP |
97 | The | |
98 | .I contents | |
99 | field is the segment type (data, expand-down data, non-conforming code, or | |
7acf749e MK |
100 | conforming code). |
101 | The other fields match their descriptions in the CPU manual, although | |
38f7c379 | 102 | .BR modify_ldt () |
c79a3031 | 103 | cannot set the hardware-defined "accessed" bit described in the CPU manual. |
38f7c379 AL |
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 | |
c79a3031 MK |
122 | A conforming code segment (i.e., one with |
123 | .IR contents==3 ) | |
124 | will be rejected if | |
38f7c379 AL |
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 () | |
7acf749e MK |
135 | will read zeros. |
136 | This appears to be a leftover from Linux 2.4. | |
47297adb | 137 | .SH RETURN VALUE |
fea681da | 138 | On success, |
e511ffb6 | 139 | .BR modify_ldt () |
fea681da MK |
140 | returns either the actual number of bytes read (for reading) |
141 | or 0 (for writing). | |
142 | On failure, | |
e511ffb6 | 143 | .BR modify_ldt () |
fea681da | 144 | returns \-1 and sets |
0daa9e92 | 145 | .I errno |
5a16bf48 | 146 | to indicate the error. |
fea681da MK |
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 | |
38f7c379 | 161 | .IR user_desc , |
fea681da MK |
162 | or |
163 | .I func | |
7acf749e | 164 | is 1 or 0x11 and the new LDT entry has invalid values. |
fea681da MK |
165 | .TP |
166 | .B ENOSYS | |
167 | .I func | |
38f7c379 | 168 | is neither 0, 1, 2, nor 0x11. |
47297adb | 169 | .SH CONFORMING TO |
8382f16d | 170 | This call is Linux-specific and should not be used in programs intended |
fea681da | 171 | to be portable. |
c12fd10d MK |
172 | .SH NOTES |
173 | Glibc does not provide a wrapper for this system call; call it using | |
174 | .BR syscall (2). | |
38f7c379 AL |
175 | .PP |
176 | .BR modify_ldt () | |
177 | should not be used for thread-local storage, as it slows down context | |
7acf749e MK |
178 | switches and only supports a limited number of threads. |
179 | Threading libraries should use | |
38f7c379 AL |
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 | |
bf7bc8b8 | 187 | .BR modify_ldt () |
7acf749e MK |
188 | is to run legacy 16-bit or segmented 32-bit code. |
189 | Not all kernels allow 16-bit segments to be installed, however. | |
f89f50fa AL |
190 | .PP |
191 | Even on 64-bit kernels, | |
bf7bc8b8 | 192 | .BR modify_ldt () |
6da93ae6 MK |
193 | cannot be used to create a long mode (i.e., 64-bit) code segment. |
194 | The undocumented field "lm" in | |
f89f50fa | 195 | .IR user_desc |
6da93ae6 MK |
196 | is not useful, and, despite its name, |
197 | does not result in a long mode segment. | |
7acf749e | 198 | .SH BUGS |
c79a3031 MK |
199 | On 64-bit kernels before Linux 3.19, |
200 | .\" commit e30ab185c490e9a9381385529e0fd32f0a399495 | |
f89f50fa | 201 | setting the "lm" bit in |
c79a3031 | 202 | .IR user_desc |
6da93ae6 MK |
203 | prevents the descriptor from being considered empty. |
204 | Keep in mind that the | |
f89f50fa AL |
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. | |
47297adb | 207 | .SH SEE ALSO |
38f7c379 | 208 | .BR arch_prctl (2), |
7acf749e | 209 | .BR set_thread_area (2), |
fea681da | 210 | .BR vm86 (2) |