diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 2b2b9d47ed..0b9bf91ed5 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -5,7 +5,7 @@ use crate::{ context::{HardBlockedReason, SignalState}, file::{FileDescriptor, InternalFlags}, memory::{handle_notify_files, AddrSpaceWrapper, Grant, PageSpan}, - process::{self, Process, ProcessId, ProcessInfo}, + process::{self, Process, ProcessId, ProcessInfo, ProcessStatus}, Context, ContextRef, Status, }, memory::PAGE_SIZE, @@ -201,22 +201,27 @@ impl Handle { impl Handle { fn continue_ignored_children(&mut self) -> Option<()> { let Handle::Process { - process, - kind: ProcHandle::Trace { pid, clones, .. }, + kind: ProcHandle::Trace { clones, .. }, + .. } = self else { return None; }; - let contexts = context::contexts(); for pid in clones.drain(..) { if ptrace::is_traced(pid) { continue; } - if let Some(process) = process::PROCESSES.read().get(&pid) { - let mut process = process.write(); - // FIXME - //context.status = context::Status::Runnable; + let Some(child_process) = process::PROCESSES.read().get(&pid).map(Arc::clone) else { + continue; + }; + for thread in child_process + .read() + .threads + .iter() + .filter_map(|t| t.upgrade()) + { + thread.write().status = context::Status::Runnable; } } Some(()) @@ -306,7 +311,7 @@ impl ProcScheme { "exe" => ( ProcHandle::Static { ty: "exe", - // FIXME + // FIXME: allow opening any thread bytes: target .read() .threads @@ -376,12 +381,9 @@ impl ProcScheme { { let target = target.read(); - // FIXME - /* - if let Status::Exited(_) = target.status { + if let ProcessStatus::Exited(_) = target.status { return Err(Error::new(ESRCH)); } - */ // Unless root, check security if handle.needs_child_process() && uid != 0 && gid != 0 { @@ -471,9 +473,12 @@ impl ProcScheme { } if flags & O_TRUNC == O_TRUNC { - let mut target = target.write(); - // FIXME - //target.ptrace_stop = true; + let target = target.read(); + for thread in target.threads.iter().filter_map(|t| t.upgrade()) { + thread.write().status = context::Status::HardBlocked { + reason: HardBlockedReason::PtraceStop, + }; + } } } @@ -1015,13 +1020,11 @@ impl ProcHandle { } // disable the ptrace_stop flag, which is used in some cases - // FIXME - /* - with_context_mut(info.pid, |context| { - context.ptrace_stop = false; - Ok(()) - })?; - */ + for thread in process.read().threads.iter().filter_map(|t| t.upgrade()) { + thread.write().status = context::Status::HardBlocked { + reason: HardBlockedReason::PtraceStop, + }; + } // and notify the tracee's WaitCondition, which is used in other cases ptrace::Session::with_session(pid, |session| { @@ -1082,14 +1085,17 @@ impl ProcHandle { ) -> Result { match self { Self::Static { bytes, .. } => read_from(buf, &bytes, offset), - Self::Trace { pid, clones, .. } => { + Self::Trace { pid, .. } => { // Wait for event if (read_flags as usize) & O_NONBLOCK != O_NONBLOCK { ptrace::wait(pid)?; } - // Check if process exists FIXME - //with_context(pid, |_| Ok(()))?; + // Check if process exists + let _ = process::PROCESSES + .read() + .get(&pid) + .ok_or(Error::new(ESRCH))?; let mut src_buf = [PtraceEvent::default(); 4]; diff --git a/src/scheme/user.rs b/src/scheme/user.rs index c4425272ba..2b3204d79e 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -891,8 +891,7 @@ impl UserInner { _ => return Err(Error::new(ENOENT)), }; - // FIXME: Description can leak if context::current() fails, or if there is no - // additional file table space. + // FIXME: Description can leak if there is no additional file table space. if flags.contains(FobtainFdFlags::MANUAL_FD) { context::current().read().insert_file( FileHandle::from(dst_fd_or_ptr),