From c6b08f89ba5282eef131bbdb74cd766dc154c6f3 Mon Sep 17 00:00:00 2001 From: jief666 Date: Mon, 27 Sep 2021 10:18:52 +0300 Subject: [PATCH] Change DsdtsList from statically allocated to XStringWArray. --- rEFIt_UEFI/Platform/Settings.cpp | 3 +-- rEFIt_UEFI/Platform/Settings.h | 3 +-- rEFIt_UEFI/refit/main.cpp | 28 ++++++---------------------- rEFIt_UEFI/refit/menu.cpp | 4 ++-- 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 809122bb5..5458ab540 100755 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -90,8 +90,7 @@ EFI_EDID_DISCOVERED_PROTOCOL *EdidDiscovered; XStringWArray ThemeNameArray; XStringWArray ConfigsList; -UINTN DsdtsNum = 0; -CHAR16 *DsdtsList[20]; +XStringWArray DsdtsList; XObjArray AudioList; // firmware diff --git a/rEFIt_UEFI/Platform/Settings.h b/rEFIt_UEFI/Platform/Settings.h index c6c24ca30..5154fb006 100755 --- a/rEFIt_UEFI/Platform/Settings.h +++ b/rEFIt_UEFI/Platform/Settings.h @@ -2749,8 +2749,7 @@ extern XObjArray AudioList; extern XStringWArray ThemeNameArray; extern XStringWArray ConfigsList; -extern CHAR16* DsdtsList[20]; -extern UINTN DsdtsNum; +extern XStringWArray DsdtsList; //extern INTN ScrollButtonsHeight; //extern INTN ScrollBarDecorationsHeight; //extern INTN ScrollScrollDecorationsHeight; diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 3cbeaa6ee..1e91d52dd 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -134,8 +134,6 @@ extern void HelpRefit(void); extern void AboutRefit(void); //extern BOOLEAN BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize, LOADER_ENTRY *Entry); -extern UINTN DsdtsNum; -extern CHAR16 *DsdtsList[]; extern EFI_AUDIO_IO_PROTOCOL *AudioIo; extern EFI_DXE_SERVICES *gDS; @@ -791,12 +789,7 @@ void LOADER_ENTRY::StartLoader() //Free memory ConfigsList.setEmpty(); - for (size_t i = 0; i < DsdtsNum; i++) { - if (DsdtsList[i]) { - FreePool(DsdtsList[i]); - DsdtsList[i] = NULL; - } - } + DsdtsList.setEmpty(); OptionMenu.FreeMenu(); //there is a place to free memory // GuiAnime @@ -2472,7 +2465,7 @@ GetListOfConfigs() } size_t NameLen = wcslen(DirEntry->FileName) - 6; //without ".plist" if ( NameLen <= MAX_INTN ) { - ConfigsList.AddReference(SWPrintf("%.*ls", (int)NameLen, DirEntry->FileName).forgetDataWithoutFreeing(), true); // this avoid to realloctae and copy memory + ConfigsList.AddReference(SWPrintf("%.*ls", (int)NameLen, DirEntry->FileName).forgetDataWithoutFreeing(), true); // this avoid to reallocate and copy memory DBG("- %ls\n", DirEntry->FileName); }else{ DBG("- bug!, NameLen > MAX_INTN"); @@ -2486,16 +2479,8 @@ GetListOfDsdts() { REFIT_DIR_ITER DirIter; EFI_FILE_INFO *DirEntry; - INTN NameLen; - if (DsdtsNum > 0) { - for (UINTN i = 0; i < DsdtsNum; i++) { - if (DsdtsList[DsdtsNum] != NULL) { - FreePool(DsdtsList[DsdtsNum]); - } - } - } - DsdtsNum = 0; + DsdtsList.setEmpty(); OldChosenDsdt = 0xFFFF; DirIterOpen(&selfOem.getConfigDir(), L"ACPI\\patched", &DirIter); @@ -2505,11 +2490,10 @@ GetListOfDsdts() continue; } if ( gSettings.ACPI.DSDT.DsdtName.isEqualIC(DirEntry->FileName) ) { - OldChosenDsdt = DsdtsNum; + OldChosenDsdt = DsdtsList.size(); // DirEntry->FileName is not yet inserted into DsdtsList. So its index will be DsdtsList.size() } - NameLen = StrLen(DirEntry->FileName); //with ".aml" - DsdtsList[DsdtsNum] = (CHAR16*)AllocateCopyPool(NameLen * sizeof(CHAR16) + 2, DirEntry->FileName); // if changing, notice freepool above - DsdtsList[DsdtsNum++][NameLen] = L'\0'; + size_t NameLen = wcslen(DirEntry->FileName); //with ".aml" + DsdtsList.AddReference(SWPrintf("%.*ls", (int)NameLen, DirEntry->FileName).forgetDataWithoutFreeing(), true); // this avoid to reallocate and copy memory DBG("- %ls\n", DirEntry->FileName); } DirIterClose(&DirIter); diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index ffba9898c..6e4de1716 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -1011,7 +1011,7 @@ void ApplyInputs(void) if (OldChosenDsdt == 0xFFFF) { gSettings.ACPI.DSDT.DsdtName = L"BIOS.aml"_XSW; } else { - gSettings.ACPI.DSDT.DsdtName.SWPrintf("%ls", DsdtsList[OldChosenDsdt]); + gSettings.ACPI.DSDT.DsdtName = DsdtsList[OldChosenDsdt]; } } i++; //117 @@ -2134,7 +2134,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuDsdts() SubScreen->AddMenuInfoLine_f("Select a DSDT file:"); SubScreen->AddMenuItemSwitch(116, "BIOS.aml", FALSE); - for (i = 0; i < DsdtsNum; i++) { + for (i = 0; i < DsdtsList.size(); i++) { InputBootArgs = new REFIT_MENU_SWITCH; InputBootArgs->Title.takeValueFrom(DsdtsList[i]); // InputBootArgs->Tag = TAG_SWITCH_OLD;