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.

177 lines
4.1 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. RgInitPredefinedKeys();
  57. #ifdef WANT_DYNKEY_SUPPORT
  58. // Initialize HKEY_DYN_DATA. If anything fails here, we won't stop the
  59. // initialize of the entire registry.
  60. if (RgCreateFileInfoNew(&g_RgDynDataKey.lpFileInfo, g_RgNull,
  61. CFIN_VERSION20 | CFIN_VOLATILE) == ERROR_SUCCESS)
  62. RgInitRootKeyFromFileInfo(&g_RgDynDataKey);
  63. ASSERT(!(g_RgDynDataKey.Flags & KEYF_INVALID));
  64. #endif
  65. return ERROR_SUCCESS;
  66. MemoryError:
  67. // Release anything that we may have allocated up to this point.
  68. VMMRegLibDetach();
  69. TRACE(("VMMRegLibAttach returning ERROR_OUTOFMEMORY\n"));
  70. return ERROR_OUTOFMEMORY;
  71. }
  72. #ifdef VXD
  73. #pragma VxD_SYSEXIT_CODE_SEG
  74. #endif
  75. #ifdef WANT_FULL_MEMORY_CLEANUP
  76. //
  77. // RgDetachPredefKey
  78. //
  79. // Destroys the memory associated with a predefined key and marks the key
  80. // invalid.
  81. //
  82. VOID
  83. INTERNAL
  84. RgDetachPredefKey(
  85. HKEY hKey
  86. )
  87. {
  88. if (!(hKey-> Flags & KEYF_INVALID)) {
  89. RgDestroyFileInfo(hKey-> lpFileInfo);
  90. hKey-> Flags |= KEYF_INVALID;
  91. }
  92. }
  93. #endif
  94. //
  95. // VMMRegLibDetach
  96. //
  97. // Releases resources allocated by VMMRegLibAttach. This function may be
  98. // called after VMMRegLibDetach returns an error, so this function and all
  99. // functions it calls must be aware that their corresponding 'alloc' function
  100. // was not called.
  101. //
  102. VOID
  103. REGAPI
  104. VMMRegLibDetach(
  105. VOID
  106. )
  107. {
  108. RgEnumFileInfos(RgFlushFileInfo);
  109. #ifdef VXD
  110. // Reduce the chance that we'll go and try to touch the file again!
  111. //g_RgFileAccessDisabled = TRUE;
  112. // Unfortunately, we cannot disable writing to the file in this case
  113. // because Win95 allowed it, and there is at least one VXD that attempts to write
  114. // to the registry when called with the Sys_VM_Terminate message.
  115. // However, it seemed like a good idea since the file system is shutting down.
  116. #endif
  117. #ifdef WANT_REGREPLACEKEY
  118. // Win95 difference: file replacement used to take place on system startup,
  119. // not system exit. It's much easier to deal with file replacement now
  120. // since we know somebody called RegReplaceKey and we only have to do the
  121. // work in one component, instead of multiple copies in io.sys, VMM loader,
  122. // and VMM.
  123. RgEnumFileInfos(RgReplaceFileInfo);
  124. #endif
  125. #ifdef WANT_FULL_MEMORY_CLEANUP
  126. //
  127. // Delete the FILE_INFO of each of these top-level keys will cause all
  128. // of their hives to be deleted.
  129. //
  130. RgDetachPredefKey(&g_RgLocalMachineKey);
  131. RgDetachPredefKey(&g_RgUsersKey);
  132. #ifdef WANT_DYNKEY_SUPPORT
  133. RgDetachPredefKey(&g_RgDynDataKey);
  134. #endif
  135. RgFreeKeyHandleStructures();
  136. if (!IsNullPtr(g_RgWorkBuffer))
  137. RgFreeMemory(g_RgWorkBuffer);
  138. #endif
  139. ASSERT(g_RgDatablockLockCount == 0);
  140. ASSERT(g_RgKeynodeLockCount == 0);
  141. #ifdef WANT_FULL_MEMORY_CLEANUP
  142. ASSERT(g_RgMemoryBlockCount == 0);
  143. #endif
  144. }