2024-03-12 13:48:09 +02:00
|
|
|
//! Data structures for process management
|
|
|
|
|
2024-03-12 14:47:15 +02:00
|
|
|
use core::{fmt, time::Duration};
|
2024-03-12 13:48:09 +02:00
|
|
|
|
|
|
|
use crate::{impl_place_lifetime, io::FileMode};
|
|
|
|
|
|
|
|
mod exit;
|
|
|
|
mod signal;
|
|
|
|
mod spawn;
|
|
|
|
|
2024-03-12 14:47:15 +02:00
|
|
|
pub use crate::generated::{ProcessId, ThreadId};
|
2024-03-12 13:48:09 +02:00
|
|
|
pub use exit::ExitCode;
|
|
|
|
pub use signal::{Signal, SignalEntryData};
|
|
|
|
pub use spawn::{ExecveOptions, SpawnOption, SpawnOptions, ThreadSpawnOptions};
|
|
|
|
|
|
|
|
/// 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],
|
|
|
|
}
|
|
|
|
}
|
2024-03-12 14:47:15 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|