From 98a0e10319b525f201d10677256bead849c4ab7e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 30 Apr 2019 01:22:18 +0200 Subject: [PATCH] LibC: Log all malloc() calls if LIBC_LOG_MALLOC is set. This makes it easier to quickly determine if a userspace process is getting bogged down in memory allocation. --- LibC/stdlib.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index a4f8fa5526..656bd91ca7 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -36,11 +36,15 @@ static byte* s_malloc_pool; static uint32_t s_malloc_sum_alloc = 0; static uint32_t s_malloc_sum_free = POOL_SIZE; +static bool s_log_malloc = false; static bool s_scrub_malloc = true; static bool s_scrub_free = true; void* malloc(size_t size) { + if (s_log_malloc) + dbgprintf("LibC: malloc(%u)\n", size); + if (size == 0) return nullptr; @@ -154,11 +158,12 @@ void __malloc_init() if (rc < 0) perror("set_mmap_name failed"); - if (auto* scrub_malloc_env = getenv("LIBC_NOSCRUB_MALLOC")) + if (getenv("LIBC_NOSCRUB_MALLOC")) s_scrub_malloc = false; - if (auto* scrub_free_env = getenv("LIBC_NOSCRUB_FREE")) + if (getenv("LIBC_NOSCRUB_FREE")) s_scrub_free = false; - + if (getenv("LIBC_LOG_MALLOC")) + s_log_malloc = true; } void* calloc(size_t count, size_t size)