Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sys_thr_get_name #674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -446,6 +447,44 @@ impl VProc {
Ok(SysOut::ZERO)
}

fn sys_thr_get_name(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
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<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
const RTP_LOOKUP: i32 = 0;
const RTP_SET: i32 = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/kernel/src/process/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ impl VThread {
&self.cpuset
}

pub fn name(&self) -> GutexReadGuard<'_, Option<String>> {
self.name.read()
}

pub fn set_name(&self, name: Option<&str>) {
*self.name.write() = name.map(|n| n.to_owned());
}
Expand Down