mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-27 08:00:37 +01:00
Use allocator for x32
This commit is contained in:
1 parent
22f1cf0e2a
commit
0db99ea4f6
5 files changed
+44
-49
No files matched your search
+38
-21
@@ -10,7 +10,8 @@ $end_info$
|
||||
#include "Common/Config.h"
|
||||
#include "ELFCodeLoader.h"
|
||||
#include "ELFCodeLoader2.h"
|
||||
#include "Tests/LinuxSyscalls/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/x32/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/SignalDelegator.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
@@ -232,7 +233,13 @@ int main(int argc, char **argv, char **const envp) {
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t KernelVersion = FEX::HLE::SyscallHandler::CalculateHostKernelVersion();
|
||||
if (KernelVersion < FEX::HLE::SyscallHandler::KernelVersion(4, 17)) {
|
||||
// We require 4.17 minimum for MAP_FIXED_NOREPLACE
|
||||
LogMan::Msg::E("FEXLoader requires kernel 4.17 minimum. Expect problems.");
|
||||
}
|
||||
|
||||
ELFCodeLoader2 Loader{Program, LDPath(), Args, ParsedArgs, envp, &Environment};
|
||||
//FEX::HarnessHelper::ELFCodeLoader Loader{Program, LDPath(), Args, ParsedArgs, envp, &Environment};
|
||||
|
||||
@@ -241,38 +248,48 @@ int main(int argc, char **argv, char **const envp) {
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
FEXCore::Config::Set(FEXCore::Config::CONFIG_APP_FILENAME, std::filesystem::canonical(Program));
|
||||
FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, Loader.Is64BitMode() ? "1" : "0");
|
||||
|
||||
if (!Loader.MapMemory([](void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
|
||||
|
||||
FEX::HLE::x32::MemAllocator *Allocator = nullptr;
|
||||
|
||||
if (Loader.Is64BitMode()) {
|
||||
if (!Loader.MapMemory([](void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
|
||||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}, [](void *addr, size_t length) {
|
||||
return munmap(addr, length);
|
||||
})) {
|
||||
// failed to map
|
||||
return -ENOEXEC;
|
||||
// failed to map
|
||||
return -ENOEXEC;
|
||||
}
|
||||
} else {
|
||||
Allocator = new FEX::HLE::x32::MemAllocator();
|
||||
if (!Loader.MapMemory([Allocator](void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
|
||||
return Allocator->mmap(addr, length, prot, flags, fd, offset);
|
||||
}, [Allocator](void *addr, size_t length) {
|
||||
return Allocator->munmap(addr, length);
|
||||
})) {
|
||||
// failed to map
|
||||
return -ENOEXEC;
|
||||
}
|
||||
}
|
||||
|
||||
FEXCore::Config::Set(FEXCore::Config::CONFIG_APP_FILENAME, std::filesystem::canonical(Program));
|
||||
FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, Loader.Is64BitMode() ? "1" : "0");
|
||||
|
||||
uint32_t KernelVersion = FEX::HLE::SyscallHandler::CalculateHostKernelVersion();
|
||||
if (KernelVersion < FEX::HLE::SyscallHandler::KernelVersion(4, 17) &&
|
||||
!Loader.Is64BitMode()) {
|
||||
// We require 4.17 minimum for MAP_FIXED_NOREPLACE on 32bit ELFs
|
||||
LogMan::Msg::E("FEXLoader requires kernel 4.17 minimum. Expect problems.");
|
||||
}
|
||||
|
||||
|
||||
FEXCore::Context::InitializeStaticTables(Loader.Is64BitMode() ? FEXCore::Context::MODE_64BIT : FEXCore::Context::MODE_32BIT);
|
||||
|
||||
auto CTX = FEXCore::Context::CreateNewContext();
|
||||
FEXCore::Context::InitializeContext(CTX);
|
||||
|
||||
std::unique_ptr<FEX::HLE::SignalDelegator> SignalDelegation = std::make_unique<FEX::HLE::SignalDelegator>();
|
||||
|
||||
std::unique_ptr<FEX::HLE::SyscallHandler> SyscallHandler{
|
||||
FEX::HLE::CreateHandler(
|
||||
Loader.Is64BitMode() ? FEXCore::Context::OperatingMode::MODE_64BIT : FEXCore::Context::OperatingMode::MODE_32BIT,
|
||||
CTX,
|
||||
SignalDelegation.get(),
|
||||
&Loader)};
|
||||
Loader.Is64BitMode() ?
|
||||
FEX::HLE::x64::CreateHandler(CTX, SignalDelegation.get()) :
|
||||
FEX::HLE::x32::CreateHandler(CTX, SignalDelegation.get(), Allocator)
|
||||
};
|
||||
|
||||
SyscallHandler->SetCodeLoader(&Loader);
|
||||
|
||||
auto BRKInfo = Loader.GetBRKInfo();
|
||||
//fprintf(stderr, "BRK %lX - %ld\n", BRKInfo.Base, BRKInfo.Size);
|
||||
|
||||
|
||||
@@ -314,21 +314,4 @@ uint64_t UnimplementedSyscallSafe(FEXCore::Core::CpuStateFrame *Frame, uint64_t
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::OperatingMode Mode,
|
||||
FEXCore::Context::Context *ctx,
|
||||
FEX::HLE::SignalDelegator *_SignalDelegation,
|
||||
FEXCore::CodeLoader *Loader) {
|
||||
|
||||
FEX::HLE::SyscallHandler *Result{};
|
||||
if (Mode == FEXCore::Context::MODE_64BIT) {
|
||||
Result = FEX::HLE::x64::CreateHandler(ctx, _SignalDelegation);
|
||||
}
|
||||
else {
|
||||
Result = FEX::HLE::x32::CreateHandler(ctx, _SignalDelegation);
|
||||
}
|
||||
|
||||
Result->SetCodeLoader(Loader);
|
||||
return Result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -146,11 +146,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::OperatingMode Mode,
|
||||
FEXCore::Context::Context *ctx,
|
||||
FEX::HLE::SignalDelegator *_SignalDelegation,
|
||||
FEXCore::CodeLoader *Loader
|
||||
);
|
||||
uint64_t HandleSyscall(SyscallHandler *Handler, FEXCore::Core::CpuStateFrame *Frame, FEXCore::HLE::SyscallArguments *Args);
|
||||
|
||||
#define SYSCALL_ERRNO() do { if (Result == -1) return -errno; return Result; } while(0)
|
||||
|
||||
@@ -527,9 +527,9 @@ uint64_t MemAllocator::shmdt(const void* shmaddr) {
|
||||
});
|
||||
}
|
||||
|
||||
x32SyscallHandler::x32SyscallHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation)
|
||||
x32SyscallHandler::x32SyscallHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation, MemAllocator *Allocator)
|
||||
: SyscallHandler {ctx, _SignalDelegation} {
|
||||
AllocHandler = std::make_unique<MemAllocator>();
|
||||
AllocHandler.reset(Allocator);
|
||||
OSABI = FEXCore::HLE::SyscallOSABI::OS_LINUX32;
|
||||
RegisterSyscallHandlers();
|
||||
}
|
||||
@@ -607,8 +607,8 @@ uint64_t MemAllocator::shmdt(const void* shmaddr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation) {
|
||||
return new x32SyscallHandler(ctx, _SignalDelegation);
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation, MemAllocator *Allocator) {
|
||||
return new x32SyscallHandler(ctx, _SignalDelegation, Allocator);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,7 +97,7 @@ private:
|
||||
|
||||
class x32SyscallHandler final : public FEX::HLE::SyscallHandler {
|
||||
public:
|
||||
x32SyscallHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation);
|
||||
x32SyscallHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation, MemAllocator *Allocator);
|
||||
|
||||
FEX::HLE::x32::MemAllocator *GetAllocator() { return AllocHandler.get(); }
|
||||
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
std::unique_ptr<MemAllocator> AllocHandler{};
|
||||
};
|
||||
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation);
|
||||
FEX::HLE::SyscallHandler *CreateHandler(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *_SignalDelegation, MemAllocator *Allocator);
|
||||
void RegisterSyscallInternal(int SyscallNumber,
|
||||
#ifdef DEBUG_STRACE
|
||||
const std::string& TraceFormatString,
|
||||
|
||||
Reference in new issue
Block a user