Send event on thread death.

This commit is contained in:
4lDO2
2025-02-21 11:53:38 +01:00
parent db5931504d
commit f40ec48b3e
6 changed files with 55 additions and 15 deletions
+7 -2
View File
@@ -25,6 +25,7 @@ use crate::syscall::error::{Error, Result, EAGAIN, ESRCH};
use super::{
empty_cr3,
file::FileDescription,
memory::{AddrSpaceWrapper, GrantFileRef},
};
@@ -120,6 +121,9 @@ pub struct Context {
pub being_sigkilled: bool,
pub fmap_ret: Option<Frame>,
// TODO: id can reappear after wraparound?
pub owner_proc_id: Option<NonZeroUsize>,
// TODO: Temporary replacement for existing kernel logic, replace with capabilities!
pub ens: SchemeNamespace,
pub euid: u32,
@@ -145,9 +149,9 @@ pub struct SignalState {
}
impl Context {
pub fn new() -> Result<Context> {
pub fn new(owner_proc_id: Option<NonZeroUsize>) -> Result<Context> {
static DEBUG_ID: AtomicU32 = AtomicU32::new(1);
let this = Context {
let this = Self {
debug_id: DEBUG_ID.fetch_add(1, Ordering::Relaxed),
sig: None,
status: Status::HardBlocked {
@@ -172,6 +176,7 @@ impl Context {
userspace: false,
fmap_ret: None,
being_sigkilled: false,
owner_proc_id,
ens: 0.into(),
euid: u32::MAX,
+11 -4
View File
@@ -2,6 +2,8 @@
//!
//! For resources on contexts, please consult [wikipedia](https://en.wikipedia.org/wiki/Context_switch) and [osdev](https://wiki.osdev.org/Context_Switching)
use core::num::NonZeroUsize;
use alloc::{borrow::Cow, collections::BTreeSet, sync::Arc};
use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard};
@@ -68,7 +70,8 @@ pub use self::arch::empty_cr3;
static CONTEXTS: RwLock<BTreeSet<ContextRef>> = RwLock::new(BTreeSet::new());
pub fn init() {
let mut context = Context::new().expect("failed to create kmain context");
let owner = None; // kmain not owned by any fd
let mut context = Context::new(owner).expect("failed to create kmain context");
context.sched_affinity = LogicalCpuSet::empty();
context.sched_affinity.atomic_set(crate::cpu_id());
context.name = Cow::Borrowed("kmain");
@@ -140,11 +143,15 @@ impl PartialEq for ContextRef {
impl Eq for ContextRef {}
/// Spawn a context from a function.
pub fn spawn(userspace_allowed: bool, func: extern "C" fn()) -> Result<Arc<RwSpinlock<Context>>> {
pub fn spawn(
userspace_allowed: bool,
owner_proc_id: Option<NonZeroUsize>,
func: extern "C" fn(),
) -> Result<Arc<RwSpinlock<Context>>> {
let stack = Kstack::new()?;
let context_lock =
Arc::try_new(RwSpinlock::new(Context::new()?)).map_err(|_| Error::new(ENOMEM))?;
let context_lock = Arc::try_new(RwSpinlock::new(Context::new(owner_proc_id)?))
.map_err(|_| Error::new(ENOMEM))?;
CONTEXTS
.write()