From 2ee33ab22945d423227daf927f7c8c993c033e06 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Wed, 27 Aug 2025 19:44:52 +0200 Subject: [PATCH] Refactor BlGetConfigValue to return EFI_STATUS and output value via parameter --- sdk/xtdk/bltypes.h | 2 +- xtldr/config.c | 21 ++++++++++++++------- xtldr/debug.c | 2 +- xtldr/includes/xtldr.h | 5 +++-- xtldr/modules/beep/beep.c | 4 +++- xtldr/textui.c | 2 +- xtldr/xtldr.c | 8 +++++--- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index 86a9878..23cb2df 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -54,7 +54,7 @@ typedef EFI_STATUS (*PBL_CLOSE_XT_PROTOCOL)(IN PEFI_HANDLE Handle, IN PEFI_GUID typedef BOOLEAN (*PBL_CONFIG_GET_BOOLEAN_VALUE)(IN CONST PWCHAR ConfigName); typedef EFI_STATUS (*PBL_CONFIG_GET_BOOT_OPTION_VALUE)(IN PLIST_ENTRY Options, IN CONST PWCHAR OptionName, OUT PWCHAR *OptionValue); typedef VOID (*PBL_CONFIG_GET_EDITABLE_OPTIONS)(OUT CONST PWCHAR **OptionsArray, OUT PSIZE_T OptionsCount); -typedef PWCHAR (*PBL_CONFIG_GET_VALUE)(IN CONST PWCHAR ConfigName); +typedef EFI_STATUS (*PBL_CONFIG_GET_VALUE)(IN CONST PWCHAR ConfigName, OUT PWCHAR *ConfigValue); typedef EFI_STATUS (*PBL_CONFIG_SET_BOOT_OPTION_VALUE)(IN PLIST_ENTRY Options, IN CONST PWCHAR OptionName, IN CONST PWCHAR OptionValue); typedef VOID (*PBL_CONSOLE_CLEAR_SCREEN)(); typedef VOID (*PBL_CONSOLE_DISABLE_CURSOR)(); diff --git a/xtldr/config.c b/xtldr/config.c index 60c4f66..4dea6fd 100644 --- a/xtldr/config.c +++ b/xtldr/config.c @@ -99,7 +99,7 @@ BlGetConfigBooleanValue(IN CONST PWCHAR ConfigName) PWCHAR Value; /* Get config value */ - Value = BlGetConfigValue(ConfigName); + BlGetConfigValue(ConfigName, &Value); /* Check if option is enabled */ if(RtlCompareWideStringInsensitive(Value, L"ENABLED", 0) == 0 || @@ -126,8 +126,9 @@ BlGetConfigBooleanValue(IN CONST PWCHAR ConfigName) * @since XT 1.0 */ XTCDECL -PWCHAR -BlGetConfigValue(IN CONST PWCHAR ConfigName) +EFI_STATUS +BlGetConfigValue(IN CONST PWCHAR ConfigName, + OUT PWCHAR *ConfigValue) { PXTBL_CONFIG_ENTRY ConfigEntry; PLIST_ENTRY ConfigListEntry; @@ -135,6 +136,9 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName) EFI_STATUS Status; PWCHAR Value; + /* Assume the option will not be found */ + *ConfigValue = NULL; + /* Get config entry name length */ KeyLength = RtlWideStringLength(ConfigName, 0); @@ -157,13 +161,14 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName) { /* Memory allocation failure, return NULL */ BlDebugPrint(L"ERROR: Memory allocation failure (Status Code: 0x%zX)\n", Status); - return NULL; + return Status; } /* Copy value and return it */ RtlCopyMemory(Value, ConfigEntry->Value, ValueLength * sizeof(WCHAR)); Value[ValueLength] = L'\0'; - return Value; + *ConfigValue = Value; + return STATUS_EFI_SUCCESS; } /* Move to the next config entry */ @@ -171,7 +176,7 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName) } /* Config entry not found, return NULL */ - return NULL; + return STATUS_EFI_NOT_FOUND; } /** @@ -852,6 +857,7 @@ VOID BlpUpdateConfiguration(IN PLIST_ENTRY NewConfig) { PXTBL_CONFIG_ENTRY ConfigEntry; + PWCHAR ConfigValue; PLIST_ENTRY ConfigListEntry, NextListEntry; /* Iterate through new config entries */ @@ -865,7 +871,8 @@ BlpUpdateConfiguration(IN PLIST_ENTRY NewConfig) NextListEntry = ConfigListEntry->Flink; /* Make sure config entry does not exist yet */ - if(BlGetConfigValue(ConfigEntry->Name) == NULL) + BlGetConfigValue(ConfigEntry->Name, &ConfigValue); + if(ConfigValue == NULL) { /* Remove new config entry from input list and put it into global config list */ RtlRemoveEntryList(&ConfigEntry->Flink); diff --git a/xtldr/debug.c b/xtldr/debug.c index b607f58..74cfdf6 100644 --- a/xtldr/debug.c +++ b/xtldr/debug.c @@ -105,7 +105,7 @@ BlpInitializeDebugConsole() BaudRate = 0; /* Get debug configuration */ - DebugConfiguration = BlGetConfigValue(L"DEBUG"); + BlGetConfigValue(L"DEBUG", &DebugConfiguration); /* Make sure any debug options are provided and debug console is not initialized yet */ if(DebugConfiguration && BlpStatus.DebugPort == 0) diff --git a/xtldr/includes/xtldr.h b/xtldr/includes/xtldr.h index 25bad02..9064a0a 100644 --- a/xtldr/includes/xtldr.h +++ b/xtldr/includes/xtldr.h @@ -149,8 +149,9 @@ BOOLEAN BlGetConfigBooleanValue(IN CONST PWCHAR ConfigName); XTCDECL -PWCHAR -BlGetConfigValue(IN CONST PWCHAR ConfigName); +EFI_STATUS +BlGetConfigValue(IN CONST PWCHAR ConfigName, + OUT PWCHAR *ConfigValue); XTCDECL EFI_STATUS diff --git a/xtldr/modules/beep/beep.c b/xtldr/modules/beep/beep.c index 26a9d1d..596f3ee 100644 --- a/xtldr/modules/beep/beep.c +++ b/xtldr/modules/beep/beep.c @@ -196,6 +196,7 @@ XtLdrModuleMain(IN EFI_HANDLE ImageHandle, IN PEFI_SYSTEM_TABLE SystemTable) { EFI_STATUS Status; + PWCHAR Tune; /* Open the XTLDR protocol */ Status = BlGetXtLdrProtocol(SystemTable, ImageHandle, &XtLdrProtocol); @@ -206,7 +207,8 @@ XtLdrModuleMain(IN EFI_HANDLE ImageHandle, } /* Play the tune set in the configuration */ - BpPlayTune(XtLdrProtocol->Config.GetValue(L"TUNE")); + XtLdrProtocol->Config.GetValue(L"TUNE", &Tune); + BpPlayTune(Tune); /* Return success */ return STATUS_EFI_SUCCESS; diff --git a/xtldr/textui.c b/xtldr/textui.c index ff7c523..8fdf7ef 100644 --- a/xtldr/textui.c +++ b/xtldr/textui.c @@ -57,7 +57,7 @@ BlDisplayBootMenu() } /* Get timeout from the configuration */ - TimeOutString = BlGetConfigValue(L"TIMEOUT"); + BlGetConfigValue(L"TIMEOUT", &TimeOutString); TimeOut = -1; /* Check if timeout is specified */ diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index d50deaa..dadc0c3 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -109,7 +109,7 @@ BlInitializeBootMenuList(IN ULONG MaxNameLength, NumberOfEntries = 0; /* Get default menu entry from configuration */ - DefaultMenuEntry = BlGetConfigValue(L"DEFAULT"); + BlGetConfigValue(L"DEFAULT", &DefaultMenuEntry); /* Check if configuration allows to use last booted OS */ if(BlGetConfigBooleanValue(L"KEEPLASTBOOT")) @@ -391,6 +391,7 @@ EFI_STATUS BlStartXtLoader(IN EFI_HANDLE ImageHandle, IN PEFI_SYSTEM_TABLE SystemTable) { + PWCHAR Modules; EFI_STATUS Status; /* Set the system table and image handle */ @@ -455,8 +456,9 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle, return Status; } - /* Load boot loader modules */ - Status = BlLoadModules(BlGetConfigValue(L"MODULES")); + /* Load all necessary modules */ + BlGetConfigValue(L"MODULES", &Modules); + Status = BlLoadModules(Modules); if(Status != STATUS_EFI_SUCCESS) { /* Failed to load modules */