Skip to main content

SwitchTarget

Struct SwitchTarget 

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

  1. old_rsp_ptr points to (*source.context.get()).saved_rsp. The source Arc is kept alive by cpu.current_task or cpu.task_to_requeue for the duration of the switch; no migration, reap, or exit can invalidate it while the lock is held.

  2. new_rsp_ptr points to (*target.context.get()).saved_rsp. Same lifetime guarantee as above: target is in cpu.current_task.

  3. old_fpu_ptr / new_fpu_ptr point 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 owning Arc<Task> is alive. FPU state is never modified concurrently: the switch context owns it exclusively between the save and restore.

  4. old_xcr0 / new_xcr0 are the XCR0 masks of source and target, read atomically from task.xcr0_mask. They are only consumed by the switch assembly which toggles XCR0 around xsave/xrstor.

  5. Lifetime: SwitchTarget must not outlive the LOCAL lock that protected its construction. It is consumed by do_switch_context immediately 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: u64

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.