1MODIFY_LDT(2) Linux Programmer's Manual MODIFY_LDT(2)
2
3
4
6 modify_ldt - get or set a per-process LDT entry
7
9 #include <sys/types.h>
10
11 int modify_ldt(int func, void *ptr, unsigned long bytecount);
12
13 Note: There is no glibc wrapper for this system call; see NOTES.
14
16 modify_ldt() reads or writes the local descriptor table (LDT) for a
17 process. The LDT is an array of segment descriptors that can be refer‐
18 enced by user code. Linux allows processes to configure a per-process
19 (actually per-mm) LDT. For more information about the LDT, see the
20 Intel Software Developer's Manual or the AMD Architecture Programming
21 Manual.
22
23 When func is 0, modify_ldt() reads the LDT into the memory pointed to
24 by ptr. The number of bytes read is the smaller of bytecount and the
25 actual size of the LDT, although the kernel may act as though the LDT
26 is padded with additional trailing zero bytes. On success, mod‐
27 ify_ldt() will return the number of bytes read.
28
29 When func is 1 or 0x11, modify_ldt() modifies the LDT entry indicated
30 by ptr->entry_number. ptr points to a user_desc structure and byte‐
31 count must equal the size of this structure.
32
33 The user_desc structure is defined in <asm/ldt.h> as:
34
35 struct user_desc {
36 unsigned int entry_number;
37 unsigned int base_addr;
38 unsigned int limit;
39 unsigned int seg_32bit:1;
40 unsigned int contents:2;
41 unsigned int read_exec_only:1;
42 unsigned int limit_in_pages:1;
43 unsigned int seg_not_present:1;
44 unsigned int useable:1;
45 };
46
47 In Linux 2.4 and earlier, this structure was named modify_ldt_ldt_s.
48
49 The contents field is the segment type (data, expand-down data, non-
50 conforming code, or conforming code). The other fields match their
51 descriptions in the CPU manual, although modify_ldt() cannot set the
52 hardware-defined "accessed" bit described in the CPU manual.
53
54 A user_desc is considered "empty" if read_exec_only and seg_not_present
55 are set to 1 and all of the other fields are 0. An LDT entry can be
56 cleared by setting it to an "empty" user_desc or, if func is 1, by set‐
57 ting both base and limit to 0.
58
59 A conforming code segment (i.e., one with contents==3) will be rejected
60 if func is 1 or if seg_not_present is 0.
61
62 When func is 2, modify_ldt() will read zeros. This appears to be a
63 leftover from Linux 2.4.
64
66 On success, modify_ldt() returns either the actual number of bytes read
67 (for reading) or 0 (for writing). On failure, modify_ldt() returns -1
68 and sets errno to indicate the error.
69
71 EFAULT ptr points outside the address space.
72
73 EINVAL ptr is 0, or func is 1 and bytecount is not equal to the size of
74 the structure user_desc, or func is 1 or 0x11 and the new LDT
75 entry has invalid values.
76
77 ENOSYS func is neither 0, 1, 2, nor 0x11.
78
80 This call is Linux-specific and should not be used in programs intended
81 to be portable.
82
84 Glibc does not provide a wrapper for this system call; call it using
85 syscall(2).
86
87 modify_ldt() should not be used for thread-local storage, as it slows
88 down context switches and only supports a limited number of threads.
89 Threading libraries should use set_thread_area(2) or arch_prctl(2)
90 instead, except on extremely old kernels that do not support those sys‐
91 tem calls.
92
93 The normal use for modify_ldt() is to run legacy 16-bit or segmented
94 32-bit code. Not all kernels allow 16-bit segments to be installed,
95 however.
96
97 Even on 64-bit kernels, modify_ldt() cannot be used to create a long
98 mode (i.e., 64-bit) code segment. The undocumented field "lm" in
99 user_desc is not useful, and, despite its name, does not result in a
100 long mode segment.
101
103 On 64-bit kernels before Linux 3.19, setting the "lm" bit in user_desc
104 prevents the descriptor from being considered empty. Keep in mind that
105 the "lm" bit does not exist in the 32-bit headers, but these buggy ker‐
106 nels will still notice the bit even when set in a 32-bit process.
107
109 arch_prctl(2), set_thread_area(2), vm86(2)
110
112 This page is part of release 5.07 of the Linux man-pages project. A
113 description of the project, information about reporting bugs, and the
114 latest version of this page, can be found at
115 https://www.kernel.org/doc/man-pages/.
116
117
118
119Linux 2020-02-09 MODIFY_LDT(2)