Merge "[malloc dispatch] Install dispatch over the top of GWP-ASan."

This commit is contained in:
Treehugger Robot 2020-02-12 03:23:21 +00:00 committed by Gerrit Code Review
commit 18b2891cd2
4 changed files with 11 additions and 2 deletions

View file

@ -344,7 +344,7 @@ bool FinishInstallHooks(libc_globals* globals, const char* options, const char*
// Do a pointer swap so that all of the functions become valid at once to
// avoid any initialization order problems.
atomic_store(&globals->default_dispatch_table, &globals->malloc_dispatch_table);
if (GetDispatchTable() == nullptr) {
if (!MallocLimitInstalled()) {
atomic_store(&globals->current_dispatch_table, &globals->malloc_dispatch_table);
}

View file

@ -45,6 +45,7 @@
#include "malloc_common.h"
#include "malloc_common_dynamic.h"
#include "malloc_heapprofd.h"
#include "malloc_limit.h"
static constexpr char kHeapprofdSharedLib[] = "heapprofd_client.so";
static constexpr char kHeapprofdPrefix[] = "heapprofd";
@ -189,7 +190,7 @@ void HandleHeapprofdSignal() {
__libc_globals.mutate([](libc_globals* globals) {
atomic_store(&globals->default_dispatch_table, &__heapprofd_init_dispatch);
auto dispatch_table = GetDispatchTable();
if (dispatch_table == nullptr || dispatch_table == &globals->malloc_dispatch_table) {
if (!MallocLimitInstalled() || dispatch_table == &globals->malloc_dispatch_table) {
atomic_store(&globals->current_dispatch_table, &__heapprofd_init_dispatch);
}
});

View file

@ -253,6 +253,10 @@ static void* LimitValloc(size_t bytes) {
}
#endif
bool MallocLimitInstalled() {
return GetDispatchTable() == &__limit_dispatch;
}
#if defined(LIBC_STATIC)
static bool EnableLimitDispatchTable() {
// This is the only valid way to modify the dispatch tables for a

View file

@ -32,3 +32,7 @@
// Function prototypes.
bool LimitEnable(void* arg, size_t arg_size);
// Returns true if malloc_limit is installed (by checking the current dispatch
// table).
bool MallocLimitInstalled();