From 9344988f52b7ccd6e01f68bd57bec7e1b0f7003f Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Wed, 10 Jan 2024 22:32:16 +0300 Subject: [PATCH 1/3] Move RhpPInvoke to wasm/RhpPInvoke.cpp --- src/coreclr/nativeaot/Runtime/thread.cpp | 12 +-------- .../nativeaot/Runtime/wasm/PInvoke.cpp | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/thread.cpp b/src/coreclr/nativeaot/Runtime/thread.cpp index 693dc9097960..78d6c8d5003a 100644 --- a/src/coreclr/nativeaot/Runtime/thread.cpp +++ b/src/coreclr/nativeaot/Runtime/thread.cpp @@ -1297,17 +1297,7 @@ COOP_PINVOKE_HELPER(void, RhpReversePInvokeReturn, (ReversePInvokeFrame * pFrame #ifdef USE_PORTABLE_HELPERS -#ifdef HOST_WASM -extern "C" void RhpSetShadowStackTop(void*); -COOP_PINVOKE_HELPER(void, RhpPInvoke, (void* pShadowStack, PInvokeTransitionFrame* pFrame)) -{ - // The implementation has to live in this file because of "FORCEINLINE" on "Thread::InlinePInvoke". - // Ideally, "InlinePInvoke" would be in "thread.inl", and this function - in "wasm/PInvoke.cpp". - RhpSetShadowStackTop(pShadowStack); - Thread* pCurThread = ThreadStore::RawGetCurrentThread(); - pCurThread->InlinePInvoke(pFrame); -} -#else // !HOST_WASM +#ifndef HOST_WASM COOP_PINVOKE_HELPER(void, RhpPInvoke, (PInvokeTransitionFrame* pFrame)) { Thread * pCurThread = ThreadStore::RawGetCurrentThread(); diff --git a/src/coreclr/nativeaot/Runtime/wasm/PInvoke.cpp b/src/coreclr/nativeaot/Runtime/wasm/PInvoke.cpp index fc5c547d88f6..5ada6305b79d 100644 --- a/src/coreclr/nativeaot/Runtime/wasm/PInvoke.cpp +++ b/src/coreclr/nativeaot/Runtime/wasm/PInvoke.cpp @@ -9,10 +9,24 @@ #include "daccess.h" #include "PalRedhawkCommon.h" #include "PalRedhawk.h" +#include "thread.h" +#include "threadstore.h" +#include "thread.inl" +#include "threadstore.inl" thread_local void* t_pShadowStackBottom = nullptr; thread_local void* t_pShadowStackTop = nullptr; +void* GetShadowStackBottom() +{ + return t_pShadowStackBottom; +} + +void* GetShadowStackTop() +{ + return t_pShadowStackTop; +} + COOP_PINVOKE_HELPER(void*, RhpGetOrInitShadowStackTop, ()) { void* pShadowStack = t_pShadowStackTop; @@ -41,12 +55,9 @@ COOP_PINVOKE_HELPER(void, RhpSetShadowStackTop, (void* pShadowStack)) t_pShadowStackTop = pShadowStack; } -void* GetShadowStackBottom() -{ - return t_pShadowStackBottom; -} - -void* GetShadowStackTop() +COOP_PINVOKE_HELPER(void, RhpPInvoke, (void* pShadowStack, PInvokeTransitionFrame* pFrame)) { - return t_pShadowStackTop; + RhpSetShadowStackTop(pShadowStack); + Thread* pCurThread = ThreadStore::RawGetCurrentThread(); + pCurThread->InlinePInvoke(pFrame); } From 864bc9f209135b5f17728b121d3888524abffece Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Wed, 10 Jan 2024 22:36:48 +0300 Subject: [PATCH 2/3] Undefine BACKGROUND_GC 56K of code gone. --- src/coreclr/gc/gc.cpp | 2 +- src/coreclr/gc/gcpriv.h | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index ec3ea813dd30..9b71e294f741 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -14076,7 +14076,7 @@ HRESULT gc_heap::initialize_gc (size_t soh_segment_size, #ifdef WRITE_WATCH hardware_write_watch_api_supported(); -#ifdef BACKGROUND_GC_SUPPORTED +#ifdef BACKGROUND_GC if (can_use_write_watch_for_gc_heap() && GCConfig::GetConcurrentGC()) { gc_can_use_concurrent = true; diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 6cecb63ad1c1..9ad47991bd20 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -185,12 +185,9 @@ inline void FATAL_GC_ERROR() #define FEATURE_PREMORTEM_FINALIZATION #define GC_HISTORY +#ifndef TARGET_WASM #define BACKGROUND_GC //concurrent background GC (requires WRITE_WATCH) - -// It is no longer possible to build without BACKGROUND_GC defined, so we have to use this duplicate -#if !defined(TARGET_WASM) || defined(FEATURE_WASM_THREADS) -#define BACKGROUND_GC_SUPPORTED -#endif // !defined(TARGET_WASM) || defined(FEATURE_WASM_THREADS) +#endif // We need the lower 3 bits in the MT to do our bookkeeping so doubly linked free list is only for 64-bit #if defined(BACKGROUND_GC) && defined(HOST_64BIT) From 58c653f4399829ff6aacef9baca03d5839f99a35 Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Wed, 10 Jan 2024 23:00:23 +0300 Subject: [PATCH 3/3] Restore FEATURE_WASM_THREADS --- src/coreclr/gc/gcpriv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 9ad47991bd20..567593f30fcf 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -185,7 +185,7 @@ inline void FATAL_GC_ERROR() #define FEATURE_PREMORTEM_FINALIZATION #define GC_HISTORY -#ifndef TARGET_WASM +#if !defined(TARGET_WASM) || defined(FEATURE_WASM_THREADS) #define BACKGROUND_GC //concurrent background GC (requires WRITE_WATCH) #endif