diff --git a/src/coreclr/vm/amd64/AsmHelpers.asm b/src/coreclr/vm/amd64/AsmHelpers.asm index 178ffe4bddcbe0..e72f89a7ed4640 100644 --- a/src/coreclr/vm/amd64/AsmHelpers.asm +++ b/src/coreclr/vm/amd64/AsmHelpers.asm @@ -4,8 +4,6 @@ include AsmMacros.inc include asmconstants.inc -Thread_GetInterpThreadContext TEXTEQU - extern PInvokeImportWorker:proc extern ThePreStub:proc extern ProfileEnter:proc @@ -15,7 +13,7 @@ extern OnHijackWorker:proc extern JIT_RareDisableHelperWorker:proc ifdef FEATURE_INTERPRETER extern ExecuteInterpretedMethod:proc -extern Thread_GetInterpThreadContext:proc +extern GetInterpThreadContextWithPossiblyMissingThread:proc endif extern g_pPollGC:QWORD @@ -564,13 +562,16 @@ NESTED_ENTRY InterpreterStub, _TEXT mov rbx, METHODDESC_REGISTER INLINE_GETTHREAD r10; thrashes rax and r11 + test r10, r10 + jz NoManagedThread mov rax, qword ptr [r10 + OFFSETOF__Thread__m_pInterpThreadContext] test rax, rax jnz HaveInterpThreadContext +NoManagedThread: mov rcx, r10 - call Thread_GetInterpThreadContext + call GetInterpThreadContextWithPossiblyMissingThread RESTORE_ARGUMENT_REGISTERS __PWTB_ArgumentRegisters RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters diff --git a/src/coreclr/vm/amd64/asmhelpers.S b/src/coreclr/vm/amd64/asmhelpers.S index fb90ce2b1034a6..5c865e0df6f81c 100644 --- a/src/coreclr/vm/amd64/asmhelpers.S +++ b/src/coreclr/vm/amd64/asmhelpers.S @@ -443,13 +443,16 @@ NESTED_ENTRY InterpreterStub, _TEXT, NoHandler INLINE_GETTHREAD // result in rax, it can thrash all argument registers as it can call a helper mov r10, rax + test rax, rax + jz LOCAL_LABEL(NoManagedThread) mov rax, qword ptr [r10 + OFFSETOF__Thread__m_pInterpThreadContext] test rax, rax jnz LOCAL_LABEL(HaveInterpThreadContext) +LOCAL_LABEL(NoManagedThread): mov rcx, r10 - call C_FUNC(_ZN6Thread22GetInterpThreadContextEv) // Thread::GetInterpThreadContext + call C_FUNC(GetInterpThreadContextWithPossiblyMissingThread) LOCAL_LABEL(HaveInterpThreadContext): mov r10, qword ptr [rax + OFFSETOF__InterpThreadContext__pStackPointer] @@ -1708,7 +1711,7 @@ NESTED_ENTRY CallJittedMethodRetVoid, _TEXT, NoHandler push_nonvol_reg rbp mov rbp, rsp alloc_stack 0x10 - save_reg_postrsp r10, 0 + save_reg_postrsp r10, 0 END_PROLOGUE sub rsp, rcx // total stack space mov r11, rdi // The routines list diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 801995254258d7..3cae429dfb7be8 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -694,12 +694,14 @@ NESTED_ENTRY InterpreterStub, _TEXT, NoHandler mov x21, x0 #endif INLINE_GETTHREAD x20 // thrashes x0 on Apple OSes (and possibly other arg registers on other Unixes) + cbz x20, LOCAL_LABEL(NoManagedThread) ldr x11, [x20, #OFFSETOF__Thread__m_pInterpThreadContext] cbnz x11, LOCAL_LABEL(HaveInterpThreadContext) +LOCAL_LABEL(NoManagedThread): #ifdef TARGET_APPLE - // There Thread::GetInterpThreadContext can destroy all argument registers, so we + // GetInterpThreadContextWithPossiblyMissingThread can destroy all argument registers, so we // need to save them. For non-Apple, they have been already saved in the PROLOG_WITH_TRANSITION_BLOCK // Restore x0 thrashed by the INLINE_GETTHREAD mov x0, x21 @@ -708,7 +710,7 @@ NESTED_ENTRY InterpreterStub, _TEXT, NoHandler #endif mov x0, x20 - bl C_FUNC(_ZN6Thread22GetInterpThreadContextEv) // Thread::GetInterpThreadContext + bl C_FUNC(GetInterpThreadContextWithPossiblyMissingThread) mov x11, x0 #ifndef TARGET_APPLE diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index 72804cc6084350..25d85f96458c56 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -24,8 +24,7 @@ IMPORT HijackHandler IMPORT ThrowControlForThread #ifdef FEATURE_INTERPRETER - SETALIAS Thread_GetInterpThreadContext, ?GetInterpThreadContext@Thread@@QEAAPEAUInterpThreadContext@@XZ - IMPORT $Thread_GetInterpThreadContext + IMPORT GetInterpThreadContextWithPossiblyMissingThread IMPORT ExecuteInterpretedMethod #endif @@ -1065,12 +1064,14 @@ JIT_PollGCRarePath PROLOG_WITH_TRANSITION_BLOCK INLINE_GETTHREAD x20, x19 + cbz x20, NoManagedThread ldr x11, [x20, #OFFSETOF__Thread__m_pInterpThreadContext] cbnz x11, HaveInterpThreadContext +NoManagedThread mov x0, x20 - bl $Thread_GetInterpThreadContext + bl GetInterpThreadContextWithPossiblyMissingThread mov x11, x0 RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index f047cc4b1bc55e..b9d86330b87deb 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -7702,6 +7702,22 @@ InterpThreadContext* Thread::GetInterpThreadContext() return m_pInterpThreadContext; } + +extern "C" InterpThreadContext* STDCALL GetInterpThreadContextWithPossiblyMissingThread(Thread *pThread) +{ + CONTRACTL + { + THROWS; + } + CONTRACTL_END; + + if (pThread == nullptr) + { + pThread = SetupThread(); + } + + return pThread->GetInterpThreadContext(); +} #endif // FEATURE_INTERPRETER /* static */