pub(super) struct SwitchTarget {
pub(super) old_rsp_ptr: *mut u64,
pub(super) new_rsp_ptr: *const u64,
pub(super) old_fpu_ptr: *mut u8,
pub(super) new_fpu_ptr: *const u8,
pub(super) old_xcr0: u64,
pub(super) new_xcr0: u64,
}Expand description
Information needed to perform a context switch after releasing the lock.
§Safety invariants
SwitchTarget contains raw pointers into Arc<Task> objects. All five
invariants below must hold at the moment do_switch_context / switch_context
reads them. They are established by yield_cpu_local under the LOCAL lock
and consumed before any other CPU can observe the pointed-to memory.
-
old_rsp_ptrpoints to(*source.context.get()).saved_rsp. ThesourceArcis kept alive by cpu.current_taskorcpu.task_to_requeuefor the duration of the switch; no migration, reap, or exit can invalidate it while the lock is held. -
new_rsp_ptrpoints to(*target.context.get()).saved_rsp. Same lifetime guarantee as above:targetis incpu.current_task. -
old_fpu_ptr/new_fpu_ptrpoint into the FPU state areas of the source / target tasks respectively. These areas sit inside the kernel stack and are valid as long as the owningArc<Task>is alive. FPU state is never modified concurrently: the switch context owns it exclusively between the save and restore. -
old_xcr0/new_xcr0are the XCR0 masks of source and target, read atomically fromtask.xcr0_mask. They are only consumed by the switch assembly which toggles XCR0 around xsave/xrstor. -
Lifetime:
SwitchTargetmust not outlive the LOCAL lock that protected its construction. It is consumed bydo_switch_contextimmediately after the lock is released, before any allocation, IPI, or scheduler operation.
§Debug checks
Under cfg(debug_assertions), prepare_switch_target validates that
old_rsp / new_rsp fall within their respective kernel stacks before
returning this struct.
Fields§
§old_rsp_ptr: *mut u64§new_rsp_ptr: *const u64§old_fpu_ptr: *mut u8§new_fpu_ptr: *const u8§old_xcr0: u64§new_xcr0: u64Trait Implementations§
impl Send for SwitchTarget
Auto Trait Implementations§
impl !Sync for SwitchTarget
impl Freeze for SwitchTarget
impl RefUnwindSafe for SwitchTarget
impl Unpin for SwitchTarget
impl UnsafeUnpin for SwitchTarget
impl UnwindSafe for SwitchTarget
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
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> ⓘ
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> ⓘ
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