Add set_tid_address
This commit is contained in:
parent
8dfeb71c90
commit
2f2b74a570
@ -6,7 +6,7 @@ pub mod table {
|
|||||||
pub use self::exit::{do_exit, do_wait4, ChildProcessFilter};
|
pub use self::exit::{do_exit, do_wait4, ChildProcessFilter};
|
||||||
pub use self::spawn::{do_spawn, FileAction};
|
pub use self::spawn::{do_spawn, FileAction};
|
||||||
pub use self::wait::{WaitQueue, Waiter};
|
pub use self::wait::{WaitQueue, Waiter};
|
||||||
pub use self::thread::{do_clone, CloneFlags, ThreadGroup};
|
pub use self::thread::{do_clone, CloneFlags, ThreadGroup, do_set_tid_address};
|
||||||
pub use self::futex::{FutexOp, FutexFlags, futex_op_and_flags_from_u32, futex_wake, futex_wait};
|
pub use self::futex::{FutexOp, FutexFlags, futex_op_and_flags_from_u32, futex_wake, futex_wait};
|
||||||
pub use self::arch_prctl::{ArchPrctlCode, do_arch_prctl};
|
pub use self::arch_prctl::{ArchPrctlCode, do_arch_prctl};
|
||||||
|
|
||||||
@ -24,6 +24,7 @@ pub struct Process {
|
|||||||
// TODO: move cwd, root_inode into a FileSystem structure
|
// TODO: move cwd, root_inode into a FileSystem structure
|
||||||
// TODO: should cwd be a String or INode?
|
// TODO: should cwd be a String or INode?
|
||||||
cwd: String,
|
cwd: String,
|
||||||
|
clear_child_tid: Option<*mut pid_t>,
|
||||||
parent: Option<ProcessRef>,
|
parent: Option<ProcessRef>,
|
||||||
children: Vec<ProcessWeakRef>,
|
children: Vec<ProcessWeakRef>,
|
||||||
waiting_children: Option<WaitQueue<ChildProcessFilter, pid_t>>,
|
waiting_children: Option<WaitQueue<ChildProcessFilter, pid_t>>,
|
||||||
@ -42,7 +43,13 @@ pub fn do_getpid() -> pid_t {
|
|||||||
current.get_pid()
|
current.get_pid()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_getgpid() -> pid_t {
|
pub fn do_gettid() -> pid_t {
|
||||||
|
let current_ref = get_current();
|
||||||
|
let current = current_ref.lock().unwrap();
|
||||||
|
current.get_tid()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn do_getpgid() -> pid_t {
|
||||||
let current_ref = get_current();
|
let current_ref = get_current();
|
||||||
let current = current_ref.lock().unwrap();
|
let current = current_ref.lock().unwrap();
|
||||||
current.get_pgid()
|
current.get_pgid()
|
||||||
|
@ -14,6 +14,7 @@ lazy_static! {
|
|||||||
tgid: 0,
|
tgid: 0,
|
||||||
exit_status: 0,
|
exit_status: 0,
|
||||||
cwd: "/".to_owned(),
|
cwd: "/".to_owned(),
|
||||||
|
clear_child_tid: None,
|
||||||
parent: None,
|
parent: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
waiting_children: Default::default(),
|
waiting_children: Default::default(),
|
||||||
@ -38,6 +39,7 @@ impl Process {
|
|||||||
pgid: new_pid,
|
pgid: new_pid,
|
||||||
tgid: new_pid,
|
tgid: new_pid,
|
||||||
cwd: cwd.to_owned(),
|
cwd: cwd.to_owned(),
|
||||||
|
clear_child_tid: None,
|
||||||
exit_status: 0,
|
exit_status: 0,
|
||||||
parent: None,
|
parent: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
@ -54,15 +56,17 @@ impl Process {
|
|||||||
pub fn get_task_mut(&mut self) -> &mut Task {
|
pub fn get_task_mut(&mut self) -> &mut Task {
|
||||||
&mut self.task
|
&mut self.task
|
||||||
}
|
}
|
||||||
|
/// pid as seen by the user is actually the thread group ID
|
||||||
pub fn get_pid(&self) -> pid_t {
|
pub fn get_pid(&self) -> pid_t {
|
||||||
|
self.tgid
|
||||||
|
}
|
||||||
|
/// tid as seen by the user is actually the process ID
|
||||||
|
pub fn get_tid(&self) -> pid_t {
|
||||||
self.pid
|
self.pid
|
||||||
}
|
}
|
||||||
pub fn get_pgid(&self) -> pid_t {
|
pub fn get_pgid(&self) -> pid_t {
|
||||||
self.pgid
|
self.pgid
|
||||||
}
|
}
|
||||||
pub fn get_tgid(&self) -> pid_t {
|
|
||||||
self.tgid
|
|
||||||
}
|
|
||||||
pub fn get_status(&self) -> Status {
|
pub fn get_status(&self) -> Status {
|
||||||
self.status
|
self.status
|
||||||
}
|
}
|
||||||
@ -101,6 +105,9 @@ impl Drop for Process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for Process {}
|
||||||
|
unsafe impl Sync for Process {}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
RUNNING,
|
RUNNING,
|
||||||
|
@ -82,3 +82,11 @@ fn new_thread_task(user_stack: usize, new_tls: usize) -> Result<Task, Error> {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn do_set_tid_address(tidptr: *mut pid_t) -> Result<pid_t, Error> {
|
||||||
|
info!("set_tid_address: tidptr: {:#x}", tidptr as usize);
|
||||||
|
let current_ref = get_current();
|
||||||
|
let mut current = current_ref.lock().unwrap();
|
||||||
|
current.clear_child_tid = Some(tidptr);
|
||||||
|
Ok(current.get_tid())
|
||||||
|
}
|
||||||
|
@ -79,6 +79,10 @@ pub extern "C" fn dispatch_syscall(
|
|||||||
arg3 as *const *const i8,
|
arg3 as *const *const i8,
|
||||||
arg4 as *const FdOp,
|
arg4 as *const FdOp,
|
||||||
),
|
),
|
||||||
|
SYS_WAIT4 => do_wait4(arg0 as i32, arg1 as *mut i32),
|
||||||
|
SYS_GETPID => do_getpid(),
|
||||||
|
SYS_GETPPID => do_getppid(),
|
||||||
|
|
||||||
SYS_CLONE => do_clone(
|
SYS_CLONE => do_clone(
|
||||||
arg0 as u32,
|
arg0 as u32,
|
||||||
arg1 as usize,
|
arg1 as usize,
|
||||||
@ -86,15 +90,14 @@ pub extern "C" fn dispatch_syscall(
|
|||||||
arg3 as *mut i32,
|
arg3 as *mut i32,
|
||||||
arg4 as usize,
|
arg4 as usize,
|
||||||
),
|
),
|
||||||
SYS_WAIT4 => do_wait4(arg0 as i32, arg1 as *mut i32),
|
|
||||||
SYS_FUTEX => do_futex(
|
SYS_FUTEX => do_futex(
|
||||||
arg0 as *const i32,
|
arg0 as *const i32,
|
||||||
arg1 as u32,
|
arg1 as u32,
|
||||||
arg2 as i32,
|
arg2 as i32,
|
||||||
// TODO: accept other optional arguments
|
// TODO: accept other optional arguments
|
||||||
),
|
),
|
||||||
SYS_GETPID => do_getpid(),
|
SYS_ARCH_PRCTL => do_arch_prctl(arg0 as u32, arg1 as *mut usize),
|
||||||
SYS_GETPPID => do_getppid(),
|
SYS_SET_TID_ADDRESS => do_set_tid_address(arg0 as *mut pid_t),
|
||||||
|
|
||||||
SYS_MMAP => do_mmap(
|
SYS_MMAP => do_mmap(
|
||||||
arg0 as usize,
|
arg0 as usize,
|
||||||
@ -122,8 +125,6 @@ pub extern "C" fn dispatch_syscall(
|
|||||||
|
|
||||||
SYS_GETTIMEOFDAY => do_gettimeofday(arg0 as *mut timeval_t),
|
SYS_GETTIMEOFDAY => do_gettimeofday(arg0 as *mut timeval_t),
|
||||||
|
|
||||||
SYS_ARCH_PRCTL => do_arch_prctl(arg0 as u32, arg1 as *mut usize),
|
|
||||||
|
|
||||||
_ => do_unknown(num, arg0, arg1, arg2, arg3, arg4, arg5),
|
_ => do_unknown(num, arg0, arg1, arg2, arg3, arg4, arg5),
|
||||||
};
|
};
|
||||||
debug!("syscall return: {:?}", ret);
|
debug!("syscall return: {:?}", ret);
|
||||||
@ -506,8 +507,8 @@ fn do_wait4(pid: i32, _exit_status: *mut i32) -> Result<isize, Error> {
|
|||||||
pid if pid < -1 => process::ChildProcessFilter::WithPGID((-pid) as pid_t),
|
pid if pid < -1 => process::ChildProcessFilter::WithPGID((-pid) as pid_t),
|
||||||
-1 => process::ChildProcessFilter::WithAnyPID,
|
-1 => process::ChildProcessFilter::WithAnyPID,
|
||||||
0 => {
|
0 => {
|
||||||
let gpid = process::do_getgpid();
|
let pgid = process::do_getpgid();
|
||||||
process::ChildProcessFilter::WithPGID(gpid)
|
process::ChildProcessFilter::WithPGID(pgid)
|
||||||
}
|
}
|
||||||
pid if pid > 0 => process::ChildProcessFilter::WithPID(pid as pid_t),
|
pid if pid > 0 => process::ChildProcessFilter::WithPID(pid as pid_t),
|
||||||
_ => {
|
_ => {
|
||||||
@ -663,3 +664,7 @@ fn do_arch_prctl(code: u32, addr: *mut usize) -> Result<isize, Error> {
|
|||||||
process::do_arch_prctl(code, addr).map(|_| 0)
|
process::do_arch_prctl(code, addr).map(|_| 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_set_tid_address(tidptr: *mut pid_t) -> Result<isize, Error> {
|
||||||
|
check_mut_ptr(tidptr)?;
|
||||||
|
process::do_set_tid_address(tidptr).map(|tid| tid as isize)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user