From 1b1a3f3f937a0a5e787be72eaa894abbe59b393a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:03:59 +0000 Subject: [PATCH 1/2] Initial plan From 1eebc574dae37b433aa470420c601af8b760faf2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:16:57 +0000 Subject: [PATCH 2/2] Remove SIGURG blocking from maybe_grow_with to allow preemptive scheduling on grown stacks Agent-Logs-Url: https://github.com/acl-dev/open-coroutine/sessions/20b581e3-30f1-4e74-b014-4d33795a3902 Co-authored-by: loongs-zhang <38336731+loongs-zhang@users.noreply.github.com> --- core/src/coroutine/korosensei.rs | 39 ++------------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/core/src/coroutine/korosensei.rs b/core/src/coroutine/korosensei.rs index 4c03949d..c646c321 100644 --- a/core/src/coroutine/korosensei.rs +++ b/core/src/coroutine/korosensei.rs @@ -332,54 +332,19 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> { return Ok(callback()); } return DefaultStack::new(stack_size).map(|stack| { - // RAII guard to ensure stack info is popped and SIGURG mask is - // restored even if `callback` panics/unwinds during on_stack(). + // RAII guard to ensure stack info is popped even if + // `callback` panics/unwinds during on_stack(). struct OnStackGuard<'a> { stack_infos: &'a mut VecDeque, - #[cfg(all(unix, feature = "preemptive"))] - old_mask: Result, - #[cfg(all(unix, feature = "preemptive"))] - sigurg_mask: SigSet, } impl Drop for OnStackGuard<'_> { fn drop(&mut self) { - #[cfg(all(unix, feature = "preemptive"))] - { - // Restore original signal mask to unblock SIGURG. - // Use saved mask for correctness with nested maybe_grow_with; - // fall back to thread_unblock if the old mask wasn't saved. - match &self.old_mask { - Ok(old) => { - _ = old.thread_set_mask(); - } - Err(_) => { - _ = self.sigurg_mask.thread_unblock(); - } - } - } _ = self.stack_infos.pop_back(); } } co.stack_infos_mut().push_back(StackInfo::from(&stack)); - cfg_if::cfg_if! { - if #[cfg(all(unix, feature = "preemptive"))] { - let mut sigurg_mask = SigSet::empty(); - sigurg_mask.add(Signal::SIGURG); - let old_mask = SigSet::thread_get_mask(); - _ = sigurg_mask.thread_block(); - } - } - // Block SIGURG during on_stack to prevent preemptive signal from - // corrupting the stack context. When the coroutine is executing on - // a grown stack via on_stack(), a SIGURG-triggered suspend would - // context-switch back to the scheduler with an inconsistent stack, - // causing SIGSEGV on resume (especially on aarch64). let guard = OnStackGuard { stack_infos: co.stack_infos_mut(), - #[cfg(all(unix, feature = "preemptive"))] - old_mask, - #[cfg(all(unix, feature = "preemptive"))] - sigurg_mask, }; let r = corosensei::on_stack(stack, callback); drop(guard);