@@ -332,54 +332,19 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
332332 return Ok ( callback ( ) ) ;
333333 }
334334 return DefaultStack :: new ( stack_size) . map ( |stack| {
335- // RAII guard to ensure stack info is popped and SIGURG mask is
336- // restored even if `callback` panics/unwinds during on_stack().
335+ // RAII guard to ensure stack info is popped even if
336+ // `callback` panics/unwinds during on_stack().
337337 struct OnStackGuard < ' a > {
338338 stack_infos : & ' a mut VecDeque < StackInfo > ,
339- #[ cfg( all( unix, feature = "preemptive" ) ) ]
340- old_mask : Result < SigSet , nix:: Error > ,
341- #[ cfg( all( unix, feature = "preemptive" ) ) ]
342- sigurg_mask : SigSet ,
343339 }
344340 impl Drop for OnStackGuard < ' _ > {
345341 fn drop ( & mut self ) {
346- #[ cfg( all( unix, feature = "preemptive" ) ) ]
347- {
348- // Restore original signal mask to unblock SIGURG.
349- // Use saved mask for correctness with nested maybe_grow_with;
350- // fall back to thread_unblock if the old mask wasn't saved.
351- match & self . old_mask {
352- Ok ( old) => {
353- _ = old. thread_set_mask ( ) ;
354- }
355- Err ( _) => {
356- _ = self . sigurg_mask . thread_unblock ( ) ;
357- }
358- }
359- }
360342 _ = self . stack_infos . pop_back ( ) ;
361343 }
362344 }
363345 co. stack_infos_mut ( ) . push_back ( StackInfo :: from ( & stack) ) ;
364- cfg_if:: cfg_if! {
365- if #[ cfg( all( unix, feature = "preemptive" ) ) ] {
366- let mut sigurg_mask = SigSet :: empty( ) ;
367- sigurg_mask. add( Signal :: SIGURG ) ;
368- let old_mask = SigSet :: thread_get_mask( ) ;
369- _ = sigurg_mask. thread_block( ) ;
370- }
371- }
372- // Block SIGURG during on_stack to prevent preemptive signal from
373- // corrupting the stack context. When the coroutine is executing on
374- // a grown stack via on_stack(), a SIGURG-triggered suspend would
375- // context-switch back to the scheduler with an inconsistent stack,
376- // causing SIGSEGV on resume (especially on aarch64).
377346 let guard = OnStackGuard {
378347 stack_infos : co. stack_infos_mut ( ) ,
379- #[ cfg( all( unix, feature = "preemptive" ) ) ]
380- old_mask,
381- #[ cfg( all( unix, feature = "preemptive" ) ) ]
382- sigurg_mask,
383348 } ;
384349 let r = corosensei:: on_stack ( stack, callback) ;
385350 drop ( guard) ;
0 commit comments