Blame man2/modify_ldt.2

Packit 7cfc04
.\" Copyright (c) 1995 Michael Chastain (mec@duracef.shout.net), 22 July 1995.
Packit 7cfc04
.\" Copyright (c) 2015 Andrew Lutomirski
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
Packit 7cfc04
.\" This is free documentation; you can redistribute it and/or
Packit 7cfc04
.\" modify it under the terms of the GNU General Public License as
Packit 7cfc04
.\" published by the Free Software Foundation; either version 2 of
Packit 7cfc04
.\" the License, or (at your option) any later version.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The GNU General Public License's references to "object code"
Packit 7cfc04
.\" and "executables" are to be interpreted as the output of any
Packit 7cfc04
.\" document formatting or typesetting system, including
Packit 7cfc04
.\" intermediate and printed output.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This manual is distributed in the hope that it will be useful,
Packit 7cfc04
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7cfc04
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 7cfc04
.\" GNU General Public License for more details.
Packit 7cfc04
.\"
Packit 7cfc04
.\" You should have received a copy of the GNU General Public
Packit 7cfc04
.\" License along with this manual; if not, see
Packit 7cfc04
.\" <http://www.gnu.org/licenses/>.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH MODIFY_LDT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
modify_ldt \- get or set a per-process LDT entry
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int modify_ldt(int " func ", void *" ptr ", unsigned long " bytecount );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There is no glibc wrapper for this system call; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
reads or writes the local descriptor table (LDT) for a process.
Packit 7cfc04
The LDT
Packit 7cfc04
is an array of segment descriptors that can be referenced by user code.
Packit 7cfc04
Linux allows processes to configure a per-process (actually per-mm) LDT.
Packit 7cfc04
For more information about the LDT, see the Intel Software Developer's
Packit 7cfc04
Manual or the AMD Architecture Programming Manual.
Packit 7cfc04
.PP
Packit 7cfc04
When
Packit 7cfc04
.I func
Packit 7cfc04
is 0,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
reads the LDT into the memory pointed to by
Packit 7cfc04
.IR ptr .
Packit 7cfc04
The number of bytes read is the smaller of
Packit 7cfc04
.I bytecount
Packit 7cfc04
and the actual size of the LDT, although the kernel may act as though
Packit 7cfc04
the LDT is padded with additional trailing zero bytes.
Packit 7cfc04
On success,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
will return the number of bytes read.
Packit 7cfc04
.PP
Packit 7cfc04
When
Packit 7cfc04
.I func
Packit 7cfc04
is 1 or 0x11,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
modifies the LDT entry indicated by
Packit 7cfc04
.IR ptr\->entry_number .
Packit 7cfc04
.I ptr
Packit 7cfc04
points to a
Packit 7cfc04
.I user_desc
Packit 7cfc04
structure
Packit 7cfc04
and
Packit 7cfc04
.I bytecount
Packit 7cfc04
must equal the size of this structure.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I user_desc
Packit 7cfc04
structure is defined in \fI<asm/ldt.h>\fP as:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct user_desc {
Packit 7cfc04
    unsigned int  entry_number;
Packit 7cfc04
    unsigned long base_addr;
Packit 7cfc04
    unsigned int  limit;
Packit 7cfc04
    unsigned int  seg_32bit:1;
Packit 7cfc04
    unsigned int  contents:2;
Packit 7cfc04
    unsigned int  read_exec_only:1;
Packit 7cfc04
    unsigned int  limit_in_pages:1;
Packit 7cfc04
    unsigned int  seg_not_present:1;
Packit 7cfc04
    unsigned int  useable:1;
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
In Linux 2.4 and earlier, this structure was named
Packit 7cfc04
.IR modify_ldt_ldt_s .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I contents
Packit 7cfc04
field is the segment type (data, expand-down data, non-conforming code, or
Packit 7cfc04
conforming code).
Packit 7cfc04
The other fields match their descriptions in the CPU manual, although
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
cannot set the hardware-defined "accessed" bit described in the CPU manual.
Packit 7cfc04
.PP
Packit 7cfc04
A
Packit 7cfc04
.I user_desc
Packit 7cfc04
is considered "empty" if
Packit 7cfc04
.I read_exec_only
Packit 7cfc04
and
Packit 7cfc04
.I seg_not_present
Packit 7cfc04
are set to 1 and all of the other fields are 0.
Packit 7cfc04
An LDT entry can be cleared by setting it to an "empty"
Packit 7cfc04
.I user_desc
Packit 7cfc04
or, if
Packit 7cfc04
.I func
Packit 7cfc04
is 1, by setting both
Packit 7cfc04
.I base
Packit 7cfc04
and
Packit 7cfc04
.I limit
Packit 7cfc04
to 0.
Packit 7cfc04
.PP
Packit 7cfc04
A conforming code segment (i.e., one with
Packit 7cfc04
.IR contents==3 )
Packit 7cfc04
will be rejected if
Packit 7cfc04
.I
Packit 7cfc04
func
Packit 7cfc04
is 1 or if
Packit 7cfc04
.I seg_not_present
Packit 7cfc04
is 0.
Packit 7cfc04
.PP
Packit 7cfc04
When
Packit 7cfc04
.I func
Packit 7cfc04
is 2,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
will read zeros.
Packit 7cfc04
This appears to be a leftover from Linux 2.4.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
returns either the actual number of bytes read (for reading)
Packit 7cfc04
or 0 (for writing).
Packit 7cfc04
On failure,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
returns \-1 and sets
Packit 7cfc04
.I errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
.I ptr
Packit 7cfc04
points outside the address space.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I ptr
Packit 7cfc04
is 0,
Packit 7cfc04
or
Packit 7cfc04
.I func
Packit 7cfc04
is 1 and
Packit 7cfc04
.I bytecount
Packit 7cfc04
is not equal to the size of the structure
Packit 7cfc04
.IR user_desc ,
Packit 7cfc04
or
Packit 7cfc04
.I func
Packit 7cfc04
is 1 or 0x11 and the new LDT entry has invalid values.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSYS
Packit 7cfc04
.I func
Packit 7cfc04
is neither 0, 1, 2, nor 0x11.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This call is Linux-specific and should not be used in programs intended
Packit 7cfc04
to be portable.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Glibc does not provide a wrapper for this system call; call it using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.PP
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
should not be used for thread-local storage, as it slows down context
Packit 7cfc04
switches and only supports a limited number of threads.
Packit 7cfc04
Threading libraries should use
Packit 7cfc04
.BR set_thread_area (2)
Packit 7cfc04
or
Packit 7cfc04
.BR arch_prctl (2)
Packit 7cfc04
instead, except on extremely old kernels that do not support those system
Packit 7cfc04
calls.
Packit 7cfc04
.PP
Packit 7cfc04
The normal use for
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
is to run legacy 16-bit or segmented 32-bit code.
Packit 7cfc04
Not all kernels allow 16-bit segments to be installed, however.
Packit 7cfc04
.PP
Packit 7cfc04
Even on 64-bit kernels,
Packit 7cfc04
.BR modify_ldt ()
Packit 7cfc04
cannot be used to create a long mode (i.e., 64-bit) code segment.
Packit 7cfc04
The undocumented field "lm" in
Packit 7cfc04
.IR user_desc
Packit 7cfc04
is not useful, and, despite its name,
Packit 7cfc04
does not result in a long mode segment.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
On 64-bit kernels before Linux 3.19,
Packit 7cfc04
.\" commit e30ab185c490e9a9381385529e0fd32f0a399495
Packit 7cfc04
setting the "lm" bit in
Packit 7cfc04
.IR user_desc
Packit 7cfc04
prevents the descriptor from being considered empty.
Packit 7cfc04
Keep in mind that the
Packit 7cfc04
"lm" bit does not exist in the 32-bit headers, but these buggy kernels
Packit 7cfc04
will still notice the bit even when set in a 32-bit process.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR arch_prctl (2),
Packit 7cfc04
.BR set_thread_area (2),
Packit 7cfc04
.BR vm86 (2)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.