1 use core::ffi::c_int; 2 3 use crate::{ 4 filesystem::vfs::file::{File, FileMode}, 5 process::{Pid, ProcessManager}, 6 syscall::{user_access::UserBufferWriter, Syscall, SystemError}, 7 }; 8 9 use super::pipe::LockedPipeInode; 10 11 impl Syscall { 12 /// # 创建带参数的匿名管道 13 /// 14 /// ## 参数 15 /// 16 /// - `fd`: 用于返回文件描述符的数组 17 /// - `flags`:设置管道的参数 18 pub fn pipe2(fd: *mut i32, flags: FileMode) -> Result<usize, SystemError> { 19 if flags.contains(FileMode::O_NONBLOCK) 20 || flags.contains(FileMode::O_CLOEXEC) 21 || flags.contains(FileMode::O_RDONLY) 22 { 23 let mut user_buffer = 24 UserBufferWriter::new(fd, core::mem::size_of::<[c_int; 2]>(), true)?; 25 let fd = user_buffer.buffer::<i32>(0)?; 26 let pipe_ptr = LockedPipeInode::new(flags); 27 let mut read_file = File::new(pipe_ptr.clone(), FileMode::O_RDONLY)?; 28 let mut write_file = File::new(pipe_ptr.clone(), FileMode::O_WRONLY)?; 29 if flags.contains(FileMode::O_CLOEXEC) { 30 read_file.set_close_on_exec(true); 31 write_file.set_close_on_exec(true); 32 } 33 let fd_table_ptr = ProcessManager::current_pcb().fd_table(); 34 let mut fd_table_guard = fd_table_ptr.write(); 35 let read_fd = fd_table_guard.alloc_fd(read_file, None)?; 36 let write_fd = fd_table_guard.alloc_fd(write_file, None)?; 37 38 drop(fd_table_guard); 39 40 fd[0] = read_fd; 41 fd[1] = write_fd; 42 Ok(0) 43 } else { 44 Err(SystemError::EINVAL) 45 } 46 } 47 48 pub fn kill(_pid: Pid, _sig: c_int) -> Result<usize, SystemError> { 49 // todo: 由于进程管理重构,目前删除了signal功能,将来重新实现它。 50 return Err(SystemError::ENOSYS); 51 } 52 53 /// @brief 用户程序用于设置信号处理动作的函数(遵循posix2008) 54 /// 55 /// @param regs->r8 signumber 信号的编号 56 /// @param regs->r9 act 新的,将要被设置的sigaction 57 /// @param regs->r10 oact 返回给用户的原本的sigaction(内核将原本的sigaction的值拷贝给这个地址) 58 /// 59 /// @return int 错误码 60 #[no_mangle] 61 pub fn sigaction( 62 _sig: c_int, 63 _act: usize, 64 _old_act: usize, 65 _from_user: bool, 66 ) -> Result<usize, SystemError> { 67 // todo: 由于进程管理重构,目前删除了signal功能,将来重新实现它。 68 return Err(SystemError::ENOSYS); 69 } 70 } 71