From b478267c4272b5338641b939f0633e88f1a4f6f9 Mon Sep 17 00:00:00 2001 From: Exverge Date: Tue, 14 Jul 2026 16:00:40 -0400 Subject: [PATCH] Keep all nt headers in one place --- src/core/arm/nce/arm_nce.cpp | 5 ++--- src/core/arm/nce/arm_nce.h | 8 -------- src/core/arm/nce/guest_context.h | 6 ++++-- src/core/arm/nce/win/exceptions.cpp | 2 +- src/core/arm/nce/win/exceptions.h | 4 ++-- src/core/arm/nce/win/nt_headers.h | 14 ++++++++++++++ 6 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/core/arm/nce/win/nt_headers.h diff --git a/src/core/arm/nce/arm_nce.cpp b/src/core/arm/nce/arm_nce.cpp index 6d5675ec85..d83e5d8c12 100644 --- a/src/core/arm/nce/arm_nce.cpp +++ b/src/core/arm/nce/arm_nce.cpp @@ -154,7 +154,6 @@ HaltReason ArmNce::ReturnToRunCodeByExceptionLevelChange(int tid, void *tpidr) { void ArmNce::ReturnToRunCodeByExceptionLevelChangeSignalHandler(int sig, void *info, void *raw_context) { auto tpidr = static_cast(RestoreGuestContext(raw_context)); - RestoreGuestContext(raw_context); #if !defined(__APPLE__) && !defined(__WIN32) // Save old value of TPIDR_EL0, load guest one u64 tpidr_el0; @@ -452,9 +451,9 @@ HaltReason ArmNce::RunThread(Kernel::KThread* thread) { auto* thread_params = &thread->GetNativeExecutionParameters(); auto* process = thread->GetOwnerProcess(); -#ifdef __APPLE__ +#if defined(__APPLE__) ASSERT(pthread_setspecific(ContextKey, &thread_params) == 0); -#elif +#elif defined(__WIN32) ASSERT(TlsSetValue(ContextKey, &thread_params) == 0); #endif diff --git a/src/core/arm/nce/arm_nce.h b/src/core/arm/nce/arm_nce.h index aa00a8983f..6bbdca7187 100644 --- a/src/core/arm/nce/arm_nce.h +++ b/src/core/arm/nce/arm_nce.h @@ -30,14 +30,6 @@ class System; constexpr pthread_key_t ContextKey = 210; #elif __WIN32 -namespace os { -extern "C" { - #include - #include - #include -} -} - static const u32 ContextKey = os::TlsAlloc(); static const u32 NCEStorage = os::TlsAlloc(); static const u64 TlsSlots = offsetof(os::TEB, TlsSlots); diff --git a/src/core/arm/nce/guest_context.h b/src/core/arm/nce/guest_context.h index d0a35f43d6..addda7d6b8 100644 --- a/src/core/arm/nce/guest_context.h +++ b/src/core/arm/nce/guest_context.h @@ -14,6 +14,8 @@ #ifdef __linux__ #include +#elif __WIN32 +#include "core/arm/nce/win/nt_headers.h" #endif namespace Core { @@ -115,7 +117,7 @@ public: return &ptr->__ss.__cpsr; } #elif defined(__WIN32) - KernelContext(void* ptr) : ptr(static_cast(ptr)) {} + KernelContext(void* ptr) : ptr(static_cast(ptr)) {} u64* pc() { return ptr->Pc; @@ -162,7 +164,7 @@ private: return reinterpret_cast(header); } #elif defined(__WIN32) - CONTEXT* ptr; + os::CONTEXT* ptr; #endif }; diff --git a/src/core/arm/nce/win/exceptions.cpp b/src/core/arm/nce/win/exceptions.cpp index 44a8170ee7..de64f45197 100644 --- a/src/core/arm/nce/win/exceptions.cpp +++ b/src/core/arm/nce/win/exceptions.cpp @@ -7,7 +7,7 @@ namespace Core { -static s32 WINAPI VectoredExecptionHandler(EXCEPTION_POINTERS* info) { +static s32 WINAPI VectoredExecptionHandler(os::EXCEPTION_POINTERS* info) { u32 code = info->ExceptionRecord->ExceptionCode; if (code == SIGSEGV || code == SIGBUS) { diff --git a/src/core/arm/nce/win/exceptions.h b/src/core/arm/nce/win/exceptions.h index e0dc9ca484..5a4e9c3e79 100644 --- a/src/core/arm/nce/win/exceptions.h +++ b/src/core/arm/nce/win/exceptions.h @@ -3,7 +3,7 @@ #pragma once -#include +#include "core/arm/nce/arm_nce.h" #define SIGBUS EXCEPTION_DATATYPE_MISALIGNMENT #define SIGSEGV EXCEPTION_ACCESS_VIOLATION @@ -13,6 +13,6 @@ namespace Core { thread_local bool is_host_fault = false; -static s32 WINAPI VectoredExecptionHandler(EXCEPTION_POINTERS* info); +static s32 WINAPI VectoredExecptionHandler(os::EXCEPTION_POINTERS* info); } // namespace Core \ No newline at end of file diff --git a/src/core/arm/nce/win/nt_headers.h b/src/core/arm/nce/win/nt_headers.h new file mode 100644 index 0000000000..61b1d7298d --- /dev/null +++ b/src/core/arm/nce/win/nt_headers.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +// Use a separate namespace to not add Windows headers to the global path in header files +// We can't directly add Windows.h because of winternl.h +namespace os { +extern "C" { + #include + #include + #include +} +} // namespace os \ No newline at end of file