Manpage of MODIFY_LDT

MODIFY_LDT

Section: Linux Programmer's Manual (2)
Updated: 2016-10-08
Index
 

NAME

modify_ldt - get or set a per-process LDT entry  

SYNOPSIS

#include <sys/types.h>int modify_ldt(int func, void *ptr, unsigned long bytecount);

Note: There is no glibc wrapper for this system call; see NOTES.  

DESCRIPTION

modify_ldt() reads or writes the local descriptor table (LDT) for a process. The LDT is an array of segment descriptors that can be referenced by user code. Linux allows processes to configure a per-process (actually per-mm) LDT. For more information about the LDT, see the Intel Software Developer's Manual or the AMD Architecture Programming Manual.

When funcis 0, modify_ldt() reads the LDT into the memory pointed to by ptr. The number of bytes read is the smaller of bytecountand the actual size of the LDT, although the kernel may act as though the LDT is padded with additional trailing zero bytes. On success, modify_ldt() will return the number of bytes read.

When funcis 1 or 0x11, modify_ldt() modifies the LDT entry indicated by ptr->entry_number. ptrpoints to a user_descstructure and bytecountmust equal the size of this structure.

The user_descstructure is defined in <asm/ldt.h> as:

struct user_desc {
    unsigned int  entry_number;
    unsigned long base_addr;
    unsigned int  limit;
    unsigned int  seg_32bit:1;
    unsigned int  contents:2;
    unsigned int  read_exec_only:1;
    unsigned int  limit_in_pages:1;
    unsigned int  seg_not_present:1;
    unsigned int  useable:1;
};

In Linux 2.4 and earlier, this structure was named modify_ldt_ldt_s.

The contentsfield is the segment type (data, expand-down data, non-conforming code, or conforming code). The other fields match their descriptions in the CPU manual, although modify_ldt() cannot set the hardware-defined "accessed" bit described in the CPU manual.

A user_descis considered "empty" if read_exec_onlyand seg_not_presentare set to 1 and all of the other fields are 0. An LDT entry can be cleared by setting it to an "empty" user_descor, if funcis 1, by setting both baseand limitto 0.

A conforming code segment (i.e., one with contents==3) will be rejected if funcis 1 or if seg_not_presentis 0.

When funcis 2, modify_ldt() will read zeros. This appears to be a leftover from Linux 2.4.  

RETURN VALUE

On success, modify_ldt() returns either the actual number of bytes read (for reading) or 0 (for writing). On failure, modify_ldt() returns -1 and sets errnoto indicate the error.  

ERRORS

EFAULT
ptrpoints outside the address space.
EINVAL
ptris 0, or funcis 1 and bytecountis not equal to the size of the structure user_desc, or funcis 1 or 0x11 and the new LDT entry has invalid values.
ENOSYS
funcis neither 0, 1, 2, nor 0x11.
 

CONFORMING TO

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

NOTES

Glibc does not provide a wrapper for this system call; call it using syscall(2).

modify_ldt() should not be used for thread-local storage, as it slows down context switches and only supports a limited number of threads. Threading libraries should use set_thread_area(2) or arch_prctl(2) instead, except on extremely old kernels that do not support those system calls.

The normal use for modify_ldt() is to run legacy 16-bit or segmented 32-bit code. Not all kernels allow 16-bit segments to be installed, however.

Even on 64-bit kernels, modify_ldt() cannot be used to create a long mode (i.e., 64-bit) code segment. The undocumented field "lm" in user_descis not useful, and, despite its name, does not result in a long mode segment.  

BUGS

On 64-bit kernels before Linux 3.19, setting the "lm" bit in user_descprevents the descriptor from being considered empty. Keep in mind that the "lm" bit does not exist in the 32-bit headers, but these buggy kernels will still notice the bit even when set in a 32-bit process.  

SEE ALSO

arch_prctl(2), set_thread_area(2), vm86(2)


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
CONFORMING TO
NOTES
BUGS
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 16:30:09 GMT, March 14, 2017 Click Here!