Skip to content

Commit 7aa94bc

Browse files
committed
Fix for obscure scenario where InterpreterStub is invoked on an InterpMethod that does not already have a populated pCallStub
1 parent 19b9833 commit 7aa94bc

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/coreclr/vm/amd64/AsmHelpers.asm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include AsmMacros.inc
55
include asmconstants.inc
66

77
Thread_GetInterpThreadContext TEXTEQU <?GetInterpThreadContext@Thread@@QEAAPEAUInterpThreadContext@@XZ>
8+
CreateNativeToInterpreterCallStub TEXTEQU <?CreateNativeToInterpreterCallStub@@YAPEAUCallStubHeader@@PEAUInterpMethod@@@Z>
89

910
extern PInvokeImportWorker:proc
1011
extern ThePreStub:proc
@@ -16,6 +17,7 @@ extern JIT_RareDisableHelperWorker:proc
1617
ifdef FEATURE_INTERPRETER
1718
extern ExecuteInterpretedMethod:proc
1819
extern Thread_GetInterpThreadContext:proc
20+
extern CreateNativeToInterpreterCallStub:proc
1921
endif
2022

2123
extern g_pPollGC:QWORD
@@ -578,8 +580,34 @@ HaveInterpThreadContext:
578580
mov r10, qword ptr [rax + OFFSETOF__InterpThreadContext__pStackPointer]
579581
; Load the InterpMethod pointer from the IR bytecode
580582
mov rax, qword ptr [rbx]
581-
mov rax, qword ptr [rax + OFFSETOF__InterpMethod__pCallStub]
582-
lea r11, qword ptr [rax + OFFSETOF__CallStubHeader__Routines]
583+
584+
; Do we have a call stub? If not, create it.
585+
mov r11, qword ptr [rax + OFFSETOF__InterpMethod__pCallStub]
586+
test r11, r11
587+
jnz HaveCallStub
588+
589+
; Pass the InterpMethod * to CreateNativeToInterpreterCallStub so it can populate the call stub
590+
mov rcx, rax
591+
; The x64 ABI considers the registers RAX, RCX, RDX, R8, R9, R10, R11, and XMM0-XMM5 volatile.
592+
push rax
593+
push rdx
594+
push r8
595+
push r9
596+
push r10
597+
; We're going to recreate r11 after this and we already trashed rcx so we don't need to save it.
598+
call CreateNativeToInterpreterCallStub
599+
; Restore the volatile registers
600+
pop r10
601+
pop r9
602+
pop r9
603+
pop rdx
604+
pop rax
605+
; CreateNativeToInterpreterCallStub populated pCallStub so now load it
606+
mov r11, qword ptr [rax + OFFSETOF__InterpMethod__pCallStub]
607+
608+
HaveCallStub:
609+
610+
lea r11, qword ptr [r11 + OFFSETOF__CallStubHeader__Routines]
583611
lea rax, [rsp + __PWTB_TransitionBlock]
584612
; Copy the arguments to the interpreter stack, invoke the InterpExecMethod and load the return value
585613
call qword ptr [r11]

0 commit comments

Comments
 (0)