diff --git a/tools/trace-malloc/lib/nsTraceMalloc.c b/tools/trace-malloc/lib/nsTraceMalloc.c index eef1baacc438..78d5ba391b74 100644 --- a/tools/trace-malloc/lib/nsTraceMalloc.c +++ b/tools/trace-malloc/lib/nsTraceMalloc.c @@ -97,48 +97,23 @@ extern __ptr_t __libc_valloc(size_t); #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) - -/* - * 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 *); - -/*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 - -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; -#endif - int prevent_reentry; -}gAllocFuncs; - #endif /* !XP_UNIX */ +#ifdef XP_WIN32 + +/* 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*); + +#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 + typedef struct logfile logfile; #define STARTUP_TMBUFSIZE (64 * 1024) diff --git a/tools/trace-malloc/lib/nsWinTraceMalloc.cpp b/tools/trace-malloc/lib/nsWinTraceMalloc.cpp index 9e4e334e45a7..3f516e56cd13 100644 --- a/tools/trace-malloc/lib/nsWinTraceMalloc.cpp +++ b/tools/trace-malloc/lib/nsWinTraceMalloc.cpp @@ -148,3 +148,34 @@ 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); +}