Skip to main content

detcore/
types.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Widely-shared type definitions.
10
11use serde::Deserialize;
12use serde::Serialize;
13
14/// Child population addressed by a wait syscall whose exit readiness Detcore can model.
15#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
16pub enum ChildWaitSelector {
17    /// One direct child process.
18    Exact(DetPid),
19    /// Any direct child process.
20    Any,
21    /// Any direct child process currently in this process group.
22    ProcessGroup(DetPid),
23}
24
25/// Linux's clone-child filtering for terminal wait events.
26#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
27pub enum ChildWaitExitClass {
28    /// Children whose clone exit signal is SIGCHLD (the normal wait population).
29    Sigchld,
30    /// Children whose clone exit signal is zero or a signal other than SIGCHLD.
31    Clone,
32    /// Both normal and clone children (`__WALL`).
33    Any,
34}
35
36/// Scheduler-owned selection criteria for a terminal child wait.
37#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
38pub struct ChildWaitSpec {
39    /// PID or process-group population selected by the syscall.
40    pub selector: ChildWaitSelector,
41    /// Restrict to children owned by this exact task (`__WNOTHREAD`).
42    pub owner: Option<DetTid>,
43    /// Filter normal versus clone children.
44    pub exit_class: ChildWaitExitClass,
45}
46
47/// What `timer_create`'s `sigev_notify_thread_id` names
48/// (`Scheduler::posix_timer_thread`).
49#[derive(PartialEq, Debug, Eq, Clone, Copy, Serialize, Deserialize)]
50pub enum PosixTimerThread {
51    /// A live thread of the calling process.
52    Thread(DetTid),
53    /// Anything else: Linux's `good_sigevent` answers EINVAL.
54    NotInGroup,
55    /// The caller is in a nested PID namespace, where the id is a pid of
56    /// that namespace, which Detcore does not translate yet
57    /// (<https://github.com/rrnewton/hermit/issues/4155>).
58    NestedNamespace,
59}
60
61/// Scheduler-owned lifecycle state for an exact child-process wait.
62#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
63pub enum ExactChildWaitState {
64    /// The requested process is not a known direct child of the caller.
65    Unknown,
66    /// At least one thread in the child process remains logically live.
67    Running,
68    /// Detcore observed logical exit, but this backend cannot report physical waitability.
69    LogicallyExited,
70    /// The backend has not yet reported the child's final kernel exit status.
71    PhysicalExitPending,
72    /// The backend has reported the child's final kernel exit status.
73    PhysicallyExited,
74}
75
76pub use detcore_model::fd::*;
77pub use detcore_model::futex::*;
78pub use detcore_model::pid::*;
79pub use detcore_model::schedule::SigWrapper;
80pub use detcore_model::schedule::*;
81pub use detcore_model::time::*;