[Build] Generalize POSIX platform guards

Most non-Windows code paths use standard POSIX APIs (sockets, signals,
dlopen, threading) that work on any POSIX platform. Change Linux-specific
guards to !WIN32 or #else where the code is portable. Linux-specific
APIs (SIGRTMIN, Vulkan/X11, fontconfig/GTK) remain Linux-guarded.
This commit is contained in:
Herman S.
2026-03-26 22:07:28 +09:00
parent 6c20f64e0d
commit cb12f7fa1e
10 changed files with 39 additions and 48 deletions

View File

@@ -9,7 +9,7 @@
#include "xenia/kernel/xthread.h"
#if XE_PLATFORM_LINUX
#if !XE_PLATFORM_WIN32
#include <signal.h>
#endif
@@ -556,17 +556,19 @@ void XThread::Execute() {
// On Windows, setjmp/longjmp is used because MSVC's longjmp performs SEH
// stack unwinding which already calls destructors.
uint32_t next_address;
#if XE_PLATFORM_LINUX
#if !XE_PLATFORM_WIN32
try {
exit_code = static_cast<int>(kernel_state()->processor()->Execute(
thread_state_, address, args.data(), args.size()));
next_address = 0;
} catch (const FiberReentryException& e) {
#if XE_PLATFORM_LINUX
// Ensure SIGRTMIN (used for thread suspend) is not left blocked.
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGRTMIN);
pthread_sigmask(SIG_UNBLOCK, &set, nullptr);
#endif
next_address = e.address;
}
@@ -578,10 +580,12 @@ void XThread::Execute() {
exit_code = static_cast<int>(thread_state_->context()->r[3]);
}
} catch (const FiberReentryException& e) {
#if XE_PLATFORM_LINUX
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGRTMIN);
pthread_sigmask(SIG_UNBLOCK, &set, nullptr);
#endif
next_address = e.address;
}
}
@@ -616,7 +620,7 @@ void XThread::Reenter(uint32_t address) {
// Called when the game switches fiber stacks (e.g., via
// KeSetCurrentStackPointers in games like Forza Horizon 2).
// Must unwind through all frames between here and Execute().
#if XE_PLATFORM_LINUX
#if !XE_PLATFORM_WIN32
// Throw a C++ exception that unwinds through JIT frames (using DWARF
// .eh_frame info) and host frames (using compiler-generated DWARF),
// calling destructors properly along the way.
@@ -767,7 +771,7 @@ X_STATUS XThread::Resume(uint32_t* out_suspend_count) {
} else {
return X_STATUS_UNSUCCESSFUL;
}
#elif XE_PLATFORM_LINUX
#else
// Use mutex to protect suspend_count access and coordinate with SelfSuspend.
bool should_resume_host = false;
{
@@ -788,8 +792,6 @@ X_STATUS XThread::Resume(uint32_t* out_suspend_count) {
thread_->Resume(&unused_host_suspend_count);
}
return X_STATUS_SUCCESS;
#else
#error "Unsupported platform"
#endif
}
@@ -821,7 +823,7 @@ X_STATUS XThread::Suspend(uint32_t* out_suspend_count) {
}
}
#if XE_PLATFORM_LINUX
#if !XE_PLATFORM_WIN32
uint32_t XThread::SelfSuspend() {
auto guest_thread = guest_object<X_KTHREAD>();
std::unique_lock<std::mutex> lock(suspend_mutex_);
@@ -831,7 +833,7 @@ uint32_t XThread::SelfSuspend() {
lock, [guest_thread]() { return guest_thread->suspend_count == 0; });
return previous;
}
#endif
#endif // !XE_PLATFORM_WIN32
X_STATUS XThread::Delay(uint32_t processor_mode, uint32_t alertable,
uint64_t interval) {