--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -1259,27 +1259,17 @@ FreeCallback(void* aPtr, Thread* aT, Dea
// malloc/free interception
//---------------------------------------------------------------------------
static void Init(malloc_table_t* aMallocTable);
} // namespace dmd
} // namespace mozilla
-void
-replace_init(malloc_table_t* aMallocTable, ReplaceMallocBridge** aBridge)
-{
- mozilla::dmd::Init(aMallocTable);
-#define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE
-#define MALLOC_DECL(name, ...) aMallocTable->name = replace_ ## name;
-#include "malloc_decls.h"
- *aBridge = mozilla::dmd::gDMDBridge;
-}
-
-void*
+static void*
replace_malloc(size_t aSize)
{
using namespace mozilla::dmd;
if (!gIsDMDInitialized) {
// DMD hasn't started up, either because it wasn't enabled by the user, or
// we're still in Init() and something has indirectly called malloc. Do a
// vanilla malloc. (In the latter case, if it fails we'll crash. But
@@ -1295,17 +1285,17 @@ replace_malloc(size_t aSize)
}
// This must be a call to malloc from outside DMD. Intercept it.
void* ptr = gMallocTable.malloc(aSize);
AllocCallback(ptr, aSize, t);
return ptr;
}
-void*
+static void*
replace_calloc(size_t aCount, size_t aSize)
{
using namespace mozilla::dmd;
if (!gIsDMDInitialized) {
return gMallocTable.calloc(aCount, aSize);
}
@@ -1314,17 +1304,17 @@ replace_calloc(size_t aCount, size_t aSi
return InfallibleAllocPolicy::calloc_(aCount * aSize);
}
void* ptr = gMallocTable.calloc(aCount, aSize);
AllocCallback(ptr, aCount * aSize, t);
return ptr;
}
-void*
+static void*
replace_realloc(void* aOldPtr, size_t aSize)
{
using namespace mozilla::dmd;
if (!gIsDMDInitialized) {
return gMallocTable.realloc(aOldPtr, aSize);
}
@@ -1355,17 +1345,17 @@ replace_realloc(void* aOldPtr, size_t aS
// block will end up looking like it was allocated for the first time here,
// which is untrue, and the slop bytes will be zero, which may be untrue.
// But this case is rare and doing better isn't worth the effort.
AllocCallback(aOldPtr, gMallocTable.malloc_usable_size(aOldPtr), t);
}
return ptr;
}
-void*
+static void*
replace_memalign(size_t aAlignment, size_t aSize)
{
using namespace mozilla::dmd;
if (!gIsDMDInitialized) {
return gMallocTable.memalign(aAlignment, aSize);
}
@@ -1374,17 +1364,17 @@ replace_memalign(size_t aAlignment, size
return InfallibleAllocPolicy::memalign_(aAlignment, aSize);
}
void* ptr = gMallocTable.memalign(aAlignment, aSize);
AllocCallback(ptr, aSize, t);
return ptr;
}
-void
+static void
replace_free(void* aPtr)
{
using namespace mozilla::dmd;
if (!gIsDMDInitialized) {
gMallocTable.free(aPtr);
return;
}
@@ -1398,16 +1388,26 @@ replace_free(void* aPtr)
// could call malloc and get the freed block and update the table, and then
// our update here would remove the newly-malloc'd block.
DeadBlock db;
FreeCallback(aPtr, t, &db);
MaybeAddToDeadBlockTable(db);
gMallocTable.free(aPtr);
}
+void
+replace_init(malloc_table_t* aMallocTable, ReplaceMallocBridge** aBridge)
+{
+ mozilla::dmd::Init(aMallocTable);
+#define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE
+#define MALLOC_DECL(name, ...) aMallocTable->name = replace_ ## name;
+#include "malloc_decls.h"
+ *aBridge = mozilla::dmd::gDMDBridge;
+}
+
namespace mozilla {
namespace dmd {
//---------------------------------------------------------------------------
// Options (Part 2)
//---------------------------------------------------------------------------
// Given an |aOptionName| like "foo", succeed if |aArg| has the form "foo=blah"
--- a/memory/replace/logalloc/LogAlloc.cpp
+++ b/memory/replace/logalloc/LogAlloc.cpp
@@ -68,16 +68,125 @@ class LogAllocBridge : public ReplaceMal
{
virtual void InitDebugFd(mozilla::DebugFdRegistry& aRegistry) override {
if (!sStdoutOrStderr) {
aRegistry.RegisterHandle(sFd);
}
}
};
+/* Do a simple, text-form, log of all calls to replace-malloc functions.
+ * Use locking to guarantee that an allocation that did happen is logged
+ * before any other allocation/free happens.
+ */
+
+static void*
+replace_malloc(size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* ptr = sFuncs.malloc(aSize);
+ if (ptr) {
+ FdPrintf(sFd, "%zu %zu malloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
+ }
+ return ptr;
+}
+
+#ifndef LOGALLOC_MINIMAL
+static int
+replace_posix_memalign(void** aPtr, size_t aAlignment, size_t aSize)
+{
+ AutoLock lock(sLock);
+ int ret = sFuncs.posix_memalign(aPtr, aAlignment, aSize);
+ if (ret == 0) {
+ FdPrintf(sFd, "%zu %zu posix_memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
+ aAlignment, aSize, *aPtr);
+ }
+ return ret;
+}
+
+static void*
+replace_aligned_alloc(size_t aAlignment, size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* ptr = sFuncs.aligned_alloc(aAlignment, aSize);
+ if (ptr) {
+ FdPrintf(sFd, "%zu %zu aligned_alloc(%zu,%zu)=%p\n", GetPid(), GetTid(),
+ aAlignment, aSize, ptr);
+ }
+ return ptr;
+}
+#endif
+
+static void*
+replace_calloc(size_t aNum, size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* ptr = sFuncs.calloc(aNum, aSize);
+ if (ptr) {
+ FdPrintf(sFd, "%zu %zu calloc(%zu,%zu)=%p\n", GetPid(), GetTid(), aNum,
+ aSize, ptr);
+ }
+ return ptr;
+}
+
+static void*
+replace_realloc(void* aPtr, size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* new_ptr = sFuncs.realloc(aPtr, aSize);
+ if (new_ptr || !aSize) {
+ FdPrintf(sFd, "%zu %zu realloc(%p,%zu)=%p\n", GetPid(), GetTid(), aPtr,
+ aSize, new_ptr);
+ }
+ return new_ptr;
+}
+
+static void
+replace_free(void* aPtr)
+{
+ AutoLock lock(sLock);
+ if (aPtr) {
+ FdPrintf(sFd, "%zu %zu free(%p)\n", GetPid(), GetTid(), aPtr);
+ }
+ sFuncs.free(aPtr);
+}
+
+static void*
+replace_memalign(size_t aAlignment, size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* ptr = sFuncs.memalign(aAlignment, aSize);
+ if (ptr) {
+ FdPrintf(sFd, "%zu %zu memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
+ aAlignment, aSize, ptr);
+ }
+ return ptr;
+}
+
+#ifndef LOGALLOC_MINIMAL
+static void*
+replace_valloc(size_t aSize)
+{
+ AutoLock lock(sLock);
+ void* ptr = sFuncs.valloc(aSize);
+ if (ptr) {
+ FdPrintf(sFd, "%zu %zu valloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
+ }
+ return ptr;
+}
+#endif
+
+static void
+replace_jemalloc_stats(jemalloc_stats_t* aStats)
+{
+ AutoLock lock(sLock);
+ sFuncs.jemalloc_stats(aStats);
+ FdPrintf(sFd, "%zu %zu jemalloc_stats()\n", GetPid(), GetTid());
+}
+
void
replace_init(malloc_table_t* aTable, ReplaceMallocBridge** aBridge)
{
static LogAllocBridge bridge;
sFuncs = *aTable;
#define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE
#define MALLOC_DECL(name, ...) aTable->name = replace_ ## name;
#include "malloc_decls.h"
@@ -164,117 +273,8 @@ replace_init(malloc_table_t* aTable, Rep
fd = open(log, O_WRONLY | O_CREAT | O_APPEND, 0644);
}
if (fd > 0) {
sFd = fd;
}
#endif
}
}
-
-/* Do a simple, text-form, log of all calls to replace-malloc functions.
- * Use locking to guarantee that an allocation that did happen is logged
- * before any other allocation/free happens.
- */
-
-void*
-replace_malloc(size_t aSize)
-{
- AutoLock lock(sLock);
- void* ptr = sFuncs.malloc(aSize);
- if (ptr) {
- FdPrintf(sFd, "%zu %zu malloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
- }
- return ptr;
-}
-
-#ifndef LOGALLOC_MINIMAL
-int
-replace_posix_memalign(void** aPtr, size_t aAlignment, size_t aSize)
-{
- AutoLock lock(sLock);
- int ret = sFuncs.posix_memalign(aPtr, aAlignment, aSize);
- if (ret == 0) {
- FdPrintf(sFd, "%zu %zu posix_memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
- aAlignment, aSize, *aPtr);
- }
- return ret;
-}
-
-void*
-replace_aligned_alloc(size_t aAlignment, size_t aSize)
-{
- AutoLock lock(sLock);
- void* ptr = sFuncs.aligned_alloc(aAlignment, aSize);
- if (ptr) {
- FdPrintf(sFd, "%zu %zu aligned_alloc(%zu,%zu)=%p\n", GetPid(), GetTid(),
- aAlignment, aSize, ptr);
- }
- return ptr;
-}
-#endif
-
-void*
-replace_calloc(size_t aNum, size_t aSize)
-{
- AutoLock lock(sLock);
- void* ptr = sFuncs.calloc(aNum, aSize);
- if (ptr) {
- FdPrintf(sFd, "%zu %zu calloc(%zu,%zu)=%p\n", GetPid(), GetTid(), aNum,
- aSize, ptr);
- }
- return ptr;
-}
-
-void*
-replace_realloc(void* aPtr, size_t aSize)
-{
- AutoLock lock(sLock);
- void* new_ptr = sFuncs.realloc(aPtr, aSize);
- if (new_ptr || !aSize) {
- FdPrintf(sFd, "%zu %zu realloc(%p,%zu)=%p\n", GetPid(), GetTid(), aPtr,
- aSize, new_ptr);
- }
- return new_ptr;
-}
-
-void
-replace_free(void* aPtr)
-{
- AutoLock lock(sLock);
- if (aPtr) {
- FdPrintf(sFd, "%zu %zu free(%p)\n", GetPid(), GetTid(), aPtr);
- }
- sFuncs.free(aPtr);
-}
-
-void*
-replace_memalign(size_t aAlignment, size_t aSize)
-{
- AutoLock lock(sLock);
- void* ptr = sFuncs.memalign(aAlignment, aSize);
- if (ptr) {
- FdPrintf(sFd, "%zu %zu memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
- aAlignment, aSize, ptr);
- }
- return ptr;
-}
-
-#ifndef LOGALLOC_MINIMAL
-void*
-replace_valloc(size_t aSize)
-{
- AutoLock lock(sLock);
- void* ptr = sFuncs.valloc(aSize);
- if (ptr) {
- FdPrintf(sFd, "%zu %zu valloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
- }
- return ptr;
-}
-#endif
-
-void
-replace_jemalloc_stats(jemalloc_stats_t* aStats)
-{
- AutoLock lock(sLock);
- sFuncs.jemalloc_stats(aStats);
- FdPrintf(sFd, "%zu %zu jemalloc_stats()\n", GetPid(), GetTid());
-}