@@ -56,7 +56,7 @@ COOP_PINVOKE_HELPER(uint8_t *, RhFindMethodStartAddress, (void * codeAddr))
56
56
57
57
PTR_UInt8 RuntimeInstance::FindMethodStartAddress (PTR_VOID ControlPC)
58
58
{
59
- ICodeManager * pCodeManager = FindCodeManagerByAddress (ControlPC);
59
+ ICodeManager * pCodeManager = GetCodeManagerForAddress (ControlPC);
60
60
MethodInfo methodInfo;
61
61
if (pCodeManager != NULL && pCodeManager->FindMethodInfo (ControlPC, &methodInfo))
62
62
{
@@ -66,20 +66,23 @@ PTR_UInt8 RuntimeInstance::FindMethodStartAddress(PTR_VOID ControlPC)
66
66
return NULL ;
67
67
}
68
68
69
- ICodeManager * RuntimeInstance::FindCodeManagerByAddress (PTR_VOID pvAddress)
69
+ // WARNING: This method is called by suspension while one thread is interrupted
70
+ // in a random location, possibly holding random locks.
71
+ // It is unsafe to use blocking APIs or allocate in this method.
72
+ // Please ensure that all methods called by this one also have this warning.
73
+ bool RuntimeInstance::IsManaged (PTR_VOID pvAddress)
70
74
{
71
- ReaderWriterLock::ReadHolder read (&m_ModuleListLock);
75
+ return (dac_cast<TADDR>(pvAddress) - dac_cast<TADDR>(m_pvManagedCodeStartRange) < m_cbManagedCodeRange);
76
+ }
72
77
73
- // TODO: ICodeManager support in DAC
74
- # ifndef DACCESS_COMPILE
75
- for (CodeManagerEntry * pEntry = m_CodeManagerList. GetHead (); pEntry != NULL ; pEntry = pEntry-> m_pNext )
78
+ ICodeManager * RuntimeInstance::GetCodeManagerForAddress (PTR_VOID pvAddress)
79
+ {
80
+ if (! IsManaged (pvAddress) )
76
81
{
77
- if (dac_cast<TADDR>(pvAddress) - dac_cast<TADDR>(pEntry->m_pvStartRange ) < pEntry->m_cbRange )
78
- return pEntry->m_pCodeManager ;
82
+ return NULL ;
79
83
}
80
- #endif
81
84
82
- return NULL ;
85
+ return m_CodeManager ;
83
86
}
84
87
85
88
#ifndef DACCESS_COMPILE
@@ -90,7 +93,7 @@ ICodeManager * RuntimeInstance::FindCodeManagerByAddress(PTR_VOID pvAddress)
90
93
ICodeManager * RuntimeInstance::FindCodeManagerForClasslibFunction (PTR_VOID address)
91
94
{
92
95
// Try looking up the code manager assuming the address is for code first. This is expected to be most common.
93
- ICodeManager * pCodeManager = FindCodeManagerByAddress (address);
96
+ ICodeManager * pCodeManager = GetCodeManagerForAddress (address);
94
97
if (pCodeManager != NULL )
95
98
return pCodeManager;
96
99
@@ -119,7 +122,7 @@ void * RuntimeInstance::GetClasslibFunctionFromCodeAddress(PTR_VOID address, Cla
119
122
120
123
PTR_UInt8 RuntimeInstance::GetTargetOfUnboxingAndInstantiatingStub (PTR_VOID ControlPC)
121
124
{
122
- ICodeManager * pCodeManager = FindCodeManagerByAddress (ControlPC);
125
+ ICodeManager * pCodeManager = GetCodeManagerForAddress (ControlPC);
123
126
if (pCodeManager != NULL )
124
127
{
125
128
PTR_UInt8 pData = (PTR_UInt8)pCodeManager->GetAssociatedData (ControlPC);
@@ -137,6 +140,10 @@ PTR_UInt8 RuntimeInstance::GetTargetOfUnboxingAndInstantiatingStub(PTR_VOID Cont
137
140
138
141
GPTR_IMPL_INIT (RuntimeInstance, g_pTheRuntimeInstance, NULL );
139
142
143
+ // WARNING: This method is called by suspension while one thread is interrupted
144
+ // in a random location, possibly holding random locks.
145
+ // It is unsafe to use blocking APIs or allocate in this method.
146
+ // Please ensure that all methods called by this one also have this warning.
140
147
PTR_RuntimeInstance GetRuntimeInstance ()
141
148
{
142
149
return g_pTheRuntimeInstance;
@@ -150,28 +157,21 @@ void RuntimeInstance::EnumAllStaticGCRefs(void * pfnCallback, void * pvCallbackD
150
157
}
151
158
}
152
159
153
- void RuntimeInstance::SetLoopHijackFlags (uint32_t flag)
154
- {
155
- for (TypeManagerList::Iterator iter = m_TypeManagerList.Begin (); iter != m_TypeManagerList.End (); iter++)
156
- {
157
- iter->m_pTypeManager ->SetLoopHijackFlag (flag);
158
- }
159
- }
160
-
161
160
RuntimeInstance::OsModuleList* RuntimeInstance::GetOsModuleList ()
162
161
{
163
162
return dac_cast<DPTR (OsModuleList)>(dac_cast<TADDR>(this ) + offsetof (RuntimeInstance, m_OsModuleList));
164
163
}
165
164
166
165
ReaderWriterLock& RuntimeInstance::GetTypeManagerLock ()
167
166
{
168
- return m_ModuleListLock ;
167
+ return m_TypeManagerLock ;
169
168
}
170
169
171
170
#ifndef DACCESS_COMPILE
172
171
173
172
RuntimeInstance::RuntimeInstance () :
174
173
m_pThreadStore(NULL ),
174
+ m_CodeManager(NULL ),
175
175
m_conservativeStackReportingEnabled(false ),
176
176
m_pUnboxingStubsRegion(NULL )
177
177
{
@@ -196,56 +196,19 @@ void RuntimeInstance::EnableConservativeStackReporting()
196
196
m_conservativeStackReportingEnabled = true ;
197
197
}
198
198
199
- bool RuntimeInstance::RegisterCodeManager (ICodeManager * pCodeManager, PTR_VOID pvStartRange, uint32_t cbRange)
199
+ void RuntimeInstance::RegisterCodeManager (ICodeManager * pCodeManager, PTR_VOID pvStartRange, uint32_t cbRange)
200
200
{
201
- CodeManagerEntry * pEntry = new (nothrow) CodeManagerEntry ();
202
- if (NULL == pEntry)
203
- return false ;
201
+ _ASSERTE (m_CodeManager == NULL );
202
+ _ASSERTE (pCodeManager != NULL );
204
203
205
- pEntry->m_pvStartRange = pvStartRange;
206
- pEntry->m_cbRange = cbRange;
207
- pEntry->m_pCodeManager = pCodeManager;
208
-
209
- {
210
- ReaderWriterLock::WriteHolder write (&m_ModuleListLock);
211
-
212
- m_CodeManagerList.PushHead (pEntry);
213
- }
214
-
215
- return true ;
216
- }
217
-
218
- void RuntimeInstance::UnregisterCodeManager (ICodeManager * pCodeManager)
219
- {
220
- CodeManagerEntry * pEntry = NULL ;
221
-
222
- {
223
- ReaderWriterLock::WriteHolder write (&m_ModuleListLock);
224
-
225
- for (CodeManagerList::Iterator i = m_CodeManagerList.Begin (), end = m_CodeManagerList.End (); i != end; i++)
226
- {
227
- if (i->m_pCodeManager == pCodeManager)
228
- {
229
- pEntry = *i;
230
-
231
- m_CodeManagerList.Remove (i);
232
- break ;
233
- }
234
- }
235
- }
236
-
237
- ASSERT (pEntry != NULL );
238
- delete pEntry;
239
- }
240
-
241
- extern " C" bool __stdcall RegisterCodeManager (ICodeManager * pCodeManager, PTR_VOID pvStartRange, uint32_t cbRange)
242
- {
243
- return GetRuntimeInstance ()->RegisterCodeManager (pCodeManager, pvStartRange, cbRange);
204
+ m_CodeManager = pCodeManager;
205
+ m_pvManagedCodeStartRange = pvStartRange;
206
+ m_cbManagedCodeRange = cbRange;
244
207
}
245
208
246
- extern " C" void __stdcall UnregisterCodeManager (ICodeManager * pCodeManager)
209
+ extern " C" void __stdcall RegisterCodeManager (ICodeManager * pCodeManager, PTR_VOID pvStartRange, uint32_t cbRange )
247
210
{
248
- return GetRuntimeInstance ()->UnregisterCodeManager (pCodeManager);
211
+ GetRuntimeInstance ()->RegisterCodeManager (pCodeManager, pvStartRange, cbRange );
249
212
}
250
213
251
214
bool RuntimeInstance::RegisterUnboxingStubs (PTR_VOID pvStartRange, uint32_t cbRange)
@@ -297,7 +260,7 @@ bool RuntimeInstance::RegisterTypeManager(TypeManager * pTypeManager)
297
260
pEntry->m_pTypeManager = pTypeManager;
298
261
299
262
{
300
- ReaderWriterLock::WriteHolder write (&m_ModuleListLock );
263
+ ReaderWriterLock::WriteHolder write (&m_TypeManagerLock );
301
264
302
265
m_TypeManagerList.PushHead (pEntry);
303
266
}
0 commit comments