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.

172 lines
3.8 KiB

  1. //
  2. // REGINIT.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. #include "pch.h"
  7. #ifdef DEBUG
  8. extern int g_RgDatablockLockCount;
  9. extern int g_RgKeynodeLockCount;
  10. extern int g_RgMemoryBlockCount;
  11. #endif
  12. #ifdef WANT_DYNKEY_SUPPORT
  13. #ifdef VXD
  14. #pragma VMM_IDATA_SEG
  15. #endif
  16. const char g_RgNull[] = "";
  17. #ifdef VXD
  18. #pragma VMM_PAGEABLE_DATA_SEG
  19. #endif
  20. #endif
  21. #ifdef VXD
  22. // Set when our post critical init routine is called indicating that it's safe
  23. // to make disk I/O calls. May also be set early when RegFlushKey gets the
  24. // magic HKEY_CRITICAL_FLUSH.
  25. BYTE g_RgPostCriticalInit = FALSE;
  26. // Set when RegFlushKey gets the magic HKEY_DISABLE_REG. No disk I/O will be
  27. // allowed after this flag is set.
  28. BYTE g_RgFileAccessDisabled = FALSE;
  29. #endif
  30. LPVOID g_RgWorkBuffer = NULL;
  31. #ifdef DEBUG
  32. BOOL g_RgWorkBufferBusy = FALSE;
  33. #endif
  34. #ifdef VXD
  35. #pragma VxD_INIT_CODE_SEG
  36. #endif
  37. //
  38. // VMMRegLibAttach
  39. //
  40. // Prepares the registry library for use by allocating any global resources.
  41. // If ERROR_SUCCESS is returned, then VMMRegLibDetach should be called to
  42. // release these resources.
  43. //
  44. LONG
  45. REGAPI
  46. VMMRegLibAttach(
  47. UINT Flags
  48. )
  49. {
  50. if (IsNullPtr((g_RgWorkBuffer = RgAllocMemory(SIZEOF_WORK_BUFFER))))
  51. goto MemoryError;
  52. #ifdef WANT_STATIC_KEYS
  53. if (!RgAllocKeyHandleStructures())
  54. goto MemoryError;
  55. #endif
  56. #ifdef WANT_DYNKEY_SUPPORT
  57. // Initialize HKEY_DYN_DATA. If anything fails here, we won't stop the
  58. // initialize of the entire registry.
  59. if (RgCreateFileInfoNew(&g_RgDynDataKey.lpFileInfo, g_RgNull,
  60. CFIN_VERSION20 | CFIN_VOLATILE) == ERROR_SUCCESS)
  61. RgInitRootKeyFromFileInfo(&g_RgDynDataKey);
  62. ASSERT(!(g_RgDynDataKey.Flags & KEYF_INVALID));
  63. #endif
  64. return ERROR_SUCCESS;
  65. MemoryError:
  66. // Release anything that we may have allocated up to this point.
  67. VMMRegLibDetach();
  68. TRACE(("VMMRegLibAttach returning ERROR_OUTOFMEMORY\n"));
  69. return ERROR_OUTOFMEMORY;
  70. }
  71. #ifdef VXD
  72. #pragma VxD_SYSEXIT_CODE_SEG
  73. #endif
  74. #ifdef WANT_FULL_MEMORY_CLEANUP
  75. //
  76. // RgDetachPredefKey
  77. //
  78. // Destroys the memory associated with a predefined key and marks the key
  79. // invalid.
  80. //
  81. VOID
  82. INTERNAL
  83. RgDetachPredefKey(
  84. HKEY hKey
  85. )
  86. {
  87. if (!(hKey-> Flags & KEYF_INVALID)) {
  88. RgDestroyFileInfo(hKey-> lpFileInfo);
  89. hKey-> Flags |= KEYF_INVALID;
  90. }
  91. }
  92. #endif
  93. //
  94. // VMMRegLibDetach
  95. //
  96. // Releases resources allocated by VMMRegLibAttach. This function may be
  97. // called after VMMRegLibDetach returns an error, so this function and all
  98. // functions it calls must be aware that their corresponding 'alloc' function
  99. // was not called.
  100. //
  101. VOID
  102. REGAPI
  103. VMMRegLibDetach(
  104. VOID
  105. )
  106. {
  107. RgEnumFileInfos(RgFlushFileInfo);
  108. #ifdef VXD
  109. // Reduce the chance that we'll go and try to touch the file again!
  110. g_RgFileAccessDisabled = TRUE;
  111. #endif
  112. #ifdef WANT_REGREPLACEKEY
  113. // Win95 difference: file replacement used to take place on system startup,
  114. // not system exit. It's much easier to deal with file replacement now
  115. // since we know somebody called RegReplaceKey and we only have to do the
  116. // work in one component, instead of multiple copies in io.sys, VMM loader,
  117. // and VMM.
  118. RgEnumFileInfos(RgReplaceFileInfo);
  119. #endif
  120. #ifdef WANT_FULL_MEMORY_CLEANUP
  121. //
  122. // Delete the FILE_INFO of each of these top-level keys will cause all
  123. // of their hives to be deleted.
  124. //
  125. RgDetachPredefKey(&g_RgLocalMachineKey);
  126. RgDetachPredefKey(&g_RgUsersKey);
  127. #ifdef WANT_DYNKEY_SUPPORT
  128. RgDetachPredefKey(&g_RgDynDataKey);
  129. #endif
  130. RgFreeKeyHandleStructures();
  131. if (!IsNullPtr(g_RgWorkBuffer))
  132. RgFreeMemory(g_RgWorkBuffer);
  133. #endif
  134. ASSERT(g_RgDatablockLockCount == 0);
  135. ASSERT(g_RgKeynodeLockCount == 0);
  136. #ifdef WANT_FULL_MEMORY_CLEANUP
  137. ASSERT(g_RgMemoryBlockCount == 0);
  138. #endif
  139. }