fex: update to 2203

This commit is contained in:
Ryan Houdek 2022-03-06 05:03:57 -08:00 committed by xtkoba
parent 1c9f9e6d98
commit b3d94b5399
39 changed files with 658 additions and 736 deletions

View File

@ -1,11 +0,0 @@
--- a/External/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp
+++ b/External/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp
@@ -16,7 +16,7 @@
#include <atomic>
#include <condition_variable>
-#include <bits/types/siginfo_t.h>
+#include <asm-generic/siginfo.h>
#include <csignal>
#include <cstring>

View File

@ -1,11 +0,0 @@
--- a/External/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h
+++ b/External/FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.h
@@ -5,7 +5,7 @@
#include "Interface/Context/Context.h"
#include "Interface/Core/ArchHelpers/MContext.h"
-#include <bits/types/stack_t.h>
+#include <asm-generic/signal.h>
#include <cstdint>
#include <stddef.h>
#include <stack>

View File

@ -1,11 +0,0 @@
--- a/External/FEXCore/Source/Interface/Core/Interpreter/InterpreterCore.cpp
+++ b/External/FEXCore/Source/Interface/Core/Interpreter/InterpreterCore.cpp
@@ -11,7 +11,7 @@
#include <FEXCore/Utils/LogManager.h>
#include <memory>
-#include <bits/types/stack_t.h>
+#include <asm-generic/signal.h>
#include <signal.h>
#include <stdint.h>
#include <unordered_map>

View File

@ -1,18 +0,0 @@
--- a/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp
+++ b/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp
@@ -23,7 +23,6 @@
#include <utility>
static constexpr uint64_t PAGE_SHIFT = 12;
-static constexpr uint64_t PAGE_MASK = (1 << PAGE_SHIFT) - 1;
namespace Alloc::OSAllocator {
class OSAllocator_64Bit final : public Alloc::HostAllocator {
@@ -37,7 +36,6 @@
int Munmap(void *addr, size_t length) override;
private:
- constexpr static uint64_t PAGE_SIZE = 4096;
// Upper bound is the maximum virtual address space of the host processor
uintptr_t UPPER_BOUND = (1ULL << 57);

View File

@ -1,11 +0,0 @@
--- a/External/FEXCore/Source/Utils/Allocator/HostAllocator.h
+++ b/External/FEXCore/Source/Utils/Allocator/HostAllocator.h
@@ -5,8 +5,6 @@
#include <memory>
#include <sys/types.h>
-constexpr static uint64_t PAGE_SIZE = 4096;
-
namespace Alloc {
// HostAllocator is just a page pased slab allocator
// Similar to mmap and munmap only mapping at the page level

View File

@ -1,19 +0,0 @@
--- a/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
+++ b/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
@@ -7,10 +7,15 @@
#include <bitset>
#include <cstddef>
-#include <memory_resource>
+#include <experimental/list>
+#include <experimental/memory_resource>
#include <mutex>
#include <vector>
+namespace std {
+ namespace pmr = experimental::pmr;
+}
+
namespace Alloc {
class ForwardOnlyIntrusiveArenaAllocator final : public std::pmr::memory_resource {
public:

View File

@ -1,13 +0,0 @@
--- a/External/FEXCore/include/FEXCore/Core/SignalDelegator.h
+++ b/External/FEXCore/include/FEXCore/Core/SignalDelegator.h
@@ -3,8 +3,8 @@
#include <FEXCore/Utils/CompilerDefs.h>
#include <array>
-#include <bits/types/siginfo_t.h>
-#include <bits/types/stack_t.h>
+#include <asm-generic/siginfo.h>
+#include <asm-generic/signal.h>
#include <cstdint>
#include <functional>
#include <utility>

View File

@ -1,17 +0,0 @@
--- a/External/FEXCore/include/FEXCore/Core/UContext.h
+++ b/External/FEXCore/include/FEXCore/Core/UContext.h
@@ -163,12 +163,14 @@
val.si_errno = si_errno;
val.si_code = si_code;
+#ifndef __ANDROID__
// Host siginfo has a pad member that is set to zeros
val.__pad0 = 0;
// Copy over the union
// The union is different sizes on 64-bit versus 32-bit
memcpy(val._sifields._pad, _sifields.pad, std::min(sizeof(val._sifields._pad), sizeof(_sifields.pad)));
+#endif
return val;
}

View File

@ -1,10 +0,0 @@
--- a/Source/Common/SocketLogging.cpp
+++ b/Source/Common/SocketLogging.cpp
@@ -7,6 +7,7 @@
#include <atomic>
#include <fcntl.h>
#include <netdb.h>
+#include <netinet/in.h>
#include <poll.h>
#include <sstream>
#include <string>

View File

@ -1,11 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp
+++ b/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp
@@ -19,8 +19,6 @@
class MemAllocator32Bit final : public FEX::HLE::MemAllocator {
private:
static constexpr uint64_t PAGE_SHIFT = 12;
- static constexpr uint64_t PAGE_SIZE = 1 << PAGE_SHIFT;
- static constexpr uint64_t PAGE_MASK = (1 << PAGE_SHIFT) - 1;
static constexpr uint64_t BASE_KEY = 16;
const uint64_t TOP_KEY = 0xFFFF'F000ULL >> PAGE_SHIFT;
const uint64_t TOP_KEY32BIT = 0x1F'F000ULL >> PAGE_SHIFT;

View File

@ -1,19 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/SignalDelegator.cpp
+++ b/Source/Tests/LinuxSyscalls/SignalDelegator.cpp
@@ -24,7 +24,7 @@
#include <exception>
#include <functional>
#include <linux/futex.h>
-#include <bits/types/stack_t.h>
+#include <asm-generic/signal.h>
#include <signal.h>
#include <syscall.h>
#include <sys/mman.h>
@@ -42,7 +42,6 @@
}
#endif
- constexpr static uint32_t SS_AUTODISARM = (1U << 31);
constexpr static uint32_t X86_MINSIGSTKSZ = 0x2000U;
// We can only have one delegator per process

View File

@ -1,13 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/SignalDelegator.h
+++ b/Source/Tests/LinuxSyscalls/SignalDelegator.h
@@ -9,8 +9,8 @@
#include <array>
#include <atomic>
-#include <bits/types/siginfo_t.h>
-#include <bits/types/stack_t.h>
+#include <asm-generic/siginfo.h>
+#include <asm-generic/signal.h>
#include <stddef.h>
#include <stdint.h>
#include <mutex>

View File

@ -1,46 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/FD.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/FD.cpp
@@ -257,11 +257,13 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 30
REGISTER_SYSCALL_IMPL_PASS(memfd_create, [](FEXCore::Core::CpuStateFrame *Frame, const char *name, uint32_t flags) -> uint64_t {
// Flags don't need remapped
uint64_t Result = ::memfd_create(name, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL(statx, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, int flags, uint32_t mask, struct statx *statxbuf) -> uint64_t {
// Flags don't need remapped
@@ -269,6 +271,7 @@
SYSCALL_ERRNO();
});
+#ifndef __ANDROID__
REGISTER_SYSCALL_IMPL_PASS(name_to_handle_at, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, struct file_handle *handle, int *mount_id, int flags) -> uint64_t {
// Flags don't need remapped
uint64_t Result = ::name_to_handle_at(dirfd, pathname, handle, mount_id, flags);
@@ -280,6 +283,7 @@
uint64_t Result = ::open_by_handle_at(mount_fd, handle, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_PASS(eventfd2, [](FEXCore::Core::CpuStateFrame *Frame, unsigned int count, int flags) -> uint64_t {
// Flags don't need remapped
@@ -287,11 +291,13 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_PASS(copy_file_range, [](FEXCore::Core::CpuStateFrame *Frame, int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) -> uint64_t {
// Flags don't need remapped
uint64_t Result = ::copy_file_range(fd_in, off_in, fd_out, off_out, len, flags);
SYSCALL_ERRNO();
});
+#endif
if (Handler->IsHostKernelVersionAtLeast(5, 3, 0)) {
REGISTER_SYSCALL_IMPL_PASS(pidfd_open, [](FEXCore::Core::CpuStateFrame *Frame, pid_t pid, unsigned int flags) -> uint64_t {

View File

@ -1,40 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/FS.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/FS.cpp
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <sys/fanotify.h>
+#include <linux/fanotify.h>
#include <sys/mount.h>
#include <sys/swap.h>
#include <sys/syscall.h>
@@ -149,10 +149,12 @@
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 28
REGISTER_SYSCALL_IMPL_PASS(syncfs, [](FEXCore::Core::CpuStateFrame *Frame, int fd) -> uint64_t {
uint64_t Result = ::syncfs(fd);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_PASS(setxattr, [](FEXCore::Core::CpuStateFrame *Frame, const char *path, const char *name, const void *value, size_t size, int flags) -> uint64_t {
uint64_t Result = ::setxattr(path, name, value, size, flags);
@@ -214,6 +216,7 @@
SYSCALL_ERRNO();
});
+#ifndef __ANDROID__
REGISTER_SYSCALL_IMPL_PASS(fanotify_init, [](FEXCore::Core::CpuStateFrame *Frame, unsigned int flags, unsigned int event_f_flags) -> uint64_t {
uint64_t Result = ::fanotify_init(flags, event_f_flags);
SYSCALL_ERRNO();
@@ -223,6 +226,7 @@
uint64_t Result = ::fanotify_mark(fanotify_fd, flags, mask, dirfd, pathname);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_PASS(pivot_root, [](FEXCore::Core::CpuStateFrame *Frame, const char *new_root, const char *put_old) -> uint64_t {
uint64_t Result = ::syscall(SYSCALL_DEF(pivot_root), new_root, put_old);

View File

@ -1,15 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Info.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Info.cpp
@@ -63,10 +63,12 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 28
REGISTER_SYSCALL_IMPL_PASS(getrandom, [](FEXCore::Core::CpuStateFrame *Frame, void *buf, size_t buflen, unsigned int flags) -> uint64_t {
uint64_t Result = ::getrandom(buf, buflen, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_PASS(capget, [](FEXCore::Core::CpuStateFrame *Frame, cap_user_header_t hdrp, cap_user_data_t datap) -> uint64_t {
uint64_t Result = ::syscall(SYSCALL_DEF(capget), hdrp, datap);

View File

@ -1,17 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Key.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Key.cpp
@@ -30,6 +30,7 @@
SYSCALL_ERRNO();
});
+#ifndef __ANDROID__
REGISTER_SYSCALL_IMPL_PASS(pkey_mprotect, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, size_t len, int prot, int pkey) -> uint64_t {
// Added in Linux 4.9
uint64_t Result = ::pkey_mprotect(addr, len, prot, pkey);
@@ -47,5 +48,6 @@
uint64_t Result = ::pkey_free(pkey);
SYSCALL_ERRNO();
});
+#endif
}
}

View File

@ -1,23 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Memory.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Memory.cpp
@@ -46,16 +46,20 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 30
REGISTER_SYSCALL_IMPL_PASS(mlock2, [](FEXCore::Core::CpuStateFrame *Frame, const void *addr, size_t len, int flags) -> uint64_t {
uint64_t Result = ::mlock2(addr, len, flags);
SYSCALL_ERRNO();
});
+#endif
+#ifndef __ANDROID__
REGISTER_SYSCALL_IMPL_PASS(remap_file_pages, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, size_t size, int prot, size_t pgoff, int flags) -> uint64_t {
// This syscall is deprecated, not sure when it will end up being removed
uint64_t Result = ::remap_file_pages(addr, size, prot, pgoff, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_PASS(mbind, [](FEXCore::Core::CpuStateFrame *Frame, void *addr, unsigned long len, int mode, const unsigned long *nodemask, unsigned long maxnode, unsigned flags) -> uint64_t {
uint64_t Result = ::syscall(SYSCALL_DEF(mbind), addr, len, mode, nodemask, maxnode, flags);

View File

@ -1,27 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Msg.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Msg.cpp
@@ -8,7 +8,7 @@
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
#include "Tests/LinuxSyscalls/x32/Syscalls.h"
-#include <mqueue.h>
+#include <linux/mqueue.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
@@ -17,6 +17,7 @@
namespace FEX::HLE {
void RegisterMsg() {
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_PASS(msgget, [](FEXCore::Core::CpuStateFrame *Frame, key_t key, int msgflg) -> uint64_t {
uint64_t Result = ::msgget(key, msgflg);
SYSCALL_ERRNO();
@@ -40,6 +41,7 @@
uint64_t Result = ::msgctl(msqid, cmd, buf);
SYSCALL_ERRNO();
});
+#endif
// last two parameters are optional
REGISTER_SYSCALL_IMPL_PASS(mq_unlink, [](FEXCore::Core::CpuStateFrame *Frame, const char *name) -> uint64_t {

View File

@ -1,20 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Semaphore.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Semaphore.cpp
@@ -10,14 +10,16 @@
#include <sys/types.h>
#include <sys/ipc.h>
-#include <sys/sem.h>
+#include <linux/sem.h>
namespace FEX::HLE {
void RegisterSemaphore() {
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_PASS(semget, [](FEXCore::Core::CpuStateFrame *Frame, key_t key, int nsems, int semflg) -> uint64_t {
uint64_t Result = ::semget(key, nsems, semflg);
SYSCALL_ERRNO();
});
+#endif
}
}

View File

@ -1,11 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/Syscalls/Thread.cpp
+++ b/Source/Tests/LinuxSyscalls/Syscalls/Thread.cpp
@@ -465,7 +465,7 @@
});
REGISTER_SYSCALL_IMPL_PASS(prlimit64, [](FEXCore::Core::CpuStateFrame *Frame, pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) -> uint64_t {
- uint64_t Result = ::prlimit(pid, (enum __rlimit_resource)(resource), new_limit, old_limit);
+ uint64_t Result = ::prlimit(pid, resource, new_limit, old_limit);
SYSCALL_ERRNO();
});

View File

@ -1,27 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/FD.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/FD.cpp
@@ -17,7 +17,7 @@
#include <FEXCore/Utils/MathUtils.h>
#include <algorithm>
-#include <bits/types/struct_iovec.h>
+#include <linux/uio.h>
#include <cstdint>
#include <fcntl.h>
#include <limits>
@@ -988,6 +988,7 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X32(sync_file_range, [](FEXCore::Core::CpuStateFrame *Frame,
int fd,
uint32_t offset_low,
@@ -1007,6 +1008,7 @@
uint64_t Result = ::sync_file_range(fd, Offset, Len, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_X32(fallocate, [](FEXCore::Core::CpuStateFrame *Frame,
int fd,

View File

@ -1,11 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Info.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Info.cpp
@@ -10,7 +10,7 @@
#include <algorithm>
#include <asm/posix_types.h>
-#include <bits/types/struct_rusage.h>
+#include <linux/resource.h>
#include <limits>
#include <linux/sysinfo.h>
#include <linux/utsname.h>

View File

@ -1,15 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Memory.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Memory.cpp
@@ -83,10 +83,12 @@
mremap(old_address, old_size, new_size, flags, new_address));
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 30
REGISTER_SYSCALL_IMPL_X32(mlockall, [](FEXCore::Core::CpuStateFrame *Frame, int flags) -> uint64_t {
uint64_t Result = ::mlock2(reinterpret_cast<void*>(0x1'0000), 0x1'0000'0000ULL - 0x1'0000, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_X32(munlockall, [](FEXCore::Core::CpuStateFrame *Frame) -> uint64_t {
uint64_t Result = ::munlock(reinterpret_cast<void*>(0x1'0000), 0x1'0000'0000ULL - 0x1'0000);

View File

@ -1,20 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Msg.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Msg.cpp
@@ -10,12 +10,16 @@
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
-#include <mqueue.h>
+#include <linux/mqueue.h>
#include <stdint.h>
#include <syscall.h>
#include <time.h>
#include <unistd.h>
+#ifdef __ANDROID__
+typedef int mqd_t;
+#endif
+
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::mq_attr32>, "%lx")
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::sigevent32>, "%lx")

View File

@ -1,43 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Semaphore.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Semaphore.cpp
@@ -19,7 +19,7 @@
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
-#include <sys/sem.h>
+#include <linux/sem.h>
#include <sys/shm.h>
#include <time.h>
#include <type_traits>
@@ -90,6 +90,7 @@
uint64_t Result{};
switch (static_cast<IPCOp>(call)) {
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
case OP_SEMOP: {
Result = ::semop(first, reinterpret_cast<struct sembuf*>(ptr), second);
break;
@@ -280,6 +281,7 @@
}
break;
}
+#endif
case OP_SHMAT: {
Result = static_cast<FEX::HLE::x32::x32SyscallHandler*>(FEX::HLE::_SyscallHandler)->GetAllocator()->
shmat(first, reinterpret_cast<const void*>(ptr), second, reinterpret_cast<uint32_t*>(third));
@@ -377,6 +379,7 @@
void RegisterSemaphore() {
REGISTER_SYSCALL_IMPL_X32(ipc, _ipc);
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X32_PASS_MANUAL(semtimedop_time64, semtimedop, [](FEXCore::Core::CpuStateFrame *Frame, int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) -> uint64_t {
uint64_t Result = ::semtimedop(semid, sops, nsops, timeout);
SYSCALL_ERRNO();
@@ -454,6 +457,7 @@
}
SYSCALL_ERRNO();
});
+#endif
}
}

View File

@ -1,11 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Signals.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Signals.cpp
@@ -13,7 +13,7 @@
#include <FEXCore/Core/SignalDelegator.h>
#include <FEXCore/Core/UContext.h>
#include <errno.h>
-#include <bits/types/siginfo_t.h>
+#include <asm-generic/siginfo.h>
#include <signal.h>
#include <stdint.h>
#include <sys/syscall.h>

View File

@ -1,11 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Socket.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Socket.cpp
@@ -11,7 +11,7 @@
#include <FEXCore/Utils/LogManager.h>
#include <alloca.h>
-#include <bits/types/struct_iovec.h>
+#include <linux/uio.h>
#include <cstdint>
#include <cstring>
#include <memory>

View File

@ -1,15 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Thread.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Thread.cpp
@@ -16,9 +16,9 @@
#include <FEXCore/Debug/InternalThreadState.h>
#include <FEXCore/HLE/Linux/ThreadManagement.h>
-#include <bits/types/siginfo_t.h>
-#include <bits/types/stack_t.h>
-#include <bits/types/struct_rusage.h>
+#include <asm-generic/siginfo.h>
+#include <asm-generic/signal.h>
+#include <linux/resource.h>
#include <errno.h>
#include <grp.h>
#include <linux/futex.h>

View File

@ -1,26 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Time.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Time.cpp
@@ -10,7 +10,6 @@
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
-#include <bits/types/clockid_t.h>
#include <stdint.h>
#include <syscall.h>
#include <sys/stat.h>
@@ -165,6 +164,7 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X32(futimesat, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, const timeval32 times[2]) -> uint64_t {
uint64_t Result = 0;
if (times) {
@@ -177,6 +177,7 @@
}
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_X32(utimensat, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, const compat_ptr<timespec32> times, int flags) -> uint64_t {
uint64_t Result = 0;

View File

@ -1,10 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Timer.cpp
+++ b/Source/Tests/LinuxSyscalls/x32/Timer.cpp
@@ -11,7 +11,6 @@
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
-#include <bits/types/timer_t.h>
#include <stdint.h>
#include <syscall.h>
#include <sys/time.h>

View File

@ -1,55 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x32/Types.h
+++ b/Source/Tests/LinuxSyscalls/x32/Types.h
@@ -12,23 +12,25 @@
#include <linux/types.h>
#include <asm/ipcbuf.h>
#include <asm/shmbuf.h>
-#include <bits/types/stack_t.h>
+#include <asm-generic/signal.h>
#include <cstdint>
#include <cstring>
#include <fcntl.h>
#include <limits>
#include <sys/ipc.h>
-#include <mqueue.h>
+#include <linux/mqueue.h>
#include <signal.h>
#include <sys/msg.h>
#include <sys/resource.h>
-#include <sys/sem.h>
+#include <linux/sem.h>
+#define semid_ds semid64_ds
#include <sys/shm.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/times.h>
+#include <linux/timex.h>
#include <sys/uio.h>
#include <time.h>
#include <type_traits>
@@ -387,10 +389,13 @@
uint32_t st_blksize;
uint32_t st_blocks; /* Number 512-byte blocks allocated. */
uint32_t st_atime_;
+#undef st_atime_nsec
uint32_t st_atime_nsec;
uint32_t st_mtime_;
+#undef st_mtime_nsec
uint32_t st_mtime_nsec;
uint32_t st_ctime_;
+#undef st_ctime_nsec
uint32_t st_ctime_nsec;
uint32_t __unused4;
uint32_t __unused5;
@@ -1164,9 +1169,6 @@
static_assert(std::is_trivial<sigval32>::value, "Needs to be trivial");
static_assert(sizeof(sigval32) == 4, "Incorrect size");
-constexpr size_t SIGEV_MAX_SIZE = 64;
-constexpr size_t SIGEV_PAD_SIZE = (SIGEV_MAX_SIZE - (sizeof(int32_t) * 2 + sizeof(sigval32))) / sizeof(int32_t);
-
struct
FEX_ANNOTATE("fex-match")
sigevent32 {

View File

@ -1,29 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x64/FD.cpp
+++ b/Source/Tests/LinuxSyscalls/x64/FD.cpp
@@ -56,10 +56,12 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X64_PASS(futimesat, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, const struct timeval times[2]) -> uint64_t {
uint64_t Result = ::futimesat(dirfd, pathname, times);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_X64_PASS(utimensat, [](FEXCore::Core::CpuStateFrame *Frame, int dirfd, const char *pathname, const struct timespec times[2], int flags) -> uint64_t {
uint64_t Result = ::syscall(SYSCALL_DEF(utimensat), dirfd, pathname, times, flags);
@@ -241,11 +243,13 @@
SYSCALL_ERRNO();
});
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X64_PASS(sync_file_range, [](FEXCore::Core::CpuStateFrame *Frame, int fd, off64_t offset, off64_t nbytes, unsigned int flags) -> uint64_t {
// Flags don't need remapped
uint64_t Result = ::sync_file_range(fd, offset, nbytes, flags);
SYSCALL_ERRNO();
});
+#endif
REGISTER_SYSCALL_IMPL_X64_PASS(fallocate, [](FEXCore::Core::CpuStateFrame *Frame, int fd, int mode, off_t offset, off_t len) -> uint64_t {
uint64_t Result = ::fallocate(fd, mode, offset, len);

View File

@ -1,20 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x64/Msg.cpp
+++ b/Source/Tests/LinuxSyscalls/x64/Msg.cpp
@@ -7,12 +7,16 @@
#include "Tests/LinuxSyscalls/Syscalls.h"
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
-#include <mqueue.h>
+#include <linux/mqueue.h>
#include <stddef.h>
#include <stdint.h>
#include <syscall.h>
#include <unistd.h>
+#ifdef __ANDROID__
+typedef int mqd_t;
+#endif
+
namespace FEXCore::Core {
struct CpuStateFrame;
}

View File

@ -1,26 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x64/Semaphore.cpp
+++ b/Source/Tests/LinuxSyscalls/x64/Semaphore.cpp
@@ -12,7 +12,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <sys/sem.h>
+#include <linux/sem.h>
namespace FEXCore::Core {
struct CpuStateFrame;
@@ -22,6 +22,7 @@
namespace FEX::HLE::x64 {
void RegisterSemaphore() {
+#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
REGISTER_SYSCALL_IMPL_X64_PASS(semop, [](FEXCore::Core::CpuStateFrame *Frame, int semid, struct sembuf *sops, size_t nsops) -> uint64_t {
uint64_t Result = ::semop(semid, sops, nsops);
SYSCALL_ERRNO();
@@ -87,5 +88,6 @@
}
SYSCALL_ERRNO();
});
+#endif
}
}

View File

@ -1,13 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x64/Thread.cpp
+++ b/Source/Tests/LinuxSyscalls/x64/Thread.cpp
@@ -14,8 +14,8 @@
#include <FEXCore/Debug/InternalThreadState.h>
#include <FEXCore/HLE/Linux/ThreadManagement.h>
-#include <bits/types/siginfo_t.h>
-#include <bits/types/stack_t.h>
+#include <asm-generic/siginfo.h>
+#include <asm-generic/signal.h>
#include <sched.h>
#include <stddef.h>
#include <syscall.h>

View File

@ -1,29 +0,0 @@
--- a/Source/Tests/LinuxSyscalls/x64/Types.h
+++ b/Source/Tests/LinuxSyscalls/x64/Types.h
@@ -13,7 +13,9 @@
#include <asm/posix_types.h>
#include <asm/sembuf.h>
#include <cstdint>
-#include <sys/sem.h>
+#include <linux/sem.h>
+#define semid_ds semid64_ds
+#include <sys/ipc.h>
#include <sys/stat.h>
#include <type_traits>
@@ -128,11 +130,15 @@
__kernel_long_t st_blocks; /* Number 512-byte blocks allocated. */
__kernel_ulong_t st_atime_;
+#undef st_atime_nsec
__kernel_ulong_t st_atime_nsec;
__kernel_ulong_t st_mtime_;
+#undef st_mtime_nsec
__kernel_ulong_t st_mtime_nsec;
__kernel_ulong_t st_ctime_;
+#undef st_ctime_nsec
__kernel_ulong_t st_ctime_nsec;
+#undef __unused
__kernel_long_t __unused[3];
guest_stat() = delete;

View File

@ -1,11 +0,0 @@
--- a/Source/Tools/FEXMountDaemon/Main.cpp
+++ b/Source/Tools/FEXMountDaemon/Main.cpp
@@ -2,7 +2,7 @@
#include <FEXHeaderUtils/Syscalls.h>
#include <atomic>
-#include <bits/types/siginfo_t.h>
+#include <asm-generic/siginfo.h>
#include <chrono>
#include <condition_variable>
#include <cstdlib>

View File

@ -2,15 +2,18 @@ TERMUX_PKG_HOMEPAGE=https://wiki.fex-emu.org/index.php/Main_Page
TERMUX_PKG_DESCRIPTION="Fast x86 emulation frontend"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=2201
TERMUX_PKG_VERSION=2203
TERMUX_PKG_SRCURL=https://github.com/FEX-Emu/FEX.git
TERMUX_PKG_GIT_BRANCH=FEX-${TERMUX_PKG_VERSION}
TERMUX_PKG_DEPENDS="libandroid-shmem, libc++"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DCMAKE_BUILD_TYPE=Release
-DENABLE_STATIC_PIE=False
-DBUILD_TESTS=OFF
-DENABLE_LTO=OFF
-DENABLE_JEMALLOC=OFF
-DENABLE_OFFLINE_TELEMETRY=OFF
-DENABLE_TERMUX_BUILD=True
"
TERMUX_PKG_BLACKLISTED_ARCHES="arm, i686, x86_64"

View File

@ -0,0 +1,654 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58850f43..602acd62 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,7 @@ option(ENABLE_COMPILE_TIME_TRACE "Enables time trace compile option" FALSE)
option(ENABLE_LIBCXX "Enables LLVM libc++" FALSE)
option(ENABLE_INTERPRETER "Enables FEX's Interpreter" FALSE)
option(ENABLE_CCACHE "Enables ccache for compile caching" TRUE)
+option(ENABLE_TERMUX_BUILD "Forces building for Termux on a non-Termux build machine" FALSE)
set (X86_C_COMPILER "x86_64-linux-gnu-gcc" CACHE STRING "c compiler for compiling x86 guest libs")
set (X86_CXX_COMPILER "x86_64-linux-gnu-g++" CACHE STRING "c++ compiler for compiling x86 guest libs")
@@ -115,59 +116,7 @@ if (NOT ENABLE_OFFLINE_TELEMETRY)
add_definitions(-DFEX_DISABLE_TELEMETRY=1)
endif()
-# Check if the build target page size is 4096
-include(CheckCSourceRuns)
-
-check_c_source_runs(
- "#include <unistd.h>
- int main(int argc, char* argv[])
- {
- return getpagesize() == 4096 ? 0 : 1;
- }"
- PAGEFILE_RESULT
- )
-
-if (NOT ${PAGEFILE_RESULT})
- message(FATAL_ERROR "Host PAGE_SIZE is not 4096. Can't build on this target")
-endif()
-
-include(CheckCXXSourceCompiles)
-check_cxx_source_compiles(
-"#include <sys/user.h>
- int main() {
- return PAGE_SIZE;
- }
- "
- HAS_PAGESIZE)
-
-check_cxx_source_compiles(
-"#include <sys/user.h>
- int main() {
- return PAGE_SHIFT;
- }
- "
- HAS_PAGESHIFT)
-
-check_cxx_source_compiles(
-"#include <sys/user.h>
- int main() {
- return PAGE_MASK;
- }
- "
- HAS_PAGEMASK)
-
-if (NOT HAS_PAGESIZE)
- add_definitions(-DPAGE_SIZE=4096)
-endif()
-
-if (NOT HAS_PAGESHIFT)
- add_definitions(-DPAGE_SHIFT=12)
-endif()
-if (NOT HAS_PAGEMASK)
- add_definitions("-DPAGE_MASK=(~(PAGE_SIZE-1))")
-endif()
-
-if(DEFINED ENV{TERMUX_VERSION})
+if(DEFINED ENV{TERMUX_VERSION} OR ENABLE_TERMUX_BUILD)
add_definitions(-DTERMUX_BUILD=1)
set(TERMUX_BUILD 1)
# Termux doesn't support Jemalloc due to bad interactions between emutls, jemalloc, and scudo
diff --git a/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp b/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp
index 561f9915..2062d4e6 100644
--- a/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp
+++ b/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp
@@ -15,6 +15,7 @@ $end_info$
#include <FEXCore/Utils/BucketList.h>
#include <FEXCore/Utils/LogManager.h>
#include <FEXCore/Utils/MathUtils.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <algorithm>
#include <cstddef>
@@ -62,7 +63,7 @@ namespace {
};
static_assert(sizeof(RegisterNode) == 128 * 4);
- constexpr size_t REGISTER_NODES_PER_PAGE = PAGE_SIZE / sizeof(RegisterNode);
+ constexpr size_t REGISTER_NODES_PER_PAGE = FHU::FEX_PAGE_SIZE / sizeof(RegisterNode);
struct RegisterSet {
std::vector<RegisterClass> Classes;
diff --git a/External/FEXCore/Source/Utils/Allocator.cpp b/External/FEXCore/Source/Utils/Allocator.cpp
index 72b0f5a8..a2605eb8 100644
--- a/External/FEXCore/Source/Utils/Allocator.cpp
+++ b/External/FEXCore/Source/Utils/Allocator.cpp
@@ -3,6 +3,7 @@
#include <FEXCore/Utils/CompilerDefs.h>
#include <FEXCore/Utils/LogManager.h>
#include <FEXHeaderUtils/Syscalls.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <array>
#include <sys/mman.h>
@@ -110,10 +111,10 @@ namespace FEXCore::Allocator {
for (int i = 0; i < 64; ++i) {
// Try grabbing a some of the top pages of the range
// x86 allocates some high pages in the top end
- void *Ptr = ::mmap(reinterpret_cast<void*>(Size - PAGE_SIZE * i), PAGE_SIZE, PROT_NONE, MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void *Ptr = ::mmap(reinterpret_cast<void*>(Size - FHU::FEX_PAGE_SIZE * i), FHU::FEX_PAGE_SIZE, PROT_NONE, MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (Ptr != (void*)~0ULL) {
- ::munmap(Ptr, PAGE_SIZE);
- if (Ptr == (void*)(Size - PAGE_SIZE * i)) {
+ ::munmap(Ptr, FHU::FEX_PAGE_SIZE);
+ if (Ptr == (void*)(Size - FHU::FEX_PAGE_SIZE * i)) {
return true;
}
}
diff --git a/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp b/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp
index 3dd72671..cc29fd00 100644
--- a/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp
+++ b/External/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp
@@ -6,6 +6,7 @@
#include <FEXCore/Utils/MathUtils.h>
#include <FEXHeaderUtils/ScopedSignalMask.h>
#include <FEXHeaderUtils/Syscalls.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <algorithm>
#include <array>
@@ -43,8 +44,8 @@ namespace Alloc::OSAllocator {
// Lower bound is the starting of the range just past the lower 32bits
constexpr static uintptr_t LOWER_BOUND = 0x1'0000'0000ULL;
- uintptr_t UPPER_BOUND_PAGE = UPPER_BOUND / PAGE_SIZE;
- constexpr static uintptr_t LOWER_BOUND_PAGE = LOWER_BOUND / PAGE_SIZE;
+ uintptr_t UPPER_BOUND_PAGE = UPPER_BOUND / FHU::FEX_PAGE_SIZE;
+ constexpr static uintptr_t LOWER_BOUND_PAGE = LOWER_BOUND / FHU::FEX_PAGE_SIZE;
struct ReservedVMARegion {
uintptr_t Base;
@@ -81,19 +82,19 @@ namespace Alloc::OSAllocator {
// 0x100'0000 Pages
// 1 bit per page for tracking means 0x20'0000 (Pages / 8) bytes of flex space
// Which is 2MB of tracking
- uint64_t NumElements = (Size >> PAGE_SHIFT) * sizeof(uint64_t);
+ uint64_t NumElements = (Size >> FHU::FEX_PAGE_SHIFT) * sizeof(uint64_t);
return sizeof(LiveVMARegion) + FEXCore::FlexBitSet<uint64_t>::Size(NumElements);
}
static void InitializeVMARegionUsed(LiveVMARegion *Region, size_t AdditionalSize) {
- size_t SizeOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(Region->SlabInfo->RegionSize), PAGE_SIZE);
+ size_t SizeOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(Region->SlabInfo->RegionSize), FHU::FEX_PAGE_SIZE);
size_t SizePlusManagedData = SizeOfLiveRegion + AdditionalSize;
Region->FreeSpace = Region->SlabInfo->RegionSize - SizePlusManagedData;
- size_t NumPages = SizePlusManagedData >> PAGE_SHIFT;
+ size_t NumPages = SizePlusManagedData >> FHU::FEX_PAGE_SHIFT;
// Memset the full tracking to zero to state nothing used
- Region->UsedPages.MemSet(Region->SlabInfo->RegionSize >> PAGE_SHIFT);
+ Region->UsedPages.MemSet(Region->SlabInfo->RegionSize >> FHU::FEX_PAGE_SHIFT);
// Set our reserved pages
for (size_t i = 0; i < NumPages; ++i) {
// Set our used pages
@@ -119,7 +120,7 @@ namespace Alloc::OSAllocator {
ReservedRegions->erase(ReservedIterator);
// mprotect the new region we've allocated
- size_t SizeOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(ReservedRegion->RegionSize), PAGE_SIZE);
+ size_t SizeOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(ReservedRegion->RegionSize), FHU::FEX_PAGE_SIZE);
size_t SizePlusManagedData = UsedSize + SizeOfLiveRegion;
[[maybe_unused]] auto Res = mprotect(reinterpret_cast<void*>(ReservedRegion->Base), SizePlusManagedData, PROT_READ | PROT_WRITE);
@@ -147,7 +148,7 @@ void OSAllocator_64Bit::DetermineVASize() {
size_t Bits = FEXCore::Allocator::DetermineVASize();
uintptr_t Size = 1ULL << Bits;
UPPER_BOUND = Size;
- UPPER_BOUND_PAGE = UPPER_BOUND / PAGE_SIZE;
+ UPPER_BOUND_PAGE = UPPER_BOUND / FHU::FEX_PAGE_SIZE;
}
void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
@@ -160,13 +161,13 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
uint64_t Addr = reinterpret_cast<uint64_t>(addr);
// Addr must be page aligned
- if (Addr & ~PAGE_MASK) {
+ if (Addr & ~FHU::FEX_PAGE_MASK) {
return reinterpret_cast<void*>(-EINVAL);
}
// If FD is provided then offset must also be page aligned
if (fd != -1 &&
- offset & ~PAGE_MASK) {
+ offset & ~FHU::FEX_PAGE_MASK) {
return reinterpret_cast<void*>(-EINVAL);
}
@@ -176,10 +177,10 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
}
bool Fixed = (flags & MAP_FIXED) || (flags & MAP_FIXED_NOREPLACE);
- length = FEXCore::AlignUp(length, PAGE_SIZE);
+ length = FEXCore::AlignUp(length, FHU::FEX_PAGE_SIZE);
uint64_t AddrEnd = Addr + length;
- size_t NumberOfPages = length / PAGE_SIZE;
+ size_t NumberOfPages = length / FHU::FEX_PAGE_SIZE;
// This needs a mutex to be thread safe
FHU::ScopedSignalMaskWithMutex lk(AllocationMutex);
@@ -223,14 +224,14 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
auto CheckIfRangeFits = [&AllocatedOffset](LiveVMARegion *Region, uint64_t length, int prot, int flags, int fd, off_t offset, uint64_t StartingPosition = 0) -> std::pair<LiveVMARegion*, void*> {
uint64_t AllocatedPage{};
- uint64_t NumberOfPages = length >> PAGE_SHIFT;
+ uint64_t NumberOfPages = length >> FHU::FEX_PAGE_SHIFT;
if (Region->FreeSpace >= length) {
uint64_t LastAllocation =
StartingPosition ?
- (StartingPosition - Region->SlabInfo->Base) >> PAGE_SHIFT
+ (StartingPosition - Region->SlabInfo->Base) >> FHU::FEX_PAGE_SHIFT
: Region->LastPageAllocation;
- size_t RegionNumberOfPages = Region->SlabInfo->RegionSize >> PAGE_SHIFT;
+ size_t RegionNumberOfPages = Region->SlabInfo->RegionSize >> FHU::FEX_PAGE_SHIFT;
// Backward scan
// We need to do a backward scan first to fill any holes
@@ -298,7 +299,7 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
}
if (AllocatedPage) {
- AllocatedOffset = Region->SlabInfo->Base + AllocatedPage * PAGE_SIZE;
+ AllocatedOffset = Region->SlabInfo->Base + AllocatedPage * FHU::FEX_PAGE_SIZE;
// We need to setup protections for this
void *MMapResult = ::mmap(reinterpret_cast<void*>(AllocatedOffset),
@@ -388,7 +389,7 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
if (!LiveRegion) {
// Couldn't find a fit in the live regions
// Allocate a new reserved region
- size_t lengthOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(length), PAGE_SIZE);
+ size_t lengthOfLiveRegion = FEXCore::AlignUp(LiveVMARegion::GetSizeWithFlexSet(length), FHU::FEX_PAGE_SIZE);
size_t lengthPlusManagedData = length + lengthOfLiveRegion;
for (auto it = ReservedRegions->begin(); it != ReservedRegions->end(); ++it) {
if ((*it)->RegionSize >= lengthPlusManagedData) {
@@ -402,7 +403,7 @@ void *OSAllocator_64Bit::Mmap(void *addr, size_t length, int prot, int flags, in
if (LiveRegion) {
// Mark the pages as used
uintptr_t RegionBegin = LiveRegion->SlabInfo->Base;
- uintptr_t MappedBegin = (AllocatedOffset - RegionBegin) >> PAGE_SHIFT;
+ uintptr_t MappedBegin = (AllocatedOffset - RegionBegin) >> FHU::FEX_PAGE_SHIFT;
for (size_t i = 0; i < NumberOfPages; ++i) {
LiveRegion->UsedPages.Set(MappedBegin + i);
@@ -428,11 +429,11 @@ int OSAllocator_64Bit::Munmap(void *addr, size_t length) {
uint64_t Addr = reinterpret_cast<uint64_t>(addr);
- if (Addr & ~PAGE_MASK) {
+ if (Addr & ~FHU::FEX_PAGE_MASK) {
return -EINVAL;
}
- if (length & ~PAGE_MASK) {
+ if (length & ~FHU::FEX_PAGE_MASK) {
return -EINVAL;
}
@@ -443,7 +444,7 @@ int OSAllocator_64Bit::Munmap(void *addr, size_t length) {
// This needs a mutex to be thread safe
FHU::ScopedSignalMaskWithMutex lk(AllocationMutex);
- length = FEXCore::AlignUp(length, PAGE_SIZE);
+ length = FEXCore::AlignUp(length, FHU::FEX_PAGE_SIZE);
uintptr_t PtrBegin = reinterpret_cast<uintptr_t>(addr);
uintptr_t PtrEnd = PtrBegin + length;
@@ -457,8 +458,8 @@ int OSAllocator_64Bit::Munmap(void *addr, size_t length) {
// Live region fully encompasses slab range
uint64_t FreedPages{};
- uint32_t SlabPageBegin = (PtrBegin - RegionBegin) >> PAGE_SHIFT;
- uint64_t PagesToFree = length >> PAGE_SHIFT;
+ uint32_t SlabPageBegin = (PtrBegin - RegionBegin) >> FHU::FEX_PAGE_SHIFT;
+ uint64_t PagesToFree = length >> FHU::FEX_PAGE_SHIFT;
for (size_t i = 0; i < PagesToFree; ++i) {
FreedPages += (*it)->UsedPages.TestAndClear(SlabPageBegin + i) ? 1 : 0;
diff --git a/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h b/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
index b69b1023..84bd2b59 100644
--- a/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
+++ b/External/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
@@ -4,6 +4,7 @@
#include "HostAllocator.h"
#include <FEXCore/Utils/MathUtils.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <bitset>
#include <cstddef>
@@ -87,9 +88,9 @@ namespace Alloc {
IntrusiveArenaAllocator(void* Ptr, size_t _Size)
: Begin {reinterpret_cast<uintptr_t>(Ptr)}
, Size {_Size} {
- uint64_t NumberOfPages = _Size / PAGE_SIZE;
+ uint64_t NumberOfPages = _Size / FHU::FEX_PAGE_SIZE;
uint64_t UsedBits = FEXCore::AlignUp(sizeof(IntrusiveArenaAllocator) +
- Size / PAGE_SIZE / 8, PAGE_SIZE);
+ Size / FHU::FEX_PAGE_SIZE / 8, FHU::FEX_PAGE_SIZE);
for (size_t i = 0; i < UsedBits; ++i) {
UsedPages.Set(i);
}
@@ -117,7 +118,7 @@ namespace Alloc {
void *do_allocate(std::size_t bytes, std::size_t alignment) override {
std::scoped_lock<std::mutex> lk{AllocationMutex};
- size_t NumberPages = FEXCore::AlignUp(bytes, PAGE_SIZE) / PAGE_SIZE;
+ size_t NumberPages = FEXCore::AlignUp(bytes, FHU::FEX_PAGE_SIZE) / FHU::FEX_PAGE_SIZE;
uintptr_t AllocatedOffset{};
@@ -161,7 +162,7 @@ namespace Alloc {
LastAllocatedPageOffset = AllocatedOffset + NumberPages;
// Now convert this base page to a pointer and return it
- return reinterpret_cast<void*>(Begin + AllocatedOffset * PAGE_SIZE);
+ return reinterpret_cast<void*>(Begin + AllocatedOffset * FHU::FEX_PAGE_SIZE);
}
return nullptr;
@@ -170,8 +171,8 @@ namespace Alloc {
void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) override {
std::scoped_lock<std::mutex> lk{AllocationMutex};
- uintptr_t PageOffset = (reinterpret_cast<uintptr_t>(p) - Begin) / PAGE_SIZE;
- size_t NumPages = FEXCore::AlignUp(bytes, PAGE_SIZE) / PAGE_SIZE;
+ uintptr_t PageOffset = (reinterpret_cast<uintptr_t>(p) - Begin) / FHU::FEX_PAGE_SIZE;
+ size_t NumPages = FEXCore::AlignUp(bytes, FHU::FEX_PAGE_SIZE) / FHU::FEX_PAGE_SIZE;
// Walk the allocation list and deallocate
uint64_t FreedPages{};
diff --git a/FEXHeaderUtils/FEXHeaderUtils/TypeDefines.h b/FEXHeaderUtils/FEXHeaderUtils/TypeDefines.h
new file mode 100644
index 00000000..8d75d4b0
--- /dev/null
+++ b/FEXHeaderUtils/FEXHeaderUtils/TypeDefines.h
@@ -0,0 +1,11 @@
+#pragma once
+#include <cstddef>
+
+namespace FHU {
+ // FEX assumes an operating page size of 4096
+ // To work around build systems that build on a 16k/64k page size, define our page size here
+ // Don't use the system provided PAGE_SIZE define because of this.
+ constexpr size_t FEX_PAGE_SIZE = 4096;
+ constexpr size_t FEX_PAGE_SHIFT = 12;
+ constexpr size_t FEX_PAGE_MASK = ~(FEX_PAGE_SIZE - 1);
+}
diff --git a/Source/Tests/HarnessHelpers.h b/Source/Tests/HarnessHelpers.h
index d15bf2dd..60f95c1d 100644
--- a/Source/Tests/HarnessHelpers.h
+++ b/Source/Tests/HarnessHelpers.h
@@ -22,6 +22,7 @@
#include <FEXCore/Utils/LogManager.h>
#include <FEXCore/Utils/MathUtils.h>
#include <FEXHeaderUtils/Syscalls.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <fmt/format.h>
@@ -396,14 +397,14 @@ namespace FEX::HarnessHelper {
};
if (LimitedSize) {
- DoMMap(0xe000'0000, PAGE_SIZE * 10);
+ DoMMap(0xe000'0000, FHU::FEX_PAGE_SIZE * 10);
// SIB8
// We test [-128, -126] (Bottom)
// We test [-8, 8] (Middle)
// We test [120, 127] (Top)
// Can fit in two pages
- DoMMap(0xe800'0000 - PAGE_SIZE, PAGE_SIZE * 2);
+ DoMMap(0xe800'0000 - FHU::FEX_PAGE_SIZE, FHU::FEX_PAGE_SIZE * 2);
}
else {
// This is scratch memory location and SIB8 location
@@ -413,7 +414,7 @@ namespace FEX::HarnessHelper {
}
// Map in the memory region for the test file
- size_t Length = FEXCore::AlignUp(RawFile.size(), PAGE_SIZE);
+ size_t Length = FEXCore::AlignUp(RawFile.size(), FHU::FEX_PAGE_SIZE);
Code_start_page = reinterpret_cast<uint64_t>(DoMMap(Code_start_page, Length));
mprotect(reinterpret_cast<void*>(Code_start_page), Length, PROT_READ | PROT_WRITE | PROT_EXEC);
RIP = Code_start_page;
@@ -446,7 +447,7 @@ namespace FEX::HarnessHelper {
bool Is64BitMode() const { return Config.Is64BitMode(); }
private:
- constexpr static uint64_t STACK_SIZE = PAGE_SIZE;
+ constexpr static uint64_t STACK_SIZE = FHU::FEX_PAGE_SIZE;
constexpr static uint64_t STACK_OFFSET = 0xc000'0000;
// Zero is special case to know when we are done
uint64_t Code_start_page = 0x1'0000;
diff --git a/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp b/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp
index 03b6d17f..422b7e95 100644
--- a/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp
+++ b/Source/Tests/LinuxSyscalls/LinuxAllocator.cpp
@@ -3,6 +3,7 @@
#include <FEXCore/Utils/MathUtils.h>
#include <FEXHeaderUtils/Syscalls.h>
+#include <FEXHeaderUtils/TypeDefines.h>
#include <bitset>
#include <map>
@@ -20,8 +21,8 @@ namespace FEX::HLE {
class MemAllocator32Bit final : public FEX::HLE::MemAllocator {
private:
static constexpr uint64_t BASE_KEY = 16;
- const uint64_t TOP_KEY = 0xFFFF'F000ULL >> PAGE_SHIFT;
- const uint64_t TOP_KEY32BIT = 0x1F'F000ULL >> PAGE_SHIFT;
+ const uint64_t TOP_KEY = 0xFFFF'F000ULL >> FHU::FEX_PAGE_SHIFT;
+ const uint64_t TOP_KEY32BIT = 0x1F'F000ULL >> FHU::FEX_PAGE_SHIFT;
public:
MemAllocator32Bit() {
@@ -132,10 +133,10 @@ uint64_t MemAllocator32Bit::FindPageRange_TopDown(uint64_t Start, size_t Pages)
void *MemAllocator32Bit::mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
std::scoped_lock<std::mutex> lk{AllocMutex};
- size_t PagesLength = FEXCore::AlignUp(length, PAGE_SIZE) >> PAGE_SHIFT;
+ size_t PagesLength = FEXCore::AlignUp(length, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
uintptr_t Addr = reinterpret_cast<uintptr_t>(addr);
- uintptr_t PageAddr = Addr >> PAGE_SHIFT;
+ uintptr_t PageAddr = Addr >> FHU::FEX_PAGE_SHIFT;
// Define MAP_FIXED_NOREPLACE ourselves to ensure we always parse this flag
constexpr int FEX_MAP_FIXED_NOREPLACE = 0x100000;
@@ -143,13 +144,13 @@ void *MemAllocator32Bit::mmap(void *addr, size_t length, int prot, int flags, in
(flags & FEX_MAP_FIXED_NOREPLACE));
// Both Addr and length must be page aligned
- if (Addr & ~PAGE_MASK) {
+ if (Addr & ~FHU::FEX_PAGE_MASK) {
return reinterpret_cast<void*>(-EINVAL);
}
// If we do have an fd then offset must be page aligned
if (fd != -1 &&
- offset & ~PAGE_MASK) {
+ offset & ~FHU::FEX_PAGE_MASK) {
return reinterpret_cast<void*>(-EINVAL);
}
@@ -190,7 +191,7 @@ restart:
{
// Try and map the range
void *MappedPtr = ::mmap(
- reinterpret_cast<void*>(LowerPage<< PAGE_SHIFT),
+ reinterpret_cast<void*>(LowerPage<< FHU::FEX_PAGE_SHIFT),
length,
prot,
flags | FEX_MAP_FIXED_NOREPLACE,
@@ -202,10 +203,10 @@ restart:
return reinterpret_cast<void*>(-errno);
}
else if (MappedPtr == MAP_FAILED ||
- MappedPtr >= reinterpret_cast<void*>(TOP_KEY << PAGE_SHIFT)) {
+ MappedPtr >= reinterpret_cast<void*>(TOP_KEY << FHU::FEX_PAGE_SHIFT)) {
// Handles the case where MAP_FIXED_NOREPLACE failed with MAP_FAILED
// or if the host system's kernel isn't new enough then it returns the wrong pointer
- if (MappedPtr >= reinterpret_cast<void*>(TOP_KEY << PAGE_SHIFT)) {
+ if (MappedPtr >= reinterpret_cast<void*>(TOP_KEY << FHU::FEX_PAGE_SHIFT)) {
// Make sure to munmap this so we don't leak memory
::munmap(MappedPtr, length);
}
@@ -251,14 +252,14 @@ restart:
}
else {
void *MappedPtr = ::mmap(
- reinterpret_cast<void*>(PageAddr << PAGE_SHIFT),
- PagesLength << PAGE_SHIFT,
+ reinterpret_cast<void*>(PageAddr << FHU::FEX_PAGE_SHIFT),
+ PagesLength << FHU::FEX_PAGE_SHIFT,
prot,
flags,
fd,
offset);
- if (MappedPtr >= reinterpret_cast<void*>(TOP_KEY << PAGE_SHIFT) &&
+ if (MappedPtr >= reinterpret_cast<void*>(TOP_KEY << FHU::FEX_PAGE_SHIFT) &&
(flags & FEX_MAP_FIXED_NOREPLACE)) {
// Handles the case where MAP_FIXED_NOREPLACE isn't handled by the host system's
// kernel and returns the wrong pointer
@@ -279,19 +280,19 @@ restart:
int MemAllocator32Bit::munmap(void *addr, size_t length) {
std::scoped_lock<std::mutex> lk{AllocMutex};
- size_t PagesLength = FEXCore::AlignUp(length, PAGE_SIZE) >> PAGE_SHIFT;
+ size_t PagesLength = FEXCore::AlignUp(length, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
uintptr_t Addr = reinterpret_cast<uintptr_t>(addr);
- uintptr_t PageAddr = Addr >> PAGE_SHIFT;
+ uintptr_t PageAddr = Addr >> FHU::FEX_PAGE_SHIFT;
uintptr_t PageEnd = PageAddr + PagesLength;
// Both Addr and length must be page aligned
- if (Addr & ~PAGE_MASK) {
+ if (Addr & ~FHU::FEX_PAGE_MASK) {
return -EINVAL;
}
- if (length & ~PAGE_MASK) {
+ if (length & ~FHU::FEX_PAGE_MASK) {
return -EINVAL;
}
@@ -307,7 +308,7 @@ int MemAllocator32Bit::munmap(void *addr, size_t length) {
while (PageAddr != PageEnd) {
// Always pass to munmap, it may be something allocated we aren't tracking
- int Result = ::munmap(reinterpret_cast<void*>(PageAddr << PAGE_SHIFT), PAGE_SIZE);
+ int Result = ::munmap(reinterpret_cast<void*>(PageAddr << FHU::FEX_PAGE_SHIFT), FHU::FEX_PAGE_SIZE);
if (Result != 0) {
return -errno;
}
@@ -323,8 +324,8 @@ int MemAllocator32Bit::munmap(void *addr, size_t length) {
}
void *MemAllocator32Bit::mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address) {
- size_t OldPagesLength = FEXCore::AlignUp(old_size, PAGE_SIZE) >> PAGE_SHIFT;
- size_t NewPagesLength = FEXCore::AlignUp(new_size, PAGE_SIZE) >> PAGE_SHIFT;
+ size_t OldPagesLength = FEXCore::AlignUp(old_size, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
+ size_t NewPagesLength = FEXCore::AlignUp(new_size, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
{
std::scoped_lock<std::mutex> lk{AllocMutex};
@@ -335,12 +336,12 @@ void *MemAllocator32Bit::mremap(void *old_address, size_t old_size, size_t new_s
if (!(flags & MREMAP_DONTUNMAP)) {
// Unmap the old location
uintptr_t OldAddr = reinterpret_cast<uintptr_t>(old_address);
- SetFreePages(OldAddr >> PAGE_SHIFT, OldPagesLength);
+ SetFreePages(OldAddr >> FHU::FEX_PAGE_SHIFT, OldPagesLength);
}
// Map the new pages
uintptr_t NewAddr = reinterpret_cast<uintptr_t>(MappedPtr);
- SetUsedPages(NewAddr >> PAGE_SHIFT, NewPagesLength);
+ SetUsedPages(NewAddr >> FHU::FEX_PAGE_SHIFT, NewPagesLength);
}
else {
return reinterpret_cast<void*>(-errno);
@@ -348,15 +349,15 @@ void *MemAllocator32Bit::mremap(void *old_address, size_t old_size, size_t new_s
}
else {
uintptr_t OldAddr = reinterpret_cast<uintptr_t>(old_address);
- uintptr_t OldPageAddr = OldAddr >> PAGE_SHIFT;
+ uintptr_t OldPageAddr = OldAddr >> FHU::FEX_PAGE_SHIFT;
if (NewPagesLength < OldPagesLength) {
void *MappedPtr = ::mremap(old_address, old_size, new_size, flags & ~MREMAP_MAYMOVE);
if (MappedPtr != MAP_FAILED) {
// Clear the pages that we just shrunk
- size_t NewPagesLength = FEXCore::AlignUp(new_size, PAGE_SIZE) >> PAGE_SHIFT;
- uintptr_t NewPageAddr = reinterpret_cast<uintptr_t>(MappedPtr) >> PAGE_SHIFT;
+ size_t NewPagesLength = FEXCore::AlignUp(new_size, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
+ uintptr_t NewPageAddr = reinterpret_cast<uintptr_t>(MappedPtr) >> FHU::FEX_PAGE_SHIFT;
SetFreePages(NewPageAddr + NewPagesLength, OldPagesLength - NewPagesLength);
return MappedPtr;
}
@@ -380,9 +381,9 @@ void *MemAllocator32Bit::mremap(void *old_address, size_t old_size, size_t new_s
if (MappedPtr != MAP_FAILED) {
// Map the new pages
- size_t NewPagesLength = FEXCore::AlignUp(new_size, PAGE_SIZE) >> PAGE_SHIFT;
+ size_t NewPagesLength = FEXCore::AlignUp(new_size, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
uintptr_t NewAddr = reinterpret_cast<uintptr_t>(MappedPtr);
- SetUsedPages(NewAddr >> PAGE_SHIFT, NewPagesLength);
+ SetUsedPages(NewAddr >> FHU::FEX_PAGE_SHIFT, NewPagesLength);
return MappedPtr;
}
else if (!(flags & MREMAP_MAYMOVE)) {
@@ -416,13 +417,13 @@ void *MemAllocator32Bit::mremap(void *old_address, size_t old_size, size_t new_s
// If we have both MREMAP_DONTUNMAP not set and the new pointer is at a new location
// Make sure to clear the old mapping
uintptr_t OldAddr = reinterpret_cast<uintptr_t>(old_address);
- SetFreePages(OldAddr >> PAGE_SHIFT , OldPagesLength);
+ SetFreePages(OldAddr >> FHU::FEX_PAGE_SHIFT , OldPagesLength);
}
// Map the new pages
- size_t NewPagesLength = FEXCore::AlignUp(new_size, PAGE_SIZE) >> PAGE_SHIFT;
+ size_t NewPagesLength = FEXCore::AlignUp(new_size, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
uintptr_t NewAddr = reinterpret_cast<uintptr_t>(MappedPtr);
- SetUsedPages(NewAddr >> PAGE_SHIFT, NewPagesLength);
+ SetUsedPages(NewAddr >> FHU::FEX_PAGE_SHIFT, NewPagesLength);
return MappedPtr;
}
@@ -445,7 +446,7 @@ uint64_t MemAllocator32Bit::shmat(int shmid, const void* shmaddr, int shmflg, ui
}
uintptr_t NewAddr = reinterpret_cast<uintptr_t>(Result);
- uintptr_t NewPageAddr = NewAddr >> PAGE_SHIFT;
+ uintptr_t NewPageAddr = NewAddr >> FHU::FEX_PAGE_SHIFT;
// Add to the map
PageToShm[NewPageAddr] = shmid;
@@ -457,7 +458,7 @@ uint64_t MemAllocator32Bit::shmat(int shmid, const void* shmaddr, int shmflg, ui
if (shmctl(shmid, IPC_STAT, &buf) == 0) {
// Map the new pages
- size_t NewPagesLength = buf.shm_segsz >> PAGE_SHIFT;
+ size_t NewPagesLength = buf.shm_segsz >> FHU::FEX_PAGE_SHIFT;
SetUsedPages(NewPageAddr, NewPagesLength);
}
@@ -475,7 +476,7 @@ uint64_t MemAllocator32Bit::shmat(int shmid, const void* shmaddr, int shmflg, ui
uint64_t PagesLength{};
if (shmctl(shmid, IPC_STAT, &buf) == 0) {
- PagesLength = FEXCore::AlignUp(buf.shm_segsz, PAGE_SIZE) >> PAGE_SHIFT;
+ PagesLength = FEXCore::AlignUp(buf.shm_segsz, FHU::FEX_PAGE_SIZE) >> FHU::FEX_PAGE_SHIFT;
}
else {
return -EINVAL;
@@ -501,7 +502,7 @@ restart:
// Try and map the range
void *MappedPtr = ::shmat(
shmid,
- reinterpret_cast<const void*>(LowerPage << PAGE_SHIFT),
+ reinterpret_cast<const void*>(LowerPage << FHU::FEX_PAGE_SHIFT),
shmflg);
if (MappedPtr == MAP_FAILED) {
@@ -544,7 +545,7 @@ restart:
}
}
uint64_t MemAllocator32Bit::shmdt(const void* shmaddr) {
- uint32_t AddrPage = reinterpret_cast<uint64_t>(shmaddr) >> PAGE_SHIFT;
+ uint32_t AddrPage = reinterpret_cast<uint64_t>(shmaddr) >> FHU::FEX_PAGE_SHIFT;
auto it = PageToShm.find(AddrPage);
if (it == PageToShm.end()) {