1 .\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995.
2 .\" Copyright (c) 2015 Andrew Lutomirski
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.
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.
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.
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/>.
25 .TH MODIFY_LDT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
27 modify_ldt \- get or set a per-process LDT entry
30 .B #include <sys/types.h>
32 .BI "int modify_ldt(int " func ", void *" ptr ", unsigned long " bytecount );
36 There is no glibc wrapper for this system call; see NOTES.
39 reads or writes the local descriptor table (LDT) for a process.
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.
50 reads the LDT into the memory pointed to by
52 The number of bytes read is the smaller of
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.
58 will return the number of bytes read.
64 modifies the LDT entry indicated by
65 .IR ptr\->entry_number .
72 must equal the size of this structure.
76 structure is defined in \fI<asm/ldt.h>\fP as:
81 unsigned int entry_number;
82 unsigned long base_addr;
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;
94 In Linux 2.4 and earlier, this structure was named
95 .IR modify_ldt_ldt_s .
99 field is the segment type (data, expand-down data, non-conforming code, or
101 The other fields match their descriptions in the CPU manual, although
103 cannot set the hardware-defined "accessed" bit described in the CPU manual.
107 is considered "empty" if
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"
116 is 1, by setting both
122 A conforming code segment (i.e., one with
136 This appears to be a leftover from Linux 2.4.
140 returns either the actual number of bytes read (for reading)
146 to indicate the error.
151 points outside the address space.
160 is not equal to the size of the structure
164 is 1 or 0x11 and the new LDT entry has invalid values.
168 is neither 0, 1, 2, nor 0x11.
170 This call is Linux-specific and should not be used in programs intended
173 Glibc does not provide a wrapper for this system call; call it using
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)
183 instead, except on extremely old kernels that do not support those system
188 is to run legacy 16-bit or segmented 32-bit code.
189 Not all kernels allow 16-bit segments to be installed, however.
191 Even on 64-bit kernels,
193 cannot be used to create a long mode (i.e., 64-bit) code segment.
194 The undocumented field "lm" in
196 is not useful, and, despite its name,
197 does not result in a long mode segment.
199 On 64-bit kernels before Linux 3.19,
200 .\" commit e30ab185c490e9a9381385529e0fd32f0a399495
201 setting the "lm" bit in
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.
209 .BR set_thread_area (2),