TaskNamespace

Struct TaskNamespace 

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

Unique 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: String

Name/description of this namespace (for debugging)

Implementations§

Source§

impl TaskNamespace

Source

pub fn new_root(name: String) -> Arc<Self>

Create a new root namespace.

§Arguments
  • name - Name/description of this namespace
§Returns

A new root namespace with ID 0

Source

pub fn new_child(parent: Arc<TaskNamespace>, name: String) -> Arc<Self>

Create a new child namespace.

§Arguments
  • parent - Parent namespace
  • name - Name/description of this namespace
§Returns

A new child namespace

Source

pub fn allocate_task_id(&self) -> usize

Allocate a new task ID in this namespace.

§Returns

The next available task ID in this namespace

Source

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.

Source

pub fn register_mapping(&self, local_id: usize, global_task_id: usize)

Register an existing namespace-local ID mapping for a global task ID.

Source

pub fn resolve_global_id(&self, local_id: usize) -> Option<usize>

Resolve a namespace-local task ID to a global task ID.

Source

pub fn resolve_local_id(&self, global_task_id: usize) -> Option<usize>

Resolve a global task ID to a namespace-local task ID.

Source

pub fn get_id(&self) -> usize

Get the namespace ID.

Source

pub fn get_parent(&self) -> Option<&Arc<TaskNamespace>>

Get the parent namespace, if any.

Source

pub fn get_name(&self) -> &str

Get the namespace name.

Source

pub fn is_root(&self) -> bool

Check if this namespace is the root namespace.

Trait Implementations§

Source§

impl Debug for TaskNamespace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for TaskNamespace

§

impl !RefUnwindSafe for TaskNamespace

§

impl Send for TaskNamespace

§

impl Sync for TaskNamespace

§

impl Unpin for TaskNamespace

§

impl !UnwindSafe for TaskNamespace

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.