Skip to main content

Task

Struct Task 

Source
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: 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: AtomicU8

Current state of the task. Stored as AtomicU8 for lock-free cross-CPU visibility. Use get_state() / set_state() for typed access.

§priority: TaskPriority

Priority 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: AtomicU64

Saved interrupt/syscall-compatible frame pointer for iretq-based resume.

§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

§irq_signal_delivery_blocked: AtomicBool

Suppress 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: 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)

§home_cpu: AtomicUsize

Home 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: AtomicU64

Virtual runtime for CFS

§fair_rq_generation: AtomicU64

Monotonic token identifying the currently valid FAIR runqueue entry.

§fair_on_rq: AtomicBool

Whether this task is logically present in the FAIR runqueue.

§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).

§rt_link: LinkedListLink

Intrusive linked-list link for the RT run queue.

Only touched while holding the per-CPU scheduler spinlock.

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 resume_kind(&self) -> ResumeKind

Returns the current resume convention for this task.

Source

pub fn set_resume_kind(&self, kind: ResumeKind)

Sets the resume convention for this task.

Source

pub fn interrupt_rsp(&self) -> u64

Returns the saved iretq-compatible frame pointer for this task.

Source

pub fn set_interrupt_rsp(&self, rsp: u64)

Updates the saved iretq-compatible frame pointer for this task.

Source

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.

Source

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.

Source

pub fn vruntime(&self) -> u64

Get virtual runtime

Source

pub fn set_vruntime(&self, vruntime: u64)

Set virtual runtime

Source

pub fn fair_prepare_enqueue(&self) -> (u64, bool)

Prepare a new FAIR runqueue entry and return its generation token.

Source

pub fn fair_generation(&self) -> u64

Returns the generation of the currently valid FAIR entry.

Source

pub fn fair_is_on_rq(&self) -> bool

Returns whether the task is logically queued in FAIR.

Source

pub fn fair_mark_dequeued(&self) -> bool

Marks the task as dequeued from FAIR.

Source

pub fn fair_invalidate_rq_entry(&self) -> bool

Invalidates the current FAIR entry so stale heap nodes can be skipped lazily.

Source

pub fn get_state(&self) -> TaskState

Read the current task state atomically.

Source

pub fn set_state(&self, new_state: TaskState)

Write the task state atomically. Uses Release ordering so the new state is visible to any CPU that subsequently does an Acquire load.

Source§

impl Task

Source

pub const DEFAULT_STACK_SIZE: usize = 65536

Default kernel stack size (64 KB - increased from 16KB due to overflow)

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 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.

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.

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> 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.