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 2021-03-22 "Linux" "Linux Programmer's Manual"
27 modify_ldt \- get or set a per-process LDT entry
30 .BR "#include <asm/ldt.h>" " /* Definition of " "struct user_desc" " */"
31 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
32 .B #include <unistd.h>
34 .BI "int syscall(SYS_modify_ldt, int " func ", void *" ptr ,
35 .BI " unsigned long " bytecount );
39 glibc provides no wrapper for
41 necessitating the use of
45 reads or writes the local descriptor table (LDT) for a process.
47 is an array of segment descriptors that can be referenced by user code.
48 Linux allows processes to configure a per-process (actually per-mm) LDT.
49 For more information about the LDT, see the Intel Software Developer's
50 Manual or the AMD Architecture Programming Manual.
56 reads the LDT into the memory pointed to by
58 The number of bytes read is the smaller of
60 and the actual size of the LDT, although the kernel may act as though
61 the LDT is padded with additional trailing zero bytes.
64 will return the number of bytes read.
70 modifies the LDT entry indicated by
71 .IR ptr\->entry_number .
78 must equal the size of this structure.
82 structure is defined in \fI<asm/ldt.h>\fP as:
87 unsigned int entry_number;
88 unsigned int base_addr;
90 unsigned int seg_32bit:1;
91 unsigned int contents:2;
92 unsigned int read_exec_only:1;
93 unsigned int limit_in_pages:1;
94 unsigned int seg_not_present:1;
95 unsigned int useable:1;
100 In Linux 2.4 and earlier, this structure was named
101 .IR modify_ldt_ldt_s .
105 field is the segment type (data, expand-down data, non-conforming code, or
107 The other fields match their descriptions in the CPU manual, although
109 cannot set the hardware-defined "accessed" bit described in the CPU manual.
113 is considered "empty" if
117 are set to 1 and all of the other fields are 0.
118 An LDT entry can be cleared by setting it to an "empty"
122 is 1, by setting both
128 A conforming code segment (i.e., one with
142 This appears to be a leftover from Linux 2.4.
146 returns either the actual number of bytes read (for reading)
152 to indicate the error.
157 points outside the address space.
166 is not equal to the size of the structure
170 is 1 or 0x11 and the new LDT entry has invalid values.
174 is neither 0, 1, 2, nor 0x11.
176 This call is Linux-specific and should not be used in programs intended
180 should not be used for thread-local storage, as it slows down context
181 switches and only supports a limited number of threads.
182 Threading libraries should use
183 .BR set_thread_area (2)
186 instead, except on extremely old kernels that do not support those system
191 is to run legacy 16-bit or segmented 32-bit code.
192 Not all kernels allow 16-bit segments to be installed, however.
194 Even on 64-bit kernels,
196 cannot be used to create a long mode (i.e., 64-bit) code segment.
197 The undocumented field "lm" in
199 is not useful, and, despite its name,
200 does not result in a long mode segment.
202 On 64-bit kernels before Linux 3.19,
203 .\" commit e30ab185c490e9a9381385529e0fd32f0a399495
204 setting the "lm" bit in
206 prevents the descriptor from being considered empty.
207 Keep in mind that the
208 "lm" bit does not exist in the 32-bit headers, but these buggy kernels
209 will still notice the bit even when set in a 32-bit process.
212 .BR set_thread_area (2),