From fa80176a628790d07dce2c6ee238e5c8a94c31c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Bi=C8=99oc?= Date: Sun, 22 Oct 2023 21:28:39 +0200 Subject: [PATCH] [FREELDR][HACK] Temporarily disable registry recovery code for AMD64 The newly implemented code for registry recovery makes the FreeLdr binary to grow in size, to the point that it would BSOD because the PE image is too big. For now we have to temporarily disable any of the newly added code, until either FreeLdr is split into a basic PE bootloader image itself and a "FreeLdrlib" that is used by the PE image to access various bootloader APIs or another proper solution is found. --- boot/freeldr/freeldr/ntldr/registry.c | 22 ++++++++++++++++++++++ sdk/lib/cmlib/hiveinit.c | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/boot/freeldr/freeldr/ntldr/registry.c b/boot/freeldr/freeldr/ntldr/registry.c index 0b81b71cf16..73d6f68097e 100644 --- a/boot/freeldr/freeldr/ntldr/registry.c +++ b/boot/freeldr/freeldr/ntldr/registry.c @@ -99,7 +99,14 @@ RegInitializeHive( _In_ BOOLEAN LoadAlternate) { NTSTATUS Status; +/* + * FIXME: Disable compilation of some parts of code for AMD64 for now, + * since it makes the FreeLdr binary size so large that it prevents + * x64 ROS from booting. + */ +#if !defined(_M_AMD64) CM_CHECK_REGISTRY_STATUS CmStatusCode; +#endif /* Initialize the hive */ Status = HvInitialize(GET_HHIVE(CmHive), @@ -121,6 +128,8 @@ RegInitializeHive( return FALSE; } +/* FIXME: See the comment above */ +#if !defined(_M_AMD64) /* Now check the hive and purge volatile data */ CmStatusCode = CmCheckRegistry(CmHive, CM_CHECK_REGISTRY_BOOTLOADER_PURGE_VOLATILES | CM_CHECK_REGISTRY_VALIDATE_HIVE); if (!CM_CHECK_REGISTRY_SUCCESS(CmStatusCode)) @@ -128,10 +137,13 @@ RegInitializeHive( ERR("CmCheckRegistry detected problems with the loaded flat hive (check code %lu)\n", CmStatusCode); return FALSE; } +#endif return TRUE; } +/* FIXME: See the comment above */ +#if !defined(_M_AMD64) /** * @brief * Loads and reads a hive log at specified @@ -406,6 +418,7 @@ RegRecoverDataHive( HiveBaseBlock->CheckSum = HvpHiveHeaderChecksum(HiveBaseBlock); return TRUE; } +#endif /** * @brief @@ -451,6 +464,14 @@ RegImportBinaryHive( CmSystemHive = FrLdrTempAlloc(sizeof(CMHIVE), 'eviH'); Success = RegInitializeHive(CmSystemHive, ChunkBase, LoadAlternate); if (!Success) +/* FIXME: See the comment above */ +#if defined(_M_AMD64) + { + ERR("Corrupted hive %p!\n", ChunkBase); + FrLdrTempFree(CmSystemHive, 'eviH'); + return FALSE; + } +#else { /* Free the buffer and retry again */ FrLdrTempFree(CmSystemHive, 'eviH'); @@ -484,6 +505,7 @@ RegImportBinaryHive( */ ((PHBASE_BLOCK)ChunkBase)->BootRecover = HBOOT_BOOT_RECOVERED_BY_HIVE_LOG; } +#endif /* Save the root key node */ SystemHive = GET_HHIVE(CmSystemHive); diff --git a/sdk/lib/cmlib/hiveinit.c b/sdk/lib/cmlib/hiveinit.c index d4adeb99518..0b03ddf258b 100644 --- a/sdk/lib/cmlib/hiveinit.c +++ b/sdk/lib/cmlib/hiveinit.c @@ -619,6 +619,11 @@ HvpGetHiveHeader( return HiveSuccess; } +/* + * FIXME: Disable compilation for AMD64 for now since it makes + * the FreeLdr binary size so large it makes booting impossible. + */ +#if !defined(_M_AMD64) /** * @brief * Computes the hive space size by querying @@ -960,6 +965,7 @@ HvpRecoverDataFromLog( return HiveSuccess; } +#endif /** * @brief @@ -998,7 +1004,12 @@ HvLoadHive( NTSTATUS Status; BOOLEAN Success; PHBASE_BLOCK BaseBlock = NULL; +/* FIXME: See the comment above (near HvpQueryHiveSize) */ +#if defined(_M_AMD64) + ULONG Result; +#else ULONG Result, Result2; +#endif LARGE_INTEGER TimeStamp; ULONG Offset = 0; PVOID HiveData; @@ -1044,6 +1055,12 @@ HvLoadHive( /* Hive header needs a repair */ case RecoverHeader: +/* FIXME: See the comment above (near HvpQueryHiveSize) */ +#if defined(_M_AMD64) + { + return STATUS_REGISTRY_CORRUPT; + } +#else { /* Check if this hive has a log at hand to begin with */ #if (NTDDI_VERSION < NTDDI_VISTA) @@ -1092,6 +1109,7 @@ HvLoadHive( break; } +#endif } /* Set the boot type */ @@ -1384,6 +1402,8 @@ HvInitialize( return Status; } +/* FIXME: See the comment above (near HvpQueryHiveSize) */ +#if !defined(_M_AMD64) /* * Check if we have recovered this hive. We are responsible to * flush the primary hive back to backing storage afterwards. @@ -1418,7 +1438,7 @@ HvInitialize( */ Status = STATUS_SUCCESS; } - +#endif break; }