Skip to content

Commit

Permalink
rename sys allocator's sys_alloc symbol to tcmalloc_sys_alloc
Browse files Browse the repository at this point in the history
Since we're not building with hidden visibility, symbols of other DSOs
can interpose our symbols. And sys_alloc is just too generic name.

And in fact erlang runtime has sys_alloc function. Which means we're
trying to write to it's first bytes as part of initializing system
allocator and crash.

This should fix issue gperftools#843.
  • Loading branch information
alk committed Feb 20, 2017
1 parent 069e3b1 commit bf640cd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/system-alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static size_t pagesize = 0;
#endif

// The current system allocator
SysAllocator* sys_alloc = NULL;
SysAllocator* tcmalloc_sys_alloc = NULL;

// Number of bytes taken from system.
size_t TCMalloc_SystemTaken = 0;
Expand Down Expand Up @@ -484,7 +484,7 @@ void InitSystemAllocators(void) {
sdef->SetChildAllocator(mmap, 1, mmap_name);
}

sys_alloc = tc_get_sysalloc_override(sdef);
tcmalloc_sys_alloc = tc_get_sysalloc_override(sdef);
}

void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
Expand All @@ -507,7 +507,7 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
actual_size = &actual_size_storage;
}

void* result = sys_alloc->Alloc(size, actual_size, alignment);
void* result = tcmalloc_sys_alloc->Alloc(size, actual_size, alignment);
if (result != NULL) {
CHECK_CONDITION(
CheckAddressBits<kAddressBits>(
Expand Down
2 changes: 1 addition & 1 deletion src/system-alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extern PERFTOOLS_DLL_DECL
void TCMalloc_SystemCommit(void* start, size_t length);

// The current system allocator.
extern PERFTOOLS_DLL_DECL SysAllocator* sys_alloc;
extern PERFTOOLS_DLL_DECL SysAllocator* tcmalloc_sys_alloc;

// Number of bytes taken from system.
extern PERFTOOLS_DLL_DECL size_t TCMalloc_SystemTaken;
Expand Down
4 changes: 2 additions & 2 deletions src/tcmalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,12 @@ class TCMallocImplementation : public MallocExtension {

virtual SysAllocator* GetSystemAllocator() {
SpinLockHolder h(Static::pageheap_lock());
return sys_alloc;
return tcmalloc_sys_alloc;
}

virtual void SetSystemAllocator(SysAllocator* alloc) {
SpinLockHolder h(Static::pageheap_lock());
sys_alloc = alloc;
tcmalloc_sys_alloc = alloc;
}

virtual void ReleaseToSystem(size_t num_bytes) {
Expand Down
6 changes: 3 additions & 3 deletions src/windows/system-alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);

// The current system allocator declaration
SysAllocator* sys_alloc = NULL;
SysAllocator* tcmalloc_sys_alloc = NULL;
// Number of bytes taken from system.
size_t TCMalloc_SystemTaken = 0;

Expand Down Expand Up @@ -121,7 +121,7 @@ SysAllocator* tc_get_sysalloc_override(SysAllocator *def)
static bool system_alloc_inited = false;
void InitSystemAllocators(void) {
VirtualSysAllocator *alloc = new (virtual_space) VirtualSysAllocator();
sys_alloc = tc_get_sysalloc_override(alloc);
tcmalloc_sys_alloc = tc_get_sysalloc_override(alloc);
}

extern PERFTOOLS_DLL_DECL
Expand All @@ -134,7 +134,7 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
system_alloc_inited = true;
}

void* result = sys_alloc->Alloc(size, actual_size, alignment);
void* result = tcmalloc_sys_alloc->Alloc(size, actual_size, alignment);
if (result != NULL) {
if (actual_size) {
TCMalloc_SystemTaken += *actual_size;
Expand Down

0 comments on commit bf640cd

Please sign in to comment.