Bug 830765 - Remove the unneeded code which tracks the list of loaded modules because it is unused and can cause multi-second hangs; r=sicking a=lsblakk
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 21 Jan 2013 15:55:31 -0500
changeset 127321 88daa2beccb378a095a64242d5fcb9bf0b33d42c
parent 127320 70d6e59610f1b29c24fa44288982263c5fd26e0d
child 127322 026c4f71b37eb2531359e624b81f49de50308596
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, lsblakk
bugs830765
milestone20.0a2
Bug 830765 - Remove the unneeded code which tracks the list of loaded modules because it is unused and can cause multi-second hangs; r=sicking a=lsblakk
toolkit/xre/nsWindowsDllBlocklist.cpp
widget/windows/nsAppShell.cpp
xpcom/base/nsDebugImpl.cpp
xpcom/base/nsError.h
--- a/toolkit/xre/nsWindowsDllBlocklist.cpp
+++ b/toolkit/xre/nsWindowsDllBlocklist.cpp
@@ -431,18 +431,16 @@ patched_LdrLoadDll (PWCHAR filePath, PUL
     }
   }
 
 continue_loading:
 #ifdef DEBUG_very_verbose
   printf_stderr("LdrLoadDll: continuing load... ('%S')\n", moduleFileName->Buffer);
 #endif
 
-  NS_SetHasLoadedNewDLLs();
-
   if (gInXPCOMLoadOnMainThread && NS_IsMainThread()) {
     // Check to ensure that the DLL has ASLR.
     full_fname = getFullPath(filePath, fname);
     if (!full_fname) {
       // uh, we couldn't find the DLL at all, so...
       printf_stderr("LdrLoadDll: Blocking load of '%s' (SearchPathW didn't find it?)\n", dllName);
       return STATUS_DLL_NOT_FOUND;
     }
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -10,20 +10,16 @@
 #include "WinTaskbar.h"
 #include "WinMouseScrollHandler.h"
 #include "nsWindowDefs.h"
 #include "nsString.h"
 #include "nsIMM32Handler.h"
 #include "mozilla/widget/AudioSession.h"
 #include "mozilla/HangMonitor.h"
 
-// For skidmark code
-#include <windows.h> 
-#include <tlhelp32.h> 
-
 const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
 const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated";
 
 static UINT sMsgId;
 
 UINT sTaskbarButtonCreatedMsg;
 
 /* static */
@@ -142,107 +138,28 @@ nsAppShell::Init()
 
   mEventWnd = CreateWindowW(kWindowClass, L"nsAppShell:EventWindow",
                            0, 0, 0, 10, 10, NULL, NULL, module, NULL);
   NS_ENSURE_STATE(mEventWnd);
 
   return nsBaseAppShell::Init();
 }
 
-/**
- * This is some temporary code to keep track of where in memory dlls are
- * loaded. This is useful in case someone calls into a dll that has been
- * unloaded. This code lets us see which dll used to be loaded at the given
- * called address.
- */
-#if defined(_MSC_VER) && defined(_M_IX86)
-
-#define LOADEDMODULEINFO_STRSIZE 23
-#define NUM_LOADEDMODULEINFO 250
-
-struct LoadedModuleInfo {
-  void* mStartAddr;
-  void* mEndAddr;
-  char mName[LOADEDMODULEINFO_STRSIZE + 1];
-};
-
-static LoadedModuleInfo* sLoadedModules = 0;
-
-static void
-CollectNewLoadedModules()
-{
-  HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
-  MODULEENTRY32W module;
-
-  // Take a snapshot of all modules in our process.
-  hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
-  if (hModuleSnap == INVALID_HANDLE_VALUE)
-    return;
-
-  // Set the size of the structure before using it.
-  module.dwSize = sizeof(MODULEENTRY32W);
-
-  // Now walk the module list of the process,
-  // and display information about each module
-  bool done = !Module32FirstW(hModuleSnap, &module);
-  while (!done) {
-    NS_LossyConvertUTF16toASCII moduleName(module.szModule);
-    bool found = false;
-    uint32_t i;
-    for (i = 0; i < NUM_LOADEDMODULEINFO &&
-                sLoadedModules[i].mStartAddr; ++i) {
-      if (sLoadedModules[i].mStartAddr == module.modBaseAddr &&
-          !strcmp(moduleName.get(),
-                  sLoadedModules[i].mName)) {
-        found = true;
-        break;
-      }
-    }
-
-    if (!found && i < NUM_LOADEDMODULEINFO) {
-      sLoadedModules[i].mStartAddr = module.modBaseAddr;
-      sLoadedModules[i].mEndAddr = module.modBaseAddr + module.modBaseSize;
-      strncpy(sLoadedModules[i].mName, moduleName.get(),
-              LOADEDMODULEINFO_STRSIZE);
-      sLoadedModules[i].mName[LOADEDMODULEINFO_STRSIZE] = 0;
-    }
-
-    done = !Module32NextW(hModuleSnap, &module);
-  }
-
-  uint32_t i;
-  for (i = 0; i < NUM_LOADEDMODULEINFO &&
-              sLoadedModules[i].mStartAddr; ++i) {}
-
-  CloseHandle(hModuleSnap);
-}
-#endif // defined(_MSC_VER) && defined(_M_IX86)
 
 NS_IMETHODIMP
 nsAppShell::Run(void)
 {
-#if defined(_MSC_VER) && defined(_M_IX86)
-  LoadedModuleInfo modules[NUM_LOADEDMODULEINFO];
-  memset(modules, 0, sizeof(modules));
-  sLoadedModules = modules;	
-#endif
-
   // Ignore failure; failing to start the application is not exactly an
   // appropriate response to failing to start an audio session.
   mozilla::widget::StartAudioSession();
 
   nsresult rv = nsBaseAppShell::Run();
 
   mozilla::widget::StopAudioSession();
 
-#if defined(_MSC_VER) && defined(_M_IX86)
-  // Don't forget to null this out!
-  sLoadedModules = nullptr;
-#endif
-
   return rv;
 }
 
 NS_IMETHODIMP
 nsAppShell::Exit(void)
 {
   return nsBaseAppShell::Exit();
 }
@@ -290,23 +207,16 @@ nsAppShell::ScheduleNativeEventCallback(
   // dropping in sub classes / modal loops we do not control. 
   mLastNativeEventScheduled = TimeStamp::Now();
   ::PostMessage(mEventWnd, sMsgId, 0, reinterpret_cast<LPARAM>(this));
 }
 
 bool
 nsAppShell::ProcessNextNativeEvent(bool mayWait)
 {
-#if defined(_MSC_VER) && defined(_M_IX86)
-  if (sXPCOMHasLoadedNewDLLs && sLoadedModules) {
-    sXPCOMHasLoadedNewDLLs = false;
-    CollectNewLoadedModules();
-  }
-#endif
-
   // Notify ipc we are spinning a (possibly nested) gecko event loop.
   mozilla::ipc::RPCChannel::NotifyGeckoEventDispatch();
 
   bool gotMessage = false;
 
   do {
     MSG msg;
     bool uiMessage = PeekUIMessage(&msg);
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -587,17 +587,8 @@ NS_ErrorAccordingToNSPR()
       case PR_DIRECTORY_NOT_EMPTY_ERROR:        return NS_ERROR_FILE_DIR_NOT_EMPTY;
       case PR_NO_ACCESS_RIGHTS_ERROR:           return NS_ERROR_FILE_ACCESS_DENIED;
       default:                                  return NS_ERROR_FAILURE;
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
-#ifdef XP_WIN
-bool sXPCOMHasLoadedNewDLLs = false;
-
-NS_EXPORT void
-NS_SetHasLoadedNewDLLs()
-{
-  sXPCOMHasLoadedNewDLLs = true;
-}
-#endif
--- a/xpcom/base/nsError.h
+++ b/xpcom/base/nsError.h
@@ -218,14 +218,9 @@ inline bool NS_ERROR_GET_SEVERITY(nsresu
 #endif
 
 
 #ifdef _MSC_VER
 #pragma warning(disable: 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream' */
 #pragma warning(disable: 4275) /* non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' */
 #endif
 
-#if defined(XP_WIN) && defined(__cplusplus)
-extern bool sXPCOMHasLoadedNewDLLs;
-NS_EXPORT void NS_SetHasLoadedNewDLLs();
 #endif
-
-#endif