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
20typedef DPTR(struct HandleTableMap) PTR_HandleTableMap;
21typedef DPTR(struct HandleTableBucket) PTR_HandleTableBucket;
22typedef DPTR(PTR_HandleTableBucket) PTR_PTR_HandleTableBucket;
23
24struct HandleTableMap
25{
26 PTR_PTR_HandleTableBucket pBuckets;
27 PTR_HandleTableMap pNext;
28 uint32_t dwMaxIndex;
29};
30
31extern 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
36struct 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
58GC_DAC_VISIBLE
59OBJECTREF GetDependentHandleSecondary(OBJECTHANDLE handle);
60
61#ifndef DACCESS_COMPILE
62void SetDependentHandleSecondary(OBJECTHANDLE handle, OBJECTREF secondary);
63#endif // !DACCESS_COMPILE
64
65#ifndef DACCESS_COMPILE
66uint32_t GetVariableHandleType(OBJECTHANDLE handle);
67void UpdateVariableHandleType(OBJECTHANDLE handle, uint32_t type);
68uint32_t CompareExchangeVariableHandleType(OBJECTHANDLE handle, uint32_t oldType, uint32_t newType);
69
70/*
71 * Convenience prototypes for using the global handles
72 */
73
74int GetCurrentThreadHomeHeapNumber();
75
76/*
77 * Table maintenance routines
78 */
79bool Ref_Initialize();
80void Ref_Shutdown();
81bool Ref_InitializeHandleTableBucket(HandleTableBucket* bucket, void* context);
82BOOL Ref_HandleAsyncPinHandles(async_pin_enum_fn callback, void* context);
83void Ref_RelocateAsyncPinHandles(HandleTableBucket *pSource, HandleTableBucket *pTarget, void (*clearIfComplete)(Object*), void (*setHandle)(Object*, OBJECTHANDLE));
84void Ref_RemoveHandleTableBucket(HandleTableBucket *pBucket);
85void Ref_DestroyHandleTableBucket(HandleTableBucket *pBucket);
86
87/*
88 * GC-time scanning entrypoints
89 */
90struct ScanContext;
91struct DhContext;
92void Ref_BeginSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration);
93void Ref_EndSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration);
94
95typedef void Ref_promote_func(class Object**, ScanContext*, uint32_t);
96
97void Ref_TraceRefCountHandles(HANDLESCANPROC callback, uintptr_t lParam1, uintptr_t lParam2);
98void Ref_TracePinningRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
99void Ref_TraceNormalRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
100void Ref_UpdatePointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
101void Ref_UpdatePinnedPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
102DhContext *Ref_GetDependentHandleContext(ScanContext* sc);
103bool Ref_ScanDependentHandlesForPromotion(DhContext *pDhContext);
104void Ref_ScanDependentHandlesForClearing(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
105void Ref_ScanDependentHandlesForRelocation(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
106void Ref_ScanSizedRefHandles(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
107#ifdef FEATURE_REDHAWK
108void Ref_ScanPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
109#endif
110
111void Ref_CheckReachable (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
112void Ref_CheckAlive (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
113void Ref_ScanHandlesForProfilerAndETW(uint32_t uMaxGeneration, uintptr_t lp1, handle_scan_fn fn);
114void Ref_ScanDependentHandlesForProfilerAndETW(uint32_t uMaxGeneration, ScanContext * SC, handle_scan_fn fn);
115void Ref_AgeHandles (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
116void Ref_RejuvenateHandles(uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
117
118void Ref_VerifyHandleTable(uint32_t condemned, uint32_t maxgen, ScanContext* sc);
119
120#endif // DACCESS_COMPILE
121
122#endif //_OBJECTHANDLE_H
123