struct SwapGsGuard {
from_ring3: bool,
}Expand description
RAII guard: swap GS to kernel on entry if we came from Ring 3, and restore user GS automatically on drop (covers every exit path including early returns).
§Why this is needed
After swapgs ; iretq in the Ring-3 trampoline:
IA32_GS_BASE= 0 (user GS base, inactive)IA32_KERNEL_GS_BASE= kernel per-CPU pointer When an interrupt fires from Ring 3, the CPU does NOT automatically call swapgs. The firstgs:[0]access (e.g. incurrent_cpu_index) would dereference virtual address 0 → page fault → double fault → triple fault.
§Safety
Must be constructed before any gs:[…] access in the handler.
InterruptStackFrame::code_segment is a plain memory read from the
interrupt stack : it does not access GS.
Fields§
§from_ring3: boolImplementations§
Trait Implementations§
Source§impl Drop for SwapGsGuard
impl Drop for SwapGsGuard
Auto Trait Implementations§
impl Freeze for SwapGsGuard
impl RefUnwindSafe for SwapGsGuard
impl Send for SwapGsGuard
impl Sync for SwapGsGuard
impl Unpin for SwapGsGuard
impl UnsafeUnpin for SwapGsGuard
impl UnwindSafe for SwapGsGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more