mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-17 21:00:37 +02:00
Merge pull request #1182 from Sonicadvance1/disable_jemalloc_option
Adds an option to disable jemalloc from cmake
This commit is contained in:
4 files changed
+33
-17
No files matched your search
@@ -15,6 +15,7 @@ option(ENABLE_VISUAL_DEBUGGER "Enables the visual debugger for compiling" FALSE)
|
||||
option(ENABLE_STRICT_WERROR "Enables stricter -Werror for CI" FALSE)
|
||||
option(ENABLE_WERROR "Enables -Werror" FALSE)
|
||||
option(ENABLE_STATIC_PIE "Enables static-pie build" FALSE)
|
||||
option(ENABLE_JEMALLOC "Enables jemalloc allocator" TRUE)
|
||||
|
||||
set (X86_C_COMPILER "x86_64-linux-gnu-gcc" CACHE STRING "c compiler for compiling x86 guest libs")
|
||||
set (X86_CXX_COMPILER "x86_64-linux-gnu-g++" CACHE STRING "c++ compiler for compiling x86 guest libs")
|
||||
@@ -148,6 +149,16 @@ if (ENABLE_TSAN)
|
||||
link_libraries(-fno-omit-frame-pointer -fsanitize=thread)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JEMALLOC)
|
||||
add_definitions(-DENABLE_JEMALLOC=1)
|
||||
else()
|
||||
message (STATUS
|
||||
" jemalloc disabled!\n"
|
||||
" This is not a recommended configuration!\n"
|
||||
" This will very explicitly break 32-bit application execution!\n"
|
||||
" Use at your own risk!")
|
||||
endif()
|
||||
|
||||
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
|
||||
set (CMAKE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
|
||||
|
||||
|
||||
+14
-15
@@ -1,7 +1,9 @@
|
||||
#include "Utils/Allocator/HostAllocator.h"
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef ENABLE_JEMALLOC
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#endif
|
||||
#include <memory>
|
||||
#include <malloc.h>
|
||||
|
||||
@@ -11,16 +13,24 @@ extern "C" {
|
||||
int fd, off_t offset);
|
||||
typedef int (*munmap_hook_type)(void *addr, size_t length);
|
||||
|
||||
#ifdef ENABLE_JEMALLOC
|
||||
extern mmap_hook_type __mmap_hook;
|
||||
extern munmap_hook_type __munmap_hook;
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace FEXCore::Allocator {
|
||||
MMAP_Hook mmap {::mmap};
|
||||
MUNMAP_Hook munmap {::munmap};
|
||||
#ifdef ENABLE_JEMALLOC
|
||||
MALLOC_Hook malloc {::je_malloc};
|
||||
REALLOC_Hook realloc {::je_realloc};
|
||||
FREE_Hook free {::je_free};
|
||||
#else
|
||||
MALLOC_Hook malloc {::malloc};
|
||||
REALLOC_Hook realloc {::realloc};
|
||||
FREE_Hook free {::free};
|
||||
#endif
|
||||
|
||||
using GLIBC_MALLOC_Hook = void*(*)(size_t, const void *caller);
|
||||
using GLIBC_REALLOC_Hook = void*(*)(void*, size_t, const void *caller);
|
||||
@@ -46,37 +56,26 @@ namespace FEXCore::Allocator {
|
||||
return Result;
|
||||
}
|
||||
|
||||
void *FEX_malloc_hook(size_t size, const void *caller) {
|
||||
return ::je_malloc(size);
|
||||
}
|
||||
|
||||
void *FEX_realloc_hook(void *ptr, size_t size, const void *caller) {
|
||||
return ::je_realloc(ptr, size);
|
||||
}
|
||||
|
||||
void FEX_free_hook(void *ptr, const void *caller) {
|
||||
return ::je_free(ptr);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
void SetupHooks() {
|
||||
Alloc64 = Alloc::OSAllocator::Create64BitAllocator();
|
||||
#ifdef ENABLE_JEMALLOC
|
||||
__mmap_hook = FEX_mmap;
|
||||
__munmap_hook = FEX_munmap;
|
||||
#endif
|
||||
FEXCore::Allocator::mmap = FEX_mmap;
|
||||
FEXCore::Allocator::munmap = FEX_munmap;
|
||||
}
|
||||
|
||||
void ClearHooks() {
|
||||
#ifdef ENABLE_JEMALLOC
|
||||
__mmap_hook = ::mmap;
|
||||
__munmap_hook = ::munmap;
|
||||
#endif
|
||||
FEXCore::Allocator::mmap = ::mmap;
|
||||
FEXCore::Allocator::munmap = ::munmap;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
add_subdirectory(LinuxSyscalls)
|
||||
|
||||
set(LIBS FEX_jemalloc FEXCore Common CommonCore)
|
||||
if (ENABLE_JEMALLOC)
|
||||
set (LIBS FEX_jemalloc)
|
||||
endif()
|
||||
|
||||
list(APPEND LIBS FEXCore Common CommonCore)
|
||||
|
||||
add_executable(FEXLoader FEXLoader.cpp)
|
||||
target_include_directories(FEXLoader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
|
||||
@@ -322,7 +322,9 @@ int main(int argc, char **argv, char **const envp) {
|
||||
|
||||
#if !(defined(ENABLE_ASAN) && ENABLE_ASAN)
|
||||
// LLVM ASAN maps things to the lower 32bits
|
||||
if (!CheckMemMapping()) {
|
||||
// Valgrind also places us in the lower 32-bits
|
||||
if (!getenv("VALGRIND_LAUNCHER") &&
|
||||
!CheckMemMapping()) {
|
||||
LogMan::Msg::E("[Unsupported] FEX mapped to lower 32bits! Exiting!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user