1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:47:45 +00:00

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.
This commit is contained in:
Andreas Kling 2019-04-30 01:22:18 +02:00
parent 87c256a7d5
commit 98a0e10319

View file

@ -36,11 +36,15 @@ static byte* s_malloc_pool;
static uint32_t s_malloc_sum_alloc = 0; static uint32_t s_malloc_sum_alloc = 0;
static uint32_t s_malloc_sum_free = POOL_SIZE; 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_malloc = true;
static bool s_scrub_free = true; static bool s_scrub_free = true;
void* malloc(size_t size) void* malloc(size_t size)
{ {
if (s_log_malloc)
dbgprintf("LibC: malloc(%u)\n", size);
if (size == 0) if (size == 0)
return nullptr; return nullptr;
@ -154,11 +158,12 @@ void __malloc_init()
if (rc < 0) if (rc < 0)
perror("set_mmap_name failed"); perror("set_mmap_name failed");
if (auto* scrub_malloc_env = getenv("LIBC_NOSCRUB_MALLOC")) if (getenv("LIBC_NOSCRUB_MALLOC"))
s_scrub_malloc = false; s_scrub_malloc = false;
if (auto* scrub_free_env = getenv("LIBC_NOSCRUB_FREE")) if (getenv("LIBC_NOSCRUB_FREE"))
s_scrub_free = false; s_scrub_free = false;
if (getenv("LIBC_LOG_MALLOC"))
s_log_malloc = true;
} }
void* calloc(size_t count, size_t size) void* calloc(size_t count, size_t size)