Skip to main content

TaskContext

Struct TaskContext 

Source
pub struct TaskContext { /* private fields */ }
Available on crate feature context only.
Expand description

Saved hardware states of a task.

The context usually includes:

  • Callee-saved registers
  • Stack pointer register
  • Thread pointer register (for kernel-space thread-local storage)
  • FP/SIMD registers

On context switch, current task saves its context from CPU to memory, and the next task restores its context from memory to CPU.

On x86_64, callee-saved registers are saved to the kernel stack by the PUSH instruction. So that rsp is the RSP after callee-saved registers are pushed, and kstack_top is the top of the kernel stack (RSP before any push).

Implementations§

Source§

impl TaskContext

Source

pub fn new() -> Self

Creates a dummy context for a new task.

Note the context is not initialized, it will be filled by switch_to (for initial tasks) and init (for regular tasks) methods.

Source

pub fn init( &mut self, entry: usize, kstack_top: VirtAddr, kernel_tls: KernelTlsBase, )

Initializes the context for a new task, with the given entry point and kernel stack.

Source

pub fn set_task_anchor(&mut self, header: TaskAnchor)

Sets the pinned task-owned runtime task anchor restored by the raw switch tail in LinuxCurrent images.

Source

pub const fn task_anchor(&self) -> Option<TaskAnchor>

Returns the configured task-owned runtime task anchor.

Source

pub fn prepare_switch_to(&mut self, _next_ctx: &Self)

Completes every helper operation that must precede current publication.

Source

pub fn prepare_user_return_fp(&self)

Restores this task’s userspace FPU image at the final IRQ-off return boundary.

Source

pub fn clone_user_fp_state_into(&self, child: &mut Self)

Available on crate features fp-simd and uspace only.

Saves the current task’s user FPU image directly into an unpublished clone.

Source

pub fn capture_user_fp_state(&self) -> UserXstate

Available on crate features fp-simd and uspace only.

Captures the current task’s complete hardware user xstate.

Source

pub fn replace_user_fp_state(&mut self, state: UserXstate)

Available on crate features fp-simd and uspace only.

Installs a complete user xstate into the current task and hardware owner.

Source

pub fn reset_user_fp_state(&mut self)

Replaces this task’s user FPU state with the architecture initial image.

Source

pub unsafe fn switch_to(&mut self, next_ctx: &Self)

Performs the final machine transfer after runtime publication.

§Safety

The caller must have serialized scheduling, prepared FP/SIMD state, and published the next task anchor, and kept both contexts and their anchors pinned and alive. IRQs must remain disabled from publication through this call, with no intervening fallible or ownership-sensitive work.

Trait Implementations§

Source§

impl Debug for TaskContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.