]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/modify_ldt.2
mknod.2: tfix
[thirdparty/man-pages.git] / man2 / modify_ldt.2
CommitLineData
fea681da 1.\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995.
38f7c379 2.\" Copyright (c) 2015 Andrew Lutomirski
fea681da 3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
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.
9.\"
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.
14.\"
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.
19.\"
20.\" You should have received a copy of the GNU General Public
c715f741
MK
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
6a8d8745 23.\" %%%LICENSE_END
fea681da 24.\"
6b621d05 25.TH MODIFY_LDT 2 2020-02-09 "Linux" "Linux Programmer's Manual"
fea681da 26.SH NAME
38f7c379 27modify_ldt \- get or set a per-process LDT entry
fea681da 28.SH SYNOPSIS
16718a1c 29.nf
527d9933 30.B #include <sys/types.h>
68e4db0a 31.PP
7acf749e 32.BI "int modify_ldt(int " func ", void *" ptr ", unsigned long " bytecount );
16718a1c 33.fi
38f7c379 34.PP
45c99e3e
MK
35.IR Note :
36There is no glibc wrapper for this system call; see NOTES.
fea681da 37.SH DESCRIPTION
e511ffb6 38.BR modify_ldt ()
7acf749e
MK
39reads or writes the local descriptor table (LDT) for a process.
40The LDT
38f7c379
AL
41is an array of segment descriptors that can be referenced by user code.
42Linux allows processes to configure a per-process (actually per-mm) LDT.
43For more information about the LDT, see the Intel Software Developer's
44Manual or the AMD Architecture Programming Manual.
fea681da
MK
45.PP
46When
47.I func
48is 0,
e511ffb6 49.BR modify_ldt ()
38f7c379 50reads the LDT into the memory pointed to by
fea681da
MK
51.IR ptr .
52The number of bytes read is the smaller of
53.I bytecount
38f7c379 54and the actual size of the LDT, although the kernel may act as though
7acf749e
MK
55the LDT is padded with additional trailing zero bytes.
56On success,
38f7c379
AL
57.BR modify_ldt ()
58will return the number of bytes read.
fea681da
MK
59.PP
60When
61.I func
38f7c379 62is 1 or 0x11,
e511ffb6 63.BR modify_ldt ()
38f7c379 64modifies the LDT entry indicated by
7acf749e 65.IR ptr\->entry_number .
fea681da
MK
66.I ptr
67points to a
5a16bf48
MK
68.I user_desc
69structure
70and
fea681da
MK
71.I bytecount
72must equal the size of this structure.
efeece04 73.PP
5a16bf48
MK
74The
75.I user_desc
c84371c6 76structure is defined in \fI<asm/ldt.h>\fP as:
e646a1ba 77.PP
088a639b 78.in +4n
e646a1ba 79.EX
5a16bf48
MK
80struct user_desc {
81 unsigned int entry_number;
59b191dc 82 unsigned int base_addr;
5a16bf48
MK
83 unsigned int limit;
84 unsigned int seg_32bit:1;
85 unsigned int contents:2;
86 unsigned int read_exec_only:1;
87 unsigned int limit_in_pages:1;
88 unsigned int seg_not_present:1;
89 unsigned int useable:1;
90};
b8302363 91.EE
5a16bf48
MK
92.in
93.PP
94In Linux 2.4 and earlier, this structure was named
95.IR modify_ldt_ldt_s .
38f7c379
AL
96.PP
97The
98.I contents
99field is the segment type (data, expand-down data, non-conforming code, or
7acf749e
MK
100conforming code).
101The other fields match their descriptions in the CPU manual, although
38f7c379 102.BR modify_ldt ()
c79a3031 103cannot set the hardware-defined "accessed" bit described in the CPU manual.
38f7c379
AL
104.PP
105A
106.I user_desc
107is considered "empty" if
108.I read_exec_only
109and
110.I seg_not_present
111are set to 1 and all of the other fields are 0.
112An LDT entry can be cleared by setting it to an "empty"
113.I user_desc
114or, if
115.I func
116is 1, by setting both
117.I base
118and
119.I limit
120to 0.
121.PP
c79a3031
MK
122A conforming code segment (i.e., one with
123.IR contents==3 )
124will be rejected if
38f7c379
AL
125.I
126func
127is 1 or if
128.I seg_not_present
129is 0.
130.PP
131When
132.I func
133is 2,
134.BR modify_ldt ()
7acf749e
MK
135will read zeros.
136This appears to be a leftover from Linux 2.4.
47297adb 137.SH RETURN VALUE
fea681da 138On success,
e511ffb6 139.BR modify_ldt ()
fea681da
MK
140returns either the actual number of bytes read (for reading)
141or 0 (for writing).
142On failure,
e511ffb6 143.BR modify_ldt ()
fea681da 144returns \-1 and sets
0daa9e92 145.I errno
5a16bf48 146to indicate the error.
fea681da
MK
147.SH ERRORS
148.TP
149.B EFAULT
150.I ptr
151points outside the address space.
152.TP
153.B EINVAL
154.I ptr
155is 0,
156or
157.I func
158is 1 and
159.I bytecount
160is not equal to the size of the structure
38f7c379 161.IR user_desc ,
fea681da
MK
162or
163.I func
7acf749e 164is 1 or 0x11 and the new LDT entry has invalid values.
fea681da
MK
165.TP
166.B ENOSYS
167.I func
38f7c379 168is neither 0, 1, 2, nor 0x11.
47297adb 169.SH CONFORMING TO
8382f16d 170This call is Linux-specific and should not be used in programs intended
fea681da 171to be portable.
c12fd10d
MK
172.SH NOTES
173Glibc does not provide a wrapper for this system call; call it using
174.BR syscall (2).
38f7c379
AL
175.PP
176.BR modify_ldt ()
177should not be used for thread-local storage, as it slows down context
7acf749e
MK
178switches and only supports a limited number of threads.
179Threading libraries should use
38f7c379
AL
180.BR set_thread_area (2)
181or
182.BR arch_prctl (2)
183instead, except on extremely old kernels that do not support those system
184calls.
185.PP
186The normal use for
bf7bc8b8 187.BR modify_ldt ()
7acf749e
MK
188is to run legacy 16-bit or segmented 32-bit code.
189Not all kernels allow 16-bit segments to be installed, however.
f89f50fa
AL
190.PP
191Even on 64-bit kernels,
bf7bc8b8 192.BR modify_ldt ()
6da93ae6
MK
193cannot be used to create a long mode (i.e., 64-bit) code segment.
194The undocumented field "lm" in
f89f50fa 195.IR user_desc
6da93ae6
MK
196is not useful, and, despite its name,
197does not result in a long mode segment.
7acf749e 198.SH BUGS
c79a3031
MK
199On 64-bit kernels before Linux 3.19,
200.\" commit e30ab185c490e9a9381385529e0fd32f0a399495
f89f50fa 201setting the "lm" bit in
c79a3031 202.IR user_desc
6da93ae6
MK
203prevents the descriptor from being considered empty.
204Keep in mind that the
f89f50fa
AL
205"lm" bit does not exist in the 32-bit headers, but these buggy kernels
206will still notice the bit even when set in a 32-bit process.
47297adb 207.SH SEE ALSO
38f7c379 208.BR arch_prctl (2),
7acf749e 209.BR set_thread_area (2),
fea681da 210.BR vm86 (2)