Rename memory related routines to follow naming convention
Builds / ExectOS (amd64) (push) Successful in 29s Details
Builds / ExectOS (i686) (push) Successful in 25s Details

This commit is contained in:
Rafal Kupiec 2024-01-15 15:13:34 +01:00
parent e64cf4d0aa
commit 8f40683270
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
9 changed files with 141 additions and 141 deletions

View File

@ -46,7 +46,7 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName)
ValueLength = RtlWideStringLength(ConfigEntry->Value, 0);
/* Allocate memory for value */
Status = BlMemoryAllocatePool(ValueLength * sizeof(WCHAR), (PVOID *)&Value);
Status = BlAllocateMemoryPool(ValueLength * sizeof(WCHAR), (PVOID *)&Value);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure, return NULL */
@ -265,15 +265,15 @@ BlpParseCommandLine(VOID)
}
/* Allocate memory for new option */
Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option);
Status = BlAllocateMemoryPool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option);
if(Status == STATUS_EFI_SUCCESS)
{
/* Allocate more memory for option name */
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name);
if(Status == STATUS_EFI_SUCCESS)
{
/* Allocate even more memory for option value */
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value);
}
}
if(Status != STATUS_EFI_SUCCESS)
@ -386,11 +386,11 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
SectionLength = RtlStringLength(SectionName, 0);
/* Allocate memory for new section */
Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_SECTION), (PVOID*)&Section);
Status = BlAllocateMemoryPool(sizeof(XTBL_CONFIG_SECTION), (PVOID*)&Section);
if(Status == STATUS_EFI_SUCCESS)
{
/* Allocate more memory for section name */
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (SectionLength + 1), (PVOID*)&Section->SectionName);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (SectionLength + 1), (PVOID*)&Section->SectionName);
}
if(Status != STATUS_EFI_SUCCESS)
{
@ -456,15 +456,15 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
ValueLength = RtlStringLength(Value, 0);
/* Allocate memory for new option */
Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option);
Status = BlAllocateMemoryPool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option);
if(Status == STATUS_EFI_SUCCESS)
{
/* Allocate more memory for option name */
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name);
if(Status == STATUS_EFI_SUCCESS)
{
/* Allocate even more memory for option value */
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value);
}
}
if(Status != STATUS_EFI_SUCCESS)

View File

@ -28,7 +28,7 @@ BlExitBootServices()
BlpStatus.BootServices = FALSE;
/* Allocate buffer for EFI memory map */
Status = BlMemoryAllocatePool(sizeof(EFI_MEMORY_MAP), (PVOID*)&MemoryMap);
Status = BlAllocateMemoryPool(sizeof(EFI_MEMORY_MAP), (PVOID*)&MemoryMap);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */

View File

@ -31,7 +31,7 @@ BlpActivateSerialIOController()
/* Allocate memory for single EFI_HANDLE, what should be enough in most cases */
PciHandleSize = sizeof(EFI_HANDLE);
Status = BlMemoryAllocatePool(PciHandleSize, (PVOID*)&PciHandle);
Status = BlAllocateMemoryPool(PciHandleSize, (PVOID*)&PciHandle);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
@ -43,8 +43,8 @@ BlpActivateSerialIOController()
if(Status == STATUS_EFI_BUFFER_TOO_SMALL)
{
/* Reallocate more memory as requested by UEFI */
BlMemoryFreePool(PciHandle);
Status = BlMemoryAllocatePool(PciHandleSize, (PVOID*)&PciHandle);
BlFreeMemoryPool(PciHandle);
Status = BlAllocateMemoryPool(PciHandleSize, (PVOID*)&PciHandle);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory reallocation failure */

View File

@ -19,6 +19,16 @@
typedef VOID (BLPRINTCHAR)(IN USHORT Character);
/* XTLDR routines forward references */
XTCDECL
EFI_STATUS
BlAllocateMemoryPages(IN UINT64 Pages,
OUT PEFI_PHYSICAL_ADDRESS Memory);
XTCDECL
EFI_STATUS
BlAllocateMemoryPool(IN UINT_PTR Size,
OUT PVOID *Memory);
XTCDECL
VOID
BlClearConsoleLine(IN ULONGLONG LineNo);
@ -98,6 +108,15 @@ BlFindVolumeDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL FsHandle,
IN CONST PWCHAR FileSystemPath,
OUT PEFI_DEVICE_PATH_PROTOCOL* DevicePath);
XTCDECL
EFI_STATUS
BlFreeMemoryPages(IN UINT64 Pages,
IN EFI_PHYSICAL_ADDRESS Memory);
XTCDECL
EFI_STATUS
BlFreeMemoryPool(IN PVOID Memory);
XTCDECL
PWCHAR
BlGetConfigValue(IN CONST PWCHAR ConfigName);
@ -158,25 +177,6 @@ BlLocateProtocolHandles(OUT PEFI_HANDLE *Handles,
OUT PUINT_PTR Count,
IN PEFI_GUID ProtocolGuid);
XTCDECL
EFI_STATUS
BlMemoryAllocatePages(IN UINT64 Pages,
OUT PEFI_PHYSICAL_ADDRESS Memory);
XTCDECL
EFI_STATUS
BlMemoryAllocatePool(IN UINT_PTR Size,
OUT PVOID *Memory);
XTCDECL
EFI_STATUS
BlMemoryFreePages(IN UINT64 Pages,
IN EFI_PHYSICAL_ADDRESS Memory);
XTCDECL
EFI_STATUS
BlMemoryFreePool(IN PVOID Memory);
XTCDECL
EFI_STATUS
BlOpenVolume(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath,

View File

@ -9,6 +9,88 @@
#include <xtldr.h>
/**
* This routine allocates one or more 4KB pages.
*
* @param Pages
* The number of contiguous 4KB pages to allocate.
*
* @param Memory
* The pointer to a physical address.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlAllocateMemoryPages(IN UINT64 Pages,
OUT PEFI_PHYSICAL_ADDRESS Memory)
{
return EfiSystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, Pages, Memory);
}
/**
* This routine allocates a pool memory.
*
* @param Size
* The number of bytes to allocate from the pool.
*
* @param Memory
* The pointer to a physical address.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlAllocateMemoryPool(IN UINT_PTR Size,
OUT PVOID *Memory)
{
/* Allocate pool */
return EfiSystemTable->BootServices->AllocatePool(EfiLoaderData, Size, Memory);
}
/**
* This routine frees memory pages.
*
* @param Pages
* The number of contiguous 4 KB pages to free.
*
* @param Memory
* The base physical address of the pages to be freed.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlFreeMemoryPages(IN UINT64 Pages,
IN EFI_PHYSICAL_ADDRESS Memory)
{
return EfiSystemTable->BootServices->FreePages(Memory, Pages);
}
/**
* Returns pool memory to the system.
*
* @param Memory
* The pointer to the buffer to free.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlFreeMemoryPool(IN PVOID Memory)
{
/* Free pool */
return EfiSystemTable->BootServices->FreePool(Memory);
}
/**
* Returns the memory descriptors which define a memory map of all the physical memory ranges reserved by the UEFI.
*
@ -50,14 +132,14 @@ BlGetMemoryMap(OUT PEFI_MEMORY_MAP MemoryMap)
if(MemoryMap->Map)
{
/* Free allocated memory */
BlMemoryFreePool(MemoryMap->Map);
BlFreeMemoryPool(MemoryMap->Map);
}
return Status;
}
/* Allocate the desired amount of memory */
MemoryMap->MapSize += 2 * MemoryMap->DescriptorSize;
BlMemoryAllocatePool(MemoryMap->MapSize, (PVOID *)&MemoryMap->Map);
BlAllocateMemoryPool(MemoryMap->MapSize, (PVOID *)&MemoryMap->Map);
}
while(Status == STATUS_EFI_BUFFER_TOO_SMALL);
@ -71,85 +153,3 @@ BlGetMemoryMap(OUT PEFI_MEMORY_MAP MemoryMap)
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* This routine allocates one or more 4KB pages.
*
* @param Pages
* The number of contiguous 4KB pages to allocate.
*
* @param Memory
* The pointer to a physical address.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlMemoryAllocatePages(IN UINT64 Pages,
OUT PEFI_PHYSICAL_ADDRESS Memory)
{
return EfiSystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, Pages, Memory);
}
/**
* This routine allocates a pool memory.
*
* @param Size
* The number of bytes to allocate from the pool.
*
* @param Memory
* The pointer to a physical address.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlMemoryAllocatePool(IN UINT_PTR Size,
OUT PVOID *Memory)
{
/* Allocate pool */
return EfiSystemTable->BootServices->AllocatePool(EfiLoaderData, Size, Memory);
}
/**
* This routine frees memory pages.
*
* @param Pages
* The number of contiguous 4 KB pages to free.
*
* @param Memory
* The base physical address of the pages to be freed.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlMemoryFreePages(IN UINT64 Pages,
IN EFI_PHYSICAL_ADDRESS Memory)
{
return EfiSystemTable->BootServices->FreePages(Memory, Pages);
}
/**
* Returns pool memory to the system.
*
* @param Memory
* The pointer to the buffer to free.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlMemoryFreePool(IN PVOID Memory)
{
/* Free pool */
return EfiSystemTable->BootServices->FreePool(Memory);
}

View File

@ -210,7 +210,7 @@ BlLoadModule(IN PWCHAR ModuleName)
}
/* Allocate memory for module information block */
Status = BlMemoryAllocatePool(sizeof(XTBL_MODULE_INFO), (PVOID*)&ModuleInfo);
Status = BlAllocateMemoryPool(sizeof(XTBL_MODULE_INFO), (PVOID*)&ModuleInfo);
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to allocate memory */
@ -251,7 +251,7 @@ BlLoadModule(IN PWCHAR ModuleName)
}
/* Allocate memory for module dependency */
Status = BlMemoryAllocatePool(sizeof(XTBL_MODULE_DEPS), (PVOID*)&ModuleDependencies);
Status = BlAllocateMemoryPool(sizeof(XTBL_MODULE_DEPS), (PVOID*)&ModuleDependencies);
if(Status == STATUS_EFI_SUCCESS)
{
/* Memory allocated successfully, store module's dependency */
@ -574,7 +574,7 @@ BlRegisterBootProtocol(IN PWCHAR SystemType,
}
/* Create new boot protocol entry */
Status = BlMemoryAllocatePool(sizeof(XTBL_BOOT_PROTOCOL), (PVOID *)&ProtocolEntry);
Status = BlAllocateMemoryPool(sizeof(XTBL_BOOT_PROTOCOL), (PVOID *)&ProtocolEntry);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
@ -625,11 +625,11 @@ BlpInstallXtLoaderProtocol()
BlpLdrProtocol.Disk.CloseVolume = BlCloseVolume;
BlpLdrProtocol.Disk.OpenVolume = BlOpenVolume;
BlpLdrProtocol.Disk.ReadFile = BlReadFile;
BlpLdrProtocol.Memory.AllocatePages = BlMemoryAllocatePages;
BlpLdrProtocol.Memory.AllocatePool = BlMemoryAllocatePool;
BlpLdrProtocol.Memory.AllocatePages = BlAllocateMemoryPages;
BlpLdrProtocol.Memory.AllocatePool = BlAllocateMemoryPool;
BlpLdrProtocol.Memory.CopyMemory = RtlCopyMemory;
BlpLdrProtocol.Memory.FreePages = BlMemoryFreePages;
BlpLdrProtocol.Memory.FreePool = BlMemoryFreePool;
BlpLdrProtocol.Memory.FreePages = BlFreeMemoryPages;
BlpLdrProtocol.Memory.FreePool = BlFreeMemoryPool;
BlpLdrProtocol.Memory.GetMemoryMap = BlGetMemoryMap;
BlpLdrProtocol.Memory.SetMemory = RtlSetMemory;
BlpLdrProtocol.Memory.ZeroMemory = RtlZeroMemory;

View File

@ -452,7 +452,7 @@ BlDisplayInputDialog(IN PWCHAR Caption,
/* Get initial input text length and allocate a buffer */
BufferLength = RtlWideStringLength(*InputFieldText, 0);
Status = BlMemoryAllocatePool(BufferLength * sizeof(WCHAR), (PVOID *)&InputFieldBuffer);
Status = BlAllocateMemoryPool(BufferLength * sizeof(WCHAR), (PVOID *)&InputFieldBuffer);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure, print error message and return */
@ -1213,7 +1213,7 @@ BlpDrawDialogMessage(IN PXTBL_DIALOG_HANDLE Handle,
/* Allocate memory for dialog box message */
Length = RtlWideStringLength(Message, 0);
Status = BlMemoryAllocatePool(Length * sizeof(WCHAR), (PVOID *)&Msg);
Status = BlAllocateMemoryPool(Length * sizeof(WCHAR), (PVOID *)&Msg);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure, print debug message and return */

View File

@ -166,7 +166,7 @@ BlEnumerateBlockDevices()
if(DriveType != XTBL_BOOT_DEVICE_UNKNOWN)
{
/* Allocate memory for block device */
Status = BlMemoryAllocatePool(sizeof(EFI_BLOCK_DEVICE), (PVOID *)&BlockDevice);
Status = BlAllocateMemoryPool(sizeof(EFI_BLOCK_DEVICE), (PVOID *)&BlockDevice);
if(Status != STATUS_EFI_SUCCESS)
{
BlDebugPrint(L"ERROR: Failed to allocate memory pool for block device (Status Code: 0x%lx)\n", Status);
@ -248,7 +248,7 @@ BlFindVolumeDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL FsHandle,
FsPathLength = RtlWideStringLength(FileSystemPath, 0) * sizeof(WCHAR);
/* Allocate memory pool for device path */
Status = BlMemoryAllocatePool(FsPathLength + DevicePathLength + sizeof(EFI_DEVICE_PATH_PROTOCOL),
Status = BlAllocateMemoryPool(FsPathLength + DevicePathLength + sizeof(EFI_DEVICE_PATH_PROTOCOL),
(PVOID *)DevicePath);
if(Status != STATUS_EFI_SUCCESS)
{
@ -516,7 +516,7 @@ BlReadFile(IN PEFI_FILE_HANDLE DirHandle,
ReadSize = sizeof(EFI_FILE_INFO) + 32;
/* Allocate necessary amount of memory */
Status = BlMemoryAllocatePool(ReadSize, (PVOID *)&FileInfo);
Status = BlAllocateMemoryPool(ReadSize, (PVOID *)&FileInfo);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
@ -529,8 +529,8 @@ BlReadFile(IN PEFI_FILE_HANDLE DirHandle,
if(Status == STATUS_EFI_BUFFER_TOO_SMALL)
{
/* Buffer is too small, but EFI tells the required size, so reallocate */
BlMemoryFreePool(&FileInfo);
Status = BlMemoryAllocatePool(ReadSize, (PVOID *)&FileInfo);
BlFreeMemoryPool(&FileInfo);
Status = BlAllocateMemoryPool(ReadSize, (PVOID *)&FileInfo);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
@ -547,7 +547,7 @@ BlReadFile(IN PEFI_FILE_HANDLE DirHandle,
{
/* Unable to get file information */
FileHandle->Close(FileHandle);
BlMemoryFreePool(&FileInfo);
BlFreeMemoryPool(&FileInfo);
return Status;
}
@ -556,12 +556,12 @@ BlReadFile(IN PEFI_FILE_HANDLE DirHandle,
Pages = EFI_SIZE_TO_PAGES(FileInfo->FileSize);
/* Allocate pages */
Status = BlMemoryAllocatePages(Pages, &Address);
Status = BlAllocateMemoryPages(Pages, &Address);
if(Status != STATUS_EFI_SUCCESS)
{
/* Pages allocation failure */
FileHandle->Close(FileHandle);
BlMemoryFreePool(&FileInfo);
BlFreeMemoryPool(&FileInfo);
return Status;
}
@ -576,14 +576,14 @@ BlReadFile(IN PEFI_FILE_HANDLE DirHandle,
{
/* Failed to read data */
FileHandle->Close(FileHandle);
BlMemoryFreePool(&FileInfo);
BlMemoryFreePages(Pages, (EFI_PHYSICAL_ADDRESS)(UINT_PTR)*FileData);
BlFreeMemoryPool(&FileInfo);
BlFreeMemoryPages(Pages, (EFI_PHYSICAL_ADDRESS)(UINT_PTR)*FileData);
return Status;
}
/* Close handle and free memory */
FileHandle->Close(FileHandle);
BlMemoryFreePool(&FileInfo);
BlFreeMemoryPool(&FileInfo);
/* Return success */
return STATUS_EFI_SUCCESS;
@ -657,7 +657,7 @@ BlpDiscoverEfiBlockDevices(OUT PLIST_ENTRY BlockDevices)
}
/* Allocate memory for block device */
Status = BlMemoryAllocatePool(sizeof(*BlockDevice), (PVOID *)&BlockDevice);
Status = BlAllocateMemoryPool(sizeof(*BlockDevice), (PVOID *)&BlockDevice);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
@ -674,7 +674,7 @@ BlpDiscoverEfiBlockDevices(OUT PLIST_ENTRY BlockDevices)
}
/* Free handles buffer */
BlMemoryFreePool(Handles);
BlFreeMemoryPool(Handles);
/* Return success */
return STATUS_EFI_SUCCESS;
@ -838,7 +838,7 @@ BlpDissectVolumeArcPath(IN PWCHAR SystemPath,
/* Store ARC name if possible */
if(ArcName)
{
BlMemoryAllocatePool(ArcLength * sizeof(WCHAR), (PVOID *)&LocalArcName);
BlAllocateMemoryPool(ArcLength * sizeof(WCHAR), (PVOID *)&LocalArcName);
RtlCopyMemory(LocalArcName, SystemPath, ArcLength * sizeof(WCHAR));
LocalArcName[ArcLength] = '\0';
*ArcName = LocalArcName;
@ -888,7 +888,7 @@ BlpDuplicateDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath)
}
/* Allocate memory for the new device path */
Status = BlMemoryAllocatePool(Length, (PVOID *)&DevicePathClone);
Status = BlAllocateMemoryPool(Length, (PVOID *)&DevicePathClone);
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to allocate memory */

View File

@ -193,7 +193,7 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList)
/* Check a length of modules list */
ModuleListLength = RtlWideStringLength(Option->Value, 0);
Status = BlMemoryAllocatePool(sizeof(PWCHAR) * ModuleListLength, (PVOID *)&ModulesList);
Status = BlAllocateMemoryPool(sizeof(PWCHAR) * ModuleListLength, (PVOID *)&ModulesList);
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to allocate memory, print error message and return status code */