Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are LDT and GDT used differently in intel x86?

Tags:

x86

intel

gdt

I understand that both tables contain segment descriptors that provide access details for each segment, including the base address, type, length, access rights ...etc.

Looking at this blog describes the differences as follows:
1. GDT have only one copy in system while LDT can have many
2. GDT may not changed during execution which LDT often changes when task switches
3. entry of LDT is save in GDT. Entries in GDT and LDT have the same structure.

How does the system use these structures differently in an actual program?

like image 820
Abundance Avatar asked Dec 12 '15 18:12

Abundance


1 Answers

The GDT is used to store memory blocks containing supervisor code, such as interrupt/exception handlers, and the blocks used by the kernel itself, so they are system-wide.

OTOH, a multitask OS must store where in memory the memory blocks that comprise a specific task are located. For that, a separate LDT can be used per task. Switching process involves loading a different LDT into the LDTR register.

Each task can see the memory blocks whose descriptors are, either referenced in the current LDT, or in the GDT. For user mode memory access, it will use local descriptors. For system calls, it can use various techniques, for example the INT instruction. This instruction effectively jumps to a code resident in a descriptor from the GDT. I can't remember if call gates are specific to GDT or they can be used in LDT too.

like image 69
mcleod_ideafix Avatar answered Sep 22 '22 13:09

mcleod_ideafix