I386_GET_LDT(2)
π I386_GET_LDT π
okay bestie, gather round, because we're about to talk about the i386_get_ldt(2) and i386_set_ldt(2) system calls β they live in the System Calls Manual section 2, and they're the ones that manage i386 per-process Local Descriptor Table entries. lowkey iconic, highkey terrifying, let's go π¦
β¨ NAME β¨
i386_get_ldt, i386_set_ldt β manage i386 per-process Local Descriptor Table entries π
π LIBRARY π
Standard C Library (libc, -lc) π
πΈ SYNOPSIS πΈ
#include <machine/segments.h>
#include <machine/sysarch.h>
int
i386_get_ldt(int start_sel, union descriptor *descs, int num_sels);
int
i386_set_ldt(int start_sel, union descriptor *descs, int num_sels);
like, those two includes are NOT optional, ok? and yeah, they both take the exact same three args, no cap π«Ά
π« DESCRIPTION π«
so the tea is this: i386_get_ldt() returns a list of the i386 descriptors sitting in the current process' LDT. meanwhile i386_set_ldt() sets a list of i386 descriptors in the current process' LDT. two sides of the same coin, fr fr π
for both routines, start_sel says which index of the selector in the LDT to start at, and descs points to an array of num_sels descriptors to be set or returned. simple as that β¨
each entry in the descs array can be either a segment_descriptor or a gate_descriptor, and those are defined in <i386/segments.h>. now listen β these structures are defined by the architecture as disjoint bit-fields, so you have to be so careful when you're constructing them. like, care must be taken. genuinely. do not freestyle this π
okay and here are the three special cases, and they're giving main character energy:
- if
start_selisLDT_AUTO_ALLOC,num_selsis 1 and the descriptor pointed to bydescsis legal, theni386_set_ldt()will allocate a descriptor and return its selector number π - if
num_descsis 1,start_selsis valid, anddescsisNULL, theni386_set_ldt()will free that descriptor (making it available to be reallocated again later) π§ - if
num_descsis 0,start_selsis 0 anddescsisNULLthen, as a special case,i386_set_ldt()will free all descriptors π
β RETURN VALUES β
upon successful completion, i386_get_ldt() returns the number of descriptors currently in the LDT. cute, right?
the i386_set_ldt() system call returns the first selector set on success. and if the kernel allocated a descriptor in the LDT, the allocated index is returned π
otherwise? a value of -1 is returned and the global variable errno is set to indicate the error. not the vibe. we don't love that for us π
π₯ ERRORS π₯
the i386_get_ldt() and i386_set_ldt() system calls will fail if:
[EINVAL]β an inappropriate value was used forstart_selornum_sels. ma'am. what did you type. π[EACCES]β the caller attempted to use a descriptor that would circumvent protection or cause a failure. bestie no, the kernel said absolutely not π«
π SEE ALSO π
- i386 Microprocessor Programmer's Reference Manual, Intel π
iykyk, that's the source material right there β¨
β οΈ WARNING β οΈ
You can really hose your process using this.
like I cannot stress this enough. genuinely. this is the scary part. be careful, bestie ππ
and that's the whole page, periodt π this one came from the Debian crew, dated October 14, 2006, and it's the I386_GET_LDT(2) page β go forth, manage your descriptor tables responsibly, and don't hose anything π«Άβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991 Regents of the University of California
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms