From 7165bd57ebf0664aea1faaa89d763445f9915f23 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 18 Nov 2024 08:03:19 +0300 Subject: [PATCH] Use pointer to GC_NT_TIB instead of PNT_TIB in win32_threads.c (refactoring) This is needed to allow own `NT_TIB` type definition if the latter is not provided in the toolchain system headers. * include/private/pthread_support.h [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_NT_TIB): Define macro (to `NT_TIB`). * include/private/pthread_support.h [WOW64_THREAD_CONTEXT_WORKAROUND && MSWINRT_FLAVOR] (GC_StackContext_Rep.tib): Replace `PNT_TIB` to `GC_NT_TIB*`. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_push_stack_for): Likewise. --- include/private/pthread_support.h | 6 +++++- win32_threads.c | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/private/pthread_support.h b/include/private/pthread_support.h index e7f910d36..d7d5b887c 100644 --- a/include/private/pthread_support.h +++ b/include/private/pthread_support.h @@ -44,6 +44,10 @@ EXTERN_C_BEGIN +# ifdef WOW64_THREAD_CONTEXT_WORKAROUND +# define GC_NT_TIB NT_TIB +# endif + typedef struct GC_StackContext_Rep { # if defined(THREAD_SANITIZER) && defined(SIGNAL_BASED_STOP_WORLD) /* A dummy field to avoid TSan false positive about the race */ @@ -255,7 +259,7 @@ typedef struct GC_Thread_Rep { # endif # if defined(WOW64_THREAD_CONTEXT_WORKAROUND) && defined(MSWINRT_FLAVOR) - PNT_TIB tib; + GC_NT_TIB *tib; # endif # ifdef RETRY_GET_THREAD_CONTEXT /* && GC_WIN32_THREADS */ diff --git a/win32_threads.c b/win32_threads.c index 3af8196d3..27649ca75 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -266,7 +266,7 @@ GC_register_my_thread_inner(const struct GC_stack_base *sb, /* Lookup TIB value via a call to NtCurrentTeb() on thread */ /* registration rather than calling GetThreadSelectorEntry() which */ /* is not available on UWP. */ - me->tib = (PNT_TIB)NtCurrentTeb(); + me->tib = (GC_NT_TIB *)NtCurrentTeb(); # endif me->crtn->last_stack_min = ADDR_LIMIT; GC_record_stack_base(me->crtn, sb); @@ -856,7 +856,7 @@ GC_push_stack_for(GC_thread thread, thread_id_t self_id, GC_bool *pfound_me) & (CONTEXT_EXCEPTION_ACTIVE /* | CONTEXT_SERVICE_ACTIVE */)) != 0) { - PNT_TIB tib; + GC_NT_TIB *tib; # ifdef MSWINRT_FLAVOR tib = thread->tib; @@ -866,9 +866,9 @@ GC_push_stack_for(GC_thread thread, thread_id_t self_id, GC_bool *pfound_me) if (!GetThreadSelectorEntry(THREAD_HANDLE(thread), SegFs, &selector)) ABORT("GetThreadSelectorEntry failed"); - tib = (PNT_TIB)(selector.BaseLow - | (selector.HighWord.Bits.BaseMid << 16) - | (selector.HighWord.Bits.BaseHi << 24)); + tib = (GC_NT_TIB *)(selector.BaseLow + | (selector.HighWord.Bits.BaseMid << 16) + | (selector.HighWord.Bits.BaseHi << 24)); # endif # ifdef DEBUG_THREADS GC_log_printf("TIB stack limit/base: %p .. %p\n",