From fc615627f660b526298edf6fa573df42acb86d4b Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Thu, 4 Aug 2022 11:11:31 -0700 Subject: [PATCH] Block SIG_RESUME in the main thread of the Posix port so that sigwait works as expected (#532) Co-authored-by: alfred gedeon <28123637+alfred2g@users.noreply.github.com> --- portable/ThirdParty/GCC/Posix/port.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 98b129411..57905bce3 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -191,13 +191,19 @@ portBASE_TYPE xPortStartScheduler( void ) * Interrupts are disabled here already. */ prvSetupTimerInterrupt(); + /* + * Block SIG_RESUME before starting any tasks so the main thread can sigwait on it. + * To sigwait on an unblocked signal is undefined. + * https://pubs.opengroup.org/onlinepubs/009604499/functions/sigwait.html + */ + sigemptyset( &xSignals ); + sigaddset( &xSignals, SIG_RESUME ); + ( void ) pthread_sigmask( SIG_BLOCK, &xSignals, NULL ); + /* Start the first task. */ vPortStartFirstTask(); /* Wait until signaled by vPortEndScheduler(). */ - sigemptyset( &xSignals ); - sigaddset( &xSignals, SIG_RESUME ); - while( xSchedulerEnd != pdTRUE ) { sigwait( &xSignals, &iSignal ); @@ -543,23 +549,10 @@ static void prvSetupSignalsAndSchedulerPolicy( void ) &xAllSignals, &xSchedulerOriginalSignalMask ); - /* SIG_RESUME is only used with sigwait() so doesn't need a - * handler. */ - sigresume.sa_flags = 0; - sigresume.sa_handler = SIG_IGN; - sigfillset( &sigresume.sa_mask ); - sigtick.sa_flags = 0; sigtick.sa_handler = vPortSystemTickHandler; sigfillset( &sigtick.sa_mask ); - iRet = sigaction( SIG_RESUME, &sigresume, NULL ); - - if( iRet == -1 ) - { - prvFatalError( "sigaction", errno ); - } - iRet = sigaction( SIGALRM, &sigtick, NULL ); if( iRet == -1 )