[PATCH 03/15] posix: Fix _POSIX_signals_Check_signal()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Apr 5 13:09:48 UTC 2016


Do not save and restore the thread wait information.  This is
superfluous and may overwrite thread wait information updates due to
interrupts leading to system corruption.
---
 cpukit/posix/src/psignal.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/cpukit/posix/src/psignal.c b/cpukit/posix/src/psignal.c
index 354fb33..6e18e05 100644
--- a/cpukit/posix/src/psignal.c
+++ b/cpukit/posix/src/psignal.c
@@ -113,10 +113,8 @@ static void _POSIX_signals_Check_signal(
   bool                is_global
 )
 {
-  siginfo_t                   siginfo_struct;
-  sigset_t                    saved_signals_unblocked;
-  Thread_Wait_information     stored_thread_wait_information;
-  Thread_Control             *executing;
+  siginfo_t siginfo_struct;
+  sigset_t  saved_signals_unblocked;
 
   if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct,
                                        is_global, true, true ) )
@@ -143,16 +141,6 @@ static void _POSIX_signals_Check_signal(
   saved_signals_unblocked = api->signals_unblocked;
   api->signals_unblocked &= ~_POSIX_signals_Vectors[ signo ].sa_mask;
 
-  executing = _Thread_Get_executing();
-
-  /*
-   *  We have to save the blocking information of the current wait queue
-   *  because the signal handler may subsequently go on and put the thread
-   *  on a wait queue, for its own purposes.
-   */
-  memcpy( &stored_thread_wait_information, &executing->Wait,
-          sizeof( stored_thread_wait_information ));
-
   /*
    *  Here, the signal handler function executes
    */
@@ -170,12 +158,6 @@ static void _POSIX_signals_Check_signal(
   }
 
   /*
-   *  Restore the blocking information
-   */
-  memcpy( &executing->Wait, &stored_thread_wait_information,
-          sizeof( executing->Wait ));
-
-  /*
    *  Restore the previous set of unblocked signals
    */
   api->signals_unblocked = saved_signals_unblocked;
@@ -211,6 +193,15 @@ void _POSIX_signals_Action_handler(
     return;
 
   /*
+   *  In case the executing thread is blocked or about to block on something
+   *  that uses the thread wait information, then this is a kernel bug.
+   */
+  _Assert(
+    ( _Thread_Wait_flags_get( executing )
+      & ( THREAD_WAIT_STATE_BLOCKED | THREAD_WAIT_STATE_INTEND_TO_BLOCK ) ) == 0
+  );
+
+  /*
    *  If we invoke any user code, there is the possibility that
    *  a new signal has been posted that we should process so we
    *  restart the loop if a signal handler was invoked.
-- 
1.8.4.5




More information about the devel mailing list