Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复epoll_pwait部分与linux不一致的行为 #1090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions kernel/src/ipc/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,24 @@ pub fn set_current_blocked(new_set: &mut SigSet) {
__set_current_blocked(new_set);
}

/// 参考 https://code.dragonos.org.cn/xref/linux-6.6.21/kernel/signal.c?fi=set_user_sigmask#set_user_sigmask
/// 功能与set_current_blocked相同,多一步保存当前的sig_blocked到saved_sigmask
/// 由于这之中设置了saved_sigmask,因此从系统调用返回之前需要恢复saved_sigmask
pub fn set_user_sigmask(new_set: &mut SigSet) {
let pcb = ProcessManager::current_pcb();
let mut guard = pcb.sig_info_mut();
let oset = *guard.sig_blocked();

let flags = pcb.flags();
flags.set(ProcessFlags::RESTORE_SIG_MASK, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个有问题啊,有设置的地方肯定要有clear的地方。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
我看他这里的逻辑好像就是这样的,当遇到非中断的错误时就会恢复,也就是在restore_saved_sigmask里面恢复信号并且更改标志位


let saved_sigmask = guard.saved_sigmask_mut();
*saved_sigmask = oset;
drop(guard);

set_current_blocked(new_set);
}

/// 设置当前进程的屏蔽信号 (sig_block)
///
/// ## 参数
Expand Down
7 changes: 3 additions & 4 deletions kernel/src/net/event_poll/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use system_error::SystemError;
use crate::{
arch::ipc::signal::SigSet,
filesystem::vfs::file::FileMode,
ipc::signal::set_current_blocked,
ipc::signal::{restore_saved_sigmask, set_user_sigmask},
mm::VirtAddr,
syscall::{
user_access::{UserBufferReader, UserBufferWriter},
Expand Down Expand Up @@ -96,13 +96,12 @@ impl Syscall {
sigmask: &mut SigSet,
) -> Result<usize, SystemError> {
// 设置屏蔽的信号
set_current_blocked(sigmask);
set_user_sigmask(sigmask);

let wait_ret = Self::epoll_wait(epfd, epoll_event, max_events, timespec);

if wait_ret.is_err() && *wait_ret.as_ref().unwrap_err() != SystemError::EINTR {
// TODO: 恢复信号?
// link:https://code.dragonos.org.cn/xref/linux-6.1.9/fs/eventpoll.c#2294
restore_saved_sigmask();
}
wait_ret
}
Expand Down
1 change: 1 addition & 0 deletions kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ pub fn process_init() {
pub struct ProcessSignalInfo {
// 当前进程被屏蔽的信号
sig_blocked: SigSet,
// 暂存旧信号,用于恢复
saved_sigmask: SigSet,
// sig_pending 中存储当前线程要处理的信号
sig_pending: SigPending,
Expand Down