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.
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.
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 FP/SIMD work before current-context publication.
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<'_>, )
Performs only the final GPR/current/TLS transfer.
§Safety
Scheduling must be serialized, FP state prepared, and the next current header published. No fallible Rust work may follow before this call.