ReactOS 0.4.16-dev-109-gf4cb10f
cm_x.h
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS Kernel
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: ntoskrnl/include/internal/cm_x.h
5* PURPOSE: Inlined Functions for the Configuration Manager
6* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7*/
8
9#if DBG
11VOID
12CmpCaptureLockBackTraceByIndex(_In_ ULONG Index)
13{
14 /* Capture the backtrace */
16 _countof(CmpCacheTable[Index].LockBackTrace),
17 CmpCacheTable[Index].LockBackTrace,
18 NULL);
19}
20#endif
21
22//
23// Returns the hashkey corresponding to a convkey
24//
25#define GET_HASH_KEY(ConvKey) \
26 ((CMP_HASH_IRRATIONAL * (ConvKey)) % CMP_HASH_PRIME)
27
28//
29// Computes the hashkey of a character
30//
31#define COMPUTE_HASH_CHAR(ConvKey, Char) \
32 (37 * ConvKey + RtlUpcaseUnicodeChar(Char))
33
34//
35// Returns the index into the hash table, or the entry itself
36//
37#define GET_HASH_INDEX(ConvKey) \
38 (GET_HASH_KEY(ConvKey) % CmpHashTableSize)
39#define GET_HASH_ENTRY(Table, ConvKey) \
40 (&Table[GET_HASH_INDEX(ConvKey)])
41#define ASSERT_VALID_HASH(h) \
42 ASSERT_KCB_VALID(CONTAINING_RECORD((h), CM_KEY_CONTROL_BLOCK, KeyHash))
43
44//
45// Returns whether or not the cell is cached
46//
47#define CMP_IS_CELL_CACHED(c) \
48 (((c) & HCELL_CACHED) && ((c) != HCELL_NIL))
49
50//
51// Return data from a cached cell
52//
53#define CMP_GET_CACHED_CELL(c) \
54 (ULONG_PTR)((c) & ~HCELL_CACHED)
55#define CMP_GET_CACHED_DATA(c) \
56 (&(((PCM_CACHED_VALUE_INDEX)(CMP_GET_CACHED_CELL(c)))->Data.CellData))
57#define CMP_GET_CACHED_INDEX(c) \
58 (&(((PCM_CACHED_ENTRY)(CMP_GET_CACHED_CELL(c)))->CellIndex))
59#define CMP_GET_CACHED_VALUE(c) \
60 (&(((PCM_CACHED_VALUE)(CMP_GET_CACHED_CELL(c)))->KeyValue))
61
62//
63// Makes sure that the registry is locked
64//
65#define CMP_ASSERT_REGISTRY_LOCK() \
66 ASSERT((CmpSpecialBootCondition == TRUE) || \
67 (CmpTestRegistryLock() == TRUE))
68
69//
70// Makes sure that the registry is locked or loading
71//
72#define CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(h) \
73 ASSERT((CmpSpecialBootCondition == TRUE) || \
74 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \
75 (CmpTestRegistryLock() == TRUE))
76
77//
78// Makes sure that the registry is exclusively locked
79//
80#define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK() \
81 ASSERT((CmpSpecialBootCondition == TRUE) || \
82 (CmpTestRegistryLockExclusive() == TRUE))
83
84//
85// Makes sure that the registry is exclusively locked or loading
86//
87#define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK_OR_LOADING(h) \
88 ASSERT((CmpSpecialBootCondition == TRUE) || \
89 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \
90 (CmpTestRegistryLockExclusive() == TRUE))
91
92//
93// Makes sure this is a valid KCB
94//
95#define ASSERT_KCB_VALID(k) \
96 ASSERT((k)->Signature == CM_KCB_SIGNATURE)
97
98//
99// Checks if a KCB is exclusively locked
100//
101#define CmpIsKcbLockedExclusive(k) \
102 (GET_HASH_ENTRY(CmpCacheTable, \
103 (k)->ConvKey)->Owner == KeGetCurrentThread())
104
105//
106// Shared acquires a KCB by index
107//
108#define CmpAcquireKcbLockSharedByIndex(i) \
109{ \
110 ExAcquirePushLockShared(&CmpCacheTable[(i)].Lock); \
111}
112
113//
114// Exclusively acquires a KCB by index
115//
117VOID
119{
123#if DBG
124 CmpCaptureLockBackTraceByIndex(Index);
125#endif
126}
127
128//
129// Exclusively acquires a KCB
130//
132VOID
134{
136}
137
138//
139// Exclusively acquires a KCB by key
140//
142VOID
144{
146}
147
148//
149// Shared acquires a KCB by key
150//
152VOID
154 _In_ ULONG ConvKey)
155{
157}
158
159//
160// Shared acquires a KCB
161//
162#define CmpAcquireKcbLockShared(k) \
163{ \
164 ExAcquirePushLockShared(&GET_HASH_ENTRY(CmpCacheTable, \
165 (k)->ConvKey)->Lock); \
166}
167
168//
169// Tries to convert a KCB lock
170//
174{
177 &GET_HASH_ENTRY(CmpCacheTable, k->ConvKey)->Lock))
178 {
180 k->ConvKey)->Owner = KeGetCurrentThread();
181 return TRUE;
182 }
183 return FALSE;
184}
185
186//
187// Releases an exlusively or shared acquired KCB by index
188//
190VOID
192{
195}
196
197//
198// Releases an exlusively or shared acquired KCB
199//
201VOID
203{
205}
206
207//
208// Releases an exlusively or shared acquired KCB by key
209//
211VOID
213{
215}
216
217//
218// Converts a KCB lock
219//
221VOID
223{
227}
228
229//
230// Exclusively acquires an NCB
231//
232#define CmpAcquireNcbLockExclusive(n) \
233{ \
234 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \
235 (n)->ConvKey)->Lock); \
236}
237
238//
239// Exclusively acquires an NCB by key
240//
241#define CmpAcquireNcbLockExclusiveByKey(k) \
242{ \
243 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \
244 (k))->Lock); \
245}
246
247//
248// Releases an exlusively or shared acquired NCB
249//
250#define CmpReleaseNcbLock(k) \
251{ \
252 ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \
253 (k)->ConvKey)->Lock); \
254}
255
256//
257// Releases an exlusively or shared acquired NCB by key
258//
259#define CmpReleaseNcbLockByKey(k) \
260{ \
261 ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \
262 (k))->Lock); \
263}
264
265//
266// Asserts that either the registry or the KCB is locked
267//
268#define CMP_ASSERT_HASH_ENTRY_LOCK(k) \
269{ \
270 ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k)->Owner == \
271 KeGetCurrentThread())) || \
272 (CmpTestRegistryLockExclusive() == TRUE)); \
273}
274
275//
276// Asserts that either the registry or the KCB is locked
277//
278#define CMP_ASSERT_KCB_LOCK(k) \
279{ \
280 ASSERT((CmpIsKcbLockedExclusive(k) == TRUE) || \
281 (CmpTestRegistryLockExclusive() == TRUE)); \
282}
283
284//
285// Gets the page attached to the KCB
286//
287#define CmpGetAllocPageFromKcb(k) \
288 (PCM_ALLOC_PAGE)(((ULONG_PTR)(k)) & ~(PAGE_SIZE - 1))
289
290//
291// Gets the page attached to the delayed allocation
292//
293#define CmpGetAllocPageFromDelayAlloc(a) \
294 (PCM_ALLOC_PAGE)(((ULONG_PTR)(a)) & ~(PAGE_SIZE - 1))
295
296//
297// Makes sure that the registry is locked for flushes
298//
299#define CMP_ASSERT_FLUSH_LOCK(h) \
300 ASSERT((CmpSpecialBootCondition == TRUE) || \
301 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \
302 (CmpTestHiveFlusherLockShared((PCMHIVE)h) == TRUE) || \
303 (CmpTestHiveFlusherLockExclusive((PCMHIVE)h) == TRUE) || \
304 (CmpTestRegistryLockExclusive() == TRUE));
unsigned char BOOLEAN
FORCEINLINE VOID CmpAcquireKcbLockExclusive(PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cm_x.h:133
FORCEINLINE VOID CmpAcquireKcbLockExclusiveByKey(IN ULONG ConvKey)
Definition: cm_x.h:143
#define GET_HASH_ENTRY(Table, ConvKey)
Definition: cm_x.h:39
FORCEINLINE VOID CmpAcquireKcbLockExclusiveByIndex(ULONG Index)
Definition: cm_x.h:118
#define GET_HASH_INDEX(ConvKey)
Definition: cm_x.h:37
FORCEINLINE VOID CmpReleaseKcbLockByKey(ULONG ConvKey)
Definition: cm_x.h:212
#define CmpIsKcbLockedExclusive(k)
Definition: cm_x.h:101
FORCEINLINE VOID CmpAcquireKcbLockSharedByKey(_In_ ULONG ConvKey)
Definition: cm_x.h:153
FORCEINLINE VOID CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
Definition: cm_x.h:222
FORCEINLINE VOID CmpReleaseKcbLockByIndex(ULONG Index)
Definition: cm_x.h:191
FORCEINLINE VOID CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cm_x.h:202
FORCEINLINE BOOLEAN CmpTryToConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
Definition: cm_x.h:173
#define CmpAcquireKcbLockSharedByIndex(i)
Definition: cm_x.h:108
PCM_KEY_HASH_TABLE_ENTRY CmpCacheTable
Definition: cmkcbncb.c:18
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
FORCEINLINE VOID ExReleasePushLock(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1296
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1036
FORCEINLINE BOOLEAN ExConvertPushLockSharedToExclusive(IN PEX_PUSH_LOCK PushLock)
Definition: ex.h:1139
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT(a)
Definition: mode.c:44
int k
Definition: mpi.c:3369
#define _In_
Definition: ms_sal.h:308
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID Owner
Definition: rtlfuncs.h:1609
#define _countof(array)
Definition: sndvol32.h:70
PKTHREAD Owner
Definition: cm.h:161
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
#define FORCEINLINE
Definition: wdftypes.h:67
NTSYSAPI USHORT NTAPI RtlCaptureStackBackTrace(_In_ ULONG FramesToSkip, _In_ ULONG FramesToCapture, _Out_writes_to_(FramesToCapture, return) PVOID *BackTrace, _Out_opt_ PULONG BackTraceHash)