pub struct TaskContext { /* private fields */ }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
impl TaskContext
Sourcepub fn new() -> Self
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_prepared (for initial tasks) and init
(for regular tasks) methods.
Sourcepub fn init(
&mut self,
entry: usize,
kstack_top: VirtAddr,
kernel_tls: KernelTlsBase,
)
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.
Sourcepub fn set_context_header(&mut self, header: NonNull<ExecutionContextHeader>)
pub fn set_context_header(&mut self, header: NonNull<ExecutionContextHeader>)
Sets the pinned task-owned execution-context header restored by the raw switch tail in LinuxCurrent images.
Sourcepub const fn context_header(&self) -> Option<NonNull<ExecutionContextHeader>>
pub const fn context_header(&self) -> Option<NonNull<ExecutionContextHeader>>
Returns the configured task-owned execution-context header.
Sourcepub fn prepare_switch_to(&mut self, _next_ctx: &Self)
pub fn prepare_switch_to(&mut self, _next_ctx: &Self)
Completes every helper operation that must precede current publication.
Sourcepub fn prepare_user_return_fp(&self)
pub fn prepare_user_return_fp(&self)
Restores this task’s userspace FPU image at the final IRQ-off return boundary.
Sourcepub fn clone_user_fp_state_into(&self, child: &mut Self)
Available on crate features fp-simd and uspace only.
pub fn clone_user_fp_state_into(&self, child: &mut Self)
fp-simd and uspace only.Saves the current task’s user FPU image directly into an unpublished clone.
Sourcepub fn capture_user_fp_state(&self) -> UserXstate
Available on crate features fp-simd and uspace only.
pub fn capture_user_fp_state(&self) -> UserXstate
fp-simd and uspace only.Captures the current task’s complete hardware user xstate.
Sourcepub fn replace_user_fp_state(&mut self, state: UserXstate)
Available on crate features fp-simd and uspace only.
pub fn replace_user_fp_state(&mut self, state: UserXstate)
fp-simd and uspace only.Installs a complete user xstate into the current task and hardware owner.
Sourcepub fn reset_user_fp_state(&mut self)
pub fn reset_user_fp_state(&mut self)
Replaces this task’s user FPU state with the architecture initial image.
Sourcepub unsafe fn switch_to_prepared(
&mut self,
next_ctx: &Self,
prepared: PreparedContextSwitch<'_>,
)
pub unsafe fn switch_to_prepared( &mut self, next_ctx: &Self, prepared: PreparedContextSwitch<'_>, )
Commits current-context publication and performs the raw transfer.
§Safety
The caller must have serialized scheduling, prepared FP/SIMD state, and
prepared must belong to next_ctx. No fallible Rust work may be
placed between its commit and the naked switch tail.