Struct CurrentTask

Source
pub struct CurrentTask(/* private fields */);
Expand description

Represents the Task in the current global.

This type exists to provide more efficient operations that are only valid on the current task. For example, to retrieve the pid-namespace of a task, you must use rcu protection unless it is the current task.

§Invariants

Each value of this type must only be accessed from the task context it was created within.

Of course, every thread is in a different task context, but for the purposes of this invariant, these operations also permanently leave the task context:

  • Returning to userspace from system call context.
  • Calling release_task().
  • Calling begin_new_exec() in a binary format loader.

Other operations temporarily create a new sub-context:

  • Calling kthread_use_mm() creates a new context, and kthread_unuse_mm() returns to the old context.

This means that a CurrentTask obtained before a kthread_use_mm() call may be used again once kthread_unuse_mm() is called, but it must not be used between these two calls. Conversely, a CurrentTask obtained between a kthread_use_mm()/kthread_unuse_mm() pair must not be used after kthread_unuse_mm().

Implementations§

Source§

impl CurrentTask

Source

pub fn mm(&self) -> Option<&MmWithUser>

Access the address space of the current task.

This function does not touch the refcount of the mm.

Source

pub fn active_pid_ns(&self) -> Option<&PidNamespace>

Access the pid namespace of the current task.

This function does not touch the refcount of the namespace or use RCU protection.

To access the pid namespace of another task, see Task::get_pid_ns.

Methods from Deref<Target = Task>§

Source

pub fn as_ptr(&self) -> *mut task_struct

Returns a raw pointer to the task.

Source

pub fn group_leader(&self) -> &Task

Returns the group leader of the given task.

Source

pub fn pid(&self) -> Pid

Returns the PID of the given task.

Source

pub fn uid(&self) -> Kuid

Returns the UID of the given task.

Source

pub fn euid(&self) -> Kuid

Returns the effective UID of the given task.

Source

pub fn signal_pending(&self) -> bool

Determines whether the given task has pending signals.

Source

pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>>

Returns task’s pid namespace with elevated reference count

Source

pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid

Returns the given task’s pid in the provided pid namespace.

Source

pub fn wake_up(&self)

Wakes up the task.

Trait Implementations§

Source§

impl Deref for CurrentTask

Source§

type Target = Task

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Task

Dereferences the value.

Auto Trait Implementations§

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, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.