Backed out 2 changesets (bug 1407693) for windows mingw32 bustages at /builds/worker/workspace/build/src/ipc/glue/GeckoChildProcessHost.cpp:1032 on a CLOSED TREE
authorAndreea Pavel <apavel@mozilla.com>
Wed, 07 Feb 2018 21:42:47 +0200
changeset 402813 20ec5beec3715aff1ff658ea95a9806e03a2046e
parent 402812 10e735083a7cf2c337827f9dbebcc3b66bbde643
child 402814 5436a03fe01ba1552a82daac7e5b59f2f8abd35e
push id33404
push usershindli@mozilla.com
push dateThu, 08 Feb 2018 10:03:18 +0000
treeherdermozilla-central@06b5d7476ebd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1407693
milestone60.0a1
backs out9c3346021c21eec994fc6b5dc6b68c00d05ea7f4
f18e1e557cf67ba54300e198124f697389ef973f
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
Backed out 2 changesets (bug 1407693) for windows mingw32 bustages at /builds/worker/workspace/build/src/ipc/glue/GeckoChildProcessHost.cpp:1032 on a CLOSED TREE Backed out changeset 9c3346021c21 (bug 1407693) Backed out changeset f18e1e557cf6 (bug 1407693)
ipc/chromium/src/base/process_util.h
ipc/chromium/src/base/process_util_win.cc
ipc/glue/GeckoChildProcessHost.cpp
security/sandbox/win/src/sandboxbroker/sandboxBroker.cpp
security/sandbox/win/src/sandboxbroker/sandboxBroker.h
toolkit/crashreporter/nsDummyExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
toolkit/xre/nsEmbedFunctions.cpp
xpcom/build/nsXULAppAPI.h
--- a/ipc/chromium/src/base/process_util.h
+++ b/ipc/chromium/src/base/process_util.h
@@ -107,18 +107,16 @@ struct LaunchOptions {
   bool wait = false;
 
 #if defined(OS_WIN)
   bool start_hidden = false;
 
   // Environment variables to be applied in addition to the current
   // process's environment, replacing them where necessary.
   EnvironmentMap env_map;
-
-  std::vector<HANDLE> handles_to_inherit;
 #endif
 #if defined(OS_POSIX)
   environment_map env_map;
 
   // A mapping of (src fd -> dest fd) to propagate into the child
   // process.  All other fds will be closed, except std{in,out,err}.
   file_handle_mapping_vector fds_to_remap;
 #endif
--- a/ipc/chromium/src/base/process_util_win.cc
+++ b/ipc/chromium/src/base/process_util_win.cc
@@ -347,33 +347,31 @@ bool LaunchApp(const std::wstring& cmdli
   STARTUPINFO &startup_info = startup_info_ex.StartupInfo;
   startup_info.cb = sizeof(startup_info);
   startup_info.dwFlags = STARTF_USESHOWWINDOW;
   startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
 
   // Per the comment in CreateThreadAttributeList, lpAttributeList will contain
   // a pointer to handlesToInherit, so make sure they have the same lifetime.
   LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList = NULL;
-  std::vector<HANDLE> handlesToInherit;
-  for (HANDLE h : options.handles_to_inherit) {
-    handlesToInherit.push_back(h);
-  }
+  HANDLE handlesToInherit[2];
+  int handleCount = 0;
 
   // setup our handle array first - if we end up with no handles that can
   // be inherited we can avoid trying to do the ThreadAttributeList dance...
   HANDLE stdOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
   HANDLE stdErr = ::GetStdHandle(STD_ERROR_HANDLE);
 
   if (IsInheritableHandle(stdOut))
-    handlesToInherit.push_back(stdOut);
+    handlesToInherit[handleCount++] = stdOut;
   if (stdErr != stdOut && IsInheritableHandle(stdErr))
-    handlesToInherit.push_back(stdErr);
+    handlesToInherit[handleCount++] = stdErr;
 
-  if (!handlesToInherit.empty()) {
-    lpAttributeList = CreateThreadAttributeList(handlesToInherit.data(), handlesToInherit.size());
+  if (handleCount) {
+    lpAttributeList = CreateThreadAttributeList(handlesToInherit, handleCount);
     if (lpAttributeList) {
       // it's safe to inherit handles, so arrange for that...
       startup_info.cb = sizeof(startup_info_ex);
       startup_info.dwFlags |= STARTF_USESTDHANDLES;
       startup_info.hStdOutput = stdOut;
       startup_info.hStdError = stdErr;
       startup_info.hStdInput = INVALID_HANDLE_VALUE;
       startup_info_ex.lpAttributeList = lpAttributeList;
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -58,17 +58,16 @@
 #include "mozilla/SandboxLaunch.h"
 #endif
 
 #include "nsTArray.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsNativeCharsetUtils.h"
 #include "nscore.h" // for NS_FREE_PERMANENT_DATA
-#include "private/pprio.h"
 
 using mozilla::MonitorAutoLock;
 using mozilla::ipc::GeckoChildProcessHost;
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
 #include "GeneratedJNIWrappers.h"
 #include "mozilla/jni/Refs.h"
@@ -118,26 +117,16 @@ GeckoChildProcessHost::~GeckoChildProces
 #endif
     );
   }
 
 #if defined(MOZ_WIDGET_COCOA)
   if (mChildTask != MACH_PORT_NULL)
     mach_port_deallocate(mach_task_self(), mChildTask);
 #endif
-
-  if (mChildProcessHandle != 0) {
-#if defined(XP_WIN)
-    CrashReporter::DeregisterChildCrashAnnotationFileDescriptor(
-      base::GetProcId(mChildProcessHandle));
-#else
-    CrashReporter::DeregisterChildCrashAnnotationFileDescriptor(
-      mChildProcessHandle);
-#endif
-  }
 }
 
 //static
 auto
 GeckoChildProcessHost::GetPathToBinary(FilePath& exePath, GeckoProcessType processType) -> BinaryPathType
 {
   if (sRunSelfAsContentProc &&
       (processType == GeckoProcessType_Content || processType == GeckoProcessType_GPU)) {
@@ -627,22 +616,16 @@ GeckoChildProcessHost::PerformAsyncLaunc
   // send the child the PID so that it can open a ProcessHandle back to us.
   // probably don't want to do this in the long run
   char pidstring[32];
   SprintfLiteral(pidstring, "%d", base::GetCurrentProcId());
 
   const char* const childProcessType =
       XRE_ChildProcessTypeToString(mProcessType);
 
-  PRFileDesc* crashAnnotationReadPipe;
-  PRFileDesc* crashAnnotationWritePipe;
-  if (PR_CreatePipe(&crashAnnotationReadPipe, &crashAnnotationWritePipe) != PR_SUCCESS) {
-    return false;
-  }
-
 //--------------------------------------------------
 #if defined(OS_POSIX)
   // For POSIX, we have to be extremely anal about *not* using
   // std::wstring in code compiled with Mozilla's -fshort-wchar
   // configuration, because chromium is compiled with -fno-short-wchar
   // and passing wstrings from one config to the other is unsafe.  So
   // we split the logic here.
 
@@ -781,20 +764,16 @@ GeckoChildProcessHost::PerformAsyncLaunc
       // "false" == crash reporting disabled
       childArgv.push_back("false");
     }
 #elif defined(MOZ_WIDGET_COCOA) // defined(OS_LINUX) || defined(OS_BSD) || defined(OS_SOLARIS)
     childArgv.push_back(CrashReporter::GetChildNotificationPipe());
 #endif  // defined(OS_LINUX) || defined(OS_BSD) || defined(OS_SOLARIS)
   }
 
-  int fd = PR_FileDesc2NativeHandle(crashAnnotationWritePipe);
-  mLaunchOptions->fds_to_remap.push_back(
-    std::make_pair(fd, CrashReporter::GetAnnotationTimeCrashFd()));
-
 # ifdef MOZ_WIDGET_COCOA
   // Add a mach port to the command line so the child can communicate its
   // 'task_t' back to the parent.
   //
   // Put a random number into the channel name, so that a compromised renderer
   // can't pretend being the child that's forked off.
   std::string mach_connection_name = StringPrintf("org.mozilla.machname.%d",
                                                   base::RandInt(0, std::numeric_limits<int>::max()));
@@ -1023,22 +1002,16 @@ GeckoChildProcessHost::PerformAsyncLaunc
   }
 
   // Process id
   cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
 
   cmdLine.AppendLooseValue(
     UTF8ToWide(CrashReporter::GetChildNotificationPipe()));
 
-  PROsfd h = PR_FileDesc2NativeHandle(crashAnnotationWritePipe);
-  mSandboxBroker.AddHandleToShare(reinterpret_cast<HANDLE>(h));
-  mLaunchOptions->handles_to_inherit.push_back(reinterpret_cast<HANDLE>(h));
-  std::string hStr = std::to_string(h);
-  cmdLine.AppendLooseValue(UTF8ToWide(hStr));
-
   // Process type
   cmdLine.AppendLooseValue(UTF8ToWide(childProcessType));
 
 # if defined(MOZ_SANDBOX)
   if (shouldSandboxCurrentProcess) {
     if (mSandboxBroker.LaunchApp(cmdLine.program().c_str(),
                                  cmdLine.command_line_string().c_str(),
                                  mLaunchOptions->env_map,
@@ -1091,25 +1064,16 @@ GeckoChildProcessHost::PerformAsyncLaunc
                             PROCESS_DUP_HANDLE | PROCESS_TERMINATE |
                             PROCESS_QUERY_INFORMATION | PROCESS_VM_READ |
                             SYNCHRONIZE,
                             FALSE, 0)
 #endif // XP_WIN
      ) {
     MOZ_CRASH("cannot open handle to child process");
   }
-#if defined(XP_WIN)
-  CrashReporter::RegisterChildCrashAnnotationFileDescriptor(
-    base::GetProcId(process), crashAnnotationReadPipe);
-#else
-  CrashReporter::RegisterChildCrashAnnotationFileDescriptor(process,
-                                                            crashAnnotationReadPipe);
-#endif
-  PR_Close(crashAnnotationWritePipe);
-
   MonitorAutoLock lock(mMonitor);
   mProcessState = PROCESS_CREATED;
   lock.Notify();
 
   mLaunchOptions = nullptr;
   return true;
 }
 
--- a/security/sandbox/win/src/sandboxbroker/sandboxBroker.cpp
+++ b/security/sandbox/win/src/sandboxbroker/sandboxBroker.cpp
@@ -1131,22 +1131,16 @@ SandboxBroker::AddTargetPeer(HANDLE aPee
     return false;
   }
 
   sandbox::ResultCode result = sBrokerService->AddTargetPeer(aPeerProcess);
   return (sandbox::SBOX_ALL_OK == result);
 }
 
 void
-SandboxBroker::AddHandleToShare(HANDLE aHandle)
-{
-  mPolicy->AddHandleToShare(aHandle);
-}
-
-void
 SandboxBroker::ApplyLoggingPolicy()
 {
   MOZ_ASSERT(mPolicy);
 
   // Add dummy rules, so that we can log in the interception code.
   // We already have a file interception set up for the client side of pipes.
   // Also, passing just "dummy" for file system policy causes win_utils.cc
   // IsReparsePoint() to loop.
--- a/security/sandbox/win/src/sandboxbroker/sandboxBroker.h
+++ b/security/sandbox/win/src/sandboxbroker/sandboxBroker.h
@@ -58,30 +58,20 @@ public:
     LockDown,
     Restricted
   };
   bool SetSecurityLevelForGMPlugin(SandboxLevel aLevel);
 
   // File system permissions
   bool AllowReadFile(wchar_t const *file);
 
-  /**
-   * Exposes AddTargetPeer from broker services, so that non-sandboxed
-   * processes can be added as handle duplication targets.
-   */
+  // Exposes AddTargetPeer from broker services, so that none sandboxed
+  // processes can be added as handle duplication targets.
   bool AddTargetPeer(HANDLE aPeerProcess);
 
-  /**
-   * Share a HANDLE with the child process. The HANDLE will be made available
-   * in the child process at the memory address
-   * |reinterpret_cast<uintptr_t>(aHandle)|. It is the caller's responsibility
-   * to communicate this address to the child.
-   */
-  void AddHandleToShare(HANDLE aHandle);
-
   // Set up dummy interceptions via the broker, so we can log calls.
   void ApplyLoggingPolicy();
 
 private:
   static sandbox::BrokerServices *sBrokerService;
   static bool sRunningFromNetworkDrive;
   sandbox::TargetPolicy *mPolicy;
 };
--- a/toolkit/crashreporter/nsDummyExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsDummyExceptionHandler.cpp
@@ -136,34 +136,16 @@ SetServerURL(const nsACString& aServerUR
 }
 
 nsresult
 SetRestartArgs(int argc, char** argv)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-#if !defined(XP_WIN)
-int
-GetAnnotationTimeCrashFd()
-{
-  return 7;
-}
-#endif
-
-void
-RegisterChildCrashAnnotationFileDescriptor(ProcessId aProcess, PRFileDesc* aFd)
-{
-}
-
-void
-DeregisterChildCrashAnnotationFileDescriptor(ProcessId aProcess)
-{
-}
-
 #ifdef XP_WIN32
 nsresult
 WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 #endif
 
@@ -311,20 +293,26 @@ UnregisterInjectorCallback(DWORD process
 #endif // MOZ_CRASHREPORTER_INJECTOR
 
 bool
 GetLastRunCrashID(nsAString& id)
 {
   return false;
 }
 
+#if defined(XP_WIN) || defined(XP_MACOSX)
+void
+InitChildProcessTmpDir(nsIFile* aDirOverride)
+{
+}
+#endif // defined(XP_WIN) || defined(XP_MACOSX)
+
 #if defined(XP_WIN)
 bool
-SetRemoteExceptionHandler(const nsACString& crashPipe,
-                          uintptr_t aCrashTimeAnnotationFile)
+SetRemoteExceptionHandler(const nsACString& crashPipe)
 {
   return false;
 }
 
 #elif defined(XP_MACOSX)
 
 bool
 SetRemoteExceptionHandler(const nsACString& crashPipe)
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -20,17 +20,16 @@
 #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"
-#include "private/pprio.h"
 
 #if defined(XP_WIN32)
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
 #endif
 
 #include "nsXULAppAPI.h"
 #include "nsIXULAppInfo.h"
@@ -238,17 +237,16 @@ static bool minidumpAnalysisAllThreads =
 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 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
 
@@ -576,18 +574,16 @@ public:
   }
 
   void Open(const wchar_t* path) {
     mHandle = CreateFile(path, GENERIC_WRITE, 0,
                          nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
                          nullptr);
   }
 
-  void OpenHandle(HANDLE aHandle) { mHandle = aHandle; }
-
   bool Valid() {
     return mHandle != INVALID_HANDLE_VALUE;
   }
 
   void WriteBuffer(const char* buffer, size_t len)
   {
     if (!Valid()) {
       return;
@@ -624,18 +620,16 @@ public:
       sys_close(mFD);
     }
   }
 
   void Open(const char* path) {
     mFD = sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
   }
 
-  void OpenHandle(int aFd) { mFD = aFd; }
-
   bool Valid() {
     return mFD != -1;
   }
 
   void WriteBuffer(const char* buffer, size_t len) {
     if (!Valid()) {
       return;
     }
@@ -1262,28 +1256,55 @@ BuildTempPath(PathStringT& aResult)
   if (!actualLen) {
     return false;
   }
   aResult.SetLength(actualLen);
   return true;
 }
 
 static void
-PrepareChildExceptionTimeAnnotations(void* context)
+PrepareChildExceptionTimeAnnotations()
 {
   MOZ_ASSERT(!XRE_IsParentProcess());
-
-  FileHandle f;
-#ifdef XP_WIN
-  f = static_cast<HANDLE>(context);
+  static XP_CHAR tempPath[XP_PATH_MAX] = {0};
+
+  // Get the temp path
+  size_t charsAvailable = XP_PATH_MAX;
+  XP_CHAR* p = tempPath;
+#if (defined(XP_MACOSX) || defined(XP_WIN))
+  if (!childProcessTmpDir || childProcessTmpDir->empty()) {
+    return;
+  }
+  p = Concat(p, childProcessTmpDir->c_str(), &charsAvailable);
+  // Ensure that this path ends with a path separator
+  if (p > tempPath && *(p - 1) != XP_PATH_SEPARATOR_CHAR) {
+    p = Concat(p, XP_PATH_SEPARATOR, &charsAvailable);
+  }
 #else
-  f = GetAnnotationTimeCrashFd();
+  size_t tempPathLen = BuildTempPath(tempPath);
+  if (!tempPathLen) {
+    return;
+  }
+  p += tempPathLen;
+  charsAvailable -= tempPathLen;
 #endif
+
+  // Generate and append the file name
+  p = Concat(p, childCrashAnnotationBaseName, &charsAvailable);
+  XP_CHAR pidBuffer[32] = XP_TEXT("");
+#if defined(XP_WIN32)
+  _ui64tow(GetCurrentProcessId(), pidBuffer, 10);
+#else
+  XP_STOA(getpid(), pidBuffer, 10);
+#endif
+  p = Concat(p, pidBuffer, &charsAvailable);
+
+  // Now open the file...
   PlatformWriter apiData;
-  apiData.OpenHandle(f);
+  OpenAPIData(apiData, tempPath);
 
   // ...and write out any annotations. These must be escaped if necessary
   // (but don't call EscapeAnnotation here, because it touches the heap).
 #ifdef XP_WIN
   WriteGlobalMemoryStatus(&apiData, nullptr);
 #endif
 
   char oomAllocationSizeBuffer[32] = "";
@@ -1369,17 +1390,17 @@ static bool FPEFilter(void* context, EXC
 }
 
 static bool
 ChildFPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
                MDRawAssertionInfo* assertion)
 {
   bool result = FPEFilter(context, exinfo, assertion);
   if (result) {
-    PrepareChildExceptionTimeAnnotations(context);
+    PrepareChildExceptionTimeAnnotations();
   }
   return result;
 }
 
 static MINIDUMP_TYPE
 GetMinidumpType()
 {
   MINIDUMP_TYPE minidump_type = MiniDumpWithFullMemoryInfo;
@@ -1435,17 +1456,17 @@ Filter(void* context)
   return true;
 }
 
 static bool
 ChildFilter(void* context)
 {
   bool result = Filter(context);
   if (result) {
-    PrepareChildExceptionTimeAnnotations(context);
+    PrepareChildExceptionTimeAnnotations();
   }
   return result;
 }
 
 static void
 TerminateHandler()
 {
   MOZ_CRASH("Unhandled exception");
@@ -3031,16 +3052,60 @@ WriteExtraData(nsIFile* extraFile,
 
 bool
 AppendExtraData(nsIFile* extraFile, const AnnotationTable& data)
 {
   return WriteExtraData(extraFile, data, Blacklist());
 }
 
 static bool
+GetExtraFileForChildPid(uint32_t aPid, nsIFile** aExtraFile)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  nsCOMPtr<nsIFile> extraFile;
+  nsresult rv;
+
+#if defined(XP_WIN) || defined(XP_MACOSX)
+  if (!childProcessTmpDir) {
+    return false;
+  }
+  CreateFileFromPath(*childProcessTmpDir, getter_AddRefs(extraFile));
+  if (!extraFile) {
+    return false;
+  }
+#elif defined(XP_UNIX)
+  rv = NS_NewLocalFile(NS_LITERAL_STRING("/tmp"), false,
+                       getter_AddRefs(extraFile));
+  if (NS_FAILED(rv)) {
+    return false;
+  }
+#else
+#error "Implement this for your platform"
+#endif
+
+  nsAutoString leafName;
+#if defined(XP_WIN)
+  leafName.AppendPrintf("%S%u%S", childCrashAnnotationBaseName, aPid,
+                        extraFileExtension);
+#else
+  leafName.AppendPrintf("%s%u%s", childCrashAnnotationBaseName, aPid,
+                        extraFileExtension);
+#endif
+
+  rv = extraFile->Append(leafName);
+  if (NS_FAILED(rv)) {
+    return false;
+  }
+
+  extraFile.forget(aExtraFile);
+  return true;
+}
+
+static bool
 IsDataEscaped(char* aData)
 {
   if (strchr(aData, '\n')) {
     // There should not be any newlines
     return false;
   }
   char* pos = aData;
   while ((pos = strchr(pos, '\\'))) {
@@ -3104,37 +3169,29 @@ WriteExtraForMinidump(nsIFile* minidump,
 
   if (!WriteExtraData(extra, *crashReporterAPIData_Hash,
                       blacklist,
                       true /*write crash time*/,
                       true /*truncate*/)) {
     return false;
   }
 
-  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) {
+  nsCOMPtr<nsIFile> exceptionTimeExtra;
+  FILE* fd;
+  if (pid && GetExtraFileForChildPid(pid, getter_AddRefs(exceptionTimeExtra)) &&
+      NS_SUCCEEDED(exceptionTimeExtra->OpenANSIFileDesc("r", &fd))) {
+    AnnotationTable exceptionTimeAnnotations;
+    ReadAndValidateExceptionTimeAnnotations(fd, exceptionTimeAnnotations);
+    fclose(fd);
+    if (!AppendExtraData(extra, exceptionTimeAnnotations)) {
       return false;
     }
-    fd = fdopen(nativeFd, "r");
-#else
-    fd = fdopen(PR_FileDesc2NativeHandle(prFd), "r");
-#endif
-    if (fd) {
-      AnnotationTable exceptionTimeAnnotations;
-      ReadAndValidateExceptionTimeAnnotations(fd, exceptionTimeAnnotations);
-      PR_Close(prFd);
-      if (!AppendExtraData(extra, exceptionTimeAnnotations)) {
-        return false;
-      }
-    }
+  }
+  if (exceptionTimeExtra) {
+    exceptionTimeExtra->Remove(false);
   }
 
   extra.forget(extraFile);
 
   return true;
 }
 
 // It really only makes sense to call this function when
@@ -3476,61 +3533,56 @@ UnregisterInjectorCallback(DWORD process
     return;
 
   MutexAutoLock lock(*dumpMapLock);
   pidToMinidump->RemoveEntry(processID);
 }
 
 #endif // MOZ_CRASHREPORTER_INJECTOR
 
-#if !defined(XP_WIN)
-int
-GetAnnotationTimeCrashFd()
-{
-  return 7;
-}
-#endif
-
+#if defined(XP_WIN) || defined(XP_MACOSX)
 void
-RegisterChildCrashAnnotationFileDescriptor(ProcessId aProcess, PRFileDesc* aFd)
+InitChildProcessTmpDir(nsIFile* aDirOverride)
 {
-  processToCrashFd[aProcess] = aFd;
-}
-
-void
-DeregisterChildCrashAnnotationFileDescriptor(ProcessId aProcess)
-{
-  auto it = processToCrashFd.find(aProcess);
-  if (it != processToCrashFd.end()) {
-    PR_Close(it->second);
-    processToCrashFd.erase(it);
+  MOZ_ASSERT(!XRE_IsParentProcess());
+  if (aDirOverride) {
+    childProcessTmpDir = CreatePathFromFile(aDirOverride);
+    return;
+  }
+
+  // When retrieved by the child process, this will always resolve to the
+  // correct directory regardless of sandbox level.
+  nsCOMPtr<nsIFile> tmpDir;
+  nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpDir));
+  if (NS_SUCCEEDED(rv)) {
+    childProcessTmpDir = CreatePathFromFile(tmpDir);
   }
 }
+#endif // defined(XP_WIN) || defined(XP_MACOSX)
 
 #if defined(XP_WIN)
 // Child-side API
 bool
-SetRemoteExceptionHandler(const nsACString& crashPipe,
-                          uintptr_t aCrashTimeAnnotationFile)
+SetRemoteExceptionHandler(const nsACString& crashPipe)
 {
   // crash reporting is disabled
   if (crashPipe.Equals(kNullNotifyPipe))
     return true;
 
   MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
 
-  gExceptionHandler = new google_breakpad::ExceptionHandler(
-    L"",
-    ChildFPEFilter,
-    nullptr, // no minidump callback
-    reinterpret_cast<void*>(aCrashTimeAnnotationFile),
-    google_breakpad::ExceptionHandler::HANDLER_ALL,
-    GetMinidumpType(),
-    NS_ConvertASCIItoUTF16(crashPipe).get(),
-    nullptr);
+  gExceptionHandler = new google_breakpad::
+    ExceptionHandler(L"",
+                     ChildFPEFilter,
+                     nullptr,    // no minidump callback
+                     nullptr,    // no callback context
+                     google_breakpad::ExceptionHandler::HANDLER_ALL,
+                     GetMinidumpType(),
+                     NS_ConvertASCIItoUTF16(crashPipe).get(),
+                     nullptr);
   gExceptionHandler->set_handle_debug_exceptions(true);
   RunAndCleanUpDelayedNotes();
 
 #ifdef _WIN64
   SetJitExceptionHandler();
 #endif
 
   mozalloc_set_oom_abort_handler(AnnotateOOMAllocationSize);
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -14,17 +14,16 @@
 
 #include "mozilla/Assertions.h"
 
 #include <functional>
 #include <stddef.h>
 #include <stdint.h>
 #include "nsError.h"
 #include "nsString.h"
-#include "prio.h"
 
 #if defined(XP_WIN32)
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
 #endif
 #include <windows.h>
 #endif
 
@@ -172,40 +171,25 @@ bool TakeMinidump(nsIFile** aResult, boo
 // is non-nullptr. The sequence parameter will be filled with an ordinal
 // indicating which remote process crashed first.
 bool TakeMinidumpForChild(uint32_t childPid,
                           nsIFile** dump,
                           uint32_t* aSequence = nullptr);
 
 #if defined(XP_WIN)
 typedef HANDLE ProcessHandle;
-typedef DWORD ProcessId;
 typedef DWORD ThreadId;
-typedef HANDLE FileHandle;
 #elif defined(XP_MACOSX)
 typedef task_t ProcessHandle;
-typedef pid_t ProcessId;
 typedef mach_port_t ThreadId;
-typedef int FileHandle;
 #else
 typedef int ProcessHandle;
-typedef pid_t ProcessId;
 typedef int ThreadId;
-typedef int FileHandle;
 #endif
 
-#if !defined(XP_WIN)
-int
-GetAnnotationTimeCrashFd();
-#endif
-void
-RegisterChildCrashAnnotationFileDescriptor(ProcessId aProcess, PRFileDesc* aFd);
-void
-DeregisterChildCrashAnnotationFileDescriptor(ProcessId aProcess);
-
 // Return the current thread's ID.
 //
 // XXX: this is a somewhat out-of-place interface to expose through
 // crashreporter, but it takes significant work to call sys_gettid()
 // correctly on Linux and breakpad has already jumped through those
 // hoops for us.
 ThreadId CurrentThreadId();
 
@@ -275,23 +259,18 @@ public:
 };
 
 // This method implies OOPInit
 void InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb);
 void UnregisterInjectorCallback(DWORD processID);
 #endif
 
 // Child-side API
-#if defined(XP_WIN32)
-bool
-SetRemoteExceptionHandler(const nsACString& crashPipe,
-                          uintptr_t aCrashTimeAnnotationFile);
-#else
 bool SetRemoteExceptionHandler(const nsACString& crashPipe);
-#endif
+void InitChildProcessTmpDir(nsIFile* aDirOverride = nullptr);
 
 #  else
 // Parent-side API for children
 
 // Set the outparams for crash reporter server's fd (|childCrashFd|)
 // and the magic fd number it should be remapped to
 // (|childCrashRemapFd|) before exec() in the child process.
 // |SetRemoteExceptionHandler()| in the child process expects to find
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -277,27 +277,19 @@ XRE_SetProcessType(const char* aProcessT
 bool
 XRE_TakeMinidumpForChild(uint32_t aChildPid, nsIFile** aDump,
                          uint32_t* aSequence)
 {
   return CrashReporter::TakeMinidumpForChild(aChildPid, aDump, aSequence);
 }
 
 bool
-#if defined(XP_WIN)
-XRE_SetRemoteExceptionHandler(const char* aPipe /*= 0*/,
-                              uintptr_t aCrashTimeAnnotationFile)
-#else
-XRE_SetRemoteExceptionHandler(const char* aPipe /*= 0*/)
-#endif
+XRE_SetRemoteExceptionHandler(const char* aPipe/*= 0*/)
 {
-#if defined(XP_WIN)
-  return CrashReporter::SetRemoteExceptionHandler(nsDependentCString(aPipe),
-                                                  aCrashTimeAnnotationFile);
-#elif defined(XP_MACOSX)
+#if defined(XP_WIN) || defined(XP_MACOSX)
   return CrashReporter::SetRemoteExceptionHandler(nsDependentCString(aPipe));
 #else
   return CrashReporter::SetRemoteExceptionHandler();
 #endif
 }
 
 #if defined(XP_WIN)
 void
@@ -482,45 +474,31 @@ XRE_InitChildProcess(int aArgc,
     return NS_ERROR_FAILURE;
   }
 
 #endif
 
   SetupErrorHandling(aArgv[0]);
 
   if (!CrashReporter::IsDummy()) {
-#if defined(XP_WIN)
     if (aArgc < 1) {
       return NS_ERROR_FAILURE;
     }
-    const char* const crashTimeAnnotationArg = aArgv[--aArgc];
-    uintptr_t crashTimeAnnotationFile =
-      static_cast<uintptr_t>(std::stoul(std::string(crashTimeAnnotationArg)));
-#endif
 
-    if (aArgc < 1)
-      return NS_ERROR_FAILURE;
     const char* const crashReporterArg = aArgv[--aArgc];
 
-#if defined(XP_MACOSX)
+#if defined(XP_WIN) || defined(XP_MACOSX)
     // on windows and mac, |crashReporterArg| is the named pipe on which the
     // server is listening for requests, or "-" if crash reporting is
     // disabled.
     if (0 != strcmp("-", crashReporterArg) &&
         !XRE_SetRemoteExceptionHandler(crashReporterArg)) {
       // Bug 684322 will add better visibility into this condition
       NS_WARNING("Could not setup crash reporting\n");
     }
-#elif defined(XP_WIN)
-    if (0 != strcmp("-", crashReporterArg) &&
-        !XRE_SetRemoteExceptionHandler(crashReporterArg,
-                                       crashTimeAnnotationFile)) {
-      // Bug 684322 will add better visibility into this condition
-      NS_WARNING("Could not setup crash reporting\n");
-    }
 #else
     // on POSIX, |crashReporterArg| is "true" if crash reporting is
     // enabled, false otherwise
     if (0 != strcmp("false", crashReporterArg) &&
         !XRE_SetRemoteExceptionHandler(nullptr)) {
       // Bug 684322 will add better visibility into this condition
       NS_WARNING("Could not setup crash reporting\n");
     }
@@ -689,16 +667,20 @@ XRE_InitChildProcess(int aArgc,
       default:
         MOZ_CRASH("Unknown main thread class");
       }
 
       if (!process->Init(aArgc, aArgv)) {
         return NS_ERROR_FAILURE;
       }
 
+#if defined(XP_WIN) || defined(XP_MACOSX)
+      CrashReporter::InitChildProcessTmpDir(crashReportTmpDir);
+#endif
+
 #if defined(XP_WIN)
       // Set child processes up such that they will get killed after the
       // chrome process is killed in cases where the user shuts the system
       // down or logs off.
       ::SetProcessShutdownParameters(0x280 - 1, SHUTDOWN_NORETRY);
 #endif
 
 #if defined(MOZ_SANDBOX) && defined(XP_WIN)
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -405,26 +405,18 @@ XRE_API(void,
         XRE_SetProcessType, (const char* aProcessTypeString))
 
 // Used in the "master" parent process hosting the crash server
 XRE_API(bool,
         XRE_TakeMinidumpForChild, (uint32_t aChildPid, nsIFile** aDump,
                                    uint32_t* aSequence))
 
 // Used in child processes.
-#if defined(XP_WIN)
-// Uses uintptr_t, even though it's really a HANDLE, because including
-// <windows.h> here caused compilation issues.
-XRE_API(bool,
-        XRE_SetRemoteExceptionHandler,
-        (const char* aPipe, uintptr_t aCrashTimeAnnotationFile))
-#else
 XRE_API(bool,
         XRE_SetRemoteExceptionHandler, (const char* aPipe))
-#endif
 
 namespace mozilla {
 namespace gmp {
 class GMPLoader;
 } // namespace gmp
 } // namespace mozilla
 
 XRE_API(nsresult,