Skip to main content

Task

Struct Task 

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

Wraps the kernel’s struct task_struct.

§Invariants

All instances are valid tasks created by the C portion of the kernel.

Instances of this type are always refcounted, that is, a call to get_task_struct ensures that the allocation remains valid at least until the matching call to put_task_struct.

§Examples

The following is an example of getting the PID of the current thread with zero additional cost when compared to the C version:

let pid = current!().pid();

Getting the PID of the current process, also zero additional cost:

let pid = current!().group_leader().pid();

Getting the current task and storing it in some struct. The reference count is automatically incremented when creating State and decremented when it is dropped:

use kernel::{task::Task, sync::aref::ARef};

struct State {
    creator: ARef<Task>,
    index: u32,
}

impl State {
    fn new() -> Self {
        Self {
            creator: ARef::from(&**current!()),
            index: 0,
        }
    }
}

Implementations§

Source§

impl Task

Source

pub fn current_raw() -> *mut task_struct

Returns a raw pointer to the current task.

It is up to the user to use the pointer correctly.

Source

pub unsafe fn current() -> impl Deref<Target = CurrentTask>

Returns a task reference for the currently executing task/thread.

The recommended way to get the current task/thread is to use the current macro because it is safe.

§Safety

Callers must ensure that the returned object is only used to access a CurrentTask within the task context that was active when this function was called. For more details, see the invariants section for CurrentTask.

Source

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

Returns a raw pointer to the 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 AlwaysRefCounted for Task

Source§

fn inc_ref(&self)

Increments the reference count on the object.
Source§

unsafe fn dec_ref(obj: NonNull<Self>)

Decrements the reference count on the object. Read more
Source§

impl PartialEq for Task

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Task

Source§

impl Send for Task

Source§

impl Sync for Task

Auto Trait Implementations§

§

impl !Freeze for Task

§

impl !RefUnwindSafe 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> Init<T> for T

Source§

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

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> KnownSize for T

Source§

fn size(_: *const T) -> usize

Get the size of an object of this type in bytes, with the metadata of the given pointer.
Source§

impl<T> PinInit<T> for T

Source§

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

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

impl<T, U, const N: u32> TryIntoBounded<T, N> for U
where T: Integer, U: TryInto<T>,

Source§

fn try_into_bounded(self) -> Option<Bounded<T, N>>

Attempts to convert self into a Bounded using N bits. Read more