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: TaskIdUnique identifier for this task
pid: PidProcess identifier visible to userspace.
tid: TidThread identifier visible to userspace.
tgid: PidThread-group identifier (equals process leader PID).
pgid: AtomicU32Process group id (job-control group).
sid: AtomicU32Session id.
uid: AtomicU32real user id.
euid: AtomicU32effective user id.
gid: AtomicU32real group id.
egid: AtomicU32effective group id.
state: SyncUnsafeCell<TaskState>Current state of the task
priority: TaskPriorityPriority level of the task
context: SyncUnsafeCell<CpuContext>Saved CPU context for this task (just the stack pointer)
kernel_stack: KernelStackKernel stack for this task
user_stack: Option<UserStack>User stack for this task (if applicable)
name: &'static strTask 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: SignalSetFile descriptor table for this task Pending signals for this task
blocked_signals: SignalSetBlocked signals mask for this task
signal_stack: SyncUnsafeCell<Option<SigStack>>Signal actions (handlers) for this task Signal alternate stack for this task
itimers: ITimersInterval timers (ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF)
wake_pending: AtomicBoolPending 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: AtomicU64Sleep deadline in nanoseconds (monotonic). If non-zero, the task is sleeping until this time. Checked by the scheduler to auto-wake.
trampoline_entry: AtomicU64Program 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: AtomicU64User-space stack top for ring3 trampoline (ELF tasks only, 0 otherwise).
trampoline_arg0: AtomicU64First argument (RDI) passed to the user process on entry (e.g. bootstrap cap handle).
ticks: AtomicU64Total CPU ticks consumed by this task
sched_policy: SyncUnsafeCell<SchedPolicy>Scheduling policy (Fair, RealTime, Idle)
vruntime: AtomicU64Virtual runtime for CFS
clear_child_tid: AtomicU64TID address for futex-based thread join (set_tid_address). The kernel writes 0 here when the thread exits, then futex_wake.
user_fs_base: AtomicU64Current 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: AtomicU64XCR0 mask for this task (inherited from its silo).
Implementations§
Source§impl Task
impl Task
Sourcepub fn default_sched_policy(priority: TaskPriority) -> SchedPolicy
pub fn default_sched_policy(priority: TaskPriority) -> SchedPolicy
Performs the default sched policy operation.
Sourcepub fn sched_policy(&self) -> SchedPolicy
pub fn sched_policy(&self) -> SchedPolicy
Get the current scheduling policy of the task
Sourcepub fn set_sched_policy(&self, policy: SchedPolicy)
pub fn set_sched_policy(&self, policy: SchedPolicy)
Set the scheduling policy of the task
Sourcepub fn set_vruntime(&self, vruntime: u64)
pub fn set_vruntime(&self, vruntime: u64)
Set virtual runtime
Source§impl Task
impl Task
Sourcepub const DEFAULT_STACK_SIZE: usize = 16384
pub const DEFAULT_STACK_SIZE: usize = 16384
Default kernel stack size (16 KB)
Sourcepub fn new_kernel_task(
entry_point: extern "C" fn() -> !,
name: &'static str,
priority: TaskPriority,
) -> Result<Arc<Self>, &'static str>
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
Sourcepub fn new_kernel_task_with_stack(
entry_point: extern "C" fn() -> !,
name: &'static str,
priority: TaskPriority,
stack_size: usize,
) -> Result<Arc<Self>, &'static str>
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.
Sourcepub fn new_user_task(
entry_point: u64,
address_space: Arc<AddressSpace>,
name: &'static str,
priority: TaskPriority,
) -> Result<Arc<Self>, &'static str>
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.
Sourcepub fn reset_signals(&self)
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).
Sourcepub fn is_kernel(&self) -> bool
pub fn is_kernel(&self) -> bool
Returns true if this is a kernel task (shares the kernel address space).
Sourcepub fn allocate_process_ids() -> (Pid, Tid, Pid)
pub fn allocate_process_ids() -> (Pid, Tid, Pid)
Allocate POSIX identifiers for a new process leader.
Sourcepub fn debug_print_layout()
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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