1MODIFY_LDT(2)              Linux Programmer's Manual             MODIFY_LDT(2)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

84       This call is Linux-specific and should not be used in programs intended
85       to be portable.
86

NOTES

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

BUGS

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

SEE ALSO

110       arch_prctl(2), set_thread_area(2), vm86(2)
111

COLOPHON

113       This page is part of release 5.13 of the Linux  man-pages  project.   A
114       description  of  the project, information about reporting bugs, and the
115       latest    version    of    this    page,    can     be     found     at
116       https://www.kernel.org/doc/man-pages/.
117
118
119
120Linux                             2021-03-22                     MODIFY_LDT(2)
Impressum