pub struct Task {Show 40 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: AtomicU8,
pub priority: TaskPriority,
pub context: SyncUnsafeCell<CpuContext>,
pub resume_kind: SyncUnsafeCell<ResumeKind>,
pub interrupt_rsp: AtomicU64,
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 irq_signal_delivery_blocked: AtomicBool,
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 home_cpu: AtomicUsize,
pub vruntime: AtomicU64,
pub fair_rq_generation: AtomicU64,
pub fair_on_rq: AtomicBool,
pub clear_child_tid: AtomicU64,
pub user_fs_base: AtomicU64,
pub fpu_state: SyncUnsafeCell<ExtendedState>,
pub xcr0_mask: AtomicU64,
pub rt_link: LinkedListLink,
}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: AtomicU8Current state of the task. Stored as AtomicU8 for lock-free cross-CPU visibility.
Use get_state() / set_state() for typed access.
priority: TaskPriorityPriority level of the task
context: SyncUnsafeCell<CpuContext>Saved CPU context for this task (just the stack pointer)
resume_kind: SyncUnsafeCell<ResumeKind>Resume convention for this task’s saved kernel stack frame.
interrupt_rsp: AtomicU64Saved interrupt/syscall-compatible frame pointer for iretq-based resume.
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
irq_signal_delivery_blocked: AtomicBoolSuppress repeated IRQ-return delivery attempts until a normal delivery path runs again.
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)
home_cpu: AtomicUsizeHome CPU index for this task. Set when the task is first scheduled
or explicitly assigned. Used by wake_task() to route to the correct
per-CPU runqueue without acquiring GLOBAL_SCHED_STATE.
vruntime: AtomicU64Virtual runtime for CFS
fair_rq_generation: AtomicU64Monotonic token identifying the currently valid FAIR runqueue entry.
fair_on_rq: AtomicBoolWhether this task is logically present in the FAIR runqueue.
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).
rt_link: LinkedListLinkIntrusive linked-list link for the RT run queue.
Only touched while holding the per-CPU scheduler spinlock.
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 resume_kind(&self) -> ResumeKind
pub fn resume_kind(&self) -> ResumeKind
Returns the current resume convention for this task.
Sourcepub fn set_resume_kind(&self, kind: ResumeKind)
pub fn set_resume_kind(&self, kind: ResumeKind)
Sets the resume convention for this task.
Sourcepub fn interrupt_rsp(&self) -> u64
pub fn interrupt_rsp(&self) -> u64
Returns the saved iretq-compatible frame pointer for this task.
Sourcepub fn set_interrupt_rsp(&self, rsp: u64)
pub fn set_interrupt_rsp(&self, rsp: u64)
Updates the saved iretq-compatible frame pointer for this task.
Sourcepub fn seed_interrupt_frame(&self, frame: SyscallFrame)
pub fn seed_interrupt_frame(&self, frame: SyscallFrame)
Seed a synthetic interrupt frame for tasks that have not yet been
preempted from an IRQ path but must still be resumable via iretq.
Sourcepub fn seed_kernel_interrupt_frame_from_context(&self)
pub fn seed_kernel_interrupt_frame_from_context(&self)
Seed an iretq-compatible frame from the legacy CpuContext bootstrap
layout used by kernel tasks (ret into task_entry_trampoline).
The synthesised frame always sets IF=1 so that IRQ-driven resumes keep
receiving timer interrupts. First-launch tasks still enter through the
legacy ret trampoline and must explicitly re-enable interrupts in
task_post_switch_enter.
Sourcepub fn set_vruntime(&self, vruntime: u64)
pub fn set_vruntime(&self, vruntime: u64)
Set virtual runtime
Sourcepub fn fair_prepare_enqueue(&self) -> (u64, bool)
pub fn fair_prepare_enqueue(&self) -> (u64, bool)
Prepare a new FAIR runqueue entry and return its generation token.
Sourcepub fn fair_generation(&self) -> u64
pub fn fair_generation(&self) -> u64
Returns the generation of the currently valid FAIR entry.
Sourcepub fn fair_is_on_rq(&self) -> bool
pub fn fair_is_on_rq(&self) -> bool
Returns whether the task is logically queued in FAIR.
Sourcepub fn fair_mark_dequeued(&self) -> bool
pub fn fair_mark_dequeued(&self) -> bool
Marks the task as dequeued from FAIR.
Sourcepub fn fair_invalidate_rq_entry(&self) -> bool
pub fn fair_invalidate_rq_entry(&self) -> bool
Invalidates the current FAIR entry so stale heap nodes can be skipped lazily.
Source§impl Task
impl Task
Sourcepub const DEFAULT_STACK_SIZE: usize = 65536
pub const DEFAULT_STACK_SIZE: usize = 65536
Default kernel stack size (64 KB - increased from 16KB due to overflow)
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 signal handlers during execve.
POSIX requires handlers installed by userspace to revert to SIG_DFL on exec, while dispositions already set to SIG_IGN remain ignored.
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Task
impl !RefUnwindSafe for Task
impl Send 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