forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloaderallocator.inl
232 lines (186 loc) · 5.76 KB
/
loaderallocator.inl
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#ifndef _LOADER_ALLOCATOR_I
#define _LOADER_ALLOCATOR_I
#include "assembly.hpp"
#ifndef DACCESS_COMPILE
inline LOADERALLOCATORREF LoaderAllocator::GetExposedObject()
{
LIMITED_METHOD_CONTRACT;
OBJECTREF loaderAllocatorObject = (m_hLoaderAllocatorObjectHandle != NULL) ? ObjectFromHandle(m_hLoaderAllocatorObjectHandle) : NULL;
return (LOADERALLOCATORREF)loaderAllocatorObject;
}
#endif
inline bool LoaderAllocator::IsExposedObjectLive()
{
LIMITED_METHOD_CONTRACT;
if (m_hLoaderAllocatorObjectHandle == 0)
return false;
return !ObjectHandleIsNull(m_hLoaderAllocatorObjectHandle);
}
inline void GlobalLoaderAllocator::Init()
{
LoaderAllocator::Init(m_ExecutableHeapInstance);
}
inline BOOL LoaderAllocatorID::Equals(LoaderAllocatorID *pId)
{
LIMITED_METHOD_CONTRACT;
if (GetType() != pId->GetType())
return false;
return GetValue() == pId->GetValue();
}
inline void LoaderAllocatorID::Init()
{
LIMITED_METHOD_CONTRACT;
m_type = LAT_Assembly;
};
inline void LoaderAllocatorID::AddDomainAssembly(DomainAssembly* pAssembly)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(m_type == LAT_Assembly);
// Link domain assembly together
if (m_pDomainAssembly != NULL)
{
pAssembly->GetAssembly()->SetNextAssemblyInSameALC(m_pDomainAssembly);
}
m_pDomainAssembly = pAssembly;
}
inline VOID* LoaderAllocatorID::GetValue()
{
LIMITED_METHOD_DAC_CONTRACT;
return m_pValue;
}
inline COUNT_T LoaderAllocatorID::Hash()
{
LIMITED_METHOD_DAC_CONTRACT;
return (COUNT_T)(SIZE_T)GetValue();
}
inline LoaderAllocatorType LoaderAllocatorID::GetType()
{
LIMITED_METHOD_DAC_CONTRACT;
return m_type;
}
inline DomainAssemblyIterator LoaderAllocatorID::GetDomainAssemblyIterator()
{
LIMITED_METHOD_DAC_CONTRACT;
_ASSERTE(m_type == LAT_Assembly);
return DomainAssemblyIterator(m_pDomainAssembly);
}
inline LoaderAllocatorID* AssemblyLoaderAllocator::Id()
{
LIMITED_METHOD_DAC_CONTRACT;
return &m_Id;
}
inline LoaderAllocatorID* GlobalLoaderAllocator::Id()
{
LIMITED_METHOD_DAC_CONTRACT;
return &m_Id;
}
/* static */
FORCEINLINE BOOL LoaderAllocator::GetHandleValueFast(LOADERHANDLE handle, OBJECTREF *pValue)
{
LIMITED_METHOD_CONTRACT;
// If the slot value does have the low bit set, then it is a simple pointer to the value
// Otherwise, we will need a more complicated operation to get the value.
if ((((UINT_PTR)handle) & 1) != 0)
{
*pValue = *((OBJECTREF *)(((UINT_PTR)handle) - 1));
return TRUE;
}
else
{
return FALSE;
}
}
FORCEINLINE BOOL LoaderAllocator::GetHandleValueFastPhase2(LOADERHANDLE handle, OBJECTREF *pValue)
{
SUPPORTS_DAC;
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_MODE_COOPERATIVE;
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
if (handle == 0)
return FALSE;
/* This is lockless access to the handle table, be careful */
OBJECTREF loaderAllocatorAsObjectRef = ObjectFromHandle(m_hLoaderAllocatorObjectHandle);
// If the managed loader allocator has been collected, then the handles associated with it are dead as well.
if (loaderAllocatorAsObjectRef == NULL)
return FALSE;
LOADERALLOCATORREF loaderAllocator = dac_cast<LOADERALLOCATORREF>(loaderAllocatorAsObjectRef);
PTRARRAYREF handleTable = loaderAllocator->DangerousGetHandleTable();
UINT_PTR index = (((UINT_PTR)handle) >> 1) - 1;
*pValue = handleTable->GetAt(index);
return TRUE;
}
FORCEINLINE OBJECTREF LoaderAllocator::GetHandleValueFastCannotFailType2(LOADERHANDLE handle)
{
SUPPORTS_DAC;
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_MODE_COOPERATIVE;
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
/* This is lockless access to the handle table, be careful */
OBJECTREF loaderAllocatorAsObjectRef = ObjectFromHandle(m_hLoaderAllocatorObjectHandle);
LOADERALLOCATORREF loaderAllocator = dac_cast<LOADERALLOCATORREF>(loaderAllocatorAsObjectRef);
PTRARRAYREF handleTable = loaderAllocator->DangerousGetHandleTable();
UINT_PTR index = (((UINT_PTR)handle) >> 1) - 1;
return handleTable->GetAt(index);
}
inline bool SegmentedHandleIndexStack::Push(DWORD value)
{
LIMITED_METHOD_CONTRACT;
if (m_TOSIndex == Segment::Size)
{
Segment* segment;
if (m_freeSegment == NULL)
{
segment = new (nothrow) Segment();
if (segment == NULL)
{
return false;
}
}
else
{
segment = m_freeSegment;
m_freeSegment = NULL;
}
segment->m_prev = m_TOSSegment;
m_TOSSegment = segment;
m_TOSIndex = 0;
}
m_TOSSegment->m_data[m_TOSIndex++] = value;
return true;
}
inline DWORD SegmentedHandleIndexStack::Pop()
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(!IsEmpty());
if (m_TOSIndex == 0)
{
Segment* prevSegment = m_TOSSegment->m_prev;
_ASSERTE(prevSegment != NULL);
delete m_freeSegment;
m_freeSegment = m_TOSSegment;
m_TOSSegment = prevSegment;
m_TOSIndex = Segment::Size;
}
return m_TOSSegment->m_data[--m_TOSIndex];
}
inline SegmentedHandleIndexStack::~SegmentedHandleIndexStack()
{
LIMITED_METHOD_CONTRACT;
while (m_TOSSegment != NULL)
{
Segment* prevSegment = m_TOSSegment->m_prev;
delete m_TOSSegment;
m_TOSSegment = prevSegment;
}
m_freeSegment = NULL;
}
inline bool SegmentedHandleIndexStack::IsEmpty()
{
LIMITED_METHOD_CONTRACT;
return (m_TOSSegment == NULL) || ((m_TOSIndex == 0) && (m_TOSSegment->m_prev == NULL));
}
#endif // _LOADER_ALLOCATOR_I