Merge "Remove gMallocLeakZygoteChild."
am: 30bcaae2b6
Change-Id: I7811d37ecaebde8d075ba0004903c5b7ce39c356
This commit is contained in:
commit
7ac684d2d2
11 changed files with 44 additions and 33 deletions
|
@ -60,9 +60,6 @@ void* (*volatile __malloc_hook)(size_t, const void*);
|
|||
void* (*volatile __realloc_hook)(void*, size_t, const void*);
|
||||
void (*volatile __free_hook)(void*, const void*);
|
||||
void* (*volatile __memalign_hook)(size_t, size_t, const void*);
|
||||
|
||||
// In a VM process, this is set to 1 after fork()ing out of zygote.
|
||||
int gMallocLeakZygoteChild = 0;
|
||||
// =============================================================================
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
@ -69,7 +69,7 @@ __END_DECLS
|
|||
|
||||
#endif
|
||||
|
||||
extern int gMallocLeakZygoteChild;
|
||||
extern bool gZygoteChild;
|
||||
|
||||
static inline const MallocDispatch* GetDispatchTable() {
|
||||
return atomic_load_explicit(&__libc_globals->current_dispatch_table, memory_order_acquire);
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
// write_malloc_leak_info: Writes the leak info data to a file.
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
|
@ -73,6 +74,8 @@
|
|||
// =============================================================================
|
||||
pthread_mutex_t gGlobalsMutateLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool gZygoteChild = false;
|
||||
|
||||
_Atomic bool gGlobalsMutating = false;
|
||||
// =============================================================================
|
||||
|
||||
|
@ -112,7 +115,7 @@ static constexpr char kDebugPropertyProgram[] = "libc.debug.malloc.program";
|
|||
static constexpr char kDebugEnvOptions[] = "LIBC_DEBUG_MALLOC_OPTIONS";
|
||||
|
||||
typedef void (*finalize_func_t)();
|
||||
typedef bool (*init_func_t)(const MallocDispatch*, int*, const char*);
|
||||
typedef bool (*init_func_t)(const MallocDispatch*, bool*, const char*);
|
||||
typedef void (*get_malloc_leak_info_func_t)(uint8_t**, size_t*, size_t*, size_t*, size_t*);
|
||||
typedef void (*free_malloc_leak_info_func_t)(uint8_t*);
|
||||
typedef bool (*write_malloc_leak_info_func_t)(FILE*);
|
||||
|
@ -329,7 +332,7 @@ void* LoadSharedLibrary(const char* shared_lib, const char* prefix, MallocDispat
|
|||
|
||||
bool FinishInstallHooks(libc_globals* globals, const char* options, const char* prefix) {
|
||||
init_func_t init_func = reinterpret_cast<init_func_t>(gFunctions[FUNC_INITIALIZE]);
|
||||
if (!init_func(&__libc_malloc_default_dispatch, &gMallocLeakZygoteChild, options)) {
|
||||
if (!init_func(&__libc_malloc_default_dispatch, &gZygoteChild, options)) {
|
||||
error_log("%s: failed to enable malloc %s", getprogname(), prefix);
|
||||
ClearGlobalFunctions();
|
||||
return false;
|
||||
|
@ -470,6 +473,14 @@ extern "C" ssize_t malloc_backtrace(void* pointer, uintptr_t* frames, size_t fra
|
|||
// Platform-internal mallopt variant.
|
||||
// =============================================================================
|
||||
extern "C" bool android_mallopt(int opcode, void* arg, size_t arg_size) {
|
||||
if (opcode == M_SET_ZYGOTE_CHILD) {
|
||||
if (arg != nullptr || arg_size != 0) {
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
gZygoteChild = true;
|
||||
return true;
|
||||
}
|
||||
if (opcode == M_SET_ALLOCATION_LIMIT_BYTES) {
|
||||
return LimitEnable(arg, arg_size);
|
||||
}
|
||||
|
|
|
@ -81,10 +81,10 @@ static _Atomic bool gHeapprofdInitHookInstalled = false;
|
|||
|
||||
// In a Zygote child process, this is set to true if profiling of this process
|
||||
// is allowed. Note that this is set at a later time than the global
|
||||
// gMallocLeakZygoteChild. The latter is set during the fork (while still in
|
||||
// gZygoteChild. The latter is set during the fork (while still in
|
||||
// zygote's SELinux domain). While this bit is set after the child is
|
||||
// specialized (and has transferred SELinux domains if applicable).
|
||||
static _Atomic bool gMallocZygoteChildProfileable = false;
|
||||
static _Atomic bool gZygoteChildProfileable = false;
|
||||
|
||||
extern "C" void* MallocInitHeapprofdHook(size_t);
|
||||
|
||||
|
@ -114,8 +114,8 @@ static constexpr MallocDispatch __heapprofd_init_dispatch
|
|||
|
||||
static void MaybeInstallInitHeapprofdHook(int) {
|
||||
// Zygote child processes must be marked profileable.
|
||||
if (gMallocLeakZygoteChild &&
|
||||
!atomic_load_explicit(&gMallocZygoteChildProfileable, memory_order_acquire)) {
|
||||
if (gZygoteChild &&
|
||||
!atomic_load_explicit(&gZygoteChildProfileable, memory_order_acquire)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ extern "C" void* MallocInitHeapprofdHook(size_t bytes) {
|
|||
|
||||
// Marks this process as a profileable zygote child.
|
||||
static bool HandleInitZygoteChildProfiling() {
|
||||
atomic_store_explicit(&gMallocZygoteChildProfileable, true, memory_order_release);
|
||||
atomic_store_explicit(&gZygoteChildProfileable, true, memory_order_release);
|
||||
|
||||
// Conditionally start "from startup" profiling.
|
||||
if (HeapprofdShouldLoad()) {
|
||||
|
|
|
@ -1483,7 +1483,6 @@ LIBC_Q { # introduced=Q
|
|||
|
||||
# Used by libandroid_runtime and libmedia
|
||||
android_mallopt; # apex
|
||||
gMallocLeakZygoteChild; # apex
|
||||
} LIBC_P;
|
||||
|
||||
LIBC_PRIVATE {
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
#include "OptionData.h"
|
||||
#include "UnwindBacktrace.h"
|
||||
|
||||
extern int* g_malloc_zygote_child;
|
||||
extern bool* g_zygote_child;
|
||||
|
||||
// Forward declarations.
|
||||
class Config;
|
||||
|
@ -89,7 +89,9 @@ struct PointerInfoType {
|
|||
size_t hash_index;
|
||||
size_t RealSize() const { return size & ~(1U << 31); }
|
||||
bool ZygoteChildAlloc() const { return size & (1U << 31); }
|
||||
static size_t GetEncodedSize(size_t size) { return GetEncodedSize(*g_malloc_zygote_child, size); }
|
||||
static size_t GetEncodedSize(size_t size) {
|
||||
return GetEncodedSize(*g_zygote_child, size);
|
||||
}
|
||||
static size_t GetEncodedSize(bool child_alloc, size_t size) {
|
||||
return size | ((child_alloc) ? (1U << 31) : 0);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
// ------------------------------------------------------------------------
|
||||
DebugData* g_debug;
|
||||
|
||||
int* g_malloc_zygote_child;
|
||||
bool* g_zygote_child;
|
||||
|
||||
const MallocDispatch* g_dispatch;
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -70,7 +70,7 @@ const MallocDispatch* g_dispatch;
|
|||
// ------------------------------------------------------------------------
|
||||
__BEGIN_DECLS
|
||||
|
||||
bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child,
|
||||
bool debug_initialize(const MallocDispatch* malloc_dispatch, bool* malloc_zygote_child,
|
||||
const char* options);
|
||||
void debug_finalize();
|
||||
void debug_dump_heap(const char* file_name);
|
||||
|
@ -225,15 +225,15 @@ static void* InitHeader(Header* header, void* orig_pointer, size_t size) {
|
|||
return g_debug->GetPointer(header);
|
||||
}
|
||||
|
||||
bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child,
|
||||
bool debug_initialize(const MallocDispatch* malloc_dispatch, bool* zygote_child,
|
||||
const char* options) {
|
||||
if (malloc_zygote_child == nullptr || options == nullptr) {
|
||||
if (zygote_child == nullptr || options == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InitAtfork();
|
||||
|
||||
g_malloc_zygote_child = malloc_zygote_child;
|
||||
g_zygote_child = zygote_child;
|
||||
|
||||
g_dispatch = malloc_dispatch;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
bool debug_initialize(const MallocDispatch*, int*, const char*);
|
||||
bool debug_initialize(const MallocDispatch*, bool*, const char*);
|
||||
void debug_finalize();
|
||||
|
||||
void* debug_malloc(size_t);
|
||||
|
@ -103,8 +103,8 @@ class MallocDebugTest : public ::testing::Test {
|
|||
}
|
||||
|
||||
void Init(const char* options) {
|
||||
zygote = 0;
|
||||
ASSERT_TRUE(debug_initialize(&dispatch, &zygote, options));
|
||||
zygote_child = false;
|
||||
ASSERT_TRUE(debug_initialize(&dispatch, &zygote_child, options));
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ class MallocDebugTest : public ::testing::Test {
|
|||
|
||||
bool initialized;
|
||||
|
||||
int zygote;
|
||||
bool zygote_child;
|
||||
|
||||
static MallocDispatch dispatch;
|
||||
};
|
||||
|
@ -1344,7 +1344,7 @@ void MallocDebugTest::BacktraceDumpOnSignal(bool trigger_with_alloc) {
|
|||
backtrace_fake_add(std::vector<uintptr_t> {0xa300, 0xb300});
|
||||
|
||||
std::vector<void*> pointers;
|
||||
zygote = 1;
|
||||
zygote_child = true;
|
||||
pointers.push_back(debug_malloc(100));
|
||||
ASSERT_TRUE(pointers.back() != nullptr);
|
||||
pointers.push_back(debug_malloc(40));
|
||||
|
@ -1352,7 +1352,7 @@ void MallocDebugTest::BacktraceDumpOnSignal(bool trigger_with_alloc) {
|
|||
pointers.push_back(debug_malloc(200));
|
||||
ASSERT_TRUE(pointers.back() != nullptr);
|
||||
|
||||
zygote = 0;
|
||||
zygote_child = false;
|
||||
pointers.push_back(debug_malloc(10));
|
||||
ASSERT_TRUE(pointers.back() != nullptr);
|
||||
pointers.push_back(debug_malloc(50));
|
||||
|
@ -1750,7 +1750,7 @@ TEST_F(MallocDebugTest, backtrace_same_stack_zygote) {
|
|||
backtrace_fake_add(std::vector<uintptr_t> {0xbc000, 0xecd00, 0x12000});
|
||||
backtrace_fake_add(std::vector<uintptr_t> {0xbc000});
|
||||
|
||||
zygote = 1;
|
||||
zygote_child = true;
|
||||
|
||||
void* pointers[4];
|
||||
pointers[0] = debug_malloc(100);
|
||||
|
@ -1809,14 +1809,14 @@ TEST_F(MallocDebugTest, backtrace_same_stack_mix_zygote) {
|
|||
backtrace_fake_add(std::vector<uintptr_t> {0xbc000, 0xecd00, 0x12000});
|
||||
backtrace_fake_add(std::vector<uintptr_t> {0xbc000});
|
||||
|
||||
zygote = 1;
|
||||
zygote_child = true;
|
||||
void* pointers[4];
|
||||
pointers[0] = debug_malloc(40);
|
||||
ASSERT_TRUE(pointers[0] != nullptr);
|
||||
pointers[1] = debug_malloc(40);
|
||||
ASSERT_TRUE(pointers[1] != nullptr);
|
||||
|
||||
zygote = 0;
|
||||
zygote_child = false;
|
||||
pointers[2] = debug_malloc(40);
|
||||
ASSERT_TRUE(pointers[2] != nullptr);
|
||||
pointers[3] = debug_malloc(100);
|
||||
|
@ -1989,7 +1989,7 @@ TEST_F(MallocDebugTest, zygote_set) {
|
|||
// Set all of the options.
|
||||
Init("guard fill backtrace leak_track free_track=2");
|
||||
|
||||
zygote = 1;
|
||||
zygote_child = true;
|
||||
|
||||
backtrace_fake_add(std::vector<uintptr_t> {0x1});
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ const MallocDispatch* g_dispatch;
|
|||
// ------------------------------------------------------------------------
|
||||
__BEGIN_DECLS
|
||||
|
||||
bool hooks_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child,
|
||||
bool hooks_initialize(const MallocDispatch* malloc_dispatch, bool* zygote_child,
|
||||
const char* options);
|
||||
void hooks_finalize();
|
||||
void hooks_get_malloc_leak_info(
|
||||
|
@ -97,7 +97,7 @@ static void* default_memalign_hook(size_t alignment, size_t bytes, const void*)
|
|||
__END_DECLS
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
bool hooks_initialize(const MallocDispatch* malloc_dispatch, int*, const char*) {
|
||||
bool hooks_initialize(const MallocDispatch* malloc_dispatch, bool*, const char*) {
|
||||
g_dispatch = malloc_dispatch;
|
||||
__malloc_hook = default_malloc_hook;
|
||||
__realloc_hook = default_realloc_hook;
|
||||
|
|
|
@ -45,6 +45,9 @@ enum {
|
|||
// arg_size = sizeof(size_t)
|
||||
M_SET_ALLOCATION_LIMIT_BYTES = 3,
|
||||
#define M_SET_ALLOCATION_LIMIT_BYTES M_SET_ALLOCATION_LIMIT_BYTES
|
||||
// Called after the zygote forks to indicate this is a child.
|
||||
M_SET_ZYGOTE_CHILD = 4,
|
||||
#define M_SET_ZYGOTE_CHILD M_SET_ZYGOTE_CHILD
|
||||
};
|
||||
|
||||
// Manipulates bionic-specific handling of memory allocation APIs such as
|
||||
|
|
|
@ -27,7 +27,7 @@ os_overcommits
|
|||
restartloop
|
||||
_ZL24gHeapprofdInitInProgress
|
||||
_ZL27gHeapprofdInitHookInstalled
|
||||
_ZL29gMallocZygoteChildProfileable
|
||||
_ZL23gZygoteChildProfileable
|
||||
_ZZ17__find_icu_symbolPKcE9found_icu
|
||||
ru_a
|
||||
ru_b
|
||||
|
@ -55,7 +55,6 @@ __free_hook
|
|||
g_atexit_lock
|
||||
gGlobalsMutateLock
|
||||
global_hashtable
|
||||
gMallocLeakZygoteChild
|
||||
gmtptr
|
||||
handlers
|
||||
je_background_thread_info
|
||||
|
|
Loading…
Reference in a new issue