1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

UserspaceEmulator+LibC: Use sys$emuctl() to pass malloc info to UE

Get rid of the awkward secret handshake sequence between malloc and UE
and simply use sys$emuctl() to notify UE of malloc, free and realloc.
This commit is contained in:
Andreas Kling 2021-03-09 08:56:35 +01:00
parent 4faeaf101c
commit 9588f01739
8 changed files with 44 additions and 90 deletions

View file

@ -47,21 +47,6 @@
#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);
}
ALWAYS_INLINE static void ue_notify_realloc(const void* ptr, size_t size)
{
send_secret_data_to_userspace_emulator(3, size, (FlatPtr)ptr);
}
static LibThread::Lock& malloc_lock()
{
static u32 lock_storage[sizeof(LibThread::Lock) / sizeof(u32)];
@ -77,6 +62,24 @@ static bool s_scrub_free = true;
static bool s_profiling = false;
static bool s_in_userspace_emulator = false;
ALWAYS_INLINE static void ue_notify_malloc(const void* ptr, size_t size)
{
if (s_in_userspace_emulator)
syscall(SC_emuctl, 1, size, (FlatPtr)ptr);
}
ALWAYS_INLINE static void ue_notify_free(const void* ptr)
{
if (s_in_userspace_emulator)
syscall(SC_emuctl, 2, (FlatPtr)ptr, 0);
}
ALWAYS_INLINE static void ue_notify_realloc(const void* ptr, size_t size)
{
if (s_in_userspace_emulator)
syscall(SC_emuctl, 3, size, (FlatPtr)ptr);
}
struct MallocStats {
size_t number_of_malloc_calls;
@ -427,10 +430,7 @@ void __malloc_init()
{
new (&malloc_lock()) LibThread::Lock();
#ifdef __serenity__
s_in_userspace_emulator = syscall(SC_emuctl) != ENOSYS;
#endif
s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
if (s_in_userspace_emulator) {
// Don't bother scrubbing memory if we're running in UE since it
// keeps track of heap memory anyway.