@@ -5,6 +5,7 @@ include AsmMacros.inc
5
5
include asmconstants. inc
6
6
7
7
Thread_GetInterpThreadContext TEXTEQU <?GetInterpThreadContext@Thread@@QEAAPEAUInterpThreadContext@@XZ>
8
+ CreateNativeToInterpreterCallStub TEXTEQU <?CreateNativeToInterpreterCallStub@@YAPEAUCallStubHeader@@PEAUInterpMethod@@@Z>
8
9
9
10
extern PInvokeImportWorker:proc
10
11
extern ThePreStub:proc
@@ -16,6 +17,7 @@ extern JIT_RareDisableHelperWorker:proc
16
17
ifdef FEATURE_INTERPRETER
17
18
extern ExecuteInterpretedMethod:proc
18
19
extern Thread_GetInterpThreadContext:proc
20
+ extern CreateNativeToInterpreterCallStub:proc
19
21
endif
20
22
21
23
extern g_pPollGC:QWORD
@@ -578,8 +580,34 @@ HaveInterpThreadContext:
578
580
mov r10 , qword ptr [ rax + OFFSETOF__InterpThreadContext__pStackPointer ]
579
581
; Load the InterpMethod pointer from the IR bytecode
580
582
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 ]
583
611
lea rax , [ rsp + __PWTB_TransitionBlock ]
584
612
; Copy the arguments to the interpreter stack, invoke the InterpExecMethod and load the return value
585
613
call qword ptr [ r11 ]
0 commit comments