VortixDev
VortixDev

Reputation: 1013

Are there multiple LDTs?

The following Wikibooks page states:

The GDT contains pointers to each LDT.

I'm currently learning about segmentation, and this implies that there are multiple LDTs. As far as I can tell there is only one: multiple references I've read refer to "the LDT", implying there is only one. Is the referenced page correct in its implication? Did it mean "LDT entry"?

Upvotes: 1

Views: 142

Answers (2)

Margaret Bloom
Margaret Bloom

Reputation: 44106

While the lgdt instruction - used to set up the GDT - takes a m16&32/64 as an operand - the lldt instruction takes a r/m16 operand.

Deciphering the jargon this means that lgdt takes a pointer to a structure holding the GDT size and base address. On the other hand, lldt take a segment selector - this segment selector must have the TI (Table indicator) field set to 0 to point into the GDT.
Long story short the LDT is not set up with a base address and a size like the GDT but with a segment descriptor in the GDT - so it depends on the GDT.

The type of the segment selected by the segment selector given to lldt must be of type LDT (decimal value 2).

If any of the conditions above fails a #GP is raised.


For a given hardware thread and a given point in time, there can be only one LDT and one GDT active.
The OS can, however, change the active LDT or GDT (rare) later - based on its own policy (e.g. for specific processes).

However, an OS rarely changes the GDT entirely and usually it pre-fill it with all the segment descriptors it needs - including all the necessary LDTs.
In any case, the GDT can hold multiple LDT segment descriptors - but only one is active at any given time, per hardware thread.

Upvotes: 3

prl
prl

Reputation: 12456

The LDTR contains the address of a single active LDT at a time. The GDT can contain entries for multiple LDTs, which are loaded into LDTR one at a time as needed.

Upvotes: 3

Related Questions