diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-15 21:54:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-15 23:25:20 +0200 |
commit | 4aa81a4fd9351248d9c3fc1d91b5907f0dd1cbb3 (patch) | |
tree | f5224e43dd94162ae3c92cd019392d119404b3e3 /Libraries/LibC | |
parent | c3142923191ead8633f33969e118871d85d19ad9 (diff) | |
download | serenity-4aa81a4fd9351248d9c3fc1d91b5907f0dd1cbb3.zip |
LibC: Communicate malloc() and free() operations to UserspaceEmulator
Use the sneaky SALC secret mechanism of UserspaceEmulator to inform it
about malloc operations.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/malloc.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibC/serenity.h | 17 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp index c271f491f5..2a7523de62 100644 --- a/Libraries/LibC/malloc.cpp +++ b/Libraries/LibC/malloc.cpp @@ -281,6 +281,10 @@ static void* malloc_impl(size_t size) #ifdef MALLOC_DEBUG 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)); + if (s_scrub_malloc) memset(ptr, MALLOC_SCRUB_BYTE, block->m_size); return ptr; @@ -382,6 +386,9 @@ 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); } void* calloc(size_t count, size_t size) diff --git a/Libraries/LibC/serenity.h b/Libraries/LibC/serenity.h index cf9615a27e..6ed6bba428 100644 --- a/Libraries/LibC/serenity.h +++ b/Libraries/LibC/serenity.h @@ -70,4 +70,21 @@ int perf_event(int type, uintptr_t arg1, uintptr_t arg2); int get_stack_bounds(uintptr_t* user_stack_base, size_t* user_stack_size); +ALWAYS_INLINE void send_secret_data_to_userspace_emulator(uintptr_t data1, uintptr_t data2, uintptr_t data3) +{ + asm volatile( + ".byte 0xd6\n" + ".byte 0xd6\n" :: + : "eax"); + asm volatile( + "push %%eax\n" + "push %%ecx\n" + "push %%edx\n" + "pop %%edx\n" + "pop %%ecx\n" + "pop %%eax\n" ::"a"(data1), + "c"(data2), "d"(data3) + : "memory"); +} + __END_DECLS |