1 .\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995.
2 .\" Copyright (c) 2015 Andrew Lutomirski
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .TH MODIFY_LDT 2 2021-03-22 "Linux man-pages (unreleased)"
8 modify_ldt \- get or set a per-process LDT entry
11 .RI ( libc ", " \-lc )
14 .BR "#include <asm/ldt.h>" " /* Definition of " "struct user_desc" " */"
15 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
16 .B #include <unistd.h>
18 .BI "int syscall(SYS_modify_ldt, int " func ", void *" ptr ,
19 .BI " unsigned long " bytecount );
23 glibc provides no wrapper for
25 necessitating the use of
29 reads or writes the local descriptor table (LDT) for a process.
31 is an array of segment descriptors that can be referenced by user code.
32 Linux allows processes to configure a per-process (actually per-mm) LDT.
33 For more information about the LDT, see the Intel Software Developer's
34 Manual or the AMD Architecture Programming Manual.
40 reads the LDT into the memory pointed to by
42 The number of bytes read is the smaller of
44 and the actual size of the LDT, although the kernel may act as though
45 the LDT is padded with additional trailing zero bytes.
48 will return the number of bytes read.
54 modifies the LDT entry indicated by
55 .IR ptr\->entry_number .
62 must equal the size of this structure.
66 structure is defined in \fI<asm/ldt.h>\fP as:
71 unsigned int entry_number;
72 unsigned int base_addr;
74 unsigned int seg_32bit:1;
75 unsigned int contents:2;
76 unsigned int read_exec_only:1;
77 unsigned int limit_in_pages:1;
78 unsigned int seg_not_present:1;
79 unsigned int useable:1;
84 In Linux 2.4 and earlier, this structure was named
85 .IR modify_ldt_ldt_s .
89 field is the segment type (data, expand-down data, non-conforming code, or
91 The other fields match their descriptions in the CPU manual, although
93 cannot set the hardware-defined "accessed" bit described in the CPU manual.
97 is considered "empty" if
101 are set to 1 and all of the other fields are 0.
102 An LDT entry can be cleared by setting it to an "empty"
106 is 1, by setting both
112 A conforming code segment (i.e., one with
126 This appears to be a leftover from Linux 2.4.
130 returns either the actual number of bytes read (for reading)
136 to indicate the error.
141 points outside the address space.
150 is not equal to the size of the structure
154 is 1 or 0x11 and the new LDT entry has invalid values.
158 is neither 0, 1, 2, nor 0x11.
160 This call is Linux-specific and should not be used in programs intended
164 should not be used for thread-local storage, as it slows down context
165 switches and only supports a limited number of threads.
166 Threading libraries should use
167 .BR set_thread_area (2)
170 instead, except on extremely old kernels that do not support those system
175 is to run legacy 16-bit or segmented 32-bit code.
176 Not all kernels allow 16-bit segments to be installed, however.
178 Even on 64-bit kernels,
180 cannot be used to create a long mode (i.e., 64-bit) code segment.
181 The undocumented field "lm" in
183 is not useful, and, despite its name,
184 does not result in a long mode segment.
186 On 64-bit kernels before Linux 3.19,
187 .\" commit e30ab185c490e9a9381385529e0fd32f0a399495
188 setting the "lm" bit in
190 prevents the descriptor from being considered empty.
191 Keep in mind that the
192 "lm" bit does not exist in the 32-bit headers, but these buggy kernels
193 will still notice the bit even when set in a 32-bit process.
196 .BR set_thread_area (2),