Fix GC_suspend_thread regarding potential cancellation of sem_wait
authorIvan Maidanski <ivmai@mail.ru>
Tue, 21 Jun 2016 09:12:56 +0000 (12:12 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 21 Jun 2016 09:12:56 +0000 (12:12 +0300)
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Call DISABLE_CANCEL before sem_wait, call RESTORE_CANCEL after it.

pthread_stop_world.c

index 1ee9ee8..dad1fdc 100644 (file)
@@ -412,6 +412,7 @@ STATIC void GC_restart_handler(int sig)
 
     GC_API void GC_CALL GC_suspend_thread(GC_SUSPEND_THREAD_ID thread) {
       GC_thread t;
+      IF_CANCEL(int cancel_state;)
       DCL_LOCK_STATE;
 
       LOCK();
@@ -447,10 +448,13 @@ STATIC void GC_restart_handler(int sig)
       /* Wait for the thread to complete threads table lookup and   */
       /* stack_ptr assignment.                                      */
       GC_ASSERT(GC_thr_initialized);
+      DISABLE_CANCEL(cancel_state);
+                /* GC_suspend_thread is not a cancellation point.   */
       while (sem_wait(&GC_suspend_ack_sem) != 0) {
         if (errno != EINTR)
           ABORT("sem_wait for handler failed (suspend_self)");
       }
+      RESTORE_CANCEL(cancel_state);
       UNLOCK();
     }