Skip to content

Commit

Permalink
some fighting with idiotic ASSERTs
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Isakov <[email protected]>
  • Loading branch information
SergeySlice committed Sep 15, 2019
1 parent 3345280 commit 14a7206
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 45 deletions.
6 changes: 2 additions & 4 deletions BaseTools/Conf/tools_def.template
Original file line number Diff line number Diff line change
Expand Up @@ -2008,12 +2008,10 @@ DEFINE GCC_X64_RC_FLAGS = -I binary -O elf64-x86-64 -B i386 --re
DEFINE GCC_ARM_RC_FLAGS = -I binary -O elf32-littlearm -B arm --rename-section .data=.hii
DEFINE GCC_AARCH64_RC_FLAGS = -I binary -O elf64-littleaarch64 -B aarch64 --rename-section .data=.hii

DEFINE GCC48_ALL_CC_FLAGS = -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -Wno-unused-const-variable -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
DEFINE GCC48_ALL_CC_FLAGS = -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20

DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address
DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector -mabi=ms "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -Os -flto

DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
DEFINE GCC48_IA32_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE GCC48_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON)
Expand Down Expand Up @@ -2081,7 +2079,7 @@ DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto

DEFINE GCC53_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS)
DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS)
DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) -Wno-unused-but-set-variable
DEFINE GCC53_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections,-z,common-page-size=0x40,--defsym=PECOFF_HEADER_SIZE=0x280,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds

DEFINE GCC53_IA32_X64_ASLDLINK_FLAGS = DEF(GCC53_IA32_X64_DLINK_COMMON),--entry,ReferenceAcpiTable,-u,ReferenceAcpiTable
Expand Down
2 changes: 1 addition & 1 deletion Conf/tools_def.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto

DEFINE GCC53_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS)
DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS)
DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) -Wno-unused-but-set-variable
DEFINE GCC53_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections,-z,common-page-size=0x40,--defsym=PECOFF_HEADER_SIZE=0x280,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds

DEFINE GCC53_IA32_X64_ASLDLINK_FLAGS = DEF(GCC53_IA32_X64_DLINK_COMMON),--entry,ReferenceAcpiTable,-u,ReferenceAcpiTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ FreePages (
IN UINTN Pages
)
{
EFI_STATUS Status;
// EFI_STATUS Status;

ASSERT (Pages != 0);
Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
ASSERT_EFI_ERROR (Status);
if (Pages != 0) {
/* Status = */CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
}
// ASSERT_EFI_ERROR (Status);
}

/**
Expand Down Expand Up @@ -421,11 +423,13 @@ FreeAlignedPages (
IN UINTN Pages
)
{
EFI_STATUS Status;
// EFI_STATUS Status;

ASSERT (Pages != 0);
Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
ASSERT_EFI_ERROR (Status);
if (Pages != 0) {
/* Status = */ CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
}
// ASSERT_EFI_ERROR (Status);
}

/**
Expand Down Expand Up @@ -1046,9 +1050,9 @@ FreePool (
IN VOID *Buffer
)
{
EFI_STATUS Status;
// EFI_STATUS Status;

Status = CoreFreePool (Buffer);
ASSERT_EFI_ERROR (Status);
/* Status = */ CoreFreePool (Buffer);
// ASSERT_EFI_ERROR (Status);
}

Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ RegisterSecurityHandler (
EFI_STATUS Status;

ASSERT (SecurityHandler != NULL);
if (!SecurityHandler) {
return EFI_INVALID_PARAMETER;
}

//
// Make sure AuthenticationOperation is valid in the register order.
//
ASSERT (CheckAuthenticationOperation (mCurrentAuthOperation, AuthenticationOperation));
if (!CheckAuthenticationOperation (mCurrentAuthOperation, AuthenticationOperation)) {
return EFI_INVALID_PARAMETER;
}
mCurrentAuthOperation = mCurrentAuthOperation | AuthenticationOperation;

//
Expand All @@ -162,6 +168,9 @@ RegisterSecurityHandler (
//
Status = ReallocateSecurityHandlerTable();
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) {
return Status;
}
}

//
Expand Down Expand Up @@ -399,11 +408,17 @@ RegisterSecurity2Handler (
EFI_STATUS Status;

ASSERT (Security2Handler != NULL);
if (!Security2Handler) {
return EFI_INVALID_PARAMETER;
}

//
// Make sure AuthenticationOperation is valid in the register order.
//
ASSERT (CheckAuthentication2Operation (mCurrentAuthOperation2, AuthenticationOperation));
if (!CheckAuthentication2Operation (mCurrentAuthOperation2, AuthenticationOperation)) {
return EFI_INVALID_PARAMETER;
}
mCurrentAuthOperation2 = mCurrentAuthOperation2 | AuthenticationOperation;

//
Expand All @@ -415,6 +430,9 @@ RegisterSecurity2Handler (
//
Status = ReallocateSecurity2HandlerTable();
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) {
return Status;
}
}

//
Expand Down
46 changes: 38 additions & 8 deletions MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,9 @@ BmGetRamDiskMemoryInfo (
UINT64 EndingAddr;

ASSERT (RamDiskDevicePath != NULL);
if (!RamDiskDevicePath) {
return NULL;
}

*RamDiskSizeInPages = 0;

Expand All @@ -1294,6 +1297,9 @@ BmGetRamDiskMemoryInfo (
//
Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &RamDiskDevicePath, &Handle);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) {
return NULL;
}
ASSERT ((DevicePathType (RamDiskDevicePath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType (RamDiskDevicePath) == MEDIA_RAM_DISK_DP));
StartingAddr = ReadUnaligned64 ((UINT64 *) ((MEDIA_RAM_DISK_DEVICE_PATH *) RamDiskDevicePath)->StartingAddr);
Expand Down Expand Up @@ -1321,6 +1327,10 @@ BmDestroyRamDisk (
UINTN RamDiskSizeInPages;

ASSERT (RamDiskDevicePath != NULL);
if (!RamDiskDevicePath) {
return;
}


RamDiskBuffer = BmGetRamDiskMemoryInfo (RamDiskDevicePath, &RamDiskSizeInPages);

Expand All @@ -1330,9 +1340,12 @@ BmDestroyRamDisk (
if (mRamDisk == NULL) {
Status = gBS->LocateProtocol (&gEfiRamDiskProtocolGuid, NULL, (VOID *) &mRamDisk);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) {
return;
}
}
Status = mRamDisk->Unregister (RamDiskDevicePath);
ASSERT_EFI_ERROR (Status);
/* Status = */mRamDisk->Unregister (RamDiskDevicePath);
// ASSERT_EFI_ERROR (Status);
FreePages (RamDiskBuffer, RamDiskSizeInPages);
}

Expand Down Expand Up @@ -1366,6 +1379,10 @@ BmExpandLoadFile (
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) {
return NULL;
}


FileBuffer = NULL;
BufferSize = 0;
Expand Down Expand Up @@ -1534,6 +1551,9 @@ BmGetNextLoadOptionDevicePath (
EFI_STATUS Status;

ASSERT (FilePath != NULL);
if (!FilePath) {
return NULL;
}

//
// Boot from media device by adding a default file name \EFI\BOOT\BOOT{machine type short-name}.EFI
Expand Down Expand Up @@ -2292,6 +2312,7 @@ EfiBootManagerRefreshAllBootOption (
// Deleting variable with current variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) break;
}
}
}
Expand Down Expand Up @@ -2404,6 +2425,9 @@ BmRegisterBootManagerMenu (
(VOID **) &LoadedImage
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
return Status;
}
DevicePath = AppendDevicePathNode (
DevicePathFromHandle (LoadedImage->DeviceHandle),
(EFI_DEVICE_PATH_PROTOCOL *) &FileNode
Expand All @@ -2422,11 +2446,16 @@ BmRegisterBootManagerMenu (
0
);
ASSERT_EFI_ERROR (Status);
FreePool (DevicePath);
if (EFI_ERROR (Status)) {
return Status;
}
if (DevicePath) {
FreePool (DevicePath);
}
if (Description != NULL) {
FreePool (Description);
}

/*
DEBUG_CODE (
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
UINTN BootOptionCount;
Expand All @@ -2435,7 +2464,7 @@ BmRegisterBootManagerMenu (
ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1);
EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
);

*/
return EfiBootManagerAddLoadOptionVariable (BootOption, 0);
}

Expand All @@ -2457,7 +2486,7 @@ EfiBootManagerGetBootManagerMenu (
EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
)
{
EFI_STATUS Status;
// EFI_STATUS Status;
UINTN BootOptionCount;
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
UINTN Index;
Expand All @@ -2466,7 +2495,7 @@ EfiBootManagerGetBootManagerMenu (

for (Index = 0; Index < BootOptionCount; Index++) {
if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) {
Status = EfiBootManagerInitializeLoadOption (
/*Status = */EfiBootManagerInitializeLoadOption (
BootOption,
BootOptions[Index].OptionNumber,
BootOptions[Index].OptionType,
Expand All @@ -2476,7 +2505,8 @@ EfiBootManagerGetBootManagerMenu (
BootOptions[Index].OptionalData,
BootOptions[Index].OptionalDataSize
);
ASSERT_EFI_ERROR (Status);
// ASSERT_EFI_ERROR (Status);

break;
}
}
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ BmProcessKeyOption (
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR(Status)) continue;
BmRegisterHotkeyNotify (TxtInEx, Hotkey);
}
}
Expand Down
12 changes: 9 additions & 3 deletions MdeModulePkg/Library/UefiHiiLib/HiiLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ HiiAddPackages (
UINT8 *Data;

ASSERT (PackageListGuid != NULL);
if (!PackageListGuid) {
return NULL;
}

//
// Calculate the length of all the packages in the variable argument list
Expand Down Expand Up @@ -251,11 +254,14 @@ HiiRemovePackages (
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STATUS Status;
// EFI_STATUS Status;

ASSERT (HiiHandle != NULL);
Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
ASSERT_EFI_ERROR (Status);
if (!HiiHandle) {
return;
}
/* Status = */gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
// ASSERT_EFI_ERROR (Status);
}


Expand Down
25 changes: 21 additions & 4 deletions MdeModulePkg/Library/UefiSortLib/UefiSortLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ DevicePathCompare (
(VOID**)&mUnicodeCollation);

ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status)) {
return -1;
}
/* if (EFI_ERROR(Status)) {
Status = gBS->LocateProtocol(
&gEfiUnicodeCollationProtocolGuid,
NULL,
(VOID**)&mUnicodeCollation);
} */
}

TextPath1 = ConvertDevicePathToText(
Expand All @@ -247,10 +257,14 @@ DevicePathCompare (
} else if (TextPath2 == NULL) {
RetVal = 1;
} else {
RetVal = mUnicodeCollation->StriColl(
mUnicodeCollation,
TextPath1,
TextPath2);
if (mUnicodeCollation) {
RetVal = mUnicodeCollation->StriColl(
mUnicodeCollation,
TextPath1,
TextPath2);
} else {
RetVal = 1;
}
}

USL_FREE_NON_NULL(TextPath1);
Expand Down Expand Up @@ -284,6 +298,9 @@ StringNoCaseCompare (
(VOID**)&mUnicodeCollation);

ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status)) {
return -1;
}
}

return (mUnicodeCollation->StriColl(
Expand Down
7 changes: 5 additions & 2 deletions MdePkg/Library/BaseLib/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ StrCpy (
)
{
CHAR16 *ReturnValue;
INTN DestMax;
// INTN DestMax;

//
// Destination cannot be NULL
//
ASSERT (Destination != NULL);
ASSERT (((UINTN) Destination & BIT0) == 0);
if (!Destination || !Source) {
return NULL;
}

//
// Destination and source cannot overlap
//
ASSERT ((UINTN)(Destination - Source) > StrLen (Source));
ASSERT ((UINTN)(Source - Destination) > StrLen (Source));

DestMax = StrLen (Destination);
// DestMax = StrLen (Destination);

ReturnValue = Destination;
while (*Source != 0) {
Expand Down
Loading

0 comments on commit 14a7206

Please sign in to comment.