From 465128da26ef43b73ddef92fe89f079b123f4768 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 1 Jul 2024 17:31:37 +0200 Subject: [PATCH] Don't block nanosleep/futex <= signals are pending. --- src/syscall/futex.rs | 6 ++++++ src/syscall/time.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/syscall/futex.rs b/src/syscall/futex.rs index e961e8f5b5..6d66c4bcf5 100644 --- a/src/syscall/futex.rs +++ b/src/syscall/futex.rs @@ -3,6 +3,7 @@ //! //! For more information about futexes, please read [this](https://eli.thegreenplace.net/2018/basics-of-futexes/) blog post, and the [futex(2)](http://man7.org/linux/man-pages/man2/futex.2.html) man page use alloc::{collections::VecDeque, sync::{Arc, Weak}}; +use syscall::EINTR; use core::sync::atomic::{AtomicU32, Ordering}; use rmm::Arch; use spin::RwLock; @@ -131,6 +132,11 @@ pub fn futex(addr: usize, op: usize, val: usize, val2: usize, addr2: usize) -> R let mut context = context_lock.write(); context.wake = timeout_opt.map(|TimeSpec { tv_sec, tv_nsec }| tv_sec as u128 * time::NANOS_PER_SEC + tv_nsec as u128); + if let Some((tctl, _pctl, _)) = context.sigcontrol() { + if tctl.currently_pending_unblocked() != 0 { + return Err(Error::new(EINTR)); + } + } context.block("futex"); } diff --git a/src/syscall/time.rs b/src/syscall/time.rs index 0160c02c59..2a7d33f51c 100644 --- a/src/syscall/time.rs +++ b/src/syscall/time.rs @@ -34,6 +34,12 @@ pub fn nanosleep(req_buf: UserSliceRo, rem_buf_opt: Option) -> Resu { let mut context = current_context.write(); + if let Some((tctl, _pctl, _)) = context.sigcontrol() { + if tctl.currently_pending_unblocked() != 0 { + return Err(Error::new(EINTR)); + } + } + context.wake = Some(end); context.block("nanosleep"); }