Bug 1332523 - Make GetBootstrap take the path to an arbitrary file next to libxul. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 13 Jan 2017 09:27:39 +0900
changeset 377757 e1baf4f6ef960a5638b83505c20342f27b121c12
parent 377756 bb2b50d94e76d2b37b9368aec186a91935253609
child 377758 8c3f028204919bc85aa873a224adbd5686c104ac
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1332523
milestone53.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 1332523 - Make GetBootstrap take the path to an arbitrary file next to libxul. r=bsmedberg The FileExists check can be removed because the code loading the library will handle that case already.
browser/app/nsBrowserApp.cpp
xpcom/glue/standalone/nsXPCOMGlue.cpp
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -229,52 +229,27 @@ static int do_main(int argc, char* argv[
 #ifdef LIBFUZZER
   if (getenv("LIBFUZZER"))
     gBootstrap->XRE_LibFuzzerSetDriver(fuzzer::FuzzerDriver);
 #endif
 
   return gBootstrap->XRE_main(argc, argv, config);
 }
 
-static bool
-FileExists(const char *path)
-{
-#ifdef XP_WIN
-  wchar_t wideDir[MAX_PATH];
-  MultiByteToWideChar(CP_UTF8, 0, path, -1, wideDir, MAX_PATH);
-  DWORD fileAttrs = GetFileAttributesW(wideDir);
-  return fileAttrs != INVALID_FILE_ATTRIBUTES;
-#else
-  return access(path, R_OK) == 0;
-#endif
-}
-
 static nsresult
 InitXPCOMGlue(const char *argv0)
 {
   char exePath[MAXPATHLEN];
 
   nsresult rv = mozilla::BinaryPath::Get(argv0, exePath);
   if (NS_FAILED(rv)) {
     Output("Couldn't find the application directory.\n");
     return rv;
   }
 
-  char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
-  if (!lastSlash ||
-      (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1))
-    return NS_ERROR_FAILURE;
-
-  strcpy(lastSlash + 1, XPCOM_DLL);
-
-  if (!FileExists(exePath)) {
-    Output("Could not find the Mozilla runtime.\n");
-    return NS_ERROR_FAILURE;
-  }
-
   gBootstrap = mozilla::GetBootstrap(exePath);
   if (!gBootstrap) {
     Output("Couldn't load XPCOM.\n");
     return NS_ERROR_FAILURE;
   }
 
   // This will set this thread as the main thread.
   gBootstrap->NS_LogInit();
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -8,16 +8,17 @@
 
 #include "nspr.h"
 #include "nsDebug.h"
 #include "nsIServiceManager.h"
 #include "nsXPCOMPrivate.h"
 #include "nsCOMPtr.h"
 #include <stdlib.h>
 #include <stdio.h>
+#include <string>
 
 #include "mozilla/FileUtils.h"
 #include "mozilla/Sprintf.h"
 
 using namespace mozilla;
 
 #define XPCOM_DEPENDENT_LIBS_LIST "dependentlibs.list"
 
@@ -386,20 +387,27 @@ namespace mozilla {
 Bootstrap::UniquePtr
 GetBootstrap(const char* aXPCOMFile)
 {
 #ifdef MOZ_GSLICE_INIT
   GSliceInit gSliceInit;
 #endif
 
   if (!aXPCOMFile) {
-    aXPCOMFile = XPCOM_DLL;
+    return nullptr;
   }
 
-  if (NS_FAILED(XPCOMGlueLoad(aXPCOMFile))) {
+  std::string file(aXPCOMFile);
+  size_t lastSlash = file.rfind(XPCOM_FILE_PATH_SEPARATOR[0]);
+  if (lastSlash == std::string::npos) {
+    return nullptr;
+  }
+  file.replace(lastSlash + 1, std::string::npos, XPCOM_DLL);
+
+  if (NS_FAILED(XPCOMGlueLoad(file.c_str()))) {
     return nullptr;
   }
 
   GetBootstrapType func = (GetBootstrapType)GetSymbol(sTop->libHandle, "XRE_GetBootstrap");
   if (!func) {
     return nullptr;
   }