Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencm_x.h
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/cm/cm_x.h 00005 * PURPOSE: Inlined Functions for the Configuration Manager 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 */ 00008 00009 // 00010 // Returns whether or not this is a small valued key 00011 // 00012 FORCEINLINE 00013 BOOLEAN 00014 CmpIsKeyValueSmall(OUT PULONG RealLength, 00015 IN ULONG Length) 00016 { 00017 /* Check if the length has the special size value */ 00018 if (Length >= CM_KEY_VALUE_SPECIAL_SIZE) 00019 { 00020 /* It does, so this is a small key: return the real length */ 00021 *RealLength = Length - CM_KEY_VALUE_SPECIAL_SIZE; 00022 return TRUE; 00023 } 00024 00025 /* This is not a small key, return the length we read */ 00026 *RealLength = Length; 00027 return FALSE; 00028 } 00029 00030 // 00031 // Returns whether or not this is a big valued key 00032 // 00033 FORCEINLINE 00034 BOOLEAN 00035 CmpIsKeyValueBig(IN PHHIVE Hive, 00036 IN ULONG Length) 00037 { 00038 /* Check if the hive is XP Beta 1 or newer */ 00039 if (Hive->Version >= HSYS_WHISTLER_BETA1) 00040 { 00041 /* Check if the key length is valid for a big value key */ 00042 if ((Length < CM_KEY_VALUE_SPECIAL_SIZE) && (Length > CM_KEY_VALUE_BIG)) 00043 { 00044 /* Yes, this value is big */ 00045 return TRUE; 00046 } 00047 } 00048 00049 /* Not a big value key */ 00050 return FALSE; 00051 } 00052 00053 // 00054 // Returns the hashkey corresponding to a convkey 00055 // 00056 #define GET_HASH_KEY(ConvKey) \ 00057 ((CMP_HASH_IRRATIONAL * (ConvKey)) % CMP_HASH_PRIME) 00058 00059 // 00060 // Returns the index into the hash table, or the entry itself 00061 // 00062 #define GET_HASH_INDEX(ConvKey) \ 00063 GET_HASH_KEY(ConvKey) % CmpHashTableSize 00064 #define GET_HASH_ENTRY(Table, ConvKey) \ 00065 (Table[GET_HASH_INDEX(ConvKey)]) 00066 #define ASSERT_VALID_HASH(h) \ 00067 ASSERT_KCB_VALID(CONTAINING_RECORD((h), CM_KEY_CONTROL_BLOCK, KeyHash)) 00068 00069 // 00070 // Returns whether or not the cell is cached 00071 // 00072 #define CMP_IS_CELL_CACHED(c) \ 00073 (((c) & HCELL_CACHED) && ((c) != HCELL_NIL)) 00074 00075 // 00076 // Return data from a cached cell 00077 // 00078 #define CMP_GET_CACHED_CELL(c) \ 00079 (ULONG_PTR)((c) & ~HCELL_CACHED) 00080 #define CMP_GET_CACHED_DATA(c) \ 00081 (&(((PCM_CACHED_VALUE_INDEX)(CMP_GET_CACHED_CELL(c)))->Data.CellData)) 00082 #define CMP_GET_CACHED_INDEX(c) \ 00083 (&(((PCM_CACHED_ENTRY)(CMP_GET_CACHED_CELL(c)))->CellIndex)) 00084 #define CMP_GET_CACHED_VALUE(c) \ 00085 (&(((PCM_CACHED_VALUE)(CMP_GET_CACHED_CELL(c)))->KeyValue)) 00086 00087 // 00088 // Makes sure that the registry is locked 00089 // 00090 #define CMP_ASSERT_REGISTRY_LOCK() \ 00091 ASSERT((CmpSpecialBootCondition == TRUE) || \ 00092 (CmpTestRegistryLock() == TRUE)) 00093 00094 // 00095 // Makes sure that the registry is locked or loading 00096 // 00097 #define CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(h) \ 00098 ASSERT((CmpSpecialBootCondition == TRUE) || \ 00099 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \ 00100 (CmpTestRegistryLock() == TRUE)) 00101 00102 // 00103 // Makes sure that the registry is exclusively locked 00104 // 00105 #define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK() \ 00106 ASSERT((CmpSpecialBootCondition == TRUE) || \ 00107 (CmpTestRegistryLockExclusive() == TRUE)) 00108 00109 // 00110 // Makes sure that the registry is exclusively locked or loading 00111 // 00112 #define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK_OR_LOADING(h) \ 00113 ASSERT((CmpSpecialBootCondition == TRUE) || \ 00114 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \ 00115 (CmpTestRegistryLockExclusive() == TRUE)) 00116 00117 // 00118 // Makes sure this is a valid KCB 00119 // 00120 #define ASSERT_KCB_VALID(k) \ 00121 ASSERT((k)->Signature == CM_KCB_SIGNATURE) 00122 00123 // 00124 // Checks if a KCB is exclusively locked 00125 // 00126 #define CmpIsKcbLockedExclusive(k) \ 00127 (GET_HASH_ENTRY(CmpCacheTable, \ 00128 (k)->ConvKey).Owner == KeGetCurrentThread()) 00129 00130 // 00131 // Exclusively acquires a KCB 00132 // 00133 #define CmpAcquireKcbLockExclusive(k) \ 00134 { \ 00135 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable, \ 00136 (k)->ConvKey).Lock); \ 00137 GET_HASH_ENTRY(CmpCacheTable, \ 00138 (k)->ConvKey).Owner = KeGetCurrentThread(); \ 00139 } 00140 00141 // 00142 // Exclusively acquires a KCB by index 00143 // 00144 #define CmpAcquireKcbLockExclusiveByIndex(i) \ 00145 { \ 00146 ExAcquirePushLockExclusive(&CmpCacheTable[(i)].Lock); \ 00147 CmpCacheTable[(i)].Owner = KeGetCurrentThread(); \ 00148 } 00149 00150 // 00151 // Exclusively acquires a KCB by key 00152 // 00153 #define CmpAcquireKcbLockExclusiveByKey(k) \ 00154 { \ 00155 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable, \ 00156 (k)).Lock); \ 00157 GET_HASH_ENTRY(CmpCacheTable, \ 00158 (k)).Owner = KeGetCurrentThread(); \ 00159 } 00160 00161 00162 // 00163 // Shared acquires a KCB 00164 // 00165 #define CmpAcquireKcbLockShared(k) \ 00166 { \ 00167 ExAcquirePushLockShared(&GET_HASH_ENTRY(CmpCacheTable, \ 00168 (k)->ConvKey).Lock); \ 00169 } 00170 00171 // 00172 // Shared acquires a KCB by index 00173 // 00174 #define CmpAcquireKcbLockSharedByIndex(i) \ 00175 { \ 00176 ExAcquirePushLockShared(&CmpCacheTable[(i)].Lock); \ 00177 } 00178 00179 // 00180 // Tries to convert a KCB lock 00181 // 00182 FORCEINLINE 00183 BOOLEAN 00184 CmpTryToConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k) 00185 { 00186 ASSERT(CmpIsKcbLockedExclusive(k) == FALSE); 00187 if (ExConvertPushLockSharedToExclusive( 00188 &GET_HASH_ENTRY(CmpCacheTable, k->ConvKey).Lock)) 00189 { 00190 GET_HASH_ENTRY(CmpCacheTable, 00191 k->ConvKey).Owner = KeGetCurrentThread(); 00192 return TRUE; 00193 } 00194 return FALSE; 00195 } 00196 00197 // 00198 // Releases an exlusively or shared acquired KCB 00199 // 00200 #define CmpReleaseKcbLock(k) \ 00201 { \ 00202 GET_HASH_ENTRY(CmpCacheTable, (k)->ConvKey).Owner = NULL; \ 00203 ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable, \ 00204 (k)->ConvKey).Lock); \ 00205 } 00206 00207 // 00208 // Releases an exlusively or shared acquired KCB by index 00209 // 00210 #define CmpReleaseKcbLockByIndex(i) \ 00211 { \ 00212 CmpCacheTable[(i)].Owner = NULL; \ 00213 ExReleasePushLock(&CmpCacheTable[(i)].Lock); \ 00214 } 00215 00216 // 00217 // Releases an exlusively or shared acquired KCB by key 00218 // 00219 #define CmpReleaseKcbLockByKey(k) \ 00220 { \ 00221 GET_HASH_ENTRY(CmpCacheTable, (k)).Owner = NULL; \ 00222 ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable, \ 00223 (k)).Lock); \ 00224 } 00225 00226 // 00227 // Converts a KCB lock 00228 // 00229 FORCEINLINE 00230 VOID 00231 CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k) 00232 { 00233 ASSERT(CmpIsKcbLockedExclusive(k) == FALSE); 00234 CmpReleaseKcbLock(k); 00235 CmpAcquireKcbLockExclusive(k); 00236 } 00237 00238 // 00239 // Exclusively acquires an NCB 00240 // 00241 #define CmpAcquireNcbLockExclusive(n) \ 00242 { \ 00243 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \ 00244 (n)->ConvKey).Lock); \ 00245 } 00246 00247 // 00248 // Exclusively acquires an NCB by key 00249 // 00250 #define CmpAcquireNcbLockExclusiveByKey(k) \ 00251 { \ 00252 ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \ 00253 (k)).Lock); \ 00254 } 00255 00256 // 00257 // Releases an exlusively or shared acquired NCB 00258 // 00259 #define CmpReleaseNcbLock(k) \ 00260 { \ 00261 ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \ 00262 (k)->ConvKey).Lock); \ 00263 } 00264 00265 // 00266 // Releases an exlusively or shared acquired NCB by key 00267 // 00268 #define CmpReleaseNcbLockByKey(k) \ 00269 { \ 00270 ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \ 00271 (k)).Lock); \ 00272 } 00273 00274 // 00275 // Asserts that either the registry or the hash entry is locked 00276 // 00277 #define CMP_ASSERT_HASH_ENTRY_LOCK(k) \ 00278 { \ 00279 ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k).Owner == \ 00280 KeGetCurrentThread())) || \ 00281 (CmpTestRegistryLockExclusive() == TRUE)); \ 00282 } 00283 00284 // 00285 // Asserts that either the registry or the KCB is locked 00286 // 00287 #define CMP_ASSERT_KCB_LOCK(k) \ 00288 { \ 00289 ASSERT((CmpIsKcbLockedExclusive(k) == TRUE) || \ 00290 (CmpTestRegistryLockExclusive() == TRUE)); \ 00291 } 00292 00293 // 00294 // Gets the page attached to the KCB 00295 // 00296 #define CmpGetAllocPageFromKcb(k) \ 00297 (PCM_ALLOC_PAGE)(((ULONG_PTR)(k)) & ~(PAGE_SIZE - 1)) 00298 00299 // 00300 // Gets the page attached to the delayed allocation 00301 // 00302 #define CmpGetAllocPageFromDelayAlloc(a) \ 00303 (PCM_ALLOC_PAGE)(((ULONG_PTR)(a)) & ~(PAGE_SIZE - 1)) 00304 00305 // 00306 // Makes sure that the registry is locked for flushes 00307 // 00308 #define CMP_ASSERT_FLUSH_LOCK(h) \ 00309 ASSERT((CmpSpecialBootCondition == TRUE) || \ 00310 (((PCMHIVE)h)->HiveIsLoading == TRUE) || \ 00311 (CmpTestHiveFlusherLockShared((PCMHIVE)h) == TRUE) || \ 00312 (CmpTestHiveFlusherLockExclusive((PCMHIVE)h) == TRUE) || \ 00313 (CmpTestRegistryLockExclusive() == TRUE)); 00314 00315 // 00316 // Asserts that either the registry or the KCB is locked 00317 // 00318 #define CMP_ASSERT_HASH_ENTRY_LOCK(k) \ 00319 { \ 00320 ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k).Owner == \ 00321 KeGetCurrentThread())) || \ 00322 (CmpTestRegistryLockExclusive() == TRUE)); \ 00323 } 00324 00325 // 00326 // Gets the page attached to the KCB 00327 // 00328 #define CmpGetAllocPageFromKcb(k) \ 00329 (PCM_ALLOC_PAGE)(((ULONG_PTR)(k)) & ~(PAGE_SIZE - 1)) 00330 00331 // 00332 // Gets the page attached to the delayed allocation 00333 // 00334 #define CmpGetAllocPageFromDelayAlloc(a) \ 00335 (PCM_ALLOC_PAGE)(((ULONG_PTR)(a)) & ~(PAGE_SIZE - 1)) Generated on Sun May 27 2012 04:37:13 for ReactOS by
1.7.6.1
|