⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Process

Struct Process 

Source
pub struct Process {
Show 28 fields pub pid: ProcessId, pub parent: Option<ProcessId>, pub name: String, pub state: AtomicU32, pub priority: Mutex<ProcessPriority>, pub memory_space: Mutex<VirtualAddressSpace>, pub capability_space: Mutex<CapabilitySpace>, pub file_table: Mutex<FileTable>, pub threads: Mutex<BTreeMap<ThreadId, Thread>>, pub ipc_endpoints: Mutex<BTreeMap<EndpointId, CapabilityId>>, pub children: Mutex<Vec<ProcessId>>, pub exit_code: AtomicU32, pub cpu_time: AtomicU64, pub memory_stats: MemoryStats, pub created_at: u64, pub uid: u32, pub gid: u32, pub pgid: AtomicU64, pub sid: AtomicU64, pub env_vars: Mutex<BTreeMap<String, String>>, pub signal_handlers: Mutex<[u64; 32]>, pub pending_signals: AtomicU64, pub signal_mask: AtomicU64, pub umask: AtomicU32, pub tls_fs_base: AtomicU64, pub container_id: AtomicU64, pub clear_child_tid: AtomicU64, pub robust_list_head: AtomicU64,
}
Expand description

Process Control Block

Fields§

§pid: ProcessId

Process ID

§parent: Option<ProcessId>

Parent process ID (None for init)

§name: String

Process name

§state: AtomicU32

Process state

§priority: Mutex<ProcessPriority>

Priority

§memory_space: Mutex<VirtualAddressSpace>

Virtual address space

§capability_space: Mutex<CapabilitySpace>

Capability space

§file_table: Mutex<FileTable>

File descriptor table

§threads: Mutex<BTreeMap<ThreadId, Thread>>

Threads in this process

§ipc_endpoints: Mutex<BTreeMap<EndpointId, CapabilityId>>

IPC endpoints owned by this process

§children: Mutex<Vec<ProcessId>>

Child processes

§exit_code: AtomicU32

Exit code (set when process exits)

§cpu_time: AtomicU64

CPU time used (in microseconds)

§memory_stats: MemoryStats

Memory usage statistics

§created_at: u64

Creation timestamp

§uid: u32

User ID (for future use)

§gid: u32

Group ID (for future use)

§pgid: AtomicU64

Process group ID (initialized to pid)

§sid: AtomicU64

Session ID (initialized to pid)

§env_vars: Mutex<BTreeMap<String, String>>

Environment variables (populated during exec, inherited on fork)

§signal_handlers: Mutex<[u64; 32]>

Signal handlers (signal number -> handler action) 0 = default, 1 = ignore, other values = handler address

§pending_signals: AtomicU64

Pending signals bitmap

§signal_mask: AtomicU64

Signal mask (blocked signals)

§umask: AtomicU32

File creation mask (umask). Default 0o022.

§tls_fs_base: AtomicU64

TLS FS_BASE address for x86_64 (Thread-Local Storage). Set by exec_process when loading an ELF with PT_TLS segment. Read by sys_exec before enter_usermode to set MSR 0xC0000100.

§container_id: AtomicU64

Container ID (0 = not containerized). Inherited by forked children so processes cannot escape their container namespace.

§clear_child_tid: AtomicU64

User-space address to zero and futex-wake on thread exit (set by set_tid_address syscall, used by pthread_join).

§robust_list_head: AtomicU64

User-space address of robust futex list head (set by set_robust_list syscall for cleanup on abnormal exit).

Implementations§

Source§

impl Process

Source

pub fn new( pid: ProcessId, parent: Option<ProcessId>, name: String, priority: ProcessPriority, ) -> Self

Create a new process

Source

pub fn get_state(&self) -> ProcessState

Get process state

Source

pub fn set_state(&self, state: ProcessState)

Set process state

Source

pub fn get_main_thread_id(&self) -> Option<ThreadId>

Get the main thread ID of this process

Source

pub fn add_thread(&self, thread: Thread) -> Result<(), KernelError>

Add a thread to this process

Source

pub fn remove_thread(&self, tid: ThreadId) -> Option<Thread>

Remove a thread from this process

Source

pub fn get_thread(&self, tid: ThreadId) -> Option<&Thread>

Get a thread by ID

Source

pub fn thread_count(&self) -> usize

Get number of threads

Source

pub fn is_alive(&self) -> bool

Check if process is alive

Source

pub fn add_cpu_time(&self, microseconds: u64)

Update CPU time

Source

pub fn get_cpu_time(&self) -> u64

Get total CPU time

Source

pub fn set_exit_code(&self, code: i32)

Set exit code

Source

pub fn get_exit_code(&self) -> i32

Get exit code

Source

pub fn set_priority(&self, new_priority: ProcessPriority)

Set process priority

Source

pub fn set_clear_child_tid(&self, addr: usize)

Set user-space address to zero and futex-wake on thread exit. Called by set_tid_address syscall; the kernel will write 0 to this address and issue a futex wake when the thread terminates, enabling pthread_join to detect thread completion.

Source

pub fn set_robust_list(&self, addr: usize)

Set user-space address of the robust futex list head. Called by set_robust_list syscall; the kernel walks this list on abnormal thread exit to unlock any held robust mutexes.

Source

pub fn memory_space_mut(&mut self) -> Option<&mut VirtualAddressSpace>

Get mutable reference to memory space

Source

pub fn set_name(&mut self, name: String)

Set process name

Source

pub fn get_main_thread_mut(&mut self) -> Option<&mut Thread>

Get main thread (first thread created)

Source

pub fn reset_signal_handlers(&self)

Reset all signal handlers to default (used during exec)

Source

pub fn set_signal_handler( &self, signum: usize, handler: u64, ) -> Result<u64, KernelError>

Set a signal handler handler: 0 = default, 1 = ignore, other = handler address

Source

pub fn get_signal_handler(&self, signum: usize) -> Option<u64>

Get a signal handler

Source

pub fn send_signal(&self, signum: usize) -> Result<(), KernelError>

Send a signal to this process

Source

pub fn is_signal_pending(&self, signum: usize) -> bool

Check if a signal is pending

Source

pub fn get_next_pending_signal(&self) -> Option<usize>

Get the next pending signal (lowest numbered, unmasked)

Source

pub fn clear_pending_signal(&self, signum: usize)

Clear a pending signal

Source

pub fn set_signal_mask(&self, new_mask: u64) -> u64

Set signal mask (returns old mask)

Source

pub fn get_signal_mask(&self) -> u64

Get current signal mask

Trait Implementations§

Source§

impl Drop for Process

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Process

§

impl !RefUnwindSafe for Process

§

impl Send for Process

§

impl Sync for Process

§

impl Unpin for Process

§

impl !UnwindSafe for Process

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.