From 732e07d83f0d642a7902220dd6720be669cd79cb Mon Sep 17 00:00:00 2001 From: "binary.bruce" Date: Mon, 22 Apr 2024 20:57:45 +0800 Subject: [PATCH 1/2] fix get status --- ulib/axstarry/src/syscall_fs/ctype/eventfd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ulib/axstarry/src/syscall_fs/ctype/eventfd.rs b/ulib/axstarry/src/syscall_fs/ctype/eventfd.rs index 1314215164..a93306521a 100644 --- a/ulib/axstarry/src/syscall_fs/ctype/eventfd.rs +++ b/ulib/axstarry/src/syscall_fs/ctype/eventfd.rs @@ -142,10 +142,10 @@ impl FileIO for EventFd { fn get_status(&self) -> OpenFlags { let mut status = OpenFlags::RDWR; if self.flags & EventFdFlag::EFD_NONBLOCK.bits() != 0 { - status &= OpenFlags::NON_BLOCK; + status |= OpenFlags::NON_BLOCK; } if self.flags & EventFdFlag::EFD_CLOEXEC.bits() != 0 { - status &= OpenFlags::CLOEXEC; + status |= OpenFlags::CLOEXEC; } status From 8706e6d0825134dae1b3a69c8511cc9a62a841af Mon Sep 17 00:00:00 2001 From: rayylee Date: Tue, 23 Apr 2024 21:39:45 +0800 Subject: [PATCH 2/2] epoll: fix deadlock for fd_table Signed-off-by: rayylee --- ulib/axstarry/src/syscall_fs/ctype/epoll.rs | 2 +- ulib/axstarry/src/syscall_fs/imp/epoll.rs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ulib/axstarry/src/syscall_fs/ctype/epoll.rs b/ulib/axstarry/src/syscall_fs/ctype/epoll.rs index 018bda8373..ca0e35ad9f 100644 --- a/ulib/axstarry/src/syscall_fs/ctype/epoll.rs +++ b/ulib/axstarry/src/syscall_fs/ctype/epoll.rs @@ -150,8 +150,8 @@ impl EpollFile { let mut ret_events = Vec::new(); loop { let current_process = current_process(); - let fd_table = current_process.fd_manager.fd_table.lock(); for req_event in events.iter() { + let fd_table = current_process.fd_manager.fd_table.lock(); if let Some(file) = &fd_table[req_event.data as usize] { let mut ret_event_type = EpollEventType::empty(); if file.is_hang_up() { diff --git a/ulib/axstarry/src/syscall_fs/imp/epoll.rs b/ulib/axstarry/src/syscall_fs/imp/epoll.rs index e3cad4bd67..df41ae372f 100644 --- a/ulib/axstarry/src/syscall_fs/imp/epoll.rs +++ b/ulib/axstarry/src/syscall_fs/imp/epoll.rs @@ -1,6 +1,6 @@ //! The epoll API performs a similar task to poll: monitoring //! multiple file descriptors to see if I/O is possible on any of -//! them. +//! them. extern crate alloc; use crate::{SyscallError, SyscallResult}; use alloc::sync::Arc; @@ -96,15 +96,17 @@ pub fn syscall_epoll_wait(args: [usize; 6]) -> SyscallResult { return Err(SyscallError::EFAULT); } - let fd_table = process.fd_manager.fd_table.lock(); - let epoll_file = if let Some(file) = fd_table[epfd as usize].as_ref() { - if let Some(epoll_file) = file.as_any().downcast_ref::() { - epoll_file.clone() + let epoll_file = { + let fd_table = process.fd_manager.fd_table.lock(); + if let Some(file) = fd_table[epfd as usize].as_ref() { + if let Some(epoll_file) = file.as_any().downcast_ref::() { + epoll_file.clone() + } else { + return Err(SyscallError::EBADF); + } } else { return Err(SyscallError::EBADF); } - } else { - return Err(SyscallError::EBADF); }; let timeout = if timeout > 0 {