Bug 946883 - Use NSPR thread for AsmJSMachExceptionHandler on OS X, so that it works with PosixNSPR. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 06 Dec 2013 21:03:27 +0100
changeset 159224 d86f108365974d2866cc36e1de9410f74768ceac
parent 159223 94cdaced90bf49679eae210824875570fb98df9c
child 159225 17760eeea357da23abfae4b120c0e96c46a7e33d
push id37231
push userjandemooij@gmail.com
push dateFri, 06 Dec 2013 20:05:07 +0000
treeherdermozilla-inbound@d86f10836597 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs946883
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946883 - Use NSPR thread for AsmJSMachExceptionHandler on OS X, so that it works with PosixNSPR. r=luke
js/src/jit/AsmJSSignalHandlers.cpp
js/src/jit/AsmJSSignalHandlers.h
--- a/js/src/jit/AsmJSSignalHandlers.cpp
+++ b/js/src/jit/AsmJSSignalHandlers.cpp
@@ -677,17 +677,17 @@ HandleMachException(JSRuntime *rt, const
 }
 
 // Taken from mach_exc in /usr/include/mach/mach_exc.defs.
 static const mach_msg_id_t sExceptionId = 2405;
 
 // The choice of id here is arbitrary, the only constraint is that sQuitId != sExceptionId.
 static const mach_msg_id_t sQuitId = 42;
 
-void *
+void
 AsmJSMachExceptionHandlerThread(void *threadArg)
 {
     JSRuntime *rt = reinterpret_cast<JSRuntime*>(threadArg);
     mach_port_t port = rt->asmJSMachExceptionHandler.port();
     kern_return_t kret;
 
     while(true) {
         ExceptionRequest request;
@@ -728,18 +728,16 @@ AsmJSMachExceptionHandlerThread(void *th
         reply.Head.msgh_remote_port = request.body.Head.msgh_remote_port;
         reply.Head.msgh_local_port = MACH_PORT_NULL;
         reply.Head.msgh_id = request.body.Head.msgh_id + 100;
         reply.NDR = NDR_record;
         reply.RetCode = replyCode;
         mach_msg(&reply.Head, MACH_SEND_MSG, sizeof(reply), 0, MACH_PORT_NULL,
                  MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
     }
-
-    return nullptr;
 }
 
 AsmJSMachExceptionHandler::AsmJSMachExceptionHandler()
   : installed_(false),
     thread_(nullptr),
     port_(MACH_PORT_NULL)
 {}
 
@@ -770,17 +768,17 @@ AsmJSMachExceptionHandler::uninstall()
         kern_return_t kret = mach_msg(&msg, MACH_SEND_MSG, sizeof(msg), 0, MACH_PORT_NULL,
                                       MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
         if (kret != KERN_SUCCESS) {
             fprintf(stderr, "AsmJSMachExceptionHandler: failed to send quit message: %d\n", (int)kret);
             MOZ_CRASH();
         }
 
         // Wait for the handler thread to complete before deallocating the port.
-        pthread_join(thread_, nullptr);
+        PR_JoinThread(thread_);
         thread_ = nullptr;
     }
     if (port_ != MACH_PORT_NULL) {
         DebugOnly<kern_return_t> kret = mach_port_destroy(mach_task_self(), port_);
         JS_ASSERT(kret == KERN_SUCCESS);
         port_ = MACH_PORT_NULL;
     }
 }
@@ -796,17 +794,19 @@ AsmJSMachExceptionHandler::install(JSRun
     kret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port_);
     if (kret != KERN_SUCCESS)
         goto error;
     kret = mach_port_insert_right(mach_task_self(), port_, port_, MACH_MSG_TYPE_MAKE_SEND);
     if (kret != KERN_SUCCESS)
         goto error;
 
     // Create a thread to block on reading port_.
-    if (pthread_create(&thread_, nullptr, AsmJSMachExceptionHandlerThread, rt))
+    thread_ = PR_CreateThread(PR_USER_THREAD, AsmJSMachExceptionHandlerThread, rt,
+                              PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+    if (!thread_)
         goto error;
 
     // Direct exceptions on this thread to port_ (and thus our handler thread).
     // Note: we are totally clobbering any existing *thread* exception ports and
     // not even attempting to forward. Breakpad and gdb both use the *process*
     // exception ports which are only called if the thread doesn't handle the
     // exception, so we should be fine.
     thread = mach_thread_self();
--- a/js/src/jit/AsmJSSignalHandlers.h
+++ b/js/src/jit/AsmJSSignalHandlers.h
@@ -6,17 +6,17 @@
 
 #ifndef jit_AsmJSSignalHandlers_h
 #define jit_AsmJSSignalHandlers_h
 
 struct JSRuntime;
 
 #ifdef XP_MACOSX
 # include <mach/mach.h>
-# include <pthread.h>
+# include "jslock.h"
 #endif
 
 namespace js {
 
 // Returns whether signal handlers for asm.js and for JitRuntime access
 // violations have been installed.
 bool
 EnsureAsmJSSignalHandlersInstalled(JSRuntime *rt);
@@ -31,17 +31,17 @@ TriggerOperationCallbackForAsmJSCode(JSR
 // rather require an extra thread. For simplicity, we create one such thread
 // per JSRuntime (upon the first use of asm.js in the JSRuntime). This thread
 // and related resources are owned by AsmJSMachExceptionHandler which is owned
 // by JSRuntime.
 #ifdef XP_MACOSX
 class AsmJSMachExceptionHandler
 {
     bool installed_;
-    pthread_t thread_;
+    PRThread *thread_;
     mach_port_t port_;
 
     void uninstall();
 
   public:
     AsmJSMachExceptionHandler();
     ~AsmJSMachExceptionHandler() { uninstall(); }
     mach_port_t port() const { return port_; }