Expand description
Pre-IRETQ diagnostics for transitioning from Ring 0 to Ring 3
validate_ring3_state should be invoked immediately before the IRETQ
trampoline. It checks the four prerequisites required for a safe switch to
Ring 3:
- GDT – CS/SS descriptors have DPL=3, P=1 and the code segment has L=1 (64‑bit).
- Paging – every level (PML4 → PDPT → PD → PT) for
target_ripandtarget_rsphas theUSER_ACCESSIBLEflag. - Alignment –
target_rspis 16‑byte aligned (System V ABI requirement). - TSS – a TSS is loaded (
TR ≠ 0) andrsp0points into kernel space (≥ 0xffff_8000_0000_0000), ensuring the CPU can switch back on exception.
If any check fails the function panic!s with a detailed description.
Constants§
- DESC_
DPL_ 🔒MASK - DESC_
DPL_ 🔒SHIFT - Bits [46:45] : DPL.
- DESC_
EXEC_ 🔒BIT - Bit 43 : Executable (type bit for code segments).
- DESC_
L_ 🔒BIT - Bit 53 : L Long Mode code segment (64-bit).
- DESC_
PRESENT_ 🔒BIT - Bit 47 : Present.
- DESC_
S_ 🔒BIT - Bit 44 : S 1 = segment code/data, 0 = system descriptor.
- PHYS_
ADDR_ 🔒MASK - Physical address mask inside a page-table entry (bits [51:12]).
Functions§
- check_
user_ 🔒mapping - Checks that
vaddris mapped and USER_ACCESSIBLE at every level of the page hierarchy (PML4 → PDPT → PD → PT). - desc_
dpl 🔒 - desc_
is_ 🔒code - desc_
long_ 🔒mode - desc_
present 🔒 - read_
gdt_ 🔒 ⚠raw - Reads an 8-byte GDT descriptor at the given
index(base 0). - validate_
ring3_ state - Validates all CPU preconditions for a safe Ring 3 transition via
iretq.