Leaked source code of windows server 2003
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.

209 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Init.c
  5. Abstract:
  6. This module contains the entry point for the Win32 Registry APIs
  7. client side DLL.
  8. Author:
  9. David J. Gilman (davegi) 06-Feb-1992
  10. --*/
  11. #include <rpc.h>
  12. #include "regrpc.h"
  13. #include "client.h"
  14. #include "ntconreg.h"
  15. #include <wow64reg.h>
  16. #if DBG
  17. BOOLEAN BreakPointOnEntry = FALSE;
  18. #endif
  19. BOOL LocalInitializeRegCreateKey();
  20. BOOL LocalCleanupRegCreateKey();
  21. BOOL InitializePredefinedHandlesTable();
  22. BOOL CleanupPredefinedHandlesTable();
  23. BOOL InitializeClassesRoot();
  24. BOOL CleanupClassesRoot(BOOL fOnlyThisThread);
  25. #if defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  26. BOOL InitializeInstrumentedRegClassHeap();
  27. BOOL CleanupInstrumentedRegClassHeap();
  28. #endif // defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  29. #if defined(LEAK_TRACK)
  30. BOOL InitializeLeakTrackTable();
  31. BOOL CleanupLeakTrackTable();
  32. #endif // defined (LEAK_TRACK)
  33. enum
  34. {
  35. ENUM_TABLE_REMOVEKEY_CRITERIA_THISTHREAD = 1,
  36. ENUM_TABLE_REMOVEKEY_CRITERIA_ANYTHREAD = 2
  37. };
  38. HKEY HKEY_ClassesRoot = NULL;
  39. extern BOOL gbDllHasThreadState ;
  40. BOOL
  41. RegInitialize (
  42. IN HANDLE Handle,
  43. IN DWORD Reason,
  44. IN PVOID Reserved
  45. )
  46. /*++
  47. Routine Description:
  48. Returns TRUE.
  49. Arguments:
  50. Handle - Unused.
  51. Reason - Unused.
  52. Reserved - Unused.
  53. Return Value:
  54. BOOL - Returns TRUE.
  55. --*/
  56. {
  57. UNREFERENCED_PARAMETER( Handle );
  58. switch( Reason ) {
  59. case DLL_PROCESS_ATTACH:
  60. #ifndef REMOTE_NOTIFICATION_DISABLED
  61. if( !InitializeRegNotifyChangeKeyValue( ) ||
  62. !LocalInitializeRegCreateKey() ||
  63. !InitializePredefinedHandlesTable() ) {
  64. return( FALSE );
  65. }
  66. #else
  67. #if defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  68. if ( !InitializeInstrumentedRegClassHeap()) {
  69. return FALSE;
  70. }
  71. #endif // defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  72. if( !LocalInitializeRegCreateKey() ||
  73. !InitializePredefinedHandlesTable() ||
  74. !InitializeClassesRoot()) {
  75. return( FALSE );
  76. }
  77. #endif
  78. #if defined(LEAK_TRACK)
  79. InitializeLeakTrackTable();
  80. // ginore errors
  81. #endif // LEAK_TRACK
  82. if ( !PerfRegInitialize() ) {
  83. return( FALSE );
  84. }
  85. #if defined(_WIN64)
  86. //
  87. // For 64bit system there is also a wow64 section in the registry that
  88. // might need some initialization.
  89. //
  90. if (!Wow64InitRegistry (1))
  91. return(FALSE);
  92. #endif
  93. return( TRUE );
  94. break;
  95. case DLL_PROCESS_DETACH:
  96. // Reserved == NULL when this is called via FreeLibrary,
  97. // we need to cleanup Performance keys.
  98. // Reserved != NULL when this is called during process exits,
  99. // no need to do anything.
  100. if( Reserved == NULL &&
  101. !CleanupPredefinedHandles()) {
  102. return( FALSE );
  103. }
  104. //initialized and used in ..\server\regclass.c
  105. if (NULL != HKEY_ClassesRoot)
  106. NtClose(HKEY_ClassesRoot);
  107. #ifndef REMOTE_NOTIFICATION_DISABLED
  108. if( !CleanupRegNotifyChangeKeyValue( ) ||
  109. !LocalCleanupRegCreateKey() ||
  110. !CleanupPredefinedHandlesTable() ||
  111. !CleanupClassesRoot( FALSE ) {
  112. return( FALSE );
  113. }
  114. #else
  115. if( !LocalCleanupRegCreateKey() ||
  116. !CleanupPredefinedHandlesTable() ||
  117. !CleanupClassesRoot( FALSE )) {
  118. return( FALSE );
  119. }
  120. #if defined(LEAK_TRACK)
  121. CleanupLeakTrackTable();
  122. #endif // LEAK_TRACK
  123. #if defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  124. if ( !CleanupInstrumentedRegClassHeap()) {
  125. return FALSE;
  126. }
  127. #endif // defined(_REGCLASS_MALLOC_INSTRUMENTED_)
  128. #endif
  129. if ( !PerfRegCleanup() ) {
  130. return FALSE;
  131. }
  132. #if defined(_WIN64)
  133. //
  134. // For 64bit system there is also a wow64 section in the registry that
  135. // might need some CleanUp.
  136. //
  137. if (!Wow64CloseRegistry (1))
  138. return(FALSE);
  139. #endif
  140. return( TRUE );
  141. break;
  142. case DLL_THREAD_ATTACH:
  143. break;
  144. case DLL_THREAD_DETACH:
  145. if ( gbDllHasThreadState ) {
  146. return CleanupClassesRoot( TRUE );
  147. }
  148. break;
  149. }
  150. return TRUE;
  151. }