pub trait Task {
// Required method
fn syscall(&mut self, registers: &mut Registers);
// Provided methods
fn page_fault(&mut self, ec: PFErrorCode, cr2: Va) { ... }
fn access_ok(&self, addr: Range<Va>, is_write: bool) -> bool { ... }
fn with_page_table_pa(&self, _f: &fn(Pa)) { ... }
}Expand description
Represents a task executed by a thread.
This trait defines core functionalities required for handling event triggered by user process, such as system calls, page faults.
Required Methods§
Sourcefn syscall(&mut self, registers: &mut Registers)
fn syscall(&mut self, registers: &mut Registers)
Handles a system call triggered by the user program.
- The
registersparameter contains the state of the CPU registers at the time of the system call. - Implementations of this function should parse the system call
arguments, execute the corresponding operation, and store the result
back in
registers.
Provided Methods§
Sourcefn page_fault(&mut self, ec: PFErrorCode, cr2: Va)
fn page_fault(&mut self, ec: PFErrorCode, cr2: Va)
Handles a page fault that occurs when accessing an unmapped memory page.
- The
ecparameter provides information about the cause of the page fault.
Sourcefn access_ok(&self, addr: Range<Va>, is_write: bool) -> bool
fn access_ok(&self, addr: Range<Va>, is_write: bool) -> bool
Validates a given memory address range before use.
addr: The range of virtual addresses being accessed.is_write: Indicates whether the memory is being read (false) or written to (true).- Returns
trueif the memory range is valid, or an appropriateKernelErrorotherwise.
Sourcefn with_page_table_pa(&self, _f: &fn(Pa))
fn with_page_table_pa(&self, _f: &fn(Pa))
Run a closure with physical address of the page table.