From a7334608faeaf8a8913502f2e6cf55d1add285db Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 15 Mar 2023 12:55:04 -0700 Subject: [PATCH] fextl: Move allocator hooks to its own header --- .../FEXCore/include/FEXCore/Utils/Allocator.h | 33 +++---------------- .../include/FEXCore/Utils/AllocatorHooks.h | 33 +++++++++++++++++++ .../FEXCore/include/FEXCore/fextl/allocator.h | 4 ++- 3 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h diff --git a/External/FEXCore/include/FEXCore/Utils/Allocator.h b/External/FEXCore/include/FEXCore/Utils/Allocator.h index 979514992..426f222fd 100644 --- a/External/FEXCore/include/FEXCore/Utils/Allocator.h +++ b/External/FEXCore/include/FEXCore/Utils/Allocator.h @@ -1,38 +1,13 @@ #pragma once #include +#include #include #include #include -#include namespace FEXCore::Allocator { - using MMAP_Hook = void*(*)(void*, size_t, int, int, int, off_t); - using MUNMAP_Hook = int(*)(void*, size_t); - - using MALLOC_Hook = void *(*)(size_t); - using CALLOC_Hook = void *(*)(size_t, size_t); - using MEMALIGN_Hook = void *(*)(size_t, size_t); - using VALLOC_Hook = void *(*)(size_t); - using POSIX_MEMALIGN_Hook = int (*)(void**, size_t, size_t); - using REALLOC_Hook = void *(*)(void*, size_t); - using FREE_Hook = void(*)(void*); - using MALLOC_USABLE_SIZE_Hook = size_t (*)(void*); - using ALIGNED_ALLOC_Hook = void *(*)(size_t, size_t); - - FEX_DEFAULT_VISIBILITY extern MMAP_Hook mmap; - FEX_DEFAULT_VISIBILITY extern MUNMAP_Hook munmap; - FEX_DEFAULT_VISIBILITY extern MALLOC_Hook malloc; - FEX_DEFAULT_VISIBILITY extern CALLOC_Hook calloc; - FEX_DEFAULT_VISIBILITY extern MEMALIGN_Hook memalign; - FEX_DEFAULT_VISIBILITY extern VALLOC_Hook valloc; - FEX_DEFAULT_VISIBILITY extern POSIX_MEMALIGN_Hook posix_memalign; - FEX_DEFAULT_VISIBILITY extern REALLOC_Hook realloc; - FEX_DEFAULT_VISIBILITY extern FREE_Hook free; - FEX_DEFAULT_VISIBILITY extern MALLOC_USABLE_SIZE_Hook malloc_usable_size; - FEX_DEFAULT_VISIBILITY extern ALIGNED_ALLOC_Hook aligned_alloc; - FEX_DEFAULT_VISIBILITY void SetupHooks(); FEX_DEFAULT_VISIBILITY void ClearHooks(); @@ -43,13 +18,13 @@ namespace FEXCore::Allocator { size_t Size; }; - FEX_DEFAULT_VISIBILITY std::vector StealMemoryRegion(uintptr_t Begin, uintptr_t End); - FEX_DEFAULT_VISIBILITY void ReclaimMemoryRegion(const std::vector & Regions); + FEX_DEFAULT_VISIBILITY fextl::vector StealMemoryRegion(uintptr_t Begin, uintptr_t End); + FEX_DEFAULT_VISIBILITY void ReclaimMemoryRegion(const fextl::vector & Regions); // When running a 64-bit executable on ARM then userspace guest only gets 47 bits of VA // This is a feature of x86-64 where the kernel gets a full 128TB of VA space // x86-64 canonical addresses with bit 48 set will sign extend the address (Ignoring LA57) // AArch64 canonical addresses are only up to bits 48/52 with the remainder being other things // Use this to reserve the top 128TB of VA so the guest never see it // Returns nullptr on host VA < 48bits - FEX_DEFAULT_VISIBILITY std::vector Steal48BitVA(); + FEX_DEFAULT_VISIBILITY fextl::vector Steal48BitVA(); } diff --git a/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h b/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h new file mode 100644 index 000000000..57a2baeff --- /dev/null +++ b/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h @@ -0,0 +1,33 @@ +#pragma once +#include + +#include +#include +#include + +namespace FEXCore::Allocator { + using MMAP_Hook = void*(*)(void*, size_t, int, int, int, off_t); + using MUNMAP_Hook = int(*)(void*, size_t); + + using MALLOC_Hook = void *(*)(size_t); + using CALLOC_Hook = void *(*)(size_t, size_t); + using MEMALIGN_Hook = void *(*)(size_t, size_t); + using VALLOC_Hook = void *(*)(size_t); + using POSIX_MEMALIGN_Hook = int (*)(void**, size_t, size_t); + using REALLOC_Hook = void *(*)(void*, size_t); + using FREE_Hook = void(*)(void*); + using MALLOC_USABLE_SIZE_Hook = size_t (*)(void*); + using ALIGNED_ALLOC_Hook = void *(*)(size_t, size_t); + + FEX_DEFAULT_VISIBILITY extern MMAP_Hook mmap; + FEX_DEFAULT_VISIBILITY extern MUNMAP_Hook munmap; + FEX_DEFAULT_VISIBILITY extern MALLOC_Hook malloc; + FEX_DEFAULT_VISIBILITY extern CALLOC_Hook calloc; + FEX_DEFAULT_VISIBILITY extern MEMALIGN_Hook memalign; + FEX_DEFAULT_VISIBILITY extern VALLOC_Hook valloc; + FEX_DEFAULT_VISIBILITY extern POSIX_MEMALIGN_Hook posix_memalign; + FEX_DEFAULT_VISIBILITY extern REALLOC_Hook realloc; + FEX_DEFAULT_VISIBILITY extern FREE_Hook free; + FEX_DEFAULT_VISIBILITY extern MALLOC_USABLE_SIZE_Hook malloc_usable_size; + FEX_DEFAULT_VISIBILITY extern ALIGNED_ALLOC_Hook aligned_alloc; +} diff --git a/External/FEXCore/include/FEXCore/fextl/allocator.h b/External/FEXCore/include/FEXCore/fextl/allocator.h index 710adc66a..830c7905e 100644 --- a/External/FEXCore/include/FEXCore/fextl/allocator.h +++ b/External/FEXCore/include/FEXCore/fextl/allocator.h @@ -1,5 +1,7 @@ #pragma once -#include +#include + +#include namespace fextl { /**