ThreadGroup

Struct ThreadGroup 

Source
pub struct ThreadGroup {
    pub weak_self: Weak<ThreadGroup>,
    pub kernel: Arc<Kernel>,
    pub process: Process,
    pub leader: pid_t,
    pub signal_actions: Arc<SignalActions>,
    pub timers: TimerTable,
    pub drop_notifier: DropNotifier,
    pub limits: OrderedMutex<ResourceLimits, ThreadGroupLimits>,
    pub next_seccomp_filter_id: AtomicU64Counter,
    pub ptracees: Mutex<BTreeMap<tid_t, TaskContainer>>,
    pub pending_signals: Mutex<QueuedSignals>,
    pub start_time: MonotonicInstant,
    /* private fields */
}
Expand description

A collection of Task objects that roughly correspond to a “process”.

Userspace programmers often think about “threads” and “process”, but those concepts have no clear analogs inside the kernel because tasks are typically created using clone(2), which takes a complex set of flags that describes how much state is shared between the original task and the new task.

If a new task is created with the CLONE_THREAD flag, the new task will be placed in the same ThreadGroup as the original task. Userspace typically uses this flag in conjunction with the CLONE_FILES, CLONE_VM, and CLONE_FS, which corresponds to the userspace notion of a “thread”. For example, that’s how pthread_create behaves. In that sense, a ThreadGroup normally corresponds to the set of “threads” in a “process”. However, this pattern is purely a userspace convention, and nothing stops userspace from using CLONE_THREAD without CLONE_FILES, for example.

In Starnix, a ThreadGroup corresponds to a Zircon process, which means we do not support the CLONE_THREAD flag without the CLONE_VM flag. If we run into problems with this limitation, we might need to revise this correspondence.

Each Task in a ThreadGroup has the same thread group ID (tgid). The task with the same pid as the tgid is called the thread group leader.

Thread groups are destroyed when the last task in the group exits.

Fields§

§weak_self: Weak<ThreadGroup>

Weak reference to the OwnedRef of this ThreadGroup. This allows to retrieve the TempRef from a raw ThreadGroup.

§kernel: Arc<Kernel>

The kernel to which this thread group belongs.

§process: Process

A handle to the underlying Zircon process object.

Currently, we have a 1-to-1 mapping between thread groups and zx::process objects. This approach might break down if/when we implement CLONE_VM without CLONE_THREAD because that creates a situation where two thread groups share an address space. To implement that situation, we might need to break the 1-to-1 mapping between thread groups and zx::process or teach zx::process to share address spaces.

§leader: pid_t

The lead task of this thread group.

The lead task is typically the initial thread created in the thread group.

§signal_actions: Arc<SignalActions>

The signal actions that are registered for this process.

§timers: TimerTable

The timers for this thread group (from timer_create(), etc.).

§drop_notifier: DropNotifier

A mechanism to be notified when this ThreadGroup is destroyed.

§limits: OrderedMutex<ResourceLimits, ThreadGroupLimits>

The resource limits for this thread group. This is outside mutable_state to avoid deadlocks where the thread_group lock is held when acquiring the task lock, and vice versa.

§next_seccomp_filter_id: AtomicU64Counter

The next unique identifier for a seccomp filter. These are required to be able to distinguish identical seccomp filters, which are treated differently for the purposes of SECCOMP_FILTER_FLAG_TSYNC. Inherited across clone because seccomp filters are also inherited across clone.

§ptracees: Mutex<BTreeMap<tid_t, TaskContainer>>

Tasks ptraced by this process

§pending_signals: Mutex<QueuedSignals>

The signals that are currently pending for this thread group.

§start_time: MonotonicInstant

The monotonic time at which the thread group started.

Implementations§

Source§

impl ThreadGroup

Source

pub fn new<L>( locked: &mut Locked<L>, kernel: Arc<Kernel>, process: Process, parent: Option<ThreadGroupWriteGuard<'_>>, leader: pid_t, exit_signal: Option<Signal>, process_group: Arc<ProcessGroup>, signal_actions: Arc<SignalActions>, ) -> Arc<ThreadGroup>

Source

pub fn read<'a>(self: &'a ThreadGroup) -> ThreadGroupReadGuard<'a>

Source

pub fn write<'a>(self: &'a ThreadGroup) -> ThreadGroupWriteGuard<'a>

Source

pub fn load_stopped(&self) -> StopState

Source

pub fn exit( &self, locked: &mut Locked<Unlocked>, exit_status: ExitStatus, current_task: Option<&mut CurrentTask>, )

Source

pub fn add(&self, task: &TempRef<'_, Task>) -> Result<(), Errno>

Source

pub fn remove<L>( &self, locked: &mut Locked<L>, pids: &mut PidTable, task: &OwnedRef<Task>, )

Remove the task from the children of this ThreadGroup.

It is important that the task is taken as an OwnedRef. It ensures the tasks of the ThreadGroup are always valid as they are still valid when removed.

Source

pub fn do_zombie_notifications(&self, zombie: OwnedRef<ZombieProcess>)

Source

pub fn setsid<L>(&self, locked: &mut Locked<L>) -> Result<(), Errno>

Source

pub fn setpgid<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, target: &Task, pgid: pid_t, ) -> Result<(), Errno>

Source

pub fn set_itimer( &self, current_task: &CurrentTask, which: u32, value: itimerval, ) -> Result<itimerval, Errno>

Source

pub fn get_itimer(&self, which: u32) -> Result<itimerval, Errno>

Source

pub fn set_stopped( &self, new_stopped: StopState, siginfo: Option<SignalInfo>, finalize_only: bool, ) -> StopState

Set the stop status of the process. If you pass |siginfo| of |None|, does not update the signal. If |finalize_only| is set, will check that the set will be a finalize (Stopping -> Stopped or Stopped -> Stopped) before executing it.

Returns the latest stop state after any changes.

Source

pub fn get_foreground_process_group( &self, terminal: &Terminal, ) -> Result<pid_t, Errno>

Source

pub fn set_foreground_process_group<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, terminal: &Terminal, pgid: pid_t, ) -> Result<(), Errno>

Source

pub fn set_controlling_terminal( &self, current_task: &CurrentTask, terminal: &Terminal, is_main: bool, steal: bool, is_readable: bool, ) -> Result<(), Errno>

Source

pub fn release_controlling_terminal<L>( &self, locked: &mut Locked<L>, _current_task: &CurrentTask, terminal: &Terminal, is_main: bool, ) -> Result<(), Errno>

Source

pub fn get_rlimit<L>(&self, locked: &mut Locked<L>, resource: Resource) -> u64

Source

pub fn adjust_rlimits<L>( locked: &mut Locked<L>, current_task: &CurrentTask, target_task: &Task, resource: Resource, maybe_new_limit: Option<rlimit>, ) -> Result<rlimit, Errno>

Adjusts the rlimits of the ThreadGroup to which target_task belongs to.

Source

pub fn time_stats(&self) -> TaskTimeStats

Source

pub fn get_ptracees_and( &self, selector: &ProcessSelector, pids: &PidTable, f: &mut dyn FnMut(&Task, &TaskMutableState), )

For each task traced by this thread_group that matches the given selector, acquire its TaskMutableState and ptracees lock and execute the given function.

Source

pub fn get_waitable_ptracee( &self, selector: &ProcessSelector, options: &WaitingOptions, pids: &mut PidTable, ) -> Option<WaitResult>

Returns a tracee whose state has changed, so that waitpid can report on it. If this returns a value, and the pid is being traced, the tracer thread is deemed to have seen the tracee ptrace-stop for the purposes of PTRACE_LISTEN.

Source

pub fn send_signal_unchecked( &self, current_task: &CurrentTask, unchecked_signal: UncheckedSignal, ) -> Result<(), Errno>

Attempts to send an unchecked signal to this thread group.

  • current_task: The task that is sending the signal.
  • unchecked_signal: The signal that is to be sent. Unchecked, since 0 is a sentinel value where rights are to be checked but no signal is actually sent.
§Returns

Returns Ok(()) if the signal was sent, or the permission checks passed with a 0 signal, otherwise the error that was encountered.

Source

pub unsafe fn send_signal_unchecked_debug( &self, current_task: &CurrentTask, unchecked_signal: UncheckedSignal, ) -> Result<(), Errno>

Sends a signal to this thread_group without performing any access checks.

§Safety

This is unsafe, because it should only be called by tools and tests.

Source

pub fn send_signal_unchecked_with_info( &self, current_task: &CurrentTask, unchecked_signal: UncheckedSignal, siginfo_ref: UserAddress, ) -> Result<(), Errno>

Attempts to send an unchecked signal to this thread group, with info read from siginfo_ref.

  • current_task: The task that is sending the signal.
  • unchecked_signal: The signal that is to be sent. Unchecked, since 0 is a sentinel value where rights are to be checked but no signal is actually sent.
  • siginfo_ref: The siginfo that will be enqueued.
§Returns

Returns Ok(()) if the signal was sent, or the permission checks passed with a 0 signal, otherwise the error that was encountered.

Source

pub async fn shut_down(this: Weak<Self>)

Drive this ThreadGroup to exit, allowing it time to handle SIGTERM before sending SIGKILL.

Returns once ThreadGroup::exit() has completed.

Must be called from the system task.

Source

pub fn get_process_koid(&self) -> Result<Koid, Status>

Returns the KOID of the process for this thread group. This method should be used to when mapping 32 bit linux process ids to KOIDs to avoid breaking the encapsulation of the zx::process within the ThreadGroup. This encapsulation is important since the relationship between the ThreadGroup and the Process may change over time. See ThreadGroup::process for more details.

Trait Implementations§

Source§

impl Debug for ThreadGroup

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for ThreadGroup

Available on debug-assertions enabled only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&ThreadGroup> for ThreadGroupKey

Source§

fn from(tg: &ThreadGroup) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ThreadGroup

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.

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

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, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> InstanceFromServiceTransport<T> for T

§

fn from_service_transport(handle: T) -> T

Converts the given service transport handle of type T to [Self]
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, U> Into32<U> for T
where U: MultiArchFrom<T>,

Source§

fn into_32(self) -> U

Source§

impl<T, U> Into64<U> for T
where U: MultiArchFrom<T>,

Source§

fn into_64(self) -> U

Source§

impl<T> IntoAny for T
where T: 'static + Send + Sync,

Source§

fn into_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Cast the given object into a dyn std::any::Any.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> IntoExt<U> for T
where U: FromExt<T>,

§

fn into_ext(self) -> U

Performs the conversion.
Source§

impl<T, U> IntoFidl<U> for T
where U: FromFidl<T>,

Source§

fn into_fidl(self) -> U

Source§

impl<T, U> MultiArchFrom<T> for U
where U: From<T>,

Source§

fn from_64(value: T) -> U

Source§

fn from_32(value: T) -> U

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T, U> TryIntoExt<U> for T
where U: TryFromExt<T>,

§

type Error = <U as TryFromExt<T>>::Error

§

fn try_into_ext(self) -> Result<U, <T as TryIntoExt<U>>::Error>

Tries to perform the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<St> WithTag for St

§

fn tagged<T>(self, tag: T) -> Tagged<T, St>

Produce a new stream from this one which yields item tupled with a constant tag
Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,

Source§

impl<B, A> LockEqualOrBefore<B> for A
where A: LockBefore<B>,

§

impl<E> RunsTransport<Mpsc> for E

§

impl<E> RunsTransport<Mpsc> for E
where E: RunsTransport<Mpsc>,