Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. cmsubs3.c
  5. Abstract:
  6. This module contains locking support routines for the configuration manager.
  7. Author:
  8. Bryan M. Willman (bryanwi) 30-Mar-1992
  9. Revision History:
  10. --*/
  11. #include "cmp.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text(PAGE,CmpLockRegistry)
  14. #pragma alloc_text(PAGE,CmpLockRegistryExclusive)
  15. #pragma alloc_text(PAGE,CmpLockKCBTree)
  16. #pragma alloc_text(PAGE,CmpLockKCBTreeExclusive)
  17. #pragma alloc_text(PAGE,CmpUnlockRegistry)
  18. #pragma alloc_text(PAGE,CmpUnlockKCBTree)
  19. #if DBG
  20. #pragma alloc_text(PAGE,CmpTestRegistryLock)
  21. #pragma alloc_text(PAGE,CmpTestRegistryLockExclusive)
  22. #pragma alloc_text(PAGE,CmpTestKCBLock)
  23. #pragma alloc_text(PAGE,CmpTestKCBLockExclusive)
  24. #endif
  25. #endif
  26. //
  27. // Global registry lock
  28. //
  29. ERESOURCE CmpRegistryLock;
  30. ERESOURCE CmpKcbLock;
  31. ULONG CmpFlushStarveWriters = 0;
  32. BOOLEAN CmpFlushOnLockRelease = FALSE;
  33. LONG CmRegistryLogSizeLimit = -1;
  34. #if DBG
  35. PVOID CmpRegistryLockCaller;
  36. PVOID CmpRegistryLockCallerCaller;
  37. PVOID CmpKCBLockCaller;
  38. PVOID CmpKCBLockCallerCaller;
  39. #endif //DBG
  40. extern BOOLEAN CmpSpecialBootCondition;
  41. VOID
  42. CmpLockRegistry(
  43. VOID
  44. )
  45. /*++
  46. Routine Description:
  47. Lock the registry for shared (read-only) access
  48. Arguments:
  49. None.
  50. Return Value:
  51. None, the registry lock will be held for shared access upon return.
  52. --*/
  53. {
  54. #if DBG
  55. PVOID Caller;
  56. PVOID CallerCaller;
  57. #endif
  58. KeEnterCriticalRegion();
  59. if( CmpFlushStarveWriters ) {
  60. //
  61. // a flush is in progress; starve potential writers
  62. //
  63. ExAcquireSharedStarveExclusive(&CmpRegistryLock, TRUE);
  64. } else {
  65. //
  66. // regular shared mode
  67. //
  68. ExAcquireResourceSharedLite(&CmpRegistryLock, TRUE);
  69. }
  70. #if DBG
  71. RtlGetCallersAddress(&Caller, &CallerCaller);
  72. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_LOCKING,"CmpLockRegistry: c, cc: %p %p\n", Caller, CallerCaller));
  73. #endif
  74. }
  75. VOID
  76. CmpLockRegistryExclusive(
  77. VOID
  78. )
  79. /*++
  80. Routine Description:
  81. Lock the registry for exclusive (write) access.
  82. Arguments:
  83. None.
  84. Return Value:
  85. TRUE - Lock was acquired exclusively
  86. FALSE - Lock is owned by another thread.
  87. --*/
  88. {
  89. KeEnterCriticalRegion();
  90. ExAcquireResourceExclusiveLite(&CmpRegistryLock,TRUE);
  91. ASSERT( CmpFlushStarveWriters == 0 );
  92. #if DBG
  93. RtlGetCallersAddress(&CmpRegistryLockCaller, &CmpRegistryLockCallerCaller);
  94. #endif //DBG
  95. }
  96. VOID
  97. CmpUnlockRegistry(
  98. )
  99. /*++
  100. Routine Description:
  101. Unlock the registry.
  102. --*/
  103. {
  104. ASSERT_CM_LOCK_OWNED();
  105. //
  106. // test if bit set to force flush; and we own the reglock exclusive and ownercount is 1
  107. //
  108. if( CmpFlushOnLockRelease && ExIsResourceAcquiredExclusiveLite(&CmpRegistryLock) && (CmpRegistryLock.OwnerThreads[0].OwnerCount == 1) ) {
  109. //
  110. // we need to flush now
  111. //
  112. ASSERT_CM_LOCK_OWNED_EXCLUSIVE();
  113. CmpDoFlushAll(TRUE);
  114. CmpFlushOnLockRelease = FALSE;
  115. }
  116. ExReleaseResourceLite(&CmpRegistryLock);
  117. KeLeaveCriticalRegion();
  118. }
  119. #if DBG
  120. BOOLEAN
  121. CmpTestRegistryLock(VOID)
  122. {
  123. BOOLEAN rc;
  124. rc = TRUE;
  125. if (ExIsResourceAcquiredShared(&CmpRegistryLock) == 0) {
  126. rc = FALSE;
  127. }
  128. return rc;
  129. }
  130. BOOLEAN
  131. CmpTestRegistryLockExclusive(VOID)
  132. {
  133. if (ExIsResourceAcquiredExclusiveLite(&CmpRegistryLock) == 0) {
  134. return(FALSE);
  135. }
  136. return(TRUE);
  137. }
  138. #endif
  139. VOID
  140. CmpLockKCBTree(
  141. VOID
  142. )
  143. /*++
  144. Routine Description:
  145. Lock the KCB tree for shared (read-only) access
  146. Arguments:
  147. None.
  148. Return Value:
  149. None, the kcb lock will be held for shared access upon return.
  150. --*/
  151. {
  152. #if DBG
  153. PVOID Caller;
  154. PVOID CallerCaller;
  155. #endif
  156. //
  157. // we don't need to enter critical section here as we are already there
  158. // (i.e. kcb lock can be aquired only while holding the registry lock)
  159. //
  160. ExAcquireResourceSharedLite(&CmpKcbLock, TRUE);
  161. #if DBG
  162. RtlGetCallersAddress(&Caller, &CallerCaller);
  163. CmKdPrintEx((DPFLTR_CONFIG_ID,CML_LOCKING,"CmpLockKCBTree: c, cc: %p %p\n", Caller, CallerCaller));
  164. #endif
  165. }
  166. VOID
  167. CmpLockKCBTreeExclusive(
  168. VOID
  169. )
  170. /*++
  171. Routine Description:
  172. Lock the KCB tree for exclusive (write) access.
  173. Arguments:
  174. None.
  175. Return Value:
  176. None, the kcb lock will be held for exclusive access upon return.
  177. --*/
  178. {
  179. //
  180. // we don't need to enter critical section here as we are already there
  181. // (i.e. kcb lock can be aquired only while holding the registry lock)
  182. //
  183. ExAcquireResourceExclusiveLite(&CmpKcbLock,TRUE);
  184. #if DBG
  185. RtlGetCallersAddress(&CmpKCBLockCaller, &CmpKCBLockCallerCaller);
  186. #endif //DBG
  187. }
  188. VOID
  189. CmpUnlockKCBTree(
  190. )
  191. /*++
  192. Routine Description:
  193. Unlock the KCB_TREE.
  194. --*/
  195. {
  196. ASSERT_KCB_LOCK_OWNED();
  197. ExReleaseResourceLite(&CmpKcbLock);
  198. }
  199. #if DBG
  200. BOOLEAN
  201. CmpTestKCBLock(VOID)
  202. {
  203. BOOLEAN rc;
  204. rc = TRUE;
  205. if (ExIsResourceAcquiredShared(&CmpKcbLock) == 0) {
  206. rc = FALSE;
  207. }
  208. return rc;
  209. }
  210. BOOLEAN
  211. CmpTestKCBLockExclusive(VOID)
  212. {
  213. if (ExIsResourceAcquiredExclusiveLite(&CmpKcbLock) == 0) {
  214. return(FALSE);
  215. }
  216. return(TRUE);
  217. }
  218. #endif