diff options
Diffstat (limited to 'libc/malloc_debug')
-rw-r--r-- | libc/malloc_debug/PointerData.h | 6 | ||||
-rw-r--r-- | libc/malloc_debug/malloc_debug.cpp | 10 | ||||
-rw-r--r-- | libc/malloc_debug/tests/malloc_debug_unit_tests.cpp | 20 |
3 files changed, 19 insertions, 17 deletions
diff --git a/libc/malloc_debug/PointerData.h b/libc/malloc_debug/PointerData.h index 24ca7482a..c7958f369 100644 --- a/libc/malloc_debug/PointerData.h +++ b/libc/malloc_debug/PointerData.h @@ -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); } diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index 114579626..91e1d2610 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -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; diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp index f611f3da7..0238d1049 100644 --- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp +++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp @@ -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}); |