From 2fcb0ad63fd65991c5ef322635ff38bcd6b81eaf Mon Sep 17 00:00:00 2001 From: John Boiles Date: Fri, 17 Jan 2025 16:48:44 -0800 Subject: [PATCH 1/3] Clear SIGRESUME (SIGUSR1) when exiting xPortStartScheduler --- portable/ThirdParty/GCC/Posix/port.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 1bec7afd88..0209218eec 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -202,6 +202,33 @@ void vPortStartFirstTask( void ) } /*-----------------------------------------------------------*/ +/* + * Clear a signal that is pending for the calling thread. + */ +void prvClearPendingSignal( int sig ) +{ + sigset_t set, oldset; + + /* Block the signal */ + sigemptyset( &set ); + sigaddset( &set, sig ); + pthread_sigmask( SIG_BLOCK, &set, &oldset ); + + /* Check if signal is pending */ + sigpending( &set ); + + if( sigismember( &set, sig ) ) + { + int signum; + /* Wait for and remove signal */ + sigwait( &set, &signum ); + } + + /* Restore the original signal mask */ + pthread_sigmask( SIG_SETMASK, &oldset, NULL ); +} +/*-----------------------------------------------------------*/ + /* * See header file for description. */ @@ -250,6 +277,9 @@ BaseType_t xPortStartScheduler( void ) hSigSetupThread = PTHREAD_ONCE_INIT; #endif /* __APPLE__*/ + // Clear SIG_RESUME (SIGUSR1), because it might have fired again while we were shutting things down. + prvClearPendingSignal( SIG_RESUME ); + /* Restore original signal mask. */ ( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); From 94263d23bd1804a8e4548458dc34022348c19022 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Wed, 29 Jan 2025 13:36:14 -0800 Subject: [PATCH 2/3] Simpler, more targeted solution --- portable/ThirdParty/GCC/Posix/port.c | 42 ++++++++-------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index e7feeb6d2d..b1c1554a29 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -260,39 +260,12 @@ void vPortStartFirstTask( void ) } /*-----------------------------------------------------------*/ -/* - * Clear a signal that is pending for the calling thread. - */ -void prvClearPendingSignal( int sig ) -{ - sigset_t set, oldset; - - /* Block the signal */ - sigemptyset( &set ); - sigaddset( &set, sig ); - pthread_sigmask( SIG_BLOCK, &set, &oldset ); - - /* Check if signal is pending */ - sigpending( &set ); - - if( sigismember( &set, sig ) ) - { - int signum; - /* Wait for and remove signal */ - sigwait( &set, &signum ); - } - - /* Restore the original signal mask */ - pthread_sigmask( SIG_SETMASK, &oldset, NULL ); -} -/*-----------------------------------------------------------*/ - /* * See header file for description. */ BaseType_t xPortStartScheduler( void ) { - int iSignal; + int iSignal = 0; sigset_t xSignals; hMainThread = pthread_self(); @@ -318,6 +291,16 @@ BaseType_t xPortStartScheduler( void ) while( xSchedulerEnd != pdTRUE ) { sigwait( &xSignals, &iSignal ); + + /* For some reason, sigwait() doesn't always clear the signal the first time. + * Clear it again if it's still pending. + */ + sigset_t set; + sigpending( &set ); + if( sigismember( &set, SIG_RESUME ) ) + { + sigwait( &xSignals, &iSignal ); + } } /* @@ -335,9 +318,6 @@ BaseType_t xPortStartScheduler( void ) hSigSetupThread = PTHREAD_ONCE_INIT; #endif /* __APPLE__*/ - // Clear SIG_RESUME (SIGUSR1), because it might have fired again while we were shutting things down. - prvClearPendingSignal( SIG_RESUME ); - /* Restore original signal mask. */ ( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); From 4bb54a3cdc72c4202abc96794fb8ed5f43aed977 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Mon, 10 Feb 2025 10:50:37 -0800 Subject: [PATCH 3/3] Add #if __APPLE__ to lldb workaround --- portable/ThirdParty/GCC/Posix/port.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 7e82200b37..ac45b7d69a 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -288,15 +288,18 @@ BaseType_t xPortStartScheduler( void ) { sigwait( &xSignals, &iSignal ); - /* For some reason, sigwait() doesn't always clear the signal the first time. - * Clear it again if it's still pending. - */ - sigset_t set; - sigpending( &set ); - if( sigismember( &set, SIG_RESUME ) ) - { - sigwait( &xSignals, &iSignal ); - } + #if __APPLE__ + /* For some reason, on macOS when running in LLDB, sigwait() doesn't + * always clear the signal the first time. Clear it again if it's still + * pending. + */ + sigset_t set; + sigpending( &set ); + if( sigismember( &set, SIG_RESUME ) ) + { + sigwait( &xSignals, &iSignal ); + } + #endif /* __APPLE__ */ } /*