[llvm] r235914 - Fixes a hang that can occur if a signal comes in during malloc calls.

Chris Bieneman beanz at apple.com
Mon Apr 27 13:45:36 PDT 2015


Author: cbieneman
Date: Mon Apr 27 15:45:35 2015
New Revision: 235914

URL: http://llvm.org/viewvc/llvm-project?rev=235914&view=rev
Log:
Fixes a hang that can occur if a signal comes in during malloc calls.

We need to dereference the signals mutex during handler registration so that we force its construction. This is to prevent the first use being during handling an actual signal because you can't safely allocate memory in a signal handler.

Modified:
    llvm/trunk/lib/Support/Unix/Signals.inc

Modified: llvm/trunk/lib/Support/Unix/Signals.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Signals.inc?rev=235914&r1=235913&r2=235914&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Signals.inc (original)
+++ llvm/trunk/lib/Support/Unix/Signals.inc Mon Apr 27 15:45:35 2015
@@ -112,6 +112,12 @@ static void RegisterHandler(int Signal)
 }
 
 static void RegisterHandlers() {
+  // We need to dereference the signals mutex during handler registration so
+  // that we force its construction. This is to prevent the first use being
+  // during handling an actual signal because you can't safely call new in a
+  // signal handler.
+  *SignalsMutex;
+  
   // If the handlers are already registered, we're done.
   if (NumRegisteredSignals != 0) return;
 





More information about the llvm-commits mailing list