Skip to content

Commit 3a5289a

Browse files
authoredJan 10, 2024
[NativeAOT-LLVM] Move RhpPInvoke and undefine BACKGROUND_GC (#2481)
* Move RhpPInvoke to wasm/RhpPInvoke.cpp * Undefine BACKGROUND_GC 56K of code gone. * Restore FEATURE_WASM_THREADS
1 parent 32ce881 commit 3a5289a

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed
 

‎src/coreclr/gc/gc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14076,7 +14076,7 @@ HRESULT gc_heap::initialize_gc (size_t soh_segment_size,
1407614076

1407714077
#ifdef WRITE_WATCH
1407814078
hardware_write_watch_api_supported();
14079-
#ifdef BACKGROUND_GC_SUPPORTED
14079+
#ifdef BACKGROUND_GC
1408014080
if (can_use_write_watch_for_gc_heap() && GCConfig::GetConcurrentGC())
1408114081
{
1408214082
gc_can_use_concurrent = true;

‎src/coreclr/gc/gcpriv.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ inline void FATAL_GC_ERROR()
185185
#define FEATURE_PREMORTEM_FINALIZATION
186186
#define GC_HISTORY
187187

188-
#define BACKGROUND_GC //concurrent background GC (requires WRITE_WATCH)
189-
190-
// It is no longer possible to build without BACKGROUND_GC defined, so we have to use this duplicate
191188
#if !defined(TARGET_WASM) || defined(FEATURE_WASM_THREADS)
192-
#define BACKGROUND_GC_SUPPORTED
193-
#endif // !defined(TARGET_WASM) || defined(FEATURE_WASM_THREADS)
189+
#define BACKGROUND_GC //concurrent background GC (requires WRITE_WATCH)
190+
#endif
194191

195192
// We need the lower 3 bits in the MT to do our bookkeeping so doubly linked free list is only for 64-bit
196193
#if defined(BACKGROUND_GC) && defined(HOST_64BIT)

‎src/coreclr/nativeaot/Runtime/thread.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -1297,17 +1297,7 @@ COOP_PINVOKE_HELPER(void, RhpReversePInvokeReturn, (ReversePInvokeFrame * pFrame
12971297

12981298
#ifdef USE_PORTABLE_HELPERS
12991299

1300-
#ifdef HOST_WASM
1301-
extern "C" void RhpSetShadowStackTop(void*);
1302-
COOP_PINVOKE_HELPER(void, RhpPInvoke, (void* pShadowStack, PInvokeTransitionFrame* pFrame))
1303-
{
1304-
// The implementation has to live in this file because of "FORCEINLINE" on "Thread::InlinePInvoke".
1305-
// Ideally, "InlinePInvoke" would be in "thread.inl", and this function - in "wasm/PInvoke.cpp".
1306-
RhpSetShadowStackTop(pShadowStack);
1307-
Thread* pCurThread = ThreadStore::RawGetCurrentThread();
1308-
pCurThread->InlinePInvoke(pFrame);
1309-
}
1310-
#else // !HOST_WASM
1300+
#ifndef HOST_WASM
13111301
COOP_PINVOKE_HELPER(void, RhpPInvoke, (PInvokeTransitionFrame* pFrame))
13121302
{
13131303
Thread * pCurThread = ThreadStore::RawGetCurrentThread();

‎src/coreclr/nativeaot/Runtime/wasm/PInvoke.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@
99
#include "daccess.h"
1010
#include "PalRedhawkCommon.h"
1111
#include "PalRedhawk.h"
12+
#include "thread.h"
13+
#include "threadstore.h"
14+
#include "thread.inl"
15+
#include "threadstore.inl"
1216

1317
thread_local void* t_pShadowStackBottom = nullptr;
1418
thread_local void* t_pShadowStackTop = nullptr;
1519

20+
void* GetShadowStackBottom()
21+
{
22+
return t_pShadowStackBottom;
23+
}
24+
25+
void* GetShadowStackTop()
26+
{
27+
return t_pShadowStackTop;
28+
}
29+
1630
COOP_PINVOKE_HELPER(void*, RhpGetOrInitShadowStackTop, ())
1731
{
1832
void* pShadowStack = t_pShadowStackTop;
@@ -41,12 +55,9 @@ COOP_PINVOKE_HELPER(void, RhpSetShadowStackTop, (void* pShadowStack))
4155
t_pShadowStackTop = pShadowStack;
4256
}
4357

44-
void* GetShadowStackBottom()
45-
{
46-
return t_pShadowStackBottom;
47-
}
48-
49-
void* GetShadowStackTop()
58+
COOP_PINVOKE_HELPER(void, RhpPInvoke, (void* pShadowStack, PInvokeTransitionFrame* pFrame))
5059
{
51-
return t_pShadowStackTop;
60+
RhpSetShadowStackTop(pShadowStack);
61+
Thread* pCurThread = ThreadStore::RawGetCurrentThread();
62+
pCurThread->InlinePInvoke(pFrame);
5263
}

0 commit comments

Comments
 (0)
Please sign in to comment.