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