Skip to main content

Module ring3_diag

Module ring3_diag 

Source
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:

  1. GDT – CS/SS descriptors have DPL=3, P=1 and the code segment has L=1 (64‑bit).
  2. Paging – every level (PML4 → PDPT → PD → PT) for target_rip and target_rsp has the USER_ACCESSIBLE flag.
  3. Alignmenttarget_rsp is 16‑byte aligned (System V ABI requirement).
  4. TSS – a TSS is loaded (TR ≠ 0) and rsp0 points 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 vaddr is 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.