Define the __libc_* on Windows to something that does automatic suppression, like on Linux. b=391477 r+a=brendan
authordbaron@dbaron.org
Fri, 10 Aug 2007 15:21:13 -0700
changeset 4498 99aae82cc4cc995bf5fa55465d7832db37230c16
parent 4497 552013b33ac14984247e71356d13dab5c02fec91
child 4499 18e747c9e0872f75f9eb868222823c826ba888a8
push idunknown
push userunknown
push dateunknown
bugs391477
milestone1.9a8pre
Define the __libc_* on Windows to something that does automatic suppression, like on Linux. b=391477 r+a=brendan
tools/trace-malloc/lib/nsTraceMalloc.c
tools/trace-malloc/lib/nsWinTraceMalloc.cpp
--- a/tools/trace-malloc/lib/nsTraceMalloc.c
+++ b/tools/trace-malloc/lib/nsTraceMalloc.c
@@ -92,57 +92,32 @@ extern __ptr_t __libc_calloc(size_t, siz
 extern __ptr_t __libc_realloc(__ptr_t, size_t);
 extern void    __libc_free(__ptr_t);
 extern __ptr_t __libc_memalign(size_t, size_t);
 extern __ptr_t __libc_valloc(size_t);
 #ifdef WRAP_SYSTEM_INCLUDES
 #pragma GCC visibility pop
 #endif
 
-#else  /* !XP_UNIX */
-
-#define __libc_malloc(x) malloc(x)
-#define __libc_calloc(x, y) calloc(x,y)
-#define __libc_realloc(x, y) realloc(x,y)
-#define __libc_free(x) free(x)
+#endif /* !XP_UNIX */
 
-/*
- * Ok we need to load malloc, free, realloc, and calloc from the dll and store
- * the function pointers somewhere. All other dlls that link with this library
- * should have their malloc overridden to call this one.
- */
-typedef void * (__stdcall *MALLOCPROC)(size_t);
-typedef void * (__stdcall *REALLOCPROC)(void *, size_t);
-typedef void * (__stdcall *CALLOCPROC)(size_t,size_t);
-typedef void (__stdcall *FREEPROC)(void *);
+#ifdef XP_WIN32
 
-/*debug types*/
-#ifdef _DEBUG
-typedef void * (__stdcall *MALLOCDEBUGPROC) ( size_t, int, const char *, int);
-typedef void * (__stdcall *CALLOCDEBUGPROC) ( size_t, size_t, int, const char *, int);
-typedef void * (__stdcall *REALLOCDEBUGPROC) ( void *, size_t, int, const char *, int);
-typedef void   (__stdcall *FREEDEBUGPROC) ( void *, int);
-#endif
+/* defined in nsWinTraceMalloc.cpp */
+void* dhw_orig_malloc(size_t);
+void* dhw_orig_calloc(size_t, size_t);
+void* dhw_orig_realloc(void*, size_t);
+void dhw_orig_free(void*);
 
-struct AllocationFuncs
-{
-  MALLOCPROC   malloc_proc;
-  CALLOCPROC   calloc_proc;
-  REALLOCPROC  realloc_proc;
-  FREEPROC     free_proc;
-#ifdef _DEBUG
-  MALLOCDEBUGPROC   malloc_debug_proc;
-  CALLOCDEBUGPROC   calloc_debug_proc;
-  REALLOCDEBUGPROC  realloc_debug_proc;
-  FREEDEBUGPROC     free_debug_proc;
+#define __libc_malloc(x)                dhw_orig_malloc(x)
+#define __libc_calloc(x, y)             dhw_orig_calloc(x,y)
+#define __libc_realloc(x, y)            dhw_orig_realloc(x,y)
+#define __libc_free(x)                  dhw_orig_free(x)
+
 #endif
-  int          prevent_reentry;
-}gAllocFuncs;
-
-#endif /* !XP_UNIX */
 
 typedef struct logfile logfile;
 
 #define STARTUP_TMBUFSIZE (64 * 1024)
 #define LOGFILE_TMBUFSIZE (16 * 1024)
 
 struct logfile {
     int         fd;
--- a/tools/trace-malloc/lib/nsWinTraceMalloc.cpp
+++ b/tools/trace-malloc/lib/nsWinTraceMalloc.cpp
@@ -143,8 +143,39 @@ StartupHooker()
   DHWImportHooker &deletehooker = getDeleteHooker();
   printf("Startup Hooker\n");
 }
 
 PR_IMPLEMENT(void)
 ShutdownHooker()
 {
 }
+
+extern "C" {
+  void* dhw_orig_malloc(size_t);
+  void* dhw_orig_calloc(size_t, size_t);
+  void* dhw_orig_realloc(void*, size_t);
+  void dhw_orig_free(void*);
+}
+
+void*
+dhw_orig_malloc(size_t size)
+{
+    return DHW_ORIGINAL(MALLOC_, getMallocHooker())(size);
+}
+
+void*
+dhw_orig_calloc(size_t count, size_t size)
+{
+    return DHW_ORIGINAL(CALLOC_, getCallocHooker())(count,size);
+}
+
+void*
+dhw_orig_realloc(void* pin, size_t size)
+{
+    return DHW_ORIGINAL(REALLOC_, getReallocHooker())(pin, size);
+}
+
+void
+dhw_orig_free(void* p)
+{
+    DHW_ORIGINAL(FREE_, getFreeHooker())(p);
+}