Skip to main content

Task

Struct Task 

Source
pub struct Task {
Show 33 fields pub id: TaskId, pub pid: Pid, pub tid: Tid, pub tgid: Pid, pub pgid: AtomicU32, pub sid: AtomicU32, pub uid: AtomicU32, pub euid: AtomicU32, pub gid: AtomicU32, pub egid: AtomicU32, pub state: SyncUnsafeCell<TaskState>, pub priority: TaskPriority, pub context: SyncUnsafeCell<CpuContext>, pub kernel_stack: KernelStack, pub user_stack: Option<UserStack>, pub name: &'static str, pub process: Arc<Process>, pub pending_signals: SignalSet, pub blocked_signals: SignalSet, pub signal_stack: SyncUnsafeCell<Option<SigStack>>, pub itimers: ITimers, pub wake_pending: AtomicBool, pub wake_deadline_ns: AtomicU64, pub trampoline_entry: AtomicU64, pub trampoline_stack_top: AtomicU64, pub trampoline_arg0: AtomicU64, pub ticks: AtomicU64, pub sched_policy: SyncUnsafeCell<SchedPolicy>, pub vruntime: AtomicU64, pub clear_child_tid: AtomicU64, pub user_fs_base: AtomicU64, pub fpu_state: SyncUnsafeCell<ExtendedState>, pub xcr0_mask: AtomicU64,
}
Expand description

Represents a single task/thread in the system

Fields§

§id: TaskId

Unique identifier for this task

§pid: Pid

Process identifier visible to userspace.

§tid: Tid

Thread identifier visible to userspace.

§tgid: Pid

Thread-group identifier (equals process leader PID).

§pgid: AtomicU32

Process group id (job-control group).

§sid: AtomicU32

Session id.

§uid: AtomicU32

real user id.

§euid: AtomicU32

effective user id.

§gid: AtomicU32

real group id.

§egid: AtomicU32

effective group id.

§state: SyncUnsafeCell<TaskState>

Current state of the task

§priority: TaskPriority

Priority level of the task

§context: SyncUnsafeCell<CpuContext>

Saved CPU context for this task (just the stack pointer)

§kernel_stack: KernelStack

Kernel stack for this task

§user_stack: Option<UserStack>

User stack for this task (if applicable)

§name: &'static str

Task name for debugging purposes

§process: Arc<Process>

Capabilities granted to this task Address space for this task (kernel tasks share the kernel AS)

§pending_signals: SignalSet

File descriptor table for this task Pending signals for this task

§blocked_signals: SignalSet

Blocked signals mask for this task

§signal_stack: SyncUnsafeCell<Option<SigStack>>

Signal actions (handlers) for this task Signal alternate stack for this task

§itimers: ITimers

Interval timers (ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF)

§wake_pending: AtomicBool

Pending wakeup flag: set by wake_task() when the task is not yet in blocked_tasks (it is still transitioning to Blocked state). Checked by block_current_task() — if set, the task skips blocking and continues execution, preventing a lost-wakeup race.

§wake_deadline_ns: AtomicU64

Sleep deadline in nanoseconds (monotonic). If non-zero, the task is sleeping until this time. Checked by the scheduler to auto-wake.

§trampoline_entry: AtomicU64

Program break (end of heap), in bytes. 0 = not yet initialised. Lazily set to BRK_BASE on the first sys_brk call. mmap_hint: next candidate virtual address for anonymous mmap allocations User-space entry point for ring3 trampoline (ELF tasks only, 0 otherwise).

§trampoline_stack_top: AtomicU64

User-space stack top for ring3 trampoline (ELF tasks only, 0 otherwise).

§trampoline_arg0: AtomicU64

First argument (RDI) passed to the user process on entry (e.g. bootstrap cap handle).

§ticks: AtomicU64

Total CPU ticks consumed by this task

§sched_policy: SyncUnsafeCell<SchedPolicy>

Scheduling policy (Fair, RealTime, Idle)

§vruntime: AtomicU64

Virtual runtime for CFS

§clear_child_tid: AtomicU64

TID address for futex-based thread join (set_tid_address). The kernel writes 0 here when the thread exits, then futex_wake.

§user_fs_base: AtomicU64

Current working directory (POSIX, inherited by children). File creation mask (inherited by children, NOT reset by exec). User-space FS.base (TLS on x86_64, set via arch_prctl ARCH_SET_FS). Saved/restored across context switches.

§fpu_state: SyncUnsafeCell<ExtendedState>

FPU/SSE/AVX extended state saved during context switch.

§xcr0_mask: AtomicU64

XCR0 mask for this task (inherited from its silo).

Implementations§

Source§

impl Task

Source

pub fn default_sched_policy(priority: TaskPriority) -> SchedPolicy

Performs the default sched policy operation.

Source

pub fn sched_policy(&self) -> SchedPolicy

Get the current scheduling policy of the task

Source

pub fn set_sched_policy(&self, policy: SchedPolicy)

Set the scheduling policy of the task

Source

pub fn vruntime(&self) -> u64

Get virtual runtime

Source

pub fn set_vruntime(&self, vruntime: u64)

Set virtual runtime

Source§

impl Task

Source

pub const DEFAULT_STACK_SIZE: usize = 16384

Default kernel stack size (16 KB)

Source

pub fn new_kernel_task( entry_point: extern "C" fn() -> !, name: &'static str, priority: TaskPriority, ) -> Result<Arc<Self>, &'static str>

Create a new kernel task with a real allocated stack

Source

pub fn new_kernel_task_with_stack( entry_point: extern "C" fn() -> !, name: &'static str, priority: TaskPriority, stack_size: usize, ) -> Result<Arc<Self>, &'static str>

Create a new kernel task with a custom kernel stack size.

Source

pub fn new_user_task( entry_point: u64, address_space: Arc<AddressSpace>, name: &'static str, priority: TaskPriority, ) -> Result<Arc<Self>, &'static str>

Create a new user task with its own address space (stub for future use).

The entry point and user stack must already be mapped in the given address space.

Source

pub fn reset_signals(&self)

Reset all signal handlers to SIG_DFL (default).

Called during execve to reset signal handlers as per POSIX: handlers set to catch signals are reset to SIG_DFL, but SIG_IGN remains ignored (implementation simplification: we reset all).

Source

pub fn is_kernel(&self) -> bool

Returns true if this is a kernel task (shares the kernel address space).

Source

pub fn allocate_process_ids() -> (Pid, Tid, Pid)

Allocate POSIX identifiers for a new process leader.

Source

pub fn debug_print_layout()

Print the memory layout of Task and Process structs for debugging.

Computes field offsets at runtime using addr_of! so the output is accurate regardless of Rust’s struct reordering decisions. Call this early in kernel init to validate the crash-site offset analysis.

Auto Trait Implementations§

§

impl !Freeze for Task

§

impl !RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

§

impl !UnwindSafe for Task

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.