Bug 1509929: Part 1 - Move IsSameBinaryAsParentProcess to its own header; r=mhowell
☠☠ backed out by d1efd32b03bf ☠ ☠
authorAaron Klotz <aklotz@mozilla.com>
Mon, 07 Jan 2019 22:36:08 +0000
changeset 509888 8bdba9ec4d5b314313bb5f1b7b539011d7cea7d4
parent 509887 f85f56be92a51494de3c62c0c7a643fd72e47e33
child 509889 5ec50f23671ee8e8fcba3667e3b8b308a782c49f
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)
reviewersmhowell
bugs1509929
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 1509929: Part 1 - Move IsSameBinaryAsParentProcess to its own header; r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D15446
browser/app/winlauncher/LauncherProcessWin.cpp
browser/app/winlauncher/SameBinary.h
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
@@ -25,16 +25,20 @@
 #include <processthreadsapi.h>
 
 #include "DllBlocklistWin.h"
 #include "ErrorHandler.h"
 #include "LauncherResult.h"
 #include "LaunchUnelevated.h"
 #include "ProcThreadAttributes.h"
 
+#if defined(MOZ_LAUNCHER_PROCESS)
+#include "SameBinary.h"
+#endif  // defined(MOZ_LAUNCHER_PROCESS)
+
 /**
  * At this point the child process has been created in a suspended state. Any
  * additional startup work (eg, blocklist setup) should go here.
  *
  * @return true if browser startup should proceed, otherwise false.
  */
 static mozilla::LauncherVoidResult PostCreationSetup(HANDLE aChildProcess,
                                                      HANDLE aChildMainThread,
@@ -135,64 +139,16 @@ static void MaybeBreakForBrowserDebuggin
   }
 
   DWORD pauseLenMs = wcstoul(pauseLenS, nullptr, 10) * 1000;
   printf_stderr("\n\nBROWSERBROWSERBROWSERBROWSER\n  debug me @ %lu\n\n",
                 ::GetCurrentProcessId());
   ::Sleep(pauseLenMs);
 }
 
-#if defined(MOZ_LAUNCHER_PROCESS)
-
-static mozilla::LauncherResult<bool> IsSameBinaryAsParentProcess() {
-  mozilla::LauncherResult<DWORD> parentPid = mozilla::nt::GetParentProcessId();
-  if (parentPid.isErr()) {
-    return LAUNCHER_ERROR_FROM_RESULT(parentPid);
-  }
-
-  nsAutoHandle parentProcess(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
-                                           FALSE, parentPid.unwrap()));
-  if (!parentProcess.get()) {
-    DWORD err = ::GetLastError();
-    if (err == ERROR_INVALID_PARAMETER) {
-      // The process identified by parentPid has already exited. This is a
-      // common case when the parent process is not Firefox, thus we should
-      // return false instead of erroring out.
-      return false;
-    }
-
-    return LAUNCHER_ERROR_FROM_WIN32(err);
-  }
-
-  WCHAR parentExe[MAX_PATH + 1] = {};
-  DWORD parentExeLen = mozilla::ArrayLength(parentExe);
-  if (!::QueryFullProcessImageNameW(parentProcess.get(), PROCESS_NAME_NATIVE,
-                                    parentExe, &parentExeLen)) {
-    return LAUNCHER_ERROR_FROM_LAST();
-  }
-
-  WCHAR ourExe[MAX_PATH + 1] = {};
-  DWORD ourExeOk =
-      ::GetModuleFileNameW(nullptr, ourExe, mozilla::ArrayLength(ourExe));
-  if (!ourExeOk || ourExeOk == mozilla::ArrayLength(ourExe)) {
-    return LAUNCHER_ERROR_FROM_LAST();
-  }
-
-  mozilla::WindowsErrorResult<bool> isSame =
-      mozilla::DoPathsPointToIdenticalFile(parentExe, ourExe,
-                                           mozilla::PathType::eNtPath);
-  if (isSame.isErr()) {
-    return LAUNCHER_ERROR_FROM_MOZ_WINDOWS_ERROR(isSame.unwrapErr());
-  }
-
-  return isSame.unwrap();
-}
-
-#endif  // defined(MOZ_LAUNCHER_PROCESS)
-
 namespace mozilla {
 
 bool RunAsLauncherProcess(int& argc, wchar_t** argv) {
   // NB: We run all tests in this function instead of returning early in order
   // to ensure that all side effects take place, such as clearing environment
   // variables.
   bool result = false;
 
new file mode 100644
--- /dev/null
+++ b/browser/app/winlauncher/SameBinary.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_SameBinary_h
+#define mozilla_SameBinary_h
+
+#include "LauncherResult.h"
+#include "NativeNt.h"
+#include "nsWindowsHelpers.h"
+
+namespace mozilla {
+
+static inline mozilla::LauncherResult<bool>
+IsSameBinaryAsParentProcess()
+{
+  mozilla::LauncherResult<DWORD> parentPid = mozilla::nt::GetParentProcessId();
+  if (parentPid.isErr()) {
+    return LAUNCHER_ERROR_FROM_RESULT(parentPid);
+  }
+
+  nsAutoHandle parentProcess(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
+                                           FALSE, parentPid.unwrap()));
+  if (!parentProcess.get()) {
+    DWORD err = ::GetLastError();
+    if (err == ERROR_INVALID_PARAMETER) {
+      // The process identified by parentPid has already exited. This is a
+      // common case when the parent process is not Firefox, thus we should
+      // return false instead of erroring out.
+      return false;
+    }
+
+    return LAUNCHER_ERROR_FROM_WIN32(err);
+  }
+
+  // Using a larger buffer for this call because we're asking for the native NT
+  // path, which may exceed MAX_PATH.
+  WCHAR parentExe[(MAX_PATH * 2) + 1] = {};
+  DWORD parentExeLen = mozilla::ArrayLength(parentExe);
+  if (!::QueryFullProcessImageNameW(parentProcess.get(), PROCESS_NAME_NATIVE,
+                                    parentExe, &parentExeLen)) {
+    return LAUNCHER_ERROR_FROM_LAST();
+  }
+
+  WCHAR ourExe[MAX_PATH + 1] = {};
+  DWORD ourExeOk = ::GetModuleFileNameW(nullptr, ourExe,
+                                        mozilla::ArrayLength(ourExe));
+  if (!ourExeOk || ourExeOk == mozilla::ArrayLength(ourExe)) {
+    return LAUNCHER_ERROR_FROM_LAST();
+  }
+
+  mozilla::WindowsErrorResult<bool> isSame =
+    mozilla::DoPathsPointToIdenticalFile(parentExe, ourExe,
+                                         mozilla::PathType::eNtPath);
+  if (isSame.isErr()) {
+    return LAUNCHER_ERROR_FROM_MOZ_WINDOWS_ERROR(isSame.unwrapErr());
+  }
+
+  return isSame.unwrap();
+}
+
+} // namespace mozilla
+
+#endif //  mozilla_SameBinary_h