[FREELDR:NTLDR] Expose and use the CurrentControlSetKey handle.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 21 Mar 2022 22:07:50 +0000 (23:07 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 7 Apr 2022 01:19:11 +0000 (03:19 +0200)
This allows: (i) to shorten dramatically the lengths of the static
registry path strings being used (and thus, allow for reduced binary
file size), and (ii) to prepare future support for selecting different
control sets (and related Last-Known-Good configurations).

boot/freeldr/freeldr/ntldr/registry.c
boot/freeldr/freeldr/ntldr/registry.h
boot/freeldr/freeldr/ntldr/winldr.c
boot/freeldr/freeldr/ntldr/wlregistry.c

index 3db2758..ea68cc3 100644 (file)
@@ -27,7 +27,7 @@ DBG_DEFAULT_CHANNEL(REGISTRY);
 
 static PCMHIVE CmHive;
 static PCM_KEY_NODE RootKeyNode;
-static HKEY CurrentControlSetKey;
+HKEY CurrentControlSetKey;
 
 PVOID
 NTAPI
index 8368749..0743be4 100644 (file)
@@ -32,6 +32,8 @@ LONG
 RegInitCurrentControlSet(
     _In_ BOOLEAN LastKnownGood);
 
+extern HKEY CurrentControlSetKey;
+
 /*
  * LONG
  * RegCloseKey(
index c923330..5427b14 100644 (file)
@@ -473,9 +473,7 @@ WinLdrDetectVersion(VOID)
     LONG rc;
     HKEY hKey;
 
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
-                    &hKey);
+    rc = RegOpenKey(CurrentControlSetKey, L"Control\\Terminal Server", &hKey);
     if (rc != ERROR_SUCCESS)
     {
         /* Key doesn't exist; assume NT 4.0 */
@@ -905,15 +903,11 @@ WinLdrInitErrataInf(
     /* Open either the 'BiosInfo' (Windows <= 2003) or the 'Errata' (Vista+) key */
     if (OperatingSystemVersion >= _WIN32_WINNT_VISTA)
     {
-        rc = RegOpenKey(NULL,
-                        L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Errata",
-                        &hKey);
+        rc = RegOpenKey(CurrentControlSetKey, L"Control\\Errata", &hKey);
     }
     else // (OperatingSystemVersion <= _WIN32_WINNT_WS03)
     {
-        rc = RegOpenKey(NULL,
-                        L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\BiosInfo",
-                        &hKey);
+        rc = RegOpenKey(CurrentControlSetKey, L"Control\\BiosInfo", &hKey);
     }
     if (rc != ERROR_SUCCESS)
     {
index 92bf593..cc139b7 100644 (file)
@@ -20,6 +20,7 @@ ULONG TotalNLSSize = 0;
 
 static BOOLEAN
 WinLdrGetNLSNames(
+    _In_ HKEY ControlSet,
     _Inout_ PUNICODE_STRING AnsiFileName,
     _Inout_ PUNICODE_STRING OemFileName,
     _Inout_ PUNICODE_STRING LangFileName, // CaseTable
@@ -186,7 +187,8 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
     WinLdrScanRegistry(&LoaderBlock->BootDriverListHead, SystemRoot);
 
     /* Get names of NLS files */
-    Success = WinLdrGetNLSNames(&AnsiFileName,
+    Success = WinLdrGetNLSNames(CurrentControlSetKey,
+                                &AnsiFileName,
                                 &OemFileName,
                                 &LangFileName,
                                 &OemHalFileName);
@@ -219,6 +221,7 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
 // Queries registry for those three file names
 static BOOLEAN
 WinLdrGetNLSNames(
+    _In_ HKEY ControlSet,
     _Inout_ PUNICODE_STRING AnsiFileName,
     _Inout_ PUNICODE_STRING OemFileName,
     _Inout_ PUNICODE_STRING LangFileName, // CaseTable
@@ -230,9 +233,7 @@ WinLdrGetNLSNames(
     WCHAR szIdBuffer[80];
 
     /* Open the CodePage key */
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
-                    &hKey);
+    rc = RegOpenKey(ControlSet, L"Control\\NLS\\CodePage", &hKey);
     if (rc != ERROR_SUCCESS)
     {
         //TRACE("Couldn't open CodePage registry key");
@@ -305,9 +306,7 @@ WinLdrGetNLSNames(
     RegCloseKey(hKey);
 
     /* Open the Language key */
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
-                    &hKey);
+    rc = RegOpenKey(ControlSet, L"Control\\NLS\\Language", &hKey);
     if (rc != ERROR_SUCCESS)
     {
         //TRACE("Couldn't open Language registry key");
@@ -545,9 +544,7 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead,
     BOOLEAN Success;
 
     /* Get 'group order list' key */
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
-                    &hOrderKey);
+    rc = RegOpenKey(CurrentControlSetKey, L"Control\\GroupOrderList", &hOrderKey);
     if (rc != ERROR_SUCCESS)
     {
         TRACE_CH(REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc);
@@ -555,9 +552,7 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead,
     }
 
     /* Get 'services' key */
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
-                    &hServiceKey);
+    rc = RegOpenKey(CurrentControlSetKey, L"Services", &hServiceKey);
     if (rc != ERROR_SUCCESS)
     {
         TRACE_CH(REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc);
@@ -566,9 +561,7 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead,
     }
 
     /* Get 'service group order' key */
-    rc = RegOpenKey(NULL,
-                    L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
-                    &hGroupKey);
+    rc = RegOpenKey(CurrentControlSetKey, L"Control\\ServiceGroupOrder", &hGroupKey);
     if (rc != ERROR_SUCCESS)
     {
         TRACE_CH(REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc);