Skip to main content

ProcTable

Struct ProcTable 

Source
pub struct ProcTable {
    pub lazy: bool,
    procs: RwLock<HashMap<i32, TraceeInfo>>,
    tids: RwLock<HashMap<i32, (i32, Instant)>>,
    defaults: RwLock<TraceeInfo>,
    forks: Mutex<HashMap<i32, VecDeque<TraceeInfo>>>,
    orphans: Mutex<VecDeque<(Instant, TraceeInfo)>>,
    shim: AtomicUsize,
    reaper: Mutex<Option<Reaper>>,
}
Expand description

The process table.

Fields§

§lazy: bool

True without ptrace: processes are discovered at their first syscall.

§procs: RwLock<HashMap<i32, TraceeInfo>>§tids: RwLock<HashMap<i32, (i32, Instant)>>§defaults: RwLock<TraceeInfo>

State given to a process whose ancestry leads nowhere known.

§forks: Mutex<HashMap<i32, VecDeque<TraceeInfo>>>

Snapshots taken at clone, waiting for the child, keyed by parent.

§orphans: Mutex<VecDeque<(Instant, TraceeInfo)>>

Snapshots whose parent exited before the child was seen.

§shim: AtomicUsize

At least the number of processes with a pending exec, so the check on every notification costs nothing while there is none.

§reaper: Mutex<Option<Reaper>>

Implementations§

Source§

impl ProcTable

Source

pub fn new(lazy: bool) -> ProcTable

Creates an empty table.

§Arguments
  • lazy - Discover processes at their first syscall (no ptrace).
Source

pub fn register_root(&self, root: i32, info: TraceeInfo)

Sets the state handed to processes with no known ancestor, and registers root with it.

§Arguments
  • root - Pid of the first tracee.
  • info - Its initial state.
Source

pub fn tgid(&self, tid: i32) -> i32

Thread-group id of thread tid, cached for TID_TTL.

A thread that is gone, or not visible, maps to itself.

§Arguments
  • tid - Thread id as a notification reports it.
Source

pub fn info(&self, tid: i32) -> TraceeInfo

A copy of what is known about the process of thread tid.

§Arguments
  • tid - Thread or process id.
Source

pub fn update(&self, tid: i32, f: impl FnOnce(&mut TraceeInfo))

Changes the state of the process of thread tid in place.

Without ptrace, children forked since the last change are registered first, with the state the parent had when it forked them.

§Arguments
  • tid - Thread or process id.
  • f - The change.
Source

pub fn fork(&self, parent: i32, child: i32)

Registers child with a copy of parent’s state (ptrace fork event).

§Arguments
  • parent - Thread id of the forking thread.
  • child - New process (or thread) id.
Source

pub fn view_of(&self, tid: i32) -> Option<Arc<View>>

The view of the process of thread tid, if it has one of its own.

§Arguments
  • tid - Thread or process id.
Source

pub fn forked(&self, tid: i32, vfork: bool)

Takes a snapshot of the forking process for the child to inherit (no ptrace).

§Arguments
  • tid - Thread calling clone, fork or vfork.
  • vfork - The child shares the parent’s memory until it execs.
Source

pub fn forget(&self, pid: i32)

Forgets a process or thread that exited.

Snapshots it left for unborn children move to the orphan list.

§Arguments
  • pid - Thread or process id.
Source

pub fn set_exe(&self, tid: i32, guest: Vec<u8>, host: Vec<u8>)

Records the executable the process of tid now runs.

Source

pub fn dumpable(&self, tid: i32) -> bool

Whether the process of thread tid still reads as dumpable.

Source

pub fn set_dumpable(&self, tid: i32, dumpable: bool)

Records the dumpable flag the process of thread tid set.

Source

pub fn exe_of(&self, tid: i32) -> Option<Vec<u8>>

The recorded guest program of thread tid, if any.

Source

pub fn cwd_of(&self, tid: i32) -> Option<Vec<u8>>

The virtual working directory of the process of tid (no ptrace).

Source

pub fn set_cwd(&self, tid: i32, cwd: Vec<u8>)

Replaces the virtual working directory of the process of tid.

Source

pub fn ids(&self, tid: i32) -> Ids

The virtual identity of the process of tid (root until changed).

Source

pub fn set_ids(&self, tid: i32, ids: Ids)

Replaces the virtual identity of the process of tid.

Source

pub fn groups(&self, tid: i32) -> Option<Vec<u32>>

Supplementary groups of the process of tid, if setgroups was called.

Source

pub fn set_groups(&self, tid: i32, groups: Vec<u32>)

Records the supplementary groups of the process of tid.

Source

pub fn shim_enter(&self, tgid: i32, pending: PendingExec)

Marks process tgid as about to run the exec shim for pending.

Source

pub fn shim_pending(&self, tgid: i32) -> Option<PendingExec>

The pending exec of process tgid, if it is in the shim.

Source

pub fn shim_leave(&self, tgid: i32)

Clears the shim mark of process tgid.

Source

fn ensure(&self, tgid: i32)

Makes sure process tgid has an entry, discovering its ancestry if needed.

Source

fn discover(&self, tgid: i32, depth: usize)

Registers tgid with the state of its parent, walking up as needed.

A parent that is still known contributes the snapshot it took at the fork, or its current state. A process whose parent is gone (reparented to init or to the supervisor) takes the oldest orphaned snapshot, or the defaults.

Source

fn adopt_children(&self, tgid: i32)

Registers the children tgid forked since its last state change.

Only done while snapshots are pending, since finding children means scanning /proc.

Source

fn watch(&self, tgid: i32)

Starts watching tgid for exit, if a reaper is running.

Source

pub fn start_reaper(table: &Arc<ProcTable>) -> Result<(), i32>

Starts the reaper thread, which forgets processes as they exit.

Processes registered before the reaper started are watched from here on.

§Arguments
  • table - The table to reap; the thread holds a reference for its life.
§Errors

Errno from epoll_create1.

Trait Implementations§

Source§

impl Debug for ProcTable

Source§

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

Formats the value using the given formatter. Read more

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, 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> 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.