summaryrefslogtreecommitdiff
path: root/MdePkg/Library
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2006-05-25 10:13:26 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2006-05-25 10:13:26 +0000
commita3657e3e7aaaccb1b9ea1b41a72d4564452e272d (patch)
tree24272aceeed6a863f6c18f331386042770d51bcb /MdePkg/Library
parentd05003bed6b96ad51fbf5d9b7b6c2897e6228245 (diff)
downloadedk2-platforms-a3657e3e7aaaccb1b9ea1b41a72d4564452e272d.tar.xz
MemoryAllocationLib: For boundary case: “AllocationSize + OverAllocationSize >= 4G”
DxeMemoryAllocationLib: Change the behavior from returning NULL to ASSERT () PeiMemoryAllocationLib: Add ASSERT () I also add ASSERT () in Pei Service AllocatePool () to catch if allocation size > 64K DebugLib: Header file (DebugLib.h): Fix an issue in ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid). In contrast with LocateProtocol (), the first & second parameter type of HandleProtocol () is EFI_HANDLE & EFI_GUID respectively. UefiLib: For UnicodeStringDisplayLength (CONST CHAR8 *String), return 0 if String is NULL. BasePrintLib: Add missing “EFIAPI” to UnicodeValueToString() and AsciiValueToString() and move their definitions from PrintLibInternal.c to PrintLib.c. Fix the comments error(Maximum Length TIME”) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@275 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library')
-rw-r--r--MdePkg/Library/BasePrintLib/PrintLib.c24
-rw-r--r--MdePkg/Library/BasePrintLib/PrintLibInternal.c23
-rw-r--r--MdePkg/Library/BasePrintLib/PrintLibInternal.h10
-rw-r--r--MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c23
-rw-r--r--MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c13
-rw-r--r--MdePkg/Library/UefiLib/Console.c4
6 files changed, 60 insertions, 37 deletions
diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c
index 816c887088..bbd0820106 100644
--- a/MdePkg/Library/BasePrintLib/PrintLib.c
+++ b/MdePkg/Library/BasePrintLib/PrintLib.c
@@ -637,3 +637,27 @@ AsciiSPrintUnicodeFormat (
VA_START (Marker, FormatString);
return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
}
+
+UINTN
+EFIAPI
+UnicodeValueToString (
+ IN OUT CHAR16 *Buffer,
+ IN UINTN Flags,
+ IN INT64 Value,
+ IN UINTN Width
+ )
+{
+ return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
+}
+
+UINTN
+EFIAPI
+AsciiValueToString (
+ IN OUT CHAR8 *Buffer,
+ IN UINTN Flags,
+ IN INT64 Value,
+ IN UINTN Width
+ )
+{
+ return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);
+}
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
index 24d8b56598..56d357525c 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
@@ -128,26 +128,3 @@ BasePrintLibConvertValueToString (
return ((Buffer - OriginalBuffer) / Increment);
}
-
-
-UINTN
-UnicodeValueToString (
- IN OUT CHAR16 *Buffer,
- IN UINTN Flags,
- IN INT64 Value,
- IN UINTN Width
- )
-{
- return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
-}
-
-UINTN
-AsciiValueToString (
- IN OUT CHAR8 *Buffer,
- IN UINTN Flags,
- IN INT64 Value,
- IN UINTN Width
- )
-{
- return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);
-}
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
index de08f0edfc..c7fecfd34c 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
@@ -39,7 +39,7 @@
/// Maximum Length Decimal String = 28 "-9,223,372,036,854,775,808"
/// Maximum Length Hexidecimal String = 17 "FFFFFFFFFFFFFFFF"
/// Maximum Length GUID = 37 "00000000-0000-0000-0000-000000000000"
-/// Maximum Length TIME = 17 "12/12/2006 12:12"
+/// Maximum Length TIME = 18 "12/12/2006 12:12"
///
#define MAXIMUM_VALUE_CHARACTERS 38
@@ -85,3 +85,11 @@ BasePrintLibValueToString (
IN UINTN Radix
);
+UINTN
+BasePrintLibConvertValueToString (
+ IN OUT CHAR8 *Buffer,
+ IN UINTN Flags,
+ IN INT64 Value,
+ IN UINTN Width,
+ IN UINTN Increment
+ );
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
index ef643eed42..088a10bb56 100644
--- a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
@@ -168,13 +168,11 @@ InternalAllocateAlignedPages (
//
AlignmentMask = Alignment - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
- if (RealPages <= Pages) {
- //
- // This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
- //
- return NULL;
- }
-
+ //
+ // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
+ //
+ ASSERT (RealPages > Pages);
+
Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
if (EFI_ERROR (Status)) {
return NULL;
@@ -601,12 +599,11 @@ InternalAllocateAlignedPool (
//
OverAllocationSize = sizeof (RawAddress) + AlignmentMask;
RealAllocationSize = AllocationSize + OverAllocationSize;
- if (RealAllocationSize <= AllocationSize ) {
- //
- // This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow.
- //
- return NULL;
- }
+ //
+ // Make sure that AllocationSize plus OverAllocationSize does not overflow.
+ //
+ ASSERT (RealAllocationSize > AllocationSize);
+
RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);
if (RawAddress == NULL) {
return NULL;
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
index 63641569ff..274287cf03 100644
--- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
@@ -158,6 +158,10 @@ InternalAllocateAlignedPages (
return NULL;
}
//
+ // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
+ //
+ ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));
+ //
// We would rather waste some memory to save PEI code size.
//
Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));
@@ -569,6 +573,10 @@ InternalAllocateAlignedPool (
} else {
AlignmentMask = Alignment - 1;
}
+ //
+ // Make sure that AllocationSize plus AlignmentMask does not overflow.
+ //
+ ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));
RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);
@@ -609,6 +617,11 @@ AllocateAlignedPool (
AlignmentMask = Alignment - 1;
}
+ //
+ // Make sure that AllocationSize plus AlignmentMask does not overflow.
+ //
+ ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));
+
RawAddress = AllocatePool (AllocationSize + AlignmentMask);
AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;
diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Console.c
index d06b0a932d..4fbdef7350 100644
--- a/MdePkg/Library/UefiLib/Console.c
+++ b/MdePkg/Library/UefiLib/Console.c
@@ -263,6 +263,10 @@ UnicodeStringDisplayLength (
UINTN Length;
UINTN Width;
+ if (String == NULL) {
+ return 0;
+ }
+
Length = 0;
while (*String != 0) {
Width = GetGlyphWidth (*String);