From 1a3fa1ef6de66f77d7c2b4696a8d05d375c135fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Miko=C5=82ajczyk?= Date: Mon, 19 Feb 2024 18:33:25 +0000 Subject: [PATCH] Implement sys_thr_get_name --- src/kernel/src/process/mod.rs | 41 +++++++++++++++++++++++++++++++- src/kernel/src/process/thread.rs | 4 ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/kernel/src/process/mod.rs b/src/kernel/src/process/mod.rs index f95380830..0e0712971 100644 --- a/src/kernel/src/process/mod.rs +++ b/src/kernel/src/process/mod.rs @@ -8,7 +8,7 @@ pub use self::signal::*; pub use self::thread::*; use crate::budget::ProcType; -use crate::errno::{EINVAL, ENAMETOOLONG, EPERM, ERANGE, ESRCH}; +use crate::errno::{EFAULT, EINVAL, ENAMETOOLONG, EPERM, ERANGE, ESRCH}; use crate::fs::Vnode; use crate::idt::Idt; use crate::info; @@ -119,6 +119,7 @@ impl VProc { sys.register(585, &vp, Self::sys_is_in_sandbox); sys.register(587, &vp, Self::sys_get_authinfo); sys.register(602, &vp, Self::sys_randomized_path); + sys.register(616, &vp, Self::sys_thr_get_name); Ok(vp) } @@ -446,6 +447,44 @@ impl VProc { Ok(SysOut::ZERO) } + fn sys_thr_get_name(self: &Arc, i: &SysIn) -> Result { + let tid: i32 = i.args[0].try_into().unwrap(); + let name: *mut c_char = i.args[1].into(); + + info!("sys_thr_get_name({:#x}, {:#x})", tid, name as usize); + + let threads = self.threads.read(); + + let thr = threads.iter().find(|t| t.id().get() == tid); + + if name.is_null() { + return Err(SysErr::Raw(EFAULT)); + } + + match thr { + Some(td) => { + let thread_name = td.name().to_owned().unwrap_or("".into()); + unsafe { + name.copy_from_nonoverlapping(thread_name.as_ptr().cast(), thread_name.len()); + *name.add(thread_name.len()) = 0; + } + } + None => { + let td = VThread::current().unwrap(); + if !td.cred().is_system() { + return Err(SysErr::Raw(ESRCH)); + } + + todo!( + "sys_thr_get_name with tid {:#x} not belonging to the process", + tid + ); + } + } + + Ok(SysOut::ZERO) + } + fn sys_rtprio_thread(self: &Arc, i: &SysIn) -> Result { const RTP_LOOKUP: i32 = 0; const RTP_SET: i32 = 1; diff --git a/src/kernel/src/process/thread.rs b/src/kernel/src/process/thread.rs index 3e3b98050..4bde46223 100644 --- a/src/kernel/src/process/thread.rs +++ b/src/kernel/src/process/thread.rs @@ -92,6 +92,10 @@ impl VThread { &self.cpuset } + pub fn name(&self) -> GutexReadGuard<'_, Option> { + self.name.read() + } + pub fn set_name(&self, name: Option<&str>) { *self.name.write() = name.map(|n| n.to_owned()); }