pub struct TaskNamespace {
id: usize,
next_task_id: Mutex<usize>,
local_to_global: Mutex<BTreeMap<usize, usize>>,
global_to_local: Mutex<BTreeMap<usize, usize>>,
parent: Option<Arc<TaskNamespace>>,
name: String,
}Expand description
Task namespace for managing task IDs within a specific context.
Each namespace maintains its own task ID counter and can be used by ABI modules to implement their own task ID systems (e.g., Linux PID namespace, xv6 process IDs, etc.).
Namespaces form a hierarchy where child namespaces inherit from parent namespaces, allowing tasks in child namespaces to be visible from parent namespaces with potentially different IDs.
Fields§
§id: usizeUnique identifier for this namespace
next_task_id: Mutex<usize>Next task ID to allocate in this namespace
local_to_global: Mutex<BTreeMap<usize, usize>>Mapping from namespace-local task IDs to global task IDs.
This enables syscall boundary translation (PID namespace semantics) while keeping kernel internals globally-addressed.
global_to_local: Mutex<BTreeMap<usize, usize>>Reverse mapping from global task IDs to namespace-local task IDs.
parent: Option<Arc<TaskNamespace>>Parent namespace (None for root namespace)
name: StringName/description of this namespace (for debugging)
Implementations§
Source§impl TaskNamespace
impl TaskNamespace
Sourcepub fn new_child(parent: Arc<TaskNamespace>, name: String) -> Arc<Self>
pub fn new_child(parent: Arc<TaskNamespace>, name: String) -> Arc<Self>
Sourcepub fn allocate_task_id(&self) -> usize
pub fn allocate_task_id(&self) -> usize
Sourcepub fn allocate_task_id_for(&self, global_task_id: usize) -> usize
pub fn allocate_task_id_for(&self, global_task_id: usize) -> usize
Allocate a new namespace-local task ID and register it for a global task.
This is the preferred allocator when a task is created or enters this namespace, because syscalls need a stable local↔global mapping.
Sourcepub fn register_mapping(&self, local_id: usize, global_task_id: usize)
pub fn register_mapping(&self, local_id: usize, global_task_id: usize)
Register an existing namespace-local ID mapping for a global task ID.
Sourcepub fn resolve_global_id(&self, local_id: usize) -> Option<usize>
pub fn resolve_global_id(&self, local_id: usize) -> Option<usize>
Resolve a namespace-local task ID to a global task ID.
Sourcepub fn resolve_local_id(&self, global_task_id: usize) -> Option<usize>
pub fn resolve_local_id(&self, global_task_id: usize) -> Option<usize>
Resolve a global task ID to a namespace-local task ID.
Sourcepub fn get_parent(&self) -> Option<&Arc<TaskNamespace>>
pub fn get_parent(&self) -> Option<&Arc<TaskNamespace>>
Get the parent namespace, if any.