Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/coreclr/vm/amd64/AsmHelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
include AsmMacros.inc
include asmconstants.inc

Thread_GetInterpThreadContext TEXTEQU <?GetInterpThreadContext@Thread@@QEAAPEAUInterpThreadContext@@XZ>

extern PInvokeImportWorker:proc
extern ThePreStub:proc
extern ProfileEnter:proc
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/vm/amd64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/vm/arm64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/vm/arm64/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading