JIT: fix building with ENABLE_JIT on OpenBSD targets (#2398)

* sockaddr_in is a forward declaration on *BSD, explicitly include the correct header

* fix building with ENABLE_JIT on OpenBSD targets

* add wxallowed linker flag for openbsd targets

* OpenBSD armjit sc_exr -> sc_elr

* wxallowed -> wxneeded

* force mmap for jit on OpenBSD

* disable fastmem on OpenBSD

* fix typo in disabling fastmem for OpenBSD

* add missing space in this if
This commit is contained in:
Izzy Meyer
2025-08-29 15:27:11 -05:00
committed by GitHub
parent 18a4885c22
commit 631080aa4e
3 changed files with 13 additions and 5 deletions

View File

@ -25,7 +25,7 @@ std::mutex globalMutex;
#define APPLE_AARCH64
#endif
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__)
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
static constexpr size_t NumCodeMemSlices = 4;
static constexpr size_t CodeMemoryAlignedSize = NumCodeMemSlices * CodeMemorySliceSize;
@ -46,7 +46,7 @@ void* AllocateCodeMem()
{
std::lock_guard guard(globalMutex);
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__)
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
if (AvailableCodeMemSlices)
{
int slice = __builtin_ctz(AvailableCodeMemSlices);
@ -73,7 +73,7 @@ void FreeCodeMem(void* codeMem)
{
std::lock_guard guard(globalMutex);
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__)
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
for (int i = 0; i < NumCodeMemSlices; i++)
{
if (codeMem == &GetAlignedCodeMemoryStart()[CodeMemorySliceSize * i])
@ -102,7 +102,7 @@ void Init()
#ifdef _WIN32
DWORD dummy;
VirtualProtect(GetAlignedCodeMemoryStart(), CodeMemoryAlignedSize, PAGE_EXECUTE_READWRITE, &dummy);
#elif defined(APPLE_AARCH64) || defined(__NetBSD__)
#elif defined(APPLE_AARCH64) || defined(__NetBSD__) || defined(__OpenBSD__)
// Apple aarch64 always uses dynamic allocation
#else
mprotect(GetAlignedCodeMemoryStart(), CodeMemoryAlignedSize, PROT_EXEC | PROT_READ | PROT_WRITE);

View File

@ -83,6 +83,8 @@
#define CONTEXT_PC uc_mcontext.mc_rip
#elif defined(__NetBSD__)
#define CONTEXT_PC uc_mcontext.__gregs[_REG_RIP]
#elif defined(__OpenBSD__)
#define CONTEXT_PC sc_rip
#endif
#elif defined(__aarch64__)
#if defined(_WIN32)
@ -95,6 +97,8 @@
#define CONTEXT_PC uc_mcontext.mc_gpregs.gp_elr
#elif defined(__NetBSD__)
#define CONTEXT_PC uc_mcontext.__gregs[_REG_PC]
#elif defined(__OpenBSD__)
#define CONTEXT_PC sc_elr
#endif
#endif
@ -739,7 +743,7 @@ u32 ARMJIT_Memory::PageShift = 0;
bool ARMJIT_Memory::IsFastMemSupported()
{
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
return false;
#else
static bool initialised = false;

View File

@ -115,6 +115,10 @@ if (ENABLE_JIT)
target_link_libraries(core PRIVATE onecore)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_options(core PUBLIC -Wl,-z,wxneeded)
endif()
if (ARCHITECTURE STREQUAL x86_64)
target_sources(core PRIVATE
dolphin/x64ABI.cpp