зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1420355 - Don't declare replace_* functions in replace_malloc.h. r=njn
The original purpose of those declarations was to avoid the function definitions being wrong, as well as forcing them being exported properly (as extern "C", as weak symbols when necessary, etc.), but: - The implementations being C++, function overloads simply allowed functions with the same name to have a different signature. - As of bug 1420353, the functions don't need to be exported anymore, nor do we care whether their symbols are mangled. Furthermore, they're now being assigned to function table fields, meaning there is type checking in place, now. So all in all, these declarations can be removed. Also, as further down the line we're going to statically link the replace-malloc libraries, avoid symbol conflicts by making those functions static. --HG-- extra : rebase_source : 0dbb15f2c85bc873e7eb662b8d757f99b0732270
This commit is contained in:
Родитель
2b959b7c6e
Коммит
449973411b
|
@ -90,11 +90,6 @@ MOZ_BEGIN_EXTERN_C
|
|||
MOZ_EXPORT void
|
||||
replace_init(malloc_table_t*, struct ReplaceMallocBridge**) MOZ_REPLACE_WEAK;
|
||||
|
||||
// Define the replace_* functions as not exported.
|
||||
#define MALLOC_DECL(name, return_type, ...) \
|
||||
return_type replace_##name(__VA_ARGS__);
|
||||
#include "malloc_decls.h"
|
||||
|
||||
MOZ_END_EXTERN_C
|
||||
|
||||
#endif // replace_malloc_h
|
||||
|
|
|
@ -1264,17 +1264,7 @@ 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;
|
||||
|
@ -1300,7 +1290,7 @@ replace_malloc(size_t aSize)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void*
|
||||
static void*
|
||||
replace_calloc(size_t aCount, size_t aSize)
|
||||
{
|
||||
using namespace mozilla::dmd;
|
||||
|
@ -1319,7 +1309,7 @@ replace_calloc(size_t aCount, size_t aSize)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void*
|
||||
static void*
|
||||
replace_realloc(void* aOldPtr, size_t aSize)
|
||||
{
|
||||
using namespace mozilla::dmd;
|
||||
|
@ -1360,7 +1350,7 @@ replace_realloc(void* aOldPtr, size_t aSize)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void*
|
||||
static void*
|
||||
replace_memalign(size_t aAlignment, size_t aSize)
|
||||
{
|
||||
using namespace mozilla::dmd;
|
||||
|
@ -1379,7 +1369,7 @@ replace_memalign(size_t aAlignment, size_t aSize)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
replace_free(void* aPtr)
|
||||
{
|
||||
using namespace mozilla::dmd;
|
||||
|
@ -1403,6 +1393,16 @@ replace_free(void* aPtr)
|
|||
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 {
|
||||
|
||||
|
|
|
@ -73,6 +73,115 @@ class LogAllocBridge : public ReplaceMallocBridge
|
|||
}
|
||||
};
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
@ -169,112 +278,3 @@ replace_init(malloc_table_t* aTable, ReplaceMallocBridge** aBridge)
|
|||
#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());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче