Bug 1487287 - Fix thread-safety of crash reporter pid map. r=gsvelto
authorJed Davis <jld@mozilla.com>
Tue, 08 Jan 2019 23:53:37 +0000
changeset 510268 5a5e1801bb364fe3771cc8c14100ca5ca6331610
parent 510267 e818109ab4e11a0bf72c6213eef37ae9884d15ce
child 510269 a0cf88b1fe5b2b34d29b621e454d43fff788dbc7
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1487287
milestone66.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 1487287 - Fix thread-safety of crash reporter pid map. r=gsvelto Depends on D8945 Differential Revision: https://phabricator.services.mozilla.com/D15886
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -14,16 +14,17 @@
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EnumeratedRange.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
 #include "mozilla/Unused.h"
 #include "mozilla/Printf.h"
 #include "mozilla/Sprintf.h"
+#include "mozilla/StaticMutex.h"
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/ipc/CrashReporterClient.h"
 
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "jsfriendapi.h"
 #include "ThreadAnnotation.h"
@@ -238,16 +239,17 @@ static uint32_t eventloopNestingLevel = 
 static Mutex* dumpSafetyLock;
 static bool isSafeToDump = false;
 
 // Whether to include heap regions of the crash context.
 static bool sIncludeContextHeap = false;
 
 // OOP crash reporting
 static CrashGenerationServer* crashServer;  // chrome process has this
+static StaticMutex processMapLock;
 static std::map<ProcessId, PRFileDesc*> processToCrashFd;
 
 static std::terminate_handler oldTerminateHandler = nullptr;
 
 #if (defined(XP_MACOSX) || defined(XP_WIN))
 // This field is valid in both chrome and content processes.
 static xpstring* childProcessTmpDir = nullptr;
 #endif
@@ -2884,16 +2886,17 @@ static bool WriteExtraForMinidump(nsIFil
     MutexAutoLock lock(*crashReporterAPILock);
     if (!WriteExtraData(extra, crashReporterAPIData_Table,
                         true /*write crash time*/, true /*truncate*/,
                         content)) {
       return false;
     }
   }
 
+  StaticMutexAutoLock pidMapLock(processMapLock);
   if (pid && processToCrashFd.count(pid)) {
     PRFileDesc* prFd = processToCrashFd[pid];
     processToCrashFd.erase(pid);
     FILE* fd;
 #if defined(XP_WIN)
     int nativeFd = _open_osfhandle(PR_FileDesc2NativeHandle(prFd), 0);
     if (nativeFd == -1) {
       return false;
@@ -3251,20 +3254,22 @@ int GetAnnotationTimeCrashFd() {
 #else
   return 7;
 #endif  // defined(MOZ_WIDGET_ANDROID)
 }
 #endif
 
 void RegisterChildCrashAnnotationFileDescriptor(ProcessId aProcess,
                                                 PRFileDesc* aFd) {
+  StaticMutexAutoLock pidMapLock(processMapLock);
   processToCrashFd[aProcess] = aFd;
 }
 
 void DeregisterChildCrashAnnotationFileDescriptor(ProcessId aProcess) {
+  StaticMutexAutoLock pidMapLock(processMapLock);
   auto it = processToCrashFd.find(aProcess);
   if (it != processToCrashFd.end()) {
     PR_Close(it->second);
     processToCrashFd.erase(it);
   }
 }
 
 #if defined(XP_WIN)