Files
termux-packages/packages/fex/fex.patch
2024-01-23 08:09:58 +00:00

211 lines
7.2 KiB
Diff

diff --git a/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h b/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
index 97a879a03..436fd16ee 100644
--- a/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
+++ b/FEXCore/Source/Utils/Allocator/IntrusiveArenaAllocator.h
@@ -9,19 +9,21 @@
#include <bitset>
#include <cstddef>
-#ifdef TERMUX_BUILD
+
#ifdef __has_include
#if __has_include(<memory_resource>)
-#error Termux <experimental/memory_resource> workaround can be removed
-#endif
-#endif
+#include <memory_resource>
+namespace fex_pmr = std::pmr;
+#else
#include <experimental/memory_resource>
#include <experimental/list>
namespace fex_pmr = std::experimental::pmr;
+#endif
#else
#include <memory_resource>
namespace fex_pmr = std::pmr;
#endif
+
#include <sys/user.h>
#include <mutex>
diff --git a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h
index 85d2d914d..9997d03cb 100644
--- a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h
+++ b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h
@@ -117,16 +117,37 @@ namespace FEXCore::Allocator {
inline void *valloc(size_t size)
{
#ifdef __ANDROID__
+#if __ANDROID_API__ < 28
+ // https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/aligned_alloc.h
+ // https://android.googlesource.com/platform/bionic/+/main/libc/platform/bionic/page.h
+ // alignment = 1 segfault in Android, 4096 is the minimum
+ void* __result = nullptr;
+ (void)::posix_memalign(&__result, 4096, size);
+ return __result;
+#else
return ::aligned_alloc(4096, size);
+#endif
#else
return ::valloc(size);
#endif
}
+#ifdef __ANDROID__
+ inline int posix_memalign(void** r, size_t a, size_t s) { return ::posix_memalign(r, 4096, s); }
+#else
inline int posix_memalign(void** r, size_t a, size_t s) { return ::posix_memalign(r, a, s); }
+#endif
inline void *realloc(void* ptr, size_t size) { return ::realloc(ptr, size); }
inline void free(void* ptr) { return ::free(ptr); }
inline size_t malloc_usable_size(void *ptr) { return ::malloc_usable_size(ptr); }
+#if defined(__ANDROID__) && __ANDROID_API__ < 28
+ inline void *aligned_alloc(size_t a, size_t s) {
+ void* __result = nullptr;
+ (void)::posix_memalign(&__result, 4096, s);
+ return __result;
+ }
+#else
inline void *aligned_alloc(size_t a, size_t s) { return ::aligned_alloc(a, s); }
+#endif
inline void aligned_free(void* ptr) { return ::free(ptr); }
#endif
diff --git a/Source/Common/Config.cpp b/Source/Common/Config.cpp
index 5d6cfed33..74918edd1 100644
--- a/Source/Common/Config.cpp
+++ b/Source/Common/Config.cpp
@@ -371,6 +371,7 @@ namespace JSON {
FEXCore::Config::Load();
auto Args = FEX::ArgLoader::Get();
+ size_t i = 0;
if (LoadProgramConfig) {
if (Args.empty()) {
@@ -378,8 +379,19 @@ namespace JSON {
return {};
}
- Args[0] = RecoverGuestProgramFilename(std::move(Args[0]), ExecFDInterp, ProgramFDFromEnv);
- fextl::string& Program = Args[0];
+ // really bad workaround for Termux Proot
+ for (size_t j=0; j<Args.size(); j++) {
+ if (Args[j] == "-U") continue;
+ if (Args[j] == "LD_LIBRARY_PATH") continue;
+ if (Args[j] == "-E") continue;
+ if (Args[j] == "LD_PRELOAD=") continue;
+ if (Args[j] == "-0") continue;
+ i=j;
+ break;
+ }
+
+ Args[i] = RecoverGuestProgramFilename(std::move(Args[i]), ExecFDInterp, ProgramFDFromEnv);
+ fextl::string& Program = Args[i];
bool Wine = false;
fextl::string ProgramName;
diff --git a/Source/Tools/CMakeLists.txt b/Source/Tools/CMakeLists.txt
index 357d16cd0..08c836886 100644
--- a/Source/Tools/CMakeLists.txt
+++ b/Source/Tools/CMakeLists.txt
@@ -5,10 +5,10 @@ if (NOT MINGW_BUILD)
add_subdirectory(FEXConfig/)
endif()
- if (NOT TERMUX_BUILD)
+ #if (NOT TERMUX_BUILD)
# Disable FEXRootFSFetcher on Termux, it doesn't even work there
add_subdirectory(FEXRootFSFetcher/)
- endif()
+ #endif()
if (ENABLE_GDB_SYMBOLS)
add_subdirectory(FEXGDBReader/)
diff --git a/Source/Tools/FEXLoader/ELFCodeLoader.h b/Source/Tools/FEXLoader/ELFCodeLoader.h
index 03ff0fa34..d29620b14 100644
--- a/Source/Tools/FEXLoader/ELFCodeLoader.h
+++ b/Source/Tools/FEXLoader/ELFCodeLoader.h
@@ -182,7 +182,11 @@ class ELFCodeLoader final : public FEXCore::CodeLoader {
do {
// This is guaranteed to not be interrupted by a signal,
// since fewer than 256 bytes of RNG data are requested
+#if defined(__ANDROID__) && __ANDROID_API__ < 28
+ Result = syscall(__NR_getrandom, Data, DataSize, 0);
+#else
Result = getrandom(Data, DataSize, 0);
+#endif
} while (Result != -1 && Result != DataSize);
return Result != -1;
diff --git a/Source/Tools/FEXLoader/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/FEXLoader/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp
index 03b73436c..fc1041b4b 100644
--- a/Source/Tools/FEXLoader/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp
+++ b/Source/Tools/FEXLoader/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp
@@ -32,6 +32,14 @@ $end_info$
#include <unistd.h>
#include <utility>
+#if defined(__ANDROID__) && __ANDROID_API__ < 30
+#include <sys/mman.h>
+#define memfd_create(name,flags) syscall(SYS_memfd_create,name,flags)
+#endif
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+
namespace FEX::EmulatedFile {
/**
* @brief Generates a temporary file using raw FDs
diff --git a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp
index db49bc7dc..99638dbec 100644
--- a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp
+++ b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp
@@ -40,6 +40,18 @@ $end_info$
#define SS_AUTODISARM (1U << 31)
#endif
+/*
+/home/builder/.termux-build/fex/src/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp:931:24: error: expected unqualified-id
+ constexpr uint32_t SA_RESTORER = 0x04000000;
+ ^
+/home/builder/.termux-build/_cache/android-r26b-api-24-v0/sysroot/usr/include/aarch64-linux-android/asm/signal.h:21:21: note: expanded from macro 'SA_RESTORER'
+#define SA_RESTORER 0x04000000
+ ^
+*/
+#ifdef SA_RESTORER
+#undef SA_RESTORER
+#endif
+
namespace FEX::HLE {
#ifdef _M_X86_64
__attribute__((naked))
diff --git a/Source/Tools/FEXLoader/VDSO_Emulation.cpp b/Source/Tools/FEXLoader/VDSO_Emulation.cpp
index 0572ec148..b8e642267 100644
--- a/Source/Tools/FEXLoader/VDSO_Emulation.cpp
+++ b/Source/Tools/FEXLoader/VDSO_Emulation.cpp
@@ -18,6 +18,15 @@
#include <sys/time.h>
#include <unistd.h>
+// Add macros which are missing in some versions of <elf.h>
+#ifndef ELF32_ST_VISIBILITY
+#define ELF32_ST_VISIBILITY(o) ((o) & 0x3)
+#endif
+
+#ifndef ELF64_ST_VISIBILITY
+#define ELF64_ST_VISIBILITY(o) ((o) & 0x3)
+#endif
+
namespace FEX::VDSO {
FEXCore::Context::VDSOSigReturn VDSOPointers{};
namespace VDSOHandlers {
@@ -253,7 +262,7 @@ namespace FEX::VDSO {
int rv;
} *args = reinterpret_cast<ArgsRV_t*>(ArgsRV);
- int Result = ::getcpu(args->cpu, args->node);
+ int Result = FHU::Syscalls::getcpu(args->cpu, args->node);
args->rv = SyscallRet(Result);
}
}