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