blob: 4361778fb9b15d2bc3452e7faaba30774806c00b (
plain)
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
|
// 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.
#include "common.h"
#include "gchandleutilities.h"
IGCHandleManager* g_pGCHandleManager = nullptr;
// Debug-only validation for handle.
void ValidateObjectAndAppDomain(OBJECTREF objRef, ADIndex appDomainIndex)
{
#ifdef _DEBUG_IMPL
VALIDATEOBJECTREF(objRef);
AppDomain *domain = SystemDomain::GetAppDomainAtIndex(appDomainIndex);
// Access to a handle in an unloaded domain is not allowed
assert(domain != nullptr);
assert(!domain->NoAccessToHandleTable());
#endif // _DEBUG_IMPL
}
void ValidateHandleAssignment(OBJECTHANDLE handle, OBJECTREF objRef)
{
#ifdef _DEBUG_IMPL
_ASSERTE(handle);
#ifdef DEBUG_DestroyedHandleValue
// Verify that we are not trying to access a freed handle.
_ASSERTE("Attempt to access destroyed handle." && *(_UNCHECKED_OBJECTREF*)handle != DEBUG_DestroyedHandleValue);
#endif
IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
ADIndex appDomainIndex = ADIndex(reinterpret_cast<DWORD>(mgr->GetHandleContext(handle)));
AppDomain *unloadingDomain = SystemDomain::AppDomainBeingUnloaded();
if (unloadingDomain && unloadingDomain->GetIndex() == appDomainIndex && unloadingDomain->NoAccessToHandleTable())
{
_ASSERTE (!"Access to a handle in unloaded domain is not allowed");
}
ValidateObjectAndAppDomain(objRef, appDomainIndex);
#endif // _DEBUG_IMPL
}
void DiagHandleCreated(OBJECTHANDLE handle, OBJECTREF objRef)
{
#ifdef GC_PROFILING
BEGIN_PIN_PROFILER(CORProfilerTrackGC());
g_profControlBlock.pProfInterface->HandleCreated((uintptr_t)handle, (ObjectID)OBJECTREF_TO_UNCHECKED_OBJECTREF(objRef));
END_PIN_PROFILER();
#else
UNREFERENCED_PARAMETER(handle);
UNREFERENCED_PARAMETER(objRef);
#endif // GC_PROFILING
}
void DiagHandleDestroyed(OBJECTHANDLE handle)
{
#ifdef GC_PROFILING
BEGIN_PIN_PROFILER(CORProfilerTrackGC());
g_profControlBlock.pProfInterface->HandleDestroyed((uintptr_t)handle);
END_PIN_PROFILER();
#else
UNREFERENCED_PARAMETER(handle);
#endif // GC_PROFILING
}
|