rustubs::proc::task

Struct Task

Source
#[repr(C)]
pub struct Task { pub magic: u64, pub pid: u32, pub kernel_stack: u64, pub mm: VMMan, pub state: TaskState, pub context: Context64, }
Expand description

currently only kernelSp and Context are important. the task struct will be placed on the starting addr (low addr) of the kernel stack. therefore we can retrive the task struct at anytime by masking the kernel stack NOTE: we assume all fields in Task are only modified by the task itself, i.e. no task should modify another task’s state. (this may change though, in which case we will need some atomics) TODO: the mm is heap allocated object (vec of vmas). But the task struct doesn’t have a lifetime. Must cleanup the memory used by the mm itself when exiting a task.

Fields§

§magic: u64§pid: u32§kernel_stack: u64

note that this points to the stack bottom (low addr)

§mm: VMMan§state: TaskState§context: Context64

Implementations§

Source§

impl Task

Source

unsafe fn settle_on_stack<'a>(stack_addr: u64, t: Task) -> &'a mut Task

unsafe because you have to make sure the stack pointer is valid i.e. allocated through KStackAllocator.

Source

fn prepare_context(&mut self, entry: u64)

settle_on_stack and prepare_context must be called before switching to the task. TODO: combine them into one single API

Source

fn get_init_kernel_sp(&self) -> u64

get kernel stack top (high addr) to initialize the new task Note that there are often alignment requirements of stack pointer. We do 8 bytes here

Source

pub fn current<'a>() -> Option<&'a mut Task>

return a reference of the current running task struct. Return none of the magic number is currupted on the kernel stack, this is because

  1. the task struct is not currectly put on the stack
  2. trying to get the current of the initial task, who has no task struct on the stack
  3. the stack is corrupted (due to e.g. stack overflow)

TODO add a canary also at the end of the task struct and check it.

Source

pub fn taskid(&self) -> TaskId

Source

pub unsafe fn curr_wait_in(wait_room: &mut VecDeque<TaskId>)

a task may be present in multiple wait rooms; this is logically not possible at the moment, but would be necessary for stuffs like EPoll. require manual attention for sync

Source

pub unsafe fn wakeup(&mut self)

does not lock the GLOBAL_SCHEDULER, the caller is responsible of doing that, e.g. call task.wakeup() from epilogue

Source

pub fn nanosleep(&mut self, ns: u64)

Source

pub fn create_task(pid: u32, entry: u64) -> TaskId

create a kernel thread, you need to add it to the scheduler run queue manually

Auto Trait Implementations§

§

impl Freeze for Task

§

impl RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl UnwindSafe for Task

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.