From 319c5bf02356a698ed25ae11893f16794b6f0842 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 7 Sep 2026 15:13:14 -0700 Subject: [PATCH 1/2] Externals/rpmalloc: Update --- External/rpmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/rpmalloc b/External/rpmalloc index 1d85c246c..09142d726 160000 --- a/External/rpmalloc +++ b/External/rpmalloc @@ -1 +1 @@ -Subproject commit 1d85c246cd827ead6865f4f880d4fef53f2b1864 +Subproject commit 09142d726429416bfa7b459151515fe3ab7622dd From 021c4fa4bf74de108a9db9fc28d75bcd0edadb74 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 7 Sep 2026 15:13:33 -0700 Subject: [PATCH 2/2] FEXCore/Allocator: Support naming VMA regions from rpmalloc This allows WTF to catch the allocations just like on Linux. Punch our unixlib path all the way through to rpmalloc so it gets named and tracked properly. --- FEXCore/Source/CMakeLists.txt | 1 + FEXCore/Source/Interface/IR/IRDumper.cpp | 4 ---- FEXCore/Source/Utils/Allocator.cpp | 1 + FEXCore/Source/Utils/AllocatorHooks.cpp | 23 +++++++++++++++++++ .../include/FEXCore/Utils/AllocatorHooks.h | 2 ++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/FEXCore/Source/CMakeLists.txt b/FEXCore/Source/CMakeLists.txt index 7db99c5a7..d292e5ca7 100644 --- a/FEXCore/Source/CMakeLists.txt +++ b/FEXCore/Source/CMakeLists.txt @@ -303,6 +303,7 @@ add_library(JemallocLibs STATIC Utils/AllocatorHooks.cpp) if (ENABLE_FEX_ALLOCATOR) target_compile_definitions(JemallocLibs PRIVATE ENABLE_FEX_ALLOCATOR=1) target_link_libraries(JemallocLibs PUBLIC rpmalloc) + target_include_directories(JemallocLibs PRIVATE "${PROJECT_SOURCE_DIR}/include/") endif() if (ENABLE_JEMALLOC_GLIBC_ALLOC) set_source_files_properties(Interface/HLE/Thunks/Thunks.cpp PROPERTIES COMPILE_DEFINITIONS ENABLE_JEMALLOC_GLIBC=1) diff --git a/FEXCore/Source/Interface/IR/IRDumper.cpp b/FEXCore/Source/Interface/IR/IRDumper.cpp index d8a7a0d9e..32f49daaf 100644 --- a/FEXCore/Source/Interface/IR/IRDumper.cpp +++ b/FEXCore/Source/Interface/IR/IRDumper.cpp @@ -348,10 +348,6 @@ static void PrintArg(fextl::ostringstream* out, const IRListView*, BranchHint Ar }(); } -static void PrintArg(fextl::ostringstream* out, const IRListView*, const std::array& Arg) { - *out << fextl::fmt::format("{:02x}", fmt::join(Arg, "")); -} - void Dump(fextl::ostringstream* out, const IRListView* IR) { auto HeaderOp = IR->GetHeader(); diff --git a/FEXCore/Source/Utils/Allocator.cpp b/FEXCore/Source/Utils/Allocator.cpp index 2060f269c..3a779abaf 100644 --- a/FEXCore/Source/Utils/Allocator.cpp +++ b/FEXCore/Source/Utils/Allocator.cpp @@ -317,6 +317,7 @@ VirtualTHPPtr VirtualTHPControl {VirtualTHPNOP}; void SetupHooks(size_t PageSize, HookPtrs Ptrs) { VirtualName = Ptrs.VirtualName; VirtualTHPControl = Ptrs.VirtualTHPControl; + SetupAllocatorHooks(VirtualName); } #endif diff --git a/FEXCore/Source/Utils/AllocatorHooks.cpp b/FEXCore/Source/Utils/AllocatorHooks.cpp index fd6947fdf..e85f09a09 100644 --- a/FEXCore/Source/Utils/AllocatorHooks.cpp +++ b/FEXCore/Source/Utils/AllocatorHooks.cpp @@ -1,4 +1,6 @@ // SPDX-License-Identifier: MIT +#include + #ifdef ENABLE_FEX_ALLOCATOR #include #ifndef _WIN32 @@ -20,16 +22,32 @@ namespace FEXCore::Allocator { using mmap_hook_type = void* (*)(void* addr, size_t length, int prot, int flags, int fd, off_t offset); using munmap_hook_type = int (*)(void* addr, size_t length); +using vma_name_hook_type = void (*)(const char* name, const void* address, size_t size); #ifdef ENABLE_FEX_ALLOCATOR typedef void* (*rp_mmap_hook_type)(size_t size, size_t alignment, size_t* offset, size_t* mapped_size); typedef void (*rp_munmap_hook_type)(void* address, size_t offset, size_t mapped_size); +typedef void (*vma_name_hook_type)(const char* name, const void* address, size_t size); extern "C" rp_mmap_hook_type rp_mmap_hook; extern "C" rp_munmap_hook_type rp_munmap_hook; +extern "C" vma_name_hook_type rp_name_hook; #ifndef _WIN32 mmap_hook_type fex_mmap_hook = ::mmap; munmap_hook_type fex_munmap_hook = ::munmap; + +static inline void LocalVirtualName(const char* Name, const void* Ptr, size_t Size) { +#ifndef _WIN32 + static bool Supports {true}; + if (Supports) { + auto Result = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, Ptr, Size, Name); + if (Result == -1) { + // Disable any additional attempts. + Supports = false; + } + } +#endif +} #endif // Assume a 64KB page size until told otherwise. @@ -172,6 +190,11 @@ void InitializeAllocator(size_t PageSize) { rpmalloc_initialize_config(&global_interface, &global_config); rp_mmap_hook = FEX_rp_mmap; rp_munmap_hook = FEX_rp_memory_unmap; + rp_name_hook = LocalVirtualName; +} +#else +void SetupAllocatorHooks(vma_name_hook_type NameHook) { + rp_name_hook = NameHook; } #endif diff --git a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h index cccce4d56..c4cadf40a 100644 --- a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h +++ b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h @@ -166,6 +166,8 @@ FEX_DEFAULT_VISIBILITY extern void InitializeThread(); #ifndef _WIN32 void SetupAllocatorHooks(void* (*)(void* addr, size_t length, int prot, int flags, int fd, off_t offset), int (*)(void* addr, size_t length)); +#else +void SetupAllocatorHooks(void (*)(const char* name, const void* address, size_t size)); #endif struct FEXAllocOperators {