Struct TaskContext
pub struct TaskContext {
    pub kstack_top: VirtAddr,
    pub rsp: u64,
    pub fs_base: usize,
    pub gs_base: usize,
    pub ext_state: ExtendedState,
    pub cr3: PhysAddr,
}Expand description
Saved hardware states of a task.
The context usually includes:
- Callee-saved registers
 - Stack pointer register
 - Thread pointer register (for thread-local storage, currently unsupported)
 - 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).
Fields§
§kstack_top: VirtAddrThe kernel stack top of the task.
rsp: u64RSP after all callee-saved registers are pushed.
fs_base: usizeThread Local Storage (TLS).
gs_base: usizeThe gs_base register value.
ext_state: ExtendedStateExtended states, i.e., FP/SIMD states.
cr3: PhysAddrThe CR3 register value, i.e., the page table root.
Implementations§
§impl TaskContext
 
impl TaskContext
pub fn new() -> TaskContext
pub fn new() -> TaskContext
pub fn init(&mut self, entry: usize, kstack_top: VirtAddr, tls_area: VirtAddr)
pub fn init(&mut self, entry: usize, kstack_top: VirtAddr, tls_area: VirtAddr)
Initializes the context for a new task, with the given entry point and kernel stack.
pub fn set_page_table_root(&mut self, cr3: PhysAddr)
pub fn set_page_table_root(&mut self, cr3: PhysAddr)
Changes the page table root in this context.
The hardware register for page table root (CR3 for x86) will be
updated to the next task’s after Self::switch_to.
pub fn switch_to(&mut self, next_ctx: &TaskContext)
pub fn switch_to(&mut self, next_ctx: &TaskContext)
Switches to another task.
It first saves the current task’s context from CPU to this place, and then
restores the next task’s context from next_ctx to CPU.