mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-08 07:00:17 +02:00
89 lines
3.0 KiB
C++
89 lines
3.0 KiB
C++
/*
|
|
$info$
|
|
tags: LinuxSyscalls|syscalls-x86-64
|
|
$end_info$
|
|
*/
|
|
|
|
#include "Tests/LinuxSyscalls/Syscalls.h"
|
|
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
|
|
#include <FEXCore/Core/Context.h>
|
|
#include <FEXCore/Debug/InternalThreadState.h>
|
|
|
|
#include <sys/mman.h>
|
|
#include <sys/shm.h>
|
|
#include <map>
|
|
#include <unistd.h>
|
|
|
|
#include <FEXCore/Core/Context.h>
|
|
#include <FEXCore/Config/Config.h>
|
|
#include <FEXCore/Utils/Allocator.h>
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
|
|
static std::string get_fdpath(int fd)
|
|
{
|
|
std::error_code ec;
|
|
return std::filesystem::canonical(std::filesystem::path("/proc/self/fd") / std::to_string(fd), ec).string();
|
|
}
|
|
|
|
namespace FEX::HLE::x64 {
|
|
void RegisterMemory() {
|
|
REGISTER_SYSCALL_IMPL_X64(munmap, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, size_t length) -> uint64_t {
|
|
uint64_t Result = FEXCore::Allocator::munmap(addr, length);
|
|
|
|
auto Thread = Frame->Thread;
|
|
if (Result != -1) {
|
|
FEXCore::Context::RemoveNamedRegion(Thread->CTX, (uintptr_t)addr, length);
|
|
FEXCore::Context::FlushCodeRange(Thread, (uintptr_t)addr, length);
|
|
}
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(mmap, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, size_t length, int prot, int flags, int fd, off_t offset) -> uint64_t {
|
|
static FEX_CONFIG_OPT(AOTIRLoad, AOTIRLOAD);
|
|
uint64_t Result = reinterpret_cast<uint64_t>(FEXCore::Allocator::mmap(addr, length, prot, flags, fd, offset));
|
|
|
|
auto Thread = Frame->Thread;
|
|
if (Result != -1) {
|
|
if (!(flags & MAP_ANONYMOUS)) {
|
|
auto filename = get_fdpath(fd);
|
|
|
|
FEXCore::Context::AddNamedRegion(Thread->CTX, Result, length, offset, filename);
|
|
}
|
|
FEXCore::Context::FlushCodeRange(Thread, (uintptr_t)Result, length);
|
|
}
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(mremap, [](FEXCore::Core::CpuStateFrame *Frame, void *old_address, size_t old_size, size_t new_size, int flags, void *new_address) -> uint64_t {
|
|
uint64_t Result = reinterpret_cast<uint64_t>(::mremap(old_address, old_size, new_size, flags, new_address));
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(mprotect, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, size_t len, int prot) -> uint64_t {
|
|
uint64_t Result = ::mprotect(addr, len, prot);
|
|
|
|
auto Thread = Frame->Thread;
|
|
if (Result != -1 && prot & PROT_EXEC) {
|
|
FEXCore::Context::FlushCodeRange(Thread, (uintptr_t)addr, len);
|
|
}
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(mlockall, [](FEXCore::Core::CpuStateFrame *Frame, int flags) -> uint64_t {
|
|
uint64_t Result = ::mlockall(flags);
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(munlockall, [](FEXCore::Core::CpuStateFrame *Frame) -> uint64_t {
|
|
uint64_t Result = ::munlockall();
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X64(shmat, [](FEXCore::Core::CpuStateFrame *Frame, int shmid, const void *shmaddr, int shmflg) -> uint64_t {
|
|
uint64_t Result = reinterpret_cast<uint64_t>(shmat(shmid, shmaddr, shmflg));
|
|
SYSCALL_ERRNO();
|
|
});
|
|
}
|
|
}
|