1modify_ldt(2)                 System Calls Manual                modify_ldt(2)
2
3
4

NAME

6       modify_ldt - get or set a per-process LDT entry
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <asm/ldt.h>         /* Definition of struct user_desc */
13       #include <sys/syscall.h>     /* Definition of SYS_* constants */
14       #include <unistd.h>
15
16       int syscall(SYS_modify_ldt, int func, void ptr[.bytecount],
17                   unsigned long bytecount);
18
19       Note: glibc provides no wrapper for modify_ldt(), necessitating the use
20       of syscall(2).
21

DESCRIPTION

23       modify_ldt() reads or writes the local descriptor  table  (LDT)  for  a
24       process.  The LDT is an array of segment descriptors that can be refer‐
25       enced by user code.  Linux allows processes to configure a  per-process
26       (actually per-mm) LDT.  For more information about the LDT, see the In‐
27       tel Software Developer's Manual or  the  AMD  Architecture  Programming
28       Manual.
29
30       When  func  is 0, modify_ldt() reads the LDT into the memory pointed to
31       by ptr.  The number of bytes read is the smaller of bytecount  and  the
32       actual  size  of the LDT, although the kernel may act as though the LDT
33       is padded with  additional  trailing  zero  bytes.   On  success,  mod‐
34       ify_ldt() will return the number of bytes read.
35
36       When  func  is 1 or 0x11, modify_ldt() modifies the LDT entry indicated
37       by ptr->entry_number.  ptr points to a user_desc  structure  and  byte‐
38       count must equal the size of this structure.
39
40       The user_desc structure is defined in <asm/ldt.h> as:
41
42           struct user_desc {
43               unsigned int  entry_number;
44               unsigned int  base_addr;
45               unsigned int  limit;
46               unsigned int  seg_32bit:1;
47               unsigned int  contents:2;
48               unsigned int  read_exec_only:1;
49               unsigned int  limit_in_pages:1;
50               unsigned int  seg_not_present:1;
51               unsigned int  useable:1;
52           };
53
54       In Linux 2.4 and earlier, this structure was named modify_ldt_ldt_s.
55
56       The  contents  field  is the segment type (data, expand-down data, non-
57       conforming code, or conforming code).  The other fields match their de‐
58       scriptions  in  the  CPU  manual,  although modify_ldt() cannot set the
59       hardware-defined "accessed" bit described in the CPU manual.
60
61       A user_desc is considered "empty" if read_exec_only and seg_not_present
62       are  set  to  1 and all of the other fields are 0.  An LDT entry can be
63       cleared by setting it to an "empty" user_desc or, if func is 1, by set‐
64       ting both base and limit to 0.
65
66       A conforming code segment (i.e., one with contents==3) will be rejected
67       if func is 1 or if seg_not_present is 0.
68
69       When func is 2, modify_ldt() will read zeros.  This  appears  to  be  a
70       leftover from Linux 2.4.
71

RETURN VALUE

73       On success, modify_ldt() returns either the actual number of bytes read
74       (for reading) or 0 (for writing).  On failure, modify_ldt() returns  -1
75       and sets errno to indicate the error.
76

ERRORS

78       EFAULT ptr points outside the address space.
79
80       EINVAL ptr is 0, or func is 1 and bytecount is not equal to the size of
81              the structure user_desc, or func is 1 or 0x11 and  the  new  LDT
82              entry has invalid values.
83
84       ENOSYS func is neither 0, 1, 2, nor 0x11.
85

STANDARDS

87       Linux.
88

NOTES

90       modify_ldt()  should  not be used for thread-local storage, as it slows
91       down context switches and only supports a limited  number  of  threads.
92       Threading  libraries should use set_thread_area(2) or arch_prctl(2) in‐
93       stead, except on extremely old kernels that do not support those system
94       calls.
95
96       The  normal  use  for modify_ldt() is to run legacy 16-bit or segmented
97       32-bit code.  Not all kernels allow 16-bit segments  to  be  installed,
98       however.
99
100       Even  on  64-bit  kernels, modify_ldt() cannot be used to create a long
101       mode (i.e., 64-bit) code  segment.   The  undocumented  field  "lm"  in
102       user_desc  is  not  useful, and, despite its name, does not result in a
103       long mode segment.
104

BUGS

106       On 64-bit kernels before Linux 3.19, setting the "lm" bit in  user_desc
107       prevents the descriptor from being considered empty.  Keep in mind that
108       the "lm" bit does not exist in the 32-bit headers, but these buggy ker‐
109       nels will still notice the bit even when set in a 32-bit process.
110

SEE ALSO

112       arch_prctl(2), set_thread_area(2), vm86(2)
113
114
115
116Linux man-pages 6.04              2023-03-30                     modify_ldt(2)
Impressum