TestHarnessRunner: Call the frontend mapping callback for created mappings

This commit is contained in:
Billy Laws committed 2025-04-19 15:29:23 +01:00
1 parent 6525b8dd14
commit 23017af874
2 files changed
+24 -11

No files matched your search

+3 -9
View File
@@ -419,14 +419,8 @@ public:
return RIP;
}
bool MapMemory() {
bool MapMemory(const std::function<void*(uint64_t, size_t)>& DoMMap) {
bool LimitedSize = true;
auto DoMMap = [](uint64_t Address, size_t Size) -> void* {
void* Result = FEXCore::Allocator::VirtualAlloc(reinterpret_cast<void*>(Address), Size, true);
LOGMAN_THROW_A_FMT(Result == reinterpret_cast<void*>(Address), "Map Memory mmap failed");
return Result;
};
auto AllocPageSize = sysconf(_SC_PAGESIZE);
if (AllocPageSize <= 0) {
AllocPageSize = FEXCore::Utils::FEX_PAGE_SIZE;
@@ -451,10 +445,10 @@ public:
// Map in the memory region for the test file
#ifndef _WIN32
size_t Length = FEXCore::AlignUp(RawASMFile.size(), FEXCore::Utils::FEX_PAGE_SIZE);
auto ASMPtr = FEXCore::Allocator::VirtualAlloc(reinterpret_cast<void*>(Code_start_page), Length, true);
auto ASMPtr = DoMMap(Code_start_page, Length);
#else
// Special magic DOS area that starts at 0x1'0000
auto ASMPtr = FEXCore::Allocator::VirtualAlloc(reinterpret_cast<void*>(1), 0x110000 - 1, true);
auto ASMPtr = DoMMap(1, 0x110000 - 1);
#endif
LOGMAN_THROW_A_FMT((uint64_t)ASMPtr == Code_start_page, "Couldn't allocate code at expected page: 0x{:x} != 0x{:x}", (uint64_t)ASMPtr,
Code_start_page);
@@ -300,14 +300,27 @@ int main(int argc, char** argv, char** const envp) {
auto SyscallHandler = Loader.Is64BitMode() ? FEX::HLE::x64::CreateHandler(CTX.get(), SignalDelegation.get(), nullptr) :
FEX::HLE::x32::CreateHandler(CTX.get(), SignalDelegation.get(), nullptr, std::move(Allocator));
auto DoMmap = [&](uint64_t Address, size_t Size) -> void* {
void* Result = SyscallHandler->GuestMmap(nullptr, (void*)Address, Size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
LOGMAN_THROW_A_FMT(Result == reinterpret_cast<void*>(Address), "Map Memory mmap failed");
return Result;
};
#else
auto SyscallHandler = FEX::WindowsHandlers::CreateSyscallHandler();
auto DoMMap = [](uint64_t Address, size_t Size) -> void* {
void* Result = FEXCore::Allocator::VirtualAlloc(reinterpret_cast<void*>(Address), Size, true);
LOGMAN_THROW_A_FMT(Result == reinterpret_cast<void*>(Address), "Map Memory mmap failed");
return Result;
};
#endif
LongJumpHandler::RegisterLongJumpHandler(SignalDelegation.get());
// Run through FEX
if (!Loader.MapMemory()) {
if (!Loader.MapMemory(DoMmap)) {
// failed to map
LogMan::Msg::EFmt("Failed to map {}-bit elf file.", Loader.Is64BitMode() ? 64 : 32);
return -ENOEXEC;
@@ -359,7 +372,13 @@ int main(int argc, char** argv, char** const envp) {
SupportsAVX = true;
FEX::HLE::ThreadStateObject ThreadStateObject {};
SignalDelegation->RegisterTLSState(&ThreadStateObject);
if (!Loader.MapMemory()) {
auto DoMmap = [&](uint64_t Address, size_t Size) -> void* {
void* Result = mmap((void*)Address, Size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
LOGMAN_THROW_A_FMT(Result == reinterpret_cast<void*>(Address), "Map Memory mmap failed");
return Result;
};
if (!Loader.MapMemory(DoMmap)) {
// failed to map
LogMan::Msg::EFmt("Failed to map {}-bit elf file.", Loader.Is64BitMode() ? 64 : 32);
return -ENOEXEC;