Bug 568467 - trace-malloc support for Windows x64. r=dbaron
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 04 Jun 2010 16:53:02 +0900
changeset 43089 6dbc5341b490d5e553dedd555cc0d927a623a6fe
parent 43088 80e47aae2681aabff38851b3d1c15f446c60c59e
child 43090 01a82f7a4e70beb8b1f96cb690159d6ce7c7fb54
push id13609
push userm_kato@ga2.so-net.ne.jp
push dateFri, 04 Jun 2010 07:53:57 +0000
treeherdermozilla-central@6dbc5341b490 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs568467
milestone1.9.3a5pre
first release with
nightly linux32
6dbc5341b490 / 3.7a5pre / 20100604030024 / files
nightly linux64
6dbc5341b490 / 3.7a5pre / 20100604030722 / files
nightly mac
6dbc5341b490 / 3.7a5pre / 20100604030629 / files
nightly win32
6dbc5341b490 / 3.7a5pre / 20100604040314 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 568467 - trace-malloc support for Windows x64. r=dbaron
tools/trace-malloc/lib/nsDebugHelpWin32.cpp
tools/trace-malloc/lib/nsDebugHelpWin32.h
--- a/tools/trace-malloc/lib/nsDebugHelpWin32.cpp
+++ b/tools/trace-malloc/lib/nsDebugHelpWin32.cpp
@@ -32,29 +32,29 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
-#if defined(_WIN32) && defined(_M_IX86)
+#if defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
 // This is the .cpp file where the globals live
 #define DHW_IMPLEMENT_GLOBALS
 #include <stdio.h>
 #include "prtypes.h"
 #include "prprf.h"
 #include "prlog.h"
 #include "plstr.h"
 #include "prlock.h"
 #include "nscore.h"
 #include "nsDebugHelpWin32.h"
 #else
-#error "nsDebugHelpWin32.cpp should only be built in Win32 x86 builds"
+#error "nsDebugHelpWin32.cpp should only be built in Win32 x86/x64 builds"
 #endif
 
 
 
 /***************************************************************************/
 
 
 PRLock*           DHWImportHooker::gLock  = nsnull;
@@ -79,17 +79,21 @@ dhwEnsureImageHlpInitialized()
              , dw);
       return PR_FALSE;
     }
 
 #define INIT_PROC(typename_, name_) \
     dhw##name_ = (typename_) ::GetProcAddress(module, #name_); \
     if(!dhw##name_) return PR_FALSE;
 
+#ifdef _WIN64
+    INIT_PROC(ENUMERATELOADEDMODULES64, EnumerateLoadedModules64);
+#else
     INIT_PROC(ENUMERATELOADEDMODULES, EnumerateLoadedModules);
+#endif
     INIT_PROC(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData);
 
 #undef INIT_PROC
 
     gInitialized = PR_TRUE;
   }
 
   return gInitialized;
@@ -203,36 +207,48 @@ DHWImportHooker::~DHWImportHooker()
         gLock = nsnull;
         PR_Unlock(theLock);
         PR_DestroyLock(theLock);
     }
     if (gLock)
         PR_Unlock(gLock);
 }    
 
+#ifdef _WIN64
+static BOOL CALLBACK ModuleEnumCallback(PCSTR ModuleName,
+                                        DWORD64 ModuleBase,
+                                        ULONG ModuleSize,
+                                        PVOID UserContext)
+#else
 static BOOL CALLBACK ModuleEnumCallback(PCSTR ModuleName,
                                         ULONG ModuleBase,
                                         ULONG ModuleSize,
                                         PVOID UserContext)
+#endif
 {
     //printf("Module Name %s\n",ModuleName);
     DHWImportHooker* self = (DHWImportHooker*) UserContext;
     HMODULE aModule = (HMODULE) ModuleBase;
     return self->PatchOneModule(aModule, ModuleName);
 }
 
 PRBool 
 DHWImportHooker::PatchAllModules()
 {
     // Need to cast to PENUMLOADED_MODULES_CALLBACK because the
     // constness of the first parameter of PENUMLOADED_MODULES_CALLBACK
     // varies over SDK versions (from non-const to const over time).
     // See bug 391848 and bug 415426.
+#ifdef _WIN64
+    return dhwEnumerateLoadedModules64(::GetCurrentProcess(),
+               (PENUMLOADED_MODULES_CALLBACK64)ModuleEnumCallback, this);
+#else
     return dhwEnumerateLoadedModules(::GetCurrentProcess(), 
                (PENUMLOADED_MODULES_CALLBACK)ModuleEnumCallback, this);
+#endif
 }    
                                 
 PRBool 
 DHWImportHooker::PatchOneModule(HMODULE aModule, const char* name)
 {
     if(aModule == mIgnoreModule)
     {
         return PR_TRUE;
--- a/tools/trace-malloc/lib/nsDebugHelpWin32.h
+++ b/tools/trace-malloc/lib/nsDebugHelpWin32.h
@@ -31,30 +31,30 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-/* Win32 x86 code for stack walking, symbol resolution, and function hooking */
+/* Win32 x86/x64 code for stack walking, symbol resolution, and function hooking */
 
 #ifndef __nsDebugHelpWin32_h__
 #define __nsDebugHelpWin32_h__
 
-#if defined(_WIN32) && defined(_M_IX86)
+#if defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
   #ifndef WIN32_LEAN_AND_MEAN
     #define WIN32_LEAN_AND_MEAN
   #endif
   #include <windows.h>
   #include <imagehlp.h>
   #include <crtdbg.h>
 #else
-  #error "nsDebugHelpWin32.h should only be included in Win32 x86 builds"
+  #error "nsDebugHelpWin32.h should only be included in Win32 x86/x64 builds"
 #endif
 
 // XXX temporary hack...
 //#include "hacky_defines.h"
 
 
 /***************************************************************************/
 // useful macros...
@@ -117,18 +117,23 @@ DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETOP
 DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETMODULEINFO, SymGetModuleInfo, \
                                 BOOL, __stdcall, (HANDLE, DWORD, PIMAGEHLP_MODULE));
 
 DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMGETSYMFROMADDRPROC, SymGetSymFromAddr, \
                                 BOOL, __stdcall, (HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL));
 
 #endif
 
+#ifndef _WIN64
 DHW_DECLARE_FUN_TYPE_AND_GLOBAL(ENUMERATELOADEDMODULES, EnumerateLoadedModules, \
                                 BOOL, __stdcall, (HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID));
+#else
+DHW_DECLARE_FUN_TYPE_AND_GLOBAL(ENUMERATELOADEDMODULES64, EnumerateLoadedModules64, \
+                                BOOL, __stdcall, (HANDLE, PENUMLOADED_MODULES_CALLBACK64, PVOID));
+#endif
 
 DHW_DECLARE_FUN_TYPE_AND_GLOBAL(IMAGEDIRECTORYENTRYTODATA, ImageDirectoryEntryToData, \
                                 PVOID, __stdcall, (PVOID, BOOL, USHORT, PULONG));
 
 // We aren't using any of the below yet...
 
 /*
 DHW_DECLARE_FUN_TYPE_AND_GLOBAL(SYMCLEANUPPROC, SymCleanup, \