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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// File: umthunkhash.cpp
//
//
#include "common.h"
#include "umthunkhash.h"
#ifdef FEATURE_MIXEDMODE
UMThunkHash::UMThunkHash(Module *pModule, AppDomain *pDomain) :
CClosedHashBase(
#ifdef _DEBUG
3,
#else
17, // CClosedHashTable will grow as necessary
#endif
sizeof(UTHEntry),
FALSE
),
m_crst(CrstUMThunkHash)
{
WRAPPER_NO_CONTRACT;
m_pModule = pModule;
m_dwAppDomainId = pDomain->GetId();
}
UMThunkHash::~UMThunkHash()
{
CONTRACT_VOID
{
NOTHROW;
DESTRUCTOR_CHECK;
GC_TRIGGERS;
FORBID_FAULT;
MODE_ANY;
}
CONTRACT_END
#ifndef DACCESS_COMPILE
UTHEntry *phe = (UTHEntry*)GetFirst();
while (phe) {
DeleteExecutable(phe->m_pUMEntryThunk);
phe->m_UMThunkMarshInfo.~UMThunkMarshInfo();
phe = (UTHEntry*)GetNext((BYTE*)phe);
}
#endif
RETURN;
}
LPVOID UMThunkHash::GetUMThunk(LPVOID pTarget, PCCOR_SIGNATURE pSig, DWORD cSig)
{
CONTRACT (LPVOID)
{
INSTANCE_CHECK;
THROWS;
GC_TRIGGERS;
MODE_ANY;
POSTCONDITION(CheckPointer(RETVAL, NULL_OK));
}
CONTRACT_END
UTHEntry *phe;
CrstHolder ch(&m_crst);
UTHKey key;
key.m_pTarget = pTarget;
key.m_pSig = pSig;
key.m_cSig = cSig;
phe =(UTHEntry *)Find((LPVOID)&key);
#ifndef DACCESS_COMPILE
if (phe == NULL)
{
NewExecutableHolder<UMEntryThunk> uET= new (executable) UMEntryThunk();
bool bNew = FALSE;
phe = (UTHEntry *)FindOrAdd((LPVOID)&key,bNew);
if (phe != NULL)
{
_ASSERTE(bNew); // we are under lock
phe->m_pUMEntryThunk=uET.Extract();
//nothrow
phe->m_UMThunkMarshInfo.LoadTimeInit(Signature(pSig, cSig), m_pModule);
phe->m_pUMEntryThunk->LoadTimeInit((PCODE)pTarget, NULL, &(phe->m_UMThunkMarshInfo),
MethodTable::GetMethodDescForSlotAddress((PCODE)pTarget),
m_dwAppDomainId);
phe->m_key = key;
phe->m_status = USED;
}
}
#endif //DACESS_COMPILE
if (phe)
RETURN (LPVOID)(phe->m_pUMEntryThunk->GetCode());
else
RETURN NULL;
}
unsigned int UMThunkHash::Hash(void const *pData)
{
LIMITED_METHOD_CONTRACT;
UTHKey *pKey = (UTHKey*)pData;
return (ULONG)(size_t)(pKey->m_pTarget);
}
inline unsigned int UMThunkHash::Compare( // 0, -1, or 1.
void const *pData, // Raw key data on lookup.
BYTE *pElement) // The element to compare data against.
{
CONTRACTL
{
NOTHROW;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;
UTHKey *pkey1 = (UTHKey*)pData;
UTHKey *pkey2 = &( ((UTHEntry*)pElement)->m_key );
if (pkey1->m_pTarget != pkey2->m_pTarget)
return 1;
if (S_OK != MetaSig::CompareMethodSigsNT(pkey1->m_pSig, pkey1->m_cSig, m_pModule, NULL, pkey2->m_pSig, pkey2->m_cSig, m_pModule, NULL))
return 1;
return 0;
}
CClosedHashBase::ELEMENTSTATUS UMThunkHash::Status( // The status of the entry.
BYTE *pElement) // The element to check.
{
LIMITED_METHOD_CONTRACT;
return ((UTHEntry*)pElement)->m_status;
}
//*****************************************************************************
// Sets the status of the given element.
//*****************************************************************************
void UMThunkHash::SetStatus(
BYTE *pElement, // The element to set status for.
ELEMENTSTATUS eStatus) // New status.
{
LIMITED_METHOD_CONTRACT;
((UTHEntry*)pElement)->m_status = eStatus;
}
//*****************************************************************************
// Returns the internal key value for an element.
//*****************************************************************************
void *UMThunkHash::GetKey( // The data to hash on.
BYTE *pElement) // The element to return data ptr for.
{
LIMITED_METHOD_CONTRACT;
return (BYTE*) &(((UTHEntry*)pElement)->m_key);
}
#endif // FEATURE_MIXEDMODE
|