forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPInvokeStubs.asm
134 lines (95 loc) · 3.92 KB
/
PInvokeStubs.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; ***********************************************************************
; File: PInvokeStubs.asm
;
; ***********************************************************************
;
; *** NOTE: If you make changes to this file, propagate the changes to
; PInvokeStubs.s in this directory
; This contains JITinterface routines that are 100% x86 assembly
.586
.model flat
include asmconstants.inc
include asmmacros.inc
option casemap:none
.code
extern _g_TrapReturningThreads:DWORD
extern _JIT_PInvokeEndRarePath@0:proc
.686P
.XMM
;
; in:
; InlinedCallFrame (ecx) = pointer to the InlinedCallFrame data, including the GS cookie slot (GS cookie right
; before actual InlinedCallFrame data)
; StackArgumentsSize (edx) = Number of argument bytes pushed on the stack, which will be popped by the callee
;
_JIT_PInvokeBegin@4 PROC public
;; set first slot to the value of InlinedCallFrame identifier (checked by runtime code)
mov dword ptr [ecx], FRAMETYPE_InlinedCallFrame
mov dword ptr [ecx + InlinedCallFrame__m_Datum], edx
mov eax, esp
add eax, 4
mov dword ptr [ecx + InlinedCallFrame__m_pCallSiteSP], eax
mov dword ptr [ecx + InlinedCallFrame__m_pCalleeSavedFP], ebp
mov eax, [esp]
mov dword ptr [ecx + InlinedCallFrame__m_pCallerReturnAddress], eax
;; edx = GetThread(). Trashes eax
INLINE_GETTHREAD edx, eax
;; pFrame->m_Next = pThread->m_pFrame;
mov eax, dword ptr [edx + Thread_m_pFrame]
mov dword ptr [ecx + Frame__m_Next], eax
;; pThread->m_pFrame = pFrame;
mov dword ptr [edx + Thread_m_pFrame], ecx
;; pThread->m_fPreemptiveGCDisabled = 0
mov dword ptr [edx + Thread_m_fPreemptiveGCDisabled], 0
ret
_JIT_PInvokeBegin@4 ENDP
;
; in:
; InlinedCallFrame (ecx) = pointer to the InlinedCallFrame data, including the GS cookie slot (GS cookie right
; before actual InlinedCallFrame data)
;
;
_JIT_PInvokeEnd@4 PROC public
;; edx = GetThread(). Trashes eax
INLINE_GETTHREAD edx, eax
;; ecx = pFrame
;; edx = pThread
;; pThread->m_fPreemptiveGCDisabled = 1
mov dword ptr [edx + Thread_m_fPreemptiveGCDisabled], 1
;; Check return trap
cmp [_g_TrapReturningThreads], 0
jnz RarePath
;; pThread->m_pFrame = pFrame->m_Next
mov eax, dword ptr [ecx + Frame__m_Next]
mov dword ptr [edx + Thread_m_pFrame], eax
ret
RarePath:
jmp _JIT_PInvokeEndRarePath@0
_JIT_PInvokeEnd@4 ENDP
;
; in:
; InlinedCallFrame (edi) = pointer to the InlinedCallFrame data
; out:
; Thread (esi) = pointer to Thread data
;
;
_JIT_InitPInvokeFrame@4 PROC public
;; esi = GetThread(). Trashes eax
INLINE_GETTHREAD esi, eax
;; edi = pFrame
;; esi = pThread
;; set first slot to the value of InlinedCallFrame identifier (checked by runtime code)
mov dword ptr [edi], FRAMETYPE_InlinedCallFrame
;; pFrame->m_Next = pThread->m_pFrame;
mov eax, dword ptr [esi + Thread_m_pFrame]
mov dword ptr [edi + Frame__m_Next], eax
mov dword ptr [edi + InlinedCallFrame__m_pCalleeSavedFP], ebp
mov dword ptr [edi + InlinedCallFrame__m_pCallerReturnAddress], 0
;; pThread->m_pFrame = pFrame;
mov dword ptr [esi + Thread_m_pFrame], edi
;; leave current Thread in ESI
ret
_JIT_InitPInvokeFrame@4 ENDP
end