block_of_code: Hide NX support behind compiler flag
Systems that require W^X can use the DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT cmake option.
This commit is contained in:
parent
de4494ffa5
commit
d5b9c4a4bb
3 changed files with 13 additions and 1 deletions
|
@ -10,9 +10,10 @@ endif()
|
||||||
|
|
||||||
# Dynarmic project options
|
# Dynarmic project options
|
||||||
option(DYNARMIC_ENABLE_CPU_FEATURE_DETECTION "Turning this off causes dynarmic to assume the host CPU doesn't support anything later than SSE3" ON)
|
option(DYNARMIC_ENABLE_CPU_FEATURE_DETECTION "Turning this off causes dynarmic to assume the host CPU doesn't support anything later than SSE3" ON)
|
||||||
option(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF)
|
option(DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT "Enables support for systems that require W^X" OFF)
|
||||||
option(DYNARMIC_TESTS "Build tests" ${MASTER_PROJECT})
|
option(DYNARMIC_TESTS "Build tests" ${MASTER_PROJECT})
|
||||||
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
|
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
|
||||||
|
option(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF)
|
||||||
option(DYNARMIC_WARNINGS_AS_ERRORS "Warnings as errors" ${MASTER_PROJECT})
|
option(DYNARMIC_WARNINGS_AS_ERRORS "Warnings as errors" ${MASTER_PROJECT})
|
||||||
|
|
||||||
# Default to a Release build
|
# Default to a Release build
|
||||||
|
|
|
@ -277,6 +277,9 @@ target_link_libraries(dynarmic
|
||||||
if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION)
|
if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION)
|
||||||
target_compile_definitions(dynarmic PRIVATE DYNARMIC_ENABLE_CPU_FEATURE_DETECTION=1)
|
target_compile_definitions(dynarmic PRIVATE DYNARMIC_ENABLE_CPU_FEATURE_DETECTION=1)
|
||||||
endif()
|
endif()
|
||||||
|
if (DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT)
|
||||||
|
target_compile_definitions(dynarmic PRIVATE DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT=1)
|
||||||
|
endif()
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
target_compile_definitions(dynarmic PRIVATE FMT_USE_WINDOWS_H=0)
|
target_compile_definitions(dynarmic PRIVATE FMT_USE_WINDOWS_H=0)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -51,12 +51,15 @@ constexpr size_t CONSTANT_POOL_SIZE = 2 * 1024 * 1024;
|
||||||
|
|
||||||
class CustomXbyakAllocator : public Xbyak::Allocator {
|
class CustomXbyakAllocator : public Xbyak::Allocator {
|
||||||
public:
|
public:
|
||||||
|
#ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT
|
||||||
bool useProtect() const override { return false; }
|
bool useProtect() const override { return false; }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is threadsafe as Xbyak::Allocator does not contain any state; it is a pure interface.
|
// This is threadsafe as Xbyak::Allocator does not contain any state; it is a pure interface.
|
||||||
CustomXbyakAllocator s_allocator;
|
CustomXbyakAllocator s_allocator;
|
||||||
|
|
||||||
|
#ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT
|
||||||
void ProtectMemory(const void* base, size_t size, bool is_executable) {
|
void ProtectMemory(const void* base, size_t size, bool is_executable) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD oldProtect = 0;
|
DWORD oldProtect = 0;
|
||||||
|
@ -69,6 +72,7 @@ void ProtectMemory(const void* base, size_t size, bool is_executable) {
|
||||||
mprotect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), mode);
|
mprotect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), mode);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
@ -92,11 +96,15 @@ void BlockOfCode::PreludeComplete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockOfCode::EnableWriting() {
|
void BlockOfCode::EnableWriting() {
|
||||||
|
#ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT
|
||||||
ProtectMemory(getCode(), maxSize_, false);
|
ProtectMemory(getCode(), maxSize_, false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockOfCode::DisableWriting() {
|
void BlockOfCode::DisableWriting() {
|
||||||
|
#ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT
|
||||||
ProtectMemory(getCode(), maxSize_, true);
|
ProtectMemory(getCode(), maxSize_, true);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockOfCode::ClearCache() {
|
void BlockOfCode::ClearCache() {
|
||||||
|
|
Loading…
Reference in a new issue