pub fn validate_ring3_state(target_rip: u64, target_rsp: u64, cs: u16, ss: u16)Expand description
Validates all CPU preconditions for a safe Ring 3 transition via iretq.
§When to call
Immediately before the iretq trampoline. If this function returns,
all prerequisites are satisfied. If a check fails it panic!s with a
detailed diagnosis (bad GDT/paging/TSS, raw descriptor values, addresses
involved).
§Arguments
target_rip– Ring 3 instruction pointer (ELF entry point)target_rsp– User-stack top (must be 16‑byte aligned)cs– Code-segment selector in the IRETQ frame (e.g.0x2B)ss– Stack-segment selector in the IRETQ frame (e.g.0x23)
§Panics
Panics with an explicit message if any of the following is false:
- CS/SS present in GDT with DPL=3, P=1; CS has L=1
target_ripandtarget_rspare USER_ACCESSIBLE at every page leveltarget_rspis 16‑byte aligned- TSS is loaded and
rsp0resides in kernel space