summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-16 20:25:51 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-16 20:46:44 +0200
commit869a3e2cf3d24d0bac88a4b7647664c9a87472f7 (patch)
tree358f8b119f81f61e61c34b5342330b03c512d1b2
parentf591157eb8759c38e3e013921a5484c223bd3427 (diff)
downloadserenity-869a3e2cf3d24d0bac88a4b7647664c9a87472f7.zip
LibC: Notify UserspaceEmulator about BigAllocationBlock mallocs
We were forgetting to inform UE about these, which caused it to believe subsequent calls to free() were invalid.
-rw-r--r--Libraries/LibC/malloc.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp
index 2a7523de62..09b90ce081 100644
--- a/Libraries/LibC/malloc.cpp
+++ b/Libraries/LibC/malloc.cpp
@@ -46,6 +46,16 @@
#define MAGIC_BIGALLOC_HEADER 0x42697267
#define PAGE_ROUND_UP(x) ((((size_t)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
+ALWAYS_INLINE static void ue_notify_malloc(const void* ptr, size_t size)
+{
+ send_secret_data_to_userspace_emulator(1, size, (FlatPtr)ptr);
+}
+
+ALWAYS_INLINE static void ue_notify_free(const void* ptr)
+{
+ send_secret_data_to_userspace_emulator(2, (FlatPtr)ptr, 0);
+}
+
static LibThread::Lock& malloc_lock()
{
static u32 lock_storage[sizeof(LibThread::Lock) / sizeof(u32)];
@@ -225,12 +235,15 @@ static void* malloc_impl(size_t size)
}
if (this_block_was_purged)
new (block) BigAllocationBlock(real_size);
+
+ ue_notify_malloc(&block->m_slot[0], size);
return &block->m_slot[0];
}
}
#endif
auto* block = (BigAllocationBlock*)os_alloc(real_size, "malloc: BigAllocationBlock");
new (block) BigAllocationBlock(real_size);
+ ue_notify_malloc(&block->m_slot[0], size);
return &block->m_slot[0];
}
@@ -282,8 +295,7 @@ static void* malloc_impl(size_t size)
dbgprintf("LibC: allocated %p (chunk in block %p, size %zu)\n", ptr, block, block->bytes_per_chunk());
#endif
- // Tell UserspaceEmulator about this malloc()
- send_secret_data_to_userspace_emulator(1, size, reinterpret_cast<FlatPtr>(ptr));
+ ue_notify_malloc(ptr, size);
if (s_scrub_malloc)
memset(ptr, MALLOC_SCRUB_BYTE, block->m_size);
@@ -386,9 +398,7 @@ void free(void* ptr)
if (s_profiling)
perf_event(PERF_EVENT_FREE, reinterpret_cast<FlatPtr>(ptr), 0);
free_impl(ptr);
-
- // Tell UserspaceEmulator about this free()
- send_secret_data_to_userspace_emulator(2, reinterpret_cast<FlatPtr>(ptr), 0);
+ ue_notify_free(ptr);
}
void* calloc(size_t count, size_t size)