73 lines
1.9 KiB
Rust

//! Data structures for process management
use core::{fmt, time::Duration};
use crate::{
impl_place_lifetime,
io::{FileMode, RawFd},
};
mod exit;
pub use crate::generated::{
ExecveOptions, ProcessId, Signal, SignalEntryData, SpawnOptions, ThreadId, ThreadSpawnOptions,
};
pub use exit::ExitCode;
/// Defines an optional argument for controlling process creation
#[derive(Debug)]
pub enum SpawnOption {
/// Indicates a new process should inherit a file descriptor from its creator
InheritFile {
/// FD on the creator side
source: RawFd,
/// What FD number should be used in the child
child: RawFd,
},
/// The new process should be placed in the specified group
SetProcessGroup(ProcessId),
/// Gain terminal control for the given FD
GainTerminal(RawFd),
}
/// Describes a single mutex operation
#[derive(Clone, Debug)]
#[repr(C)]
pub enum MutexOperation {
/// Waits on the mutex object until it is different from "compare value"
Wait(u32, Option<Duration>),
/// Wakes a single mutex-waiting thread
Wake,
/// Wakes all threads waiting on the mutex
WakeAll,
}
/// Provides some amount of process-related information
#[derive(Clone, Debug)]
pub enum ProcessInfoElement {
/// Mask applied to file modes when creating new files/directories
Umask(FileMode),
}
// TODO not sure if I really need #[repr(C)] ABI here
impl_place_lifetime! {
#[doc = "Argument struct passed from the kernel to a spawned process"]
#[derive(Debug)]
pub struct ProgramArgumentInner<'a> {
#[doc = "Argument list"]
pub args: &'a [&'a str],
#[doc = "List of KEY=VALUE environment variable pairs"]
pub env: &'a [&'a str],
}
}
impl ProcessId {
pub const ZERO: Self = Self(0);
}
impl fmt::Display for ProcessId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<Process {}>", self.0)
}
}