Bug 1467736: Add support for DllBlocklist_Shutdown;r=aklotz
authorCarl Corcoran <ccorcoran@mozilla.com>
Wed, 29 Aug 2018 18:49:49 +0000
changeset 491682 bda9e323c7fb9731fd39373f3dcd586530ead2a7
parent 491681 c21566b512f1a7339bb3d0e286865dadc5e25ace
child 491683 a6f7137925e1e17f2c75de62efcbdfd9f3349c75
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1467736
milestone63.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 1467736: Add support for DllBlocklist_Shutdown;r=aklotz Differential Revision: https://phabricator.services.mozilla.com/D4544
browser/app/nsBrowserApp.cpp
ipc/app/MozillaRuntimeMain.cpp
js/xpconnect/shell/xpcshell.cpp
mozglue/build/WindowsDllBlocklist.cpp
mozglue/build/WindowsDllBlocklist.h
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -281,16 +281,20 @@ int main(int argc, char* argv[], char* e
 
     nsresult rv = InitXPCOMGlue();
     if (NS_FAILED(rv)) {
       return 255;
     }
 
     int result = content_process_main(gBootstrap.get(), argc, argv);
 
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+    DllBlocklist_Shutdown();
+#endif
+
     // InitXPCOMGlue calls NS_LogInit, so we need to balance it here.
     gBootstrap->NS_LogTerm();
 
     return result;
   }
 #endif
 
 #ifdef HAS_DLL_BLOCKLIST
@@ -307,16 +311,20 @@ int main(int argc, char* argv[], char* e
 #ifdef MOZ_BROWSER_CAN_BE_CONTENTPROC
   gBootstrap->XRE_EnableSameExecutableForContentProc();
 #endif
 
   int result = do_main(argc, argv, envp);
 
   gBootstrap->NS_LogTerm();
 
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
+
 #ifdef XP_MACOSX
   // Allow writes again. While we would like to catch writes from static
   // destructors to allow early exits to use _exit, we know that there is
   // at least one such write that we don't control (see bug 826029). For
   // now we enable writes again and early exits will have to use exit instead
   // of _exit.
   gBootstrap->XRE_StopLateWriteChecks();
 #endif
--- a/ipc/app/MozillaRuntimeMain.cpp
+++ b/ipc/app/MozillaRuntimeMain.cpp
@@ -17,10 +17,14 @@ main(int argc, char *argv[])
 #ifdef HAS_DLL_BLOCKLIST
   DllBlocklist_Initialize(eDllBlocklistInitFlagIsChildProcess);
 #endif
 
   Bootstrap::UniquePtr bootstrap = GetBootstrap();
   if (!bootstrap) {
     return 2;
   }
-  return content_process_main(bootstrap.get(), argc, argv);
+  int ret = content_process_main(bootstrap.get(), argc, argv);
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
+  return ret;
 }
--- a/js/xpconnect/shell/xpcshell.cpp
+++ b/js/xpconnect/shell/xpcshell.cpp
@@ -61,14 +61,18 @@ main(int argc, char** argv, char** envp)
 
     mozilla::Bootstrap::UniquePtr bootstrap = mozilla::GetBootstrap();
     if (!bootstrap) {
         return 2;
     }
 
     int result = bootstrap->XRE_XPCShellMain(argc, argv, envp, &shellData);
 
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+    DllBlocklist_Shutdown();
+#endif
+
 #ifdef XP_MACOSX
     FinishAutoreleasePool();
 #endif
 
     return result;
 }
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -766,16 +766,23 @@ DllBlocklist_Initialize(uint32_t aInitFl
     pProc = (void*)GetProcAddress(hKernel, "LoadLibraryExW");
     if (pProc) {
       gStartAddressesToBlock->append(pProc);
     }
   }
 #endif
 }
 
+#ifdef DEBUG
+MFBT_API void
+DllBlocklist_Shutdown()
+{
+}
+#endif // DEBUG
+
 static void
 WriteAnnotation(HANDLE aFile, Annotation aAnnotation, const char* aValue,
                 DWORD* aNumBytes)
 {
   const char* str = AnnotationToString(aAnnotation);
   WriteFile(aFile, str, strlen(str), aNumBytes, nullptr);
   WriteFile(aFile, "=", 1, aNumBytes, nullptr);
   WriteFile(aFile, aValue, strlen(aValue), aNumBytes, nullptr);
--- a/mozglue/build/WindowsDllBlocklist.h
+++ b/mozglue/build/WindowsDllBlocklist.h
@@ -24,16 +24,23 @@ enum DllBlocklistInitFlags
   eDllBlocklistInitFlagIsChildProcess = 1,
   eDllBlocklistInitFlagWasBootstrapped = 2
 };
 
 MFBT_API void DllBlocklist_Initialize(uint32_t aInitFlags = eDllBlocklistInitFlagDefault);
 MFBT_API void DllBlocklist_WriteNotes(HANDLE file);
 MFBT_API bool DllBlocklist_CheckStatus();
 
+// This export intends to clean up after DllBlocklist_Initialize().
+// It's disabled in release builds for performance and to limit callers' ability
+// to interfere with dll blocking.
+#ifdef DEBUG
+MFBT_API void DllBlocklist_Shutdown();
+#endif // DEBUG
+
 #ifdef ENABLE_TESTS
 typedef void (*DllLoadHookType)(bool aDllLoaded, NTSTATUS aNtStatus,
                                 HANDLE aDllBase, PUNICODE_STRING aDllName);
 MFBT_API void DllBlocklist_SetDllLoadHook(DllLoadHookType aHook);
 typedef void (*CreateThreadHookType)(bool aWasAllowed, void *aStartAddress);
 MFBT_API void DllBlocklist_SetCreateThreadHook(CreateThreadHookType aHook);
 #endif // ENABLE_TESTS
 
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -1332,16 +1332,19 @@ FreeBreakpadVM()
  *
  * Also calls FreeBreakpadVM if appropriate.
  */
 static bool FPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
                       MDRawAssertionInfo* assertion)
 {
   if (!exinfo) {
     mozilla::IOInterposer::Disable();
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+    DllBlocklist_Shutdown();
+#endif
     FreeBreakpadVM();
     return true;
   }
 
   PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)exinfo->ExceptionRecord;
   switch (e->ExceptionCode) {
     case STATUS_FLOAT_DENORMAL_OPERAND:
     case STATUS_FLOAT_DIVIDE_BY_ZERO:
@@ -1350,16 +1353,19 @@ static bool FPEFilter(void* context, EXC
     case STATUS_FLOAT_OVERFLOW:
     case STATUS_FLOAT_STACK_CHECK:
     case STATUS_FLOAT_UNDERFLOW:
     case STATUS_FLOAT_MULTIPLE_FAULTS:
     case STATUS_FLOAT_MULTIPLE_TRAPS:
       return false; // Don't write minidump, continue exception search
   }
   mozilla::IOInterposer::Disable();
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
   FreeBreakpadVM();
   return true;
 }
 
 static bool
 ChildFPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
                MDRawAssertionInfo* assertion)
 {
@@ -1418,16 +1424,19 @@ static bool ShouldReport()
 
   return true;
 }
 
 static bool
 Filter(void* context)
 {
   mozilla::IOInterposer::Disable();
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
   return true;
 }
 
 static bool
 ChildFilter(void* context)
 {
   bool result = Filter(context);
   if (result) {
@@ -3811,16 +3820,20 @@ GetChildThread(ProcessHandle childPid, T
 }
 #endif
 
 bool TakeMinidump(nsIFile** aResult, bool aMoveToPending)
 {
   if (!GetEnabled())
     return false;
 
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
+
   AutoIOInterposerDisable disableIOInterposition;
 
   xpstring dump_path;
 #ifndef XP_LINUX
   dump_path = gExceptionHandler->dump_path();
 #else
   dump_path = gExceptionHandler->minidump_descriptor().directory();
 #endif
@@ -3932,16 +3945,19 @@ CreateMinidumpsAndPair(ProcessHandle aTa
                        nsIFile** aMainDumpOut,
                        std::function<void(bool)>&& aCallback,
                        bool aAsync)
 {
   if (!GetEnabled()) {
     aCallback(false);
     return;
   }
+#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
+  DllBlocklist_Shutdown();
+#endif
 
   AutoIOInterposerDisable disableIOInterposition;
 
   xpstring dump_path;
 #ifndef XP_LINUX
   dump_path = gExceptionHandler->dump_path();
 #else
   dump_path = gExceptionHandler->minidump_descriptor().directory();