1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

LibC: Add mmap_with_name() that names the allocation immediately.

This allows us to skip the separate call to set_mmap_name() in code that
we control, e.g malloc() and GraphicsBitmap.
This commit is contained in:
Andreas Kling 2019-05-19 15:54:56 +02:00
parent 5f26f83451
commit 189b342e6f
8 changed files with 28 additions and 13 deletions

View file

@ -123,9 +123,9 @@ size_t malloc_good_size(size_t size)
return PAGE_ROUND_UP(size);
}
static void* os_alloc(size_t size)
static void* os_alloc(size_t size, const char* name)
{
return mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
return mmap_with_name(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0, name);
}
static void os_free(void* ptr, size_t size)
@ -155,10 +155,9 @@ void* malloc(size_t size)
}
}
#endif
auto* block = (BigAllocationBlock*)os_alloc(real_size);
char buffer[64];
snprintf(buffer, sizeof(buffer), "malloc: BigAllocationBlock(%u)", real_size);
set_mmap_name(block, PAGE_SIZE, buffer);
auto* block = (BigAllocationBlock*)os_alloc(real_size, buffer);
new (block) BigAllocationBlock(real_size);
return &block->m_slot[0];
}
@ -171,10 +170,9 @@ void* malloc(size_t size)
}
if (!block) {
block = (ChunkedBlock*)os_alloc(PAGE_SIZE);
char buffer[64];
snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%u)", good_size);
set_mmap_name(block, PAGE_SIZE, buffer);
block = (ChunkedBlock*)os_alloc(PAGE_SIZE, buffer);
new (block) ChunkedBlock(good_size);
allocator->usable_blocks.append(block);
++allocator->block_count;