Bug 840277 - Explicitly check that the preallocated process hasn't been killed before we use it. r=cjones, a=blocking-tef
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 15 Feb 2013 12:07:32 -0500
changeset 118532 ef2edab2f16875120fd3c8533d6e11b09e0fb423
parent 118531 15587a04ec3db0869f1a193d15569914b3b754fb
child 118533 3de3a83f5bf2ad25a79a1327e8a0199179ab56c4
push id465
push userjlebar@mozilla.com
push dateFri, 15 Feb 2013 17:08:37 +0000
reviewerscjones, blocking-tef
bugs840277
milestone18.0
Bug 840277 - Explicitly check that the preallocated process hasn't been killed before we use it. r=cjones, a=blocking-tef We have to do this check /after/ we set the process's priority, since before then, it has BACKGROUND priority and is a candidate for killing.
dom/ipc/ContentParent.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -542,17 +542,32 @@ ContentParent::TransformPreallocatedInto
     // TemporarilySetProcessPriorityToForeground() from within
     // ContentChild::AllocPBrowser, but this happens earlier, thus reducing the
     // window in which the child might be killed due to low memory.
     if (Preferences::GetBool("dom.ipc.processPriorityManager.enabled")) {
         SetProcessPriority(base::GetProcId(mSubprocess->GetChildProcessHandle()),
                            PROCESS_PRIORITY_FOREGROUND);
     }
 
-    // If this fails, the child process died.
+    // Now that we've increased the process's priority from BACKGROUND (where
+    // the preallocated app sits) to something higher, check whether the process
+    // is still alive.  Hopefully the process won't unexpectedly crash after
+    // this point!
+    //
+    // It's not legal to call DidProcessCrash on Windows if the process has not
+    // terminated yet, so we have to skip this check there.
+
+#ifndef XP_WIN
+    bool exited = false;
+    base::DidProcessCrash(&exited, mSubprocess->GetChildProcessHandle());
+    if (exited) {
+        return false;
+    }
+#endif
+
     return SendSetProcessPrivileges(aPrivs);
 }
 
 void
 ContentParent::ShutDownProcess()
 {
   if (!mIsDestroyed) {
     const InfallibleTArray<PIndexedDBParent*>& idbParents =