1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /* |
6 | * Wraps handle table to implement various handle types (Strong, Weak, etc.) |
7 | * |
8 | |
9 | * |
10 | */ |
11 | |
12 | #ifndef _OBJECTHANDLE_H |
13 | #define _OBJECTHANDLE_H |
14 | |
15 | /* |
16 | * include handle manager declarations |
17 | */ |
18 | #include "handletable.h" |
19 | |
20 | typedef DPTR(struct HandleTableMap) PTR_HandleTableMap; |
21 | typedef DPTR(struct HandleTableBucket) PTR_HandleTableBucket; |
22 | typedef DPTR(PTR_HandleTableBucket) PTR_PTR_HandleTableBucket; |
23 | |
24 | struct HandleTableMap |
25 | { |
26 | PTR_PTR_HandleTableBucket pBuckets; |
27 | PTR_HandleTableMap pNext; |
28 | uint32_t dwMaxIndex; |
29 | }; |
30 | |
31 | extern HandleTableMap g_HandleTableMap; |
32 | |
33 | // struct containing g_SystemInfo.dwNumberOfProcessors HHANDLETABLEs and current table index |
34 | // instead of just single HHANDLETABLE for on-fly balancing while adding handles on multiproc machines |
35 | |
36 | struct HandleTableBucket |
37 | { |
38 | PTR_HHANDLETABLE pTable; |
39 | uint32_t HandleTableIndex; |
40 | |
41 | bool Contains(OBJECTHANDLE handle); |
42 | }; |
43 | |
44 | |
45 | /* |
46 | * Type mask definitions for HNDTYPE_VARIABLE handles. |
47 | */ |
48 | #define VHT_WEAK_SHORT (0x00000100) // avoid using low byte so we don't overlap normal types |
49 | #define VHT_WEAK_LONG (0x00000200) // avoid using low byte so we don't overlap normal types |
50 | #define VHT_STRONG (0x00000400) // avoid using low byte so we don't overlap normal types |
51 | #define VHT_PINNED (0x00000800) // avoid using low byte so we don't overlap normal types |
52 | |
53 | #define IS_VALID_VHT_VALUE(flag) ((flag == VHT_WEAK_SHORT) || \ |
54 | (flag == VHT_WEAK_LONG) || \ |
55 | (flag == VHT_STRONG) || \ |
56 | (flag == VHT_PINNED)) |
57 | |
58 | GC_DAC_VISIBLE |
59 | OBJECTREF GetDependentHandleSecondary(OBJECTHANDLE handle); |
60 | |
61 | #ifndef DACCESS_COMPILE |
62 | void SetDependentHandleSecondary(OBJECTHANDLE handle, OBJECTREF secondary); |
63 | #endif // !DACCESS_COMPILE |
64 | |
65 | #ifndef DACCESS_COMPILE |
66 | uint32_t GetVariableHandleType(OBJECTHANDLE handle); |
67 | void UpdateVariableHandleType(OBJECTHANDLE handle, uint32_t type); |
68 | uint32_t CompareExchangeVariableHandleType(OBJECTHANDLE handle, uint32_t oldType, uint32_t newType); |
69 | |
70 | /* |
71 | * Convenience prototypes for using the global handles |
72 | */ |
73 | |
74 | int GetCurrentThreadHomeHeapNumber(); |
75 | |
76 | /* |
77 | * Table maintenance routines |
78 | */ |
79 | bool Ref_Initialize(); |
80 | void Ref_Shutdown(); |
81 | bool Ref_InitializeHandleTableBucket(HandleTableBucket* bucket, void* context); |
82 | BOOL Ref_HandleAsyncPinHandles(async_pin_enum_fn callback, void* context); |
83 | void Ref_RelocateAsyncPinHandles(HandleTableBucket *pSource, HandleTableBucket *pTarget, void (*clearIfComplete)(Object*), void (*setHandle)(Object*, OBJECTHANDLE)); |
84 | void Ref_RemoveHandleTableBucket(HandleTableBucket *pBucket); |
85 | void Ref_DestroyHandleTableBucket(HandleTableBucket *pBucket); |
86 | |
87 | /* |
88 | * GC-time scanning entrypoints |
89 | */ |
90 | struct ScanContext; |
91 | struct DhContext; |
92 | void Ref_BeginSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration); |
93 | void Ref_EndSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration); |
94 | |
95 | typedef void Ref_promote_func(class Object**, ScanContext*, uint32_t); |
96 | |
97 | void Ref_TraceRefCountHandles(HANDLESCANPROC callback, uintptr_t lParam1, uintptr_t lParam2); |
98 | void Ref_TracePinningRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
99 | void Ref_TraceNormalRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
100 | void Ref_UpdatePointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
101 | void Ref_UpdatePinnedPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
102 | DhContext *Ref_GetDependentHandleContext(ScanContext* sc); |
103 | bool Ref_ScanDependentHandlesForPromotion(DhContext *pDhContext); |
104 | void Ref_ScanDependentHandlesForClearing(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
105 | void Ref_ScanDependentHandlesForRelocation(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
106 | void Ref_ScanSizedRefHandles(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
107 | #ifdef FEATURE_REDHAWK |
108 | void Ref_ScanPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn); |
109 | #endif |
110 | |
111 | void Ref_CheckReachable (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1); |
112 | void Ref_CheckAlive (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1); |
113 | void Ref_ScanHandlesForProfilerAndETW(uint32_t uMaxGeneration, uintptr_t lp1, handle_scan_fn fn); |
114 | void Ref_ScanDependentHandlesForProfilerAndETW(uint32_t uMaxGeneration, ScanContext * SC, handle_scan_fn fn); |
115 | void Ref_AgeHandles (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1); |
116 | void Ref_RejuvenateHandles(uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1); |
117 | |
118 | void Ref_VerifyHandleTable(uint32_t condemned, uint32_t maxgen, ScanContext* sc); |
119 | |
120 | #endif // DACCESS_COMPILE |
121 | |
122 | #endif //_OBJECTHANDLE_H |
123 | |