1*ab5c8ca4Slogin use core::ffi::{c_int, c_void}; 2*ab5c8ca4Slogin 3*ab5c8ca4Slogin use crate::{ 4*ab5c8ca4Slogin arch::asm::current::current_pcb, 5*ab5c8ca4Slogin include::bindings::bindings::{pid_t, process_do_exit}, 6*ab5c8ca4Slogin syscall::{Syscall, SystemError}, 7*ab5c8ca4Slogin }; 8*ab5c8ca4Slogin 9*ab5c8ca4Slogin extern "C" { 10*ab5c8ca4Slogin fn c_sys_wait4(pid: pid_t, wstatus: *mut c_int, options: c_int, rusage: *mut c_void) -> c_int; 11*ab5c8ca4Slogin } 12*ab5c8ca4Slogin 13*ab5c8ca4Slogin impl Syscall { 14*ab5c8ca4Slogin #[allow(dead_code)] 15*ab5c8ca4Slogin pub fn fork(&self) -> Result<usize, SystemError> { 16*ab5c8ca4Slogin // 由于进程管理未完成重构,fork调用暂时在arch/x86_64/syscall.rs中调用,以后会移动到这里。 17*ab5c8ca4Slogin todo!() 18*ab5c8ca4Slogin } 19*ab5c8ca4Slogin 20*ab5c8ca4Slogin #[allow(dead_code)] 21*ab5c8ca4Slogin pub fn vfork(&self) -> Result<usize, SystemError> { 22*ab5c8ca4Slogin // 由于进程管理未完成重构,vfork调用暂时在arch/x86_64/syscall.rs中调用,以后会移动到这里。 23*ab5c8ca4Slogin todo!() 24*ab5c8ca4Slogin } 25*ab5c8ca4Slogin 26*ab5c8ca4Slogin #[allow(dead_code)] 27*ab5c8ca4Slogin pub fn execve( 28*ab5c8ca4Slogin _path: *const c_void, 29*ab5c8ca4Slogin _argv: *const *const c_void, 30*ab5c8ca4Slogin _envp: *const *const c_void, 31*ab5c8ca4Slogin ) -> Result<usize, SystemError> { 32*ab5c8ca4Slogin // 由于进程管理未完成重构,execve调用暂时在arch/x86_64/syscall.rs中调用,以后会移动到这里。 33*ab5c8ca4Slogin todo!() 34*ab5c8ca4Slogin } 35*ab5c8ca4Slogin 36*ab5c8ca4Slogin pub fn wait4( 37*ab5c8ca4Slogin pid: pid_t, 38*ab5c8ca4Slogin wstatus: *mut c_int, 39*ab5c8ca4Slogin options: c_int, 40*ab5c8ca4Slogin rusage: *mut c_void, 41*ab5c8ca4Slogin ) -> Result<usize, SystemError> { 42*ab5c8ca4Slogin let ret = unsafe { c_sys_wait4(pid, wstatus, options, rusage) }; 43*ab5c8ca4Slogin if (ret as isize) < 0 { 44*ab5c8ca4Slogin return Err(SystemError::from_posix_errno(-(ret as isize) as i32) 45*ab5c8ca4Slogin .expect("wait4: Invalid errno")); 46*ab5c8ca4Slogin } 47*ab5c8ca4Slogin return Ok(ret as usize); 48*ab5c8ca4Slogin } 49*ab5c8ca4Slogin 50*ab5c8ca4Slogin /// # 退出进程 51*ab5c8ca4Slogin /// 52*ab5c8ca4Slogin /// ## 参数 53*ab5c8ca4Slogin /// 54*ab5c8ca4Slogin /// - status: 退出状态 55*ab5c8ca4Slogin pub fn exit(status: usize) -> ! { 56*ab5c8ca4Slogin unsafe { process_do_exit(status as u64) }; 57*ab5c8ca4Slogin loop {} 58*ab5c8ca4Slogin } 59*ab5c8ca4Slogin 60*ab5c8ca4Slogin /// # 获取进程ID 61*ab5c8ca4Slogin pub fn getpid() -> Result<usize, SystemError> { 62*ab5c8ca4Slogin return Ok(current_pcb().pid as usize); 63*ab5c8ca4Slogin } 64*ab5c8ca4Slogin } 65