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
This commit is contained in:
qhuang8
2006-05-25 10:13:26 +00:00
parent d05003bed6
commit a3657e3e7a
9 changed files with 74 additions and 45 deletions

View File

@ -301,8 +301,12 @@ Returns:
EFI_STATUS Status; EFI_STATUS Status;
EFI_HOB_MEMORY_POOL *Hob; EFI_HOB_MEMORY_POOL *Hob;
//
Status = PeiCoreCreateHob ( // If some <20><>post-memory<72><79> PEIM wishes to allocate larger pool,
// it should use AllocatePages service instead.
//
ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL));
Status = PeiCoreCreateHob (
EFI_HOB_TYPE_PEI_MEMORY_POOL, EFI_HOB_TYPE_PEI_MEMORY_POOL,
(UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size), (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),
(VOID **)&Hob (VOID **)&Hob

View File

@ -72,7 +72,7 @@ DebugPrint (
Prints an assert message containing a filename, line number, and description. Prints an assert message containing a filename, line number, and description.
This may be followed by a breakpoint or a dead loop. This may be followed by a breakpoint or a dead loop.
Print a message of the form <20>ASSERT <FileName>(<LineNumber>): <Description>\n<EFBFBD> Print a message of the form <20>ASSERT <FileName>(<LineNumber>): <Description>\n?
to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
@ -81,9 +81,9 @@ DebugPrint (
DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
processing another DebugAssert(), then DebugAssert() must return immediately. processing another DebugAssert(), then DebugAssert() must return immediately.
If FileName is NULL, then a <FileName> string of <EFBFBD>(NULL) Filename<EFBFBD> is printed. If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.
If Description is NULL, then a <Description> string of <EFBFBD>(NULL) Description<EFBFBD> is printed. If Description is NULL, then a <Description> string of ?NULL) Description?is printed.
@param FileName Pointer to the name of the source file that generated the assert condition. @param FileName Pointer to the name of the source file that generated the assert condition.
@param LineNumber The line number in the source file that generated the assert condition @param LineNumber The line number in the source file that generated the assert condition
@ -108,7 +108,7 @@ DebugAssert (
If Buffer is NULL, then ASSERT(). If Buffer is NULL, then ASSERT().
If Length is greater than (MAX_ADDRESS <EFBFBD> Buffer + 1), then ASSERT(). If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT().
@param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue. @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
@param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
@ -321,7 +321,7 @@ DebugClearMemoryEnabled (
_ASSERT (Guid already installed in database); \ _ASSERT (Guid already installed in database); \
} \ } \
} else { \ } else { \
if (!EFI_ERROR (gBS->HandleProtocol (Guid, Handle, &Instance))) { \ if (!EFI_ERROR (gBS->HandleProtocol (Handle, Guid, &Instance))) { \
_ASSERT (Guid already installed on Handle); \ _ASSERT (Guid already installed on Handle); \
} \ } \
} \ } \
@ -411,7 +411,7 @@ DebugClearMemoryEnabled (
by TYPE is compared to TestSignature. If the signatures match, then a pointer by TYPE is compared to TestSignature. If the signatures match, then a pointer
to the pointer to a data structure of the type specified by TYPE is returned. to the pointer to a data structure of the type specified by TYPE is returned.
If the signatures do not match, then DebugAssert() is called with a description If the signatures do not match, then DebugAssert() is called with a description
of <20>CR has a bad signature<EFBFBD> and Record is returned. of <20>CR has a bad signature?and Record is returned.
If the data type specified by TYPE does not contain the field specified by Field, If the data type specified by TYPE does not contain the field specified by Field,
then the module will not compile. then the module will not compile.

View File

@ -98,6 +98,7 @@ AsciiSPrintUnicodeFormat (
); );
UINTN UINTN
EFIAPI
UnicodeValueToString ( UnicodeValueToString (
IN OUT CHAR16 *Buffer, IN OUT CHAR16 *Buffer,
IN UINTN Flags, IN UINTN Flags,
@ -106,6 +107,7 @@ UnicodeValueToString (
); );
UINTN UINTN
EFIAPI
AsciiValueToString ( AsciiValueToString (
IN OUT CHAR8 *Buffer, IN OUT CHAR8 *Buffer,
IN UINTN Flags, IN UINTN Flags,

View File

@ -637,3 +637,27 @@ AsciiSPrintUnicodeFormat (
VA_START (Marker, FormatString); VA_START (Marker, FormatString);
return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); 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);
}

View File

@ -128,26 +128,3 @@ BasePrintLibConvertValueToString (
return ((Buffer - OriginalBuffer) / Increment); 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);
}

View File

@ -39,7 +39,7 @@
/// Maximum Length Decimal String = 28 "-9,223,372,036,854,775,808" /// Maximum Length Decimal String = 28 "-9,223,372,036,854,775,808"
/// Maximum Length Hexidecimal String = 17 "FFFFFFFFFFFFFFFF" /// Maximum Length Hexidecimal String = 17 "FFFFFFFFFFFFFFFF"
/// Maximum Length GUID = 37 "00000000-0000-0000-0000-000000000000" /// 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 #define MAXIMUM_VALUE_CHARACTERS 38
@ -85,3 +85,11 @@ BasePrintLibValueToString (
IN UINTN Radix IN UINTN Radix
); );
UINTN
BasePrintLibConvertValueToString (
IN OUT CHAR8 *Buffer,
IN UINTN Flags,
IN INT64 Value,
IN UINTN Width,
IN UINTN Increment
);

View File

@ -168,13 +168,11 @@ InternalAllocateAlignedPages (
// //
AlignmentMask = Alignment - 1; AlignmentMask = Alignment - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment); RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
if (RealPages <= Pages) { //
// // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
// This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. //
// ASSERT (RealPages > Pages);
return NULL;
}
Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory); Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
@ -601,12 +599,11 @@ InternalAllocateAlignedPool (
// //
OverAllocationSize = sizeof (RawAddress) + AlignmentMask; OverAllocationSize = sizeof (RawAddress) + AlignmentMask;
RealAllocationSize = AllocationSize + OverAllocationSize; RealAllocationSize = AllocationSize + OverAllocationSize;
if (RealAllocationSize <= AllocationSize ) { //
// // Make sure that AllocationSize plus OverAllocationSize does not overflow.
// This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow. //
// ASSERT (RealAllocationSize > AllocationSize);
return NULL;
}
RawAddress = InternalAllocatePool (PoolType, RealAllocationSize); RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);
if (RawAddress == NULL) { if (RawAddress == NULL) {
return NULL; return NULL;

View File

@ -158,6 +158,10 @@ InternalAllocateAlignedPages (
return NULL; 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. // We would rather waste some memory to save PEI code size.
// //
Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment)); Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));
@ -569,6 +573,10 @@ InternalAllocateAlignedPool (
} else { } else {
AlignmentMask = Alignment - 1; AlignmentMask = Alignment - 1;
} }
//
// Make sure that AllocationSize plus AlignmentMask does not overflow.
//
ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));
RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask); RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);
@ -609,6 +617,11 @@ AllocateAlignedPool (
AlignmentMask = Alignment - 1; AlignmentMask = Alignment - 1;
} }
//
// Make sure that AllocationSize plus AlignmentMask does not overflow.
//
ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));
RawAddress = AllocatePool (AllocationSize + AlignmentMask); RawAddress = AllocatePool (AllocationSize + AlignmentMask);
AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask; AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;

View File

@ -263,6 +263,10 @@ UnicodeStringDisplayLength (
UINTN Length; UINTN Length;
UINTN Width; UINTN Width;
if (String == NULL) {
return 0;
}
Length = 0; Length = 0;
while (*String != 0) { while (*String != 0) {
Width = GetGlyphWidth (*String); Width = GetGlyphWidth (*String);