mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 09:00:17 +02:00
TestHarnessRunner: Get running on Win32
This commit is contained in:
1 parent
4cb385a27b
commit
d75fb38344
4 files changed
+250
-164
No files matched your search
@@ -1,5 +1,6 @@
|
||||
add_subdirectory(Common/)
|
||||
add_subdirectory(Tools/)
|
||||
|
||||
if (NOT MINGW_BUILD)
|
||||
add_subdirectory(Common/)
|
||||
add_subdirectory(Linux/)
|
||||
add_subdirectory(Tools/)
|
||||
endif()
|
||||
@@ -19,13 +19,14 @@ if (NOT MINGW_BUILD)
|
||||
add_subdirectory(FEXGetConfig/)
|
||||
add_subdirectory(FEXServer/)
|
||||
add_subdirectory(FEXBash/)
|
||||
add_subdirectory(FEXLoader/)
|
||||
|
||||
set(NAME Opt)
|
||||
set(SRCS Opt.cpp)
|
||||
|
||||
add_executable(${NAME} ${SRCS})
|
||||
target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
|
||||
target_link_libraries(${NAME} FEXCore Common pthread)
|
||||
endif()
|
||||
|
||||
set(NAME Opt)
|
||||
set(SRCS Opt.cpp)
|
||||
|
||||
add_executable(${NAME} ${SRCS})
|
||||
target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
|
||||
target_link_libraries(${NAME} FEXCore Common pthread)
|
||||
add_subdirectory(FEXLoader/)
|
||||
@@ -1,148 +1,156 @@
|
||||
add_subdirectory(LinuxSyscalls)
|
||||
|
||||
list(APPEND LIBS FEXCore Common)
|
||||
|
||||
if (TERMUX_BUILD)
|
||||
# Termux needs android-shmem to get the shm emulation library.
|
||||
list(APPEND LIBS android-shmem)
|
||||
endif()
|
||||
if (NOT MINGW_BUILD)
|
||||
add_subdirectory(LinuxSyscalls)
|
||||
|
||||
function(GenerateInterpreter NAME AsInterpreter)
|
||||
add_executable(${NAME}
|
||||
FEXLoader.cpp
|
||||
VDSO_Emulation.cpp
|
||||
AOT/AOTGenerator.cpp)
|
||||
if (TERMUX_BUILD)
|
||||
# Termux needs android-shmem to get the shm emulation library.
|
||||
list(APPEND LIBS android-shmem)
|
||||
endif()
|
||||
|
||||
# Enable FEX APIs to be used by targets that use target_link_libraries on FEXLoader
|
||||
set_target_properties(${NAME} PROPERTIES ENABLE_EXPORTS 1)
|
||||
function(GenerateInterpreter NAME AsInterpreter)
|
||||
add_executable(${NAME}
|
||||
FEXLoader.cpp
|
||||
VDSO_Emulation.cpp
|
||||
AOT/AOTGenerator.cpp)
|
||||
|
||||
target_include_directories(${NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
)
|
||||
target_link_libraries(${NAME}
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
LinuxEmulation
|
||||
${PTHREAD_LIB}
|
||||
fmt::fmt
|
||||
)
|
||||
target_compile_definitions(${NAME} PRIVATE -DFEXLOADER_AS_INTERPRETER=${AsInterpreter})
|
||||
# Enable FEX APIs to be used by targets that use target_link_libraries on FEXLoader
|
||||
set_target_properties(${NAME} PROPERTIES ENABLE_EXPORTS 1)
|
||||
|
||||
if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
|
||||
target_link_options(${NAME}
|
||||
target_include_directories(${NAME}
|
||||
PRIVATE
|
||||
"LINKER:--gc-sections"
|
||||
"LINKER:--strip-all"
|
||||
"LINKER:--as-needed"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT MINGW_BUILD)
|
||||
install(TARGETS ${NAME}
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
target_link_libraries(${NAME}
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
LinuxEmulation
|
||||
${PTHREAD_LIB}
|
||||
fmt::fmt
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
target_compile_definitions(${NAME} PRIVATE -DFEXLOADER_AS_INTERPRETER=${AsInterpreter})
|
||||
|
||||
GenerateInterpreter(FEXLoader 0)
|
||||
GenerateInterpreter(FEXInterpreter 1)
|
||||
|
||||
install(PROGRAMS "${PROJECT_SOURCE_DIR}/Scripts/FEXUpdateAOTIRCache.sh" DESTINATION bin RENAME FEXUpdateAOTIRCache)
|
||||
|
||||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
|
||||
# Check for conflicting binfmt before installing
|
||||
set (CONFLICTING_BINFMTS_32
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-i386
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/box86)
|
||||
set (CONFLICTING_BINFMTS_64
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-x86_64
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/box64)
|
||||
|
||||
find_program(UPDATE_BINFMTS_PROGRAM update-binfmts)
|
||||
if (UPDATE_BINFMTS_PROGRAM)
|
||||
add_custom_target(binfmt_misc_32
|
||||
echo "Attempting to install FEX-x86 misc now."
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_32}
|
||||
COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86 installed"
|
||||
)
|
||||
|
||||
add_custom_target(binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to install FEX-x86_64 misc now."
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_64}
|
||||
COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86_64"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86_64 installed"
|
||||
)
|
||||
if(TARGET uninstall)
|
||||
add_custom_target(uninstall_binfmt_misc_32
|
||||
COMMAND update-binfmts --unimport FEX-x86 || (exit 0)
|
||||
if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
|
||||
target_link_options(${NAME}
|
||||
PRIVATE
|
||||
"LINKER:--gc-sections"
|
||||
"LINKER:--strip-all"
|
||||
"LINKER:--as-needed"
|
||||
)
|
||||
add_custom_target(uninstall_binfmt_misc_64
|
||||
COMMAND update-binfmts --unimport FEX-x86_64 || (exit 0)
|
||||
)
|
||||
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_32)
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_64)
|
||||
endif()
|
||||
else()
|
||||
# In the case of update-binfmts not being available (Arch for example) then we need to install manually
|
||||
add_custom_target(binfmt_misc_32
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to remove FEX-x86 misc prior to install. Ignore permission denied"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0)
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
|
||||
if (NOT MINGW_BUILD)
|
||||
install(TARGETS ${NAME}
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
GenerateInterpreter(FEXLoader 0)
|
||||
GenerateInterpreter(FEXInterpreter 1)
|
||||
|
||||
install(PROGRAMS "${PROJECT_SOURCE_DIR}/Scripts/FEXUpdateAOTIRCache.sh" DESTINATION bin RENAME FEXUpdateAOTIRCache)
|
||||
|
||||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
|
||||
# Check for conflicting binfmt before installing
|
||||
set (CONFLICTING_BINFMTS_32
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-i386
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/box86)
|
||||
set (CONFLICTING_BINFMTS_64
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-x86_64
|
||||
${CMAKE_INSTALL_PREFIX}/share/binfmts/box64)
|
||||
|
||||
find_program(UPDATE_BINFMTS_PROGRAM update-binfmts)
|
||||
if (UPDATE_BINFMTS_PROGRAM)
|
||||
add_custom_target(binfmt_misc_32
|
||||
echo "Attempting to install FEX-x86 misc now."
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo
|
||||
':FEX-x86:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:POCF' > /proc/sys/fs/binfmt_misc/register
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_32}
|
||||
COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86 installed"
|
||||
)
|
||||
add_custom_target(binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to remove FEX-x86_64 misc prior to install. Ignore permission denied"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0)
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
|
||||
add_custom_target(binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to install FEX-x86_64 misc now."
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo
|
||||
':FEX-x86_64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x3e\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:POCF' > /proc/sys/fs/binfmt_misc/register
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_64}
|
||||
COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86_64"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86_64 installed"
|
||||
)
|
||||
if(TARGET uninstall)
|
||||
add_custom_target(uninstall_binfmt_misc_32
|
||||
COMMAND update-binfmts --unimport FEX-x86 || (exit 0)
|
||||
)
|
||||
add_custom_target(uninstall_binfmt_misc_64
|
||||
COMMAND update-binfmts --unimport FEX-x86_64 || (exit 0)
|
||||
)
|
||||
|
||||
if(TARGET uninstall)
|
||||
add_custom_target(uninstall_binfmt_misc_32
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_32)
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_64)
|
||||
endif()
|
||||
else()
|
||||
# In the case of update-binfmts not being available (Arch for example) then we need to install manually
|
||||
add_custom_target(binfmt_misc_32
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to remove FEX-x86 misc prior to install. Ignore permission denied"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0)
|
||||
)
|
||||
add_custom_target(uninstall_binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to install FEX-x86 misc now."
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo
|
||||
':FEX-x86:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:POCF' > /proc/sys/fs/binfmt_misc/register
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86 installed"
|
||||
)
|
||||
add_custom_target(binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to remove FEX-x86_64 misc prior to install. Ignore permission denied"
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0)
|
||||
)
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "Attempting to install FEX-x86_64 misc now."
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo
|
||||
':FEX-x86_64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x3e\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:POCF' > /proc/sys/fs/binfmt_misc/register
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo "binfmt_misc FEX-x86_64 installed"
|
||||
)
|
||||
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_32)
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_64)
|
||||
if(TARGET uninstall)
|
||||
add_custom_target(uninstall_binfmt_misc_32
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0)
|
||||
)
|
||||
add_custom_target(uninstall_binfmt_misc_64
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0)
|
||||
)
|
||||
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_32)
|
||||
add_dependencies(uninstall uninstall_binfmt_misc_64)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_custom_target(binfmt_misc
|
||||
DEPENDS binfmt_misc_32
|
||||
DEPENDS binfmt_misc_64
|
||||
)
|
||||
add_custom_target(binfmt_misc
|
||||
DEPENDS binfmt_misc_32
|
||||
DEPENDS binfmt_misc_64
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (BUILD_TESTS)
|
||||
add_executable(TestHarnessRunner TestHarnessRunner/HostRunner.cpp TestHarnessRunner.cpp)
|
||||
set (SRCS TestHarnessRunner.cpp)
|
||||
if (NOT MINGW_BUILD)
|
||||
list(APPEND SRCS TestHarnessRunner/HostRunner.cpp)
|
||||
list(APPEND LIBS LinuxEmulation)
|
||||
endif()
|
||||
|
||||
add_executable(TestHarnessRunner ${SRCS})
|
||||
target_include_directories(TestHarnessRunner
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/
|
||||
@@ -151,23 +159,24 @@ if (BUILD_TESTS)
|
||||
target_link_libraries(TestHarnessRunner
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
LinuxEmulation
|
||||
${PTHREAD_LIB}
|
||||
)
|
||||
|
||||
add_executable(IRLoader
|
||||
IRLoader.cpp
|
||||
)
|
||||
target_include_directories(IRLoader
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
)
|
||||
target_link_libraries(IRLoader
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
LinuxEmulation
|
||||
${PTHREAD_LIB}
|
||||
fmt::fmt
|
||||
)
|
||||
if (NOT MINGW_BUILD)
|
||||
add_executable(IRLoader
|
||||
IRLoader.cpp
|
||||
)
|
||||
target_include_directories(IRLoader
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
)
|
||||
target_link_libraries(IRLoader
|
||||
PRIVATE
|
||||
${LIBS}
|
||||
LinuxEmulation
|
||||
${PTHREAD_LIB}
|
||||
fmt::fmt
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
@@ -5,23 +5,31 @@ desc: Used to run Assembly tests
|
||||
$end_info$
|
||||
*/
|
||||
|
||||
#include "Common/ArgumentLoader.h"
|
||||
#include "TestHarnessRunner/HostRunner.h"
|
||||
#include "HarnessHelpers.h"
|
||||
#ifdef _WIN32
|
||||
#include "WindowsDummyHandlers.h"
|
||||
#include "ArchHelpers/WinContext.h"
|
||||
#else
|
||||
#include "LinuxSyscalls/LinuxAllocator.h"
|
||||
#include "LinuxSyscalls/Syscalls.h"
|
||||
#include "LinuxSyscalls/x32/Syscalls.h"
|
||||
#include "LinuxSyscalls/x64/Syscalls.h"
|
||||
#include "LinuxSyscalls/SignalDelegator.h"
|
||||
#endif
|
||||
|
||||
#include "Common/ArgumentLoader.h"
|
||||
#include "TestHarnessRunner/HostRunner.h"
|
||||
#include "HarnessHelpers.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
#include <FEXCore/Core/Context.h>
|
||||
#include <FEXCore/Core/CoreState.h>
|
||||
#include <FEXCore/Core/CPUBackend.h>
|
||||
#include <FEXCore/Core/HostFeatures.h>
|
||||
#include <FEXCore/Core/SignalDelegator.h>
|
||||
#include <FEXCore/Debug/InternalThreadState.h>
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/ArchHelpers/Arm64.h>
|
||||
#include <FEXCore/fextl/memory.h>
|
||||
#include <FEXCore/fextl/string.h>
|
||||
#include <FEXCore/fextl/vector.h>
|
||||
@@ -114,8 +122,72 @@ private:
|
||||
};
|
||||
}
|
||||
|
||||
namespace LongJumpHandler {
|
||||
static jmp_buf LongJump{};
|
||||
static bool DidFault{};
|
||||
|
||||
#ifndef _WIN32
|
||||
void RegisterLongJumpHandler(FEX::HLE::SignalDelegator *Handler) {
|
||||
Handler->RegisterFrontendHostSignalHandler(SIGSEGV, [](FEXCore::Core::InternalThreadState *Thread, int Signal, void *info, void *ucontext) {
|
||||
constexpr uint8_t HLT = 0xF4;
|
||||
if (reinterpret_cast<uint8_t*>(Thread->CurrentFrame->State.rip)[0] != HLT) {
|
||||
DidFault = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
longjmp(LongJumpHandler::LongJump, 1);
|
||||
return false;
|
||||
}, true);
|
||||
}
|
||||
#else
|
||||
FEX::WindowsHandlers::DummySignalDelegator *Handler;
|
||||
|
||||
LONG WINAPI
|
||||
VectoredExceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo) {
|
||||
auto Thread = Handler->GetBackingTLSThread();
|
||||
PCONTEXT Context;
|
||||
Context = ExceptionInfo->ContextRecord;
|
||||
|
||||
switch (ExceptionInfo->ExceptionRecord->ExceptionCode) {
|
||||
case STATUS_DATATYPE_MISALIGNMENT: {
|
||||
const auto PC = FEX::ArchHelpers::Context::GetPc(Context);
|
||||
if (!Thread->CPUBackend->IsAddressInCodeBuffer(PC)) {
|
||||
// Wasn't a sigbus in JIT code
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
const auto Result = FEXCore::ArchHelpers::Arm64::HandleUnalignedAccess(true, PC, FEX::ArchHelpers::Context::GetArmGPRs(Context));
|
||||
FEX::ArchHelpers::Context::SetPc(Context, PC + Result.second);
|
||||
return Result.first ?
|
||||
EXCEPTION_CONTINUE_EXECUTION :
|
||||
EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
printf("!Fault!\n");
|
||||
printf("\tExceptionCode: 0x%lx\n", ExceptionInfo->ExceptionRecord->ExceptionCode);
|
||||
printf("\tExceptionFlags: 0x%lx\n", ExceptionInfo->ExceptionRecord->ExceptionFlags);
|
||||
printf("\tExceptionRecord: 0x%p\n", ExceptionInfo->ExceptionRecord->ExceptionRecord);
|
||||
printf("\tExceptionAddress: 0x%p\n", ExceptionInfo->ExceptionRecord->ExceptionAddress);
|
||||
printf("\tNumberParameters: 0x%lx\n", ExceptionInfo->ExceptionRecord->NumberParameters);
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
void RegisterLongJumpHandler(FEX::WindowsHandlers::DummySignalDelegator *Handler) {
|
||||
// Install VEH handler.
|
||||
AddVectoredExceptionHandler(0, VectoredExceptionHandler);
|
||||
|
||||
LongJumpHandler::Handler = Handler;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **const envp) {
|
||||
#ifndef _WIN32
|
||||
auto SBRKPointer = FEXCore::Allocator::DisableSBRKAllocations();
|
||||
#endif
|
||||
FEXCore::Allocator::GLIBCScopedFault GLIBFaultScope;
|
||||
LogMan::Throw::InstallHandler(AssertHandler);
|
||||
LogMan::Msg::InstallHandler(MsgHandler);
|
||||
@@ -141,6 +213,7 @@ int main(int argc, char **argv, char **const envp) {
|
||||
|
||||
FEX_CONFIG_OPT(Core, CORE);
|
||||
|
||||
#ifndef _WIN32
|
||||
fextl::unique_ptr<FEX::HLE::MemAllocator> Allocator;
|
||||
|
||||
if (!Loader.Is64BitMode()) {
|
||||
@@ -157,8 +230,8 @@ int main(int argc, char **argv, char **const envp) {
|
||||
Allocator = FEX::HLE::CreatePassthroughAllocator();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool DidFault = false;
|
||||
bool SupportsAVX = false;
|
||||
FEXCore::Core::CPUState State;
|
||||
|
||||
@@ -168,7 +241,11 @@ int main(int argc, char **argv, char **const envp) {
|
||||
|
||||
CTX->InitializeContext();
|
||||
|
||||
#ifndef _WIN32
|
||||
auto SignalDelegation = FEX::HLE::CreateSignalDelegator(CTX.get());
|
||||
#else
|
||||
auto SignalDelegation = FEX::WindowsHandlers::CreateSignalDelegator();
|
||||
#endif
|
||||
|
||||
// Skip any tests that the host doesn't support features for
|
||||
auto HostFeatures = CTX->GetHostFeatures();
|
||||
@@ -190,23 +267,16 @@ int main(int argc, char **argv, char **const envp) {
|
||||
}
|
||||
|
||||
if (Core != FEXCore::Config::CONFIG_CUSTOM) {
|
||||
jmp_buf LongJump{};
|
||||
int LongJumpVal{};
|
||||
|
||||
SignalDelegation->RegisterFrontendHostSignalHandler(SIGSEGV, [&DidFault, &LongJump](FEXCore::Core::InternalThreadState *Thread, int Signal, void *info, void *ucontext) {
|
||||
constexpr uint8_t HLT = 0xF4;
|
||||
if (reinterpret_cast<uint8_t*>(Thread->CurrentFrame->State.rip)[0] != HLT) {
|
||||
DidFault = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
longjmp(LongJump, 1);
|
||||
return false;
|
||||
}, true);
|
||||
|
||||
#ifndef _WIN32
|
||||
auto SyscallHandler = Loader.Is64BitMode() ? FEX::HLE::x64::CreateHandler(CTX.get(), SignalDelegation.get())
|
||||
: FEX::HLE::x32::CreateHandler(CTX.get(), SignalDelegation.get(), std::move(Allocator));
|
||||
|
||||
#else
|
||||
auto SyscallHandler = FEX::WindowsHandlers::CreateSyscallHandler();
|
||||
#endif
|
||||
|
||||
LongJumpHandler::RegisterLongJumpHandler(SignalDelegation.get());
|
||||
|
||||
// Run through FEX
|
||||
if (!Loader.MapMemory()) {
|
||||
// failed to map
|
||||
@@ -223,7 +293,7 @@ int main(int argc, char **argv, char **const envp) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
LongJumpVal = setjmp(LongJump);
|
||||
int LongJumpVal = setjmp(LongJumpHandler::LongJump);
|
||||
if (!LongJumpVal) {
|
||||
CTX->RunUntilExit();
|
||||
}
|
||||
@@ -232,7 +302,9 @@ int main(int argc, char **argv, char **const envp) {
|
||||
CTX->GetCPUState(&State);
|
||||
|
||||
SyscallHandler.reset();
|
||||
} else {
|
||||
}
|
||||
#ifndef _WIN32
|
||||
else {
|
||||
// Run as host
|
||||
SupportsAVX = true;
|
||||
SignalDelegation->RegisterTLSState((FEXCore::Core::InternalThreadState*)UINTPTR_MAX);
|
||||
@@ -244,10 +316,11 @@ int main(int argc, char **argv, char **const envp) {
|
||||
|
||||
RunAsHost(SignalDelegation, Loader.DefaultRIP(), Loader.GetStackPointer(), &State);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Passed = !DidFault && Loader.CompareStates(&State, nullptr, SupportsAVX);
|
||||
bool Passed = !LongJumpHandler::DidFault && Loader.CompareStates(&State, nullptr, SupportsAVX);
|
||||
|
||||
LogMan::Msg::IFmt("Faulted? {}", DidFault ? "Yes" : "No");
|
||||
LogMan::Msg::IFmt("Faulted? {}", LongJumpHandler::DidFault ? "Yes" : "No");
|
||||
LogMan::Msg::IFmt("Passed? {}", Passed ? "Yes" : "No");
|
||||
|
||||
|
||||
@@ -258,9 +331,11 @@ int main(int argc, char **argv, char **const envp) {
|
||||
LogMan::Throw::UnInstallHandlers();
|
||||
LogMan::Msg::UnInstallHandlers();
|
||||
|
||||
#ifndef _WIN32
|
||||
FEXCore::Allocator::ClearHooks();
|
||||
|
||||
FEXCore::Allocator::ReenableSBRKAllocations(SBRKPointer);
|
||||
#endif
|
||||
|
||||
return Passed ? 0 : -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user