WIP: Remove SYS_CLONE (to be done in userspace).

This commit is contained in:
4lDO2
2022-07-04 10:42:04 +02:00
parent 563121596d
commit 283ada82a0
20 changed files with 380 additions and 909 deletions
+2 -32
View File
@@ -25,9 +25,9 @@ pub use self::process::*;
pub use self::time::*;
pub use self::validate::*;
use self::data::{CloneInfo, ExecMemRange, Map, SigAction, Stat, TimeSpec};
use self::data::{Map, SigAction, Stat, TimeSpec};
use self::error::{Error, Result, ENOSYS, EINVAL};
use self::flag::{CloneFlags, MapFlags, PhysmapFlags, WaitFlags};
use self::flag::{MapFlags, PhysmapFlags, WaitFlags};
use self::number::*;
use crate::context::ContextId;
@@ -112,36 +112,6 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
SYS_GETPGID => getpgid(ContextId::from(b)).map(ContextId::into),
SYS_GETPPID => getppid().map(ContextId::into),
SYS_EXEC => exec(validate_slice(b as *const ExecMemRange, c)?, d, e),
SYS_CLONE => {
let b = CloneFlags::from_bits_truncate(b);
let info = if b.contains(CloneFlags::CLONE_VM) {
if d < core::mem::size_of::<CloneInfo>() {
return Err(Error::new(EINVAL));
}
Some(&validate_slice(c as *const CloneInfo, 1)?[0])
} else { None };
#[cfg(not(target_arch = "x86_64"))]
{
//TODO: CLONE_STACK
let ret = clone(b, bp).map(ContextId::into);
ret
}
#[cfg(target_arch = "x86_64")]
{
let old_rsp = stack.iret.rsp;
// TODO: Unify CLONE_STACK and CLONE_VM.
if b.contains(flag::CLONE_STACK) {
stack.iret.rsp = info.as_ref().ok_or(Error::new(EINVAL))?.target_stack;
}
let ret = clone(b, bp, info).map(ContextId::into);
stack.iret.rsp = old_rsp;
ret
}
},
SYS_EXIT => exit((b & 0xFF) << 8),
SYS_KILL => kill(ContextId::from(b), c),
SYS_WAITPID => waitpid(ContextId::from(b), c, WaitFlags::from_bits_truncate(d)).map(ContextId::into),