From nobody Sun Apr 28 08:41:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100498+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100498+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1677286487; cv=none; d=zohomail.com; s=zohoarc; b=bnrvqpsZ5AijobX6NG1YvjUGrBUpDFtcmj/YYX2HXpAyIUOYx8Xw9nFsaUDR5XdFFSnT0v/pmqtHhkhJEocb5Ruh/Ji5BV+P9O2VWyIXJUDRdpjeX7fbm8OlLGVv+bhCH4Uu9NsTk/SzvmG89iAzDFvGWdo/Tc8eIKPX0cF+IqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677286487; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/TxA8IQr1y4MykM1xXpSUKaV99jS1/mE+UZFBQLSTyU=; b=Q2qyJDTkc4ArJkbXvNPOqcvM+44Oy17D6/mQVhkiPNE/AL+I8vra8PC26gPxtXdphQRuIhOU+Kh7dTf2Fif3iR8P75Kp+dWZaahlfRRNeE+ylTd7tjj3qOTUj0Q68DGT17rQa8dZOEOG39hJ7OY4kkqbP/lnYkYb1lEzX3mZHxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100498+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677286487500487.72883880479867; Fri, 24 Feb 2023 16:54:47 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q92rYY1788612xcFAeMNFOuT; Fri, 24 Feb 2023 16:54:47 -0800 X-Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mx.groups.io with SMTP id smtpd.web11.35174.1677286486144972470 for ; Fri, 24 Feb 2023 16:54:46 -0800 X-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 2845F3200941; Fri, 24 Feb 2023 19:54:45 -0500 (EST) X-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 24 Feb 2023 19:54:45 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekgedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfgvsggv tggtrgcuvehrrghnuceorhgvsggvtggtrgessghsughiohdrtghomheqnecuggftrfgrth htvghrnhepgeffueeuledvgefgvddvgfetvdduhfefkedukeeikedtudekfeetteeifedv leefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprh gvsggvtggtrgessghsughiohdrtghomh X-ME-Proxy: Feedback-ID: i5b994698:Fastmail X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Feb 2023 19:54:43 -0500 (EST) From: "Rebecca Cran" To: devel@edk2.groups.io, Bob Feng , Liming Gao , Yuwei Chen Cc: Rebecca Cran Subject: [edk2-devel] [PATCH 1/3] BaseTools: Source/C/Common: Fix doc block locations and convert to Doxygen Date: Fri, 24 Feb 2023 17:54:29 -0700 Message-Id: <20230225005431.12173-2-rebecca@bsdio.com> In-Reply-To: <20230225005431.12173-1-rebecca@bsdio.com> References: <20230225005431.12173-1-rebecca@bsdio.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com X-Gm-Message-State: zjOHH4mftqQTtVSm4tCtE7q4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677286487; bh=O2mbq4zKO2VWI8Kyzz9DKHMLsBbQUYPgJKmIbpEQ7+4=; h=Cc:Date:From:Reply-To:Subject:To; b=pcdFIwTXcUgQdyFYawlYSLDlF7RABaV9Qg8SXA4nGwRZjTLIqIZk9Ih6KFrsVL94TeC 3bWuYlNLueY72huylvDpa/RdZrd9Y0lVJGxA5ZUPXsDzhCeAujr6IjOfysFHVKcobBCoW vZE6n8yjyRDpsR0SvnC3UcSMOCcRjl1fiko= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677286489376100005 Content-Type: text/plain; charset="utf-8" Move the documentation blocks from between the parameter list and function body to above the function. Convert all the documentation blocks to Doxygen format. Signed-off-by: Rebecca Cran --- BaseTools/Source/C/Common/CommonLib.h | 14 +- BaseTools/Source/C/Common/Compress.h | 45 +- BaseTools/Source/C/Common/Crc32.h | 30 +- BaseTools/Source/C/Common/Decompress.h | 118 ++- BaseTools/Source/C/Common/MemoryFile.h | 72 +- BaseTools/Source/C/Common/MyAlloc.h | 146 ++-- BaseTools/Source/C/Common/OsPath.h | 90 +- BaseTools/Source/C/Common/ParseGuidedSectionTools.h | 95 +-- BaseTools/Source/C/Common/ParseInf.h | 204 ++--- BaseTools/Source/C/Common/PcdValueCommon.h | 175 ++-- BaseTools/Source/C/Common/StringFuncs.h | 191 ++--- BaseTools/Source/C/Common/BasePeCoff.c | 202 ++--- BaseTools/Source/C/Common/CommonLib.c | 336 +++----- BaseTools/Source/C/Common/Crc32.c | 30 +- BaseTools/Source/C/Common/Decompress.c | 470 ++++------- BaseTools/Source/C/Common/EfiCompress.c | 574 +++++-------- BaseTools/Source/C/Common/EfiUtilityMsgs.c | 522 +++++------- BaseTools/Source/C/Common/FirmwareVolumeBuffer.c | 869 +++++++---------= ---- BaseTools/Source/C/Common/FvLib.c | 401 ++++----- BaseTools/Source/C/Common/MemoryFile.c | 84 +- BaseTools/Source/C/Common/MyAlloc.c | 155 ++-- BaseTools/Source/C/Common/OsPath.c | 101 +-- BaseTools/Source/C/Common/ParseGuidedSectionTools.c | 92 +-- BaseTools/Source/C/Common/ParseInf.c | 225 ++--- BaseTools/Source/C/Common/PcdValueCommon.c | 303 +++---- BaseTools/Source/C/Common/PeCoffLoaderEx.c | 66 +- BaseTools/Source/C/Common/SimpleFileParsing.c | 430 ++++------ BaseTools/Source/C/Common/StringFuncs.c | 246 ++---- BaseTools/Source/C/Common/TianoCompress.c | 610 +++++--------- 29 files changed, 2452 insertions(+), 4444 deletions(-) diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Com= mon/CommonLib.h index 0f05d88db206..a841029c2aaa 100644 --- a/BaseTools/Source/C/Common/CommonLib.h +++ b/BaseTools/Source/C/Common/CommonLib.h @@ -95,13 +95,6 @@ GetFileImage ( ) ; =20 -EFI_STATUS -PutFileImage ( - IN CHAR8 *OutputFileName, - IN CHAR8 *OutputFileImage, - IN UINT32 BytesToWrite - ) -; /*++ =20 Routine Description: @@ -122,6 +115,13 @@ Routine Description: EFI_OUT_OF_RESOURCES No resource to complete operations. =20 **/ +EFI_STATUS +PutFileImage ( + IN CHAR8 *OutputFileName, + IN CHAR8 *OutputFileImage, + IN UINT32 BytesToWrite + ) +; =20 UINT8 CalculateChecksum8 ( diff --git a/BaseTools/Source/C/Common/Compress.h b/BaseTools/Source/C/Comm= on/Compress.h index 40255a9665da..499e183c2b40 100644 --- a/BaseTools/Source/C/Common/Compress.h +++ b/BaseTools/Source/C/Common/Compress.h @@ -15,13 +15,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "CommonLib.h" #include -/*++ - -Routine Description: =20 +/** Tiano compression routine. - ---*/ +**/ EFI_STATUS TianoCompress ( IN UINT8 *SrcBuffer, @@ -31,13 +28,9 @@ TianoCompress ( ) ; =20 -/*++ - -Routine Description: - +/** Efi compression routine. - ---*/ +**/ EFI_STATUS EfiCompress ( IN UINT8 *SrcBuffer, @@ -47,29 +40,21 @@ EfiCompress ( ) ; =20 -/*++ - -Routine Description: - +/** The compression routine. =20 -Arguments: + @param SrcBuffer The buffer storing the source data + @param SrcSize The size of source data + @param DstBuffer The buffer to store the compressed data + @param DstSize On input, the size of DstBuffer; On output, + the size of the actual compressed data. =20 - SrcBuffer - The buffer storing the source data - SrcSize - The size of source data - DstBuffer - The buffer to store the compressed data - DstSize - On input, the size of DstBuffer; On output, - the size of the actual compressed data. - -Returns: - - EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case, + @retval EFI_BUFFER_TOO_SMALL The DstBuffer is too small. In this case, DstSize contains the size needed. - EFI_SUCCESS - Compression is successful. - EFI_OUT_OF_RESOURCES - No resource to complete function. - EFI_INVALID_PARAMETER - Parameter supplied is wrong. - ---*/ + @retval EFI_SUCCESS Compression is successful. + @retval EFI_OUT_OF_RESOURCES No resource to complete function. + @retval EFI_INVALID_PARAMETER Parameter supplied is wrong. +**/ typedef EFI_STATUS (*COMPRESS_FUNCTION) ( diff --git a/BaseTools/Source/C/Common/Crc32.h b/BaseTools/Source/C/Common/= Crc32.h index 61f99b96b565..3f6b5b35fc36 100644 --- a/BaseTools/Source/C/Common/Crc32.h +++ b/BaseTools/Source/C/Common/Crc32.h @@ -11,31 +11,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 +/** + The CalculateCrc32 routine. + + @param Data The buffer containing the data to be processed + @param DataSize The size of data to be processed + @param CrcOut A pointer to the caller allocated UINT32 that on + contains the CRC32 checksum of Data + + @retval EFI_SUCCESS - Calculation is successful. + @retval EFI_INVALID_PARAMETER - Data / CrcOut =3D NULL, or DataSize = =3D 0 +**/ EFI_STATUS CalculateCrc32 ( IN UINT8 *Data, IN UINTN DataSize, IN OUT UINT32 *CrcOut ) -/*++ - -Routine Description: - - The CalculateCrc32 routine. - -Arguments: - - Data - The buffer containing the data to be processed - DataSize - The size of data to be processed - CrcOut - A pointer to the caller allocated UINT32 that on - contains the CRC32 checksum of Data - -Returns: - - EFI_SUCCESS - Calculation is successful. - EFI_INVALID_PARAMETER - Data / CrcOut =3D NULL, or DataSize =3D 0 - ---*/ ; =20 #endif diff --git a/BaseTools/Source/C/Common/Decompress.h b/BaseTools/Source/C/Co= mmon/Decompress.h index 983a27d8fc26..00a1e31b8c21 100644 --- a/BaseTools/Source/C/Common/Decompress.h +++ b/BaseTools/Source/C/Common/Decompress.h @@ -11,13 +11,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 -EFI_STATUS -EfiGetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ); /** =20 Routine Description: @@ -37,95 +30,78 @@ Routine Description: EFI_INVALID_PARAMETER - The source data is corrupted =20 **/ - EFI_STATUS -EfiDecompress ( +EfiGetInfo ( IN VOID *Source, IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize + OUT UINT32 *DstSize, + OUT UINT32 *ScratchSize ); + /** - -Routine Description: - The implementation of Efi Decompress(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This= buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successful - EFI_INVALID_PARAMETER - The source data is corrupted - + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param Destination The destination buffer to store the decompressed data + @param DstSize The size of destination buffer. + @param Scratch The buffer used internally by the decompress routine.= This buffer is needed to store intermediate data. + @param ScratchSize The size of scratch buffer. + + @retval EFI_SUCCESS Decompression is successful + @retval EFI_INVALID_PARAMETER The source data is corrupted **/ - EFI_STATUS -TianoGetInfo ( +EfiDecompress ( IN VOID *Source, IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize + IN OUT VOID *Destination, + IN UINT32 DstSize, + IN OUT VOID *Scratch, + IN UINT32 ScratchSize ); + /** - -Routine Description: - The implementation Tiano Decompress GetInfo(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of s= cratch buffer are successfully retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param DstSize The size of destination buffer. + @param ScratchSize The size of scratch buffer. =20 + @retval EFI_SUCCESS The size of destination buffer and the siz= e of scratch buffer are successfully retrieved. + @retval EFI_INVALID_PARAMETER The source data is corrupted **/ - EFI_STATUS -TianoDecompress ( +TianoGetInfo ( IN VOID *Source, IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize + OUT UINT32 *DstSize, + OUT UINT32 *ScratchSize ); + /** - -Routine Description: - The implementation of Tiano Decompress(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This= buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successful - EFI_INVALID_PARAMETER - The source data is corrupted - + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param Destination The destination buffer to store the decompressed data + @param DstSize The size of destination buffer. + @param Scratch The buffer used internally by the decompress routine.= This buffer is needed to store intermediate data. + @param ScratchSize The size of scratch buffer. + + @retval EFI_SUCCESS Decompression is successful + @retval EFI_INVALID_PARAMETER The source data is corrupted **/ +EFI_STATUS +TianoDecompress ( + IN VOID *Source, + IN UINT32 SrcSize, + IN OUT VOID *Destination, + IN UINT32 DstSize, + IN OUT VOID *Scratch, + IN UINT32 ScratchSize + ); =20 typedef EFI_STATUS diff --git a/BaseTools/Source/C/Common/MemoryFile.h b/BaseTools/Source/C/Co= mmon/MemoryFile.h index 58fc8bb224f3..c84848cf15d6 100644 --- a/BaseTools/Source/C/Common/MemoryFile.h +++ b/BaseTools/Source/C/Common/MemoryFile.h @@ -27,79 +27,53 @@ typedef struct { // Functions declarations // =20 -EFI_STATUS -GetMemoryFile ( - IN CHAR8 *InputFileName, - OUT EFI_HANDLE *OutputMemoryFile - ) -; /** - -Routine Description: - This opens a file, reads it into memory and returns a memory file object. =20 -Arguments: + @param InputFile Memory file image. + @param OutputMemoryFile Handle to memory file =20 - InputFile Memory file image. - OutputMemoryFile Handle to memory file - -Returns: - - EFI_STATUS + @return EFI_STATUS OutputMemoryFile is valid if !EFI_ERROR - **/ +EFI_STATUS +GetMemoryFile ( + IN CHAR8 *InputFileName, + OUT EFI_HANDLE *OutputMemoryFile + ) +; + +/** + Frees all memory associated with the input memory file. =20 + @param InputMemoryFile Handle to memory file =20 + @return EFI_STATUS +**/ EFI_STATUS FreeMemoryFile ( IN EFI_HANDLE InputMemoryFile ) ; -/** - -Routine Description: - - Frees all memory associated with the input memory file. - -Arguments: - - InputMemoryFile Handle to memory file - -Returns: =20 - EFI_STATUS - -**/ - - -CHAR8 * -ReadMemoryFileLine ( - IN EFI_HANDLE InputMemoryFile - ) -; /** - -Routine Description: - This function reads a line from the memory file. The newline characters are stripped and a null terminated string is returned. =20 If the string pointer returned is non-NULL, then the caller must free the memory associated with this string. =20 -Arguments: - - InputMemoryFile Handle to memory file - -Returns: - - NULL if error or EOF - NULL character termincated string otherwise (MUST BE FREED BY CALLER) + @param InputMemoryFile Handle to memory file =20 + @retval NULL if error or EOF + @retval NULL character termincated string otherwise (MUST BE FREED BY CA= LLER) **/ +CHAR8 * +ReadMemoryFileLine ( + IN EFI_HANDLE InputMemoryFile + ) +; =20 =20 #endif diff --git a/BaseTools/Source/C/Common/MyAlloc.h b/BaseTools/Source/C/Commo= n/MyAlloc.h index aff29d05ab7d..de3323d30d97 100644 --- a/BaseTools/Source/C/Common/MyAlloc.h +++ b/BaseTools/Source/C/Common/MyAlloc.h @@ -71,6 +71,17 @@ typedef struct MyAllocStruct { #define MYALLOC_HEAD_MAGIK 0xBADFACED #define MYALLOC_TAIL_MAGIK 0xDEADBEEF =20 +/** + Check for corruptions in the allocated memory chain. If a corruption + is detection program operation stops w/ an exit(1) call. + + @param Final When FALSE, MyCheck() returns if the allocated memory chain + has not been corrupted. When TRUE, MyCheck() returns if th= ere + are no un-freed allocations. If there are un-freed allocat= ions, + they are displayed and exit(1) is called. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. +**/ VOID MyCheck ( BOOLEAN Final, @@ -78,31 +89,20 @@ MyCheck ( UINTN Line ) ; -// -// *++ -// Description: -// -// Check for corruptions in the allocated memory chain. If a corruption -// is detection program operation stops w/ an exit(1) call. -// -// Parameters: -// -// Final :=3D When FALSE, MyCheck() returns if the allocated memory chain -// has not been corrupted. When TRUE, MyCheck() returns if there -// are no un-freed allocations. If there are un-freed allocatio= ns, -// they are displayed and exit(1) is called. -// -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// n/a -// -// --*/ -// + +/** + Allocate a new link in the allocation chain along with enough storage + for the File[] string, requested Size and alignment overhead. If + memory cannot be allocated or the allocation chain has been corrupted, + exit(1) will be called. + + @param Size Number of bytes (UINT8) requested by the called. + Size cannot be zero. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. + + @return Pointer to the caller's buffer. +**/ VOID * MyAlloc ( UINTN Size, @@ -110,30 +110,20 @@ MyAlloc ( UINTN Line ) ; -// -// *++ -// Description: -// -// Allocate a new link in the allocation chain along with enough storage -// for the File[] string, requested Size and alignment overhead. If -// memory cannot be allocated or the allocation chain has been corrupted, -// exit(1) will be called. -// -// Parameters: -// -// Size :=3D Number of bytes (UINT8) requested by the called. -// Size cannot be zero. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// Pointer to the caller's buffer. -// -// --*/ -// + +/** + This does a MyAlloc(), memcpy() and MyFree(). There is no optimization + for shrinking or expanding buffers. An invalid parameter will cause + MyRealloc() to fail with a call to exit(1). + + @param Ptr Pointer to the caller's buffer to be re-allocated. + Ptr cannot be NULL. + @param Size Size of new buffer. Size cannot be zero. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. + + @return Pointer to new caller's buffer. +**/ VOID * MyRealloc ( VOID *Ptr, @@ -142,31 +132,16 @@ MyRealloc ( UINTN Line ) ; -// -// *++ -// Description: -// -// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization -// for shrinking or expanding buffers. An invalid parameter will cause -// MyRealloc() to fail with a call to exit(1). -// -// Parameters: -// -// Ptr :=3D Pointer to the caller's buffer to be re-allocated. -// Ptr cannot be NULL. -// -// Size :=3D Size of new buffer. Size cannot be zero. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// Pointer to new caller's buffer. -// -// --*/ -// + +/** + Release a previously allocated buffer. Invalid parameters will cause + MyFree() to fail with an exit(1) call. + + @param Ptr Pointer to the caller's buffer to be freed. + A NULL pointer will be ignored. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. +**/ VOID MyFree ( VOID *Ptr, @@ -174,28 +149,7 @@ MyFree ( UINTN Line ) ; -// -// *++ -// Description: -// -// Release a previously allocated buffer. Invalid parameters will cause -// MyFree() to fail with an exit(1) call. -// -// Parameters: -// -// Ptr :=3D Pointer to the caller's buffer to be freed. -// A NULL pointer will be ignored. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// n/a -// -// --*/ -// + #else /* USE_MYALLOC */ =20 // diff --git a/BaseTools/Source/C/Common/OsPath.h b/BaseTools/Source/C/Common= /OsPath.h index 1868103e7f1b..b1881c4a1ec7 100644 --- a/BaseTools/Source/C/Common/OsPath.h +++ b/BaseTools/Source/C/Common/OsPath.h @@ -16,15 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Functions declarations // =20 -CHAR8* -OsPathDirName ( - IN CHAR8 *FilePath - ) -; /** - -Routine Description: - This function returns the directory path which contains the particular p= ath. Some examples: "a/b/c" -> "a/b" @@ -37,26 +29,17 @@ Routine Description: =20 The caller must free the string returned. =20 -Arguments: - - FilePath Path name of file to get the parent directory for. - -Returns: - - NULL if error + @param FilePath Path name of file to get the parent directory for. =20 + @return NULL if error **/ - - -VOID -OsPathNormPathInPlace ( - IN CHAR8 *Path +CHAR8* +OsPathDirName ( + IN CHAR8 *FilePath ) ; + /** - -Routine Description: - This function returns the directory path which contains the particular p= ath. Some examples: "a/b/../c" -> "a/c" @@ -65,27 +48,17 @@ Routine Description: =20 This function does not check for the existence of the file. =20 -Arguments: - - Path Path name of file to normalize - -Returns: - - The string is altered in place. + @param Path Path name of file to normalize =20 + @return The string is altered in place. **/ - - -CHAR8* -OsPathPeerFilePath ( - IN CHAR8 *OldPath, - IN CHAR8 *Peer +VOID +OsPathNormPathInPlace ( + IN CHAR8 *Path ) ; + /** - -Routine Description: - This function replaces the final portion of a path with an alternative 'peer' filename. For example: "a/b/../c", "peer" -> "a/b/../peer" @@ -95,39 +68,30 @@ Routine Description: =20 This function does not check for the existence of the file. =20 -Arguments: + @param OldPath Path name of replace the final segment + @param Peer The new path name to concatenate to become the peer p= ath =20 - OldPath Path name of replace the final segment - Peer The new path name to concatenate to become the peer path + @return A CHAR8* string, which must be freed by the caller +**/ +CHAR8* +OsPathPeerFilePath ( + IN CHAR8 *OldPath, + IN CHAR8 *Peer + ) +; =20 -Returns: +/** + Checks if a file exists =20 - A CHAR8* string, which must be freed by the caller + @param InputFileName The name of the file to check for existence =20 + @retval TRUE The file exists + @retval FALSE The file does not exist **/ - - BOOLEAN OsPathExists ( IN CHAR8 *InputFileName ) ; -/** - -Routine Description: - - Checks if a file exists - -Arguments: - - InputFileName The name of the file to check for existence - -Returns: - - TRUE The file exists - FALSE The file does not exist - -**/ - =20 #endif diff --git a/BaseTools/Source/C/Common/ParseGuidedSectionTools.h b/BaseTool= s/Source/C/Common/ParseGuidedSectionTools.h index 2714b8ce8222..2180bbd0740f 100644 --- a/BaseTools/Source/C/Common/ParseGuidedSectionTools.h +++ b/BaseTools/Source/C/Common/ParseGuidedSectionTools.h @@ -15,106 +15,73 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Functions declarations // =20 +/** + This function parses the tools_def.txt file. It returns a + EFI_HANDLE object which can be used for the other library + functions and should be passed to FreeParsedToolsDefHandle + to free resources when the tools_def.txt information is no + longer needed. + + @param InputFile Path name of file to read + + @retval NULL if error parsing + @retval A non-NULL EFI_HANDLE otherwise +**/ EFI_HANDLE ParseGuidedSectionToolsFile ( IN CHAR8 *InputFile ) ; + /** - -Routine Description: - This function parses the tools_def.txt file. It returns a EFI_HANDLE object which can be used for the other library functions and should be passed to FreeParsedToolsDefHandle to free resources when the tools_def.txt information is no longer needed. =20 -Arguments: - - InputFile Path name of file to read - -Returns: - - NULL if error parsing - A non-NULL EFI_HANDLE otherwise + @param InputFile Memory file image. =20 + @retval NULL if error parsing + @retval A non-NULL EFI_HANDLE otherwise **/ - - EFI_HANDLE ParseGuidedSectionToolsMemoryFile ( IN EFI_HANDLE InputFile ) ; + /** + This function looks up the appropriate tool to use for extracting + a GUID defined FV section. =20 -Routine Description: - - This function parses the tools_def.txt file. It returns a - EFI_HANDLE object which can be used for the other library - functions and should be passed to FreeParsedToolsDefHandle - to free resources when the tools_def.txt information is no - longer needed. - -Arguments: - - InputFile Memory file image. - -Returns: - - NULL if error parsing - A non-NULL EFI_HANDLE otherwise + @param ParsedGuidedSectionToolsHandle A parsed GUID section tools han= dle. + @param SectionGuid The GUID for the section. =20 + @retval NULL if no tool is found or there is another error + @retval Non-NULL The tool to use to access the section contents. (The c= aller + must free the memory associated with this string.) **/ - CHAR8* LookupGuidedSectionToolPath ( IN EFI_HANDLE ParsedGuidedSectionToolsHandle, IN EFI_GUID *SectionGuid ) ; -/** - -Routine Description: - - This function looks up the appropriate tool to use for extracting - a GUID defined FV section. - -Arguments: - - ParsedGuidedSectionToolsHandle A parsed GUID section tools handle. - SectionGuid The GUID for the section. =20 -Returns: - - NULL - if no tool is found or there is another error - Non-NULL - The tool to use to access the section contents. (The caller - must free the memory associated with this string.) - -**/ - -EFI_STATUS -FreeParsedGuidedSectionToolsHandle ( - IN EFI_HANDLE ParsedGuidedSectionToolsHandle - ) -; /** - -Routine Description: - Frees resources that were allocated by ParseGuidedSectionToolsFile. After freeing these resources, the information that was parsed is no longer accessible. =20 -Arguments: - - ParsedToolDefHandle Handle returned from ParseGuidedSectionToolsFile - -Returns: - - EFI_STATUS + @param ParsedToolDefHandle Handle returned from ParseGuidedSectionTool= sFile =20 + @return EFI_STATUS **/ +EFI_STATUS +FreeParsedGuidedSectionToolsHandle ( + IN EFI_HANDLE ParsedGuidedSectionToolsHandle + ) +; =20 #endif diff --git a/BaseTools/Source/C/Common/ParseInf.h b/BaseTools/Source/C/Comm= on/ParseInf.h index 596cb3aa3bbb..a0881a5c9ed0 100644 --- a/BaseTools/Source/C/Common/ParseInf.h +++ b/BaseTools/Source/C/Common/ParseInf.h @@ -20,18 +20,8 @@ extern "C" { // // Functions declarations // -CHAR8 * -ReadLine ( - IN MEMORY_FILE *InputFile, - IN OUT CHAR8 *InputBuffer, - IN UINTN MaxLength - ) -; - -/*++ - -Routine Description: =20 +/** This function reads a line, stripping any comments. The function reads a string from the input stream argument and stores it= in the input string. ReadLine reads characters from the current file positi= on @@ -39,18 +29,31 @@ Routine Description: until the number of characters read is equal to MaxLength - 1, whichever comes first. The newline character, if read, is replaced with a \0. =20 -Arguments: + @param InputFile Memory file image. + @param InputBuffer Buffer to read into, must be MaxLength size. + @param MaxLength The maximum size of the input buffer. =20 - InputFile Memory file image. - InputBuffer Buffer to read into, must be MaxLength size. - MaxLength The maximum size of the input buffer. + @retval NULL if error or EOF + @retval InputBuffer otherwise +**/ +CHAR8 * +ReadLine ( + IN MEMORY_FILE *InputFile, + IN OUT CHAR8 *InputBuffer, + IN UINTN MaxLength + ) +; =20 -Returns: +/** + This function parses a file from the beginning to find a section. + The section string may be anywhere within a line. =20 - NULL if error or EOF - InputBuffer otherwise + @param InputFile Memory file image. + @param Section Section to search for =20 ---*/ + @retval FALSE if error or EOF + @retval TRUE if section found +**/ BOOLEAN FindSection ( IN MEMORY_FILE *InputFile, @@ -58,24 +61,21 @@ FindSection ( ) ; =20 -/*++ - -Routine Description: - - This function parses a file from the beginning to find a section. - The section string may be anywhere within a line. - -Arguments: - - InputFile Memory file image. - Section Section to search for - -Returns: - - FALSE if error or EOF - TRUE if section found - ---*/ +/** + Finds a token value given the section and token to search for. + + @param InputFile Memory file image. + @param Section The section to search for, a string within []. + @param Token The token to search for, e.g. EFI_PEIM_RECOVERY, follow= ed by an =3D in the INF file. + @param Instance The instance of the token to search for. Zero is the f= irst instance. + @param Value The string that holds the value following the =3D. Mus= t be MAX_LONG_FILE_PATH in size. + + @retval EFI_SUCCESS Value found. + @retval EFI_ABORTED Format error detected in INF file. + @retval EFI_INVALID_PARAMETER Input argument was null. + @retval EFI_LOAD_ERROR Error reading from the file. + @retval EFI_NOT_FOUND Section/Token/Value not found. +**/ EFI_STATUS FindToken ( IN MEMORY_FILE *InputFile, @@ -86,29 +86,16 @@ FindToken ( ) ; =20 -/*++ +/** + Converts a string to an EFI_GUID. The string must be in the + xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format. =20 -Routine Description: + @param GuidBuffer pointer to destination Guid + @param AsciiGuidBuffer pointer to ascii string =20 - Finds a token value given the section and token to search for. - -Arguments: - - InputFile Memory file image. - Section The section to search for, a string within []. - Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by a= n =3D in the INF file. - Instance The instance of the token to search for. Zero is the first in= stance. - Value The string that holds the value following the =3D. Must be MA= X_LONG_FILE_PATH in size. - -Returns: - - EFI_SUCCESS Value found. - EFI_ABORTED Format error detected in INF file. - EFI_INVALID_PARAMETER Input argument was null. - EFI_LOAD_ERROR Error reading from the file. - EFI_NOT_FOUND Section/Token/Value not found. - ---*/ + @retval EFI_ABORTED Could not convert the string + @retval EFI_SUCCESS The string was successfully converted +**/ EFI_STATUS StringToGuid ( IN CHAR8 *AsciiGuidBuffer, @@ -116,53 +103,36 @@ StringToGuid ( ) ; =20 -/*++ - -Routine Description: - - Converts a string to an EFI_GUID. The string must be in the - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format. - -Arguments: - - GuidBuffer - pointer to destination Guid - AsciiGuidBuffer - pointer to ascii string - -Returns: - - EFI_ABORTED Could not convert the string - EFI_SUCCESS The string was successfully converted - ---*/ -EFI_STATUS -AsciiStringToUint64 ( - IN CONST CHAR8 *AsciiString, - IN BOOLEAN IsHex, - OUT UINT64 *ReturnValue - ) -; - -/*++ - -Routine Description: - +/** Converts a null terminated ascii string that represents a number into a UINT64 value. A hex number may be preceded by a 0x, but may not be succeeded by an h. A number without 0x or 0X is considered to be base 10 unless the IsHex input is true. =20 -Arguments: + @param AsciiString The string to convert. + @param IsHex Force the string to be treated as a hex number. + @param ReturnValue The return value. =20 - AsciiString The string to convert. - IsHex Force the string to be treated as a hex number. - ReturnValue The return value. + @retval EFI_SUCCESS Number successfully converted. + @retval EFI_ABORTED Invalid character encountered. +**/ +EFI_STATUS +AsciiStringToUint64 ( + IN CONST CHAR8 *AsciiString, + IN BOOLEAN IsHex, + OUT UINT64 *ReturnValue + ) +; =20 -Returns: +/** + This function reads a line, stripping any comments. =20 - EFI_SUCCESS Number successfully converted. - EFI_ABORTED Invalid character encountered. + @param InputFile Stream pointer. + @param InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH siz= e. =20 ---*/ + @retval NULL if error or EOF + @retval InputBuffer otherwise +**/ CHAR8 * ReadLineInStream ( IN FILE *InputFile, @@ -170,23 +140,16 @@ ReadLineInStream ( ) ; =20 -/*++ +/** + This function parses a stream file from the beginning to find a section. + The section string may be anywhere within a line. =20 -Routine Description: + @param InputFile Stream pointer. + @param Section Section to search for =20 - This function reads a line, stripping any comments. - -Arguments: - - InputFile Stream pointer. - InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH size. - -Returns: - - NULL if error or EOF - InputBuffer otherwise - ---*/ + @retval FALSE if error or EOF + @retval TRUE if section found +**/ BOOLEAN FindSectionInStream ( IN FILE *InputFile, @@ -194,25 +157,6 @@ FindSectionInStream ( ) ; =20 -/*++ - -Routine Description: - - This function parses a stream file from the beginning to find a section. - The section string may be anywhere within a line. - -Arguments: - - InputFile Stream pointer. - Section Section to search for - -Returns: - - FALSE if error or EOF - TRUE if section found - ---*/ - #ifdef __cplusplus } #endif diff --git a/BaseTools/Source/C/Common/PcdValueCommon.h b/BaseTools/Source/= C/Common/PcdValueCommon.h index 1652bd543039..02ef803be479 100644 --- a/BaseTools/Source/C/Common/PcdValueCommon.h +++ b/BaseTools/Source/C/Common/PcdValueCommon.h @@ -24,101 +24,81 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define __STATIC_ASSERT _Static_assert #endif =20 +/** + Main function updates PCD values. It is auto generated by Build +**/ VOID PcdEntryPoint ( VOID ) -/*++ =20 -Routine Description: - - Main function updates PCD values. It is auto generated by Build - -Arguments: - - None - -Returns: - None ---*/ ; =20 +/** + Main function updates PCD values. + + @param argc Number of command line parameters. + @param argv Array of pointers to parameter strings. + + @retval EXIT_SUCCESS +**/ int PcdValueMain ( int argc, char *argv[] ) -/*++ - -Routine Description: - - Main function updates PCD values. - -Arguments: - - argc Number of command line parameters. - argv Array of pointers to parameter strings. - -Returns: - EXIT_SUCCESS ---*/ ; =20 -VOID -__PcdSet ( - CHAR8 *SkuName OPTIONAL, - CHAR8 *DefaultValueName OPTIONAL, - CHAR8 *TokenSpaceGuidName, - CHAR8 *TokenName, - UINT64 Value - ) -/*++ - -Routine Description: - - Get PCD value - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - -Returns: - - PCD value ---*/ -; - -VOID -__PcdSet ( - CHAR8 *SkuName OPTIONAL, - CHAR8 *DefaultValueName OPTIONAL, - CHAR8 *TokenSpaceGuidName, - CHAR8 *TokenName, - UINT64 Value - ) -/*++ - -Routine Description: - +/** Set PCD value =20 -Arguments: + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Value PCD value to be set +**/ +VOID +__PcdSet ( + CHAR8 *SkuName OPTIONAL, + CHAR8 *DefaultValueName OPTIONAL, + CHAR8 *TokenSpaceGuidName, + CHAR8 *TokenName, + UINT64 Value + ) +; =20 - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Value PCD value to be set +/** + Get PCD value =20 -Returns: + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String =20 - None ---*/ + @return PCD value +**/ +VOID +__PcdSet ( + CHAR8 *SkuName OPTIONAL, + CHAR8 *DefaultValueName OPTIONAL, + CHAR8 *TokenSpaceGuidName, + CHAR8 *TokenName, + UINT64 Value + ) ; =20 +/** + Get PCD value buffer + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Size Size of PCD value buffer + + @return PCD value buffer +**/ VOID * __PcdGetPtr ( CHAR8 *SkuName OPTIONAL, @@ -127,26 +107,18 @@ __PcdGetPtr ( CHAR8 *TokenName, UINT32 *Size ) -/*++ - -Routine Description: - - Get PCD value buffer - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Size Size of PCD value buffer - -Returns: - - PCD value buffer ---*/ ; =20 +/** + Set PCD value buffer + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Size Size of PCD value + @param Value Pointer to the updated PCD value buffer +**/ VOID __PcdSetPtr ( CHAR8 *SkuName OPTIONAL, @@ -156,25 +128,6 @@ __PcdSetPtr ( UINT32 Size, UINT8 *Value ) -/*++ - -Routine Description: - - Set PCD value buffer - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Size Size of PCD value - Value Pointer to the updated PCD value buffer - -Returns: - - None ---*/ ; =20 #define PcdGet(A, B, C, D) __PcdGet(#A, #B, #C, #D) diff --git a/BaseTools/Source/C/Common/StringFuncs.h b/BaseTools/Source/C/C= ommon/StringFuncs.h index 8fc616de8034..23dce2724448 100644 --- a/BaseTools/Source/C/Common/StringFuncs.h +++ b/BaseTools/Source/C/Common/StringFuncs.h @@ -29,216 +29,139 @@ typedef struct { // Functions declarations // =20 -CHAR8* -CloneString ( - IN CHAR8 *String - ) -; /** - -Routine Description: - Allocates a new string and copies 'String' to clone it =20 -Arguments: - - String The string to clone - -Returns: - - CHAR8* - NULL if there are not enough resources + @param String The string to clone =20 + @return CHAR8* - NULL if there are not enough resources **/ - - -EFI_STATUS -StripInfDscStringInPlace ( +CHAR8* +CloneString ( IN CHAR8 *String ) ; + /** - -Routine Description: - Remove all comments, leading and trailing whitespace from the string. =20 -Arguments: - - String The string to 'strip' - -Returns: - - EFI_STATUS + @param String The string to 'strip' =20 + @return EFI_STATUS **/ - - -STRING_LIST* -SplitStringByWhitespace ( +EFI_STATUS +StripInfDscStringInPlace ( IN CHAR8 *String ) ; + /** - -Routine Description: - Creates and returns a 'split' STRING_LIST by splitting the string on whitespace boundaries. =20 -Arguments: - - String The string to 'split' - -Returns: - - EFI_STATUS + @param String The string to 'split' =20 + @return EFI_STATUS **/ - - STRING_LIST* -NewStringList ( +SplitStringByWhitespace ( + IN CHAR8 *String ) ; + /** - -Routine Description: - Creates a new STRING_LIST with 0 strings. =20 -Returns: - - STRING_LIST* - Null if there is not enough resources to create the objec= t. - + @return STRING_LIST* - Null if there is not enough resources to create t= he object. **/ - - -EFI_STATUS -AppendCopyOfStringToList ( - IN OUT STRING_LIST **StringList, - IN CHAR8 *String +STRING_LIST* +NewStringList ( ) ; + + /** - -Routine Description: - Adds String to StringList. A new copy of String is made before it is added to StringList. =20 -Returns: - - EFI_STATUS - + @return EFI_STATUS **/ - - EFI_STATUS -RemoveLastStringFromList ( - IN STRING_LIST *StringList +AppendCopyOfStringToList ( + IN OUT STRING_LIST **StringList, + IN CHAR8 *String ) ; + /** - -Routine Description: - Removes the last string from StringList and frees the memory associated with it. =20 -Arguments: + @param StringList The string list to remove the string from =20 - StringList The string list to remove the string from - -Returns: + @return EFI_STATUS +**/ +EFI_STATUS +RemoveLastStringFromList ( + IN STRING_LIST *StringList + ) +; =20 - EFI_STATUS =20 -**/ +/** + Allocates a STRING_LIST structure that can store StringCount strings. =20 + @param StringCount The number of strings that need to be stored =20 + @return EFI_STATUS +**/ STRING_LIST* AllocateStringListStruct ( IN UINTN StringCount ) ; -/** - -Routine Description: - - Allocates a STRING_LIST structure that can store StringCount strings. - -Arguments: - - StringCount The number of strings that need to be stored =20 -Returns: =20 - EFI_STATUS - -**/ - - -VOID -FreeStringList ( - IN STRING_LIST *StringList - ) -; /** - -Routine Description: - Frees all memory associated with StringList. =20 -Arguments: - - StringList The string list to free - -Returns: - - EFI_STATUS + @param StringList The string list to free =20 + @return EFI_STATUS **/ - - -CHAR8* -StringListToString ( +VOID +FreeStringList ( IN STRING_LIST *StringList ) ; + + /** - -Routine Description: - Generates a string that represents the STRING_LIST =20 -Arguments: + @param StringList The string list to convert to a string =20 - StringList The string list to convert to a string - -Returns: - - CHAR8* - The string list represented with a single string. The returned + @return CHAR8* The string list represented with a single string. The re= turned string must be freed by the caller. - **/ - - -VOID -PrintStringList ( +CHAR8* +StringListToString ( IN STRING_LIST *StringList ) ; + + /** - -Routine Description: - Prints out the string list =20 -Arguments: - - StringList The string list to print - + @param StringList The string list to print **/ +VOID +PrintStringList ( + IN STRING_LIST *StringList + ) +; + =20 =20 #endif diff --git a/BaseTools/Source/C/Common/BasePeCoff.c b/BaseTools/Source/C/Co= mmon/BasePeCoff.c index 30400d1341dc..b8bfb7b58b91 100644 --- a/BaseTools/Source/C/Common/BasePeCoff.c +++ b/BaseTools/Source/C/Common/BasePeCoff.c @@ -77,33 +77,23 @@ PeCoffLoaderRelocateLoongArch64Image ( IN UINT64 Adjust ); =20 -STATIC -RETURN_STATUS -PeCoffLoaderGetPeHeader ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - OUT EFI_IMAGE_OPTIONAL_HEADER_UNION **PeHdr, - OUT EFI_TE_IMAGE_HEADER **TeHdr - ) -/*++ - -Routine Description: - +/** Retrieves the PE or TE Header from a PE/COFF or TE image =20 -Arguments: + @param ImageContext The context of the image being loaded + @param PeHdr The buffer in which to return the PE header + @param TeHdr The buffer in which to return the TE header =20 - ImageContext - The context of the image being loaded - - PeHdr - The buffer in which to return the PE header - - TeHdr - The buffer in which to return the TE header - -Returns: - - RETURN_SUCCESS if the PE or TE Header is read, + @return RETURN_SUCCESS if the PE or TE Header is read, Otherwise, the error status from reading the PE/COFF or TE image using t= he ImageRead function. - ---*/ +**/ +STATIC +RETURN_STATUS +PeCoffLoaderGetPeHeader ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_IMAGE_OPTIONAL_HEADER_UNION **PeHdr, + OUT EFI_TE_IMAGE_HEADER **TeHdr + ) { RETURN_STATUS Status; EFI_IMAGE_DOS_HEADER DosHdr; @@ -150,6 +140,17 @@ Routine Description: return RETURN_SUCCESS; } =20 +/** + Checks the PE or TE header of a PE/COFF or TE image to determine if it s= upported + + @param ImageContext The context of the image being loaded + @param PeHdr The buffer in which to return the PE header + @param TeHdr The buffer in which to return the TE header + + @retval RETURN_SUCCESS if the PE/COFF or TE image is supported + @retval RETURN_UNSUPPORTED of the PE/COFF or TE image is not supported. + +**/ STATIC RETURN_STATUS PeCoffLoaderCheckImageType ( @@ -157,26 +158,6 @@ PeCoffLoaderCheckImageType ( IN EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr, IN EFI_TE_IMAGE_HEADER *TeHdr ) -/*++ - -Routine Description: - - Checks the PE or TE header of a PE/COFF or TE image to determine if it s= upported - -Arguments: - - ImageContext - The context of the image being loaded - - PeHdr - The buffer in which to return the PE header - - TeHdr - The buffer in which to return the TE header - -Returns: - - RETURN_SUCCESS if the PE/COFF or TE image is supported - RETURN_UNSUPPORTED of the PE/COFF or TE image is not supported. - ---*/ { // // See if the machine type is supported. @@ -239,31 +220,24 @@ Routine Description: return RETURN_SUCCESS; } =20 +/** + Retrieves information on a PE/COFF image + + @param This Calling context + @param ImageContext The context of the image being loaded + + @retval RETURN_SUCCESS The information on the PE/COFF image wa= s collected. + @retval RETURN_INVALID_PARAMETER ImageContext is NULL. + @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. + @retval Otherwise The error status from reading the PE/CO= FF image using the + ImageContext->ImageRead() function + +**/ RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) -/*++ - -Routine Description: - - Retrieves information on a PE/COFF image - -Arguments: - - This - Calling context - ImageContext - The context of the image being loaded - -Returns: - - RETURN_SUCCESS - The information on the PE/COFF image was coll= ected. - RETURN_INVALID_PARAMETER - ImageContext is NULL. - RETURN_UNSUPPORTED - The PE/COFF image is not supported. - Otherwise - The error status from reading the PE/COFF image = using the - ImageContext->ImageRead() function - ---*/ { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; @@ -539,29 +513,21 @@ Routine Description: return RETURN_SUCCESS; } =20 -STATIC -VOID * -PeCoffLoaderImageAddress ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN UINTN Address - ) -/*++ - -Routine Description: - +/** Converts an image address to the loaded address =20 -Arguments: + @param ImageContext The context of the image being loaded + @param Address The address to be converted to the loaded address =20 - ImageContext - The context of the image being loaded - - Address - The address to be converted to the loaded address - -Returns: - - NULL if the address can not be converted, otherwise, the converted addre= ss + @return NULL if the address can not be converted, otherwise, the convert= ed address =20 --*/ +STATIC +VOID * +PeCoffLoaderImageAddress ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN UINTN Address + ) { if (Address >=3D ImageContext->ImageSize) { ImageContext->ImageError =3D IMAGE_ERROR_INVALID_IMAGE_ADDRESS; @@ -571,30 +537,22 @@ Routine Description: return (UINT8 *) ((UINTN) ImageContext->ImageAddress + Address); } =20 -RETURN_STATUS -EFIAPI -PeCoffLoaderRelocateImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -/*++ - -Routine Description: - +/** Relocates a PE/COFF image in memory =20 -Arguments: - - This - Calling context - - ImageContext - Contains information on the loaded image to relocate - -Returns: - - RETURN_SUCCESS if the PE/COFF image was relocated - RETURN_LOAD_ERROR if the image is not a valid PE/COFF image - RETURN_UNSUPPORTED not support - ---*/ + @param This Calling context + @param ImageContext Contains information on the loaded image to relocate + + @retval RETURN_SUCCESS if the PE/COFF image was relocated + @retval RETURN_LOAD_ERROR if the image is not a valid PE/COFF image + @retval RETURN_UNSUPPORTED not support + +**/ +RETURN_STATUS +EFIAPI +PeCoffLoaderRelocateImage ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; @@ -853,31 +811,23 @@ Routine Description: return RETURN_SUCCESS; } =20 -RETURN_STATUS -EFIAPI -PeCoffLoaderLoadImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -/*++ - -Routine Description: - +/** Loads a PE/COFF image into memory =20 -Arguments: - - This - Calling context - - ImageContext - Contains information on image to load into memory - -Returns: - - RETURN_SUCCESS if the PE/COFF image was loaded - RETURN_BUFFER_TOO_SMALL if the caller did not provide a large enough b= uffer - RETURN_LOAD_ERROR if the image is a runtime driver with no reloc= ations - RETURN_INVALID_PARAMETER if the image address is invalid - ---*/ + @param This Calling context + @param ImageContext Contains information on image to load into memory + + @retval RETURN_SUCCESS if the PE/COFF image was loaded + @retval RETURN_BUFFER_TOO_SMALL if the caller did not provide a large = enough buffer + @retval RETURN_LOAD_ERROR if the image is a runtime driver with = no relocations + @retval RETURN_INVALID_PARAMETER if the image address is invalid + +**/ +RETURN_STATUS +EFIAPI +PeCoffLoaderLoadImage ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Com= mon/CommonLib.c index 7fb4ab764fcd..cd270f9a9074 100644 --- a/BaseTools/Source/C/Common/CommonLib.c +++ b/BaseTools/Source/C/Common/CommonLib.c @@ -26,28 +26,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent } \ } while (FALSE) =20 -VOID -PeiZeroMem ( - IN VOID *Buffer, - IN UINTN Size - ) -/*++ - -Routine Description: - +/** Set Buffer to zero for Size bytes. =20 -Arguments: - - Buffer - Memory to set. - - Size - Number of bytes to set - -Returns: - - None - ---*/ + @param Buffer Memory to set. + @param Size Number of bytes to set +**/ +VOID +PeiZeroMem ( + IN VOID *Buffer, + IN UINTN Size + ) { INT8 *Ptr; =20 @@ -57,31 +46,19 @@ Routine Description: } } =20 -VOID -PeiCopyMem ( - IN VOID *Destination, - IN VOID *Source, - IN UINTN Length - ) -/*++ - -Routine Description: - +/** Copy Length bytes from Source to Destination. =20 -Arguments: - - Destination - Target of copy - - Source - Place to copy from - - Length - Number of bytes to copy - -Returns: - - None - ---*/ + @param Destination Target of copy + @param Source Place to copy from + @param Length Number of bytes to copy +**/ +VOID +PeiCopyMem ( + IN VOID *Destination, + IN VOID *Source, + IN UINTN Length + ) { CHAR8 *Destination8; CHAR8 *Source8; @@ -112,27 +89,20 @@ CopyMem ( PeiCopyMem (Destination, Source, Length); } =20 +/** + Compares to GUIDs + + @param Guid1 guid to compare + @param Guid2 guid to compare + + @retval =3D 0 if Guid1 =3D=3D Guid2 + @retval !=3D 0 if Guid1 !=3D Guid2 +**/ INTN CompareGuid ( IN EFI_GUID *Guid1, IN EFI_GUID *Guid2 ) -/*++ - -Routine Description: - - Compares to GUIDs - -Arguments: - - Guid1 - guid to compare - Guid2 - guid to compare - -Returns: - =3D 0 if Guid1 =3D=3D Guid2 - !=3D 0 if Guid1 !=3D Guid2 - ---*/ { INT32 *g1; INT32 *g2; @@ -152,34 +122,25 @@ Routine Description: return r; } =20 +/** + This function opens a file and reads it into a memory buffer. The funct= ion + will allocate the memory buffer and returns the size of the buffer. =20 + @param InputFileName The name of the file to read. + @param InputFileImage A pointer to the memory buffer. + @param BytesRead The size of the memory buffer. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER One of the input parameters was invalid. + @retval EFI_ABORTED An error occurred. + @retval EFI_OUT_OF_RESOURCES No resource to complete operations. +**/ EFI_STATUS GetFileImage ( IN CHAR8 *InputFileName, OUT CHAR8 **InputFileImage, OUT UINT32 *BytesRead ) -/*++ - -Routine Description: - - This function opens a file and reads it into a memory buffer. The funct= ion - will allocate the memory buffer and returns the size of the buffer. - -Arguments: - - InputFileName The name of the file to read. - InputFileImage A pointer to the memory buffer. - BytesRead The size of the memory buffer. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_INVALID_PARAMETER One of the input parameters was invalid. - EFI_ABORTED An error occurred. - EFI_OUT_OF_RESOURCES No resource to complete operations. - ---*/ { FILE *InputFile; UINT32 FileSize; @@ -255,32 +216,24 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function opens a file and writes OutputFileImage into the file. + + @param OutputFileName The name of the file to write. + @param OutputFileImage A pointer to the memory buffer. + @param BytesToWrite The size of the memory buffer. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER One of the input parameters was invalid. + @retval EFI_ABORTED An error occurred. + @retval EFI_OUT_OF_RESOURCES No resource to complete operations. +**/ EFI_STATUS PutFileImage ( IN CHAR8 *OutputFileName, IN CHAR8 *OutputFileImage, IN UINT32 BytesToWrite ) -/*++ - -Routine Description: - - This function opens a file and writes OutputFileImage into the file. - -Arguments: - - OutputFileName The name of the file to write. - OutputFileImage A pointer to the memory buffer. - BytesToWrite The size of the memory buffer. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_INVALID_PARAMETER One of the input parameters was invalid. - EFI_ABORTED An error occurred. - EFI_OUT_OF_RESOURCES No resource to complete operations. - ---*/ { FILE *OutputFile; UINT32 BytesWrote; @@ -320,52 +273,36 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function calculates the value needed for a valid UINT8 checksum + + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 8 bit checksum value needed. +**/ UINT8 CalculateChecksum8 ( IN UINT8 *Buffer, IN UINTN Size ) -/*++ - -Routine Description: - - This function calculates the value needed for a valid UINT8 checksum - -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 8 bit checksum value needed. - ---*/ { return (UINT8) (0x100 - CalculateSum8 (Buffer, Size)); } =20 +/** + This function calculates the UINT8 sum for the requested region. + + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 8 bit checksum value needed. +**/ UINT8 CalculateSum8 ( IN UINT8 *Buffer, IN UINTN Size ) -/*++ - -Routine Description:: - - This function calculates the UINT8 sum for the requested region. - -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 8 bit checksum value needed. - ---*/ { UINTN Index; UINT8 Sum; @@ -382,52 +319,36 @@ Routine Description:: return Sum; } =20 -UINT16 -CalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size - ) -/*++ - -Routine Description:: - +/** This function calculates the value needed for a valid UINT16 checksum =20 -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 16 bit checksum value needed. - ---*/ + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer +=20 + @return The 16 bit checksum value needed. +**/ +UINT16 +CalculateChecksum16 ( + IN UINT16 *Buffer, + IN UINTN Size + ) { return (UINT16) (0x10000 - CalculateSum16 (Buffer, Size)); } =20 -UINT16 -CalculateSum16 ( - IN UINT16 *Buffer, - IN UINTN Size - ) -/*++ - -Routine Description: - +/** This function calculates the UINT16 sum for the requested region. =20 -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 16 bit checksum - ---*/ + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 16 bit checksum +**/ +UINT16 +CalculateSum16 ( + IN UINT16 *Buffer, + IN UINTN Size + ) { UINTN Index; UINT16 Sum; @@ -444,26 +365,18 @@ Routine Description: return (UINT16) Sum; } =20 +/** + This function prints a GUID to STDOUT. + + @param Guid Pointer to a GUID to print. + + @retval EFI_SUCCESS The GUID was printed. + @retval EFI_INVALID_PARAMETER The input was NULL. +**/ EFI_STATUS PrintGuid ( IN EFI_GUID *Guid ) -/*++ - -Routine Description: - - This function prints a GUID to STDOUT. - -Arguments: - - Guid Pointer to a GUID to print. - -Returns: - - EFI_SUCCESS The GUID was printed. - EFI_INVALID_PARAMETER The input was NULL. - ---*/ { if (Guid =3D=3D NULL) { Error (NULL, 0, 2000, "Invalid parameter", "PrintGuidToBuffer() called= with a NULL value"); @@ -487,6 +400,18 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function prints a GUID to a buffer + + @param Guid Pointer to a GUID to print. + @param Buffer Pointer to a user-provided buffer to print to + @param BufferLen Size of the Buffer + @param Uppercase If use upper case. + + @retval EFI_SUCCESS The GUID was printed. + @retval EFI_INVALID_PARAMETER The input was NULL. + @retval EFI_BUFFER_TOO_SMALL The input buffer was not big enough +**/ EFI_STATUS PrintGuidToBuffer ( IN EFI_GUID *Guid, @@ -494,26 +419,6 @@ PrintGuidToBuffer ( IN UINT32 BufferLen, IN BOOLEAN Uppercase ) -/*++ - -Routine Description: - - This function prints a GUID to a buffer - -Arguments: - - Guid - Pointer to a GUID to print. - Buffer - Pointer to a user-provided buffer to print to - BufferLen - Size of the Buffer - Uppercase - If use upper case. - -Returns: - - EFI_SUCCESS The GUID was printed. - EFI_INVALID_PARAMETER The input was NULL. - EFI_BUFFER_TOO_SMALL The input buffer was not big enough - ---*/ { if (Guid =3D=3D NULL) { Error (NULL, 0, 2000, "Invalid parameter", "PrintGuidToBuffer() called= with a NULL value"); @@ -591,22 +496,17 @@ char *strlwr(char *s) // CHAR8 mCommonLibFullPath[MAX_LONG_FILE_PATH]; =20 +/** + Convert FileName to the long file path, which can support larger than 26= 0 length. + + @param FileName FileName. + + @return LongFilePath A pointer to the converted long file path. +**/ CHAR8 * LongFilePath ( IN CHAR8 *FileName ) -/*++ - -Routine Description: - Convert FileName to the long file path, which can support larger than 26= 0 length. - -Arguments: - FileName - FileName. - -Returns: - LongFilePath A pointer to the converted long file path. - ---*/ { #ifdef __GNUC__ // diff --git a/BaseTools/Source/C/Common/Crc32.c b/BaseTools/Source/C/Common/= Crc32.c index 7281d5f0e913..00cae948985d 100644 --- a/BaseTools/Source/C/Common/Crc32.c +++ b/BaseTools/Source/C/Common/Crc32.c @@ -268,31 +268,23 @@ UINT32 mCrcTable[256] =3D { 0x2D02EF8D }; =20 +/** + The CalculateCrc32 routine. + + @param Data The buffer containing the data to be processed + @param DataSize The size of data to be processed + @param CrcOut A pointer to the caller allocated UINT32 that on + contains the CRC32 checksum of Data + + @retval EFI_SUCCESS Calculation is successful. + @retval EFI_INVALID_PARAMETER Data / CrcOut =3D NULL, or DataSize = =3D 0 +**/ EFI_STATUS CalculateCrc32 ( IN UINT8 *Data, IN UINTN DataSize, IN OUT UINT32 *CrcOut ) -/*++ - -Routine Description: - - The CalculateCrc32 routine. - -Arguments: - - Data - The buffer containing the data to be processed - DataSize - The size of data to be processed - CrcOut - A pointer to the caller allocated UINT32 that on - contains the CRC32 checksum of Data - -Returns: - - EFI_SUCCESS - Calculation is successful. - EFI_INVALID_PARAMETER - Data / CrcOut =3D NULL, or DataSize =3D 0 - ---*/ { UINT32 Crc; UINTN Index; diff --git a/BaseTools/Source/C/Common/Decompress.c b/BaseTools/Source/C/Co= mmon/Decompress.c index d85098f13140..a0f54c08342b 100644 --- a/BaseTools/Source/C/Common/Decompress.c +++ b/BaseTools/Source/C/Common/Decompress.c @@ -62,26 +62,18 @@ typedef struct { =20 STATIC UINT16 mPbit =3D EFIPBIT; =20 -STATIC -VOID -FillBuf ( - IN SCRATCH_DATA *Sd, - IN UINT16 NumOfBits - ) -/*++ - -Routine Description: - +/** Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source. =20 -Arguments: - - Sd - The global scratch data - NumOfBit - The number of bits to shift and read. - -Returns: (VOID) - ---*/ + @param Sd The global scratch data + @param NumOfBit The number of bits to shift and read. +**/ +STATIC +VOID +FillBuf ( + IN SCRATCH_DATA *Sd, + IN UINT16 NumOfBits + ) { Sd->mBitBuf =3D (UINT32) (((UINT64)Sd->mBitBuf) << NumOfBits); =20 @@ -112,30 +104,22 @@ Returns: (VOID) Sd->mBitBuf |=3D Sd->mSubBitBuf >> Sd->mBitCount; } =20 -STATIC -UINT32 -GetBits ( - IN SCRATCH_DATA *Sd, - IN UINT16 NumOfBits - ) -/*++ - -Routine Description: - +/** Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent NumOfBits of bits from source. Returns NumOfBits of bits that are popped out. =20 -Arguments: - - Sd - The global scratch data. - NumOfBits - The number of bits to pop and read. - -Returns: - - The bits that are popped out. - ---*/ + @param Sd The global scratch data. + @param NumOfBits The number of bits to pop and read. + + @return The bits that are popped out. +**/ +STATIC +UINT32 +GetBits ( + IN SCRATCH_DATA *Sd, + IN UINT16 NumOfBits + ) { UINT32 OutBits; =20 @@ -146,6 +130,18 @@ Routine Description: return OutBits; } =20 +/** + Creates Huffman Code mapping table according to code length array. + + @param Sd The global scratch data + @param NumOfChar Number of symbols in the symbol set + @param BitLen Code length array + @param TableBits The width of the mapping table + @param Table The table + + @retval 0 - OK. + @retval BAD_TABLE - The table is corrupted. +**/ STATIC UINT16 MakeTable ( @@ -155,26 +151,6 @@ MakeTable ( IN UINT16 TableBits, OUT UINT16 *Table ) -/*++ - -Routine Description: - - Creates Huffman Code mapping table according to code length array. - -Arguments: - - Sd - The global scratch data - NumOfChar - Number of symbols in the symbol set - BitLen - Code length array - TableBits - The width of the mapping table - Table - The table - -Returns: - - 0 - OK. - BAD_TABLE - The table is corrupted. - ---*/ { UINT16 Count[17]; UINT16 Weight[17]; @@ -290,26 +266,18 @@ Routine Description: return 0; } =20 +/** + Decodes a position value. + + @param Sd the global scratch data + + @return The position value decoded. +**/ STATIC UINT32 DecodeP ( IN SCRATCH_DATA *Sd ) -/*++ - -Routine Description: - - Decodes a position value. - -Arguments: - - Sd - the global scratch data - -Returns: - - The position value decoded. - ---*/ { UINT16 Val; UINT32 Mask; @@ -344,6 +312,17 @@ Routine Description: return Pos; } =20 +/** + Reads code lengths for the Extra Set or the Position Set + + @param Sd The global scratch data + @param nn Number of symbols + @param nbit Number of bits needed to represent nn + @param Special The special symbol that needs to be taken care of + + @retval 0 - OK. + @retval BAD_TABLE - Table is corrupted. +**/ STATIC UINT16 ReadPTLen ( @@ -352,25 +331,6 @@ ReadPTLen ( IN UINT16 nbit, IN UINT16 Special ) -/*++ - -Routine Description: - - Reads code lengths for the Extra Set or the Position Set - -Arguments: - - Sd - The global scratch data - nn - Number of symbols - nbit - Number of bits needed to represent nn - Special - The special symbol that needs to be taken care of - -Returns: - - 0 - OK. - BAD_TABLE - Table is corrupted. - ---*/ { UINT16 Number; UINT16 CharC; @@ -430,24 +390,16 @@ Routine Description: return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable); } =20 -STATIC -VOID -ReadCLen ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - +/** Reads code lengths for Char&Len Set. =20 -Arguments: - - Sd - the global scratch data - -Returns: (VOID) - ---*/ + @param Sd the global scratch data +**/ +STATIC +VOID +ReadCLen ( + SCRATCH_DATA *Sd + ) { UINT16 Number; UINT16 CharC; @@ -526,26 +478,18 @@ Returns: (VOID) return ; } =20 -STATIC -UINT16 -DecodeC ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - +/** Decode a character/length value. =20 -Arguments: - - Sd - The global scratch data. - -Returns: - - The value decoded. - ---*/ + @param Sd The global scratch data. + + @return The value decoded. +**/ +STATIC +UINT16 +DecodeC ( + SCRATCH_DATA *Sd + ) { UINT16 Index2; UINT32 Mask; @@ -592,24 +536,16 @@ Routine Description: return Index2; } =20 -STATIC -VOID -Decode ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - +/** Decode the source data and put the resulting data into the destination b= uffer. =20 -Arguments: - - Sd - The global scratch data - -Returns: (VOID) - - --*/ + @param Sd The global scratch data + **/ +STATIC +VOID +Decode ( + SCRATCH_DATA *Sd + ) { UINT16 BytesRemain; UINT32 DataIdx; @@ -669,32 +605,24 @@ Returns: (VOID) return ; } =20 -EFI_STATUS -GetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - +/** The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of s= cratch buffer are successfully retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param DstSize The size of destination buffer. + @param ScratchSize The size of scratch buffer. + + @retval EFI_SUCCESS - The size of destination buffer and the s= ize of scratch buffer are successfully retrieved. + @retval EFI_INVALID_PARAMETER - The source data is corrupted +**/ +EFI_STATUS +GetInfo ( + IN VOID *Source, + IN UINT32 SrcSize, + OUT UINT32 *DstSize, + OUT UINT32 *ScratchSize + ) { UINT8 *Src; UINT32 CompSize; @@ -716,36 +644,28 @@ Routine Description: return EFI_SUCCESS; } =20 -EFI_STATUS -Decompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ) -/*++ - -Routine Description: - +/** The implementation Efi and Tiano Decompress(). =20 -Arguments: + @param Source - The source buffer containing the compressed data. + @param SrcSize - The size of source buffer + @param Destination - The destination buffer to store the decompressed da= ta + @param DstSize - The size of destination buffer. + @param Scratch - The buffer used internally by the decompress routin= e. This buffer is needed to store intermediate data. + @param ScratchSize - The size of scratch buffer. =20 - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This= buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successful - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ + @retval EFI_SUCCESS - Decompression is successful + @retval EFI_INVALID_PARAMETER - The source data is corrupted +**/ +EFI_STATUS +Decompress ( + IN VOID *Source, + IN UINT32 SrcSize, + IN OUT VOID *Destination, + IN UINT32 DstSize, + IN OUT VOID *Scratch, + IN UINT32 ScratchSize + ) { UINT32 Index; UINT32 CompSize; @@ -811,131 +731,99 @@ Routine Description: return Status; } =20 -EFI_STATUS -EfiGetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - +/** The implementation Efi Decompress GetInfo(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of s= cratch buffer are successfully retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - return GetInfo (Source, SrcSize, DstSize, ScratchSize); -} - + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param DstSize The size of destination buffer. + @param ScratchSize The size of scratch buffer. + + @retval EFI_SUCCESS The size of destination buffer and the siz= e of scratch buffer are successfully retrieved. + @retval EFI_INVALID_PARAMETER The source data is corrupted +**/ EFI_STATUS -TianoGetInfo ( +EfiGetInfo ( IN VOID *Source, IN UINT32 SrcSize, OUT UINT32 *DstSize, OUT UINT32 *ScratchSize ) -/*++ - -Routine Description: +{ + return GetInfo (Source, SrcSize, DstSize, ScratchSize); +} =20 +/** The implementation Tiano Decompress GetInfo(). =20 -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of s= cratch buffer are successfully retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - return GetInfo (Source, SrcSize, DstSize, ScratchSize); -} - + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param DstSize The size of destination buffer. + @param ScratchSize The size of scratch buffer. + + @retval EFI_SUCCESS The size of destination buffer and the siz= e of scratch buffer are successfully retrieved. + @retval EFI_INVALID_PARAMETER The source data is corrupted +**/ EFI_STATUS -EfiDecompress ( +TianoGetInfo ( IN VOID *Source, IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize + OUT UINT32 *DstSize, + OUT UINT32 *ScratchSize ) -/*++ - -Routine Description: +{ + return GetInfo (Source, SrcSize, DstSize, ScratchSize); +} =20 +/** The implementation of Efi Decompress(). =20 -Arguments: + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param Destination The destination buffer to store the decompressed data + @param DstSize The size of destination buffer. + @param Scratch The buffer used internally by the decompress routine.= This buffer is needed to store intermediate data. + @param ScratchSize The size of scratch buffer. =20 - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This= buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successful - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ + @retval EFI_SUCCESS Decompression is successful + @retval EFI_INVALID_PARAMETER The source data is corrupted +**/ +EFI_STATUS +EfiDecompress ( + IN VOID *Source, + IN UINT32 SrcSize, + IN OUT VOID *Destination, + IN UINT32 DstSize, + IN OUT VOID *Scratch, + IN UINT32 ScratchSize + ) { mPbit =3D EFIPBIT; return Decompress (Source, SrcSize, Destination, DstSize, Scratch, Scrat= chSize); } =20 -EFI_STATUS -TianoDecompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ) -/*++ - -Routine Description: - +/** The implementation of Tiano Decompress(). =20 -Arguments: + @param Source The source buffer containing the compressed data. + @param SrcSize The size of source buffer + @param Destination The destination buffer to store the decompressed data + @param DstSize The size of destination buffer. + @param Scratch The buffer used internally by the decompress routine.= This buffer is needed to store intermediate data. + @param ScratchSize The size of scratch buffer. =20 - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This= buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successful - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ + @retval EFI_SUCCESS Decompression is successful + @retval EFI_INVALID_PARAMETER The source data is corrupted +**/ +EFI_STATUS +TianoDecompress ( + IN VOID *Source, + IN UINT32 SrcSize, + IN OUT VOID *Destination, + IN UINT32 DstSize, + IN OUT VOID *Scratch, + IN UINT32 ScratchSize + ) { mPbit =3D MAXPBIT; return Decompress (Source, SrcSize, Destination, DstSize, Scratch, Scrat= chSize); diff --git a/BaseTools/Source/C/Common/EfiCompress.c b/BaseTools/Source/C/C= ommon/EfiCompress.c index db5ebe3157d2..0db958b8535a 100644 --- a/BaseTools/Source/C/Common/EfiCompress.c +++ b/BaseTools/Source/C/Common/EfiCompress.c @@ -250,6 +250,20 @@ STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mP= arent, *mPrev, *mNext =3D NU // functions // =20 +/** + The main compression routine. + + @param SrcBuffer The buffer storing the source data + @param SrcSize The size of source data + @param DstBuffer The buffer to store the compressed data + @param DstSize On input, the size of DstBuffer; On output, + the size of the actual compressed data. + + @retval EFI_BUFFER_TOO_SMALL The DstBuffer is too small. In this case, + DstSize contains the size needed. + @retval EFI_SUCCESS Compression is successful. + +**/ EFI_STATUS EfiCompress ( IN UINT8 *SrcBuffer, @@ -257,27 +271,6 @@ EfiCompress ( IN UINT8 *DstBuffer, IN OUT UINT32 *DstSize ) -/*++ - -Routine Description: - - The main compression routine. - -Arguments: - - SrcBuffer - The buffer storing the source data - SrcSize - The size of source data - DstBuffer - The buffer to store the compressed data - DstSize - On input, the size of DstBuffer; On output, - the size of the actual compressed data. - -Returns: - - EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case, - DstSize contains the size needed. - EFI_SUCCESS - Compression is successful. - ---*/ { EFI_STATUS Status =3D EFI_SUCCESS; =20 @@ -345,24 +338,16 @@ Routine Description: =20 } =20 -STATIC -VOID -PutDword( - IN UINT32 Data - ) -/*++ - -Routine Description: - +/** Put a dword to output stream =20 -Arguments: - - Data - the dword to put - -Returns: (VOID) - ---*/ + @param Data the dword to put +**/ +STATIC +VOID +PutDword( + IN UINT32 Data + ) { if (mDst < mDstUpperLimit) { *mDst++ =3D (UINT8)(((UINT8)(Data )) & 0xff); @@ -381,23 +366,15 @@ Returns: (VOID) } } =20 -STATIC -EFI_STATUS -AllocateMemory () -/*++ - -Routine Description: - +/** Allocate memory spaces for data structures used in compression process =20 -Arguments: (VOID) - -Returns: - - EFI_SUCCESS - Memory is allocated successfully - EFI_OUT_OF_RESOURCES - Allocation fails - ---*/ + @retval EFI_SUCCESS Memory is allocated successfully + @retva; EFI_OUT_OF_RESOURCES Allocation fails +**/ +STATIC +EFI_STATUS +AllocateMemory () { UINT32 i; =20 @@ -432,19 +409,11 @@ Arguments: (VOID) return EFI_SUCCESS; } =20 -VOID -FreeMemory () -/*++ - -Routine Description: - +/** Called when compression is completed to free memory previously allocated. - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +VOID +FreeMemory () { if (mText) { free (mText); @@ -481,21 +450,12 @@ Returns: (VOID) return; } =20 - -STATIC -VOID -InitSlide () -/*++ - -Routine Description: - +/** Initialize String Info Log data structures - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +InitSlide () { NODE i; =20 @@ -517,29 +477,20 @@ Returns: (VOID) } } =20 - -STATIC -NODE -Child ( - IN NODE q, - IN UINT8 c - ) -/*++ - -Routine Description: - +/** Find child node given the parent node and the edge character =20 -Arguments: - - q - the parent node - c - the edge character - -Returns: - - The child node (NIL if not found) - ---*/ + @param q the parent node + @param c the edge character + + @return The child node (NIL if not found) +**/ +STATIC +NODE +Child ( + IN NODE q, + IN UINT8 c + ) { NODE r; =20 @@ -552,28 +503,20 @@ Routine Description: return r; } =20 -STATIC -VOID -MakeChild ( - IN NODE q, - IN UINT8 c, - IN NODE r - ) -/*++ - -Routine Description: - +/** Create a new child for a given parent node. =20 -Arguments: - - q - the parent node - c - the edge character - r - the child node - -Returns: (VOID) - ---*/ + @param q the parent node + @param c the edge character + @param r the child node +**/ +STATIC +VOID +MakeChild ( + IN NODE q, + IN UINT8 c, + IN NODE r + ) { NODE h, t; =20 @@ -587,24 +530,16 @@ Returns: (VOID) mChildCount[q]++; } =20 -STATIC -VOID -Split ( - NODE Old - ) -/*++ - -Routine Description: - +/** Split a node. =20 -Arguments: - - Old - the node to split - -Returns: (VOID) - ---*/ + @param Old the node to split +**/ +STATIC +VOID +Split ( + NODE Old + ) { NODE New, t; =20 @@ -624,20 +559,12 @@ Returns: (VOID) MakeChild(New, mText[mPos + mMatchLen], mPos); } =20 -STATIC -VOID -InsertNode () -/*++ - -Routine Description: - +/** Insert string info for current position into the String Info Log - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +InsertNode () { NODE q, r, j, t; UINT8 c, *t1, *t2; @@ -739,21 +666,13 @@ Returns: (VOID) =20 } =20 -STATIC -VOID -DeleteNode () -/*++ - -Routine Description: - +/** Delete outdated string info. (The Usage of PERC_FLAG ensures a clean deletion) - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +DeleteNode () { NODE q, r, s, t, u; =20 @@ -813,21 +732,13 @@ Returns: (VOID) mAvail =3D r; } =20 -STATIC -VOID -GetNextMatch () -/*++ - -Routine Description: - +/** Advance the current position (read in new data if needed). Delete outdated string info. Find a match string for current position. - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +GetNextMatch () { INT32 n; =20 @@ -842,23 +753,15 @@ Returns: (VOID) InsertNode(); } =20 -STATIC -EFI_STATUS -Encode () -/*++ - -Routine Description: - +/** The main controlling routine for compression process. =20 -Arguments: (VOID) - -Returns: - - EFI_SUCCESS - The compression is successful - EFI_OUT_0F_RESOURCES - Not enough memory for compression process - ---*/ + @retval EFI_SUCCESS The compression is successful + @retval EFI_OUT_0F_RESOURCES Not enough memory for compression process +**/ +STATIC +EFI_STATUS +Encode () { EFI_STATUS Status; INT32 LastMatchLen; @@ -920,20 +823,12 @@ Arguments: (VOID) return EFI_SUCCESS; } =20 -STATIC -VOID -CountTFreq () -/*++ - -Routine Description: - +/** Count the frequencies for the Extra Set - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +CountTFreq () { INT32 i, k, n, Count; =20 @@ -969,28 +864,20 @@ Returns: (VOID) } } =20 -STATIC -VOID -WritePTLen ( - IN INT32 n, - IN INT32 nbit, - IN INT32 Special - ) -/*++ - -Routine Description: - +/** Outputs the code length array for the Extra Set or the Position Set. =20 -Arguments: - - n - the number of symbols - nbit - the number of bits needed to represent 'n' - Special - the special symbol that needs to be take care of - -Returns: (VOID) - ---*/ + @param n the number of symbols + @param nbit the number of bits needed to represent 'n' + @param Special the special symbol that needs to be take care of +**/ +STATIC +VOID +WritePTLen ( + IN INT32 n, + IN INT32 nbit, + IN INT32 Special + ) { INT32 i, k; =20 @@ -1015,20 +902,12 @@ Returns: (VOID) } } =20 -STATIC -VOID -WriteCLen () -/*++ - -Routine Description: - +/** Outputs the code length array for Char&Length Set - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +WriteCLen () { INT32 i, k, n, Count; =20 @@ -1096,20 +975,12 @@ EncodeP ( } } =20 -STATIC -VOID -SendBlock () -/*++ - -Routine Description: - +/** Huffman code the block and output it. - -Argument: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +SendBlock () { UINT32 i, k, Flags, Root, Pos, Size; Flags =3D 0; @@ -1164,27 +1035,18 @@ Returns: (VOID) } } =20 - -STATIC -VOID -Output ( - IN UINT32 c, - IN UINT32 p - ) -/*++ - -Routine Description: - +/** Outputs an Original Character or a Pointer =20 -Arguments: - - c - The original character or the 'String Length' element of a Point= er - p - The 'Position' field of a Pointer - -Returns: (VOID) - ---*/ + @param c The original character or the 'String Length' element of a = Pointer + @param p The 'Position' field of a Pointer +**/ +STATIC +VOID +Output ( + IN UINT32 c, + IN UINT32 p + ) { STATIC UINT32 CPos; =20 @@ -1263,26 +1125,18 @@ MakeCrcTable () } } =20 -STATIC -VOID -PutBits ( - IN INT32 n, - IN UINT32 x - ) -/*++ - -Routine Description: - +/** Outputs rightmost n bits of x =20 -Arguments: - - n - the rightmost n bits of the data is used - x - the data - -Returns: (VOID) - ---*/ + @param n the rightmost n bits of the data is used + @param x the data +**/ +STATIC +VOID +PutBits ( + IN INT32 n, + IN UINT32 x + ) { UINT8 Temp; =20 @@ -1311,28 +1165,20 @@ Returns: (VOID) } } =20 -STATIC -INT32 -FreadCrc ( - OUT UINT8 *p, - IN INT32 n - ) -/*++ - -Routine Description: - +/** Read in source data =20 -Arguments: - - p - the buffer to hold the data - n - number of bytes to read - -Returns: - - number of bytes actually read - ---*/ + @param p the buffer to hold the data + @param n number of bytes to read + + @return number of bytes actually read +**/ +STATIC +INT32 +FreadCrc ( + OUT UINT8 *p, + IN INT32 n + ) { INT32 i; =20 @@ -1358,24 +1204,16 @@ InitPutBits () mSubBitBuf =3D 0; } =20 -STATIC -VOID -CountLen ( - IN INT32 i - ) -/*++ - -Routine Description: - +/** Count the number of each code length for a Huffman tree. =20 -Arguments: - - i - the top node - -Returns: (VOID) - ---*/ + @param i the top node +**/ +STATIC +VOID +CountLen ( + IN INT32 i + ) { STATIC INT32 Depth =3D 0; =20 @@ -1389,22 +1227,16 @@ Returns: (VOID) } } =20 -STATIC -VOID -MakeLen ( - IN INT32 Root - ) -/*++ - -Routine Description: - +/** Create code length array for a Huffman tree =20 -Arguments: - - Root - the root of the tree - ---*/ + @param Root the root of the tree +**/ +STATIC +VOID +MakeLen ( + IN INT32 Root + ) { INT32 i, k; UINT32 Cum; @@ -1468,28 +1300,20 @@ DownHeap ( mHeap[i] =3D (INT16)k; } =20 -STATIC -VOID -MakeCode ( - IN INT32 n, - IN UINT8 Len[], - OUT UINT16 Code[] - ) -/*++ - -Routine Description: - +/** Assign code to each symbol based on the code length array =20 -Arguments: - - n - number of symbols - Len - the code length array - Code - stores codes for each symbol - -Returns: (VOID) - ---*/ + @param n number of symbols + @param Len the code length array + @param Code stores codes for each symbol +**/ +STATIC +VOID +MakeCode ( + IN INT32 n, + IN UINT8 Len[], + OUT UINT16 Code[] + ) { INT32 i; UINT16 Start[18]; @@ -1503,32 +1327,24 @@ Returns: (VOID) } } =20 -STATIC -INT32 -MakeTree ( - IN INT32 NParm, - IN UINT16 FreqParm[], - OUT UINT8 LenParm[], - OUT UINT16 CodeParm[] - ) -/*++ - -Routine Description: - +/** Generates Huffman codes given a frequency distribution of symbols =20 -Arguments: - - NParm - number of symbols - FreqParm - frequency of each symbol - LenParm - code length for each symbol - CodeParm - code for each symbol - -Returns: - - Root of the Huffman tree. - ---*/ + @param NParm number of symbols + @param FreqParm frequency of each symbol + @param LenParm code length for each symbol + @param CodeParm code for each symbol + + @return Root of the Huffman tree. +**/ +STATIC +INT32 +MakeTree ( + IN INT32 NParm, + IN UINT16 FreqParm[], + OUT UINT8 LenParm[], + OUT UINT16 CodeParm[] + ) { INT32 i, j, k, Avail; =20 diff --git a/BaseTools/Source/C/Common/EfiUtilityMsgs.c b/BaseTools/Source/= C/Common/EfiUtilityMsgs.c index f8d2a40be1e1..89524550884a 100644 --- a/BaseTools/Source/C/Common/EfiUtilityMsgs.c +++ b/BaseTools/Source/C/Common/EfiUtilityMsgs.c @@ -36,65 +36,59 @@ PrintLimitExceeded ( VOID ); =20 -VOID -Error ( - CHAR8 *FileName, - UINT32 LineNumber, - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Prints an error message. =20 -Arguments: All arguments are optional, though the printed message may be useless if at least something valid is not specified. +=20 + @note: + We print the following (similar to the Warn() and Debug() + W + Typical error/warning message format: =20 - FileName - name of the file or application. If not specified, then the + bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : functi= on does not take 2 parameters + + BUGBUG -- these three utility functions are almost identical, and + should be modified to share code. + + Visual Studio does not find error messages with: + + " error :" + " error 1:" + " error c1:" + " error 1000:" + " error c100:" + + It does find: + " error c1000:" + + @param FileName name of the file or application. If not specified, then = the utility name (as set by the utility calling SetUtilityName() earlier) is used. Otherwise "Unknown utility" is used. =20 - LineNumber - the line number of error, typically used by parsers. If the + @param LineNumber the line number of error, typically used by parsers. I= f the utility is not a parser, then 0 should be specified. Otherw= ise the FileName and LineNumber info can be used to cause MS Visual Studio to jump to the error. =20 - MessageCode - an application-specific error code that can be referenced = in + @param MessageCode an application-specific error code that can be refere= nced in other documentation. =20 - Text - the text in question, typically used by parsers. + @param Text the text in question, typically used by parsers. =20 - MsgFmt - the format string for the error message. Can contain formatting + @param MsgFmt the format string for the error message. Can contain forma= tting controls for use with the varargs. - -Returns: - None. - -Notes: - We print the following (similar to the Warn() and Debug() - W - Typical error/warning message format: - - bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : functio= n does not take 2 parameters - - BUGBUG -- these three utility functions are almost identical, and - should be modified to share code. - - Visual Studio does not find error messages with: - - " error :" - " error 1:" - " error c1:" - " error 1000:" - " error c100:" - - It does find: - " error c1000:" ---*/ +**/ +VOID +Error ( + CHAR8 *FileName, + UINT32 LineNumber, + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + ... + ) { va_list List; // @@ -127,28 +121,21 @@ Routine Description: va_end (List); } =20 -VOID -ParserError ( - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Print a parser error, using the source file name and line number set by a previous call to SetParserPosition(). =20 -Arguments: - MessageCode - application-specific error code - Text - text to print in the error message - MsgFmt - format string to print at the end of the error message - -Returns: - NA - ---*/ + @param MessageCode application-specific error code + @param Text text to print in the error message + @param MsgFmt format string to print at the end of the error mess= age +**/ +VOID +ParserError ( + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + ... + ) { va_list List; // @@ -181,6 +168,14 @@ Routine Description: va_end (List); } =20 +/** + Print a parser warning, using the source file name and line number + set by a previous call to SetParserPosition(). + + @param ErrorCode application-specific error code + @param OffendingText text to print in the warning message + @param MsgFmt format string to print at the end of the warning me= ssage +**/ VOID ParserWarning ( UINT32 ErrorCode, @@ -188,21 +183,6 @@ ParserWarning ( CHAR8 *MsgFmt, ... ) -/*++ - -Routine Description: - Print a parser warning, using the source file name and line number - set by a previous call to SetParserPosition(). - -Arguments: - ErrorCode - application-specific error code - OffendingText - text to print in the warning message - MsgFmt - format string to print at the end of the warning message - -Returns: - NA - ---*/ { va_list List; // @@ -241,39 +221,28 @@ Routine Description: // } } =20 -VOID -Warning ( - CHAR8 *FileName, - UINT32 LineNumber, - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Print a warning message. =20 -Arguments: - FileName - name of the file where the warning was detected, or the na= me - of the application that detected the warning - - LineNumber - the line number where the warning was detected (parsers). - 0 should be specified if the utility is not a parser. - - MessageCode - an application-specific warning code that can be reference= d in - other documentation. - - Text - the text in question (parsers) - - MsgFmt - the format string for the warning message. Can contain for= matting - controls for use with varargs. - -Returns: - None. - ---*/ + @param FileName name of the file where the warning was detected, or t= he name + of the application that detected the warning + @param LineNumber the line number where the warning was detected (parse= rs). + 0 should be specified if the utility is not a parser. + @param MessageCode an application-specific warning code that can be refe= renced in + other documentation. + @param Text the text in question (parsers) + @param MsgFmt the format string for the warning message. Can contai= n formatting + controls for use with varargs. +**/ +VOID +Warning ( + CHAR8 *FileName, + UINT32 LineNumber, + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + ... + ) { va_list List; =20 @@ -313,6 +282,18 @@ Routine Description: va_end (List); } =20 +/** + Print a Debug message. +=20 + @param FileName typically the name of the utility printing the debug = message, but + can be the name of a file being parsed. + @param LineNumber the line number in FileName (parsers) + @param MsgLevel Debug message print level (0~9) + @param Text the text in question (parsers) + @param MsgFmt the format string for the debug message. Can contain = formatting + controls for use with varargs. + +**/ VOID DebugMsg ( CHAR8 *FileName, @@ -322,28 +303,6 @@ DebugMsg ( CHAR8 *MsgFmt, ... ) -/*++ - -Routine Description: - Print a Debug message. - -Arguments: - FileName - typically the name of the utility printing the debug messa= ge, but - can be the name of a file being parsed. - - LineNumber - the line number in FileName (parsers) - - MsgLevel - Debug message print level (0~9) - - Text - the text in question (parsers) - - MsgFmt - the format string for the debug message. Can contain forma= tting - controls for use with varargs. - -Returns: - None. - ---*/ { va_list List; // @@ -358,64 +317,52 @@ Routine Description: va_end (List); } =20 -VOID -PrintMessage ( - CHAR8 *Type, - CHAR8 *FileName, - UINT32 LineNumber, - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - va_list List - ) -/*++ - -Routine Description: +/** Worker routine for all the utility printing services. Prints the message= in a format that Visual Studio will find when scanning build outputs for errors or warnings. +=20 + @note: + If FileName =3D=3D NULL then this utility will use the string passed in= to SetUtilityName(). =20 -Arguments: - Type - "warning" or "error" string to insert into the message to = be + LineNumber is only used if the caller is a parser, in which case FileNa= me refers to the + file being parsed. + + Text and MsgFmt are both optional, though it would be of little use cal= ling this function with + them both NULL. + + Output will typically be of the form: + () : : : + + Parser (LineNumber !=3D 0) + VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function= does not take 2 parameters + Generic utility (LineNumber =3D=3D 0) + UtilityName : error E1234 : Text string : MsgFmt string and args + + @param Type "warning" or "error" string to insert into the messag= e to be printed. The first character of this string (converted to = uppercase) is used to precede the MessageCode value in the output str= ing. - - FileName - name of the file where the warning was detected, or the na= me + @param FileName name of the file where the warning was detected, or t= he name of the application that detected the warning - - LineNumber - the line number where the warning was detected (parsers). + @param LineNumber the line number where the warning was detected (parse= rs). 0 should be specified if the utility is not a parser. - - MessageCode - an application-specific warning code that can be reference= d in + @param MessageCode an application-specific warning code that can be refe= renced in other documentation. - - Text - part of the message to print - - MsgFmt - the format string for the message. Can contain formatting + @param Text part of the message to print + @param MsgFmt the format string for the message. Can contain format= ting controls for use with varargs. - List - the variable list. - -Returns: - None. - -Notes: - If FileName =3D=3D NULL then this utility will use the string passed int= o SetUtilityName(). - - LineNumber is only used if the caller is a parser, in which case FileNam= e refers to the - file being parsed. - - Text and MsgFmt are both optional, though it would be of little use call= ing this function with - them both NULL. - - Output will typically be of the form: - () : : : - - Parser (LineNumber !=3D 0) - VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function = does not take 2 parameters - Generic utility (LineNumber =3D=3D 0) - UtilityName : error E1234 : Text string : MsgFmt string and args - ---*/ + @param List the variable list. +**/ +VOID +PrintMessage ( + CHAR8 *Type, + CHAR8 *FileName, + UINT32 LineNumber, + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + va_list List + ) { CHAR8 Line[MAX_LINE_LEN]; CHAR8 Line2[MAX_LINE_LEN]; @@ -523,24 +470,19 @@ Routine Description: =20 } =20 -STATIC -VOID -PrintSimpleMessage ( - CHAR8 *MsgFmt, - va_list List - ) -/*++ -Routine Description: +/** Print message into stdout. =20 -Arguments: - MsgFmt - the format string for the message. Can contain formatting - controls for use with varargs. - List - the variable list. - -Returns: - None. ---*/ + @param MsgFmt the format string for the message. Can contain format= ting + controls for use with varargs. + @param List the variable list. +**/ +STATIC +VOID +PrintSimpleMessage ( + CHAR8 *MsgFmt, + va_list List + ) { CHAR8 Line[MAX_LINE_LEN]; // @@ -552,51 +494,37 @@ Routine Description: } } =20 +/** + Set the position in a file being parsed. This can be used to + print error messages deeper down in a parser. + + @param SourceFileName name of the source file being parsed + @param LineNum line number of the source file being parsed +**/ VOID ParserSetPosition ( CHAR8 *SourceFileName, UINT32 LineNum ) -/*++ - -Routine Description: - Set the position in a file being parsed. This can be used to - print error messages deeper down in a parser. - -Arguments: - SourceFileName - name of the source file being parsed - LineNum - line number of the source file being parsed - -Returns: - NA - ---*/ { mSourceFileName =3D SourceFileName; mSourceFileLineNum =3D LineNum; } =20 -VOID -SetUtilityName ( - CHAR8 *UtilityName - ) -/*++ - -Routine Description: +/** All printed error/warning/debug messages follow the same format, and typically will print a filename or utility name followed by the error text. However if a filename is not passed to the print routines, then they'll print the utility name if you call this function early in your app to set the utility name. =20 -Arguments: - UtilityName - name of the utility, which will be printed with all - error/warning/debug messages. - -Returns: - NA - ---*/ + @param UtilityName name of the utility, which will be printed with all + error/warning/debug messages. +**/ +VOID +SetUtilityName ( + CHAR8 *UtilityName + ) { // // Save the name of the utility in our local variable. Make sure its @@ -613,69 +541,48 @@ Routine Description: } } =20 -STATUS -GetUtilityStatus ( - VOID - ) -/*++ - -Routine Description: +/** When you call Error() or Warning(), this module keeps track of it and sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility exits, it can call this function to get the status and use it as a return value. =20 -Arguments: - None. - -Returns: - Worst-case status reported, as defined by which print function was calle= d. - ---*/ + @return Worst-case status reported, as defined by which print function w= as called. +**/ +STATUS +GetUtilityStatus ( + VOID + ) { return mStatus; } =20 -VOID -SetPrintLevel ( - UINT64 LogLevel - ) -/*++ - -Routine Description: +/** Set the printing message Level. This is used by the PrintMsg() function to determine when/if a message should be printed. =20 -Arguments: - LogLevel - 0~50 to specify the different level message. - -Returns: - NA - ---*/ + @param LogLevel 0~50 to specify the different level message. +**/ +VOID +SetPrintLevel ( + UINT64 LogLevel + ) { mPrintLogLevel =3D LogLevel; } =20 -VOID -VerboseMsg ( - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Print a verbose level message. =20 -Arguments: - MsgFmt - the format string for the message. Can contain formatting - controls for use with varargs. - List - the variable list. - -Returns: - NA - ---*/ + @param MsgFmt the format string for the message. Can contain format= ting + controls for use with varargs. + @param List the variable list. +**/ +VOID +VerboseMsg ( + CHAR8 *MsgFmt, + ... + ) { va_list List; // @@ -690,25 +597,18 @@ Routine Description: va_end (List); } =20 -VOID -NormalMsg ( - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Print a default level message. =20 -Arguments: - MsgFmt - the format string for the message. Can contain formatting - controls for use with varargs. - List - the variable list. - -Returns: - NA - ---*/ + @param MsgFmt the format string for the message. Can contain format= ting + controls for use with varargs. + @param List the variable list. +**/ +VOID +NormalMsg ( + CHAR8 *MsgFmt, + ... + ) { va_list List; // @@ -723,25 +623,18 @@ Routine Description: va_end (List); } =20 -VOID -KeyMsg ( - CHAR8 *MsgFmt, - ... - ) -/*++ - -Routine Description: +/** Print a key level message. =20 -Arguments: - MsgFmt - the format string for the message. Can contain formatting - controls for use with varargs. - List - the variable list. - -Returns: - NA - ---*/ + @param MsgFmt the format string for the message. Can contain format= ting + controls for use with varargs. + @param List the variable list. +**/ +VOID +KeyMsg ( + CHAR8 *MsgFmt, + ... + ) { va_list List; // @@ -756,28 +649,21 @@ Routine Description: va_end (List); } =20 +/** + Set the limits of how many errors, warnings, and errors+warnings + we will print. + + @param MaxErrors maximum number of error messages to print + @param MaxWarnings maximum number of warning messages to print + @param MaxWarningsPlusErrors + maximum number of errors+warnings to print +**/ VOID SetPrintLimits ( UINT32 MaxErrors, UINT32 MaxWarnings, UINT32 MaxWarningsPlusErrors ) -/*++ - -Routine Description: - Set the limits of how many errors, warnings, and errors+warnings - we will print. - -Arguments: - MaxErrors - maximum number of error messages to print - MaxWarnings - maximum number of warning messages to print - MaxWarningsPlusErrors - - maximum number of errors+warnings to print - -Returns: - NA - ---*/ { mMaxErrors =3D MaxErrors; mMaxWarnings =3D MaxWarnings; diff --git a/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c b/BaseTools/S= ource/C/Common/FirmwareVolumeBuffer.c index ace26eb71c6b..3fae6f901da0 100644 --- a/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c +++ b/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c @@ -78,29 +78,21 @@ FvBufCalculateChecksum8 ( // Procedures start // =20 +/** + Clears out all files from the Fv buffer in memory + + @param SourceFv Address of the Fv in memory, this firmware volume will + be modified, if SourceFfsFile exists + @param SourceFfsFile Input FFS file to replace + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND +**/ EFI_STATUS FvBufRemoveFileNew ( IN OUT VOID *Fv, IN EFI_GUID *Name ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - SourceFv - Address of the Fv in memory, this firmware volume will - be modified, if SourceFfsFile exists - SourceFfsFile - Input FFS file to replace - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - ---*/ { EFI_STATUS Status; EFI_FFS_FILE_HEADER* FileToRm; @@ -127,30 +119,21 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Clears out all files from the Fv buffer in memory =20 + @param SourceFv Address of the Fv in memory, this firmware volume will + be modified, if SourceFfsFile exists + @param SourceFfsFile Input FFS file to replace + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND +**/ EFI_STATUS FvBufRemoveFile ( IN OUT VOID *Fv, IN EFI_GUID *Name ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - SourceFv - Address of the Fv in memory, this firmware volume will - be modified, if SourceFfsFile exists - SourceFfsFile - Input FFS file to replace - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - ---*/ { EFI_STATUS Status; EFI_FFS_FILE_HEADER *NextFile; @@ -216,27 +199,18 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Clears out all files from the Fv buffer in memory =20 + @param SourceFfsFile Input FFS file to update the checksum for + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND +**/ EFI_STATUS FvBufChecksumFile ( IN OUT VOID *FfsFile ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - SourceFfsFile - Input FFS file to update the checksum for - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - ---*/ { EFI_FFS_FILE_HEADER* File =3D (EFI_FFS_FILE_HEADER*)FfsFile; EFI_FFS_FILE_STATE StateBackup; @@ -272,29 +246,20 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Clears out all files from the Fv buffer in memory =20 + @param SourceFv Address of the Fv in memory, this firmware volume will + be modified, if SourceFfsFile exists + @param SourceFfsFile Input FFS file to replace + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND +**/ EFI_STATUS FvBufChecksumHeader ( IN OUT VOID *Fv ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - SourceFv - Address of the Fv in memory, this firmware volume will - be modified, if SourceFfsFile exists - SourceFfsFile - Input FFS file to replace - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - ---*/ { EFI_FIRMWARE_VOLUME_HEADER* FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; =20 @@ -308,31 +273,22 @@ Routine Description: return EFI_SUCCESS; } =20 - -EFI_STATUS -FvBufDuplicate ( - IN VOID *SourceFv, - IN OUT VOID **DestinationFv - ) -/*++ - -Routine Description: - +/** Clears out all files from the Fv buffer in memory =20 -Arguments: - - SourceFv - Address of the Fv in memory - DestinationFv - Output for destination Fv + @param SourceFv - Address of the Fv in memory + @param DestinationFv - Output for destination Fv DestinationFv =3D=3D NULL - invalid parameter *DestinationFv =3D=3D NULL - memory will be allocated *DestinationFv !=3D NULL - this address will be the destination =20 -Returns: - - EFI_SUCCESS - ---*/ + @retval EFI_SUCCESS +**/ +EFI_STATUS +FvBufDuplicate ( + IN VOID *SourceFv, + IN OUT VOID **DestinationFv + ) { EFI_STATUS Status; UINTN size; @@ -358,35 +314,26 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Extends a firmware volume by the given number of bytes. =20 + BUGBUG: Does not handle the case where the firmware volume has a + VTF (Volume Top File). The VTF will not be moved to the + end of the extended FV. + + @param Fv Source and destination firmware volume. + Note: The original firmware volume buffer is freed! + + @param Size The minimum size that the firmware volume is to be extended = by. + The FV may be extended more than this size. + + @retval EFI_SUCCESS +**/ EFI_STATUS FvBufExtend ( IN VOID **Fv, IN UINTN Size ) -/*++ - -Routine Description: - - Extends a firmware volume by the given number of bytes. - - BUGBUG: Does not handle the case where the firmware volume has a - VTF (Volume Top File). The VTF will not be moved to the - end of the extended FV. - -Arguments: - - Fv - Source and destination firmware volume. - Note: The original firmware volume buffer is freed! - - Size - The minimum size that the firmware volume is to be extended by. - The FV may be extended more than this size. - -Returns: - - EFI_SUCCESS - ---*/ { EFI_STATUS Status; UINTN OldSize; @@ -469,27 +416,17 @@ Routine Description: =20 } =20 +/** + Clears out all files from the Fv buffer in memory =20 + @param Fv Address of the Fv in memory + + @retval EFI_SUCCESS +**/ EFI_STATUS FvBufClearAllFiles ( IN OUT VOID *Fv ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - Fv - Address of the Fv in memory - -Returns: - - EFI_SUCCESS - ---*/ - { EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; EFI_STATUS Status; @@ -509,28 +446,18 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Clears out all files from the Fv buffer in memory =20 + @param Fv Address of the Fv in memory + + @retval EFI_SUCCESS +**/ EFI_STATUS FvBufGetSize ( IN VOID *Fv, OUT UINTN *Size ) -/*++ - -Routine Description: - - Clears out all files from the Fv buffer in memory - -Arguments: - - Fv - Address of the Fv in memory - -Returns: - - EFI_SUCCESS - ---*/ - { EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; @@ -554,28 +481,19 @@ Routine Description: return EFI_SUCCESS; } =20 - -EFI_STATUS -FvBufAddFile ( - IN OUT VOID *Fv, - IN VOID *File - ) -/*++ - -Routine Description: - +/** Adds a new FFS file =20 -Arguments: - - Fv - Address of the Fv in memory - File - FFS file to add to Fv - -Returns: - - EFI_SUCCESS - ---*/ + @param Fv Address of the Fv in memory + @param File FFS file to add to Fv + + @retval EFI_SUCCESS +**/ +EFI_STATUS +FvBufAddFile ( + IN OUT VOID *Fv, + IN VOID *File + ) { EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; =20 @@ -652,32 +570,23 @@ Routine Description: return EFI_SUCCESS; } =20 - -EFI_STATUS -FvBufAddFileWithExtend ( - IN OUT VOID **Fv, - IN VOID *File - ) -/*++ - -Routine Description: - +/** Adds a new FFS file. Extends the firmware volume if needed. =20 -Arguments: - - Fv - Source and destination firmware volume. - Note: If the FV is extended, then the original firmware volume + @param Fv Source and destination firmware volume. + Note: If the FV is extended, then the original firmware volume buffer is freed! =20 - Size - The minimum size that the firmware volume is to be extended by. - The FV may be extended more than this size. + @param Size The minimum size that the firmware volume is to be extended = by. + The FV may be extended more than this size. =20 -Returns: - - EFI_SUCCESS - ---*/ + @retval EFI_SUCCESS +**/ +EFI_STATUS +FvBufAddFileWithExtend ( + IN OUT VOID **Fv, + IN VOID *File + ) { EFI_STATUS Status; EFI_FFS_FILE_HEADER* NewFile; @@ -706,29 +615,20 @@ Routine Description: return Status; } =20 - -EFI_STATUS -FvBufAddVtfFile ( - IN OUT VOID *Fv, - IN VOID *File - ) -/*++ - -Routine Description: - +/** Adds a new FFS VFT (Volume Top File) file. In other words, adds the file to the end of the firmware volume. =20 -Arguments: - - Fv - Address of the Fv in memory - File - FFS file to add to Fv - -Returns: - - EFI_SUCCESS - ---*/ + @param Fv Address of the Fv in memory + @param File FFS file to add to Fv + + @retval EFI_SUCCESS +**/ +EFI_STATUS +FvBufAddVtfFile ( + IN OUT VOID *Fv, + IN VOID *File + ) { EFI_STATUS Status; =20 @@ -811,52 +711,35 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Expands the 3 byte size commonly used in Firmware Volume data structures =20 + @param Size Address of the 3 byte array representing the size + + @return UINT32 +**/ VOID FvBufCompact3ByteSize ( OUT VOID* SizeDest, IN UINT32 Size ) -/*++ - -Routine Description: - - Expands the 3 byte size commonly used in Firmware Volume data structures - -Arguments: - - Size - Address of the 3 byte array representing the size - -Returns: - - UINT32 - ---*/ { ((UINT8*)SizeDest)[0] =3D (UINT8)Size; ((UINT8*)SizeDest)[1] =3D (UINT8)(Size >> 8); ((UINT8*)SizeDest)[2] =3D (UINT8)(Size >> 16); } =20 -UINT32 -FvBufGetFfsFileSize ( - IN EFI_FFS_FILE_HEADER *Ffs - ) -/*++ - -Routine Description: - +/** Get the FFS file size. =20 -Arguments: - - Ffs - Pointer to FFS header - -Returns: - - UINT32 - ---*/ + @param Ffs Pointer to FFS header + + @return UINT32 +**/ +UINT32 +FvBufGetFfsFileSize ( + IN EFI_FFS_FILE_HEADER *Ffs + ) { if (Ffs =3D=3D NULL) { return 0; @@ -867,25 +750,17 @@ Routine Description: return FvBufExpand3ByteSize(Ffs->Size); } =20 -UINT32 -FvBufGetFfsHeaderSize ( - IN EFI_FFS_FILE_HEADER *Ffs - ) -/*++ - -Routine Description: - +/** Get the FFS header size. =20 -Arguments: - - Ffs - Pointer to FFS header - -Returns: - - UINT32 - ---*/ + @param Ffs Pointer to FFS header + + @return UINT32 +**/ +UINT32 +FvBufGetFfsHeaderSize ( + IN EFI_FFS_FILE_HEADER *Ffs + ) { if (Ffs =3D=3D NULL) { return 0; @@ -896,60 +771,44 @@ Routine Description: return sizeof(EFI_FFS_FILE_HEADER); } =20 +/** + Expands the 3 byte size commonly used in Firmware Volume data structures + + @param Size Address of the 3 byte array representing the size + + @return UINT32 +**/ UINT32 FvBufExpand3ByteSize ( IN VOID* Size ) -/*++ - -Routine Description: - - Expands the 3 byte size commonly used in Firmware Volume data structures - -Arguments: - - Size - Address of the 3 byte array representing the size - -Returns: - - UINT32 - ---*/ { return (((UINT8*)Size)[2] << 16) + (((UINT8*)Size)[1] << 8) + ((UINT8*)Size)[0]; } =20 -EFI_STATUS -FvBufFindNextFile ( - IN VOID *Fv, - IN OUT UINTN *Key, - OUT VOID **File - ) -/*++ - -Routine Description: - +/** Iterates through the files contained within the firmware volume =20 -Arguments: - - Fv - Address of the Fv in memory - Key - Should be 0 to get the first file. After that, it should be - passed back in without modifying its contents to retrieve - subsequent files. - File - Output file pointer + @param Fv Address of the Fv in memory + @param Key Should be 0 to get the first file. After that, it should be + passed back in without modifying its contents to retrieve + subsequent files. + @param File Output file pointer File =3D=3D NULL - invalid parameter otherwise - *File will be update to the location of the file =20 -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ +EFI_STATUS +FvBufFindNextFile ( + IN VOID *Fv, + IN OUT UINTN *Key, + OUT VOID **File + ) { EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; =20 @@ -1028,35 +887,26 @@ Routine Description: return EFI_NOT_FOUND; } =20 - -EFI_STATUS -FvBufFindFileByName ( - IN VOID *Fv, - IN EFI_GUID *Name, - OUT VOID **File - ) -/*++ - -Routine Description: - +/** Searches the Fv for a file by its name =20 -Arguments: - - Fv - Address of the Fv in memory - Name - Guid filename to search for in the firmware volume - File - Output file pointer + @param Fv Address of the Fv in memory + @param Name Guid filename to search for in the firmware volume + @param File Output file pointer File =3D=3D NULL - Only determine if the file exists, based on return value from the function call. otherwise - *File will be update to the location of the file =20 -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ +EFI_STATUS +FvBufFindFileByName ( + IN VOID *Fv, + IN EFI_GUID *Name, + OUT VOID **File + ) { EFI_STATUS Status; UINTN Key; @@ -1080,35 +930,26 @@ Routine Description: return EFI_NOT_FOUND; } =20 - -EFI_STATUS -FvBufFindFileByType ( - IN VOID *Fv, - IN EFI_FV_FILETYPE Type, - OUT VOID **File - ) -/*++ - -Routine Description: - +/** Searches the Fv for a file by its type =20 -Arguments: - - Fv - Address of the Fv in memory - Type - FFS FILE type to search for - File - Output file pointer + @param Fv Address of the Fv in memory + @param Type FFS FILE type to search for + @param File Output file pointer (File =3D=3D NULL) -> Only determine if the file exists, based on retu= rn value from the function call. otherwise -> *File will be update to the location of the file =20 -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ +EFI_STATUS +FvBufFindFileByType ( + IN VOID *Fv, + IN EFI_FV_FILETYPE Type, + OUT VOID **File + ) { EFI_STATUS Status; UINTN Key; @@ -1132,34 +973,25 @@ Routine Description: return EFI_NOT_FOUND; } =20 +/** + Searches the requested file for raw data. =20 + This routine either returns all the payload of a EFI_FV_FILETYPE_RAW fil= e, + or finds the EFI_SECTION_RAW section within the file and returns its dat= a. + + @param FfsFile Address of the FFS file in memory + @param RawData Pointer to the raw data within the file + (This is NOT allocated. It is within the file.) + @param RawDataSize Size of the raw data within the file + + @return EFI_STATUS +**/ EFI_STATUS FvBufGetFileRawData ( IN VOID* FfsFile, OUT VOID** RawData, OUT UINTN* RawDataSize ) -/*++ - -Routine Description: - - Searches the requested file for raw data. - - This routine either returns all the payload of a EFI_FV_FILETYPE_RAW fil= e, - or finds the EFI_SECTION_RAW section within the file and returns its dat= a. - -Arguments: - - FfsFile - Address of the FFS file in memory - RawData - Pointer to the raw data within the file - (This is NOT allocated. It is within the file.) - RawDataSize - Size of the raw data within the file - -Returns: - - EFI_STATUS - ---*/ { EFI_STATUS Status; EFI_FFS_FILE_HEADER* File; @@ -1195,7 +1027,19 @@ Routine Description: =20 } =20 +/** + Packages up a FFS file containing the input raw data. =20 + The file created will have a type of EFI_FV_FILETYPE_FREEFORM, and will + contain one EFI_FV_FILETYPE_RAW section. + + @param RawData Pointer to the raw data to be packed + @param RawDataSize Size of the raw data to be packed + @param FfsFile Address of the packaged FFS file. + Note: The called must deallocate this memory! + + @return EFI_STATUS +**/ EFI_STATUS FvBufPackageFreeformRawFile ( IN EFI_GUID* Filename, @@ -1203,27 +1047,6 @@ FvBufPackageFreeformRawFile ( IN UINTN RawDataSize, OUT VOID** FfsFile ) -/*++ - -Routine Description: - - Packages up a FFS file containing the input raw data. - - The file created will have a type of EFI_FV_FILETYPE_FREEFORM, and will - contain one EFI_FV_FILETYPE_RAW section. - -Arguments: - - RawData - Pointer to the raw data to be packed - RawDataSize - Size of the raw data to be packed - FfsFile - Address of the packaged FFS file. - Note: The called must deallocate this memory! - -Returns: - - EFI_STATUS - ---*/ { EFI_FFS_FILE_HEADER* NewFile; UINT32 NewFileSize; @@ -1304,7 +1127,22 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Iterates through the sections contained within a given array of sections =20 + @param SectionsStart Address of the start of the FFS sections array + @param TotalSectionsSize Total size of all the sections + @param Key Should be 0 to get the first section. After that, it should = be + passed back in without modifying its contents to retrieve + subsequent files. + @param Section Output section pointer + (Section =3D=3D NULL) -> invalid parameter + otherwise -> *Section will be update to the location of the file + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ EFI_STATUS FvBufFindNextSection ( IN VOID *SectionsStart, @@ -1312,30 +1150,6 @@ FvBufFindNextSection ( IN OUT UINTN *Key, OUT VOID **Section ) -/*++ - -Routine Description: - - Iterates through the sections contained within a given array of sections - -Arguments: - - SectionsStart - Address of the start of the FFS sections array - TotalSectionsSize - Total size of all the sections - Key - Should be 0 to get the first section. After that, it should be - passed back in without modifying its contents to retrieve - subsequent files. - Section - Output section pointer - (Section =3D=3D NULL) -> invalid parameter - otherwise -> *Section will be update to the location of the file - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ { EFI_COMMON_SECTION_HEADER *sectionHdr; UINTN sectionSize; @@ -1363,31 +1177,22 @@ Routine Description: =20 } =20 +/** + Searches the FFS file and counts the number of sections found. + The sections are NOT recursed. =20 + @param FfsFile Address of the FFS file in memory + @param Count The location to store the section count in + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ EFI_STATUS FvBufCountSections ( IN VOID* FfsFile, IN UINTN* Count ) -/*++ - -Routine Description: - - Searches the FFS file and counts the number of sections found. - The sections are NOT recursed. - -Arguments: - - FfsFile - Address of the FFS file in memory - Count - The location to store the section count in - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ { EFI_STATUS Status; UINTN Key; @@ -1424,35 +1229,26 @@ Routine Description: return EFI_NOT_FOUND; } =20 +/** + Searches the FFS file for a section by its type =20 + @param FfsFile Address of the FFS file in memory + @param Type FFS FILE section type to search for + @param Section Output section pointer + (Section =3D=3D NULL) -> Only determine if the section exists, based o= n return + value from the function call. + otherwise -> *Section will be update to the location of the file + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ EFI_STATUS FvBufFindSectionByType ( IN VOID *FfsFile, IN UINT8 Type, OUT VOID **Section ) -/*++ - -Routine Description: - - Searches the FFS file for a section by its type - -Arguments: - - FfsFile - Address of the FFS file in memory - Type - FFS FILE section type to search for - Section - Output section pointer - (Section =3D=3D NULL) -> Only determine if the section exists, based o= n return - value from the function call. - otherwise -> *Section will be update to the location of the file - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ { EFI_STATUS Status; UINTN Key; @@ -1487,30 +1283,21 @@ Routine Description: return EFI_NOT_FOUND; } =20 +/** + Shrinks a firmware volume (in place) to provide a minimal FV. =20 + BUGBUG: Does not handle the case where the firmware volume has a + VTF (Volume Top File). The VTF will not be moved to the + end of the extended FV. + + @param Fv Firmware volume. + =20 + @retval EFI_SUCCESS +**/ EFI_STATUS FvBufShrinkWrap ( IN VOID *Fv ) -/*++ - -Routine Description: - - Shrinks a firmware volume (in place) to provide a minimal FV. - - BUGBUG: Does not handle the case where the firmware volume has a - VTF (Volume Top File). The VTF will not be moved to the - end of the extended FV. - -Arguments: - - Fv - Firmware volume. - -Returns: - - EFI_SUCCESS - ---*/ { EFI_STATUS Status; UINTN OldSize; @@ -1569,32 +1356,23 @@ Routine Description: =20 } =20 +/** + Searches the FFS file for a section by its type =20 + @param Fv Address of the Fv in memory + @param BlockSize The size of the blocks to convert the Fv to. If the to= tal size + of the Fv is not evenly divisible by this size, then + EFI_INVALID_PARAMETER will be returned. + + @retval EFI_SUCCESS + @retval EFI_NOT_FOUND + @retval EFI_VOLUME_CORRUPTED +**/ EFI_STATUS FvBufUnifyBlockSizes ( IN OUT VOID *Fv, IN UINTN BlockSize ) -/*++ - -Routine Description: - - Searches the FFS file for a section by its type - -Arguments: - - Fv - Address of the Fv in memory - BlockSize - The size of the blocks to convert the Fv to. If the total s= ize - of the Fv is not evenly divisible by this size, then - EFI_INVALID_PARAMETER will be returned. - -Returns: - - EFI_SUCCESS - EFI_NOT_FOUND - EFI_VOLUME_CORRUPTED - ---*/ { EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; @@ -1641,28 +1419,20 @@ Routine Description: return EFI_SUCCESS; } =20 -STATIC -UINT16 -FvBufCalculateSum16 ( - IN UINT16 *Buffer, - IN UINTN Size - ) -/*++ - -Routine Description: - +/** This function calculates the UINT16 sum for the requested region. =20 -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 16 bit checksum - ---*/ + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 16 bit checksum +**/ +STATIC +UINT16 +FvBufCalculateSum16 ( + IN UINT16 *Buffer, + IN UINTN Size + ) { UINTN Index; UINT16 Sum; @@ -1679,56 +1449,38 @@ Routine Description: return (UINT16) Sum; } =20 - -STATIC -UINT16 -FvBufCalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size - ) -/*++ - -Routine Description:: - +/** This function calculates the value needed for a valid UINT16 checksum =20 -Arguments: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Returns: - - The 16 bit checksum value needed. - ---*/ + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 16 bit checksum value needed. +**/ +STATIC +UINT16 +FvBufCalculateChecksum16 ( + IN UINT16 *Buffer, + IN UINTN Size + ) { return (UINT16)(0x10000 - FvBufCalculateSum16 (Buffer, Size)); } =20 +/** + This function calculates the UINT8 sum for the requested region. =20 + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer +=20 + @return The 8 bit checksum value needed. +**/ STATIC UINT8 FvBufCalculateSum8 ( IN UINT8 *Buffer, IN UINTN Size ) -/*++ - -Description: - - This function calculates the UINT8 sum for the requested region. - -Input: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Return: - - The 8 bit checksum value needed. - ---*/ { UINTN Index; UINT8 Sum; @@ -1745,29 +1497,20 @@ FvBufCalculateSum8 ( return Sum; } =20 - -STATIC -UINT8 -FvBufCalculateChecksum8 ( - IN UINT8 *Buffer, - IN UINTN Size - ) -/*++ - -Description: - +/** This function calculates the value needed for a valid UINT8 checksum =20 -Input: - - Buffer Pointer to buffer containing byte data of component. - Size Size of the buffer - -Return: - - The 8 bit checksum value needed. - ---*/ + @param Buffer Pointer to buffer containing byte data of component. + @param Size Size of the buffer + + @return The 8 bit checksum value needed. +**/ +STATIC +UINT8 +FvBufCalculateChecksum8 ( + IN UINT8 *Buffer, + IN UINTN Size + ) { return (UINT8)(0x100 - FvBufCalculateSum8 (Buffer, Size)); } diff --git a/BaseTools/Source/C/Common/FvLib.c b/BaseTools/Source/C/Common/= FvLib.c index 82dc557bb7db..37631f470f2a 100644 --- a/BaseTools/Source/C/Common/FvLib.c +++ b/BaseTools/Source/C/Common/FvLib.c @@ -22,29 +22,22 @@ UINT32 mFvLength =3D 0; // // External function implementations // + +/** + This initializes the FV lib with a pointer to the FV and length. It doe= s not + verify the FV in any way. + + @param Fv Buffer containing the FV. + @param FvLength Length of the FV + + @retval EFI_SUCCESS Function Completed successfully. + @retval EFI_INVALID_PARAMETER A required parameter was NULL. +**/ EFI_STATUS InitializeFvLib ( IN VOID *Fv, IN UINT32 FvLength ) -/*++ - -Routine Description: - - This initializes the FV lib with a pointer to the FV and length. It doe= s not - verify the FV in any way. - -Arguments: - - Fv Buffer containing the FV. - FvLength Length of the FV - -Returns: - - EFI_SUCCESS Function Completed successfully. - EFI_INVALID_PARAMETER A required parameter was NULL. - ---*/ { // // Verify input arguments @@ -59,29 +52,21 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function returns a pointer to the current FV and the size. + + @param FvHeader Pointer to the FV buffer. + @param FvLength Length of the FV + + @retval EFI_SUCCESS Function Completed successfully. + @retval EFI_INVALID_PARAMETER A required parameter was NULL. + @retvalEFI_ABORTED The library needs to be initialized. +**/ EFI_STATUS GetFvHeader ( OUT EFI_FIRMWARE_VOLUME_HEADER **FvHeader, OUT UINT32 *FvLength ) -/*++ - -Routine Description: - - This function returns a pointer to the current FV and the size. - -Arguments: - - FvHeader Pointer to the FV buffer. - FvLength Length of the FV - -Returns: - - EFI_SUCCESS Function Completed successfully. - EFI_INVALID_PARAMETER A required parameter was NULL. - EFI_ABORTED The library needs to be initialized. - ---*/ { // // Verify library has been initialized. @@ -101,31 +86,23 @@ Routine Description: return EFI_SUCCESS; } =20 -EFI_STATUS -GetNextFile ( - IN EFI_FFS_FILE_HEADER *CurrentFile, - OUT EFI_FFS_FILE_HEADER **NextFile - ) -/*++ - -Routine Description: - +/** This function returns the next file. If the current file is NULL, it re= turns the first file in the FV. If the function returns EFI_SUCCESS and the f= ile pointer is NULL, then there are no more files in the FV. =20 -Arguments: - - CurrentFile Pointer to the current file, must be within the current FV. - NextFile Pointer to the next file in the FV. - -Returns: - - EFI_SUCCESS Function completed successfully. - EFI_INVALID_PARAMETER A required parameter was NULL or is out of range. - EFI_ABORTED The library needs to be initialized. - ---*/ + @param CurrentFile Pointer to the current file, must be within the cur= rent FV. + @param NextFile Pointer to the next file in the FV. + + @retval EFI_SUCCESS Function completed successfully. + @retval EFI_INVALID_PARAMETER A required parameter was NULL or is out = of range. + @retval EFI_ABORTED The library needs to be initialized. +**/ +EFI_STATUS +GetNextFile ( + IN EFI_FFS_FILE_HEADER *CurrentFile, + OUT EFI_FFS_FILE_HEADER **NextFile + ) { EFI_STATUS Status; =20 @@ -214,29 +191,21 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Find a file by name. The function will return NULL if the file is not f= ound. + + @param FileName The GUID file name of the file to search for. + @param File Return pointer. In the case of an error, contents ar= e undefined. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error was encountered. + @retval EFI_INVALID_PARAMETER One of the parameters was NULL. +**/ EFI_STATUS GetFileByName ( IN EFI_GUID *FileName, OUT EFI_FFS_FILE_HEADER **File ) -/*++ - -Routine Description: - - Find a file by name. The function will return NULL if the file is not f= ound. - -Arguments: - - FileName The GUID file name of the file to search for. - File Return pointer. In the case of an error, contents are undef= ined. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_ABORTED An error was encountered. - EFI_INVALID_PARAMETER One of the parameters was NULL. - ---*/ { EFI_FFS_FILE_HEADER *CurrentFile; EFI_STATUS Status; @@ -295,33 +264,25 @@ Routine Description: return EFI_SUCCESS; } =20 -EFI_STATUS -GetFileByType ( - IN EFI_FV_FILETYPE FileType, - IN UINTN Instance, - OUT EFI_FFS_FILE_HEADER **File - ) -/*++ - -Routine Description: - +/** Find a file by type and instance. An instance of 1 is the first instanc= e. The function will return NULL if a matching file cannot be found. File type EFI_FV_FILETYPE_ALL means any file type is valid. =20 -Arguments: - - FileType Type of file to search for. - Instance Instance of the file type to return. - File Return pointer. In the case of an error, contents are undef= ined. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_ABORTED An error was encountered. - EFI_INVALID_PARAMETER One of the parameters was NULL. - ---*/ + @param FileType Type of file to search for. + @param Instance Instance of the file type to return. + @param File Return pointer. In the case of an error, contents ar= e undefined. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error was encountered. + @retval EFI_INVALID_PARAMETER One of the parameters was NULL. +**/ +EFI_STATUS +GetFileByType ( + IN EFI_FV_FILETYPE FileType, + IN UINTN Instance, + OUT EFI_FFS_FILE_HEADER **File + ) { EFI_FFS_FILE_HEADER *CurrentFile; EFI_STATUS Status; @@ -383,6 +344,23 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Helper function to search a sequence of sections from the section pointed + by FirstSection to SearchEnd for the Instance-th section of type Section= Type. + The current counter is saved in StartIndex and when the section is found= , it's + saved in Section. GUID-defined sections, if special processing is not re= quired, + are searched recursively in a depth-first manner. + + @param FirstSection The first section to start searching from. + @param SearchEnd The end address to stop search. + @param SectionType The type of section to search. + @param StartIndex The current counter is saved. + @param Instance The requested n-th section number. + @param Section The found section returned. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The section is not found. +**/ EFI_STATUS SearchSectionByType ( IN EFI_FILE_SECTION_POINTER FirstSection, @@ -392,30 +370,6 @@ SearchSectionByType ( IN UINTN Instance, OUT EFI_FILE_SECTION_POINTER *Section ) -/*++ - -Routine Description: - - Helper function to search a sequence of sections from the section pointed - by FirstSection to SearchEnd for the Instance-th section of type Section= Type. - The current counter is saved in StartIndex and when the section is found= , it's - saved in Section. GUID-defined sections, if special processing is not re= quired, - are searched recursively in a depth-first manner. - -Arguments: - - FirstSection The first section to start searching from. - SearchEnd The end address to stop search. - SectionType The type of section to search. - StartIndex The current counter is saved. - Instance The requested n-th section number. - Section The found section returned. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_NOT_FOUND The section is not found. ---*/ { EFI_FILE_SECTION_POINTER CurrentSection; EFI_FILE_SECTION_POINTER InnerSection; @@ -479,36 +433,29 @@ Routine Description: return EFI_NOT_FOUND; } =20 -EFI_STATUS -GetSectionByType ( - IN EFI_FFS_FILE_HEADER *File, - IN EFI_SECTION_TYPE SectionType, - IN UINTN Instance, - OUT EFI_FILE_SECTION_POINTER *Section - ) -/*++ - -Routine Description: - +/** Find a section in a file by type and instance. An instance of 1 is the = first instance. The function will return NULL if a matching section cannot be= found. GUID-defined sections, if special processing is not needed, are handled = in a depth-first manner. =20 -Arguments: + @param File The file to search. + @param SectionType Type of file to search for. + @param Instance Instance of the section to return. + @param Section Return pointer. In the case of an error, contents ar= e undefined. =20 - File The file to search. - SectionType Type of file to search for. - Instance Instance of the section to return. - Section Return pointer. In the case of an error, contents are undef= ined. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_ABORTED An error was encountered. - EFI_INVALID_PARAMETER One of the parameters was NULL. - EFI_NOT_FOUND No found. ---*/ + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error was encountered. + @retval EFI_INVALID_PARAMETER One of the parameters was NULL. + @retval EFI_NOT_FOUND No found. +**/ +EFI_STATUS +GetSectionByType ( + IN EFI_FFS_FILE_HEADER *File, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_FILE_SECTION_POINTER *Section + ) { EFI_FILE_SECTION_POINTER CurrentSection; EFI_STATUS Status; @@ -560,31 +507,25 @@ Routine Description: return EFI_NOT_FOUND; } } + // // will not parse compressed sections // + +/** + Verify the current pointer points to a valid FV header. + + @param FvHeader Pointer to an alleged FV file. + + @retval EFI_SUCCESS The FV header is valid. + @retval EFI_VOLUME_CORRUPTED The FV header is not valid. + @retval EFI_INVALID_PARAMETER A required parameter was NULL. + @retval EFI_ABORTED Operation aborted. +**/ EFI_STATUS VerifyFv ( IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader ) -/*++ - -Routine Description: - - Verify the current pointer points to a valid FV header. - -Arguments: - - FvHeader Pointer to an alleged FV file. - -Returns: - - EFI_SUCCESS The FV header is valid. - EFI_VOLUME_CORRUPTED The FV header is not valid. - EFI_INVALID_PARAMETER A required parameter was NULL. - EFI_ABORTED Operation aborted. - ---*/ { UINT16 Checksum; =20 @@ -612,28 +553,20 @@ Routine Description: return EFI_SUCCESS; } =20 -EFI_STATUS -VerifyFfsFile ( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -/*++ - -Routine Description: - +/** Verify the current pointer points to a FFS file header. =20 -Arguments: - - FfsHeader Pointer to an alleged FFS file. - -Returns: - - EFI_SUCCESS The Ffs header is valid. - EFI_NOT_FOUND This "file" is the beginning of free space. - EFI_VOLUME_CORRUPTED The Ffs header is not valid. - EFI_ABORTED The erase polarity is not known. - ---*/ + @param FfsHeader Pointer to an alleged FFS file. + + @retval EFI_SUCCESS The Ffs header is valid. + @retval EFI_NOT_FOUND This "file" is the beginning of free space. + @retval EFI_VOLUME_CORRUPTED The Ffs header is not valid. + @retval EFI_ABORTED The erase polarity is not known. +**/ +EFI_STATUS +VerifyFfsFile ( + IN EFI_FFS_FILE_HEADER *FfsHeader + ) { BOOLEAN ErasePolarity; EFI_STATUS Status; @@ -754,25 +687,17 @@ GetSectionHeaderLength( return sizeof(EFI_COMMON_SECTION_HEADER); } =20 +/** + Get FFS file length including FFS header. + + @param FfsHeader Pointer to EFI_FFS_FILE_HEADER. + + @return UINT32 Length of FFS file header. +**/ UINT32 GetFfsFileLength ( EFI_FFS_FILE_HEADER *FfsHeader ) -/*++ - -Routine Description: - - Get FFS file length including FFS header. - -Arguments: - - FfsHeader Pointer to EFI_FFS_FILE_HEADER. - -Returns: - - UINT32 Length of FFS file header. - ---*/ { if (FfsHeader =3D=3D NULL) { return 0; @@ -800,25 +725,17 @@ GetSectionFileLength ( return Length; } =20 +/** + Converts a three byte length value into a UINT32. + + @param ThreeByteLength Pointer to the first of the 3 byte length. + + @return UINT32 Size of the section +**/ UINT32 GetLength ( UINT8 *ThreeByteLength ) -/*++ - -Routine Description: - - Converts a three byte length value into a UINT32. - -Arguments: - - ThreeByteLength Pointer to the first of the 3 byte length. - -Returns: - - UINT32 Size of the section - ---*/ { UINT32 Length; =20 @@ -832,28 +749,20 @@ Routine Description: return Length; } =20 -EFI_STATUS -GetErasePolarity ( - OUT BOOLEAN *ErasePolarity - ) -/*++ - -Routine Description: - +/** This function returns with the FV erase polarity. If the erase polarity for a bit is 1, the function return TRUE. =20 -Arguments: - - ErasePolarity A pointer to the erase polarity. - -Returns: - - EFI_SUCCESS The function completed successfully. - EFI_INVALID_PARAMETER One of the input parameters was invalid. - EFI_ABORTED Operation aborted. - ---*/ + @param ErasePolarity A pointer to the erase polarity. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER One of the input parameters was invalid. + @retval EFI_ABORTED Operation aborted. +**/ +EFI_STATUS +GetErasePolarity ( + OUT BOOLEAN *ErasePolarity + ) { EFI_STATUS Status; =20 @@ -886,28 +795,20 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function returns a the highest state bit in the FFS that is set. + It in no way validate the FFS file. + + @param ErasePolarity The erase polarity for the file state bits. + @param FfsHeader Pointer to a FFS file. + + @retval UINT8 The hightest set state of the file. +**/ UINT8 GetFileState ( IN BOOLEAN ErasePolarity, IN EFI_FFS_FILE_HEADER *FfsHeader ) -/*++ - -Routine Description: - - This function returns a the highest state bit in the FFS that is set. - It in no way validate the FFS file. - -Arguments: - - ErasePolarity The erase polarity for the file state bits. - FfsHeader Pointer to a FFS file. - -Returns: - - UINT8 The hightest set state of the file. - ---*/ { UINT8 FileState; UINT8 HighestBit; diff --git a/BaseTools/Source/C/Common/MemoryFile.c b/BaseTools/Source/C/Co= mmon/MemoryFile.c index 8154a3c99006..47481326833e 100644 --- a/BaseTools/Source/C/Common/MemoryFile.c +++ b/BaseTools/Source/C/Common/MemoryFile.c @@ -27,29 +27,21 @@ CheckMemoryFileState ( // Function implementations // =20 -EFI_STATUS -GetMemoryFile ( - IN CHAR8 *InputFileName, - OUT EFI_HANDLE *OutputMemoryFile - ) -/*++ - -Routine Description: - +/** This opens a file, reads it into memory and returns a memory file object. =20 -Arguments: + @param InputFile Memory file image. + @param OutputMemoryFile Handle to memory file =20 - InputFile Memory file image. - OutputMemoryFile Handle to memory file - -Returns: - - EFI_STATUS + @return EFI_STATUS OutputMemoryFile is valid if !EFI_ERROR - ---*/ +**/ +EFI_STATUS +GetMemoryFile ( + IN CHAR8 *InputFileName, + OUT EFI_HANDLE *OutputMemoryFile + ) { EFI_STATUS Status; CHAR8 *InputFileImage; @@ -78,26 +70,17 @@ Routine Description: return EFI_SUCCESS; } =20 - -EFI_STATUS -FreeMemoryFile ( - IN EFI_HANDLE InputMemoryFile - ) -/*++ - -Routine Description: - +/** Frees all memory associated with the input memory file. =20 -Arguments: - - InputMemoryFile Handle to memory file - -Returns: - - EFI_STATUS - ---*/ + @param InputMemoryFile Handle to memory file + + @return EFI_STATUS +**/ +EFI_STATUS +FreeMemoryFile ( + IN EFI_HANDLE InputMemoryFile + ) { MEMORY_FILE *MemoryFile; =20 @@ -118,31 +101,22 @@ Routine Description: return EFI_SUCCESS; } =20 - -CHAR8 * -ReadMemoryFileLine ( - IN EFI_HANDLE InputMemoryFile - ) -/*++ - -Routine Description: - +/** This function reads a line from the memory file. The newline characters are stripped and a null terminated string is returned. =20 If the string pointer returned is non-NULL, then the caller must free the memory associated with this string. =20 -Arguments: - - InputMemoryFile Handle to memory file - -Returns: - - NULL if error or EOF - NULL character termincated string otherwise (MUST BE FREED BY CALLER) - ---*/ + @param InputMemoryFile Handle to memory file + + @retval NULL if error or EOF + @retval NULL character termincated string otherwise (MUST BE FREED BY CA= LLER) +**/ +CHAR8 * +ReadMemoryFileLine ( + IN EFI_HANDLE InputMemoryFile + ) { CHAR8 *EndOfLine; UINTN CharsToCopy; diff --git a/BaseTools/Source/C/Common/MyAlloc.c b/BaseTools/Source/C/Commo= n/MyAlloc.c index d104795d4687..17ff5cfbbd3e 100644 --- a/BaseTools/Source/C/Common/MyAlloc.c +++ b/BaseTools/Source/C/Common/MyAlloc.c @@ -27,40 +27,23 @@ STATIC MY_ALLOC_STRUCT *MyAllocData =3D NULL; STATIC UINT32 MyAllocHeadMagik =3D MYALLOC_HEAD_MAGIK; STATIC UINT32 MyAllocTailMagik =3D MYALLOC_TAIL_MAGIK; =20 -// -// ///////////////////////////////////////////////////////////////////////= ///// -// -// +/** + Check for corruptions in the allocated memory chain. If a corruption + is detection program operation stops w/ an exit(1) call. + + @param Final When FALSE, MyCheck() returns if the allocated memory chain + has not been corrupted. When TRUE, MyCheck() returns if th= ere + are no un-freed allocations. If there are un-freed allocat= ions, + they are displayed and exit(1) is called. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. +**/ VOID MyCheck ( BOOLEAN Final, UINT8 File[], UINTN Line ) -// *++ -// Description: -// -// Check for corruptions in the allocated memory chain. If a corruption -// is detection program operation stops w/ an exit(1) call. -// -// Parameters: -// -// Final :=3D When FALSE, MyCheck() returns if the allocated memory chain -// has not been corrupted. When TRUE, MyCheck() returns if there -// are no un-freed allocations. If there are un-freed allocatio= ns, -// they are displayed and exit(1) is called. -// -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// n/a -// -// --*/ -// { MY_ALLOC_STRUCT *Tmp; =20 @@ -155,39 +138,26 @@ MyCheck ( } } } -// -// ///////////////////////////////////////////////////////////////////////= ///// -// -// + +/** + Allocate a new link in the allocation chain along with enough storage + for the File[] string, requested Size and alignment overhead. If + memory cannot be allocated or the allocation chain has been corrupted, + exit(1) will be called. + + @param Size Number of bytes (UINT8) requested by the called. + Size cannot be zero. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. + + @return Pointer to the caller's buffer. +**/ VOID * MyAlloc ( UINTN Size, UINT8 File[], UINTN Line ) -// *++ -// Description: -// -// Allocate a new link in the allocation chain along with enough storage -// for the File[] string, requested Size and alignment overhead. If -// memory cannot be allocated or the allocation chain has been corrupted, -// exit(1) will be called. -// -// Parameters: -// -// Size :=3D Number of bytes (UINT8) requested by the called. -// Size cannot be zero. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// Pointer to the caller's buffer. -// -// --*/ -// { MY_ALLOC_STRUCT *Tmp; UINTN Len; @@ -278,10 +248,19 @@ MyAlloc ( =20 return Tmp->Buffer + sizeof (UINT32); } -// -// ///////////////////////////////////////////////////////////////////////= ///// -// -// + +/** + This does a MyAlloc(), memcpy() and MyFree(). There is no optimization + for shrinking or expanding buffers. An invalid parameter will cause + MyRealloc() to fail with a call to exit(1). + + @param Ptr Pointer to the caller's buffer to be re-allocated. + @param Size Size of new buffer. Size cannot be zero. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. + + @return Pointer to new caller's buffer. +**/ VOID * MyRealloc ( VOID *Ptr, @@ -289,29 +268,6 @@ MyRealloc ( UINT8 File[], UINTN Line ) -// *++ -// Description: -// -// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization -// for shrinking or expanding buffers. An invalid parameter will cause -// MyRealloc() to fail with a call to exit(1). -// -// Parameters: -// -// Ptr :=3D Pointer to the caller's buffer to be re-allocated. -// -// Size :=3D Size of new buffer. Size cannot be zero. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// Pointer to new caller's buffer. -// -// --*/ -// { MY_ALLOC_STRUCT *Tmp; VOID *Buffer; @@ -398,37 +354,22 @@ MyRealloc ( =20 return Buffer; } -// -// ///////////////////////////////////////////////////////////////////////= ///// -// -// + +/** + Release a previously allocated buffer. Invalid parameters will cause + MyFree() to fail with an exit(1) call. + + @param Ptr Pointer to the caller's buffer to be freed. + A NULL pointer will be ignored. + @param File Set to __FILE__ by macro expansion. + @param Line Set to __LINE__ by macro expansion. +**/ VOID MyFree ( VOID *Ptr, UINT8 File[], UINTN Line ) -// *++ -// Description: -// -// Release a previously allocated buffer. Invalid parameters will cause -// MyFree() to fail with an exit(1) call. -// -// Parameters: -// -// Ptr :=3D Pointer to the caller's buffer to be freed. -// A NULL pointer will be ignored. -// -// File :=3D Set to __FILE__ by macro expansion. -// -// Line :=3D Set to __LINE__ by macro expansion. -// -// Returns: -// -// n/a -// -// --*/ -// { MY_ALLOC_STRUCT *Tmp; MY_ALLOC_STRUCT *Tmp2; diff --git a/BaseTools/Source/C/Common/OsPath.c b/BaseTools/Source/C/Common= /OsPath.c index 35ca54761f14..9901f686c98f 100644 --- a/BaseTools/Source/C/Common/OsPath.c +++ b/BaseTools/Source/C/Common/OsPath.c @@ -20,14 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // BUGBUG: Not fully implemented yet. // -CHAR8* -OsPathDirName ( - IN CHAR8 *FilePath - ) -/*++ - -Routine Description: =20 +/** This function returns the directory path which contains the particular p= ath. Some examples: "a/b/c" -> "a/b" @@ -40,15 +34,15 @@ Routine Description: =20 The caller must free the string returned. =20 -Arguments: + @param FilePath Path name of file to get the parent directory for. =20 - FilePath Path name of file to get the parent directory for. + @return NULL if error +**/ +CHAR8* +OsPathDirName ( + IN CHAR8 *FilePath + ) =20 -Returns: - - NULL if error - ---*/ { CHAR8 *Return; CHAR8 *Pos; @@ -97,14 +91,8 @@ Routine Description: // // BUGBUG: Not fully implemented yet. // -VOID -OsPathNormPathInPlace ( - IN CHAR8 *Path - ) -/*++ - -Routine Description: =20 +/** This function returns the directory path which contains the particular p= ath. Some examples: "a/b/../c" -> "a/c" @@ -113,15 +101,14 @@ Routine Description: =20 This function does not check for the existence of the file. =20 -Arguments: - - Path Path name of file to normalize - -Returns: - - The string is altered in place. - ---*/ + @param Path Path name of file to normalize + + @return The string is altered in place. +**/ +VOID +OsPathNormPathInPlace ( + IN CHAR8 *Path + ) { CHAR8 *Pos; INTN Offset; @@ -200,16 +187,7 @@ Routine Description: } #endif =20 - -CHAR8* -OsPathPeerFilePath ( - IN CHAR8 *OldPath, - IN CHAR8 *Peer - ) -/*++ - -Routine Description: - +/** This function replaces the final portion of a path with an alternative 'peer' filename. For example: "a/b/../c", "peer" -> "a/b/../peer" @@ -219,16 +197,16 @@ Routine Description: =20 This function does not check for the existence of the file. =20 -Arguments: - - OldPath Path name of replace the final segment - Peer The new path name to concatenate to become the peer path - -Returns: - - A CHAR8* string, which must be freed by the caller - ---*/ + @param OldPath Path name of replace the final segment + @param Peer The new path name to concatenate to become the peer p= ath + + @return A CHAR8* string, which must be freed by the caller +**/ +CHAR8* +OsPathPeerFilePath ( + IN CHAR8 *OldPath, + IN CHAR8 *Peer + ) { CHAR8 *Result; INTN Offset; @@ -259,27 +237,18 @@ Routine Description: return Result; } =20 +/** + Checks if a file exists =20 + @param InputFileName The name of the file to check for existence + + @retval TRUE The file exists + @retval FALSE The file does not exist +**/ BOOLEAN OsPathExists ( IN CHAR8 *InputFileName ) -/*++ - -Routine Description: - - Checks if a file exists - -Arguments: - - InputFileName The name of the file to check for existence - -Returns: - - TRUE The file exists - FALSE The file does not exist - ---*/ { FILE *InputFile; InputFile =3D fopen (LongFilePath (InputFileName), "rb"); diff --git a/BaseTools/Source/C/Common/ParseGuidedSectionTools.c b/BaseTool= s/Source/C/Common/ParseGuidedSectionTools.c index a34581ecb61a..e1e9a97e7bf6 100644 --- a/BaseTools/Source/C/Common/ParseGuidedSectionTools.c +++ b/BaseTools/Source/C/Common/ParseGuidedSectionTools.c @@ -33,30 +33,22 @@ typedef struct _GUID_SEC_TOOL_ENTRY { // Function Implementation // =20 +/** + This function parses the tools_def.txt file. It returns a + EFI_HANDLE object which can be used for the other library + functions and should be passed to FreeParsedGuidedSectionToolsHandle + to free resources when the tools_def.txt information is no + longer needed. + + @param InputFile Path name of file to read + + @retval NULL if error parsing + @retval A non-NULL EFI_HANDLE otherwise +**/ EFI_HANDLE ParseGuidedSectionToolsFile ( IN CHAR8 *InputFile ) -/*++ - -Routine Description: - - This function parses the tools_def.txt file. It returns a - EFI_HANDLE object which can be used for the other library - functions and should be passed to FreeParsedGuidedSectionToolsHandle - to free resources when the tools_def.txt information is no - longer needed. - -Arguments: - - InputFile Path name of file to read - -Returns: - - NULL if error parsing - A non-NULL EFI_HANDLE otherwise - ---*/ { EFI_STATUS Status; EFI_HANDLE MemoryFile; @@ -74,31 +66,22 @@ Routine Description: return ParsedGuidedSectionTools; } =20 +/** + This function parses the tools_def.txt file. It returns a + EFI_HANDLE object which can be used for the other library + functions and should be passed to FreeParsedGuidedSectionToolsHandle + to free resources when the tools_def.txt information is no + longer needed. =20 + @param InputFile Memory file image. + + @retval NULL if error or EOF + @retval InputBuffer otherwise +**/ EFI_HANDLE ParseGuidedSectionToolsMemoryFile ( IN EFI_HANDLE InputFile ) -/*++ - -Routine Description: - - This function parses the tools_def.txt file. It returns a - EFI_HANDLE object which can be used for the other library - functions and should be passed to FreeParsedGuidedSectionToolsHandle - to free resources when the tools_def.txt information is no - longer needed. - -Arguments: - - InputFile Memory file image. - -Returns: - - NULL if error or EOF - InputBuffer otherwise - ---*/ { EFI_STATUS Status; CHAR8 *NextLine; @@ -160,31 +143,22 @@ Routine Description: return FirstGuidTool; } =20 +/** + This function looks up the appropriate tool to use for extracting + a GUID defined FV section. =20 + @param ParsedGuidedSectionToolsHandle A parsed GUID section tools han= dle. + @param SectionGuid The GUID for the section. + + @retval NULL if no tool is found or there is another error + @retval Non-NULL The tool to use to access the section contents. (The c= aller + must free the memory associated with this string.) +**/ CHAR8* LookupGuidedSectionToolPath ( IN EFI_HANDLE ParsedGuidedSectionToolsHandle, IN EFI_GUID *SectionGuid ) -/*++ - -Routine Description: - - This function looks up the appropriate tool to use for extracting - a GUID defined FV section. - -Arguments: - - ParsedGuidedSectionToolsHandle A parsed GUID section tools handle. - SectionGuid The GUID for the section. - -Returns: - - NULL - if no tool is found or there is another error - Non-NULL - The tool to use to access the section contents. (The caller - must free the memory associated with this string.) - ---*/ { GUID_SEC_TOOL_ENTRY *GuidTool; =20 diff --git a/BaseTools/Source/C/Common/ParseInf.c b/BaseTools/Source/C/Comm= on/ParseInf.c index 5ef8f1306d65..63da3d647cb7 100644 --- a/BaseTools/Source/C/Common/ParseInf.c +++ b/BaseTools/Source/C/Common/ParseInf.c @@ -14,16 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "ParseInf.h" #include "CommonLib.h" =20 -CHAR8 * -ReadLine ( - IN MEMORY_FILE *InputFile, - IN OUT CHAR8 *InputBuffer, - IN UINTN MaxLength - ) -/*++ - -Routine Description: - +/** This function reads a line, stripping any comments. The function reads a string from the input stream argument and stores it= in the input string. ReadLine reads characters from the current file positi= on @@ -31,18 +22,20 @@ Routine Description: until the number of characters read is equal to MaxLength - 1, whichever comes first. The newline character, if read, is replaced with a \0. =20 -Arguments: + @param InputFile Memory file image. + @param InputBuffer Buffer to read into, must be MaxLength size. + @param MaxLength The maximum size of the input buffer. + + @retval NULL if error or EOF + @retval InputBuffer otherwise +**/ +CHAR8 * +ReadLine ( + IN MEMORY_FILE *InputFile, + IN OUT CHAR8 *InputBuffer, + IN UINTN MaxLength + ) =20 - InputFile Memory file image. - InputBuffer Buffer to read into, must be MaxLength size. - MaxLength The maximum size of the input buffer. - -Returns: - - NULL if error or EOF - InputBuffer otherwise - ---*/ { CHAR8 *CharPtr; CHAR8 *EndOfLine; @@ -129,29 +122,21 @@ Routine Description: return InputBuffer; } =20 +/** + This function parses a file from the beginning to find a section. + The section string may be anywhere within a line. + + @param InputFile Memory file image. + @param Section Section to search for + + @retval FALSE if error or EOF + @retval TRUE if section found +**/ BOOLEAN FindSection ( IN MEMORY_FILE *InputFile, IN CHAR8 *Section ) -/*++ - -Routine Description: - - This function parses a file from the beginning to find a section. - The section string may be anywhere within a line. - -Arguments: - - InputFile Memory file image. - Section Section to search for - -Returns: - - FALSE if error or EOF - TRUE if section found - ---*/ { CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; CHAR8 *CurrentToken; @@ -190,6 +175,21 @@ Routine Description: return FALSE; } =20 +/** + Finds a token value given the section and token to search for. + + @param InputFile Memory file image. + @param Section The section to search for, a string within []. + @param Token The token to search for, e.g. EFI_PEIM_RECOVERY, follow= ed by an =3D in the INF file. + @param Instance The instance of the token to search for. Zero is the f= irst instance. + @param Value The string that holds the value following the =3D. Mus= t be MAX_LONG_FILE_PATH in size. + + @retval EFI_SUCCESS Value found. + @retval EFI_ABORTED Format error detected in INF file. + @retval EFI_INVALID_PARAMETER Input argument was null. + @retval EFI_LOAD_ERROR Error reading from the file. + @retval EFI_NOT_FOUND Section/Token/Value not found. +**/ EFI_STATUS FindToken ( IN MEMORY_FILE *InputFile, @@ -198,29 +198,6 @@ FindToken ( IN UINTN Instance, OUT CHAR8 *Value ) -/*++ - -Routine Description: - - Finds a token value given the section and token to search for. - -Arguments: - - InputFile Memory file image. - Section The section to search for, a string within []. - Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by a= n =3D in the INF file. - Instance The instance of the token to search for. Zero is the first in= stance. - Value The string that holds the value following the =3D. Must be MA= X_LONG_FILE_PATH in size. - -Returns: - - EFI_SUCCESS Value found. - EFI_ABORTED Format error detected in INF file. - EFI_INVALID_PARAMETER Input argument was null. - EFI_LOAD_ERROR Error reading from the file. - EFI_NOT_FOUND Section/Token/Value not found. - ---*/ { CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; CHAR8 *CurrentToken; @@ -359,30 +336,22 @@ Routine Description: return EFI_NOT_FOUND; } =20 +/** + Converts a string to an EFI_GUID. The string must be in the + xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format. + + @param AsciiGuidBuffer pointer to ascii string + @param GuidBuffer pointer to destination Guid + + @retval EFI_ABORTED Could not convert the string + @retval EFI_SUCCESS The string was successfully converted + @retval EFI_INVALID_PARAMETER Input parameter is invalid. +**/ EFI_STATUS StringToGuid ( IN CHAR8 *AsciiGuidBuffer, OUT EFI_GUID *GuidBuffer ) -/*++ - -Routine Description: - - Converts a string to an EFI_GUID. The string must be in the - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format. - -Arguments: - - AsciiGuidBuffer - pointer to ascii string - GuidBuffer - pointer to destination Guid - -Returns: - - EFI_ABORTED Could not convert the string - EFI_SUCCESS The string was successfully converted - EFI_INVALID_PARAMETER Input parameter is invalid. - ---*/ { INT32 Index; int Data1; @@ -461,33 +430,25 @@ Routine Description: return EFI_SUCCESS; } =20 -EFI_STATUS -AsciiStringToUint64 ( - IN CONST CHAR8 *AsciiString, - IN BOOLEAN IsHex, - OUT UINT64 *ReturnValue - ) -/*++ - -Routine Description: - +/** Converts a null terminated ascii string that represents a number into a UINT64 value. A hex number may be preceded by a 0x, but may not be succeeded by an h. A number without 0x or 0X is considered to be base 10 unless the IsHex input is true. =20 -Arguments: - - AsciiString The string to convert. - IsHex Force the string to be treated as a hex number. - ReturnValue The return value. - -Returns: - - EFI_SUCCESS Number successfully converted. - EFI_ABORTED Invalid character encountered. - ---*/ + @param AsciiString The string to convert. + @param IsHex Force the string to be treated as a hex number. + @param ReturnValue The return value. + + @retval EFI_SUCCESS Number successfully converted. + @retval EFI_ABORTED Invalid character encountered. +**/ +EFI_STATUS +AsciiStringToUint64 ( + IN CONST CHAR8 *AsciiString, + IN BOOLEAN IsHex, + OUT UINT64 *ReturnValue + ) { UINT8 Index; UINT64 Value; @@ -577,29 +538,21 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + This function reads a line, stripping any comments. + // BUGBUG: This is obsolete once genmake goes away... + + @param InputFile Stream pointer. + @param InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH siz= e. + + @retval NULL if error or EOF + @retval InputBuffer otherwise +**/ CHAR8 * ReadLineInStream ( IN FILE *InputFile, IN OUT CHAR8 *InputBuffer ) -/*++ - -Routine Description: - - This function reads a line, stripping any comments. - // BUGBUG: This is obsolete once genmake goes away... - -Arguments: - - InputFile Stream pointer. - InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH size. - -Returns: - - NULL if error or EOF - InputBuffer otherwise - ---*/ { CHAR8 *CharPtr; =20 @@ -633,30 +586,22 @@ Routine Description: return InputBuffer; } =20 +/** + This function parses a stream file from the beginning to find a section. + The section string may be anywhere within a line. + // BUGBUG: This is obsolete once genmake goes away... + + @param InputFile Stream pointer. + @param Section Section to search for + + @retval FALSE if error or EOF + @retval TRUE if section found +**/ BOOLEAN FindSectionInStream ( IN FILE *InputFile, IN CHAR8 *Section ) -/*++ - -Routine Description: - - This function parses a stream file from the beginning to find a section. - The section string may be anywhere within a line. - // BUGBUG: This is obsolete once genmake goes away... - -Arguments: - - InputFile Stream pointer. - Section Section to search for - -Returns: - - FALSE if error or EOF - TRUE if section found - ---*/ { CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; CHAR8 *CurrentToken; diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c b/BaseTools/Source/= C/Common/PcdValueCommon.c index 98023e8786d8..591a7787828c 100644 --- a/BaseTools/Source/C/Common/PcdValueCommon.c +++ b/BaseTools/Source/C/Common/PcdValueCommon.c @@ -35,6 +35,15 @@ typedef struct { PCD_ENTRY *PcdList; UINT32 PcdListLength; =20 +/** + Record new token information + + @param FileBuffer File Buffer to be record + @param PcdIndex Index of PCD in database + @param TokenIndex Index of Token + @param TokenStart Start of Token + @param TokenEnd End of Token +**/ VOID STATIC RecordToken ( @@ -44,24 +53,7 @@ RecordToken ( UINT32 TokenStart, UINT32 TokenEnd ) -/*++ =20 -Routine Description: - - Record new token information - -Arguments: - - FileBuffer File Buffer to be record - PcdIndex Index of PCD in database - TokenIndex Index of Token - TokenStart Start of Token - TokenEnd End of Token - -Returns: - - None ---*/ { CHAR8 *Token; =20 @@ -109,31 +101,24 @@ Routine Description: } } =20 -int -STATIC -LookupPcdIndex ( - CHAR8 *SkuName OPTIONAL, - CHAR8 *DefaultValueName OPTIONAL, - CHAR8 *TokenSpaceGuidName, - CHAR8 *TokenName - ) -/*++ - -Routine Description: - +/** Get PCD index in Pcd database =20 -Arguments: + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String =20 - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - -Returns: - - Index of PCD in Pcd database ---*/ + @return Index of PCD in Pcd database +**/ +int +STATIC +LookupPcdIndex ( + CHAR8 *SkuName OPTIONAL, + CHAR8 *DefaultValueName OPTIONAL, + CHAR8 *TokenSpaceGuidName, + CHAR8 *TokenName + ) { UINT32 Index; =20 @@ -161,6 +146,16 @@ Routine Description: return -1; } =20 +/** + Get PCD value + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + + @return PCD value +**/ UINT64 __PcdGet ( CHAR8 *SkuName OPTIONAL, @@ -168,23 +163,6 @@ __PcdGet ( CHAR8 *TokenSpaceGuidName, CHAR8 *TokenName ) -/*++ - -Routine Description: - - Get PCD value - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - -Returns: - - PCD value ---*/ { int Index; CHAR8 *End; @@ -212,6 +190,15 @@ Routine Description: return 0; } =20 +/** + Set PCD value + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Value PCD value to be set +**/ VOID __PcdSet ( CHAR8 *SkuName OPTIONAL, @@ -220,24 +207,6 @@ __PcdSet ( CHAR8 *TokenName, UINT64 Value ) -/*++ - -Routine Description: - - Set PCD value - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Value PCD value to be set - -Returns: - - None ---*/ { int Index; =20 @@ -275,6 +244,17 @@ Routine Description: } } =20 +/** + Get PCD value buffer + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Size Size of PCD value buffer +=20 + @return PCD value buffer +**/ VOID * __PcdGetPtr ( CHAR8 *SkuName OPTIONAL, @@ -283,24 +263,6 @@ __PcdGetPtr ( CHAR8 *TokenName, UINT32 *Size ) -/*++ - -Routine Description: - - Get PCD value buffer - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Size Size of PCD value buffer - -Returns: - - PCD value buffer ---*/ { int Index; CHAR8 *Value; @@ -341,6 +303,16 @@ Routine Description: return 0; } =20 +/** + Set PCD value buffer + + @param SkuName SkuName String + @param DefaultValueName DefaultValueName String + @param TokenSpaceGuidName TokenSpaceGuidName String + @param TokenName TokenName String + @param Size Size of PCD value + @param Value Pointer to the updated PCD value buffer +**/ VOID __PcdSetPtr ( CHAR8 *SkuName OPTIONAL, @@ -350,25 +322,6 @@ __PcdSetPtr ( UINT32 Size, UINT8 *Value ) -/*++ - -Routine Description: - - Set PCD value buffer - -Arguments: - - SkuName SkuName String - DefaultValueName DefaultValueName String - TokenSpaceGuidName TokenSpaceGuidName String - TokenName TokenName String - Size Size of PCD value - Value Pointer to the updated PCD value buffer - -Returns: - - None ---*/ { int Index; UINT32 ValueIndex; @@ -400,6 +353,13 @@ Routine Description: } } =20 +/** + Read the file buffer from the input file. +=20 + @param InputFileName Point to the input file name. + @param FileBuffer Point to the input file buffer. + @param FileSize Size of the file buffer. +**/ VOID STATIC ReadInputFile ( @@ -407,22 +367,6 @@ ReadInputFile ( UINT8 **FileBuffer, UINT32 *FileSize ) -/*++ - -Routine Description: - - Read the file buffer from the input file. - -Arguments: - - InputFileName Point to the input file name. - FileBuffer Point to the input file buffer. - FileSize Size of the file buffer. - -Returns: - - None ---*/ { FILE *InputFile; UINT32 BytesRead; @@ -492,27 +436,18 @@ Routine Description: fclose (InputFile); } =20 +/** + Read the initial PCD value from the input file buffer. + + @param FileBuffer Point to the input file buffer. + @param FileSize Size of the file buffer. +**/ VOID STATIC ParseFile ( UINT8 *FileBuffer, UINT32 FileSize ) -/*++ - -Routine Description: - - Read the initial PCD value from the input file buffer. - -Arguments: - - FileBuffer Point to the input file buffer. - FileSize Size of the file buffer. - -Returns: - - None ---*/ { UINT32 Index; UINT32 NumLines; @@ -552,25 +487,16 @@ Routine Description: } } =20 +/** + Write the updated PCD value into the output file name. + + @param OutputFileName Point to the output file name. +**/ VOID STATIC WriteOutputFile ( CHAR8 *OutputFileName ) -/*++ - -Routine Description: - - Write the updated PCD value into the output file name. - -Arguments: - - OutputFileName Point to the output file name. - -Returns: - - None ---*/ { FILE *OutputFile; UINT32 Index; @@ -605,26 +531,14 @@ Routine Description: } } =20 +/** + Displays the utility usage syntax to STDOUT +**/ VOID STATIC Usage ( VOID ) -/*++ - -Routine Description: - - Displays the utility usage syntax to STDOUT - -Arguments: - - None - -Returns: - - None - ---*/ { fprintf (stdout, "Usage: -i -o \n\n"); fprintf (stdout, "optional arguments:\n"); @@ -635,6 +549,14 @@ Routine Description: PCD Database Output file name\n"); } =20 +/** + Parse the input parameters to get the input/output file name. + + @param argc Number of command line parameters. + @param argv Array of pointers to parameter strings. + @param InputFileName Point to the input file name. + @param OutputFileName Point to the output file name. +**/ VOID STATIC ParseArguments ( @@ -643,23 +565,6 @@ ParseArguments ( CHAR8 **InputFileName, CHAR8 **OutputFileName ) -/*++ - -Routine Description: - - Parse the input parameters to get the input/output file name. - -Arguments: - - argc Number of command line parameters. - argv Array of pointers to parameter strings. - InputFileName Point to the input file name. - OutputFileName Point to the output file name. - -Returns: - - None ---*/ { if (argc =3D=3D 1) { fprintf (stderr, "Missing options\n"); @@ -722,25 +627,19 @@ Routine Description: } } =20 +/** + Main function updates PCD values. + + @param argc Number of command line parameters. + @param argv Array of pointers to parameter strings. + + @retval EXIT_SUCCESS +**/ int PcdValueMain ( int argc, char *argv[] ) -/*++ - -Routine Description: - - Main function updates PCD values. - -Arguments: - - argc Number of command line parameters. - argv Array of pointers to parameter strings. - -Returns: - EXIT_SUCCESS ---*/ { CHAR8 *InputFileName; CHAR8 *OutputFileName; diff --git a/BaseTools/Source/C/Common/PeCoffLoaderEx.c b/BaseTools/Source/= C/Common/PeCoffLoaderEx.c index 2cc428d733b4..181192035ef1 100644 --- a/BaseTools/Source/C/Common/PeCoffLoaderEx.c +++ b/BaseTools/Source/C/Common/PeCoffLoaderEx.c @@ -65,59 +65,37 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 UINT32 *RiscVHi20Fixup =3D NULL; =20 -RETURN_STATUS -PeCoffLoaderRelocateIa32Image ( - IN UINT16 *Reloc, - IN OUT CHAR8 *Fixup, - IN OUT CHAR8 **FixupData, - IN UINT64 Adjust - ) -/*++ - -Routine Description: - +/** Performs an IA-32 specific relocation fixup =20 -Arguments: - - Reloc - Pointer to the relocation record - - Fixup - Pointer to the address to fix up - - FixupData - Pointer to a buffer to log the fixups - - Adjust - The offset to adjust the fixup - -Returns: - - EFI_UNSUPPORTED - Unsupported now - ---*/ + @param Reloc Pointer to the relocation record + @param Fixup Pointer to the address to fix up + @param FixupData Pointer to a buffer to log the fixups + @param Adjust The offset to adjust the fixup + + @retval EFI_UNSUPPORTED - Unsupported now +**/ +RETURN_STATUS +PeCoffLoaderRelocateIa32Image ( + IN UINT16 *Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust + ) { return RETURN_UNSUPPORTED; } =20 -/*++ - -Routine Description: - +/** Performs an RISC-V specific relocation fixup =20 -Arguments: + @param Reloc Pointer to the relocation record + @param Fixup Pointer to the address to fix up + @param FixupData Pointer to a buffer to log the fixups + @param Adjust The offset to adjust the fixup =20 - Reloc - Pointer to the relocation record - - Fixup - Pointer to the address to fix up - - FixupData - Pointer to a buffer to log the fixups - - Adjust - The offset to adjust the fixup - -Returns: - - Status code - ---*/ + @return Status code +**/ RETURN_STATUS PeCoffLoaderRelocateRiscVImage ( IN UINT16 *Reloc, diff --git a/BaseTools/Source/C/Common/SimpleFileParsing.c b/BaseTools/Sour= ce/C/Common/SimpleFileParsing.c index eb6abea1bec7..51d59cf4a765 100644 --- a/BaseTools/Source/C/Common/SimpleFileParsing.c +++ b/BaseTools/Source/C/Common/SimpleFileParsing.c @@ -152,65 +152,43 @@ SetFilePosition ( FILE_POSITION *Fpos ); =20 +/** + @retval STATUS_SUCCESS always +**/ STATUS SFPInit ( VOID ) -/*++ - -Routine Description: - -Arguments: - None. - -Returns: - STATUS_SUCCESS always - ---*/ { memset ((VOID *) &mGlobals, 0, sizeof (mGlobals)); return STATUS_SUCCESS; } =20 -UINTN -SFPGetLineNumber ( - VOID - ) -/*++ - -Routine Description: +/** Return the line number of the file we're parsing. Used for error reporting purposes. =20 -Arguments: - None. - -Returns: - The line number, or 0 if no file is being processed - ---*/ + @return The line number, or 0 if no file is being processed +**/ +UINTN +SFPGetLineNumber ( + VOID + ) { return mGlobals.SourceFile.LineNum; } =20 -CHAR8 * -SFPGetFileName ( - VOID - ) -/*++ - -Routine Description: +/** Return the name of the file we're parsing. Used for error reporting purposes. =20 -Arguments: - None. - -Returns: - A pointer to the file name. Null if no file is being + @return A pointer to the file name. Null if no file is being processed. - ---*/ +**/ +CHAR8 * +SFPGetFileName ( + VOID + ) { if (mGlobals.SourceFile.FileName[0]) { return mGlobals.SourceFile.FileName; @@ -219,22 +197,15 @@ Routine Description: return NULL; } =20 +/** + Open a file for parsing. + + @param FileName name of the file to parse +**/ STATUS SFPOpenFile ( CHAR8 *FileName ) -/*++ - -Routine Description: - Open a file for parsing. - -Arguments: - FileName - name of the file to parse - -Returns: - - ---*/ { STATUS Status; t_strcpy (mGlobals.SourceFile.FileName, FileName); @@ -242,31 +213,26 @@ Routine Description: return Status; } =20 -BOOLEAN -SFPIsToken ( - CHAR8 *Str - ) -/*++ - -Routine Description: +/** Check to see if the specified token is found at the current position in the input file. =20 -Arguments: - Str - the token to look for + @note: + We do a simple string comparison on this function. It is + the responsibility of the caller to ensure that the token + is not a subset of some other token. =20 -Returns: - TRUE - the token is next - FALSE - the token is not next + The file pointer is advanced past the token in the input file. +=20 + @param Str the token to look for =20 -Notes: - We do a simple string comparison on this function. It is - the responsibility of the caller to ensure that the token - is not a subset of some other token. - - The file pointer is advanced past the token in the input file. - ---*/ + @retval TRUE the token is next + @retval FALSE the token is not next +**/ +BOOLEAN +SFPIsToken ( + CHAR8 *Str + ) { UINTN Len; SkipWhiteSpace (&mGlobals.SourceFile); @@ -286,28 +252,23 @@ Routine Description: return FALSE; } =20 -BOOLEAN -SFPIsKeyword ( - CHAR8 *Str - ) -/*++ - -Routine Description: +/** Check to see if the specified keyword is found at the current position in the input file. =20 -Arguments: - Str - keyword to look for + @note: + A keyword is defined as a "special" string that has a non-alphanumeric + character following it. +=20 + @param Str keyword to look for =20 -Returns: - TRUE - the keyword is next - FALSE - the keyword is not next - -Notes: - A keyword is defined as a "special" string that has a non-alphanumeric - character following it. - ---*/ + @retval TRUE the keyword is next + @retval FALSE the keyword is not next +**/ +BOOLEAN +SFPIsKeyword ( + CHAR8 *Str + ) { UINTN Len; SkipWhiteSpace (&mGlobals.SourceFile); @@ -331,30 +292,25 @@ Routine Description: return FALSE; } =20 +/** + Get the next token from the input stream. + + @note: + Preceding white space is ignored. + The parser's buffer pointer is advanced past the end of the + token. +=20 + @param Str pointer to a copy of the next token + @param Len size of buffer pointed to by Str + + @retval TRUE next token successfully returned + @retval FALSE otherwise +**/ BOOLEAN SFPGetNextToken ( CHAR8 *Str, UINTN Len ) -/*++ - -Routine Description: - Get the next token from the input stream. - -Arguments: - Str - pointer to a copy of the next token - Len - size of buffer pointed to by Str - -Returns: - TRUE - next token successfully returned - FALSE - otherwise - -Notes: - Preceding white space is ignored. - The parser's buffer pointer is advanced past the end of the - token. - ---*/ { UINTN Index; CHAR8 TempChar; @@ -436,25 +392,20 @@ Routine Description: return FALSE; } =20 +/** + Parse a GUID from the input stream. Stop when you discover white space. + + @param Str pointer to a copy of the next token + @param Len size of buffer pointed to by Str + + @retval TRUE GUID string returned successfully + @retval FALSE otherwise +**/ BOOLEAN SFPGetGuidToken ( CHAR8 *Str, UINT32 Len ) -/*++ - -Routine Description: - Parse a GUID from the input stream. Stop when you discover white space. - -Arguments: - Str - pointer to a copy of the next token - Len - size of buffer pointed to by Str - -Returns: - TRUE - GUID string returned successfully - FALSE - otherwise - ---*/ { UINT32 Index; SkipWhiteSpace (&mGlobals.SourceFile); @@ -505,24 +456,19 @@ SFPSkipToToken ( return FALSE; } =20 -BOOLEAN -SFPGetNumber ( - UINTN *Value - ) -/*++ - -Routine Description: +/** Check the token at the current file position for a numeric value. May be either decimal or hex. =20 -Arguments: - Value - pointer where to store the value + @param Value pointer where to store the value =20 -Returns: - FALSE - current token is not a number - TRUE - current token is a number - ---*/ + @retval FALSE current token is not a number + @retval TRUE current token is a number +**/ +BOOLEAN +SFPGetNumber ( + UINTN *Value + ) { int Val; =20 @@ -561,23 +507,16 @@ Routine Description: } } =20 -STATUS -SFPCloseFile ( - VOID - ) -/*++ - -Routine Description: +/** Close the file being parsed. =20 -Arguments: - None. - -Returns: - STATUS_SUCCESS - the file was closed - STATUS_ERROR - no file is currently open - ---*/ + @retval STATUS_SUCCESS the file was closed + @retval STATUS_ERROR no file is currently open +**/ +STATUS +SFPCloseFile ( + VOID + ) { if (mGlobals.SourceFile.FileBuffer !=3D NULL) { free (mGlobals.SourceFile.FileBuffer); @@ -588,28 +527,20 @@ Routine Description: return STATUS_ERROR; } =20 -STATIC -STATUS -ProcessIncludeFile ( - SOURCE_FILE *SourceFile, - SOURCE_FILE *ParentSourceFile - ) -/*++ - -Routine Description: - +/** Given a source file, open the file and parse it =20 -Arguments: - - SourceFile - name of file to parse - ParentSourceFile - for error reporting purposes, the file that #include= d SourceFile. - -Returns: - - Standard status. - ---*/ + @param SourceFile name of file to parse + @param ParentSourceFile for error reporting purposes, the file that #in= cluded SourceFile. + + @return Standard status. +**/ +STATIC +STATUS +ProcessIncludeFile ( + SOURCE_FILE *SourceFile, + SOURCE_FILE *ParentSourceFile + ) { STATIC UINTN NestDepth =3D 0; CHAR8 FoundFileName[MAX_PATH]; @@ -657,27 +588,19 @@ Routine Description: return Status; } =20 -STATIC -STATUS -ProcessFile ( - SOURCE_FILE *SourceFile - ) -/*++ - -Routine Description: - +/** Given a source file that's been opened, read the contents into an intern= al buffer and pre-process it to remove comments. =20 -Arguments: - - SourceFile - structure containing info on the file to process - -Returns: - - Standard status. - ---*/ + @param SourceFile structure containing info on the file to process + + @return Standard status. +**/ +STATIC +STATUS +ProcessFile ( + SOURCE_FILE *SourceFile + ) { // // Get the file size, and then read the entire thing into memory. @@ -706,24 +629,17 @@ Routine Description: return STATUS_SUCCESS; } =20 -STATIC -VOID -PreprocessFile ( - SOURCE_FILE *SourceFile - ) -/*++ - -Routine Description: +/** Preprocess a file to replace all carriage returns with NULLs so we can print lines (as part of error messages) from the file to the scre= en. =20 -Arguments: - SourceFile - structure that we use to keep track of an input file. - -Returns: - Nothing. - ---*/ + @param SourceFile structure that we use to keep track of an input file. +**/ +STATIC +VOID +PreprocessFile ( + SOURCE_FILE *SourceFile + ) { BOOLEAN InComment; BOOLEAN SlashSlashComment; @@ -812,26 +728,21 @@ Routine Description: } } =20 +/** + Retrieve a quoted-string from the input file. + + @param Str pointer to a copy of the quoted string parsed + @param Length size of buffer pointed to by Str + + @retval TRUE next token in input stream was a quoted string, and + the string value was returned in Str + @retval FALSE otherwise +**/ BOOLEAN SFPGetQuotedString ( CHAR8 *Str, INTN Length ) -/*++ - -Routine Description: - Retrieve a quoted-string from the input file. - -Arguments: - Str - pointer to a copy of the quoted string parsed - Length - size of buffer pointed to by Str - -Returns: - TRUE - next token in input stream was a quoted string, and - the string value was returned in Str - FALSE - otherwise - ---*/ { SkipWhiteSpace (&mGlobals.SourceFile); if (EndOfFile (&mGlobals.SourceFile)) { @@ -866,24 +777,17 @@ Routine Description: return FALSE; } =20 -BOOLEAN -SFPIsEOF ( - VOID - ) -/*++ - -Routine Description: +/** Return TRUE of FALSE to indicate whether or not we've reached the end of= the file we're parsing. =20 -Arguments: - NA - -Returns: - TRUE - EOF reached - FALSE - otherwise - ---*/ + @retval TRUE EOF reached + @retval FALSE otherwise +**/ +BOOLEAN +SFPIsEOF ( + VOID + ) { SkipWhiteSpace (&mGlobals.SourceFile); return EndOfFile (&mGlobals.SourceFile); @@ -1112,27 +1016,22 @@ SkipWhiteSpace ( return Count; } =20 -STATIC -UINTN -t_strcmp ( - CHAR8 *Buffer, - CHAR8 *Str - ) -/*++ - -Routine Description: +/** Compare two strings for equality. The string pointed to by 'Buffer' may = or may not be null-terminated, so only compare up to the length of Str. =20 -Arguments: - Buffer - pointer to first (possibly not null-terminated) string - Str - pointer to null-terminated string to compare to Buffer + @param Buffer pointer to first (possibly not null-terminated) string + @param Str pointer to null-terminated string to compare to Buffer =20 -Returns: - Number of bytes matched if exact match - 0 if Buffer does not start with Str - ---*/ + @retval Number of bytes matched if exact match + @retval 0 if Buffer does not start with Str +**/ +STATIC +UINTN +t_strcmp ( + CHAR8 *Buffer, + CHAR8 *Str + ) { UINTN Len; =20 @@ -1245,28 +1144,23 @@ GetHexChars ( return Len; } =20 +/** + Parse a GUID from the input stream. Stop when you discover white space. + + GUID styles + Style[0] 12345678-1234-5678-AAAA-BBBBCCCCDDDD + + @param GuidStyle Style of the following GUID token + @param Value pointer to EFI_GUID struct for output + + @retval TRUE GUID string parsed successfully + @retval FALSE otherwise +**/ BOOLEAN SFPGetGuid ( INTN GuidStyle, EFI_GUID *Value ) -/*++ - -Routine Description: - Parse a GUID from the input stream. Stop when you discover white space. - -Arguments: - GuidStyle - Style of the following GUID token - Value - pointer to EFI_GUID struct for output - -Returns: - TRUE - GUID string parsed successfully - FALSE - otherwise - - GUID styles - Style[0] 12345678-1234-5678-AAAA-BBBBCCCCDDDD - ---*/ { INT32 Value32; UINT32 Index; diff --git a/BaseTools/Source/C/Common/StringFuncs.c b/BaseTools/Source/C/C= ommon/StringFuncs.c index 50573fdf0999..bc85ba012440 100644 --- a/BaseTools/Source/C/Common/StringFuncs.c +++ b/BaseTools/Source/C/Common/StringFuncs.c @@ -14,25 +14,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Functions implementations // =20 -CHAR8* -CloneString ( - IN CHAR8 *String - ) -/*++ - -Routine Description: - +/** Allocates a new string and copies 'String' to clone it =20 -Arguments: - - String The string to clone - -Returns: - - CHAR8* - NULL if there are not enough resources - ---*/ + @param String The string to clone + + @return CHAR8* - NULL if there are not enough resources +**/ +CHAR8* +CloneString ( + IN CHAR8 *String + ) { CHAR8* NewString; =20 @@ -44,26 +36,17 @@ Routine Description: return NewString; } =20 - -EFI_STATUS -StripInfDscStringInPlace ( - IN CHAR8 *String - ) -/*++ - -Routine Description: - +/** Remove all comments, leading and trailing whitespace from the string. =20 -Arguments: - - String The string to 'strip' - -Returns: - - EFI_STATUS - ---*/ + @param String The string to 'strip' + + @return EFI_STATUS +**/ +EFI_STATUS +StripInfDscStringInPlace ( + IN CHAR8 *String + ) { CHAR8 *Pos; =20 @@ -110,27 +93,18 @@ Routine Description: return EFI_SUCCESS; } =20 - -STRING_LIST* -SplitStringByWhitespace ( - IN CHAR8 *String - ) -/*++ - -Routine Description: - +/** Creates and returns a 'split' STRING_LIST by splitting the string on whitespace boundaries. =20 -Arguments: - - String The string to 'split' - -Returns: - - EFI_STATUS - ---*/ + @param String The string to 'split' + + @return EFI_STATUS +**/ +STRING_LIST* +SplitStringByWhitespace ( + IN CHAR8 *String + ) { CHAR8 *Pos; CHAR8 *EndOfSubString; @@ -172,21 +146,14 @@ Routine Description: return Output; } =20 - -STRING_LIST* -NewStringList ( - ) -/*++ - -Routine Description: - +/** Creates a new STRING_LIST with 0 strings. =20 -Returns: - - STRING_LIST* - Null if there is not enough resources to create the objec= t. - ---*/ + @return STRING_LIST* - Null if there is not enough resources to create t= he object. +**/ +STRING_LIST* +NewStringList ( + ) { STRING_LIST *NewList; NewList =3D AllocateStringListStruct (0); @@ -196,24 +163,17 @@ Routine Description: return NewList; } =20 - -EFI_STATUS -AppendCopyOfStringToList ( - IN OUT STRING_LIST **StringList, - IN CHAR8 *String - ) -/*++ - -Routine Description: - +/** Adds String to StringList. A new copy of String is made before it is added to StringList. =20 -Returns: - - EFI_STATUS - ---*/ + @return EFI_STATUS +**/ +EFI_STATUS +AppendCopyOfStringToList ( + IN OUT STRING_LIST **StringList, + IN CHAR8 *String + ) { STRING_LIST *OldList; STRING_LIST *NewList; @@ -245,27 +205,18 @@ Routine Description: return EFI_SUCCESS; } =20 - -EFI_STATUS -RemoveLastStringFromList ( - IN STRING_LIST *StringList - ) -/*++ - -Routine Description: - +/** Removes the last string from StringList and frees the memory associated with it. =20 -Arguments: - - StringList The string list to remove the string from - -Returns: - - EFI_STATUS - ---*/ + @param StringList The string list to remove the string from + + @return EFI_STATUS +**/ +EFI_STATUS +RemoveLastStringFromList ( + IN STRING_LIST *StringList + ) { if (StringList->Count =3D=3D 0) { return EFI_INVALID_PARAMETER; @@ -276,49 +227,30 @@ Routine Description: return EFI_SUCCESS; } =20 +/** + Allocates a STRING_LIST structure that can store StringCount strings. =20 + @param StringCount The number of strings that need to be stored + + @return EFI_STATUS +**/ STRING_LIST* AllocateStringListStruct ( IN UINTN StringCount ) -/*++ - -Routine Description: - - Allocates a STRING_LIST structure that can store StringCount strings. - -Arguments: - - StringCount The number of strings that need to be stored - -Returns: - - EFI_STATUS - ---*/ { return malloc (OFFSET_OF(STRING_LIST, Strings[StringCount + 1])); } =20 - -VOID -FreeStringList ( - IN STRING_LIST *StringList - ) -/*++ - -Routine Description: - +/** Frees all memory associated with StringList. =20 -Arguments: - - StringList The string list to free - -Returns: - - VOID ---*/ + @param StringList The string list to free +**/ +VOID +FreeStringList ( + IN STRING_LIST *StringList + ) { while (StringList->Count > 0) { RemoveLastStringFromList (StringList); @@ -327,27 +259,18 @@ Routine Description: free (StringList); } =20 - -CHAR8* -StringListToString ( - IN STRING_LIST *StringList - ) -/*++ - -Routine Description: - +/** Generates a string that represents the STRING_LIST =20 -Arguments: + @param StringList The string list to convert to a string =20 - StringList The string list to convert to a string - -Returns: - - CHAR8* - The string list represented with a single string. The returned + @return CHAR8* - The string list represented with a single string. The = returned string must be freed by the caller. - ---*/ +**/ +CHAR8* +StringListToString ( + IN STRING_LIST *StringList + ) { UINTN Count; UINTN Length; @@ -381,26 +304,17 @@ Routine Description: return NewString; } =20 - -VOID -PrintStringList ( - IN STRING_LIST *StringList - ) -/*++ - -Routine Description: - +/** Prints out the string list =20 -Arguments: - - StringList The string list to print - -Returns: - - EFI_STATUS - ---*/ + @param StringList The string list to print +=20 + @return EFI_STATUS +**/ +VOID +PrintStringList ( + IN STRING_LIST *StringList + ) { CHAR8* String; String =3D StringListToString (StringList); diff --git a/BaseTools/Source/C/Common/TianoCompress.c b/BaseTools/Source/C= /Common/TianoCompress.c index 030cdca025b8..2f484b9731dc 100644 --- a/BaseTools/Source/C/Common/TianoCompress.c +++ b/BaseTools/Source/C/Common/TianoCompress.c @@ -256,6 +256,25 @@ STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mP= arent, *mPrev, *mNext =3D NU // // functions // + +/** + The internal implementation of [Efi/Tiano]Compress(). + + @param SrcBuffer The buffer storing the source data + @param SrcSize The size of source data + @param DstBuffer The buffer to store the compressed data + @param DstSize On input, the size of DstBuffer; On output, + the size of the actual compressed data. + @param Version The version of de/compression algorithm. + Version 1 for UEFI 2.0 de/compression algorithm. + Version 2 for Tiano de/compression algorithm. + + @retval EFI_BUFFER_TOO_SMALL The DstBuffer is too small. In this case, + DstSize contains the size needed. + @retval EFI_SUCCESS Compression is successful. + @retval EFI_OUT_OF_RESOURCES No resource to complete function. + @retval EFI_INVALID_PARAMETER Parameter supplied is wrong. +**/ EFI_STATUS TianoCompress ( IN UINT8 *SrcBuffer, @@ -263,32 +282,6 @@ TianoCompress ( IN UINT8 *DstBuffer, IN OUT UINT32 *DstSize ) -/*++ - -Routine Description: - - The internal implementation of [Efi/Tiano]Compress(). - -Arguments: - - SrcBuffer - The buffer storing the source data - SrcSize - The size of source data - DstBuffer - The buffer to store the compressed data - DstSize - On input, the size of DstBuffer; On output, - the size of the actual compressed data. - Version - The version of de/compression algorithm. - Version 1 for UEFI 2.0 de/compression algorithm. - Version 2 for Tiano de/compression algorithm. - -Returns: - - EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case, - DstSize contains the size needed. - EFI_SUCCESS - Compression is successful. - EFI_OUT_OF_RESOURCES - No resource to complete function. - EFI_INVALID_PARAMETER - Parameter supplied is wrong. - ---*/ { EFI_STATUS Status; =20 @@ -351,24 +344,16 @@ Routine Description: =20 } =20 -STATIC -VOID -PutDword ( - IN UINT32 Data - ) -/*++ - -Routine Description: - +/** Put a dword to output stream =20 -Arguments: - - Data - the dword to put - -Returns: (VOID) - ---*/ + @param Data the dword to put +**/ +STATIC +VOID +PutDword ( + IN UINT32 Data + ) { if (mDst < mDstUpperLimit) { *mDst++ =3D (UINT8) (((UINT8) (Data)) & 0xff); @@ -387,26 +372,17 @@ Returns: (VOID) } } =20 -STATIC -EFI_STATUS -AllocateMemory ( - VOID - ) -/*++ - -Routine Description: - +/** Allocate memory spaces for data structures used in compression process =20 -Arguments: + @retval EFI_SUCCESS Memory is allocated successfully + @retval EFI_OUT_OF_RESOURCES Allocation fails +**/ +STATIC +EFI_STATUS +AllocateMemory ( VOID - -Returns: - - EFI_SUCCESS - Memory is allocated successfully - EFI_OUT_OF_RESOURCES - Allocation fails - ---*/ + ) { UINT32 Index; =20 @@ -445,21 +421,13 @@ Routine Description: return EFI_SUCCESS; } =20 -VOID -FreeMemory ( - VOID - ) -/*++ - -Routine Description: - +/** Called when compression is completed to free memory previously allocated. - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +VOID +FreeMemory ( + VOID + ) { if (mText !=3D NULL) { free (mText); @@ -496,22 +464,14 @@ Returns: (VOID) return ; } =20 -STATIC -VOID -InitSlide ( - VOID - ) -/*++ - -Routine Description: - +/** Initialize String Info Log data structures - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +InitSlide ( + VOID + ) { NODE Index; =20 @@ -535,28 +495,20 @@ Returns: (VOID) } } =20 -STATIC -NODE -Child ( - IN NODE NodeQ, - IN UINT8 CharC - ) -/*++ - -Routine Description: - +/** Find child node given the parent node and the edge character =20 -Arguments: - - NodeQ - the parent node - CharC - the edge character - -Returns: - - The child node (NIL if not found) - ---*/ + @param NodeQ the parent node + @param CharC the edge character + + @return The child node (NIL if not found) +**/ +STATIC +NODE +Child ( + IN NODE NodeQ, + IN UINT8 CharC + ) { NODE NodeR; =20 @@ -572,6 +524,13 @@ Routine Description: return NodeR; } =20 +/** + Create a new child for a given parent node. + + @param Parent the parent node + @param CharC the edge character + @param Child the child node +**/ STATIC VOID MakeChild ( @@ -579,21 +538,6 @@ MakeChild ( IN UINT8 CharC, IN NODE Child ) -/*++ - -Routine Description: - - Create a new child for a given parent node. - -Arguments: - - Parent - the parent node - CharC - the edge character - Child - the child node - -Returns: (VOID) - ---*/ { NODE Node1; NODE Node2; @@ -608,24 +552,16 @@ Returns: (VOID) mChildCount[Parent]++; } =20 -STATIC -VOID -Split ( - NODE Old - ) -/*++ - -Routine Description: - +/** Split a node. =20 -Arguments: - - Old - the node to split - -Returns: (VOID) - ---*/ + @param Old the node to split +**/ +STATIC +VOID +Split ( + NODE Old + ) { NODE New; NODE TempNode; @@ -646,22 +582,14 @@ Returns: (VOID) MakeChild (New, mText[mPos + mMatchLen], mPos); } =20 -STATIC -VOID -InsertNode ( - VOID - ) -/*++ - -Routine Description: - +/** Insert string info for current position into the String Info Log - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +InsertNode ( + VOID + ) { NODE NodeQ; NODE NodeR; @@ -778,23 +706,15 @@ Returns: (VOID) =20 } =20 -STATIC -VOID -DeleteNode ( - VOID - ) -/*++ - -Routine Description: - +/** Delete outdated string info. (The Usage of PERC_FLAG ensures a clean deletion) - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +DeleteNode ( + VOID + ) { NODE NodeQ; NODE NodeR; @@ -873,23 +793,15 @@ Returns: (VOID) mAvail =3D NodeR; } =20 -STATIC -VOID -GetNextMatch ( - VOID - ) -/*++ - -Routine Description: - +/** Advance the current position (read in new data if needed). Delete outdated string info. Find a match string for current position. - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +GetNextMatch ( + VOID + ) { INT32 Number; =20 @@ -906,25 +818,17 @@ Returns: (VOID) InsertNode (); } =20 -STATIC -EFI_STATUS -Encode ( - VOID - ) -/*++ - -Routine Description: - +/** The main controlling routine for compression process. =20 -Arguments: (VOID) - -Returns: - - EFI_SUCCESS - The compression is successful - EFI_OUT_0F_RESOURCES - Not enough memory for compression process - ---*/ + @retval EFI_SUCCESS The compression is successful + @retval EFI_OUT_0F_RESOURCES Not enough memory for compression process +**/ +STATIC +EFI_STATUS +Encode ( + VOID + ) { EFI_STATUS Status; INT32 LastMatchLen; @@ -996,22 +900,14 @@ Arguments: (VOID) return EFI_SUCCESS; } =20 -STATIC -VOID -CountTFreq ( - VOID - ) -/*++ - -Routine Description: - +/** Count the frequencies for the Extra Set - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +CountTFreq ( + VOID + ) { INT32 Index; INT32 Index3; @@ -1053,28 +949,20 @@ Returns: (VOID) } } =20 -STATIC -VOID -WritePTLen ( - IN INT32 Number, - IN INT32 nbit, - IN INT32 Special - ) -/*++ - -Routine Description: - +/** Outputs the code length array for the Extra Set or the Position Set. =20 -Arguments: - - Number - the number of symbols - nbit - the number of bits needed to represent 'n' - Special - the special symbol that needs to be take care of - -Returns: (VOID) - ---*/ + @param Number the number of symbols + @param nbit the number of bits needed to represent 'n' + @param Special the special symbol that needs to be take care of +**/ +STATIC +VOID +WritePTLen ( + IN INT32 Number, + IN INT32 nbit, + IN INT32 Special + ) { INT32 Index; INT32 Index3; @@ -1103,22 +991,14 @@ Returns: (VOID) } } =20 -STATIC -VOID -WriteCLen ( - VOID - ) -/*++ - -Routine Description: - +/** Outputs the code length array for Char&Length Set - -Arguments: (VOID) - -Returns: (VOID) - ---*/ +**/ +STATIC +VOID +WriteCLen ( + VOID + ) { INT32 Index; INT32 Index3; @@ -1193,24 +1073,14 @@ EncodeP ( } } =20 -STATIC -VOID -SendBlock ( - VOID - ) -/*++ - -Routine Description: - +/** Huffman code the block and output it. - -Arguments: - (VOID) - -Returns: - (VOID) - ---*/ +**/ +STATIC +VOID +SendBlock ( + VOID + ) { UINT32 Index; UINT32 Index2; @@ -1281,26 +1151,18 @@ Routine Description: } } =20 +/** + Outputs an Original Character or a Pointer + + @param CharC The original character or the 'String Length' element of = a Pointer + @param Pos The 'Position' field of a Pointer +**/ STATIC VOID Output ( IN UINT32 CharC, IN UINT32 Pos ) -/*++ - -Routine Description: - - Outputs an Original Character or a Pointer - -Arguments: - - CharC - The original character or the 'String Length' element of a P= ointer - Pos - The 'Position' field of a Pointer - -Returns: (VOID) - ---*/ { STATIC UINT32 CPos; =20 @@ -1399,26 +1261,18 @@ MakeCrcTable ( } } =20 -STATIC -VOID -PutBits ( - IN INT32 Number, - IN UINT32 Value - ) -/*++ - -Routine Description: - +/** Outputs rightmost n bits of x - -Arguments: - - Number - the rightmost n bits of the data is used - x - the data - -Returns: (VOID) - ---*/ +=20 + @param Number the rightmost n bits of the data is used + @param x the data +**/ +STATIC +VOID +PutBits ( + IN INT32 Number, + IN UINT32 Value + ) { UINT8 Temp; =20 @@ -1439,28 +1293,20 @@ Returns: (VOID) mSubBitBuf |=3D Value << (mBitCount -=3D Number); } =20 -STATIC -INT32 -FreadCrc ( - OUT UINT8 *Pointer, - IN INT32 Number - ) -/*++ - -Routine Description: - +/** Read in source data =20 -Arguments: - - Pointer - the buffer to hold the data - Number - number of bytes to read - -Returns: - - number of bytes actually read - ---*/ + @param Pointer - the buffer to hold the data + @param Number - number of bytes to read + + @return number of bytes actually read +**/ +STATIC +INT32 +FreadCrc ( + OUT UINT8 *Pointer, + IN INT32 Number + ) { INT32 Index; =20 @@ -1491,24 +1337,16 @@ InitPutBits ( mSubBitBuf =3D 0; } =20 -STATIC -VOID -CountLen ( - IN INT32 Index - ) -/*++ - -Routine Description: - +/** Count the number of each code length for a Huffman tree. =20 -Arguments: - - Index - the top node - -Returns: (VOID) - ---*/ + @param Index the top node +**/ +STATIC +VOID +CountLen ( + IN INT32 Index + ) { STATIC INT32 Depth =3D 0; =20 @@ -1522,26 +1360,16 @@ Returns: (VOID) } } =20 -STATIC -VOID -MakeLen ( - IN INT32 Root - ) -/*++ - -Routine Description: - +/** Create code length array for a Huffman tree =20 -Arguments: - - Root - the root of the tree - -Returns: - - VOID - ---*/ + @param Root the root of the tree +**/ +STATIC +VOID +MakeLen ( + IN INT32 Root + ) { INT32 Index; INT32 Index3; @@ -1616,28 +1444,20 @@ DownHeap ( mHeap[Index] =3D (INT16) Index3; } =20 -STATIC -VOID -MakeCode ( - IN INT32 Number, - IN UINT8 Len[ ], - OUT UINT16 Code[] - ) -/*++ - -Routine Description: - +/** Assign code to each symbol based on the code length array =20 -Arguments: - - Number - number of symbols - Len - the code length array - Code - stores codes for each symbol - -Returns: (VOID) - ---*/ + @param Number number of symbols + @param Len the code length array + @param Code stores codes for each symbol +**/ +STATIC +VOID +MakeCode ( + IN INT32 Number, + IN UINT8 Len[ ], + OUT UINT16 Code[] + ) { INT32 Index; UINT16 Start[18]; @@ -1652,32 +1472,24 @@ Returns: (VOID) } } =20 -STATIC -INT32 -MakeTree ( - IN INT32 NParm, - IN UINT16 FreqParm[], - OUT UINT8 LenParm[ ], - OUT UINT16 CodeParm[] - ) -/*++ - -Routine Description: - +/** Generates Huffman codes given a frequency distribution of symbols =20 -Arguments: - - NParm - number of symbols - FreqParm - frequency of each symbol - LenParm - code length for each symbol - CodeParm - code for each symbol - -Returns: - - Root of the Huffman tree. - ---*/ + @param NParm number of symbols + @param FreqParm frequency of each symbol + @param LenParm code length for each symbol + @param CodeParm code for each symbol + + @return Root of the Huffman tree. +**/ +STATIC +INT32 +MakeTree ( + IN INT32 NParm, + IN UINT16 FreqParm[], + OUT UINT8 LenParm[ ], + OUT UINT16 CodeParm[] + ) { INT32 Index; INT32 Index2; --=20 2.37.1 (Apple Git-137.1) -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100498): https://edk2.groups.io/g/devel/message/100498 Mute This Topic: https://groups.io/mt/97218959/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun Apr 28 08:41:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100499+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100499+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1677286489; cv=none; d=zohomail.com; s=zohoarc; b=b4UpnAmT0SIHFPNlbsQLOPRzbNfVfKRZiX8BFSzv58Fh6jaxHCJY+l/5Q/czPu5qecIaK74Wd3EDyKvzBXlFRVRE36enbDyq2eKDc+BuupZxzeEHFwy0ZasLEyf9kUafYo1p/rS+nt4o6HFNvrOKg1Ha0mXJaFrNphmInXLN8Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677286489; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cB5phqw6/NPdbcQFq6HzWmjGvna33ny3kXgWN5d4Uag=; b=BTTqnaDryxQPPyrfANdBcgAIeETYO5nd59kK5pzVUF30tcH2ls/IFxPC85EXFA4Xh+prKHrs4R7ewUvQdua5v+SWdvdEDTyyOwYu6ps/5NPidzdhSzl/X0aNhqRSlAonIgbU2lA95EzB7iJJPBxfQbyDeKYxgH2imod+1aU9cHM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100499+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677286489126478.27283130243814; Fri, 24 Feb 2023 16:54:49 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id vwHrYY1788612xwX8m2LCo4b; Fri, 24 Feb 2023 16:54:48 -0800 X-Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mx.groups.io with SMTP id smtpd.web10.35243.1677286488363925028 for ; Fri, 24 Feb 2023 16:54:48 -0800 X-Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 8C4AC32005BC; Fri, 24 Feb 2023 19:54:47 -0500 (EST) X-Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 24 Feb 2023 19:54:47 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekgedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfgvsggv tggtrgcuvehrrghnuceorhgvsggvtggtrgessghsughiohdrtghomheqnecuggftrfgrth htvghrnhepgeffueeuledvgefgvddvgfetvdduhfefkedukeeikedtudekfeetteeifedv leefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprh gvsggvtggtrgessghsughiohdrtghomh X-ME-Proxy: Feedback-ID: i5b994698:Fastmail X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Feb 2023 19:54:46 -0500 (EST) From: "Rebecca Cran" To: devel@edk2.groups.io, Bob Feng , Liming Gao , Yuwei Chen Cc: Rebecca Cran Subject: [edk2-devel] [PATCH 2/3] BaseTools: Replace duplicate __PcdSet prototype with __PcdGet Date: Fri, 24 Feb 2023 17:54:30 -0700 Message-Id: <20230225005431.12173-3-rebecca@bsdio.com> In-Reply-To: <20230225005431.12173-1-rebecca@bsdio.com> References: <20230225005431.12173-1-rebecca@bsdio.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com X-Gm-Message-State: gGqjiEILhPWuAZr1E87omYK7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677286488; bh=FCUjzPeTqVcwjhLrpHumloWztF05c4uGy9Ua5Ma35nA=; h=Cc:Date:From:Reply-To:Subject:To; b=AVdnqhFySUyf76sNbc7vx79EKP4sTfhQRE7L79BK6CaSs3+kudDr00bmnf5crJ9mQXR W7OnOU53WkGQW2w9NhoOj2Hhlfhn7iEfWyuVaLcq3OsGAUT8MZJNpMvocWlzAwKCvFknA UwtpTQExVwbycy3oAD/jiRMaeVVI9UnWRxc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677286491257100010 Content-Type: text/plain; charset="utf-8" Replace the duplicate __PcdSet prototype in PcdValueCommon.h with the prototype for __PcdGet. Signed-off-by: Rebecca Cran Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/PcdValueCommon.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/C/Common/PcdValueCommon.h b/BaseTools/Source/= C/Common/PcdValueCommon.h index 02ef803be479..7dac5bd92dbc 100644 --- a/BaseTools/Source/C/Common/PcdValueCommon.h +++ b/BaseTools/Source/C/Common/PcdValueCommon.h @@ -78,13 +78,12 @@ __PcdSet ( =20 @return PCD value **/ -VOID -__PcdSet ( - CHAR8 *SkuName OPTIONAL, - CHAR8 *DefaultValueName OPTIONAL, - CHAR8 *TokenSpaceGuidName, - CHAR8 *TokenName, - UINT64 Value +UINT64 +__PcdGet ( + CHAR8 *SkuName OPTIONAL, + CHAR8 *DefaultValueName OPTIONAL, + CHAR8 *TokenSpaceGuidName, + CHAR8 *TokenName ) ; =20 --=20 2.37.1 (Apple Git-137.1) -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100499): https://edk2.groups.io/g/devel/message/100499 Mute This Topic: https://groups.io/mt/97218961/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun Apr 28 08:41:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+100500+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100500+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1677286492; cv=none; d=zohomail.com; s=zohoarc; b=cRVtItU9yyhOMXh0jJ64/ihSiEELe/xWhGSf1Ij4dhJi0E7kM6gOq/DjW1UPlRPCa9BKfyP/uEekW9sdAejQCR1u68C5aolvMR3tMeGzYhdc8cUtG4AoewDVAD8eYfc6yAwcqKxR4l84Aj7+CkjOnAkPWt6naKaw6xcdvTu9dHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677286492; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zPFH3eE1sHJ36OBB2zyyrbtxKPpD84FxzWJTwGXwv9E=; b=WDpT4I5VPuvCeE3MbtaKKxWXlcHdBBLr4r7yU4H4j8W05PfihIg5hvQvD10pdE5MZeMcqHH07XyirMWYaWmXJLQP28G/cw5lVjIKjkpoOMjvbPm6drjJld8BtEEZSpikp4XrpZnWQ5GqsTouzXquxKk2bgCX3Q7oSHeeLKQsTQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+100500+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1677286492442845.3249153066439; Fri, 24 Feb 2023 16:54:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uW9fYY1788612xzboMHrFDWG; Fri, 24 Feb 2023 16:54:52 -0800 X-Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mx.groups.io with SMTP id smtpd.web10.35244.1677286490987059198 for ; Fri, 24 Feb 2023 16:54:51 -0800 X-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id EF306320024A; Fri, 24 Feb 2023 19:54:49 -0500 (EST) X-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 24 Feb 2023 19:54:50 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekgedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfgvsggv tggtrgcuvehrrghnuceorhgvsggvtggtrgessghsughiohdrtghomheqnecuggftrfgrth htvghrnhepgeffueeuledvgefgvddvgfetvdduhfefkedukeeikedtudekfeetteeifedv leefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprh gvsggvtggtrgessghsughiohdrtghomh X-ME-Proxy: Feedback-ID: i5b994698:Fastmail X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Feb 2023 19:54:48 -0500 (EST) From: "Rebecca Cran" To: devel@edk2.groups.io, Bob Feng , Liming Gao , Yuwei Chen Cc: Rebecca Cran Subject: [edk2-devel] [PATCH 3/3] BaseTools: Run Uncrustify over files in Source/C/Common Date: Fri, 24 Feb 2023 17:54:31 -0700 Message-Id: <20230225005431.12173-4-rebecca@bsdio.com> In-Reply-To: <20230225005431.12173-1-rebecca@bsdio.com> References: <20230225005431.12173-1-rebecca@bsdio.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com X-Gm-Message-State: S9tkW5FhFsEbKzudsh6tlj48x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1677286492; bh=ej+S9RoqSgw9ddBy/YpvVfnpJP5jj6BzRu+f9FX5Avg=; h=Cc:Date:From:Reply-To:Subject:To; b=SUdGRfzq2/21JeiJ8P7qPfGIiDSx6s0GhQbrWoLzKHQJHuE1D5eubyiBgnqp0axI8iX S2a33ibOUyiXuxUZFKWEfqX1BdZLpycu1ikYHP6MBZrh04uiMGG2PMmUGLKo4/h4WZ3Pe Q1q1TtBW9Dg+i45vjFpxQ37gJumP7bnKb8g= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1677286493509100001 Content-Type: text/plain; charset="utf-8" Reformat the files in Source/C/Common by running Uncrustify on them. Signed-off-by: Rebecca Cran --- BaseTools/Source/C/Common/BinderFuncs.h | 27 +- BaseTools/Source/C/Common/CommonLib.h | 259 +++--- BaseTools/Source/C/Common/Crc32.h | 6 +- BaseTools/Source/C/Common/Decompress.h | 4 +- BaseTools/Source/C/Common/EfiUtilityMsgs.h | 38 +- BaseTools/Source/C/Common/FirmwareVolumeBufferLib.h | 101 ++- BaseTools/Source/C/Common/FvLib.h | 51 +- BaseTools/Source/C/Common/MemoryFile.h | 16 +- BaseTools/Source/C/Common/MyAlloc.h | 50 +- BaseTools/Source/C/Common/OsPath.h | 14 +- BaseTools/Source/C/Common/ParseGuidedSectionTools.h | 12 +- BaseTools/Source/C/Common/ParseInf.h | 28 +- BaseTools/Source/C/Common/PcdValueCommon.h | 22 +- BaseTools/Source/C/Common/PeCoffLib.h | 66 +- BaseTools/Source/C/Common/SimpleFileParsing.h | 24 +- BaseTools/Source/C/Common/StringFuncs.h | 42 +- BaseTools/Source/C/Common/WinNtInclude.h | 28 +- BaseTools/Source/C/Common/BasePeCoff.c | 868 ++++++++++------= ---- BaseTools/Source/C/Common/BinderFuncs.c | 31 +- BaseTools/Source/C/Common/CommonLib.c | 584 +++++++------ BaseTools/Source/C/Common/Crc32.c | 8 +- BaseTools/Source/C/Common/Decompress.c | 325 ++++---- BaseTools/Source/C/Common/EfiCompress.c | 679 ++++++++------- BaseTools/Source/C/Common/EfiUtilityMsgs.c | 173 ++-- BaseTools/Source/C/Common/FirmwareVolumeBuffer.c | 617 +++++++------- BaseTools/Source/C/Common/FvLib.c | 261 +++--- BaseTools/Source/C/Common/MemoryFile.c | 55 +- BaseTools/Source/C/Common/MyAlloc.c | 110 +-- BaseTools/Source/C/Common/OsPath.c | 91 +- BaseTools/Source/C/Common/ParseGuidedSectionTools.c | 54 +- BaseTools/Source/C/Common/ParseInf.c | 184 +++-- BaseTools/Source/C/Common/PcdValueCommon.c | 315 +++---- BaseTools/Source/C/Common/PeCoffLoaderEx.c | 217 +++-- BaseTools/Source/C/Common/SimpleFileParsing.c | 325 ++++---- BaseTools/Source/C/Common/StringFuncs.c | 90 +- BaseTools/Source/C/Common/TianoCompress.c | 477 +++++------ 36 files changed, 3269 insertions(+), 2983 deletions(-) diff --git a/BaseTools/Source/C/Common/BinderFuncs.h b/BaseTools/Source/C/C= ommon/BinderFuncs.h index ceaa9cd318ff..138356d340df 100644 --- a/BaseTools/Source/C/Common/BinderFuncs.h +++ b/BaseTools/Source/C/Common/BinderFuncs.h @@ -22,40 +22,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 VOID * CommonLibBinderAllocate ( - IN UINTN Size + IN UINTN Size ); =20 VOID CommonLibBinderFree ( - IN VOID *Pointer + IN VOID *Pointer ); =20 VOID CommonLibBinderCopyMem ( - IN VOID *Destination, - IN VOID *Source, - IN UINTN Length + IN VOID *Destination, + IN VOID *Source, + IN UINTN Length ); =20 VOID CommonLibBinderSetMem ( - IN VOID *Destination, - IN UINTN Length, - IN UINT8 Value + IN VOID *Destination, + IN UINTN Length, + IN UINT8 Value ); =20 INTN CommonLibBinderCompareMem ( - IN VOID *MemOne, - IN VOID *MemTwo, - IN UINTN Length + IN VOID *MemOne, + IN VOID *MemTwo, + IN UINTN Length ); =20 BOOLEAN CommonLibBinderCompareGuid ( - IN EFI_GUID *Guid1, - IN EFI_GUID *Guid2 + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 ); =20 #endif // #ifndef CommonLibs_h_INCLUDED - diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Com= mon/CommonLib.h index a841029c2aaa..65a3c2ebd783 100644 --- a/BaseTools/Source/C/Common/CommonLib.h +++ b/BaseTools/Source/C/Common/CommonLib.h @@ -13,35 +13,35 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #ifndef _WIN32 -#include + #include #endif =20 #define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination =20 #ifdef PATH_MAX -#define MAX_LONG_FILE_PATH PATH_MAX +#define MAX_LONG_FILE_PATH PATH_MAX #else -#define MAX_LONG_FILE_PATH 500 +#define MAX_LONG_FILE_PATH 500 #endif =20 -#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL) -#define MAX_UINT32 ((UINT32)0xFFFFFFFF) +#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL) +#define MAX_UINT32 ((UINT32)0xFFFFFFFF) #define MAX_UINT16 ((UINT16)0xFFFF) #define MAX_UINT8 ((UINT8)0xFF) -#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0])) -#define ASCII_RSIZE_MAX 1000000 +#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0])) +#define ASCII_RSIZE_MAX 1000000 #undef RSIZE_MAX -#define RSIZE_MAX 1000000 +#define RSIZE_MAX 1000000 =20 -#define IS_COMMA(a) ((a) =3D=3D L',') -#define IS_HYPHEN(a) ((a) =3D=3D L'-') -#define IS_DOT(a) ((a) =3D=3D L'.') -#define IS_LEFT_PARENTH(a) ((a) =3D=3D L'(') -#define IS_RIGHT_PARENTH(a) ((a) =3D=3D L')') -#define IS_SLASH(a) ((a) =3D=3D L'/') -#define IS_NULL(a) ((a) =3D=3D L'\0') +#define IS_COMMA(a) ((a) =3D=3D L',') +#define IS_HYPHEN(a) ((a) =3D=3D L'-') +#define IS_DOT(a) ((a) =3D=3D L'.') +#define IS_LEFT_PARENTH(a) ((a) =3D=3D L'(') +#define IS_RIGHT_PARENTH(a) ((a) =3D=3D L')') +#define IS_SLASH(a) ((a) =3D=3D L'/') +#define IS_NULL(a) ((a) =3D=3D L'\0') =20 -#define ASSERT(x) assert(x) +#define ASSERT(x) assert(x) =20 #ifdef __cplusplus extern "C" { @@ -82,8 +82,8 @@ CopyMem ( =20 INTN CompareGuid ( - IN EFI_GUID *Guid1, - IN EFI_GUID *Guid2 + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 ) ; =20 @@ -117,64 +117,64 @@ Routine Description: **/ EFI_STATUS PutFileImage ( - IN CHAR8 *OutputFileName, - IN CHAR8 *OutputFileImage, - IN UINT32 BytesToWrite + IN CHAR8 *OutputFileName, + IN CHAR8 *OutputFileImage, + IN UINT32 BytesToWrite ) ; =20 UINT8 CalculateChecksum8 ( - IN UINT8 *Buffer, - IN UINTN Size + IN UINT8 *Buffer, + IN UINTN Size ) ; =20 UINT8 CalculateSum8 ( - IN UINT8 *Buffer, - IN UINTN Size + IN UINT8 *Buffer, + IN UINTN Size ) ; =20 UINT16 CalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) ; =20 UINT16 CalculateSum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) ; =20 EFI_STATUS PrintGuid ( - IN EFI_GUID *Guid + IN EFI_GUID *Guid ) ; =20 #define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination EFI_STATUS PrintGuidToBuffer ( - IN EFI_GUID *Guid, - IN OUT UINT8 *Buffer, - IN UINT32 BufferLen, - IN BOOLEAN Uppercase + IN EFI_GUID *Guid, + IN OUT UINT8 *Buffer, + IN UINT32 BufferLen, + IN BOOLEAN Uppercase ) ; =20 CHAR8 * LongFilePath ( - IN CHAR8 *FileName -); + IN CHAR8 *FileName + ); =20 UINTN StrLen ( - CONST CHAR16 *String + CONST CHAR16 *String ); =20 VOID * @@ -185,177 +185,178 @@ AllocateCopyPool ( =20 INTN StrnCmp ( - CONST CHAR16 *FirstString, - CONST CHAR16 *SecondString, - UINTN Length + CONST CHAR16 *FirstString, + CONST CHAR16 *SecondString, + UINTN Length ); =20 RETURN_STATUS StrToGuid ( - CONST CHAR16 *String, - EFI_GUID *Guid + CONST CHAR16 *String, + EFI_GUID *Guid ); =20 RETURN_STATUS StrHexToBytes ( - CONST CHAR16 *String, - UINTN Length, - UINT8 *Buffer, - UINTN MaxBufferSize + CONST CHAR16 *String, + UINTN Length, + UINT8 *Buffer, + UINTN MaxBufferSize ); =20 UINTN InternalHexCharToUintn ( - CHAR16 Char + CHAR16 Char ); =20 VOID * InternalAllocateCopyPool ( - UINTN AllocationSize, - CONST VOID *Buffer + UINTN AllocationSize, + CONST VOID *Buffer ); =20 BOOLEAN InternalIsDecimalDigitCharacter ( - CHAR16 Char + CHAR16 Char ); =20 UINT32 SwapBytes32 ( - UINT32 Value + UINT32 Value ); =20 UINT16 SwapBytes16 ( - UINT16 Value + UINT16 Value ); =20 EFI_GUID * CopyGuid ( - EFI_GUID *DestinationGuid, - CONST EFI_GUID *SourceGuid + EFI_GUID *DestinationGuid, + CONST EFI_GUID *SourceGuid ); =20 UINT64 WriteUnaligned64 ( - UINT64 *Buffer, - UINT64 Value + UINT64 *Buffer, + UINT64 Value ); =20 UINT64 ReadUnaligned64 ( - CONST UINT64 *Buffer + CONST UINT64 *Buffer ); =20 UINTN StrSize ( - CONST CHAR16 *String + CONST CHAR16 *String ); =20 UINT64 StrHexToUint64 ( - CONST CHAR16 *String + CONST CHAR16 *String ); =20 UINT64 StrDecimalToUint64 ( - CONST CHAR16 *String + CONST CHAR16 *String ); =20 RETURN_STATUS StrHexToUint64S ( - CONST CHAR16 *String, - CHAR16 **EndPointer, - UINT64 *Data + CONST CHAR16 *String, + CHAR16 **EndPointer, + UINT64 *Data ); =20 RETURN_STATUS StrDecimalToUint64S ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINT64 *Data + CONST CHAR16 *String, + CHAR16 **EndPointer, OPTIONAL + UINT64 *Data ); =20 VOID * ReallocatePool ( - UINTN OldSize, - UINTN NewSize, - VOID *OldBuffer OPTIONAL + UINTN OldSize, + UINTN NewSize, + VOID *OldBuffer OPTIONAL ); =20 VOID * InternalReallocatePool ( - UINTN OldSize, - UINTN NewSize, - VOID *OldBuffer OPTIONAL + UINTN OldSize, + UINTN NewSize, + VOID *OldBuffer OPTIONAL ); =20 VOID * InternalAllocateZeroPool ( - UINTN AllocationSize - ) ; + UINTN AllocationSize + ); =20 VOID * InternalAllocatePool ( - UINTN AllocationSize + UINTN AllocationSize ); =20 UINTN StrnLenS ( - CONST CHAR16 *String, - UINTN MaxSize + CONST CHAR16 *String, + UINTN MaxSize ); =20 CHAR16 InternalCharToUpper ( - CHAR16 Char + CHAR16 Char ); =20 INTN StrCmp ( - CONST CHAR16 *FirstString, - CONST CHAR16 *SecondString + CONST CHAR16 *FirstString, + CONST CHAR16 *SecondString ); =20 UINT64 SwapBytes64 ( - UINT64 Value + UINT64 Value ); =20 UINT64 InternalMathSwapBytes64 ( - UINT64 Operand + UINT64 Operand ); =20 RETURN_STATUS StrToIpv4Address ( - CONST CHAR16 *String, - CHAR16 **EndPointer, - EFI_IPv4_ADDRESS *Address, - UINT8 *PrefixLength + CONST CHAR16 *String, + CHAR16 **EndPointer, + EFI_IPv4_ADDRESS *Address, + UINT8 *PrefixLength ); =20 RETURN_STATUS StrToIpv6Address ( - CONST CHAR16 *String, - CHAR16 **EndPointer, - EFI_IPv6_ADDRESS *Address, - UINT8 *PrefixLength + CONST CHAR16 *String, + CHAR16 **EndPointer, + EFI_IPv6_ADDRESS *Address, + UINT8 *PrefixLength ); =20 RETURN_STATUS StrCpyS ( - CHAR16 *Destination, - UINTN DestMax, - CONST CHAR16 *Source + CHAR16 *Destination, + UINTN DestMax, + CONST CHAR16 *Source ); =20 RETURN_STATUS UnicodeStrToAsciiStrS ( - CONST CHAR16 *Source, - CHAR8 *Destination, - UINTN DestMax + CONST CHAR16 *Source, + CHAR8 *Destination, + UINTN DestMax ); + VOID * AllocatePool ( UINTN AllocationSize @@ -363,13 +364,13 @@ AllocatePool ( =20 UINT16 WriteUnaligned16 ( - UINT16 *Buffer, - UINT16 Value + UINT16 *Buffer, + UINT16 Value ); =20 UINT16 ReadUnaligned16 ( - CONST UINT16 *Buffer + CONST UINT16 *Buffer ); =20 VOID * @@ -379,15 +380,15 @@ AllocateZeroPool ( =20 BOOLEAN InternalIsHexaDecimalDigitCharacter ( - CHAR16 Char + CHAR16 Char ); =20 BOOLEAN InternalSafeStringIsOverlap ( - IN VOID *Base1, - IN UINTN Size1, - IN VOID *Base2, - IN UINTN Size2 + IN VOID *Base1, + IN UINTN Size1, + IN VOID *Base2, + IN UINTN Size2 ); =20 BOOLEAN @@ -400,30 +401,30 @@ InternalSafeStringNoStrOverlap ( =20 BOOLEAN IsHexStr ( - CHAR16 *Str + CHAR16 *Str ); =20 UINTN Strtoi ( - CHAR16 *Str + CHAR16 *Str ); =20 VOID Strtoi64 ( - CHAR16 *Str, - UINT64 *Data + CHAR16 *Str, + UINT64 *Data ); =20 VOID StrToAscii ( - CHAR16 *Str, - CHAR8 **AsciiStr + CHAR16 *Str, + CHAR8 **AsciiStr ); =20 CHAR16 * SplitStr ( - CHAR16 **List, - CHAR16 Separator + CHAR16 **List, + CHAR16 Separator ); =20 /*++ @@ -444,26 +445,34 @@ Routine Description: #endif =20 #ifdef __GNUC__ -#include -#include -#define stricmp strcasecmp -#define _stricmp strcasecmp -#define strnicmp strncasecmp -#define strcmpi strcasecmp -size_t _filelength(int fd); -#ifndef __CYGWIN__ -char *strlwr(char *s); -#endif + #include + #include +#define stricmp strcasecmp +#define _stricmp strcasecmp +#define strnicmp strncasecmp +#define strcmpi strcasecmp +size_t +_filelength ( + int fd + ); + + #ifndef __CYGWIN__ +char * +strlwr ( + char *s + ); + + #endif #endif =20 // // On windows, mkdir only has one parameter. // On unix, it has two parameters // -#if defined(__GNUC__) -#define mkdir(dir, perm) mkdir(dir, perm) +#if defined (__GNUC__) +#define mkdir(dir, perm) mkdir(dir, perm) #else -#define mkdir(dir, perm) mkdir(dir) +#define mkdir(dir, perm) mkdir(dir) #endif =20 #endif diff --git a/BaseTools/Source/C/Common/Crc32.h b/BaseTools/Source/C/Common/= Crc32.h index 3f6b5b35fc36..a5946f961d45 100644 --- a/BaseTools/Source/C/Common/Crc32.h +++ b/BaseTools/Source/C/Common/Crc32.h @@ -24,9 +24,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ EFI_STATUS CalculateCrc32 ( - IN UINT8 *Data, - IN UINTN DataSize, - IN OUT UINT32 *CrcOut + IN UINT8 *Data, + IN UINTN DataSize, + IN OUT UINT32 *CrcOut ) ; =20 diff --git a/BaseTools/Source/C/Common/Decompress.h b/BaseTools/Source/C/Co= mmon/Decompress.h index 00a1e31b8c21..81460cf1d6c6 100644 --- a/BaseTools/Source/C/Common/Decompress.h +++ b/BaseTools/Source/C/Common/Decompress.h @@ -127,8 +127,8 @@ EFI_STATUS Extract ( IN VOID *Source, IN UINT32 SrcSize, - OUT VOID **Destination, - OUT UINT32 *DstSize, + OUT VOID **Destination, + OUT UINT32 *DstSize, IN UINTN Algorithm ); =20 diff --git a/BaseTools/Source/C/Common/EfiUtilityMsgs.h b/BaseTools/Source/= C/Common/EfiUtilityMsgs.h index 85f018cbad1c..ffdac5bd9e14 100644 --- a/BaseTools/Source/C/Common/EfiUtilityMsgs.h +++ b/BaseTools/Source/C/Common/EfiUtilityMsgs.h @@ -14,11 +14,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Log message print Level // -#define VERBOSE_LOG_LEVEL 15 -#define WARNING_LOG_LEVEL 15 -#define INFO_LOG_LEVEL 20 -#define KEY_LOG_LEVEL 40 -#define ERROR_LOG_LEVLE 50 +#define VERBOSE_LOG_LEVEL 15 +#define WARNING_LOG_LEVEL 15 +#define INFO_LOG_LEVEL 20 +#define KEY_LOG_LEVEL 40 +#define ERROR_LOG_LEVLE 50 =20 // // Status codes returned by EFI utility programs and functions @@ -26,12 +26,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define STATUS_SUCCESS 0 #define STATUS_WARNING 1 #define STATUS_ERROR 2 -#define VOID void +#define VOID void =20 typedef int STATUS; =20 -#define MAX_LINE_LEN 0x200 -#define MAXIMUM_INPUT_FILE_NUM 10 +#define MAX_LINE_LEN 0x200 +#define MAXIMUM_INPUT_FILE_NUM 10 =20 #ifdef __cplusplus extern "C" { @@ -53,19 +53,19 @@ GetUtilityStatus ( // VOID SetUtilityName ( - CHAR8 *ProgramName + CHAR8 *ProgramName ) ; =20 VOID PrintMessage ( - CHAR8 *Type, - CHAR8 *FileName, - UINT32 LineNumber, - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - va_list List + CHAR8 *Type, + CHAR8 *FileName, + UINT32 LineNumber, + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + va_list List ); =20 VOID @@ -103,19 +103,19 @@ DebugMsg ( =20 VOID VerboseMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ); =20 VOID NormalMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ); =20 VOID KeyMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ); =20 diff --git a/BaseTools/Source/C/Common/FirmwareVolumeBufferLib.h b/BaseTool= s/Source/C/Common/FirmwareVolumeBufferLib.h index 6b1caba993dc..c725a6c4145d 100644 --- a/BaseTools/Source/C/Common/FirmwareVolumeBufferLib.h +++ b/BaseTools/Source/C/Common/FirmwareVolumeBufferLib.h @@ -15,149 +15,148 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 EFI_STATUS FvBufAddFile ( - IN OUT VOID *Fv, - IN VOID *File + IN OUT VOID *Fv, + IN VOID *File ); =20 EFI_STATUS FvBufAddFileWithExtend ( - IN OUT VOID **Fv, - IN VOID *File + IN OUT VOID **Fv, + IN VOID *File ); =20 EFI_STATUS FvBufAddVtfFile ( - IN OUT VOID *Fv, - IN VOID *File + IN OUT VOID *Fv, + IN VOID *File ); =20 EFI_STATUS FvBufChecksumFile ( - IN OUT VOID *FfsFile + IN OUT VOID *FfsFile ); =20 EFI_STATUS FvBufChecksumHeader ( - IN OUT VOID *Fv + IN OUT VOID *Fv ); =20 EFI_STATUS FvBufClearAllFiles ( - IN OUT VOID *Fv + IN OUT VOID *Fv ); =20 VOID FvBufCompact3ByteSize ( - OUT VOID* SizeDest, - IN UINT32 Size + OUT VOID *SizeDest, + IN UINT32 Size ); =20 EFI_STATUS FvBufCountSections ( - IN VOID* FfsFile, - IN UINTN* Count + IN VOID *FfsFile, + IN UINTN *Count ); =20 EFI_STATUS FvBufDuplicate ( - IN VOID *SourceFv, - IN OUT VOID **DestinationFv + IN VOID *SourceFv, + IN OUT VOID **DestinationFv ); =20 UINT32 FvBufExpand3ByteSize ( - IN VOID* Size + IN VOID *Size ); =20 UINT32 FvBufGetFfsFileSize ( - IN EFI_FFS_FILE_HEADER *Ffs + IN EFI_FFS_FILE_HEADER *Ffs ); =20 UINT32 FvBufGetFfsHeaderSize ( - IN EFI_FFS_FILE_HEADER *Ffs + IN EFI_FFS_FILE_HEADER *Ffs ); =20 EFI_STATUS FvBufExtend ( - IN VOID **Fv, - IN UINTN Size + IN VOID **Fv, + IN UINTN Size ); =20 EFI_STATUS FvBufFindFileByName ( - IN VOID *Fv, - IN EFI_GUID *Name, - OUT VOID **File + IN VOID *Fv, + IN EFI_GUID *Name, + OUT VOID **File ); =20 EFI_STATUS FvBufFindFileByType ( - IN VOID *Fv, - IN EFI_FV_FILETYPE Type, - OUT VOID **File + IN VOID *Fv, + IN EFI_FV_FILETYPE Type, + OUT VOID **File ); =20 EFI_STATUS FvBufFindNextFile ( - IN VOID *Fv, - IN OUT UINTN *Key, - OUT VOID **File + IN VOID *Fv, + IN OUT UINTN *Key, + OUT VOID **File ); =20 EFI_STATUS FvBufFindNextSection ( - IN VOID *SectionsStart, - IN UINTN TotalSectionsSize, - IN OUT UINTN *Key, - OUT VOID **Section + IN VOID *SectionsStart, + IN UINTN TotalSectionsSize, + IN OUT UINTN *Key, + OUT VOID **Section ); =20 EFI_STATUS FvBufFindSectionByType ( - IN VOID *FfsFile, - IN UINT8 Type, - OUT VOID **Section + IN VOID *FfsFile, + IN UINT8 Type, + OUT VOID **Section ); =20 EFI_STATUS FvBufGetFileRawData ( - IN VOID* FfsFile, - OUT VOID** RawData, - OUT UINTN* RawDataSize + IN VOID *FfsFile, + OUT VOID **RawData, + OUT UINTN *RawDataSize ); =20 EFI_STATUS FvBufGetSize ( - IN VOID *Fv, - OUT UINTN *Size + IN VOID *Fv, + OUT UINTN *Size ); =20 EFI_STATUS FvBufPackageFreeformRawFile ( - IN EFI_GUID* Filename, - IN VOID* RawData, - IN UINTN RawDataSize, - OUT VOID** FfsFile + IN EFI_GUID *Filename, + IN VOID *RawData, + IN UINTN RawDataSize, + OUT VOID **FfsFile ); =20 EFI_STATUS FvBufRemoveFile ( - IN OUT VOID *Fv, - IN EFI_GUID *Name + IN OUT VOID *Fv, + IN EFI_GUID *Name ); =20 EFI_STATUS FvBufUnifyBlockSizes ( - IN OUT VOID *Fv, - IN UINTN BlockSize + IN OUT VOID *Fv, + IN UINTN BlockSize ); =20 EFI_STATUS FvBufShrinkWrap ( - IN VOID *Fv + IN VOID *Fv ); =20 #endif // #ifndef FirmwareVolumeBuffer_h_INCLUDED - diff --git a/BaseTools/Source/C/Common/FvLib.h b/BaseTools/Source/C/Common/= FvLib.h index 815df6f802c4..f27888a14da0 100644 --- a/BaseTools/Source/C/Common/FvLib.h +++ b/BaseTools/Source/C/Common/FvLib.h @@ -20,8 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 EFI_STATUS InitializeFvLib ( - IN VOID *Fv, - IN UINT32 FvLength + IN VOID *Fv, + IN UINT32 FvLength ) ; =20 @@ -34,71 +34,72 @@ GetFvHeader ( =20 EFI_STATUS GetNextFile ( - IN EFI_FFS_FILE_HEADER *CurrentFile, - OUT EFI_FFS_FILE_HEADER **NextFile + IN EFI_FFS_FILE_HEADER *CurrentFile, + OUT EFI_FFS_FILE_HEADER **NextFile ) ; =20 EFI_STATUS GetFileByName ( - IN EFI_GUID *FileName, - OUT EFI_FFS_FILE_HEADER **File + IN EFI_GUID *FileName, + OUT EFI_FFS_FILE_HEADER **File ) ; =20 EFI_STATUS GetFileByType ( - IN EFI_FV_FILETYPE FileType, - IN UINTN Instance, - OUT EFI_FFS_FILE_HEADER **File + IN EFI_FV_FILETYPE FileType, + IN UINTN Instance, + OUT EFI_FFS_FILE_HEADER **File ) ; =20 EFI_STATUS GetSectionByType ( - IN EFI_FFS_FILE_HEADER *File, - IN EFI_SECTION_TYPE SectionType, - IN UINTN Instance, - OUT EFI_FILE_SECTION_POINTER *Section + IN EFI_FFS_FILE_HEADER *File, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_FILE_SECTION_POINTER *Section ) ; + // // will not parse compressed sections // EFI_STATUS VerifyFv ( - IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader ) ; =20 EFI_STATUS VerifyFfsFile ( - IN EFI_FFS_FILE_HEADER *FfsHeader + IN EFI_FFS_FILE_HEADER *FfsHeader ) ; =20 UINT32 GetFfsFileLength ( - EFI_FFS_FILE_HEADER *FfsHeader + EFI_FFS_FILE_HEADER *FfsHeader ) ; =20 UINT32 GetSectionFileLength ( - EFI_COMMON_SECTION_HEADER *SectionHeader + EFI_COMMON_SECTION_HEADER *SectionHeader ) ; =20 UINT32 -GetFfsHeaderLength( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) +GetFfsHeaderLength ( + IN EFI_FFS_FILE_HEADER *FfsHeader + ) ; =20 UINT32 -GetSectionHeaderLength( - IN EFI_COMMON_SECTION_HEADER *SectionHeader - ) +GetSectionHeaderLength ( + IN EFI_COMMON_SECTION_HEADER *SectionHeader + ) ; =20 /*++ @@ -120,7 +121,7 @@ Routine Description: --*/ UINT32 GetLength ( - UINT8 *ThreeByteLength + UINT8 *ThreeByteLength ) ; =20 @@ -141,7 +142,7 @@ Routine Description: --*/ EFI_STATUS GetErasePolarity ( - OUT BOOLEAN *ErasePolarity + OUT BOOLEAN *ErasePolarity ) ; =20 diff --git a/BaseTools/Source/C/Common/MemoryFile.h b/BaseTools/Source/C/Co= mmon/MemoryFile.h index c84848cf15d6..309aa57ed000 100644 --- a/BaseTools/Source/C/Common/MemoryFile.h +++ b/BaseTools/Source/C/Common/MemoryFile.h @@ -17,12 +17,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Common data structures // typedef struct { - CHAR8 *FileImage; - CHAR8 *Eof; - CHAR8 *CurrentFilePointer; + CHAR8 *FileImage; + CHAR8 *Eof; + CHAR8 *CurrentFilePointer; } MEMORY_FILE; =20 - // // Functions declarations // @@ -39,8 +38,8 @@ typedef struct { **/ EFI_STATUS GetMemoryFile ( - IN CHAR8 *InputFileName, - OUT EFI_HANDLE *OutputMemoryFile + IN CHAR8 *InputFileName, + OUT EFI_HANDLE *OutputMemoryFile ) ; =20 @@ -53,7 +52,7 @@ GetMemoryFile ( **/ EFI_STATUS FreeMemoryFile ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ) ; =20 @@ -71,9 +70,8 @@ FreeMemoryFile ( **/ CHAR8 * ReadMemoryFileLine ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ) ; =20 - #endif diff --git a/BaseTools/Source/C/Common/MyAlloc.h b/BaseTools/Source/C/Commo= n/MyAlloc.h index de3323d30d97..3bdaeb63d485 100644 --- a/BaseTools/Source/C/Common/MyAlloc.h +++ b/BaseTools/Source/C/Common/MyAlloc.h @@ -22,29 +22,29 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // your project. // #ifndef USE_MYALLOC -#define USE_MYALLOC 1 +#define USE_MYALLOC 1 #endif =20 #if USE_MYALLOC // // Replace C library allocation routines with MyAlloc routines. // -#define malloc(size) MyAlloc ((size), __FILE__, __LINE__) -#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__) -#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__) -#define free(ptr) MyFree ((ptr), __FILE__, __LINE__) -#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__) +#define malloc(size) MyAlloc ((size), __FILE__, __LINE__) +#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__) +#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__) +#define free(ptr) MyFree ((ptr), __FILE__, __LINE__) +#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__) =20 // // Structure for checking/tracking memory allocations. // typedef struct MyAllocStruct { - UINTN Cksum; - struct MyAllocStruct *Next; - UINTN Line; - UINTN Size; - UINT8 *File; - UINT8 *Buffer; + UINTN Cksum; + struct MyAllocStruct *Next; + UINTN Line; + UINTN Size; + UINT8 *File; + UINT8 *Buffer; } MY_ALLOC_STRUCT; // // Cksum :=3D (UINTN)This + (UINTN)Next + Line + Size + (UINTN)File + @@ -84,9 +84,9 @@ typedef struct MyAllocStruct { **/ VOID MyCheck ( - BOOLEAN Final, - UINT8 File[], - UINTN Line + BOOLEAN Final, + UINT8 File[], + UINTN Line ) ; =20 @@ -105,9 +105,9 @@ MyCheck ( **/ VOID * MyAlloc ( - UINTN Size, - UINT8 File[], - UINTN Line + UINTN Size, + UINT8 File[], + UINTN Line ) ; =20 @@ -126,10 +126,10 @@ MyAlloc ( **/ VOID * MyRealloc ( - VOID *Ptr, - UINTN Size, - UINT8 File[], - UINTN Line + VOID *Ptr, + UINTN Size, + UINT8 File[], + UINTN Line ) ; =20 @@ -144,9 +144,9 @@ MyRealloc ( **/ VOID MyFree ( - VOID *Ptr, - UINT8 File[], - UINTN Line + VOID *Ptr, + UINT8 File[], + UINTN Line ) ; =20 diff --git a/BaseTools/Source/C/Common/OsPath.h b/BaseTools/Source/C/Common= /OsPath.h index b1881c4a1ec7..c776901280ac 100644 --- a/BaseTools/Source/C/Common/OsPath.h +++ b/BaseTools/Source/C/Common/OsPath.h @@ -33,9 +33,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 @return NULL if error **/ -CHAR8* +CHAR8 * OsPathDirName ( - IN CHAR8 *FilePath + IN CHAR8 *FilePath ) ; =20 @@ -54,7 +54,7 @@ OsPathDirName ( **/ VOID OsPathNormPathInPlace ( - IN CHAR8 *Path + IN CHAR8 *Path ) ; =20 @@ -73,10 +73,10 @@ OsPathNormPathInPlace ( =20 @return A CHAR8* string, which must be freed by the caller **/ -CHAR8* +CHAR8 * OsPathPeerFilePath ( - IN CHAR8 *OldPath, - IN CHAR8 *Peer + IN CHAR8 *OldPath, + IN CHAR8 *Peer ) ; =20 @@ -90,7 +90,7 @@ OsPathPeerFilePath ( **/ BOOLEAN OsPathExists ( - IN CHAR8 *InputFileName + IN CHAR8 *InputFileName ) ; =20 diff --git a/BaseTools/Source/C/Common/ParseGuidedSectionTools.h b/BaseTool= s/Source/C/Common/ParseGuidedSectionTools.h index 2180bbd0740f..22fa5948fee4 100644 --- a/BaseTools/Source/C/Common/ParseGuidedSectionTools.h +++ b/BaseTools/Source/C/Common/ParseGuidedSectionTools.h @@ -29,7 +29,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ EFI_HANDLE ParseGuidedSectionToolsFile ( - IN CHAR8 *InputFile + IN CHAR8 *InputFile ) ; =20 @@ -47,7 +47,7 @@ ParseGuidedSectionToolsFile ( **/ EFI_HANDLE ParseGuidedSectionToolsMemoryFile ( - IN EFI_HANDLE InputFile + IN EFI_HANDLE InputFile ) ; =20 @@ -62,10 +62,10 @@ ParseGuidedSectionToolsMemoryFile ( @retval Non-NULL The tool to use to access the section contents. (The c= aller must free the memory associated with this string.) **/ -CHAR8* +CHAR8 * LookupGuidedSectionToolPath ( - IN EFI_HANDLE ParsedGuidedSectionToolsHandle, - IN EFI_GUID *SectionGuid + IN EFI_HANDLE ParsedGuidedSectionToolsHandle, + IN EFI_GUID *SectionGuid ) ; =20 @@ -80,7 +80,7 @@ LookupGuidedSectionToolPath ( **/ EFI_STATUS FreeParsedGuidedSectionToolsHandle ( - IN EFI_HANDLE ParsedGuidedSectionToolsHandle + IN EFI_HANDLE ParsedGuidedSectionToolsHandle ) ; =20 diff --git a/BaseTools/Source/C/Common/ParseInf.h b/BaseTools/Source/C/Comm= on/ParseInf.h index a0881a5c9ed0..aa612f6fb730 100644 --- a/BaseTools/Source/C/Common/ParseInf.h +++ b/BaseTools/Source/C/Common/ParseInf.h @@ -38,9 +38,9 @@ extern "C" { **/ CHAR8 * ReadLine ( - IN MEMORY_FILE *InputFile, - IN OUT CHAR8 *InputBuffer, - IN UINTN MaxLength + IN MEMORY_FILE *InputFile, + IN OUT CHAR8 *InputBuffer, + IN UINTN MaxLength ) ; =20 @@ -56,8 +56,8 @@ ReadLine ( **/ BOOLEAN FindSection ( - IN MEMORY_FILE *InputFile, - IN CHAR8 *Section + IN MEMORY_FILE *InputFile, + IN CHAR8 *Section ) ; =20 @@ -78,11 +78,11 @@ FindSection ( **/ EFI_STATUS FindToken ( - IN MEMORY_FILE *InputFile, - IN CHAR8 *Section, - IN CHAR8 *Token, - IN UINTN Instance, - OUT CHAR8 *Value + IN MEMORY_FILE *InputFile, + IN CHAR8 *Section, + IN CHAR8 *Token, + IN UINTN Instance, + OUT CHAR8 *Value ) ; =20 @@ -98,8 +98,8 @@ FindToken ( **/ EFI_STATUS StringToGuid ( - IN CHAR8 *AsciiGuidBuffer, - OUT EFI_GUID *GuidBuffer + IN CHAR8 *AsciiGuidBuffer, + OUT EFI_GUID *GuidBuffer ) ; =20 @@ -152,8 +152,8 @@ ReadLineInStream ( **/ BOOLEAN FindSectionInStream ( - IN FILE *InputFile, - IN CHAR8 *Section + IN FILE *InputFile, + IN CHAR8 *Section ) ; =20 diff --git a/BaseTools/Source/C/Common/PcdValueCommon.h b/BaseTools/Source/= C/Common/PcdValueCommon.h index 7dac5bd92dbc..3f4d35cf8f71 100644 --- a/BaseTools/Source/C/Common/PcdValueCommon.h +++ b/BaseTools/Source/C/Common/PcdValueCommon.h @@ -12,16 +12,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 -#define __FIELD_SIZE(TYPE, Field) (sizeof((TYPE *)0)->Field) -#define __ARRAY_ELEMENT_SIZE(TYPE, Field) (sizeof((TYPE *)0)->Field[0]) -#define __OFFSET_OF(TYPE, Field) ((UINT32)(size_t) &(((TYPE *)0)->Field)) -#define __FLEXIBLE_SIZE(Size, TYPE, Field, MaxIndex) if (__FIELD_SIZE(TY= PE, Field) =3D=3D 0) Size =3D MAX((__OFFSET_OF(TYPE, Field) + __ARRAY_ELEME= NT_SIZE(TYPE, Field) * (MaxIndex)), Size) -#define __ARRAY_SIZE(Array) (sizeof(Array)/sizeof(Array[0])) +#define __FIELD_SIZE(TYPE, Field) (sizeof((TYPE *)0)->= Field) +#define __ARRAY_ELEMENT_SIZE(TYPE, Field) (sizeof((TYPE *)0)->= Field[0]) +#define __OFFSET_OF(TYPE, Field) ((UINT32)(size_t) &(= ((TYPE *)0)->Field)) +#define __FLEXIBLE_SIZE(Size, TYPE, Field, MaxIndex) if (__FIELD_SIZE(TYP= E, Field) =3D=3D 0) Size =3D MAX((__OFFSET_OF(TYPE, Field) + __ARRAY_ELEMEN= T_SIZE(TYPE, Field) * (MaxIndex)), Size) +#define __ARRAY_SIZE(Array) (sizeof(Array)/sizeo= f(Array[0])) =20 -#if defined(_MSC_EXTENSIONS) -#define __STATIC_ASSERT static_assert +#if defined (_MSC_EXTENSIONS) +#define __STATIC_ASSERT static_assert #else -#define __STATIC_ASSERT _Static_assert +#define __STATIC_ASSERT _Static_assert #endif =20 /** @@ -129,9 +129,9 @@ __PcdSetPtr ( ) ; =20 -#define PcdGet(A, B, C, D) __PcdGet(#A, #B, #C, #D) -#define PcdSet(A, B, C, D, Value) __PcdSet(#A, #B, #C, #D, Value) -#define PcdGetPtr(A, B, C, D, Size) __PcdGetPtr(#A, #B, #C, #D, Size) +#define PcdGet(A, B, C, D) __PcdGet(#A, #B, #C, #D) +#define PcdSet(A, B, C, D, Value) __PcdSet(#A, #B, #C, #D, Value) +#define PcdGetPtr(A, B, C, D, Size) __PcdGetPtr(#A, #B, #C, #D, Si= ze) #define PcdSetPtr(A, B, C, D, Size, Value) __PcdSetPtr(#A, #B, #C, #D, Si= ze, Value) =20 #endif diff --git a/BaseTools/Source/C/Common/PeCoffLib.h b/BaseTools/Source/C/Com= mon/PeCoffLib.h index dd38f442f952..0da434fc19f6 100644 --- a/BaseTools/Source/C/Common/PeCoffLib.h +++ b/BaseTools/Source/C/Common/PeCoffLib.h @@ -29,9 +29,9 @@ // // Macro definitions for RISC-V architecture. // -#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1)) -#define RISCV_IMM_BITS 12 -#define RISCV_IMM_REACH (1LL<> (s)) & ((1<<(n))-1)) +#define RISCV_IMM_BITS 12 +#define RISCV_IMM_REACH (1LL<ImageRead ( - ImageContext->Handle, - 0, - &Size, - &DosHdr - ); + ImageContext->Handle, + 0, + &Size, + &DosHdr + ); if (RETURN_ERROR (Status)) { ImageContext->ImageError =3D IMAGE_ERROR_IMAGE_READ; return Status; @@ -122,10 +121,11 @@ PeCoffLoaderGetPeHeader ( // ImageContext->PeCoffHeaderOffset =3D DosHdr.e_lfanew; } + // // Get the PE/COFF Header pointer // - *PeHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINTN)ImageContext->Han= dle + ImageContext->PeCoffHeaderOffset); + *PeHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINTN)ImageContext->Hand= le + ImageContext->PeCoffHeaderOffset); if ((*PeHdr)->Pe32.Signature !=3D EFI_IMAGE_NT_SIGNATURE) { // // Check the PE/COFF Header Signature. If not, then try to get a TE he= ader @@ -134,6 +134,7 @@ PeCoffLoaderGetPeHeader ( if ((*TeHdr)->Signature !=3D EFI_TE_IMAGE_HEADER_SIGNATURE) { return RETURN_UNSUPPORTED; } + ImageContext->IsTeImage =3D TRUE; } =20 @@ -154,9 +155,9 @@ PeCoffLoaderGetPeHeader ( STATIC RETURN_STATUS PeCoffLoaderCheckImageType ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr, - IN EFI_TE_IMAGE_HEADER *TeHdr + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr, + IN EFI_TE_IMAGE_HEADER *TeHdr ) { // @@ -169,13 +170,14 @@ PeCoffLoaderCheckImageType ( ImageContext->Machine =3D TeHdr->Machine; } =20 - if (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_IA32 && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_X64 && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_ARMT && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_EBC && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_AARCH64 && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_RISCV64 && \ - ImageContext->Machine !=3D EFI_IMAGE_MACHINE_LOONGARCH64) { + if ((ImageContext->Machine !=3D EFI_IMAGE_MACHINE_IA32) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_X64) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_ARMT) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_EBC) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_AARCH64) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_RISCV64) && \ + (ImageContext->Machine !=3D EFI_IMAGE_MACHINE_LOONGARCH64)) + { if (ImageContext->Machine =3D=3D IMAGE_FILE_MACHINE_ARM) { // // There are two types of ARM images. Pure ARM and ARM/Thumb. @@ -188,7 +190,6 @@ PeCoffLoaderCheckImageType ( } else { TeHdr->Machine =3D ImageContext->Machine; } - } else { // // unsupported PeImage machine type @@ -204,13 +205,14 @@ PeCoffLoaderCheckImageType ( if (ImageContext->IsTeImage =3D=3D FALSE) { ImageContext->ImageType =3D PeHdr->Pe32.OptionalHeader.Subsystem; } else { - ImageContext->ImageType =3D (UINT16) (TeHdr->Subsystem); + ImageContext->ImageType =3D (UINT16)(TeHdr->Subsystem); } =20 - if (ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION && \ - ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DR= IVER && \ - ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = && \ - ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER)= { + if ((ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) &= & \ + (ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_D= RIVER) && \ + (ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER= ) && \ + (ImageContext->ImageType !=3D EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER= )) + { // // unsupported PeImage subsystem type // @@ -236,36 +238,37 @@ PeCoffLoaderCheckImageType ( RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - RETURN_STATUS Status; - EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; - EFI_TE_IMAGE_HEADER *TeHdr; - EFI_IMAGE_DATA_DIRECTORY *DebugDirectoryEntry; - UINTN Size; - UINTN Index; - UINTN DebugDirectoryEntryRva; - UINTN DebugDirectoryEntryFileOffset; - UINTN SectionHeaderOffset; - EFI_IMAGE_SECTION_HEADER SectionHeader; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry; - EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; + EFI_TE_IMAGE_HEADER *TeHdr; + EFI_IMAGE_DATA_DIRECTORY *DebugDirectoryEntry; + UINTN Size; + UINTN Index; + UINTN DebugDirectoryEntryRva; + UINTN DebugDirectoryEntryFileOffset; + UINTN SectionHeaderOffset; + EFI_IMAGE_SECTION_HEADER SectionHeader; + EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry; + EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; =20 - PeHdr =3D NULL; - TeHdr =3D NULL; + PeHdr =3D NULL; + TeHdr =3D NULL; DebugDirectoryEntry =3D NULL; DebugDirectoryEntryRva =3D 0; =20 if (NULL =3D=3D ImageContext) { return RETURN_INVALID_PARAMETER; } + // // Assume success // - ImageContext->ImageError =3D IMAGE_ERROR_SUCCESS; + ImageContext->ImageError =3D IMAGE_ERROR_SUCCESS; =20 - Status =3D PeCoffLoaderGetPeHeader (ImageContext, &Pe= Hdr, &TeHdr); + Status =3D PeCoffLoaderGetPeHeader (ImageContext, &PeHdr, &TeHdr); if (RETURN_ERROR (Status)) { return Status; } @@ -277,20 +280,22 @@ PeCoffLoaderGetImageInfo ( if (RETURN_ERROR (Status)) { return Status; } - OptionHeader.Header =3D (VOID *) &(PeHdr->Pe32.OptionalHeader); + + OptionHeader.Header =3D (VOID *)&(PeHdr->Pe32.OptionalHeader); =20 // // Retrieve the base address of the image // if (!(ImageContext->IsTeImage)) { if (PeHdr->Pe32.OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR3= 2_MAGIC) { - ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS) OptionHeader.Optio= nal32->ImageBase; + ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS)OptionHeader.Option= al32->ImageBase; } else { - ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS) OptionHeader.Optio= nal64->ImageBase; + ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS)OptionHeader.Option= al64->ImageBase; } } else { - ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS) (TeHdr->ImageBase + = TeHdr->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER)); + ImageContext->ImageAddress =3D (PHYSICAL_ADDRESS)(TeHdr->ImageBase + T= eHdr->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER)); } + // // Initialize the alternate destination address to 0 indicating that it // should not be used. @@ -300,8 +305,8 @@ PeCoffLoaderGetImageInfo ( // // Initialize the codeview pointer. // - ImageContext->CodeView =3D NULL; - ImageContext->PdbPointer =3D NULL; + ImageContext->CodeView =3D NULL; + ImageContext->PdbPointer =3D NULL; =20 // // Three cases with regards to relocations: @@ -323,31 +328,30 @@ PeCoffLoaderGetImageInfo ( } =20 if (!(ImageContext->IsTeImage)) { - if (PeHdr->Pe32.OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR3= 2_MAGIC) { - ImageContext->ImageSize =3D (UINT64) OptionHeader.Optional32= ->SizeOfImage; - ImageContext->SectionAlignment =3D OptionHeader.Optional32->Section= Alignment; - ImageContext->SizeOfHeaders =3D OptionHeader.Optional32->SizeOfH= eaders; + ImageContext->ImageSize =3D (UINT64)OptionHeader.Optional32->= SizeOfImage; + ImageContext->SectionAlignment =3D OptionHeader.Optional32->SectionA= lignment; + ImageContext->SizeOfHeaders =3D OptionHeader.Optional32->SizeOfHe= aders; =20 // // Modify ImageSize to contain .PDB file name if required and initia= lize // PdbRVA field... // if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_DEBUG) { - DebugDirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) &(OptionHeade= r.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); + DebugDirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(OptionHea= der.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); DebugDirectoryEntryRva =3D DebugDirectoryEntry->VirtualAddress; } } else { - ImageContext->ImageSize =3D (UINT64) OptionHeader.Optional64= ->SizeOfImage; - ImageContext->SectionAlignment =3D OptionHeader.Optional64->Section= Alignment; - ImageContext->SizeOfHeaders =3D OptionHeader.Optional64->SizeOfH= eaders; + ImageContext->ImageSize =3D (UINT64)OptionHeader.Optional64->= SizeOfImage; + ImageContext->SectionAlignment =3D OptionHeader.Optional64->SectionA= lignment; + ImageContext->SizeOfHeaders =3D OptionHeader.Optional64->SizeOfHe= aders; =20 // // Modify ImageSize to contain .PDB file name if required and initia= lize // PdbRVA field... // if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_DEBUG) { - DebugDirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) &(OptionHeade= r.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); + DebugDirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(OptionHea= der.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); DebugDirectoryEntryRva =3D DebugDirectoryEntry->VirtualAddress; } } @@ -361,17 +365,17 @@ PeCoffLoaderGetImageInfo ( DebugDirectoryEntryFileOffset =3D 0; =20 SectionHeaderOffset =3D (UINTN)( - ImageContext->PeCoffHeaderOffset + - sizeof (UINT32) + - sizeof (EFI_IMAGE_FILE_HEADER) + - PeHdr->Pe32.FileHeader.SizeOfOptionalHeader - ); + ImageContext->PeCoffHeaderOffset + + sizeof (UINT32) + + sizeof (EFI_IMAGE_FILE_HEADER) + + PeHdr->Pe32.FileHeader.SizeOfOptionalH= eader + ); =20 for (Index =3D 0; Index < PeHdr->Pe32.FileHeader.NumberOfSections; I= ndex++) { // // Read section header from file // - Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); + Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); Status =3D ImageContext->ImageRead ( ImageContext->Handle, SectionHeaderOffset, @@ -383,9 +387,10 @@ PeCoffLoaderGetImageInfo ( return Status; } =20 - if (DebugDirectoryEntryRva >=3D SectionHeader.VirtualAddress && - DebugDirectoryEntryRva < SectionHeader.VirtualAddress + Sectio= nHeader.Misc.VirtualSize) { - DebugDirectoryEntryFileOffset =3D + if ((DebugDirectoryEntryRva >=3D SectionHeader.VirtualAddress) && + (DebugDirectoryEntryRva < SectionHeader.VirtualAddress + Secti= onHeader.Misc.VirtualSize)) + { + DebugDirectoryEntryFileOffset =3D DebugDirectoryEntryRva - SectionHeader.VirtualAddress + Sectio= nHeader.PointerToRawData; break; } @@ -398,7 +403,7 @@ PeCoffLoaderGetImageInfo ( // // Read next debug directory entry // - Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); Status =3D ImageContext->ImageRead ( ImageContext->Handle, DebugDirectoryEntryFileOffset + Index, @@ -411,8 +416,8 @@ PeCoffLoaderGetImageInfo ( } =20 if (DebugEntry.Type =3D=3D EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { - ImageContext->DebugDirectoryEntryRva =3D (UINT32) (DebugDirect= oryEntryRva + Index); - if (DebugEntry.RVA =3D=3D 0 && DebugEntry.FileOffset !=3D 0) { + ImageContext->DebugDirectoryEntryRva =3D (UINT32)(DebugDirecto= ryEntryRva + Index); + if ((DebugEntry.RVA =3D=3D 0) && (DebugEntry.FileOffset !=3D 0= )) { ImageContext->ImageSize +=3D DebugEntry.SizeOfData; } =20 @@ -422,21 +427,21 @@ PeCoffLoaderGetImageInfo ( } } } else { - ImageContext->ImageSize =3D 0; - ImageContext->SectionAlignment =3D 4096; - ImageContext->SizeOfHeaders =3D sizeof (EFI_TE_IMAGE_HEADER) + (UI= NTN) TeHdr->BaseOfCode - (UINTN) TeHdr->StrippedSize; + ImageContext->ImageSize =3D 0; + ImageContext->SectionAlignment =3D 4096; + ImageContext->SizeOfHeaders =3D sizeof (EFI_TE_IMAGE_HEADER) + (UIN= TN)TeHdr->BaseOfCode - (UINTN)TeHdr->StrippedSize; =20 - DebugDirectoryEntry =3D &TeHdr->DataDirectory[1]; - DebugDirectoryEntryRva =3D DebugDirectoryEntry->VirtualAddres= s; - SectionHeaderOffset =3D (UINTN) (sizeof (EFI_TE_IMAGE_HEAD= ER)); + DebugDirectoryEntry =3D &TeHdr->DataDirectory[1]; + DebugDirectoryEntryRva =3D DebugDirectoryEntry->VirtualAddress; + SectionHeaderOffset =3D (UINTN)(sizeof (EFI_TE_IMAGE_HEADER)); =20 - DebugDirectoryEntryFileOffset =3D 0; + DebugDirectoryEntryFileOffset =3D 0; =20 for (Index =3D 0; Index < TeHdr->NumberOfSections;) { // // Read section header from file // - Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); + Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); Status =3D ImageContext->ImageRead ( ImageContext->Handle, SectionHeaderOffset, @@ -448,21 +453,22 @@ PeCoffLoaderGetImageInfo ( return Status; } =20 - if (DebugDirectoryEntryRva >=3D SectionHeader.VirtualAddress && - DebugDirectoryEntryRva < SectionHeader.VirtualAddress + SectionH= eader.Misc.VirtualSize) { + if ((DebugDirectoryEntryRva >=3D SectionHeader.VirtualAddress) && + (DebugDirectoryEntryRva < SectionHeader.VirtualAddress + Section= Header.Misc.VirtualSize)) + { DebugDirectoryEntryFileOffset =3D DebugDirectoryEntryRva - - SectionHeader.VirtualAddress + - SectionHeader.PointerToRawData + - sizeof (EFI_TE_IMAGE_HEADER) - - TeHdr->StrippedSize; + SectionHeader.VirtualAddress + + SectionHeader.PointerToRawData + + sizeof (EFI_TE_IMAGE_HEADER) - + TeHdr->StrippedSize; =20 // // File offset of the debug directory was found, if this is not th= e last // section, then skip to the last section for calculating the imag= e size. // - if (Index < (UINTN) TeHdr->NumberOfSections - 1) { + if (Index < (UINTN)TeHdr->NumberOfSections - 1) { SectionHeaderOffset +=3D (TeHdr->NumberOfSections - 1 - Index) *= sizeof (EFI_IMAGE_SECTION_HEADER); - Index =3D TeHdr->NumberOfSections - 1; + Index =3D TeHdr->NumberOfSections - 1; continue; } } @@ -477,7 +483,7 @@ PeCoffLoaderGetImageInfo ( // by the RVA and the VirtualSize of the last section header in the // Section Table. // - if ((++Index) =3D=3D (UINTN) TeHdr->NumberOfSections) { + if ((++Index) =3D=3D (UINTN)TeHdr->NumberOfSections) { ImageContext->ImageSize =3D (SectionHeader.VirtualAddress + Sectio= nHeader.Misc.VirtualSize + ImageContext->SectionAlignment - 1) & ~= (ImageContext->SectionAlignment - 1); } @@ -490,7 +496,7 @@ PeCoffLoaderGetImageInfo ( // // Read next debug directory entry // - Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); Status =3D ImageContext->ImageRead ( ImageContext->Handle, DebugDirectoryEntryFileOffset, @@ -503,7 +509,7 @@ PeCoffLoaderGetImageInfo ( } =20 if (DebugEntry.Type =3D=3D EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { - ImageContext->DebugDirectoryEntryRva =3D (UINT32) (DebugDirector= yEntryRva + Index); + ImageContext->DebugDirectoryEntryRva =3D (UINT32)(DebugDirectory= EntryRva + Index); return RETURN_SUCCESS; } } @@ -525,8 +531,8 @@ PeCoffLoaderGetImageInfo ( STATIC VOID * PeCoffLoaderImageAddress ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN UINTN Address + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN UINTN Address ) { if (Address >=3D ImageContext->ImageSize) { @@ -534,7 +540,7 @@ PeCoffLoaderImageAddress ( return NULL; } =20 - return (UINT8 *) ((UINTN) ImageContext->ImageAddress + Address); + return (UINT8 *)((UINTN)ImageContext->ImageAddress + Address); } =20 /** @@ -554,24 +560,24 @@ PeCoffLoaderRelocateImage ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - RETURN_STATUS Status; - EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; - EFI_TE_IMAGE_HEADER *TeHdr; - EFI_IMAGE_DATA_DIRECTORY *RelocDir; - UINT64 Adjust; - EFI_IMAGE_BASE_RELOCATION *RelocBase; - EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd; - UINT16 *Reloc; - UINT16 *RelocEnd; - CHAR8 *Fixup; - CHAR8 *FixupBase; - UINT16 *F16; - UINT32 *F32; - UINT64 *F64; - CHAR8 *FixupData; - PHYSICAL_ADDRESS BaseAddress; - UINT16 MachineType; - EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; + EFI_TE_IMAGE_HEADER *TeHdr; + EFI_IMAGE_DATA_DIRECTORY *RelocDir; + UINT64 Adjust; + EFI_IMAGE_BASE_RELOCATION *RelocBase; + EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd; + UINT16 *Reloc; + UINT16 *RelocEnd; + CHAR8 *Fixup; + CHAR8 *FixupBase; + UINT16 *F16; + UINT32 *F32; + UINT64 *F64; + CHAR8 *FixupData; + PHYSICAL_ADDRESS BaseAddress; + UINT16 MachineType; + EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; =20 PeHdr =3D NULL; TeHdr =3D NULL; @@ -594,12 +600,12 @@ PeCoffLoaderRelocateImage ( =20 if (!(ImageContext->IsTeImage)) { PeHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINTN)ImageContext->Ima= geAddress + - ImageContext->PeCoffHeaderOffs= et); - OptionHeader.Header =3D (VOID *) &(PeHdr->Pe32.OptionalHeader); + ImageContext->PeCoffHeader= Offset); + OptionHeader.Header =3D (VOID *)&(PeHdr->Pe32.OptionalHeader); if (PeHdr->Pe32.OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR3= 2_MAGIC) { - Adjust =3D (UINT64) BaseAddress - OptionHeader.Optional32->ImageBase; - OptionHeader.Optional32->ImageBase =3D (UINT32) BaseAddress; - MachineType =3D ImageContext->Machine; + Adjust =3D (UINT64)BaseAddress - OptionH= eader.Optional32->ImageBase; + OptionHeader.Optional32->ImageBase =3D (UINT32)BaseAddress; + MachineType =3D ImageContext->Machine; // // Find the relocation block // @@ -608,14 +614,14 @@ PeCoffLoaderRelocateImage ( // the optional header to verify a desired directory entry is there. // if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_BASERELOC) { - RelocDir =3D &OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DI= RECTORY_ENTRY_BASERELOC]; + RelocDir =3D &OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DIR= ECTORY_ENTRY_BASERELOC]; if ((RelocDir !=3D NULL) && (RelocDir->Size > 0)) { - RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir->= VirtualAddress); + RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDi= r->VirtualAddress); RelocBaseEnd =3D PeCoffLoaderImageAddress ( ImageContext, RelocDir->VirtualAddress + RelocDir->Size - 1 ); - if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || RelocBa= seEnd < RelocBase) { + if ((RelocBase =3D=3D NULL) || (RelocBaseEnd =3D=3D NULL) || (Re= locBaseEnd < RelocBase)) { ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; return RETURN_LOAD_ERROR; } @@ -632,9 +638,9 @@ PeCoffLoaderRelocateImage ( RelocBase =3D RelocBaseEnd =3D 0; } } else { - Adjust =3D (UINT64) BaseAddress - OptionHeader.Optional64->ImageBase; + Adjust =3D (UINT64)BaseAddress - OptionH= eader.Optional64->ImageBase; OptionHeader.Optional64->ImageBase =3D BaseAddress; - MachineType =3D ImageContext->Machine; + MachineType =3D ImageContext->Machine; // // Find the relocation block // @@ -643,14 +649,14 @@ PeCoffLoaderRelocateImage ( // the optional header to verify a desired directory entry is there. // if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_BASERELOC) { - RelocDir =3D &OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DI= RECTORY_ENTRY_BASERELOC]; + RelocDir =3D &OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DIR= ECTORY_ENTRY_BASERELOC]; if ((RelocDir !=3D NULL) && (RelocDir->Size > 0)) { - RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir->= VirtualAddress); + RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDi= r->VirtualAddress); RelocBaseEnd =3D PeCoffLoaderImageAddress ( ImageContext, RelocDir->VirtualAddress + RelocDir->Size - 1 - ); - if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || RelocBa= seEnd < RelocBase) { + ); + if ((RelocBase =3D=3D NULL) || (RelocBaseEnd =3D=3D NULL) || (Re= locBaseEnd < RelocBase)) { ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; return RETURN_LOAD_ERROR; } @@ -668,22 +674,22 @@ PeCoffLoaderRelocateImage ( } } } else { - TeHdr =3D (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->I= mageAddress); - Adjust =3D (UINT64) (BaseAddress - TeHdr->ImageBase); - TeHdr->ImageBase =3D (UINT64) (BaseAddress); - MachineType =3D TeHdr->Machine; + TeHdr =3D (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->Imag= eAddress); + Adjust =3D (UINT64)(BaseAddress - TeHdr->ImageBase); + TeHdr->ImageBase =3D (UINT64)(BaseAddress); + MachineType =3D TeHdr->Machine; =20 // // Find the relocation block // - RelocDir =3D &TeHdr->DataDirectory[0]; + RelocDir =3D &TeHdr->DataDirectory[0]; RelocBase =3D (EFI_IMAGE_BASE_RELOCATION *)(UINTN)( - ImageContext->ImageAddress + - RelocDir->VirtualAddress + - sizeof(EFI_TE_IMAGE_HEADER) - - TeHdr->StrippedSize - ); - RelocBaseEnd =3D (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (U= INTN) RelocDir->Size - 1); + ImageContext->ImageAd= dress + + RelocDir->VirtualAddr= ess + + sizeof (EFI_TE_IMAGE_= HEADER) - + TeHdr->StrippedSize + ); + RelocBaseEnd =3D (EFI_IMAGE_BASE_RELOCATION *)((UINTN)RelocBase + (UIN= TN)RelocDir->Size - 1); } =20 // @@ -691,9 +697,8 @@ PeCoffLoaderRelocateImage ( // FixupData =3D ImageContext->FixupData; while (RelocBase < RelocBaseEnd) { - - Reloc =3D (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE= _RELOCATION)); - RelocEnd =3D (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock= ); + Reloc =3D (UINT16 *)((CHAR8 *)RelocBase + sizeof (EFI_IMAGE_BASE_RE= LOCATION)); + RelocEnd =3D (UINT16 *)((CHAR8 *)RelocBase + RelocBase->SizeOfBlock); if (!(ImageContext->IsTeImage)) { FixupBase =3D PeCoffLoaderImageAddress (ImageContext, RelocBase->Vir= tualAddress); if (FixupBase =3D=3D NULL) { @@ -702,15 +707,16 @@ PeCoffLoaderRelocateImage ( } } else { FixupBase =3D (CHAR8 *)(UINTN)(ImageContext->ImageAddress + - RelocBase->VirtualAddress + - sizeof(EFI_TE_IMAGE_HEADER) - - TeHdr->StrippedSize - ); + RelocBase->VirtualAddress + + sizeof (EFI_TE_IMAGE_HEADER) - + TeHdr->StrippedSize + ); } =20 - if ((CHAR8 *) RelocEnd < (CHAR8 *) ((UINTN) ImageContext->ImageAddress= ) || - (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + - (UINTN)ImageContext->ImageSize)) { + if (((CHAR8 *)RelocEnd < (CHAR8 *)((UINTN)ImageContext->ImageAddress))= || + ((CHAR8 *)RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + + (UINTN)ImageContext->ImageSize))) + { ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; return RETURN_LOAD_ERROR; } @@ -719,81 +725,85 @@ PeCoffLoaderRelocateImage ( // Run this relocation record // while (Reloc < RelocEnd) { - Fixup =3D FixupBase + (*Reloc & 0xFFF); switch ((*Reloc) >> 12) { - case EFI_IMAGE_REL_BASED_ABSOLUTE: - break; + case EFI_IMAGE_REL_BASED_ABSOLUTE: + break; =20 - case EFI_IMAGE_REL_BASED_HIGH: - F16 =3D (UINT16 *) Fixup; - *F16 =3D (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16))); - if (FixupData !=3D NULL) { - *(UINT16 *) FixupData =3D *F16; - FixupData =3D FixupData + sizeof (UINT16); - } - break; + case EFI_IMAGE_REL_BASED_HIGH: + F16 =3D (UINT16 *)Fixup; + *F16 =3D (UINT16)(*F16 + ((UINT16)((UINT32)Adjust >> 16))); + if (FixupData !=3D NULL) { + *(UINT16 *)FixupData =3D *F16; + FixupData =3D FixupData + sizeof (UINT16); + } =20 - case EFI_IMAGE_REL_BASED_LOW: - F16 =3D (UINT16 *) Fixup; - *F16 =3D (UINT16) (*F16 + (UINT16) Adjust); - if (FixupData !=3D NULL) { - *(UINT16 *) FixupData =3D *F16; - FixupData =3D FixupData + sizeof (UINT16); - } - break; + break; =20 - case EFI_IMAGE_REL_BASED_HIGHLOW: - F32 =3D (UINT32 *) Fixup; - *F32 =3D *F32 + (UINT32) Adjust; - if (FixupData !=3D NULL) { - FixupData =3D ALIGN_POINTER (FixupData, sizeof (UINT= 32)); - *(UINT32 *) FixupData =3D *F32; - FixupData =3D FixupData + sizeof (UINT32); - } - break; + case EFI_IMAGE_REL_BASED_LOW: + F16 =3D (UINT16 *)Fixup; + *F16 =3D (UINT16)(*F16 + (UINT16)Adjust); + if (FixupData !=3D NULL) { + *(UINT16 *)FixupData =3D *F16; + FixupData =3D FixupData + sizeof (UINT16); + } =20 - case EFI_IMAGE_REL_BASED_DIR64: - F64 =3D (UINT64 *) Fixup; - *F64 =3D *F64 + (UINT64) Adjust; - if (FixupData !=3D NULL) { - FixupData =3D ALIGN_POINTER (FixupData, sizeof (UINT= 64)); - *(UINT64 *) FixupData =3D *F64; - FixupData =3D FixupData + sizeof (UINT64); - } - break; + break; =20 - case EFI_IMAGE_REL_BASED_HIGHADJ: - // - // Return the same EFI_UNSUPPORTED return code as - // PeCoffLoaderRelocateImageEx() returns if it does not recognize - // the relocation type. - // - ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; - return RETURN_UNSUPPORTED; + case EFI_IMAGE_REL_BASED_HIGHLOW: + F32 =3D (UINT32 *)Fixup; + *F32 =3D *F32 + (UINT32)Adjust; + if (FixupData !=3D NULL) { + FixupData =3D ALIGN_POINTER (FixupData, sizeof (UIN= T32)); + *(UINT32 *)FixupData =3D *F32; + FixupData =3D FixupData + sizeof (UINT32); + } =20 - default: - switch (MachineType) { - case EFI_IMAGE_MACHINE_IA32: - Status =3D PeCoffLoaderRelocateIa32Image (Reloc, Fixup, &FixupDa= ta, Adjust); - break; - case EFI_IMAGE_MACHINE_ARMT: - Status =3D PeCoffLoaderRelocateArmImage (&Reloc, Fixup, &FixupDa= ta, Adjust); - break; - case EFI_IMAGE_MACHINE_RISCV64: - Status =3D PeCoffLoaderRelocateRiscVImage (Reloc, Fixup, &FixupD= ata, Adjust); break; - case EFI_IMAGE_MACHINE_LOONGARCH64: - Status =3D PeCoffLoaderRelocateLoongArch64Image (Reloc, Fixup, &= FixupData, Adjust); - break; - default: - Status =3D RETURN_UNSUPPORTED; + + case EFI_IMAGE_REL_BASED_DIR64: + F64 =3D (UINT64 *)Fixup; + *F64 =3D *F64 + (UINT64)Adjust; + if (FixupData !=3D NULL) { + FixupData =3D ALIGN_POINTER (FixupData, sizeof (UIN= T64)); + *(UINT64 *)FixupData =3D *F64; + FixupData =3D FixupData + sizeof (UINT64); + } + break; - } - if (RETURN_ERROR (Status)) { + + case EFI_IMAGE_REL_BASED_HIGHADJ: + // + // Return the same EFI_UNSUPPORTED return code as + // PeCoffLoaderRelocateImageEx() returns if it does not recognize + // the relocation type. + // ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; - return Status; - } + return RETURN_UNSUPPORTED; + + default: + switch (MachineType) { + case EFI_IMAGE_MACHINE_IA32: + Status =3D PeCoffLoaderRelocateIa32Image (Reloc, Fixup, &Fix= upData, Adjust); + break; + case EFI_IMAGE_MACHINE_ARMT: + Status =3D PeCoffLoaderRelocateArmImage (&Reloc, Fixup, &Fix= upData, Adjust); + break; + case EFI_IMAGE_MACHINE_RISCV64: + Status =3D PeCoffLoaderRelocateRiscVImage (Reloc, Fixup, &Fi= xupData, Adjust); + break; + case EFI_IMAGE_MACHINE_LOONGARCH64: + Status =3D PeCoffLoaderRelocateLoongArch64Image (Reloc, Fixu= p, &FixupData, Adjust); + break; + default: + Status =3D RETURN_UNSUPPORTED; + break; + } + + if (RETURN_ERROR (Status)) { + ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; + return Status; + } } =20 // @@ -805,7 +815,7 @@ PeCoffLoaderRelocateImage ( // // Next reloc block // - RelocBase =3D (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; + RelocBase =3D (EFI_IMAGE_BASE_RELOCATION *)RelocEnd; } =20 return RETURN_SUCCESS; @@ -829,25 +839,25 @@ PeCoffLoaderLoadImage ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - RETURN_STATUS Status; - EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; - EFI_TE_IMAGE_HEADER *TeHdr; - PE_COFF_LOADER_IMAGE_CONTEXT CheckContext; - EFI_IMAGE_SECTION_HEADER *FirstSection; - EFI_IMAGE_SECTION_HEADER *Section; - UINTN NumberOfSections; - UINTN Index; - CHAR8 *Base; - CHAR8 *End; - CHAR8 *MaxEnd; - EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; - UINTN Size; - UINT32 TempDebugEntryRva; - EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr; + EFI_TE_IMAGE_HEADER *TeHdr; + PE_COFF_LOADER_IMAGE_CONTEXT CheckContext; + EFI_IMAGE_SECTION_HEADER *FirstSection; + EFI_IMAGE_SECTION_HEADER *Section; + UINTN NumberOfSections; + UINTN Index; + CHAR8 *Base; + CHAR8 *End; + CHAR8 *MaxEnd; + EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; + EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; + UINTN Size; + UINT32 TempDebugEntryRva; + EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader; =20 - PeHdr =3D NULL; - TeHdr =3D NULL; + PeHdr =3D NULL; + TeHdr =3D NULL; OptionHeader.Header =3D NULL; // // Assume success @@ -887,6 +897,7 @@ PeCoffLoaderLoadImage ( ImageContext->ImageError =3D IMAGE_ERROR_INVALID_SUBSYSTEM; return RETURN_LOAD_ERROR; } + // // If the image does not contain relocations, and the requested load a= ddress // is not the linked address, then return an error. @@ -896,6 +907,7 @@ PeCoffLoaderLoadImage ( return RETURN_INVALID_PARAMETER; } } + // // Make sure the allocated space has the proper section alignment // @@ -905,46 +917,46 @@ PeCoffLoaderLoadImage ( return RETURN_INVALID_PARAMETER; } } + // // Read the entire PE/COFF or TE header into memory // if (!(ImageContext->IsTeImage)) { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - 0, - &ImageContext->SizeOfHeaders, - (VOID *) (UINTN) ImageContext->ImageAddress - ); + ImageContext->Handle, + 0, + &ImageContext->SizeOfHeaders, + (VOID *)(UINTN)ImageContext->ImageAddress + ); =20 PeHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *) - ((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffse= t); + ((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeade= rOffset); =20 - OptionHeader.Header =3D (VOID *) &(PeHdr->Pe32.OptionalHeader); + OptionHeader.Header =3D (VOID *)&(PeHdr->Pe32.OptionalHeader); =20 - FirstSection =3D (EFI_IMAGE_SECTION_HEADER *) ( - (UINTN)ImageContext->ImageAddress + - ImageContext->PeCoffHeaderOffset + - sizeof(UINT32) + - sizeof(EFI_IMAGE_FILE_HEADER) + - PeHdr->Pe32.FileHeader.SizeOfOptionalHeader - ); - NumberOfSections =3D (UINTN) (PeHdr->Pe32.FileHeader.NumberOfSections); + FirstSection =3D (EFI_IMAGE_SECTION_HEADER *)( + (UINTN)ImageContext->Image= Address + + ImageContext->PeCoffHeader= Offset + + sizeof (UINT32) + + sizeof (EFI_IMAGE_FILE_HEA= DER) + + PeHdr->Pe32.FileHeader.Siz= eOfOptionalHeader + ); + NumberOfSections =3D (UINTN)(PeHdr->Pe32.FileHeader.NumberOfSections); } else { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - 0, - &ImageContext->SizeOfHeaders, - (VOID *) (UINTN) ImageContext->ImageAddress - ); + ImageContext->Handle, + 0, + &ImageContext->SizeOfHeaders, + (VOID *)(UINTN)ImageContext->ImageAddress + ); =20 - TeHdr =3D (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->I= mageAddress); - - FirstSection =3D (EFI_IMAGE_SECTION_HEADER *) ( - (UINTN)ImageContext->ImageAddress + - sizeof(EFI_TE_IMAGE_HEADER) - ); - NumberOfSections =3D (UINTN) (TeHdr->NumberOfSections); + TeHdr =3D (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->ImageAddress); =20 + FirstSection =3D (EFI_IMAGE_SECTION_HEADER *)( + (UINTN)ImageContext->Image= Address + + sizeof (EFI_TE_IMAGE_HEADE= R) + ); + NumberOfSections =3D (UINTN)(TeHdr->NumberOfSections); } =20 if (RETURN_ERROR (Status)) { @@ -957,15 +969,14 @@ PeCoffLoaderLoadImage ( // Section =3D FirstSection; for (Index =3D 0, MaxEnd =3D NULL; Index < NumberOfSections; Index++) { - // // Compute sections address // Base =3D PeCoffLoaderImageAddress (ImageContext, Section->VirtualAddre= ss); - End =3D PeCoffLoaderImageAddress ( - ImageContext, - Section->VirtualAddress + Section->Misc.VirtualSize - 1 - ); + End =3D PeCoffLoaderImageAddress ( + ImageContext, + Section->VirtualAddress + Section->Misc.VirtualSize - 1 + ); =20 // // If the base start or end address resolved to 0, then fail. @@ -975,10 +986,9 @@ PeCoffLoaderLoadImage ( return RETURN_LOAD_ERROR; } =20 - if (ImageContext->IsTeImage) { - Base =3D (CHAR8 *) ((UINTN) Base + sizeof (EFI_TE_IMAGE_HEADER) - (= UINTN) TeHdr->StrippedSize); - End =3D (CHAR8 *) ((UINTN) End + sizeof (EFI_TE_IMAGE_HEADER) - (U= INTN) TeHdr->StrippedSize); + Base =3D (CHAR8 *)((UINTN)Base + sizeof (EFI_TE_IMAGE_HEADER) - (UIN= TN)TeHdr->StrippedSize); + End =3D (CHAR8 *)((UINTN)End + sizeof (EFI_TE_IMAGE_HEADER) - (UINT= N)TeHdr->StrippedSize); } =20 if (End > MaxEnd) { @@ -988,26 +998,26 @@ PeCoffLoaderLoadImage ( // // Read the section // - Size =3D (UINTN) Section->Misc.VirtualSize; + Size =3D (UINTN)Section->Misc.VirtualSize; if ((Size =3D=3D 0) || (Size > Section->SizeOfRawData)) { - Size =3D (UINTN) Section->SizeOfRawData; + Size =3D (UINTN)Section->SizeOfRawData; } =20 if (Section->SizeOfRawData) { if (!(ImageContext->IsTeImage)) { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - Section->PointerToRawData, - &Size, - Base - ); + ImageContext->Handle, + Section->PointerToRawData, + &Size, + Base + ); } else { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - Section->PointerToRawData + sizeof (EFI_TE= _IMAGE_HEADER) - (UINTN) TeHdr->StrippedSize, - &Size, - Base - ); + ImageContext->Handle, + Section->PointerToRawData + sizeof (EFI_T= E_IMAGE_HEADER) - (UINTN)TeHdr->StrippedSize, + &Size, + Base + ); } =20 if (RETURN_ERROR (Status)) { @@ -1034,15 +1044,15 @@ PeCoffLoaderLoadImage ( // Get image's entry point // if (!(ImageContext->IsTeImage)) { - ImageContext->EntryPoint =3D (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderIm= ageAddress ( - ImageConte= xt, - PeHdr->Pe3= 2.OptionalHeader.AddressOfEntryPoint - ); + ImageContext->EntryPoint =3D (PHYSICAL_ADDRESS)(UINTN)PeCoffLoaderImag= eAddress ( + ImageContext, + PeHdr->Pe32.Opti= onalHeader.AddressOfEntryPoint + ); } else { ImageContext->EntryPoint =3D (UINTN)ImageContext->ImageAddress + (UINTN)TeHdr->AddressOfEntryPoint + - (UINTN)sizeof(EFI_TE_IMAGE_HEADER) - - (UINTN) TeHdr->StrippedSize; + (UINTN)sizeof (EFI_TE_IMAGE_HEADER) - + (UINTN)TeHdr->StrippedSize; } =20 // @@ -1056,7 +1066,7 @@ PeCoffLoaderLoadImage ( if (PeHdr->Pe32.OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR3= 2_MAGIC) { if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_BASERELOC) { DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) - &OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTR= Y_BASERELOC]; + &OptionHeader.Optional32->DataDirectory[EFI_IMAGE= _DIRECTORY_ENTRY_BASERELOC]; ImageContext->FixupDataSize =3D DirectoryEntry->Size / sizeof (UIN= T16) * sizeof (UINTN); } else { ImageContext->FixupDataSize =3D 0; @@ -1064,7 +1074,7 @@ PeCoffLoaderLoadImage ( } else { if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTO= RY_ENTRY_BASERELOC) { DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) - &OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTR= Y_BASERELOC]; + &OptionHeader.Optional64->DataDirectory[EFI_IMAGE= _DIRECTORY_ENTRY_BASERELOC]; ImageContext->FixupDataSize =3D DirectoryEntry->Size / sizeof (UIN= T16) * sizeof (UINTN); } else { ImageContext->FixupDataSize =3D 0; @@ -1074,6 +1084,7 @@ PeCoffLoaderLoadImage ( DirectoryEntry =3D &TeHdr->DataDirectory[0]; ImageContext->FixupDataSize =3D DirectoryEntry->Size / sizeof (UINT16)= * sizeof (UINTN); } + // // Consumer must allocate a buffer for the relocation fixup log. // Only used for runtime drivers. @@ -1086,23 +1097,23 @@ PeCoffLoaderLoadImage ( if (ImageContext->DebugDirectoryEntryRva !=3D 0) { if (!(ImageContext->IsTeImage)) { DebugEntry =3D PeCoffLoaderImageAddress ( - ImageContext, - ImageContext->DebugDirectoryEntryRva - ); + ImageContext, + ImageContext->DebugDirectoryEntryRva + ); } else { DebugEntry =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)(UINTN)( - ImageContext->ImageAddress + - ImageContext->DebugDirector= yEntryRva + - sizeof(EFI_TE_IMAGE_HEADER)= - - TeHdr->StrippedSize - ); + ImageContext= ->ImageAddress + + ImageContext= ->DebugDirectoryEntryRva + + sizeof (EFI_= TE_IMAGE_HEADER) - + TeHdr->Strip= pedSize + ); } =20 if (DebugEntry !=3D NULL) { TempDebugEntryRva =3D DebugEntry->RVA; - if (DebugEntry->RVA =3D=3D 0 && DebugEntry->FileOffset !=3D 0) { + if ((DebugEntry->RVA =3D=3D 0) && (DebugEntry->FileOffset !=3D 0)) { Section--; - if ((UINTN) Section->SizeOfRawData < Section->Misc.VirtualSize) { + if ((UINTN)Section->SizeOfRawData < Section->Misc.VirtualSize) { TempDebugEntryRva =3D Section->VirtualAddress + Section->Misc.Vi= rtualSize; } else { TempDebugEntryRva =3D Section->VirtualAddress + Section->SizeOfR= awData; @@ -1114,11 +1125,11 @@ PeCoffLoaderLoadImage ( ImageContext->CodeView =3D PeCoffLoaderImageAddress (ImageContex= t, TempDebugEntryRva); } else { ImageContext->CodeView =3D (VOID *)( - (UINTN)ImageContext->ImageAddress + - (UINTN)TempDebugEntryRva + - (UINTN)sizeof(EFI_TE_IMAGE_HEADER) - - (UINTN) TeHdr->StrippedSize - ); + (UINTN)ImageContext->ImageAddr= ess + + (UINTN)TempDebugEntryRva + + (UINTN)sizeof (EFI_TE_IMAGE_HE= ADER) - + (UINTN)TeHdr->StrippedSize + ); } =20 if (ImageContext->CodeView =3D=3D NULL) { @@ -1130,18 +1141,18 @@ PeCoffLoaderLoadImage ( Size =3D DebugEntry->SizeOfData; if (!(ImageContext->IsTeImage)) { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - DebugEntry->FileOffset, - &Size, - ImageContext->CodeView - ); + ImageContext->Handle, + DebugEntry->FileOffset, + &Size, + ImageContext->CodeView + ); } else { Status =3D ImageContext->ImageRead ( - ImageContext->Handle, - DebugEntry->FileOffset + sizeof (EFI_T= E_IMAGE_HEADER) - TeHdr->StrippedSize, - &Size, - ImageContext->CodeView - ); + ImageContext->Handle, + DebugEntry->FileOffset + sizeof (EFI_= TE_IMAGE_HEADER) - TeHdr->StrippedSize, + &Size, + ImageContext->CodeView + ); // // Should we apply fix up to this field according to the size = difference between PE and TE? // Because now we maintain TE header fields unfixed, this fiel= d will also remain as they are @@ -1157,20 +1168,20 @@ PeCoffLoaderLoadImage ( DebugEntry->RVA =3D TempDebugEntryRva; } =20 - switch (*(UINT32 *) ImageContext->CodeView) { - case CODEVIEW_SIGNATURE_NB10: - ImageContext->PdbPointer =3D (CHAR8 *) ImageContext->CodeView + = sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY); - break; + switch (*(UINT32 *)ImageContext->CodeView) { + case CODEVIEW_SIGNATURE_NB10: + ImageContext->PdbPointer =3D (CHAR8 *)ImageContext->CodeView += sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY); + break; =20 - case CODEVIEW_SIGNATURE_RSDS: - ImageContext->PdbPointer =3D (CHAR8 *) ImageContext->CodeView + = sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY); - break; + case CODEVIEW_SIGNATURE_RSDS: + ImageContext->PdbPointer =3D (CHAR8 *)ImageContext->CodeView += sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY); + break; =20 - case CODEVIEW_SIGNATURE_MTOC: - ImageContext->PdbPointer =3D (CHAR8 *) ImageContext->CodeView + = sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY); + case CODEVIEW_SIGNATURE_MTOC: + ImageContext->PdbPointer =3D (CHAR8 *)ImageContext->CodeView += sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY); =20 - default: - break; + default: + break; } } } @@ -1204,17 +1215,17 @@ PeCoffLoaderGetPdbPointer ( IN VOID *Pe32Data ) { - EFI_IMAGE_DOS_HEADER *DosHdr; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; - UINTN DirCount; - VOID *CodeViewEntryPointer; - INTN TEImageAdjust; - UINT32 NumberOfRvaAndSizes; - UINT16 Magic; - EFI_IMAGE_SECTION_HEADER *SectionHeader; - UINT32 Index, Index1; + EFI_IMAGE_DOS_HEADER *DosHdr; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; + EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; + UINTN DirCount; + VOID *CodeViewEntryPointer; + INTN TEImageAdjust; + UINT32 NumberOfRvaAndSizes; + UINT16 Magic; + EFI_IMAGE_SECTION_HEADER *SectionHeader; + UINT32 Index, Index1; =20 if (Pe32Data =3D=3D NULL) { return NULL; @@ -1233,7 +1244,7 @@ PeCoffLoaderGetPdbPointer ( // // DOS image header is present, so read the PE header after the DOS im= age header. // - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((D= osHdr->e_lfanew) & 0x0ffff)); + Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((Dos= Hdr->e_lfanew) & 0x0ffff)); } else { // // DOS image header is not present, so PE header is at the image base. @@ -1243,22 +1254,23 @@ PeCoffLoaderGetPdbPointer ( =20 if (EFI_TE_IMAGE_HEADER_SIGNATURE =3D=3D Hdr.Te->Signature) { if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualA= ddress !=3D 0) { - DirectoryEntry =3D &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_EN= TRY_DEBUG]; - TEImageAdjust =3D sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedS= ize; + DirectoryEntry =3D &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENT= RY_DEBUG]; + TEImageAdjust =3D sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSi= ze; =20 // // Get the DebugEntry offset in the raw data image. // - SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) (Hdr.Te + 1); - Index =3D Hdr.Te->NumberOfSections; - for (Index1 =3D 0; Index1 < Index; Index1 ++) { + SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *)(Hdr.Te + 1); + Index =3D Hdr.Te->NumberOfSections; + for (Index1 =3D 0; Index1 < Index; Index1++) { if ((DirectoryEntry->VirtualAddress >=3D SectionHeader[Index1].Vir= tualAddress) && - (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].Virtua= lAddress + SectionHeader[Index1].Misc.VirtualSize))) { - DebugEntry =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.T= e + - DirectoryEntry->VirtualAddress - - SectionHeader [Index1].VirtualAddress + - SectionHeader [Index1].PointerToRawData + - TEImageAdjust); + (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].Virtu= alAddress + SectionHeader[Index1].Misc.VirtualSize))) + { + DebugEntry =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Hdr.Te= + + DirectoryEntry-= >VirtualAddress - + SectionHeader[I= ndex1].VirtualAddress + + SectionHeader[I= ndex1].PointerToRawData + + TEImageAdjust); break; } } @@ -1270,32 +1282,32 @@ PeCoffLoaderGetPdbPointer ( // generate PE32+ image with PE32 Magic. // switch (Hdr.Pe32->FileHeader.Machine) { - case EFI_IMAGE_MACHINE_IA32: - case EFI_IMAGE_MACHINE_ARMT: - // - // Assume PE32 image with IA32 Machine field. - // - Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; - break; - case EFI_IMAGE_MACHINE_X64: - // - // Assume PE32+ image with X64 Machine field - // - Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - break; - default: - // - // For unknown Machine field, use Magic in optional Header - // - Magic =3D Hdr.Pe32->OptionalHeader.Magic; + case EFI_IMAGE_MACHINE_IA32: + case EFI_IMAGE_MACHINE_ARMT: + // + // Assume PE32 image with IA32 Machine field. + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; + break; + case EFI_IMAGE_MACHINE_X64: + // + // Assume PE32+ image with X64 Machine field + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; + break; + default: + // + // For unknown Machine field, use Magic in optional Header + // + Magic =3D Hdr.Pe32->OptionalHeader.Magic; } =20 - SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ( - (UINT8 *) Hdr.Pe32 + - sizeof (UINT32) + - sizeof (EFI_IMAGE_FILE_HEADER) + - Hdr.Pe32->FileHeader.SizeOfOptionalHeader - ); + SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *)( + (UINT8 *)Hdr.Pe32 + + sizeof (UINT32) + + sizeof (EFI_IMAGE_FILE_HE= ADER) + + Hdr.Pe32->FileHeader.Size= OfOptionalHeader + ); Index =3D Hdr.Pe32->FileHeader.NumberOfSections; =20 if (EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC =3D=3D Magic) { @@ -1303,30 +1315,31 @@ PeCoffLoaderGetPdbPointer ( // Use PE32 offset get Debug Directory Entry // NumberOfRvaAndSizes =3D Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes; - DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalH= eader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); + DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->Opti= onalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); } else if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL= _HDR64_MAGIC) { // // Use PE32+ offset get Debug Directory Entry // NumberOfRvaAndSizes =3D Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndS= izes; - DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->Optio= nalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); + DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->= OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); } =20 - if (NumberOfRvaAndSizes <=3D EFI_IMAGE_DIRECTORY_ENTRY_DEBUG || Direct= oryEntry->VirtualAddress =3D=3D 0) { + if ((NumberOfRvaAndSizes <=3D EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) || (Dir= ectoryEntry->VirtualAddress =3D=3D 0)) { DirectoryEntry =3D NULL; - DebugEntry =3D NULL; + DebugEntry =3D NULL; } else { // // Get the DebugEntry offset in the raw data image. // - for (Index1 =3D 0; Index1 < Index; Index1 ++) { + for (Index1 =3D 0; Index1 < Index; Index1++) { if ((DirectoryEntry->VirtualAddress >=3D SectionHeader[Index1].Vir= tualAddress) && - (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].Virtua= lAddress + SectionHeader[Index1].Misc.VirtualSize))) { - DebugEntry =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ( - (UINTN) Pe32Data + - DirectoryEntry->VirtualAddress - - SectionHeader[Index1].VirtualAddress + - SectionHeader[Index1].PointerToRawData); + (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].Virtu= alAddress + SectionHeader[Index1].Misc.VirtualSize))) + { + DebugEntry =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)( + (UINTN)Pe32Data= + + DirectoryEntry-= >VirtualAddress - + SectionHeader[I= ndex1].VirtualAddress + + SectionHeader[I= ndex1].PointerToRawData); break; } } @@ -1335,7 +1348,7 @@ PeCoffLoaderGetPdbPointer ( return NULL; } =20 - if (NULL =3D=3D DebugEntry || NULL =3D=3D DirectoryEntry) { + if ((NULL =3D=3D DebugEntry) || (NULL =3D=3D DirectoryEntry)) { return NULL; } =20 @@ -1349,33 +1362,36 @@ PeCoffLoaderGetPdbPointer ( // Get the DebugEntry offset in the raw data image. // CodeViewEntryPointer =3D NULL; - for (Index1 =3D 0; Index1 < Index; Index1 ++) { + for (Index1 =3D 0; Index1 < Index; Index1++) { if ((DebugEntry->RVA >=3D SectionHeader[Index1].VirtualAddress) = && - (DebugEntry->RVA < (SectionHeader[Index1].VirtualAddress + Se= ctionHeader[Index1].Misc.VirtualSize))) { - CodeViewEntryPointer =3D (VOID *) ( - ((UINTN)Pe32Data) + - (UINTN) DebugEntry->RVA - - SectionHeader[Index1].VirtualAddress + - SectionHeader[Index1].PointerToRawData + - (UINTN)TEImageAdjust); + (DebugEntry->RVA < (SectionHeader[Index1].VirtualAddress + S= ectionHeader[Index1].Misc.VirtualSize))) + { + CodeViewEntryPointer =3D (VOID *)( + ((UINTN)Pe32Data) + + (UINTN)DebugEntry->RVA - + SectionHeader[Index1].VirtualA= ddress + + SectionHeader[Index1].PointerT= oRawData + + (UINTN)TEImageAdjust); break; } } + if (Index1 >=3D Index) { // // Can't find CodeViewEntryPointer in raw PE/COFF image. // continue; } - switch (* (UINT32 *) CodeViewEntryPointer) { - case CODEVIEW_SIGNATURE_NB10: - return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMA= GE_DEBUG_CODEVIEW_NB10_ENTRY)); - case CODEVIEW_SIGNATURE_RSDS: - return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMA= GE_DEBUG_CODEVIEW_RSDS_ENTRY)); - case CODEVIEW_SIGNATURE_MTOC: - return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMA= GE_DEBUG_CODEVIEW_MTOC_ENTRY)); - default: - break; + + switch (*(UINT32 *)CodeViewEntryPointer) { + case CODEVIEW_SIGNATURE_NB10: + return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IM= AGE_DEBUG_CODEVIEW_NB10_ENTRY)); + case CODEVIEW_SIGNATURE_RSDS: + return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IM= AGE_DEBUG_CODEVIEW_RSDS_ENTRY)); + case CODEVIEW_SIGNATURE_MTOC: + return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IM= AGE_DEBUG_CODEVIEW_MTOC_ENTRY)); + default: + break; } } } @@ -1384,7 +1400,6 @@ PeCoffLoaderGetPdbPointer ( return NULL; } =20 - RETURN_STATUS EFIAPI PeCoffLoaderGetEntryPoint ( @@ -1393,15 +1408,15 @@ PeCoffLoaderGetEntryPoint ( OUT VOID **BaseOfImage ) { - EFI_IMAGE_DOS_HEADER *DosHdr; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_DOS_HEADER *DosHdr; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; =20 DosHdr =3D (EFI_IMAGE_DOS_HEADER *)Pe32Data; if (DosHdr->e_magic =3D=3D EFI_IMAGE_DOS_SIGNATURE) { // // DOS image header is present, so read the PE header after the DOS im= age header. // - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((D= osHdr->e_lfanew) & 0x0ffff)); + Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((Dos= Hdr->e_lfanew) & 0x0ffff)); } else { // // DOS image header is not present, so PE header is at the image base. @@ -1415,7 +1430,7 @@ PeCoffLoaderGetEntryPoint ( // if (Hdr.Te->Signature =3D=3D EFI_TE_IMAGE_HEADER_SIGNATURE) { *BaseOfImage =3D (VOID *)(UINTN)(Hdr.Te->ImageBase + Hdr.Te->StrippedS= ize - sizeof (EFI_TE_IMAGE_HEADER)); - *EntryPoint =3D (VOID *)((UINTN)*BaseOfImage + (Hdr.Te->AddressOfEntry= Point & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize); + *EntryPoint =3D (VOID *)((UINTN)*BaseOfImage + (Hdr.Te->AddressOfEntr= yPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize= ); return RETURN_SUCCESS; } else if (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE) { *EntryPoint =3D (VOID *)(UINTN)Hdr.Pe32->OptionalHeader.AddressOfEntry= Point; @@ -1424,6 +1439,7 @@ PeCoffLoaderGetEntryPoint ( } else { *BaseOfImage =3D (VOID *)(UINTN)Hdr.Pe32Plus->OptionalHeader.ImageBa= se; } + *EntryPoint =3D (VOID *)(UINTN)((UINTN)*EntryPoint + (UINTN)*BaseOfIma= ge); return RETURN_SUCCESS; } diff --git a/BaseTools/Source/C/Common/BinderFuncs.c b/BaseTools/Source/C/C= ommon/BinderFuncs.c index de835287e95c..be256c1fd29a 100644 --- a/BaseTools/Source/C/Common/BinderFuncs.c +++ b/BaseTools/Source/C/Common/BinderFuncs.c @@ -17,15 +17,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 VOID * CommonLibBinderAllocate ( - IN UINTN Size + IN UINTN Size ) { - return (VOID *) malloc (Size); + return (VOID *)malloc (Size); } =20 VOID CommonLibBinderFree ( - IN VOID *Pointer + IN VOID *Pointer ) { free (Pointer); @@ -33,9 +33,9 @@ CommonLibBinderFree ( =20 VOID CommonLibBinderCopyMem ( - IN VOID *Destination, - IN VOID *Source, - IN UINTN Length + IN VOID *Destination, + IN VOID *Source, + IN UINTN Length ) { memmove (Destination, Source, Length); @@ -43,9 +43,9 @@ CommonLibBinderCopyMem ( =20 VOID CommonLibBinderSetMem ( - IN VOID *Destination, - IN UINTN Length, - IN UINT8 Value + IN VOID *Destination, + IN UINTN Length, + IN UINT8 Value ) { memset (Destination, Value, Length); @@ -53,9 +53,9 @@ CommonLibBinderSetMem ( =20 INTN CommonLibBinderCompareMem ( - IN VOID *MemOne, - IN VOID *MemTwo, - IN UINTN Length + IN VOID *MemOne, + IN VOID *MemTwo, + IN UINTN Length ) { return memcmp (MemOne, MemTwo, Length); @@ -63,12 +63,9 @@ CommonLibBinderCompareMem ( =20 BOOLEAN CommonLibBinderCompareGuid ( - IN EFI_GUID *Guid1, - IN EFI_GUID *Guid2 + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 ) { return CompareGuid (Guid1, Guid2) ? FALSE : TRUE; } - - - diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Com= mon/CommonLib.c index cd270f9a9074..861426dd8d3f 100644 --- a/BaseTools/Source/C/Common/CommonLib.c +++ b/BaseTools/Source/C/Common/CommonLib.c @@ -11,9 +11,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #ifdef __GNUC__ -#include + #include #else -#include + #include #endif #include "CommonLib.h" #include "EfiUtilityMsgs.h" @@ -60,11 +60,11 @@ PeiCopyMem ( IN UINTN Length ) { - CHAR8 *Destination8; - CHAR8 *Source8; + CHAR8 *Destination8; + CHAR8 *Source8; =20 - Destination8 =3D Destination; - Source8 =3D Source; + Destination8 =3D Destination; + Source8 =3D Source; while (Length--) { *(Destination8++) =3D *(Source8++); } @@ -100,21 +100,21 @@ CopyMem ( **/ INTN CompareGuid ( - IN EFI_GUID *Guid1, - IN EFI_GUID *Guid2 + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 ) { - INT32 *g1; - INT32 *g2; - INT32 r; + INT32 *g1; + INT32 *g2; + INT32 r; =20 // // Compare 32 bits at a time // - g1 =3D (INT32 *) Guid1; - g2 =3D (INT32 *) Guid2; + g1 =3D (INT32 *)Guid1; + g2 =3D (INT32 *)Guid2; =20 - r =3D g1[0] - g2[0]; + r =3D g1[0] - g2[0]; r |=3D g1[1] - g2[1]; r |=3D g1[2] - g2[2]; r |=3D g1[3] - g2[3]; @@ -148,9 +148,10 @@ GetFileImage ( // // Verify input parameters. // - if (InputFileName =3D=3D NULL || strlen (InputFileName) =3D=3D 0 || Inpu= tFileImage =3D=3D NULL) { + if ((InputFileName =3D=3D NULL) || (strlen (InputFileName) =3D=3D 0) || = (InputFileImage =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } + // // Open the file and copy contents into a memory buffer. // @@ -162,6 +163,7 @@ GetFileImage ( Error (NULL, 0, 0001, "Error opening the input file", InputFileName); return EFI_ABORTED; } + // // Go to the end so that we can determine the file size // @@ -170,6 +172,7 @@ GetFileImage ( fclose (InputFile); return EFI_ABORTED; } + // // Get the file size // @@ -179,6 +182,7 @@ GetFileImage ( fclose (InputFile); return EFI_ABORTED; } + // // Allocate a buffer // @@ -187,6 +191,7 @@ GetFileImage ( fclose (InputFile); return EFI_OUT_OF_RESOURCES; } + // // Reset to the beginning of the file // @@ -197,6 +202,7 @@ GetFileImage ( *InputFileImage =3D NULL; return EFI_ABORTED; } + // // Read all of the file contents. // @@ -208,6 +214,7 @@ GetFileImage ( *InputFileImage =3D NULL; return EFI_ABORTED; } + // // Close the file // @@ -230,9 +237,9 @@ GetFileImage ( **/ EFI_STATUS PutFileImage ( - IN CHAR8 *OutputFileName, - IN CHAR8 *OutputFileImage, - IN UINT32 BytesToWrite + IN CHAR8 *OutputFileName, + IN CHAR8 *OutputFileImage, + IN UINT32 BytesToWrite ) { FILE *OutputFile; @@ -241,9 +248,10 @@ PutFileImage ( // // Verify input parameters. // - if (OutputFileName =3D=3D NULL || strlen (OutputFileName) =3D=3D 0 || Ou= tputFileImage =3D=3D NULL) { + if ((OutputFileName =3D=3D NULL) || (strlen (OutputFileName) =3D=3D 0) |= | (OutputFileImage =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } + // // Open the file and copy contents into a memory buffer. // @@ -265,6 +273,7 @@ PutFileImage ( fclose (OutputFile); return EFI_ABORTED; } + // // Close the file // @@ -283,11 +292,11 @@ PutFileImage ( **/ UINT8 CalculateChecksum8 ( - IN UINT8 *Buffer, - IN UINTN Size + IN UINT8 *Buffer, + IN UINTN Size ) { - return (UINT8) (0x100 - CalculateSum8 (Buffer, Size)); + return (UINT8)(0x100 - CalculateSum8 (Buffer, Size)); } =20 /** @@ -304,8 +313,8 @@ CalculateSum8 ( IN UINTN Size ) { - UINTN Index; - UINT8 Sum; + UINTN Index; + UINT8 Sum; =20 Sum =3D 0; =20 @@ -313,7 +322,7 @@ CalculateSum8 ( // Perform the byte sum for buffer // for (Index =3D 0; Index < Size; Index++) { - Sum =3D (UINT8) (Sum + Buffer[Index]); + Sum =3D (UINT8)(Sum + Buffer[Index]); } =20 return Sum; @@ -324,16 +333,16 @@ CalculateSum8 ( =20 @param Buffer Pointer to buffer containing byte data of component. @param Size Size of the buffer -=20 + @return The 16 bit checksum value needed. **/ UINT16 CalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) { - return (UINT16) (0x10000 - CalculateSum16 (Buffer, Size)); + return (UINT16)(0x10000 - CalculateSum16 (Buffer, Size)); } =20 /** @@ -346,8 +355,8 @@ CalculateChecksum16 ( **/ UINT16 CalculateSum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) { UINTN Index; @@ -359,10 +368,10 @@ CalculateSum16 ( // Perform the word sum for buffer // for (Index =3D 0; Index < Size; Index++) { - Sum =3D (UINT16) (Sum + Buffer[Index]); + Sum =3D (UINT16)(Sum + Buffer[Index]); } =20 - return (UINT16) Sum; + return (UINT16)Sum; } =20 /** @@ -375,7 +384,7 @@ CalculateSum16 ( **/ EFI_STATUS PrintGuid ( - IN EFI_GUID *Guid + IN EFI_GUID *Guid ) { if (Guid =3D=3D NULL) { @@ -385,7 +394,7 @@ PrintGuid ( =20 printf ( "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", - (unsigned) Guid->Data1, + (unsigned)Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0], @@ -414,10 +423,10 @@ PrintGuid ( **/ EFI_STATUS PrintGuidToBuffer ( - IN EFI_GUID *Guid, - IN OUT UINT8 *Buffer, - IN UINT32 BufferLen, - IN BOOLEAN Uppercase + IN EFI_GUID *Guid, + IN OUT UINT8 *Buffer, + IN UINT32 BufferLen, + IN BOOLEAN Uppercase ) { if (Guid =3D=3D NULL) { @@ -434,7 +443,7 @@ PrintGuidToBuffer ( sprintf ( (CHAR8 *)Buffer, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", - (unsigned) Guid->Data1, + (unsigned)Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0], @@ -450,7 +459,7 @@ PrintGuidToBuffer ( sprintf ( (CHAR8 *)Buffer, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - (unsigned) Guid->Data1, + (unsigned)Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0], @@ -469,32 +478,42 @@ PrintGuidToBuffer ( =20 #ifdef __GNUC__ =20 -size_t _filelength(int fd) +size_t +_filelength ( + int fd + ) { - struct stat stat_buf; - fstat(fd, &stat_buf); + struct stat stat_buf; + + fstat (fd, &stat_buf); return stat_buf.st_size; } =20 -#ifndef __CYGWIN__ -char *strlwr(char *s) + #ifndef __CYGWIN__ +char * +strlwr ( + char *s + ) { - char *p =3D s; - for(;*s;s++) { - *s =3D tolower(*s); + char *p =3D s; + + for ( ; *s; s++) { + *s =3D tolower (*s); } + return p; } -#endif + + #endif #endif =20 -#define WINDOWS_EXTENSION_PATH "\\\\?\\" -#define WINDOWS_UNC_EXTENSION_PATH "\\\\?\\UNC" +#define WINDOWS_EXTENSION_PATH "\\\\?\\" +#define WINDOWS_UNC_EXTENSION_PATH "\\\\?\\UNC" =20 // // Global data to store full file path. It is not required to be free. // -CHAR8 mCommonLibFullPath[MAX_LONG_FILE_PATH]; +CHAR8 mCommonLibFullPath[MAX_LONG_FILE_PATH]; =20 /** Convert FileName to the long file path, which can support larger than 26= 0 length. @@ -505,21 +524,21 @@ CHAR8 mCommonLibFullPath[MAX_LONG_FILE_PATH]; **/ CHAR8 * LongFilePath ( - IN CHAR8 *FileName - ) + IN CHAR8 *FileName + ) { -#ifdef __GNUC__ + #ifdef __GNUC__ // // __GNUC__ may not be good way to differentiate unix and windows. Need = more investigation here. // unix has no limitation on file path. Just return FileName. // return FileName; -#else - CHAR8 *RootPath; - CHAR8 *PathPointer; - CHAR8 *NextPointer; + #else + CHAR8 *RootPath; + CHAR8 *PathPointer; + CHAR8 *NextPointer; =20 - PathPointer =3D (CHAR8 *) FileName; + PathPointer =3D (CHAR8 *)FileName; =20 if (FileName !=3D NULL) { // @@ -528,13 +547,13 @@ LongFilePath ( mCommonLibFullPath[0] =3D 0; strcpy (mCommonLibFullPath, WINDOWS_EXTENSION_PATH); =20 - if (strlen (FileName) > 1 && FileName[0] =3D=3D '\\' && FileName[1] = =3D=3D '\\') { + if ((strlen (FileName) > 1) && (FileName[0] =3D=3D '\\') && (FileName[= 1] =3D=3D '\\')) { // // network path like \\server\share to \\?\UNC\server\share // strcpy (mCommonLibFullPath, WINDOWS_UNC_EXTENSION_PATH); - FileName ++; - } else if (strlen (FileName) < 3 || FileName[1] !=3D ':' || (FileName[= 2] !=3D '\\' && FileName[2] !=3D '/')) { + FileName++; + } else if ((strlen (FileName) < 3) || (FileName[1] !=3D ':') || ((File= Name[2] !=3D '\\') && (FileName[2] !=3D '/'))) { // // Relative file path. Convert it to absolute path. // @@ -545,18 +564,21 @@ LongFilePath ( free (RootPath); return NULL; } + strncat (mCommonLibFullPath, RootPath, MAX_LONG_FILE_PATH - strlen= (mCommonLibFullPath) - 1); - if (FileName[0] !=3D '\\' && FileName[0] !=3D '/') { + if ((FileName[0] !=3D '\\') && (FileName[0] !=3D '/')) { if (strlen (mCommonLibFullPath) + 1 > MAX_LONG_FILE_PATH - 1) { Error (NULL, 0, 2000, "Invalid parameter", "RootPath is too lo= ng!"); free (RootPath); return NULL; } + // // Attach directory separator // strncat (mCommonLibFullPath, "\\", MAX_LONG_FILE_PATH - strlen (= mCommonLibFullPath) - 1); } + free (RootPath); } } @@ -568,17 +590,18 @@ LongFilePath ( Error (NULL, 0, 2000, "Invalid parameter", "FileName %s is too long!= ", FileName); return NULL; } + strncat (mCommonLibFullPath, FileName, MAX_LONG_FILE_PATH - strlen (mC= ommonLibFullPath) - 1); =20 // // Convert directory separator '/' to '\\' // - PathPointer =3D (CHAR8 *) mCommonLibFullPath; + PathPointer =3D (CHAR8 *)mCommonLibFullPath; do { if (*PathPointer =3D=3D '/') { *PathPointer =3D '\\'; } - } while (*PathPointer ++ !=3D '\0'); + } while (*PathPointer++ !=3D '\0'); =20 // // Convert ":\\\\" to ":\\", because it doesn't work with WINDOWS_EXTE= NSION_PATH. @@ -610,7 +633,7 @@ LongFilePath ( while ((PathPointer =3D strstr (mCommonLibFullPath, "\\..\\")) !=3D NU= LL) { NextPointer =3D PathPointer + 3; do { - PathPointer --; + PathPointer--; } while (PathPointer > mCommonLibFullPath && *PathPointer !=3D ':' &= & *PathPointer !=3D '\\'); =20 if (*PathPointer =3D=3D '\\') { @@ -631,16 +654,16 @@ LongFilePath ( } =20 return PathPointer; -#endif + #endif } =20 CHAR16 InternalCharToUpper ( - CHAR16 Char + CHAR16 Char ) { - if (Char >=3D L'a' && Char <=3D L'z') { - return (CHAR16) (Char - (L'a' - L'A')); + if ((Char >=3D L'a') && (Char <=3D L'z')) { + return (CHAR16)(Char - (L'a' - L'A')); } =20 return Char; @@ -648,13 +671,13 @@ InternalCharToUpper ( =20 UINTN StrnLenS ( - CONST CHAR16 *String, - UINTN MaxSize + CONST CHAR16 *String, + UINTN MaxSize ) { - UINTN Length; + UINTN Length; =20 - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // If String is a null pointer or MaxSize is 0, then the StrnLenS functi= on returns zero. @@ -668,47 +691,48 @@ StrnLenS ( if (Length >=3D MaxSize - 1) { return MaxSize; } + Length++; } + return Length; } =20 - VOID * InternalAllocatePool ( - UINTN AllocationSize + UINTN AllocationSize ) { - VOID * Memory; + VOID *Memory; =20 - Memory =3D malloc(AllocationSize); - ASSERT(Memory !=3D NULL); + Memory =3D malloc (AllocationSize); + ASSERT (Memory !=3D NULL); return Memory; } =20 - VOID * InternalReallocatePool ( - UINTN OldSize, - UINTN NewSize, - VOID *OldBuffer OPTIONAL + UINTN OldSize, + UINTN NewSize, + VOID *OldBuffer OPTIONAL ) { VOID *NewBuffer; =20 NewBuffer =3D AllocateZeroPool (NewSize); - if (NewBuffer !=3D NULL && OldBuffer !=3D NULL) { + if ((NewBuffer !=3D NULL) && (OldBuffer !=3D NULL)) { memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); - free(OldBuffer); + free (OldBuffer); } + return NewBuffer; } =20 VOID * ReallocatePool ( - UINTN OldSize, - UINTN NewSize, - VOID *OldBuffer OPTIONAL + UINTN OldSize, + UINTN NewSize, + VOID *OldBuffer OPTIONAL ) { return InternalReallocatePool (OldSize, NewSize, OldBuffer); @@ -733,13 +757,13 @@ ReallocatePool ( **/ UINTN StrLen ( - CONST CHAR16 *String + CONST CHAR16 *String ) { - UINTN Length; + UINTN Length; =20 ASSERT (String !=3D NULL); - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 for (Length =3D 0; *String !=3D L'\0'; String++, Length++) { // @@ -747,21 +771,24 @@ StrLen ( // length should not more than PcdMaximumUnicodeStringLength // } + return Length; } =20 BOOLEAN InternalSafeStringIsOverlap ( - IN VOID *Base1, - IN UINTN Size1, - IN VOID *Base2, - IN UINTN Size2 + IN VOID *Base1, + IN UINTN Size1, + IN VOID *Base2, + IN UINTN Size2 ) { if ((((UINTN)Base1 >=3D (UINTN)Base2) && ((UINTN)Base1 < (UINTN)Base2 + = Size2)) || - (((UINTN)Base2 >=3D (UINTN)Base1) && ((UINTN)Base2 < (UINTN)Base1 + = Size1))) { + (((UINTN)Base2 >=3D (UINTN)Base1) && ((UINTN)Base2 < (UINTN)Base1 + = Size1))) + { return TRUE; } + return FALSE; } =20 @@ -773,7 +800,7 @@ InternalSafeStringNoStrOverlap ( IN UINTN Size2 ) { - return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2,= Size2 * sizeof(CHAR16)); + return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof (CHAR16), Str2= , Size2 * sizeof (CHAR16)); } =20 /** @@ -826,12 +853,12 @@ InternalSafeStringNoStrOverlap ( **/ RETURN_STATUS StrDecimalToUint64S ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINT64 *Data + CONST CHAR16 *String, + CHAR16 **EndPointer, OPTIONAL + UINT64 *Data ) { - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. Neither String nor Data shall be a null pointer. @@ -847,7 +874,7 @@ StrDecimalToUint64S ( } =20 if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } =20 // @@ -875,8 +902,9 @@ StrDecimalToUint64S ( if (*Data > ((MAX_UINT64 - (*String - L'0'))/10)) { *Data =3D MAX_UINT64; if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } + return RETURN_UNSUPPORTED; } =20 @@ -885,8 +913,9 @@ StrDecimalToUint64S ( } =20 if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } + return RETURN_SUCCESS; } =20 @@ -945,12 +974,12 @@ StrDecimalToUint64S ( **/ RETURN_STATUS StrHexToUint64S ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINT64 *Data + CONST CHAR16 *String, + CHAR16 **EndPointer, OPTIONAL + UINT64 *Data ) { - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. Neither String nor Data shall be a null pointer. @@ -966,7 +995,7 @@ StrHexToUint64S ( } =20 if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } =20 // @@ -988,6 +1017,7 @@ StrHexToUint64S ( *Data =3D 0; return RETURN_SUCCESS; } + // // Skip the 'X' // @@ -1005,8 +1035,9 @@ StrHexToUint64S ( if (*Data > ((MAX_UINT64 - InternalHexCharToUintn (*String))>>4)) { *Data =3D MAX_UINT64; if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } + return RETURN_UNSUPPORTED; } =20 @@ -1015,46 +1046,45 @@ StrHexToUint64S ( } =20 if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) String; + *EndPointer =3D (CHAR16 *)String; } + return RETURN_SUCCESS; } =20 UINT64 StrDecimalToUint64 ( - CONST CHAR16 *String + CONST CHAR16 *String ) { - UINT64 Result; + UINT64 Result; =20 - StrDecimalToUint64S (String, (CHAR16 **) NULL, &Result); + StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result); return Result; } =20 - UINT64 StrHexToUint64 ( - CONST CHAR16 *String + CONST CHAR16 *String ) { - UINT64 Result; + UINT64 Result; =20 - StrHexToUint64S (String, (CHAR16 **) NULL, &Result); + StrHexToUint64S (String, (CHAR16 **)NULL, &Result); return Result; } =20 UINTN StrSize ( - CONST CHAR16 *String + CONST CHAR16 *String ) { return (StrLen (String) + 1) * sizeof (*String); } =20 - UINT64 ReadUnaligned64 ( - CONST UINT64 *Buffer + CONST UINT64 *Buffer ) { ASSERT (Buffer !=3D NULL); @@ -1064,8 +1094,8 @@ ReadUnaligned64 ( =20 UINT64 WriteUnaligned64 ( - UINT64 *Buffer, - UINT64 Value + UINT64 *Buffer, + UINT64 Value ) { ASSERT (Buffer !=3D NULL); @@ -1073,58 +1103,56 @@ WriteUnaligned64 ( return *Buffer =3D Value; } =20 - EFI_GUID * CopyGuid ( - EFI_GUID *DestinationGuid, - CONST EFI_GUID *SourceGuid + EFI_GUID *DestinationGuid, + CONST EFI_GUID *SourceGuid ) { WriteUnaligned64 ( - (UINT64*)DestinationGuid, - ReadUnaligned64 ((CONST UINT64*)SourceGuid) + (UINT64 *)DestinationGuid, + ReadUnaligned64 ((CONST UINT64 *)SourceGuid) ); WriteUnaligned64 ( - (UINT64*)DestinationGuid + 1, - ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1) + (UINT64 *)DestinationGuid + 1, + ReadUnaligned64 ((CONST UINT64 *)SourceGuid + 1) ); return DestinationGuid; } =20 UINT16 SwapBytes16 ( - UINT16 Value + UINT16 Value ) { - return (UINT16) ((Value<< 8) | (Value>> 8)); + return (UINT16)((Value<< 8) | (Value>> 8)); } =20 - UINT32 SwapBytes32 ( - UINT32 Value + UINT32 Value ) { UINT32 LowerBytes; UINT32 HigherBytes; =20 - LowerBytes =3D (UINT32) SwapBytes16 ((UINT16) Value); - HigherBytes =3D (UINT32) SwapBytes16 ((UINT16) (Value >> 16)); + LowerBytes =3D (UINT32)SwapBytes16 ((UINT16)Value); + HigherBytes =3D (UINT32)SwapBytes16 ((UINT16)(Value >> 16)); return (LowerBytes << 16 | HigherBytes); } =20 BOOLEAN InternalIsDecimalDigitCharacter ( - CHAR16 Char + CHAR16 Char ) { - return (BOOLEAN) (Char >=3D L'0' && Char <=3D L'9'); + return (BOOLEAN)(Char >=3D L'0' && Char <=3D L'9'); } =20 VOID * InternalAllocateCopyPool ( - UINTN AllocationSize, - CONST VOID *Buffer + UINTN AllocationSize, + CONST VOID *Buffer ) { VOID *Memory; @@ -1133,25 +1161,25 @@ InternalAllocateCopyPool ( =20 Memory =3D malloc (AllocationSize); if (Memory !=3D NULL) { - Memory =3D memcpy (Memory, Buffer, AllocationSize); + Memory =3D memcpy (Memory, Buffer, AllocationSize); } + return Memory; } =20 BOOLEAN InternalIsHexaDecimalDigitCharacter ( - CHAR16 Char + CHAR16 Char ) { - - return (BOOLEAN) (InternalIsDecimalDigitCharacter (Char) || - (Char >=3D L'A' && Char <=3D L'F') || - (Char >=3D L'a' && Char <=3D L'f')); + return (BOOLEAN)(InternalIsDecimalDigitCharacter (Char) || + (Char >=3D L'A' && Char <=3D L'F') || + (Char >=3D L'a' && Char <=3D L'f')); } =20 UINTN InternalHexCharToUintn ( - CHAR16 Char + CHAR16 Char ) { if (InternalIsDecimalDigitCharacter (Char)) { @@ -1161,7 +1189,6 @@ InternalHexCharToUintn ( return (10 + InternalCharToUpper (Char) - L'A'); } =20 - /** Convert a Null-terminated Unicode hexadecimal string to a byte array. =20 @@ -1208,15 +1235,15 @@ InternalHexCharToUintn ( **/ RETURN_STATUS StrHexToBytes ( - CONST CHAR16 *String, - UINTN Length, - UINT8 *Buffer, - UINTN MaxBufferSize + CONST CHAR16 *String, + UINTN Length, + UINT8 *Buffer, + UINTN MaxBufferSize ) { - UINTN Index; + UINTN Index; =20 - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. None of String or Buffer shall be a null pointer. @@ -1249,6 +1276,7 @@ StrHexToBytes ( break; } } + if (Index !=3D Length) { return RETURN_UNSUPPORTED; } @@ -1256,18 +1284,18 @@ StrHexToBytes ( // // Convert the hex string to bytes. // - for(Index =3D 0; Index < Length; Index++) { - + for (Index =3D 0; Index < Length; Index++) { // // For even characters, write the upper nibble for each buffer byte, // and for even characters, the lower nibble. // if ((Index & BIT0) =3D=3D 0) { - Buffer[Index / 2] =3D (UINT8) InternalHexCharToUintn (String[Index]= ) << 4; + Buffer[Index / 2] =3D (UINT8)InternalHexCharToUintn (String[Index]) = << 4; } else { - Buffer[Index / 2] |=3D (UINT8) InternalHexCharToUintn (String[Index]= ); + Buffer[Index / 2] |=3D (UINT8)InternalHexCharToUintn (String[Index]); } } + return RETURN_SUCCESS; } =20 @@ -1317,14 +1345,14 @@ StrHexToBytes ( **/ RETURN_STATUS StrToGuid ( - CONST CHAR16 *String, - EFI_GUID *Guid + CONST CHAR16 *String, + EFI_GUID *Guid ) { - RETURN_STATUS Status; - EFI_GUID LocalGuid; + RETURN_STATUS Status; + EFI_GUID LocalGuid; =20 - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. None of String or Guid shall be a null pointer. @@ -1335,49 +1363,53 @@ StrToGuid ( // // Get aabbccdd in big-endian. // - Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data1), (UINT8 *= ) &LocalGuid.Data1, sizeof (LocalGuid.Data1)); - if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data1)] !=3D L= '-') { + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data1), (UINT8 *= )&LocalGuid.Data1, sizeof (LocalGuid.Data1)); + if (RETURN_ERROR (Status) || (String[2 * sizeof (LocalGuid.Data1)] !=3D = L'-')) { return RETURN_UNSUPPORTED; } + // // Convert big-endian to little-endian. // LocalGuid.Data1 =3D SwapBytes32 (LocalGuid.Data1); - String +=3D 2 * sizeof (LocalGuid.Data1) + 1; + String +=3D 2 * sizeof (LocalGuid.Data1) + 1; =20 // // Get eeff in big-endian. // - Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data2), (UINT8 *= ) &LocalGuid.Data2, sizeof (LocalGuid.Data2)); - if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data2)] !=3D L= '-') { + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data2), (UINT8 *= )&LocalGuid.Data2, sizeof (LocalGuid.Data2)); + if (RETURN_ERROR (Status) || (String[2 * sizeof (LocalGuid.Data2)] !=3D = L'-')) { return RETURN_UNSUPPORTED; } + // // Convert big-endian to little-endian. // LocalGuid.Data2 =3D SwapBytes16 (LocalGuid.Data2); - String +=3D 2 * sizeof (LocalGuid.Data2) + 1; + String +=3D 2 * sizeof (LocalGuid.Data2) + 1; =20 // // Get gghh in big-endian. // - Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data3), (UINT8 *= ) &LocalGuid.Data3, sizeof (LocalGuid.Data3)); - if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data3)] !=3D L= '-') { + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data3), (UINT8 *= )&LocalGuid.Data3, sizeof (LocalGuid.Data3)); + if (RETURN_ERROR (Status) || (String[2 * sizeof (LocalGuid.Data3)] !=3D = L'-')) { return RETURN_UNSUPPORTED; } + // // Convert big-endian to little-endian. // LocalGuid.Data3 =3D SwapBytes16 (LocalGuid.Data3); - String +=3D 2 * sizeof (LocalGuid.Data3) + 1; + String +=3D 2 * sizeof (LocalGuid.Data3) + 1; =20 // // Get iijj. // Status =3D StrHexToBytes (String, 2 * 2, &LocalGuid.Data4[0], 2); - if (RETURN_ERROR (Status) || String[2 * 2] !=3D L'-') { + if (RETURN_ERROR (Status) || (String[2 * 2] !=3D L'-')) { return RETURN_UNSUPPORTED; } + String +=3D 2 * 2 + 1; =20 // @@ -1426,9 +1458,9 @@ StrToGuid ( **/ INTN StrnCmp ( - CONST CHAR16 *FirstString, - CONST CHAR16 *SecondString, - UINTN Length + CONST CHAR16 *FirstString, + CONST CHAR16 *SecondString, + UINTN Length ) { if (Length =3D=3D 0) { @@ -1445,7 +1477,8 @@ StrnCmp ( while ((*FirstString !=3D L'\0') && (*SecondString !=3D L'\0') && (*FirstString =3D=3D *SecondString) && - (Length > 1)) { + (Length > 1)) + { FirstString++; SecondString++; Length--; @@ -1456,8 +1489,8 @@ StrnCmp ( =20 VOID * AllocateCopyPool ( - UINTN AllocationSize, - CONST VOID *Buffer + UINTN AllocationSize, + CONST VOID *Buffer ) { return InternalAllocateCopyPool (AllocationSize, Buffer); @@ -1465,8 +1498,8 @@ AllocateCopyPool ( =20 INTN StrCmp ( - CONST CHAR16 *FirstString, - CONST CHAR16 *SecondString + CONST CHAR16 *FirstString, + CONST CHAR16 *SecondString ) { // @@ -1479,12 +1512,13 @@ StrCmp ( FirstString++; SecondString++; } + return *FirstString - *SecondString; } =20 UINT64 SwapBytes64 ( - UINT64 Value + UINT64 Value ) { return InternalMathSwapBytes64 (Value); @@ -1492,37 +1526,37 @@ SwapBytes64 ( =20 UINT64 InternalMathSwapBytes64 ( - UINT64 Operand + UINT64 Operand ) { UINT64 LowerBytes; UINT64 HigherBytes; =20 - LowerBytes =3D (UINT64) SwapBytes32 ((UINT32) Operand); - HigherBytes =3D (UINT64) SwapBytes32 ((UINT32) (Operand >> 32)); + LowerBytes =3D (UINT64)SwapBytes32 ((UINT32)Operand); + HigherBytes =3D (UINT64)SwapBytes32 ((UINT32)(Operand >> 32)); =20 return (LowerBytes << 32 | HigherBytes); } =20 RETURN_STATUS StrToIpv4Address ( - CONST CHAR16 *String, - CHAR16 **EndPointer, - EFI_IPv4_ADDRESS *Address, - UINT8 *PrefixLength + CONST CHAR16 *String, + CHAR16 **EndPointer, + EFI_IPv4_ADDRESS *Address, + UINT8 *PrefixLength ) { - RETURN_STATUS Status; - UINTN AddressIndex; - UINT64 Uint64; - EFI_IPv4_ADDRESS LocalAddress; - UINT8 LocalPrefixLength; - CHAR16 *Pointer; + RETURN_STATUS Status; + UINTN AddressIndex; + UINT64 Uint64; + EFI_IPv4_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CHAR16 *Pointer; =20 - LocalPrefixLength =3D MAX_UINT8; + LocalPrefixLength =3D MAX_UINT8; LocalAddress.Addr[0] =3D 0; =20 - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. None of String or Guid shall be a null pointer. @@ -1530,7 +1564,7 @@ StrToIpv4Address ( SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); SAFE_STRING_CONSTRAINT_CHECK ((Address !=3D NULL), RETURN_INVALID_PARAME= TER); =20 - for (Pointer =3D (CHAR16 *) String, AddressIndex =3D 0; AddressIndex < A= RRAY_SIZE (Address->Addr) + 1;) { + for (Pointer =3D (CHAR16 *)String, AddressIndex =3D 0; AddressIndex < AR= RAY_SIZE (Address->Addr) + 1;) { if (!InternalIsDecimalDigitCharacter (*Pointer)) { // // D or P contains invalid characters. @@ -1541,10 +1575,11 @@ StrToIpv4Address ( // // Get D or P. // - Status =3D StrDecimalToUint64S ((CONST CHAR16 *) Pointer, &Pointer, &U= int64); + Status =3D StrDecimalToUint64S ((CONST CHAR16 *)Pointer, &Pointer, &Ui= nt64); if (RETURN_ERROR (Status)) { return RETURN_UNSUPPORTED; } + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { // // It's P. @@ -1552,7 +1587,8 @@ StrToIpv4Address ( if (Uint64 > 32) { return RETURN_UNSUPPORTED; } - LocalPrefixLength =3D (UINT8) Uint64; + + LocalPrefixLength =3D (UINT8)Uint64; } else { // // It's D. @@ -1560,7 +1596,8 @@ StrToIpv4Address ( if (Uint64 > MAX_UINT8) { return RETURN_UNSUPPORTED; } - LocalAddress.Addr[AddressIndex] =3D (UINT8) Uint64; + + LocalAddress.Addr[AddressIndex] =3D (UINT8)Uint64; AddressIndex++; } =20 @@ -1600,6 +1637,7 @@ StrToIpv4Address ( if (PrefixLength !=3D NULL) { *PrefixLength =3D LocalPrefixLength; } + if (EndPointer !=3D NULL) { *EndPointer =3D Pointer; } @@ -1609,27 +1647,27 @@ StrToIpv4Address ( =20 RETURN_STATUS StrToIpv6Address ( - CONST CHAR16 *String, - CHAR16 **EndPointer, - EFI_IPv6_ADDRESS *Address, - UINT8 *PrefixLength + CONST CHAR16 *String, + CHAR16 **EndPointer, + EFI_IPv6_ADDRESS *Address, + UINT8 *PrefixLength ) { - RETURN_STATUS Status; - UINTN AddressIndex; - UINT64 Uint64; - EFI_IPv6_ADDRESS LocalAddress; - UINT8 LocalPrefixLength; - CONST CHAR16 *Pointer; - CHAR16 *End; - UINTN CompressStart; - BOOLEAN ExpectPrefix; + RETURN_STATUS Status; + UINTN AddressIndex; + UINT64 Uint64; + EFI_IPv6_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CONST CHAR16 *Pointer; + CHAR16 *End; + UINTN CompressStart; + BOOLEAN ExpectPrefix; =20 LocalPrefixLength =3D MAX_UINT8; CompressStart =3D ARRAY_SIZE (Address->Addr); ExpectPrefix =3D FALSE; =20 - ASSERT (((UINTN) String & BIT0) =3D=3D 0); + ASSERT (((UINTN)String & BIT0) =3D=3D 0); =20 // // 1. None of String or Guid shall be a null pointer. @@ -1657,7 +1695,7 @@ StrToIpv6Address ( return RETURN_UNSUPPORTED; } =20 - if (CompressStart !=3D ARRAY_SIZE (Address->Addr) || AddressIndex = =3D=3D ARRAY_SIZE (Address->Addr)) { + if ((CompressStart !=3D ARRAY_SIZE (Address->Addr)) || (AddressIndex= =3D=3D ARRAY_SIZE (Address->Addr))) { // // "::" can only appear once. // "::" can only appear when address is not full length. @@ -1677,6 +1715,7 @@ StrToIpv6Address ( // return RETURN_UNSUPPORTED; } + Pointer++; } } @@ -1699,33 +1738,35 @@ StrToIpv6Address ( // Get X. // Status =3D StrHexToUint64S (Pointer, &End, &Uint64); - if (RETURN_ERROR (Status) || End - Pointer > 4) { + if (RETURN_ERROR (Status) || (End - Pointer > 4)) { // // Number of hexadecimal digit characters is no more than 4. // return RETURN_UNSUPPORTED; } + Pointer =3D End; // // Uint64 won't exceed MAX_UINT16 if number of hexadecimal digit c= haracters is no more than 4. // ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); - LocalAddress.Addr[AddressIndex] =3D (UINT8) ((UINT16) Uint64 >> 8); - LocalAddress.Addr[AddressIndex + 1] =3D (UINT8) Uint64; - AddressIndex +=3D 2; + LocalAddress.Addr[AddressIndex] =3D (UINT8)((UINT16)Uint64 >> = 8); + LocalAddress.Addr[AddressIndex + 1] =3D (UINT8)Uint64; + AddressIndex +=3D 2; } else { // // Get P, then exit the loop. // Status =3D StrDecimalToUint64S (Pointer, &End, &Uint64); - if (RETURN_ERROR (Status) || End =3D=3D Pointer || Uint64 > 128) { + if (RETURN_ERROR (Status) || (End =3D=3D Pointer) || (Uint64 > 128= )) { // // Prefix length should not exceed 128. // return RETURN_UNSUPPORTED; } - LocalPrefixLength =3D (UINT8) Uint64; - Pointer =3D End; + + LocalPrefixLength =3D (UINT8)Uint64; + Pointer =3D End; break; } } @@ -1748,21 +1789,24 @@ StrToIpv6Address ( // break; } + Pointer++; } =20 - if ((AddressIndex =3D=3D ARRAY_SIZE (Address->Addr) && CompressStart != =3D ARRAY_SIZE (Address->Addr)) || - (AddressIndex !=3D ARRAY_SIZE (Address->Addr) && CompressStart =3D=3D = ARRAY_SIZE (Address->Addr)) - ) { + if (((AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) && (CompressStart = !=3D ARRAY_SIZE (Address->Addr))) || + ((AddressIndex !=3D ARRAY_SIZE (Address->Addr)) && (CompressStart = =3D=3D ARRAY_SIZE (Address->Addr))) + ) + { // // Full length of address shall not have compressing zeros. // Non-full length of address shall have compressing zeros. // return RETURN_UNSUPPORTED; } + memcpy (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); if (AddressIndex > CompressStart) { - memset (&Address->Addr[CompressStart], 0, ARRAY_SIZE (Address->Addr) = - AddressIndex); + memset (&Address->Addr[CompressStart], 0, ARRAY_SIZE (Address->Addr) -= AddressIndex); memcpy ( &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressI= ndex], &LocalAddress.Addr[CompressStart], @@ -1773,24 +1817,24 @@ StrToIpv6Address ( if (PrefixLength !=3D NULL) { *PrefixLength =3D LocalPrefixLength; } + if (EndPointer !=3D NULL) { - *EndPointer =3D (CHAR16 *) Pointer; + *EndPointer =3D (CHAR16 *)Pointer; } =20 return RETURN_SUCCESS; } =20 - RETURN_STATUS UnicodeStrToAsciiStrS ( - CONST CHAR16 *Source, - CHAR8 *Destination, - UINTN DestMax + CONST CHAR16 *Source, + CHAR8 *Destination, + UINTN DestMax ) { - UINTN SourceLen; + UINTN SourceLen; =20 - ASSERT (((UINTN) Source & BIT0) =3D=3D 0); + ASSERT (((UINTN)Source & BIT0) =3D=3D 0); =20 // // 1. Neither Destination nor Source shall be a null pointer. @@ -1804,6 +1848,7 @@ UnicodeStrToAsciiStrS ( if (ASCII_RSIZE_MAX !=3D 0) { SAFE_STRING_CONSTRAINT_CHECK ((DestMax <=3D ASCII_RSIZE_MAX), RETURN_I= NVALID_PARAMETER); } + if (RSIZE_MAX !=3D 0) { SAFE_STRING_CONSTRAINT_CHECK ((DestMax <=3D RSIZE_MAX), RETURN_INVALID= _PARAMETER); } @@ -1822,7 +1867,7 @@ UnicodeStrToAsciiStrS ( // // 5. Copying shall not take place between objects that overlap. // - SAFE_STRING_CONSTRAINT_CHECK (!InternalSafeStringIsOverlap (Destination,= DestMax, (VOID *)Source, (SourceLen + 1) * sizeof(CHAR16)), RETURN_ACCESS_= DENIED); + SAFE_STRING_CONSTRAINT_CHECK (!InternalSafeStringIsOverlap (Destination,= DestMax, (VOID *)Source, (SourceLen + 1) * sizeof (CHAR16)), RETURN_ACCESS= _DENIED); =20 // // convert string @@ -1833,8 +1878,9 @@ UnicodeStrToAsciiStrS ( // non-zero value in the upper 8 bits, then ASSERT(). // ASSERT (*Source < 0x100); - *(Destination++) =3D (CHAR8) *(Source++); + *(Destination++) =3D (CHAR8)*(Source++); } + *Destination =3D '\0'; =20 return RETURN_SUCCESS; @@ -1842,15 +1888,15 @@ UnicodeStrToAsciiStrS ( =20 RETURN_STATUS StrCpyS ( - CHAR16 *Destination, - UINTN DestMax, - CONST CHAR16 *Source + CHAR16 *Destination, + UINTN DestMax, + CONST CHAR16 *Source ) { - UINTN SourceLen; + UINTN SourceLen; =20 - ASSERT (((UINTN) Destination & BIT0) =3D=3D 0); - ASSERT (((UINTN) Source & BIT0) =3D=3D 0); + ASSERT (((UINTN)Destination & BIT0) =3D=3D 0); + ASSERT (((UINTN)Source & BIT0) =3D=3D 0); =20 // // 1. Neither Destination nor Source shall be a null pointer. @@ -1888,6 +1934,7 @@ StrCpyS ( while (*Source !=3D 0) { *(Destination++) =3D *(Source++); } + *Destination =3D 0; =20 return RETURN_SUCCESS; @@ -1898,13 +1945,15 @@ AllocateZeroPool ( UINTN AllocationSize ) { - VOID * Memory; - Memory =3D malloc(AllocationSize); + VOID *Memory; + + Memory =3D malloc (AllocationSize); ASSERT (Memory !=3D NULL); if (Memory =3D=3D NULL) { - fprintf(stderr, "Not memory for malloc\n"); + fprintf (stderr, "Not memory for malloc\n"); } - memset(Memory, 0, AllocationSize); + + memset (Memory, 0, AllocationSize); return Memory; } =20 @@ -1918,8 +1967,8 @@ AllocatePool ( =20 UINT16 WriteUnaligned16 ( - UINT16 *Buffer, - UINT16 Value + UINT16 *Buffer, + UINT16 Value ) { ASSERT (Buffer !=3D NULL); @@ -1929,13 +1978,14 @@ WriteUnaligned16 ( =20 UINT16 ReadUnaligned16 ( - CONST UINT16 *Buffer + CONST UINT16 *Buffer ) { ASSERT (Buffer !=3D NULL); =20 return *Buffer; } + /** Return whether the integer string is a hex string. =20 @@ -1947,23 +1997,24 @@ ReadUnaligned16 ( **/ BOOLEAN IsHexStr ( - CHAR16 *Str + CHAR16 *Str ) { // // skip preceding white space // while ((*Str !=3D 0) && *Str =3D=3D L' ') { - Str ++; + Str++; } + // // skip preceding zeros // while ((*Str !=3D 0) && *Str =3D=3D L'0') { - Str ++; + Str++; } =20 - return (BOOLEAN) (*Str =3D=3D L'x' || *Str =3D=3D L'X'); + return (BOOLEAN)(*Str =3D=3D L'x' || *Str =3D=3D L'X'); } =20 /** @@ -1977,7 +2028,7 @@ IsHexStr ( **/ UINTN Strtoi ( - CHAR16 *Str + CHAR16 *Str ) { if (IsHexStr (Str)) { @@ -1997,8 +2048,8 @@ Strtoi ( **/ VOID Strtoi64 ( - CHAR16 *Str, - UINT64 *Data + CHAR16 *Str, + UINT64 *Data ) { if (IsHexStr (Str)) { @@ -2018,16 +2069,17 @@ Strtoi64 ( **/ VOID StrToAscii ( - CHAR16 *Str, - CHAR8 **AsciiStr + CHAR16 *Str, + CHAR8 **AsciiStr ) { - CHAR8 *Dest; + CHAR8 *Dest; =20 Dest =3D *AsciiStr; while (!IS_NULL (*Str)) { - *(Dest++) =3D (CHAR8) *(Str++); + *(Dest++) =3D (CHAR8)*(Str++); } + *Dest =3D 0; =20 // @@ -2050,14 +2102,14 @@ StrToAscii ( **/ CHAR16 * SplitStr ( - CHAR16 **List, - CHAR16 Separator + CHAR16 **List, + CHAR16 Separator ) { CHAR16 *Str; CHAR16 *ReturnStr; =20 - Str =3D *List; + Str =3D *List; ReturnStr =3D Str; =20 if (IS_NULL (*Str)) { @@ -2071,6 +2123,7 @@ SplitStr ( if (*Str =3D=3D Separator) { break; } + Str++; } =20 @@ -2088,4 +2141,3 @@ SplitStr ( *List =3D Str; return ReturnStr; } - diff --git a/BaseTools/Source/C/Common/Crc32.c b/BaseTools/Source/C/Common/= Crc32.c index 00cae948985d..1a702cab86ed 100644 --- a/BaseTools/Source/C/Common/Crc32.c +++ b/BaseTools/Source/C/Common/Crc32.c @@ -281,9 +281,9 @@ UINT32 mCrcTable[256] =3D { **/ EFI_STATUS CalculateCrc32 ( - IN UINT8 *Data, - IN UINTN DataSize, - IN OUT UINT32 *CrcOut + IN UINT8 *Data, + IN UINTN DataSize, + IN OUT UINT32 *CrcOut ) { UINT32 Crc; @@ -296,7 +296,7 @@ CalculateCrc32 ( =20 Crc =3D 0xffffffff; for (Index =3D 0, Ptr =3D Data; Index < DataSize; Index++, Ptr++) { - Crc =3D (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr]; + Crc =3D (Crc >> 8) ^ mCrcTable[(UINT8)Crc ^ *Ptr]; } =20 *CrcOut =3D Crc ^ 0xffffffff; diff --git a/BaseTools/Source/C/Common/Decompress.c b/BaseTools/Source/C/Co= mmon/Decompress.c index a0f54c08342b..68745e8a0bd7 100644 --- a/BaseTools/Source/C/Common/Decompress.c +++ b/BaseTools/Source/C/Common/Decompress.c @@ -15,52 +15,52 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Decompression algorithm begins here // -#define BITBUFSIZ 32 -#define MAXMATCH 256 -#define THRESHOLD 3 -#define CODE_BIT 16 -#define BAD_TABLE - 1 +#define BITBUFSIZ 32 +#define MAXMATCH 256 +#define THRESHOLD 3 +#define CODE_BIT 16 +#define BAD_TABLE - 1 =20 // // C: Char&Len Set; P: Position Set; T: exTra Set // -#define NC (0xff + MAXMATCH + 2 - THRESHOLD) -#define CBIT 9 -#define EFIPBIT 4 -#define MAXPBIT 5 -#define TBIT 5 -#define MAXNP ((1U << MAXPBIT) - 1) -#define NT (CODE_BIT + 3) +#define NC (0xff + MAXMATCH + 2 - THRESHOLD) +#define CBIT 9 +#define EFIPBIT 4 +#define MAXPBIT 5 +#define TBIT 5 +#define MAXNP ((1U << MAXPBIT) - 1) +#define NT (CODE_BIT + 3) #if NT > MAXNP -#define NPT NT +#define NPT NT #else -#define NPT MAXNP +#define NPT MAXNP #endif =20 typedef struct { - UINT8 *mSrcBase; // Starting address of compressed data - UINT8 *mDstBase; // Starting address of decompressed data - UINT32 mOutBuf; - UINT32 mInBuf; + UINT8 *mSrcBase; // Starting address of compressed data + UINT8 *mDstBase; // Starting address of decompressed data + UINT32 mOutBuf; + UINT32 mInBuf; =20 - UINT16 mBitCount; - UINT32 mBitBuf; - UINT32 mSubBitBuf; - UINT16 mBlockSize; - UINT32 mCompSize; - UINT32 mOrigSize; + UINT16 mBitCount; + UINT32 mBitBuf; + UINT32 mSubBitBuf; + UINT16 mBlockSize; + UINT32 mCompSize; + UINT32 mOrigSize; =20 - UINT16 mBadTableFlag; + UINT16 mBadTableFlag; =20 - UINT16 mLeft[2 * NC - 1]; - UINT16 mRight[2 * NC - 1]; - UINT8 mCLen[NC]; - UINT8 mPTLen[NPT]; - UINT16 mCTable[4096]; - UINT16 mPTTable[256]; + UINT16 mLeft[2 * NC - 1]; + UINT16 mRight[2 * NC - 1]; + UINT8 mCLen[NC]; + UINT8 mPTLen[NPT]; + UINT16 mCTable[4096]; + UINT16 mPTTable[256]; } SCRATCH_DATA; =20 -STATIC UINT16 mPbit =3D EFIPBIT; +STATIC UINT16 mPbit =3D EFIPBIT; =20 /** Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source. @@ -75,33 +75,30 @@ FillBuf ( IN UINT16 NumOfBits ) { - Sd->mBitBuf =3D (UINT32) (((UINT64)Sd->mBitBuf) << NumOfBits); + Sd->mBitBuf =3D (UINT32)(((UINT64)Sd->mBitBuf) << NumOfBits); =20 while (NumOfBits > Sd->mBitCount) { - - Sd->mBitBuf |=3D (UINT32) (((UINT64)Sd->mSubBitBuf) << (NumOfBits =3D = (UINT16) (NumOfBits - Sd->mBitCount))); + Sd->mBitBuf |=3D (UINT32)(((UINT64)Sd->mSubBitBuf) << (NumOfBits =3D (= UINT16)(NumOfBits - Sd->mBitCount))); =20 if (Sd->mCompSize > 0) { // // Get 1 byte into SubBitBuf // Sd->mCompSize--; - Sd->mSubBitBuf =3D 0; - Sd->mSubBitBuf =3D Sd->mSrcBase[Sd->mInBuf++]; - Sd->mBitCount =3D 8; - + Sd->mSubBitBuf =3D 0; + Sd->mSubBitBuf =3D Sd->mSrcBase[Sd->mInBuf++]; + Sd->mBitCount =3D 8; } else { // // No more bits from the source, just pad zero bit. // - Sd->mSubBitBuf =3D 0; - Sd->mBitCount =3D 8; - + Sd->mSubBitBuf =3D 0; + Sd->mBitCount =3D 8; } } =20 - Sd->mBitCount =3D (UINT16) (Sd->mBitCount - NumOfBits); - Sd->mBitBuf |=3D Sd->mSubBitBuf >> Sd->mBitCount; + Sd->mBitCount =3D (UINT16)(Sd->mBitCount - NumOfBits); + Sd->mBitBuf |=3D Sd->mSubBitBuf >> Sd->mBitCount; } =20 /** @@ -123,7 +120,7 @@ GetBits ( { UINT32 OutBits; =20 - OutBits =3D (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits)); + OutBits =3D (UINT32)(Sd->mBitBuf >> (BITBUFSIZ - NumOfBits)); =20 FillBuf (Sd, NumOfBits); =20 @@ -172,76 +169,73 @@ MakeTable ( =20 for (Index =3D 0; Index < NumOfChar; Index++) { if (BitLen[Index] > 16) { - return (UINT16) BAD_TABLE; + return (UINT16)BAD_TABLE; } + Count[BitLen[Index]]++; } =20 Start[1] =3D 0; =20 for (Index =3D 1; Index <=3D 16; Index++) { - Start[Index + 1] =3D (UINT16) (Start[Index] + (Count[Index] << (16 - I= ndex))); + Start[Index + 1] =3D (UINT16)(Start[Index] + (Count[Index] << (16 - In= dex))); } =20 if (Start[17] !=3D 0) { /*(1U << 16)*/ - return (UINT16) BAD_TABLE; + return (UINT16)BAD_TABLE; } =20 - JuBits =3D (UINT16) (16 - TableBits); + JuBits =3D (UINT16)(16 - TableBits); =20 for (Index =3D 1; Index <=3D TableBits; Index++) { Start[Index] >>=3D JuBits; - Weight[Index] =3D (UINT16) (1U << (TableBits - Index)); + Weight[Index] =3D (UINT16)(1U << (TableBits - Index)); } =20 while (Index <=3D 16) { - Weight[Index] =3D (UINT16) (1U << (16 - Index)); + Weight[Index] =3D (UINT16)(1U << (16 - Index)); Index++; } =20 - Index =3D (UINT16) (Start[TableBits + 1] >> JuBits); + Index =3D (UINT16)(Start[TableBits + 1] >> JuBits); =20 if (Index !=3D 0) { - Index3 =3D (UINT16) (1U << TableBits); + Index3 =3D (UINT16)(1U << TableBits); while (Index !=3D Index3) { Table[Index++] =3D 0; } } =20 - Avail =3D NumOfChar; - Mask =3D (UINT16) (1U << (15 - TableBits)); - MaxTableLength =3D (UINT16) (1U << TableBits); + Avail =3D NumOfChar; + Mask =3D (UINT16)(1U << (15 - TableBits)); + MaxTableLength =3D (UINT16)(1U << TableBits); =20 for (Char =3D 0; Char < NumOfChar; Char++) { - Len =3D BitLen[Char]; - if (Len =3D=3D 0 || Len >=3D 17) { + if ((Len =3D=3D 0) || (Len >=3D 17)) { continue; } =20 - NextCode =3D (UINT16) (Start[Len] + Weight[Len]); + NextCode =3D (UINT16)(Start[Len] + Weight[Len]); =20 if (Len <=3D TableBits) { - - if (Start[Len] >=3D NextCode || NextCode > MaxTableLength){ - return (UINT16) BAD_TABLE; + if ((Start[Len] >=3D NextCode) || (NextCode > MaxTableLength)) { + return (UINT16)BAD_TABLE; } =20 for (Index =3D Start[Len]; Index < NextCode; Index++) { Table[Index] =3D Char; } - } else { - Index3 =3D Start[Len]; Pointer =3D &Table[Index3 >> JuBits]; - Index =3D (UINT16) (Len - TableBits); + Index =3D (UINT16)(Len - TableBits); =20 while (Index !=3D 0) { if (*Pointer =3D=3D 0) { - Sd->mRight[Avail] =3D Sd->mLeft[Avail] =3D 0; - *Pointer =3D Avail++; + Sd->mRight[Avail] =3D Sd->mLeft[Avail] =3D 0; + *Pointer =3D Avail++; } =20 if (Index3 & Mask) { @@ -255,11 +249,11 @@ MakeTable ( } =20 *Pointer =3D Char; - } =20 Start[Len] =3D NextCode; } + // // Succeeds // @@ -289,7 +283,6 @@ DecodeP ( Mask =3D 1U << (BITBUFSIZ - 1 - 8); =20 do { - if (Sd->mBitBuf & Mask) { Val =3D Sd->mRight[Val]; } else { @@ -299,6 +292,7 @@ DecodeP ( Mask >>=3D 1; } while (Val >=3D MAXNP); } + // // Advance what we have read // @@ -306,7 +300,7 @@ DecodeP ( =20 Pos =3D Val; if (Val > 1) { - Pos =3D (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1))= ); + Pos =3D (UINT32)((1U << (Val - 1)) + GetBits (Sd, (UINT16)(Val - 1))); } =20 return Pos; @@ -339,10 +333,10 @@ ReadPTLen ( =20 assert (nn <=3D NPT); =20 - Number =3D (UINT16) GetBits (Sd, nbit); + Number =3D (UINT16)GetBits (Sd, nbit); =20 if (Number =3D=3D 0) { - CharC =3D (UINT16) GetBits (Sd, nbit); + CharC =3D (UINT16)GetBits (Sd, nbit); =20 for (Index =3D 0; Index < 256; Index++) { Sd->mPTTable[Index] =3D CharC; @@ -358,8 +352,7 @@ ReadPTLen ( Index =3D 0; =20 while (Index < Number && Index < NPT) { - - CharC =3D (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3)); + CharC =3D (UINT16)(Sd->mBitBuf >> (BITBUFSIZ - 3)); =20 if (CharC =3D=3D 7) { Mask =3D 1U << (BITBUFSIZ - 1 - 3); @@ -369,14 +362,14 @@ ReadPTLen ( } } =20 - FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3)); + FillBuf (Sd, (UINT16)((CharC < 7) ? 3 : CharC - 3)); =20 - Sd->mPTLen[Index++] =3D (UINT8) CharC; + Sd->mPTLen[Index++] =3D (UINT8)CharC; =20 if (Index =3D=3D Special) { - CharC =3D (UINT16) GetBits (Sd, 2); + CharC =3D (UINT16)GetBits (Sd, 2); CharC--; - while ((INT16) (CharC) >=3D 0 && Index < NPT) { + while ((INT16)(CharC) >=3D 0 && Index < NPT) { Sd->mPTLen[Index++] =3D 0; CharC--; } @@ -406,10 +399,10 @@ ReadCLen ( UINT16 Index; UINT32 Mask; =20 - Number =3D (UINT16) GetBits (Sd, CBIT); + Number =3D (UINT16)GetBits (Sd, CBIT); =20 if (Number =3D=3D 0) { - CharC =3D (UINT16) GetBits (Sd, CBIT); + CharC =3D (UINT16)GetBits (Sd, CBIT); =20 for (Index =3D 0; Index < NC; Index++) { Sd->mCLen[Index] =3D 0; @@ -419,18 +412,16 @@ ReadCLen ( Sd->mCTable[Index] =3D CharC; } =20 - return ; + return; } =20 Index =3D 0; while (Index < Number) { - CharC =3D Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)]; if (CharC >=3D NT) { Mask =3D 1U << (BITBUFSIZ - 1 - 8); =20 do { - if (Mask & Sd->mBitBuf) { CharC =3D Sd->mRight[CharC]; } else { @@ -438,34 +429,30 @@ ReadCLen ( } =20 Mask >>=3D 1; - } while (CharC >=3D NT); } + // // Advance what we have read // FillBuf (Sd, Sd->mPTLen[CharC]); =20 if (CharC <=3D 2) { - if (CharC =3D=3D 0) { CharC =3D 1; } else if (CharC =3D=3D 1) { - CharC =3D (UINT16) (GetBits (Sd, 4) + 3); + CharC =3D (UINT16)(GetBits (Sd, 4) + 3); } else if (CharC =3D=3D 2) { - CharC =3D (UINT16) (GetBits (Sd, CBIT) + 20); + CharC =3D (UINT16)(GetBits (Sd, CBIT) + 20); } =20 CharC--; - while ((INT16) (CharC) >=3D 0) { + while ((INT16)(CharC) >=3D 0) { Sd->mCLen[Index++] =3D 0; CharC--; } - } else { - - Sd->mCLen[Index++] =3D (UINT8) (CharC - 2); - + Sd->mCLen[Index++] =3D (UINT8)(CharC - 2); } } =20 @@ -475,7 +462,7 @@ ReadCLen ( =20 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable); =20 - return ; + return; } =20 /** @@ -498,7 +485,7 @@ DecodeC ( // // Starting a new block // - Sd->mBlockSize =3D (UINT16) GetBits (Sd, 16); + Sd->mBlockSize =3D (UINT16)GetBits (Sd, 16); Sd->mBadTableFlag =3D ReadPTLen (Sd, NT, TBIT, 3); if (Sd->mBadTableFlag !=3D 0) { return 0; @@ -506,7 +493,7 @@ DecodeC ( =20 ReadCLen (Sd); =20 - Sd->mBadTableFlag =3D ReadPTLen (Sd, MAXNP, mPbit, (UINT16) (-1)); + Sd->mBadTableFlag =3D ReadPTLen (Sd, MAXNP, mPbit, (UINT16)(-1)); if (Sd->mBadTableFlag !=3D 0) { return 0; } @@ -528,6 +515,7 @@ DecodeC ( Mask >>=3D 1; } while (Index2 >=3D NC); } + // // Advance what we have read // @@ -551,58 +539,60 @@ Decode ( UINT32 DataIdx; UINT16 CharC; =20 - BytesRemain =3D (UINT16) (-1); + BytesRemain =3D (UINT16)(-1); =20 - DataIdx =3D 0; + DataIdx =3D 0; =20 - for (;;) { + for ( ; ;) { CharC =3D DecodeC (Sd); if (Sd->mBadTableFlag !=3D 0) { - return ; + return; } =20 if (CharC < 256) { // // Process an Original character // - Sd->mDstBase[Sd->mOutBuf++] =3D (UINT8) CharC; + Sd->mDstBase[Sd->mOutBuf++] =3D (UINT8)CharC; if (Sd->mOutBuf >=3D Sd->mOrigSize) { - return ; + return; } - } else { // // Process a Pointer // - CharC =3D (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD)); + CharC =3D (UINT16)(CharC - (UINT8_MAX + 1 - THRESHOLD)); =20 BytesRemain =3D CharC; =20 - DataIdx =3D Sd->mOutBuf - DecodeP (Sd) - 1; + DataIdx =3D Sd->mOutBuf - DecodeP (Sd) - 1; =20 BytesRemain--; - while ((INT16) (BytesRemain) >=3D 0) { + while ((INT16)(BytesRemain) >=3D 0) { if (Sd->mOutBuf >=3D Sd->mOrigSize) { - return ; + return; } + if (DataIdx >=3D Sd->mOrigSize) { - Sd->mBadTableFlag =3D (UINT16) BAD_TABLE; - return ; + Sd->mBadTableFlag =3D (UINT16)BAD_TABLE; + return; } + Sd->mDstBase[Sd->mOutBuf++] =3D Sd->mDstBase[DataIdx++]; =20 BytesRemain--; } + // // Once mOutBuf is fully filled, directly return // if (Sd->mOutBuf >=3D Sd->mOrigSize) { - return ; + return; } } } =20 - return ; + return; } =20 /** @@ -624,12 +614,12 @@ GetInfo ( OUT UINT32 *ScratchSize ) { - UINT8 *Src; - UINT32 CompSize; + UINT8 *Src; + UINT32 CompSize; =20 - *ScratchSize =3D sizeof (SCRATCH_DATA); + *ScratchSize =3D sizeof (SCRATCH_DATA); =20 - Src =3D Source; + Src =3D Source; if (SrcSize < 8) { return EFI_INVALID_PARAMETER; } @@ -637,7 +627,7 @@ GetInfo ( CompSize =3D Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24); *DstSize =3D Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); =20 - if (SrcSize < CompSize + 8 || (CompSize + 8) < 8) { + if ((SrcSize < CompSize + 8) || ((CompSize + 8) < 8)) { return EFI_INVALID_PARAMETER; } =20 @@ -675,24 +665,24 @@ Decompress ( UINT8 *Src; UINT8 *Dst; =20 - Status =3D EFI_SUCCESS; - Src =3D Source; - Dst =3D Destination; + Status =3D EFI_SUCCESS; + Src =3D Source; + Dst =3D Destination; =20 if (ScratchSize < sizeof (SCRATCH_DATA)) { return EFI_INVALID_PARAMETER; } =20 - Sd =3D (SCRATCH_DATA *) Scratch; + Sd =3D (SCRATCH_DATA *)Scratch; =20 if (SrcSize < 8) { return EFI_INVALID_PARAMETER; } =20 - CompSize =3D Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24); - OrigSize =3D Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); + CompSize =3D Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24); + OrigSize =3D Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); =20 - if (SrcSize < CompSize + 8 || (CompSize + 8) < 8) { + if ((SrcSize < CompSize + 8) || ((CompSize + 8) < 8)) { return EFI_INVALID_PARAMETER; } =20 @@ -703,7 +693,7 @@ Decompress ( Src =3D Src + 8; =20 for (Index =3D 0; Index < sizeof (SCRATCH_DATA); Index++) { - ((UINT8 *) Sd)[Index] =3D 0; + ((UINT8 *)Sd)[Index] =3D 0; } =20 Sd->mSrcBase =3D Src; @@ -833,63 +823,66 @@ EFI_STATUS Extract ( IN VOID *Source, IN UINT32 SrcSize, - OUT VOID **Destination, - OUT UINT32 *DstSize, + OUT VOID **Destination, + OUT UINT32 *DstSize, IN UINTN Algorithm ) { - VOID *Scratch; - UINT32 ScratchSize; - EFI_STATUS Status; + VOID *Scratch; + UINT32 ScratchSize; + EFI_STATUS Status; =20 Scratch =3D NULL; Status =3D EFI_SUCCESS; =20 switch (Algorithm) { - case 0: - *Destination =3D (VOID *)malloc(SrcSize); - if (*Destination !=3D NULL) { - memcpy(*Destination, Source, SrcSize); - } else { - Status =3D EFI_OUT_OF_RESOURCES; - } - break; - case 1: - Status =3D EfiGetInfo(Source, SrcSize, DstSize, &ScratchSize); - if (Status =3D=3D EFI_SUCCESS) { - Scratch =3D (VOID *)malloc(ScratchSize); - if (Scratch =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; + case 0: + *Destination =3D (VOID *)malloc (SrcSize); + if (*Destination !=3D NULL) { + memcpy (*Destination, Source, SrcSize); + } else { + Status =3D EFI_OUT_OF_RESOURCES; } =20 - *Destination =3D (VOID *)malloc(*DstSize); - if (*Destination =3D=3D NULL) { - free (Scratch); - return EFI_OUT_OF_RESOURCES; - } + break; + case 1: + Status =3D EfiGetInfo (Source, SrcSize, DstSize, &ScratchSize); + if (Status =3D=3D EFI_SUCCESS) { + Scratch =3D (VOID *)malloc (ScratchSize); + if (Scratch =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *Destination =3D (VOID *)malloc (*DstSize); + if (*Destination =3D=3D NULL) { + free (Scratch); + return EFI_OUT_OF_RESOURCES; + } =20 - Status =3D EfiDecompress(Source, SrcSize, *Destination, *DstSize, Sc= ratch, ScratchSize); - } - break; - case 2: - Status =3D TianoGetInfo(Source, SrcSize, DstSize, &ScratchSize); - if (Status =3D=3D EFI_SUCCESS) { - Scratch =3D (VOID *)malloc(ScratchSize); - if (Scratch =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; + Status =3D EfiDecompress (Source, SrcSize, *Destination, *DstSize,= Scratch, ScratchSize); } =20 - *Destination =3D (VOID *)malloc(*DstSize); - if (*Destination =3D=3D NULL) { - free (Scratch); - return EFI_OUT_OF_RESOURCES; + break; + case 2: + Status =3D TianoGetInfo (Source, SrcSize, DstSize, &ScratchSize); + if (Status =3D=3D EFI_SUCCESS) { + Scratch =3D (VOID *)malloc (ScratchSize); + if (Scratch =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *Destination =3D (VOID *)malloc (*DstSize); + if (*Destination =3D=3D NULL) { + free (Scratch); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D TianoDecompress (Source, SrcSize, *Destination, *DstSiz= e, Scratch, ScratchSize); } =20 - Status =3D TianoDecompress(Source, SrcSize, *Destination, *DstSize, = Scratch, ScratchSize); - } - break; - default: - Status =3D EFI_INVALID_PARAMETER; + break; + default: + Status =3D EFI_INVALID_PARAMETER; } =20 if (Scratch !=3D NULL) { @@ -898,5 +891,3 @@ Extract ( =20 return Status; } - - diff --git a/BaseTools/Source/C/Common/EfiCompress.c b/BaseTools/Source/C/C= ommon/EfiCompress.c index 0db958b8535a..badcc4d83972 100644 --- a/BaseTools/Source/C/Common/EfiCompress.c +++ b/BaseTools/Source/C/Common/EfiCompress.c @@ -11,42 +11,41 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "Compress.h" =20 - // // Macro Definitions // =20 #undef UINT8_MAX -typedef INT16 NODE; -#define UINT8_MAX 0xff -#define UINT8_BIT 8 -#define THRESHOLD 3 -#define INIT_CRC 0 -#define WNDBIT 13 -#define WNDSIZ (1U << WNDBIT) -#define MAXMATCH 256 -#define PERC_FLAG 0x8000U -#define CODE_BIT 16 -#define NIL 0 -#define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX) -#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2) -#define CRCPOLY 0xA001 -#define UPDATE_CRC(c) mCrc =3D mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc = >> UINT8_BIT) +typedef INT16 NODE; +#define UINT8_MAX 0xff +#define UINT8_BIT 8 +#define THRESHOLD 3 +#define INIT_CRC 0 +#define WNDBIT 13 +#define WNDSIZ (1U << WNDBIT) +#define MAXMATCH 256 +#define PERC_FLAG 0x8000U +#define CODE_BIT 16 +#define NIL 0 +#define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX) +#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2) +#define CRCPOLY 0xA001 +#define UPDATE_CRC(c) mCrc =3D mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> = UINT8_BIT) =20 // // C: the Char&Len Set; P: the Position Set; T: the exTra Set // =20 -#define NC (UINT8_MAX + MAXMATCH + 2 - THRESHOLD) -#define CBIT 9 -#define NP (WNDBIT + 1) -#define PBIT 4 -#define NT (CODE_BIT + 3) -#define TBIT 5 +#define NC (UINT8_MAX + MAXMATCH + 2 - THRESHOLD) +#define CBIT 9 +#define NP (WNDBIT + 1) +#define PBIT 4 +#define NT (CODE_BIT + 3) +#define TBIT 5 #if NT > NP - #define NPT NT +#define NPT NT #else - #define NPT NP +#define NPT NP #endif =20 // @@ -55,8 +54,8 @@ typedef INT16 NODE; =20 STATIC VOID -PutDword( - IN UINT32 Data +PutDword ( + IN UINT32 Data ); =20 STATIC @@ -77,22 +76,22 @@ InitSlide ( STATIC NODE Child ( - IN NODE q, - IN UINT8 c + IN NODE q, + IN UINT8 c ); =20 STATIC VOID MakeChild ( - IN NODE q, - IN UINT8 c, - IN NODE r + IN NODE q, + IN UINT8 c, + IN NODE r ); =20 STATIC VOID Split ( - IN NODE Old + IN NODE Old ); =20 STATIC @@ -123,9 +122,9 @@ CountTFreq ( STATIC VOID WritePTLen ( - IN INT32 n, - IN INT32 nbit, - IN INT32 Special + IN INT32 n, + IN INT32 nbit, + IN INT32 Special ); =20 STATIC @@ -136,13 +135,13 @@ WriteCLen ( STATIC VOID EncodeC ( - IN INT32 c + IN INT32 c ); =20 STATIC VOID EncodeP ( - IN UINT32 p + IN UINT32 p ); =20 STATIC @@ -153,8 +152,8 @@ SendBlock ( STATIC VOID Output ( - IN UINT32 c, - IN UINT32 p + IN UINT32 c, + IN UINT32 p ); =20 STATIC @@ -175,15 +174,15 @@ MakeCrcTable ( STATIC VOID PutBits ( - IN INT32 n, - IN UINT32 x + IN INT32 n, + IN UINT32 x ); =20 STATIC INT32 FreadCrc ( - OUT UINT8 *p, - IN INT32 n + OUT UINT8 *p, + IN INT32 n ); =20 STATIC @@ -194,27 +193,27 @@ InitPutBits ( STATIC VOID CountLen ( - IN INT32 i + IN INT32 i ); =20 STATIC VOID MakeLen ( - IN INT32 Root + IN INT32 Root ); =20 STATIC VOID DownHeap ( - IN INT32 i + IN INT32 i ); =20 STATIC VOID MakeCode ( - IN INT32 n, - IN UINT8 Len[], - OUT UINT16 Code[] + IN INT32 n, + IN UINT8 Len[], + OUT UINT16 Code[] ); =20 STATIC @@ -226,25 +225,23 @@ MakeTree ( OUT UINT16 CodeParm[] ); =20 - // // Global Variables // =20 STATIC UINT8 *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit; =20 -STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT]= , *mLen; -STATIC INT16 mHeap[NC + 1]; -STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN; -STATIC UINT32 mBufSiz =3D 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc; -STATIC UINT32 mCompSize, mOrigSize; +STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT= ], *mLen; +STATIC INT16 mHeap[NC + 1]; +STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN; +STATIC UINT32 mBufSiz =3D 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc; +STATIC UINT32 mCompSize, mOrigSize; =20 -STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2 = * NC - 1], - mCrcTable[UINT8_MAX + 1], mCFreq[2 * NC - 1],mCCode[NC], - mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq[2 * NT - 1]; - -STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNex= t =3D NULL; +STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2= * NC - 1], + mCrcTable[UINT8_MAX + 1], mCFreq[2 * NC - 1], mCCode[NC], + mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq[2 * NT - 1]; =20 +STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNext= =3D NULL; =20 // // functions @@ -272,13 +269,13 @@ EfiCompress ( IN OUT UINT32 *DstSize ) { - EFI_STATUS Status =3D EFI_SUCCESS; + EFI_STATUS Status =3D EFI_SUCCESS; =20 // // Initializations // - mBufSiz =3D 0; - mBuf =3D NULL; + mBufSiz =3D 0; + mBuf =3D NULL; mText =3D NULL; mLevel =3D NULL; mChildCount =3D NULL; @@ -287,25 +284,24 @@ EfiCompress ( mPrev =3D NULL; mNext =3D NULL; =20 - - mSrc =3D SrcBuffer; + mSrc =3D SrcBuffer; mSrcUpperLimit =3D mSrc + SrcSize; - mDst =3D DstBuffer; + mDst =3D DstBuffer; mDstUpperLimit =3D mDst + *DstSize; =20 - PutDword(0L); - PutDword(0L); + PutDword (0L); + PutDword (0L); =20 MakeCrcTable (); =20 mOrigSize =3D mCompSize =3D 0; - mCrc =3D INIT_CRC; + mCrc =3D INIT_CRC; =20 // // Compress it // =20 - Status =3D Encode(); + Status =3D Encode (); if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } @@ -321,8 +317,8 @@ EfiCompress ( // Fill in compressed size and original size // mDst =3D DstBuffer; - PutDword(mCompSize+1); - PutDword(mOrigSize); + PutDword (mCompSize+1); + PutDword (mOrigSize); =20 // // Return @@ -335,7 +331,6 @@ EfiCompress ( *DstSize =3D mCompSize + 1 + 8; return EFI_SUCCESS; } - } =20 /** @@ -345,12 +340,12 @@ EfiCompress ( **/ STATIC VOID -PutDword( - IN UINT32 Data +PutDword ( + IN UINT32 Data ) { if (mDst < mDstUpperLimit) { - *mDst++ =3D (UINT8)(((UINT8)(Data )) & 0xff); + *mDst++ =3D (UINT8)(((UINT8)(Data)) & 0xff); } =20 if (mDst < mDstUpperLimit) { @@ -374,36 +369,40 @@ PutDword( **/ STATIC EFI_STATUS -AllocateMemory () +AllocateMemory ( + ) { - UINT32 i; + UINT32 i; =20 - mText =3D malloc (WNDSIZ * 2 + MAXMATCH); + mText =3D malloc (WNDSIZ * 2 + MAXMATCH); if (mText =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } - for (i =3D 0 ; i < WNDSIZ * 2 + MAXMATCH; i ++) { + + for (i =3D 0; i < WNDSIZ * 2 + MAXMATCH; i++) { mText[i] =3D 0; } =20 - mLevel =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mLevel)); - mChildCount =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mChildCount)); - mPosition =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mPosition)); - mParent =3D malloc (WNDSIZ * 2 * sizeof(*mParent)); - mPrev =3D malloc (WNDSIZ * 2 * sizeof(*mPrev)); - mNext =3D malloc ((MAX_HASH_VAL + 1) * sizeof(*mNext)); - if (mLevel =3D=3D NULL || mChildCount =3D=3D NULL || mPosition =3D=3D NU= LL || - mParent =3D=3D NULL || mPrev =3D=3D NULL || mNext =3D=3D NULL) { + mLevel =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel)); + mChildCount =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mChildCount)= ); + mPosition =3D malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition)); + mParent =3D malloc (WNDSIZ * 2 * sizeof (*mParent)); + mPrev =3D malloc (WNDSIZ * 2 * sizeof (*mPrev)); + mNext =3D malloc ((MAX_HASH_VAL + 1) * sizeof (*mNext)); + if ((mLevel =3D=3D NULL) || (mChildCount =3D=3D NULL) || (mPosition =3D= =3D NULL) || + (mParent =3D=3D NULL) || (mPrev =3D=3D NULL) || (mNext =3D=3D NULL)) + { return EFI_OUT_OF_RESOURCES; } =20 mBufSiz =3D 16 * 1024U; - while ((mBuf =3D malloc(mBufSiz)) =3D=3D NULL) { + while ((mBuf =3D malloc (mBufSiz)) =3D=3D NULL) { mBufSiz =3D (mBufSiz / 10U) * 9U; if (mBufSiz < 4 * 1024U) { return EFI_OUT_OF_RESOURCES; } } + mBuf[0] =3D 0; =20 return EFI_SUCCESS; @@ -413,7 +412,8 @@ AllocateMemory () Called when compression is completed to free memory previously allocated. **/ VOID -FreeMemory () +FreeMemory ( + ) { if (mText) { free (mText); @@ -455,17 +455,20 @@ FreeMemory () **/ STATIC VOID -InitSlide () +InitSlide ( + ) { - NODE i; + NODE i; =20 for (i =3D WNDSIZ; i <=3D WNDSIZ + UINT8_MAX; i++) { - mLevel[i] =3D 1; + mLevel[i] =3D 1; mPosition[i] =3D NIL; /* sentinel */ } + for (i =3D WNDSIZ; i < WNDSIZ * 2; i++) { mParent[i] =3D NIL; } + mAvail =3D 1; for (i =3D 1; i < WNDSIZ - 1; i++) { mNext[i] =3D (NODE)(i + 1); @@ -488,13 +491,13 @@ InitSlide () STATIC NODE Child ( - IN NODE q, - IN UINT8 c + IN NODE q, + IN UINT8 c ) { - NODE r; + NODE r; =20 - r =3D mNext[HASH(q, c)]; + r =3D mNext[HASH (q, c)]; mParent[NIL] =3D q; /* sentinel */ while (mParent[r] !=3D q) { r =3D mNext[r]; @@ -513,19 +516,19 @@ Child ( STATIC VOID MakeChild ( - IN NODE q, - IN UINT8 c, - IN NODE r + IN NODE q, + IN UINT8 c, + IN NODE r ) { - NODE h, t; + NODE h, t; =20 - h =3D (NODE)HASH(q, c); - t =3D mNext[h]; - mNext[h] =3D r; - mNext[r] =3D t; - mPrev[t] =3D r; - mPrev[r] =3D h; + h =3D (NODE)HASH (q, c); + t =3D mNext[h]; + mNext[h] =3D r; + mNext[r] =3D t; + mPrev[t] =3D r; + mPrev[r] =3D h; mParent[r] =3D q; mChildCount[q]++; } @@ -538,25 +541,25 @@ MakeChild ( STATIC VOID Split ( - NODE Old + NODE Old ) { - NODE New, t; + NODE New, t; =20 - New =3D mAvail; - mAvail =3D mNext[New]; + New =3D mAvail; + mAvail =3D mNext[New]; mChildCount[New] =3D 0; - t =3D mPrev[Old]; - mPrev[New] =3D t; - mNext[t] =3D New; - t =3D mNext[Old]; - mNext[New] =3D t; - mPrev[t] =3D New; - mParent[New] =3D mParent[Old]; - mLevel[New] =3D (UINT8)mMatchLen; - mPosition[New] =3D mPos; - MakeChild(New, mText[mMatchPos + mMatchLen], Old); - MakeChild(New, mText[mPos + mMatchLen], mPos); + t =3D mPrev[Old]; + mPrev[New] =3D t; + mNext[t] =3D New; + t =3D mNext[Old]; + mNext[New] =3D t; + mPrev[t] =3D New; + mParent[New] =3D mParent[Old]; + mLevel[New] =3D (UINT8)mMatchLen; + mPosition[New] =3D mPos; + MakeChild (New, mText[mMatchPos + mMatchLen], Old); + MakeChild (New, mText[mPos + mMatchLen], mPos); } =20 /** @@ -564,13 +567,13 @@ Split ( **/ STATIC VOID -InsertNode () +InsertNode ( + ) { - NODE q, r, j, t; - UINT8 c, *t1, *t2; + NODE q, r, j, t; + UINT8 c, *t1, *t2; =20 if (mMatchLen >=3D 4) { - // // We have just got a long match, the target tree // can be located by MatchPos + 1. Traverse the tree @@ -584,30 +587,34 @@ InsertNode () while ((q =3D mParent[r]) =3D=3D NIL) { r =3D mNext[r]; } + while (mLevel[q] >=3D mMatchLen) { - r =3D q; q =3D mParent[q]; + r =3D q; + q =3D mParent[q]; } + t =3D q; while (mPosition[t] < 0) { mPosition[t] =3D mPos; - t =3D mParent[t]; + t =3D mParent[t]; } + if (t < WNDSIZ) { mPosition[t] =3D (NODE)(mPos | PERC_FLAG); } } else { - // // Locate the target tree // =20 q =3D (INT16)(mText[mPos] + WNDSIZ); c =3D mText[mPos + 1]; - if ((r =3D Child(q, c)) =3D=3D NIL) { - MakeChild(q, c, mPos); + if ((r =3D Child (q, c)) =3D=3D NIL) { + MakeChild (q, c, mPos); mMatchLen =3D 1; return; } + mMatchLen =3D 2; } =20 @@ -619,51 +626,57 @@ InsertNode () =20 for ( ; ; ) { if (r >=3D WNDSIZ) { - j =3D MAXMATCH; + j =3D MAXMATCH; mMatchPos =3D r; } else { - j =3D mLevel[r]; + j =3D mLevel[r]; mMatchPos =3D (NODE)(mPosition[r] & ~PERC_FLAG); } + if (mMatchPos >=3D mPos) { mMatchPos -=3D WNDSIZ; } + t1 =3D &mText[mPos + mMatchLen]; t2 =3D &mText[mMatchPos + mMatchLen]; while (mMatchLen < j) { if (*t1 !=3D *t2) { - Split(r); + Split (r); return; } + mMatchLen++; t1++; t2++; } + if (mMatchLen >=3D MAXMATCH) { break; } + mPosition[r] =3D mPos; - q =3D r; - if ((r =3D Child(q, *t1)) =3D=3D NIL) { - MakeChild(q, *t1, mPos); + q =3D r; + if ((r =3D Child (q, *t1)) =3D=3D NIL) { + MakeChild (q, *t1, mPos); return; } + mMatchLen++; } - t =3D mPrev[r]; - mPrev[mPos] =3D t; - mNext[t] =3D mPos; - t =3D mNext[r]; - mNext[mPos] =3D t; - mPrev[t] =3D mPos; + + t =3D mPrev[r]; + mPrev[mPos] =3D t; + mNext[t] =3D mPos; + t =3D mNext[r]; + mNext[mPos] =3D t; + mPrev[t] =3D mPos; mParent[mPos] =3D q; - mParent[r] =3D NIL; + mParent[r] =3D NIL; =20 // // Special usage of 'next' // mNext[r] =3D mPos; - } =20 /** @@ -672,27 +685,30 @@ InsertNode () **/ STATIC VOID -DeleteNode () +DeleteNode ( + ) { - NODE q, r, s, t, u; + NODE q, r, s, t, u; =20 if (mParent[mPos] =3D=3D NIL) { return; } =20 - r =3D mPrev[mPos]; - s =3D mNext[mPos]; - mNext[r] =3D s; - mPrev[s] =3D r; - r =3D mParent[mPos]; + r =3D mPrev[mPos]; + s =3D mNext[mPos]; + mNext[r] =3D s; + mPrev[s] =3D r; + r =3D mParent[mPos]; mParent[mPos] =3D NIL; - if (r >=3D WNDSIZ || --mChildCount[r] > 1) { + if ((r >=3D WNDSIZ) || (--mChildCount[r] > 1)) { return; } + t =3D (NODE)(mPosition[r] & ~PERC_FLAG); if (t >=3D mPos) { t -=3D WNDSIZ; } + s =3D t; q =3D mParent[r]; while ((u =3D mPosition[q]) & PERC_FLAG) { @@ -700,36 +716,42 @@ DeleteNode () if (u >=3D mPos) { u -=3D WNDSIZ; } + if (u > s) { s =3D u; } + mPosition[q] =3D (INT16)(s | WNDSIZ); - q =3D mParent[q]; + q =3D mParent[q]; } + if (q < WNDSIZ) { if (u >=3D mPos) { u -=3D WNDSIZ; } + if (u > s) { s =3D u; } + mPosition[q] =3D (INT16)(s | WNDSIZ | PERC_FLAG); } - s =3D Child(r, mText[t + mLevel[r]]); - t =3D mPrev[s]; - u =3D mNext[s]; - mNext[t] =3D u; - mPrev[u] =3D t; - t =3D mPrev[r]; - mNext[t] =3D s; - mPrev[s] =3D t; - t =3D mNext[r]; - mPrev[t] =3D s; - mNext[s] =3D t; + + s =3D Child (r, mText[t + mLevel[r]]); + t =3D mPrev[s]; + u =3D mNext[s]; + mNext[t] =3D u; + mPrev[u] =3D t; + t =3D mPrev[r]; + mNext[t] =3D s; + mPrev[s] =3D t; + t =3D mNext[r]; + mPrev[t] =3D s; + mNext[s] =3D t; mParent[s] =3D mParent[r]; mParent[r] =3D NIL; - mNext[r] =3D mAvail; - mAvail =3D r; + mNext[r] =3D mAvail; + mAvail =3D r; } =20 /** @@ -738,19 +760,21 @@ DeleteNode () **/ STATIC VOID -GetNextMatch () +GetNextMatch ( + ) { - INT32 n; + INT32 n; =20 mRemainder--; if (++mPos =3D=3D WNDSIZ * 2) { - memmove(&mText[0], &mText[WNDSIZ], WNDSIZ + MAXMATCH); - n =3D FreadCrc(&mText[WNDSIZ + MAXMATCH], WNDSIZ); + memmove (&mText[0], &mText[WNDSIZ], WNDSIZ + MAXMATCH); + n =3D FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ); mRemainder +=3D n; - mPos =3D WNDSIZ; + mPos =3D WNDSIZ; } - DeleteNode(); - InsertNode(); + + DeleteNode (); + InsertNode (); } =20 /** @@ -761,65 +785,68 @@ GetNextMatch () **/ STATIC EFI_STATUS -Encode () +Encode ( + ) { EFI_STATUS Status; INT32 LastMatchLen; NODE LastMatchPos; =20 - Status =3D AllocateMemory(); - if (EFI_ERROR(Status)) { - FreeMemory(); + Status =3D AllocateMemory (); + if (EFI_ERROR (Status)) { + FreeMemory (); return Status; } =20 - InitSlide(); + InitSlide (); =20 - HufEncodeStart(); + HufEncodeStart (); =20 - mRemainder =3D FreadCrc(&mText[WNDSIZ], WNDSIZ + MAXMATCH); + mRemainder =3D FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH); =20 mMatchLen =3D 0; - mPos =3D WNDSIZ; - InsertNode(); + mPos =3D WNDSIZ; + InsertNode (); if (mMatchLen > mRemainder) { mMatchLen =3D mRemainder; } + while (mRemainder > 0) { LastMatchLen =3D mMatchLen; LastMatchPos =3D mMatchPos; - GetNextMatch(); + GetNextMatch (); if (mMatchLen > mRemainder) { mMatchLen =3D mRemainder; } =20 - if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) { - + if ((mMatchLen > LastMatchLen) || (LastMatchLen < THRESHOLD)) { // // Not enough benefits are gained by outputting a pointer, // so just output the original character // =20 - Output(mText[mPos - 1], 0); + Output (mText[mPos - 1], 0); } else { - // // Outputting a pointer is beneficial enough, do it. // =20 - Output(LastMatchLen + (UINT8_MAX + 1 - THRESHOLD), - (mPos - LastMatchPos - 2) & (WNDSIZ - 1)); + Output ( + LastMatchLen + (UINT8_MAX + 1 - THRESHOLD), + (mPos - LastMatchPos - 2) & (WNDSIZ - 1) + ); while (--LastMatchLen > 0) { - GetNextMatch(); + GetNextMatch (); } + if (mMatchLen > mRemainder) { mMatchLen =3D mRemainder; } } } =20 - HufEncodeEnd(); - FreeMemory(); + HufEncodeEnd (); + FreeMemory (); return EFI_SUCCESS; } =20 @@ -828,17 +855,20 @@ Encode () **/ STATIC VOID -CountTFreq () +CountTFreq ( + ) { - INT32 i, k, n, Count; + INT32 i, k, n, Count; =20 for (i =3D 0; i < NT; i++) { mTFreq[i] =3D 0; } + n =3D NC; while (n > 0 && mCLen[n - 1] =3D=3D 0) { n--; } + i =3D 0; while (i < n) { k =3D mCLen[i++]; @@ -848,6 +878,7 @@ CountTFreq () i++; Count++; } + if (Count <=3D 2) { mTFreq[0] =3D (UINT16)(mTFreq[0] + Count); } else if (Count <=3D 18) { @@ -874,30 +905,33 @@ CountTFreq () STATIC VOID WritePTLen ( - IN INT32 n, - IN INT32 nbit, - IN INT32 Special + IN INT32 n, + IN INT32 nbit, + IN INT32 Special ) { - INT32 i, k; + INT32 i, k; =20 while (n > 0 && mPTLen[n - 1] =3D=3D 0) { n--; } - PutBits(nbit, n); + + PutBits (nbit, n); i =3D 0; while (i < n) { k =3D mPTLen[i++]; if (k <=3D 6) { - PutBits(3, k); + PutBits (3, k); } else { - PutBits(k - 3, (1U << (k - 3)) - 2); + PutBits (k - 3, (1U << (k - 3)) - 2); } + if (i =3D=3D Special) { while (i < 6 && mPTLen[i] =3D=3D 0) { i++; } - PutBits(2, (i - 3) & 3); + + PutBits (2, (i - 3) & 3); } } } @@ -907,15 +941,17 @@ WritePTLen ( **/ STATIC VOID -WriteCLen () +WriteCLen ( + ) { - INT32 i, k, n, Count; + INT32 i, k, n, Count; =20 n =3D NC; while (n > 0 && mCLen[n - 1] =3D=3D 0) { n--; } - PutBits(CBIT, n); + + PutBits (CBIT, n); i =3D 0; while (i < n) { k =3D mCLen[i++]; @@ -925,23 +961,24 @@ WriteCLen () i++; Count++; } + if (Count <=3D 2) { for (k =3D 0; k < Count; k++) { - PutBits(mPTLen[0], mPTCode[0]); + PutBits (mPTLen[0], mPTCode[0]); } } else if (Count <=3D 18) { - PutBits(mPTLen[1], mPTCode[1]); - PutBits(4, Count - 3); + PutBits (mPTLen[1], mPTCode[1]); + PutBits (4, Count - 3); } else if (Count =3D=3D 19) { - PutBits(mPTLen[0], mPTCode[0]); - PutBits(mPTLen[1], mPTCode[1]); - PutBits(4, 15); + PutBits (mPTLen[0], mPTCode[0]); + PutBits (mPTLen[1], mPTCode[1]); + PutBits (4, 15); } else { - PutBits(mPTLen[2], mPTCode[2]); - PutBits(CBIT, Count - 20); + PutBits (mPTLen[2], mPTCode[2]); + PutBits (CBIT, Count - 20); } } else { - PutBits(mPTLen[k + 2], mPTCode[k + 2]); + PutBits (mPTLen[k + 2], mPTCode[k + 2]); } } } @@ -949,19 +986,19 @@ WriteCLen () STATIC VOID EncodeC ( - IN INT32 c + IN INT32 c ) { - PutBits(mCLen[c], mCCode[c]); + PutBits (mCLen[c], mCCode[c]); } =20 STATIC VOID EncodeP ( - IN UINT32 p + IN UINT32 p ) { - UINT32 c, q; + UINT32 c, q; =20 c =3D 0; q =3D p; @@ -969,9 +1006,10 @@ EncodeP ( q >>=3D 1; c++; } - PutBits(mPTLen[c], mPTCode[c]); + + PutBits (mPTLen[c], mPTCode[c]); if (c > 1) { - PutBits(c - 1, p & (0xFFFFU >> (17 - c))); + PutBits (c - 1, p & (0xFFFFU >> (17 - c))); } } =20 @@ -980,37 +1018,42 @@ EncodeP ( **/ STATIC VOID -SendBlock () +SendBlock ( + ) { - UINT32 i, k, Flags, Root, Pos, Size; + UINT32 i, k, Flags, Root, Pos, Size; + Flags =3D 0; =20 - Root =3D MakeTree(NC, mCFreq, mCLen, mCCode); + Root =3D MakeTree (NC, mCFreq, mCLen, mCCode); Size =3D mCFreq[Root]; - PutBits(16, Size); + PutBits (16, Size); if (Root >=3D NC) { - CountTFreq(); - Root =3D MakeTree(NT, mTFreq, mPTLen, mPTCode); + CountTFreq (); + Root =3D MakeTree (NT, mTFreq, mPTLen, mPTCode); if (Root >=3D NT) { - WritePTLen(NT, TBIT, 3); + WritePTLen (NT, TBIT, 3); } else { - PutBits(TBIT, 0); - PutBits(TBIT, Root); + PutBits (TBIT, 0); + PutBits (TBIT, Root); } - WriteCLen(); + + WriteCLen (); } else { - PutBits(TBIT, 0); - PutBits(TBIT, 0); - PutBits(CBIT, 0); - PutBits(CBIT, Root); + PutBits (TBIT, 0); + PutBits (TBIT, 0); + PutBits (CBIT, 0); + PutBits (CBIT, Root); } - Root =3D MakeTree(NP, mPFreq, mPTLen, mPTCode); + + Root =3D MakeTree (NP, mPFreq, mPTLen, mPTCode); if (Root >=3D NP) { - WritePTLen(NP, PBIT, -1); + WritePTLen (NP, PBIT, -1); } else { - PutBits(PBIT, 0); - PutBits(PBIT, Root); + PutBits (PBIT, 0); + PutBits (PBIT, Root); } + Pos =3D 0; for (i =3D 0; i < Size; i++) { if (i % UINT8_BIT =3D=3D 0) { @@ -1018,18 +1061,21 @@ SendBlock () } else { Flags <<=3D 1; } + if (Flags & (1U << (UINT8_BIT - 1))) { - EncodeC(mBuf[Pos++] + (1U << UINT8_BIT)); - k =3D mBuf[Pos++] << UINT8_BIT; + EncodeC (mBuf[Pos++] + (1U << UINT8_BIT)); + k =3D mBuf[Pos++] << UINT8_BIT; k +=3D mBuf[Pos++]; - EncodeP(k); + EncodeP (k); } else { - EncodeC(mBuf[Pos++]); + EncodeC (mBuf[Pos++]); } } + for (i =3D 0; i < NC; i++) { mCFreq[i] =3D 0; } + for (i =3D 0; i < NP; i++) { mPFreq[i] =3D 0; } @@ -1044,73 +1090,80 @@ SendBlock () STATIC VOID Output ( - IN UINT32 c, - IN UINT32 p + IN UINT32 c, + IN UINT32 p ) { - STATIC UINT32 CPos; + STATIC UINT32 CPos; =20 if ((mOutputMask >>=3D 1) =3D=3D 0) { mOutputMask =3D 1U << (UINT8_BIT - 1); if (mOutputPos >=3D mBufSiz - 3 * UINT8_BIT) { - SendBlock(); + SendBlock (); mOutputPos =3D 0; } - CPos =3D mOutputPos++; + + CPos =3D mOutputPos++; mBuf[CPos] =3D 0; } - mBuf[mOutputPos++] =3D (UINT8) c; + + mBuf[mOutputPos++] =3D (UINT8)c; mCFreq[c]++; if (c >=3D (1U << UINT8_BIT)) { - mBuf[CPos] |=3D mOutputMask; + mBuf[CPos] |=3D mOutputMask; mBuf[mOutputPos++] =3D (UINT8)(p >> UINT8_BIT); - mBuf[mOutputPos++] =3D (UINT8) p; - c =3D 0; + mBuf[mOutputPos++] =3D (UINT8)p; + c =3D 0; while (p) { p >>=3D 1; c++; } + mPFreq[c]++; } } =20 STATIC VOID -HufEncodeStart () +HufEncodeStart ( + ) { - INT32 i; + INT32 i; =20 for (i =3D 0; i < NC; i++) { mCFreq[i] =3D 0; } + for (i =3D 0; i < NP; i++) { mPFreq[i] =3D 0; } + mOutputPos =3D mOutputMask =3D 0; - InitPutBits(); + InitPutBits (); return; } =20 STATIC VOID -HufEncodeEnd () +HufEncodeEnd ( + ) { - SendBlock(); + SendBlock (); =20 // // Flush remaining bits // - PutBits(UINT8_BIT - 1, 0); + PutBits (UINT8_BIT - 1, 0); =20 return; } =20 - STATIC VOID -MakeCrcTable () +MakeCrcTable ( + ) { - UINT32 i, j, r; + UINT32 i, j, r; =20 for (i =3D 0; i <=3D UINT8_MAX; i++) { r =3D i; @@ -1121,6 +1174,7 @@ MakeCrcTable () r >>=3D 1; } } + mCrcTable[i] =3D (UINT16)r; } } @@ -1134,30 +1188,30 @@ MakeCrcTable () STATIC VOID PutBits ( - IN INT32 n, - IN UINT32 x + IN INT32 n, + IN UINT32 x ) { - UINT8 Temp; + UINT8 Temp; =20 if (n < mBitCount) { mSubBitBuf |=3D x << (mBitCount -=3D n); } else { - Temp =3D (UINT8)(mSubBitBuf | (x >> (n -=3D mBitCount))); if (mDst < mDstUpperLimit) { *mDst++ =3D Temp; } + mCompSize++; =20 if (n < UINT8_BIT) { mSubBitBuf =3D x << (mBitCount =3D UINT8_BIT - n); } else { - Temp =3D (UINT8)(x >> (n - UINT8_BIT)); if (mDst < mDstUpperLimit) { *mDst++ =3D Temp; } + mCompSize++; =20 mSubBitBuf =3D x << (mBitCount =3D 2 * UINT8_BIT - n); @@ -1176,31 +1230,33 @@ PutBits ( STATIC INT32 FreadCrc ( - OUT UINT8 *p, - IN INT32 n + OUT UINT8 *p, + IN INT32 n ) { - INT32 i; + INT32 i; =20 for (i =3D 0; mSrc < mSrcUpperLimit && i < n; i++) { *p++ =3D *mSrc++; } + n =3D i; =20 - p -=3D n; + p -=3D n; mOrigSize +=3D n; while (--i >=3D 0) { - UPDATE_CRC(*p++); + UPDATE_CRC (*p++); } + return n; } =20 - STATIC VOID -InitPutBits () +InitPutBits ( + ) { - mBitCount =3D UINT8_BIT; + mBitCount =3D UINT8_BIT; mSubBitBuf =3D 0; } =20 @@ -1212,17 +1268,17 @@ InitPutBits () STATIC VOID CountLen ( - IN INT32 i + IN INT32 i ) { - STATIC INT32 Depth =3D 0; + STATIC INT32 Depth =3D 0; =20 if (i < mN) { mLenCnt[(Depth < 16) ? Depth : 16]++; } else { Depth++; - CountLen(mLeft [i]); - CountLen(mRight[i]); + CountLen (mLeft[i]); + CountLen (mRight[i]); Depth--; } } @@ -1235,16 +1291,17 @@ CountLen ( STATIC VOID MakeLen ( - IN INT32 Root + IN INT32 Root ) { - INT32 i, k; - UINT32 Cum; + INT32 i, k; + UINT32 Cum; =20 for (i =3D 0; i <=3D 16; i++) { mLenCnt[i] =3D 0; } - CountLen(Root); + + CountLen (Root); =20 // // Adjust the length count array so that @@ -1255,6 +1312,7 @@ MakeLen ( for (i =3D 16; i > 0; i--) { Cum +=3D mLenCnt[i] << (16 - i); } + while (Cum !=3D (1U << 16)) { mLenCnt[16]--; for (i =3D 15; i > 0; i--) { @@ -1264,8 +1322,10 @@ MakeLen ( break; } } + Cum--; } + for (i =3D 16; i > 0; i--) { k =3D mLenCnt[i]; while (--k >=3D 0) { @@ -1277,10 +1337,10 @@ MakeLen ( STATIC VOID DownHeap ( - IN INT32 i + IN INT32 i ) { - INT32 j, k; + INT32 j, k; =20 // // priority queue: send i-th entry down heap @@ -1288,15 +1348,18 @@ DownHeap ( =20 k =3D mHeap[i]; while ((j =3D 2 * i) <=3D mHeapSize) { - if (j < mHeapSize && mFreq[mHeap[j]] > mFreq[mHeap[j + 1]]) { + if ((j < mHeapSize) && (mFreq[mHeap[j]] > mFreq[mHeap[j + 1]])) { j++; } + if (mFreq[k] <=3D mFreq[mHeap[j]]) { break; } + mHeap[i] =3D mHeap[j]; - i =3D j; + i =3D j; } + mHeap[i] =3D (INT16)k; } =20 @@ -1310,18 +1373,19 @@ DownHeap ( STATIC VOID MakeCode ( - IN INT32 n, - IN UINT8 Len[], - OUT UINT16 Code[] + IN INT32 n, + IN UINT8 Len[], + OUT UINT16 Code[] ) { - INT32 i; - UINT16 Start[18]; + INT32 i; + UINT16 Start[18]; =20 Start[1] =3D 0; for (i =3D 1; i <=3D 16; i++) { Start[i + 1] =3D (UINT16)((Start[i] + mLenCnt[i]) << 1); } + for (i =3D 0; i < n; i++) { Code[i] =3D Start[Len[i]]++; } @@ -1346,62 +1410,65 @@ MakeTree ( OUT UINT16 CodeParm[] ) { - INT32 i, j, k, Avail; + INT32 i, j, k, Avail; =20 // // make tree, calculate len[], return root // =20 - mN =3D NParm; - mFreq =3D FreqParm; - mLen =3D LenParm; - Avail =3D mN; + mN =3D NParm; + mFreq =3D FreqParm; + mLen =3D LenParm; + Avail =3D mN; mHeapSize =3D 0; - mHeap[1] =3D 0; + mHeap[1] =3D 0; for (i =3D 0; i < mN; i++) { mLen[i] =3D 0; if (mFreq[i]) { mHeap[++mHeapSize] =3D (INT16)i; } } + if (mHeapSize < 2) { CodeParm[mHeap[1]] =3D 0; return mHeap[1]; } + for (i =3D mHeapSize / 2; i >=3D 1; i--) { - // // make priority queue // - DownHeap(i); + DownHeap (i); } + mSortPtr =3D CodeParm; do { i =3D mHeap[1]; if (i < mN) { *mSortPtr++ =3D (UINT16)i; } + mHeap[1] =3D mHeap[mHeapSize--]; - DownHeap(1); + DownHeap (1); j =3D mHeap[1]; if (j < mN) { *mSortPtr++ =3D (UINT16)j; } - k =3D Avail++; + + k =3D Avail++; mFreq[k] =3D (UINT16)(mFreq[i] + mFreq[j]); mHeap[1] =3D (INT16)k; - DownHeap(1); - mLeft[k] =3D (UINT16)i; + DownHeap (1); + mLeft[k] =3D (UINT16)i; mRight[k] =3D (UINT16)j; } while (mHeapSize > 1); =20 mSortPtr =3D CodeParm; - MakeLen(k); - MakeCode(NParm, LenParm, CodeParm); + MakeLen (k); + MakeCode (NParm, LenParm, CodeParm); =20 // // return root // return k; } - diff --git a/BaseTools/Source/C/Common/EfiUtilityMsgs.c b/BaseTools/Source/= C/Common/EfiUtilityMsgs.c index 89524550884a..fa4c5ded0dce 100644 --- a/BaseTools/Source/C/Common/EfiUtilityMsgs.c +++ b/BaseTools/Source/C/Common/EfiUtilityMsgs.c @@ -18,17 +18,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Declare module globals for keeping track of the utility's // name and other settings. // -STATIC STATUS mStatus =3D STATUS_SUCCESS; -STATIC CHAR8 mUtilityName[50] =3D { 0 }; -STATIC UINT64 mPrintLogLevel =3D INFO_LOG_LEVEL; -STATIC CHAR8 *mSourceFileName =3D NULL; -STATIC UINT32 mSourceFileLineNum =3D 0; -STATIC UINT32 mErrorCount =3D 0; -STATIC UINT32 mWarningCount =3D 0; -STATIC UINT32 mMaxErrors =3D 0; -STATIC UINT32 mMaxWarnings =3D 0; -STATIC UINT32 mMaxWarningsPlusErrors =3D 0; -STATIC INT8 mPrintLimitsSet =3D 0; +STATIC STATUS mStatus =3D STATUS_SUCCESS; +STATIC CHAR8 mUtilityName[50] =3D { 0 }; +STATIC UINT64 mPrintLogLevel =3D INFO_LOG_LEVEL; +STATIC CHAR8 *mSourceFileName =3D NULL; +STATIC UINT32 mSourceFileLineNum =3D 0; +STATIC UINT32 mErrorCount =3D 0; +STATIC UINT32 mWarningCount =3D 0; +STATIC UINT32 mMaxErrors =3D 0; +STATIC UINT32 mMaxWarnings =3D 0; +STATIC UINT32 mMaxWarningsPlusErrors =3D 0; +STATIC INT8 mPrintLimitsSet =3D 0; =20 STATIC VOID @@ -41,7 +41,7 @@ PrintLimitExceeded ( =20 All arguments are optional, though the printed message may be useless if at least something valid is not specified. -=20 + @note: We print the following (similar to the Warn() and Debug() W @@ -90,7 +90,8 @@ Error ( ... ) { - va_list List; + va_list List; + // // If limits have been set, then check that we have not exceeded them // @@ -101,16 +102,17 @@ Error ( if (mMaxWarningsPlusErrors !=3D 0) { if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) { PrintLimitExceeded (); - return ; + return; } } + // // See if we've exceeded our error count // if (mMaxErrors !=3D 0) { if (mErrorCount > mMaxErrors) { PrintLimitExceeded (); - return ; + return; } } } @@ -137,7 +139,8 @@ ParserError ( ... ) { - va_list List; + va_list List; + // // If limits have been set, then check them // @@ -148,16 +151,17 @@ ParserError ( if (mMaxWarningsPlusErrors !=3D 0) { if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) { PrintLimitExceeded (); - return ; + return; } } + // // See if we've exceeded our error count // if (mMaxErrors !=3D 0) { if (mErrorCount > mMaxErrors) { PrintLimitExceeded (); - return ; + return; } } } @@ -184,7 +188,8 @@ ParserWarning ( ... ) { - va_list List; + va_list List; + // // If limits have been set, then check them // @@ -195,16 +200,17 @@ ParserWarning ( if (mMaxWarningsPlusErrors !=3D 0) { if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) { PrintLimitExceeded (); - return ; + return; } } + // // See if we've exceeded our warning count // if (mMaxWarnings !=3D 0) { if (mWarningCount > mMaxWarnings) { PrintLimitExceeded (); - return ; + return; } } } @@ -244,7 +250,7 @@ Warning ( ... ) { - va_list List; + va_list List; =20 // // Current Print Level not output warning information. @@ -252,6 +258,7 @@ Warning ( if (WARNING_LOG_LEVEL < mPrintLogLevel) { return; } + // // If limits have been set, then check them // @@ -262,16 +269,17 @@ Warning ( if (mMaxWarningsPlusErrors !=3D 0) { if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) { PrintLimitExceeded (); - return ; + return; } } + // // See if we've exceeded our warning count // if (mMaxWarnings !=3D 0) { if (mWarningCount > mMaxWarnings) { PrintLimitExceeded (); - return ; + return; } } } @@ -284,7 +292,7 @@ Warning ( =20 /** Print a Debug message. -=20 + @param FileName typically the name of the utility printing the debug = message, but can be the name of a file being parsed. @param LineNumber the line number in FileName (parsers) @@ -304,12 +312,13 @@ DebugMsg ( ... ) { - va_list List; + va_list List; + // // If the debug level is less than current print level, then do nothing. // if (MsgLevel < mPrintLogLevel) { - return ; + return; } =20 va_start (List, MsgFmt); @@ -321,7 +330,7 @@ DebugMsg ( Worker routine for all the utility printing services. Prints the message= in a format that Visual Studio will find when scanning build outputs for errors or warnings. -=20 + @note: If FileName =3D=3D NULL then this utility will use the string passed in= to SetUtilityName(). =20 @@ -355,25 +364,25 @@ DebugMsg ( **/ VOID PrintMessage ( - CHAR8 *Type, - CHAR8 *FileName, - UINT32 LineNumber, - UINT32 MessageCode, - CHAR8 *Text, - CHAR8 *MsgFmt, - va_list List + CHAR8 *Type, + CHAR8 *FileName, + UINT32 LineNumber, + UINT32 MessageCode, + CHAR8 *Text, + CHAR8 *MsgFmt, + va_list List ) { - CHAR8 Line[MAX_LINE_LEN]; - CHAR8 Line2[MAX_LINE_LEN]; - CHAR8 *Cptr; - struct tm *NewTime; - time_t CurrentTime; + CHAR8 Line[MAX_LINE_LEN]; + CHAR8 Line2[MAX_LINE_LEN]; + CHAR8 *Cptr; + struct tm *NewTime; + time_t CurrentTime; =20 // // init local variable // - Line[0] =3D '\0'; + Line[0] =3D '\0'; Line2[0] =3D '\0'; =20 // @@ -393,20 +402,23 @@ PrintMessage ( time (&CurrentTime); NewTime =3D localtime (&CurrentTime); if (NewTime !=3D NULL) { - fprintf (stdout, "%04d-%02d-%02d %02d:%02d:%02d", - NewTime->tm_year + 1900, - NewTime->tm_mon + 1, - NewTime->tm_mday, - NewTime->tm_hour, - NewTime->tm_min, - NewTime->tm_sec - ); + fprintf ( + stdout, + "%04d-%02d-%02d %02d:%02d:%02d", + NewTime->tm_year + 1900, + NewTime->tm_mon + 1, + NewTime->tm_mday, + NewTime->tm_hour, + NewTime->tm_min, + NewTime->tm_sec + ); } + if (Cptr !=3D NULL) { strcpy (Line, ": "); strncat (Line, Cptr, MAX_LINE_LEN - strlen (Line) - 1); if (LineNumber !=3D 0) { - sprintf (Line2, "(%u)", (unsigned) LineNumber); + sprintf (Line2, "(%u)", (unsigned)LineNumber); strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } } @@ -418,10 +430,11 @@ PrintMessage ( if (mUtilityName[0] !=3D '\0') { fprintf (stdout, "%s...\n", mUtilityName); } + strncpy (Line, Cptr, MAX_LINE_LEN - 1); Line[MAX_LINE_LEN - 1] =3D 0; if (LineNumber !=3D 0) { - sprintf (Line2, "(%u)", (unsigned) LineNumber); + sprintf (Line2, "(%u)", (unsigned)LineNumber); strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } } else { @@ -448,9 +461,10 @@ PrintMessage ( strncat (Line, ": ", MAX_LINE_LEN - strlen (Line) - 1); strncat (Line, Type, MAX_LINE_LEN - strlen (Line) - 1); if (MessageCode !=3D 0) { - sprintf (Line2, " %04u", (unsigned) MessageCode); + sprintf (Line2, " %04u", (unsigned)MessageCode); strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } + fprintf (stdout, "%s", Line); // // If offending text was provided, then print it @@ -458,6 +472,7 @@ PrintMessage ( if (Text !=3D NULL) { fprintf (stdout, ": %s", Text); } + fprintf (stdout, "\n"); =20 // @@ -467,7 +482,6 @@ PrintMessage ( vsprintf (Line2, MsgFmt, List); fprintf (stdout, " %s\n", Line2); } - } =20 /** @@ -480,11 +494,12 @@ PrintMessage ( STATIC VOID PrintSimpleMessage ( - CHAR8 *MsgFmt, - va_list List + CHAR8 *MsgFmt, + va_list List ) { - CHAR8 Line[MAX_LINE_LEN]; + CHAR8 Line[MAX_LINE_LEN]; + // // Print formatted message if provided // @@ -507,8 +522,8 @@ ParserSetPosition ( UINT32 LineNum ) { - mSourceFileName =3D SourceFileName; - mSourceFileLineNum =3D LineNum; + mSourceFileName =3D SourceFileName; + mSourceFileLineNum =3D LineNum; } =20 /** @@ -523,7 +538,7 @@ ParserSetPosition ( **/ VOID SetUtilityName ( - CHAR8 *UtilityName + CHAR8 *UtilityName ) { // @@ -534,6 +549,7 @@ SetUtilityName ( if (strlen (UtilityName) >=3D sizeof (mUtilityName)) { Error (UtilityName, 0, 0, "application error", "utility name length = exceeds internal buffer size"); } + strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1); mUtilityName[sizeof (mUtilityName) - 1] =3D 0; } else { @@ -580,16 +596,17 @@ SetPrintLevel ( **/ VOID VerboseMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ) { - va_list List; + va_list List; + // // If the debug level is less than current print level, then do nothing. // if (VERBOSE_LOG_LEVEL < mPrintLogLevel) { - return ; + return; } =20 va_start (List, MsgFmt); @@ -606,16 +623,17 @@ VerboseMsg ( **/ VOID NormalMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ) { - va_list List; + va_list List; + // // If the debug level is less than current print level, then do nothing. // if (INFO_LOG_LEVEL < mPrintLogLevel) { - return ; + return; } =20 va_start (List, MsgFmt); @@ -632,16 +650,17 @@ NormalMsg ( **/ VOID KeyMsg ( - CHAR8 *MsgFmt, + CHAR8 *MsgFmt, ... ) { - va_list List; + va_list List; + // // If the debug level is less than current print level, then do nothing. // if (KEY_LOG_LEVEL < mPrintLogLevel) { - return ; + return; } =20 va_start (List, MsgFmt); @@ -665,10 +684,10 @@ SetPrintLimits ( UINT32 MaxWarningsPlusErrors ) { - mMaxErrors =3D MaxErrors; - mMaxWarnings =3D MaxWarnings; - mMaxWarningsPlusErrors =3D MaxWarningsPlusErrors; - mPrintLimitsSet =3D 1; + mMaxErrors =3D MaxErrors; + mMaxWarnings =3D MaxWarnings; + mMaxWarningsPlusErrors =3D MaxWarningsPlusErrors; + mPrintLimitsSet =3D 1; } =20 STATIC @@ -677,7 +696,8 @@ PrintLimitExceeded ( VOID ) { - STATIC INT8 mPrintLimitExceeded =3D 0; + STATIC INT8 mPrintLimitExceeded =3D 0; + // // If we've already printed the message, do nothing. Otherwise // temporarily increase our print limits so we can pass one @@ -701,10 +721,10 @@ TestUtilityMessages ( VOID ) { - CHAR8 *ArgStr =3D "ArgString"; - int ArgInt; + CHAR8 *ArgStr =3D "ArgString"; + int ArgInt; =20 - ArgInt =3D 0x12345678; + ArgInt =3D 0x12345678; // // Test without setting utility name // @@ -785,4 +805,5 @@ TestUtilityMessages ( ParserSetPosition (__FILE__, __LINE__ + 1); ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt); } + #endif diff --git a/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c b/BaseTools/S= ource/C/Common/FirmwareVolumeBuffer.c index 3fae6f901da0..9a94461e4e57 100644 --- a/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c +++ b/BaseTools/Source/C/Common/FirmwareVolumeBuffer.c @@ -19,40 +19,44 @@ SPDX-License-Identifier: BSD-2-Clause-Patent ) \ ) =20 - // // Local prototypes // =20 STATIC UINT32 -FvBufGetSecHdrLen( - IN EFI_COMMON_SECTION_HEADER *SectionHeader - ) +FvBufGetSecHdrLen ( + IN EFI_COMMON_SECTION_HEADER *SectionHeader + ) { if (SectionHeader =3D=3D NULL) { return 0; } - if (FvBufExpand3ByteSize(SectionHeader->Size) =3D=3D 0xffffff) { - return sizeof(EFI_COMMON_SECTION_HEADER2); + + if (FvBufExpand3ByteSize (SectionHeader->Size) =3D=3D 0xffffff) { + return sizeof (EFI_COMMON_SECTION_HEADER2); } - return sizeof(EFI_COMMON_SECTION_HEADER); + + return sizeof (EFI_COMMON_SECTION_HEADER); } =20 STATIC UINT32 FvBufGetSecFileLen ( - IN EFI_COMMON_SECTION_HEADER *SectionHeader + IN EFI_COMMON_SECTION_HEADER *SectionHeader ) { - UINT32 Length; + UINT32 Length; + if (SectionHeader =3D=3D NULL) { return 0; } - Length =3D FvBufExpand3ByteSize(SectionHeader->Size); + + Length =3D FvBufExpand3ByteSize (SectionHeader->Size); if (Length =3D=3D 0xffffff) { Length =3D ((EFI_COMMON_SECTION_HEADER2 *)SectionHeader)->ExtendedSize; } + return Length; } =20 @@ -63,15 +67,15 @@ FvBufGetSecFileLen ( STATIC UINT16 FvBufCalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ); =20 STATIC UINT8 FvBufCalculateChecksum8 ( - IN UINT8 *Buffer, - IN UINTN Size + IN UINT8 *Buffer, + IN UINTN Size ); =20 // @@ -90,19 +94,19 @@ FvBufCalculateChecksum8 ( **/ EFI_STATUS FvBufRemoveFileNew ( - IN OUT VOID *Fv, - IN EFI_GUID *Name + IN OUT VOID *Fv, + IN EFI_GUID *Name ) { - EFI_STATUS Status; - EFI_FFS_FILE_HEADER* FileToRm; - UINTN FileToRmLength; + EFI_STATUS Status; + EFI_FFS_FILE_HEADER *FileToRm; + UINTN FileToRmLength; =20 - Status =3D FvBufFindFileByName( - Fv, - Name, - (VOID **)&FileToRm - ); + Status =3D FvBufFindFileByName ( + Fv, + Name, + (VOID **)&FileToRm + ); if (EFI_ERROR (Status)) { return Status; } @@ -112,7 +116,7 @@ FvBufRemoveFileNew ( CommonLibBinderSetMem ( FileToRm, FileToRmLength, - (((EFI_FIRMWARE_VOLUME_HEADER*)Fv)->Attributes & EFI_FVB2_ERASE_POLARI= TY) + (((EFI_FIRMWARE_VOLUME_HEADER *)Fv)->Attributes & EFI_FVB2_ERASE_POLAR= ITY) ? 0xFF : 0 ); =20 @@ -131,21 +135,21 @@ FvBufRemoveFileNew ( **/ EFI_STATUS FvBufRemoveFile ( - IN OUT VOID *Fv, - IN EFI_GUID *Name + IN OUT VOID *Fv, + IN EFI_GUID *Name ) { EFI_STATUS Status; - EFI_FFS_FILE_HEADER *NextFile; - EFI_FIRMWARE_VOLUME_HEADER *TempFv; + EFI_FFS_FILE_HEADER *NextFile; + EFI_FIRMWARE_VOLUME_HEADER *TempFv; UINTN FileKey; UINTN FvLength; =20 - Status =3D FvBufFindFileByName( - Fv, - Name, - NULL - ); + Status =3D FvBufFindFileByName ( + Fv, + Name, + NULL + ); if (EFI_ERROR (Status)) { return Status; } @@ -172,7 +176,6 @@ FvBufRemoveFile ( =20 FileKey =3D 0; while (TRUE) { - Status =3D FvBufFindNextFile (Fv, &FileKey, (VOID **)&NextFile); if (Status =3D=3D EFI_NOT_FOUND) { break; @@ -183,8 +186,7 @@ FvBufRemoveFile ( =20 if (CommonLibBinderCompareGuid (Name, &NextFile->Name)) { continue; - } - else { + } else { Status =3D FvBufAddFile (TempFv, NextFile); if (EFI_ERROR (Status)) { CommonLibBinderFree (TempFv); @@ -209,12 +211,12 @@ FvBufRemoveFile ( **/ EFI_STATUS FvBufChecksumFile ( - IN OUT VOID *FfsFile + IN OUT VOID *FfsFile ) { - EFI_FFS_FILE_HEADER* File =3D (EFI_FFS_FILE_HEADER*)FfsFile; - EFI_FFS_FILE_STATE StateBackup; - UINT32 FileSize; + EFI_FFS_FILE_HEADER *File =3D (EFI_FFS_FILE_HEADER *)FfsFile; + EFI_FFS_FILE_STATE StateBackup; + UINT32 FileSize; =20 FileSize =3D FvBufGetFfsFileSize (File); =20 @@ -222,21 +224,21 @@ FvBufChecksumFile ( // Fill in checksums and state, they must be 0 for checksumming. // File->IntegrityCheck.Checksum.Header =3D 0; - File->IntegrityCheck.Checksum.File =3D 0; - StateBackup =3D File->State; - File->State =3D 0; + File->IntegrityCheck.Checksum.File =3D 0; + StateBackup =3D File->State; + File->State =3D 0; =20 File->IntegrityCheck.Checksum.Header =3D FvBufCalculateChecksum8 ( - (UINT8 *) File, + (UINT8 *)File, FvBufGetFfsHeaderSize (File) ); =20 if (File->Attributes & FFS_ATTRIB_CHECKSUM) { File->IntegrityCheck.Checksum.File =3D FvBufCalculateChecksum8 ( - (VOID*)((UINT8 *)File + Fv= BufGetFfsHeaderSize (File)), - FileSize - FvBufGetFfsHead= erSize (File) - ); + (VOID *)((UINT8 *)File + FvBufG= etFfsHeaderSize (File)), + FileSize - FvBufGetFfsHeaderSiz= e (File) + ); } else { File->IntegrityCheck.Checksum.File =3D FFS_FIXED_CHECKSUM; } @@ -258,15 +260,15 @@ FvBufChecksumFile ( **/ EFI_STATUS FvBufChecksumHeader ( - IN OUT VOID *Fv + IN OUT VOID *Fv ) { - EFI_FIRMWARE_VOLUME_HEADER* FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)= Fv; =20 FvHeader->Checksum =3D 0; FvHeader->Checksum =3D FvBufCalculateChecksum16 ( - (UINT16*) FvHeader, + (UINT16 *)FvHeader, FvHeader->HeaderLength / sizeof (UINT16) ); =20 @@ -286,12 +288,12 @@ FvBufChecksumHeader ( **/ EFI_STATUS FvBufDuplicate ( - IN VOID *SourceFv, - IN OUT VOID **DestinationFv + IN VOID *SourceFv, + IN OUT VOID **DestinationFv ) { - EFI_STATUS Status; - UINTN size; + EFI_STATUS Status; + UINTN size; =20 if (DestinationFv =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -331,18 +333,18 @@ FvBufDuplicate ( **/ EFI_STATUS FvBufExtend ( - IN VOID **Fv, - IN UINTN Size + IN VOID **Fv, + IN UINTN Size ) { - EFI_STATUS Status; - UINTN OldSize; - UINTN NewSize; - UINTN BlockCount; - VOID* NewFv; + EFI_STATUS Status; + UINTN OldSize; + UINTN NewSize; + UINTN BlockCount; + VOID *NewFv; =20 - EFI_FIRMWARE_VOLUME_HEADER* hdr; - EFI_FV_BLOCK_MAP_ENTRY* blk; + EFI_FIRMWARE_VOLUME_HEADER *hdr; + EFI_FV_BLOCK_MAP_ENTRY *blk; =20 Status =3D FvBufGetSize (*Fv, &OldSize); if (EFI_ERROR (Status)) { @@ -352,7 +354,7 @@ FvBufExtend ( // // Locate the block map in the fv header // - hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)*Fv; + hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)*Fv; blk =3D hdr->BlockMap; =20 // @@ -384,9 +386,9 @@ FvBufExtend ( // // Locate the block map in the new fv header // - hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)NewFv; + hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)NewFv; hdr->FvLength =3D NewSize; - blk =3D hdr->BlockMap; + blk =3D hdr->BlockMap; =20 // // Update the block map for the new fv @@ -402,7 +404,7 @@ FvBufExtend ( // Clear out the new area of the FV // CommonLibBinderSetMem ( - (UINT8*)NewFv + OldSize, + (UINT8 *)NewFv + OldSize, (NewSize - OldSize), (hdr->Attributes & EFI_FVB2_ERASE_POLARITY) ? 0xFF : 0 ); @@ -413,7 +415,6 @@ FvBufExtend ( *Fv =3D NewFv; =20 return EFI_SUCCESS; - } =20 /** @@ -425,20 +426,20 @@ FvBufExtend ( **/ EFI_STATUS FvBufClearAllFiles ( - IN OUT VOID *Fv + IN OUT VOID *Fv ) { - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; - EFI_STATUS Status; - UINTN size =3D 0; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; + EFI_STATUS Status; + UINTN size =3D 0; =20 Status =3D FvBufGetSize (Fv, &size); if (EFI_ERROR (Status)) { return Status; } =20 - CommonLibBinderSetMem( - (UINT8*)hdr + hdr->HeaderLength, + CommonLibBinderSetMem ( + (UINT8 *)hdr + hdr->HeaderLength, size - hdr->HeaderLength, (hdr->Attributes & EFI_FVB2_ERASE_POLARITY) ? 0xFF : 0 ); @@ -455,12 +456,12 @@ FvBufClearAllFiles ( **/ EFI_STATUS FvBufGetSize ( - IN VOID *Fv, - OUT UINTN *Size + IN VOID *Fv, + OUT UINTN *Size ) { - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; - EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; + EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; =20 *Size =3D 0; =20 @@ -470,6 +471,7 @@ FvBufGetSize ( // If size is greater than 1GB, then assume it is corrupted return EFI_VOLUME_CORRUPTED; } + blk++; } =20 @@ -491,21 +493,21 @@ FvBufGetSize ( **/ EFI_STATUS FvBufAddFile ( - IN OUT VOID *Fv, - IN VOID *File + IN OUT VOID *Fv, + IN VOID *File ) { - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; =20 - EFI_FFS_FILE_HEADER *fhdr =3D NULL; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - UINTN offset; - UINTN fsize; - UINTN newSize; - UINTN clearLoop; + EFI_FFS_FILE_HEADER *fhdr =3D NULL; + EFI_FVB_ATTRIBUTES_2 FvbAttributes; + UINTN offset; + UINTN fsize; + UINTN newSize; + UINTN clearLoop; =20 - EFI_STATUS Status; - UINTN fvSize; + EFI_STATUS Status; + UINTN fvSize; =20 Status =3D FvBufGetSize (Fv, &fvSize); if (EFI_ERROR (Status)) { @@ -513,27 +515,28 @@ FvBufAddFile ( } =20 FvbAttributes =3D hdr->Attributes; - newSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)File); + newSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER *)File); =20 - for( - offset =3D (UINTN)ALIGN_POINTER (hdr->HeaderLength, 8); - offset + newSize <=3D fvSize; - offset =3D (UINTN)ALIGN_POINTER (offset, 8) - ) { + for ( + offset =3D (UINTN)ALIGN_POINTER (hdr->HeaderLength, 8); + offset + newSize <=3D fvSize; + offset =3D (UINTN)ALIGN_POINTER (offset, 8) + ) + { + fhdr =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)hdr + offset); =20 - fhdr =3D (EFI_FFS_FILE_HEADER*) ((UINT8*)hdr + offset); - - if (EFI_TEST_FFS_ATTRIBUTES_BIT( + if (EFI_TEST_FFS_ATTRIBUTES_BIT ( FvbAttributes, fhdr->State, EFI_FILE_HEADER_VALID + ) ) - ) { + { // BUGBUG: Need to make sure that the new file does not already // exist. =20 fsize =3D FvBufGetFfsFileSize (fhdr); - if (fsize =3D=3D 0 || (offset + fsize > fvSize)) { + if ((fsize =3D=3D 0) || (offset + fsize > fvSize)) { return EFI_VOLUME_CORRUPTED; } =20 @@ -543,10 +546,11 @@ FvBufAddFile ( =20 clearLoop =3D 0; while ((clearLoop < newSize) && - (((UINT8*)fhdr)[clearLoop] =3D=3D - (UINT8)((hdr->Attributes & EFI_FVB2_ERASE_POLARITY) ? 0xFF : = 0) + (((UINT8 *)fhdr)[clearLoop] =3D=3D + (UINT8)((hdr->Attributes & EFI_FVB2_ERASE_POLARITY) ? 0xFF : 0) ) - ) { + ) + { clearLoop++; } =20 @@ -584,14 +588,14 @@ FvBufAddFile ( **/ EFI_STATUS FvBufAddFileWithExtend ( - IN OUT VOID **Fv, - IN VOID *File + IN OUT VOID **Fv, + IN VOID *File ) { - EFI_STATUS Status; - EFI_FFS_FILE_HEADER* NewFile; + EFI_STATUS Status; + EFI_FFS_FILE_HEADER *NewFile; =20 - NewFile =3D (EFI_FFS_FILE_HEADER*)File; + NewFile =3D (EFI_FFS_FILE_HEADER *)File; =20 // // Try to add to the capsule volume @@ -626,25 +630,25 @@ FvBufAddFileWithExtend ( **/ EFI_STATUS FvBufAddVtfFile ( - IN OUT VOID *Fv, - IN VOID *File + IN OUT VOID *Fv, + IN VOID *File ) { - EFI_STATUS Status; + EFI_STATUS Status; =20 - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; =20 - EFI_FFS_FILE_HEADER* NewFile; + EFI_FFS_FILE_HEADER *NewFile; UINTN NewFileSize; =20 - UINT8 erasedUint8; - UINTN clearLoop; + UINT8 erasedUint8; + UINTN clearLoop; =20 - EFI_FFS_FILE_HEADER *LastFile; - UINTN LastFileSize; + EFI_FFS_FILE_HEADER *LastFile; + UINTN LastFileSize; =20 - UINTN fvSize; - UINTN Key; + UINTN fvSize; + UINTN Key; =20 Status =3D FvBufGetSize (Fv, &fvSize); if (EFI_ERROR (Status)) { @@ -652,7 +656,7 @@ FvBufAddVtfFile ( } =20 erasedUint8 =3D (UINT8)((hdr->Attributes & EFI_FVB2_ERASE_POLARITY) ? 0x= FF : 0); - NewFileSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)File); + NewFileSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER *)File); =20 if (NewFileSize !=3D (UINTN)ALIGN_POINTER (NewFileSize, 8)) { return EFI_INVALID_PARAMETER; @@ -661,31 +665,31 @@ FvBufAddVtfFile ( // // Find the last file in the FV // - Key =3D 0; - LastFile =3D NULL; + Key =3D 0; + LastFile =3D NULL; LastFileSize =3D 0; do { - Status =3D FvBufFindNextFile (Fv, &Key, (VOID **)&LastFile); - LastFileSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)File); + Status =3D FvBufFindNextFile (Fv, &Key, (VOID **)&LastFile); + LastFileSize =3D FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER *)File); } while (!EFI_ERROR (Status)); =20 // // If no files were found, then we start at the beginning of the FV // if (LastFile =3D=3D NULL) { - LastFile =3D (EFI_FFS_FILE_HEADER*)((UINT8*)hdr + hdr->HeaderLength); + LastFile =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)hdr + hdr->HeaderLength); } =20 // // We want to put the new file (VTF) at the end of the FV // - NewFile =3D (EFI_FFS_FILE_HEADER*)((UINT8*)hdr + (fvSize - NewFileSize)); + NewFile =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)hdr + (fvSize - NewFileSize= )); =20 // // Check to see if there is enough room for the VTF after the last file // found in the FV // - if ((UINT8*)NewFile < ((UINT8*)LastFile + LastFileSize)) { + if ((UINT8 *)NewFile < ((UINT8 *)LastFile + LastFileSize)) { return EFI_OUT_OF_RESOURCES; } =20 @@ -694,8 +698,9 @@ FvBufAddVtfFile ( // clearLoop =3D 0; while ((clearLoop < NewFileSize) && - (((UINT8*)NewFile)[clearLoop] =3D=3D erasedUint8) - ) { + (((UINT8 *)NewFile)[clearLoop] =3D=3D erasedUint8) + ) + { clearLoop++; } =20 @@ -720,13 +725,13 @@ FvBufAddVtfFile ( **/ VOID FvBufCompact3ByteSize ( - OUT VOID* SizeDest, - IN UINT32 Size + OUT VOID *SizeDest, + IN UINT32 Size ) { - ((UINT8*)SizeDest)[0] =3D (UINT8)Size; - ((UINT8*)SizeDest)[1] =3D (UINT8)(Size >> 8); - ((UINT8*)SizeDest)[2] =3D (UINT8)(Size >> 16); + ((UINT8 *)SizeDest)[0] =3D (UINT8)Size; + ((UINT8 *)SizeDest)[1] =3D (UINT8)(Size >> 8); + ((UINT8 *)SizeDest)[2] =3D (UINT8)(Size >> 16); } =20 /** @@ -738,16 +743,18 @@ FvBufCompact3ByteSize ( **/ UINT32 FvBufGetFfsFileSize ( - IN EFI_FFS_FILE_HEADER *Ffs + IN EFI_FFS_FILE_HEADER *Ffs ) { if (Ffs =3D=3D NULL) { return 0; } + if (Ffs->Attributes & FFS_ATTRIB_LARGE_FILE) { - return (UINT32) ((EFI_FFS_FILE_HEADER2 *)Ffs)->ExtendedSize; + return (UINT32)((EFI_FFS_FILE_HEADER2 *)Ffs)->ExtendedSize; } - return FvBufExpand3ByteSize(Ffs->Size); + + return FvBufExpand3ByteSize (Ffs->Size); } =20 /** @@ -759,16 +766,18 @@ FvBufGetFfsFileSize ( **/ UINT32 FvBufGetFfsHeaderSize ( - IN EFI_FFS_FILE_HEADER *Ffs + IN EFI_FFS_FILE_HEADER *Ffs ) { if (Ffs =3D=3D NULL) { return 0; } + if (Ffs->Attributes & FFS_ATTRIB_LARGE_FILE) { - return sizeof(EFI_FFS_FILE_HEADER2); + return sizeof (EFI_FFS_FILE_HEADER2); } - return sizeof(EFI_FFS_FILE_HEADER); + + return sizeof (EFI_FFS_FILE_HEADER); } =20 /** @@ -780,12 +789,12 @@ FvBufGetFfsHeaderSize ( **/ UINT32 FvBufExpand3ByteSize ( - IN VOID* Size + IN VOID *Size ) { - return (((UINT8*)Size)[2] << 16) + - (((UINT8*)Size)[1] << 8) + - ((UINT8*)Size)[0]; + return (((UINT8 *)Size)[2] << 16) + + (((UINT8 *)Size)[1] << 8) + + ((UINT8 *)Size)[0]; } =20 /** @@ -805,19 +814,19 @@ FvBufExpand3ByteSize ( **/ EFI_STATUS FvBufFindNextFile ( - IN VOID *Fv, - IN OUT UINTN *Key, - OUT VOID **File + IN VOID *Fv, + IN OUT UINTN *Key, + OUT VOID **File ) { - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; =20 - EFI_FFS_FILE_HEADER *fhdr =3D NULL; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - UINTN fsize; + EFI_FFS_FILE_HEADER *fhdr =3D NULL; + EFI_FVB_ATTRIBUTES_2 FvbAttributes; + UINTN fsize; =20 - EFI_STATUS Status; - UINTN fvSize; + EFI_STATUS Status; + UINTN fvSize; =20 if (Fv =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -834,50 +843,53 @@ FvBufFindNextFile ( =20 FvbAttributes =3D hdr->Attributes; =20 - for( - *Key =3D (UINTN)ALIGN_POINTER (*Key, 8); - (*Key + sizeof (*fhdr)) < fvSize; - *Key =3D (UINTN)ALIGN_POINTER (*Key, 8) - ) { - - fhdr =3D (EFI_FFS_FILE_HEADER*) ((UINT8*)hdr + *Key); + for ( + *Key =3D (UINTN)ALIGN_POINTER (*Key, 8); + (*Key + sizeof (*fhdr)) < fvSize; + *Key =3D (UINTN)ALIGN_POINTER (*Key, 8) + ) + { + fhdr =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)hdr + *Key); fsize =3D FvBufGetFfsFileSize (fhdr); =20 - if (!EFI_TEST_FFS_ATTRIBUTES_BIT( - FvbAttributes, - fhdr->State, - EFI_FILE_HEADER_VALID - ) || - EFI_TEST_FFS_ATTRIBUTES_BIT( + if (!EFI_TEST_FFS_ATTRIBUTES_BIT ( + FvbAttributes, + fhdr->State, + EFI_FILE_HEADER_VALID + ) || + EFI_TEST_FFS_ATTRIBUTES_BIT ( FvbAttributes, fhdr->State, EFI_FILE_HEADER_INVALID + ) ) - ) { + { *Key =3D *Key + 1; // Make some forward progress continue; - } else if( - EFI_TEST_FFS_ATTRIBUTES_BIT( - FvbAttributes, - fhdr->State, - EFI_FILE_MARKED_FOR_UPDATE - ) || - EFI_TEST_FFS_ATTRIBUTES_BIT( - FvbAttributes, - fhdr->State, - EFI_FILE_DELETED - ) - ) { + } else if ( + EFI_TEST_FFS_ATTRIBUTES_BIT ( + FvbAttributes, + fhdr->State, + EFI_FILE_MARKED_FOR_UPDATE + ) || + EFI_TEST_FFS_ATTRIBUTES_BIT ( + FvbAttributes, + fhdr->State, + EFI_FILE_DELETED + ) + ) + { *Key =3D *Key + fsize; continue; - } else if (EFI_TEST_FFS_ATTRIBUTES_BIT( - FvbAttributes, - fhdr->State, - EFI_FILE_DATA_VALID - ) - ) { - *File =3D (UINT8*)hdr + *Key; - *Key =3D *Key + fsize; + } else if (EFI_TEST_FFS_ATTRIBUTES_BIT ( + FvbAttributes, + fhdr->State, + EFI_FILE_DATA_VALID + ) + ) + { + *File =3D (UINT8 *)hdr + *Key; + *Key =3D *Key + fsize; return EFI_SUCCESS; } =20 @@ -903,14 +915,14 @@ FvBufFindNextFile ( **/ EFI_STATUS FvBufFindFileByName ( - IN VOID *Fv, - IN EFI_GUID *Name, - OUT VOID **File + IN VOID *Fv, + IN EFI_GUID *Name, + OUT VOID **File ) { - EFI_STATUS Status; - UINTN Key; - EFI_FFS_FILE_HEADER *NextFile; + EFI_STATUS Status; + UINTN Key; + EFI_FFS_FILE_HEADER *NextFile; =20 Key =3D 0; while (TRUE) { @@ -923,6 +935,7 @@ FvBufFindFileByName ( if (File !=3D NULL) { *File =3D NextFile; } + return EFI_SUCCESS; } } @@ -946,14 +959,14 @@ FvBufFindFileByName ( **/ EFI_STATUS FvBufFindFileByType ( - IN VOID *Fv, - IN EFI_FV_FILETYPE Type, - OUT VOID **File + IN VOID *Fv, + IN EFI_FV_FILETYPE Type, + OUT VOID **File ) { - EFI_STATUS Status; - UINTN Key; - EFI_FFS_FILE_HEADER *NextFile; + EFI_STATUS Status; + UINTN Key; + EFI_FFS_FILE_HEADER *NextFile; =20 Key =3D 0; while (TRUE) { @@ -966,6 +979,7 @@ FvBufFindFileByType ( if (File !=3D NULL) { *File =3D NextFile; } + return EFI_SUCCESS; } } @@ -988,16 +1002,16 @@ FvBufFindFileByType ( **/ EFI_STATUS FvBufGetFileRawData ( - IN VOID* FfsFile, - OUT VOID** RawData, - OUT UINTN* RawDataSize + IN VOID *FfsFile, + OUT VOID **RawData, + OUT UINTN *RawDataSize ) { - EFI_STATUS Status; - EFI_FFS_FILE_HEADER* File; - EFI_RAW_SECTION* Section; + EFI_STATUS Status; + EFI_FFS_FILE_HEADER *File; + EFI_RAW_SECTION *Section; =20 - File =3D (EFI_FFS_FILE_HEADER*)FfsFile; + File =3D (EFI_FFS_FILE_HEADER *)FfsFile; =20 // // Is the file type =3D=3D EFI_FV_FILETYPE_RAW? @@ -1006,7 +1020,7 @@ FvBufGetFileRawData ( // // Raw filetypes don't have sections, so we just return the raw data // - *RawData =3D (VOID*)((UINT8 *)File + FvBufGetFfsHeaderSize (File)); + *RawData =3D (VOID *)((UINT8 *)File + FvBufGetFfsHeaderSize (File)= ); *RawDataSize =3D FvBufGetFfsFileSize (File) - FvBufGetFfsHeaderSize (F= ile); return EFI_SUCCESS; } @@ -1019,12 +1033,11 @@ FvBufGetFileRawData ( return Status; } =20 - *RawData =3D (VOID*)((UINT8 *)Section + FvBufGetSecHdrLen(Section)); + *RawData =3D (VOID *)((UINT8 *)Section + FvBufGetSecHdrLen (Section)= ); *RawDataSize =3D - FvBufGetSecFileLen (Section) - FvBufGetSecHdrLen(Section); + FvBufGetSecFileLen (Section) - FvBufGetSecHdrLen (Section); =20 return EFI_SUCCESS; - } =20 /** @@ -1042,37 +1055,37 @@ FvBufGetFileRawData ( **/ EFI_STATUS FvBufPackageFreeformRawFile ( - IN EFI_GUID* Filename, - IN VOID* RawData, - IN UINTN RawDataSize, - OUT VOID** FfsFile + IN EFI_GUID *Filename, + IN VOID *RawData, + IN UINTN RawDataSize, + OUT VOID **FfsFile ) { - EFI_FFS_FILE_HEADER* NewFile; - UINT32 NewFileSize; - EFI_RAW_SECTION* NewSection; - UINT32 NewSectionSize; - UINT32 FfsHdrLen; - UINT32 SecHdrLen; + EFI_FFS_FILE_HEADER *NewFile; + UINT32 NewFileSize; + EFI_RAW_SECTION *NewSection; + UINT32 NewSectionSize; + UINT32 FfsHdrLen; + UINT32 SecHdrLen; =20 // // The section size is the DataSize + the size of the section header // NewSectionSize =3D (UINT32)sizeof (EFI_RAW_SECTION) + (UINT32)RawDataSiz= e; - SecHdrLen =3D sizeof (EFI_RAW_SECTION); + SecHdrLen =3D sizeof (EFI_RAW_SECTION); if (NewSectionSize >=3D MAX_SECTION_SIZE) { NewSectionSize =3D (UINT32)sizeof (EFI_RAW_SECTION2) + (UINT32)RawData= Size; - SecHdrLen =3D sizeof (EFI_RAW_SECTION2); + SecHdrLen =3D sizeof (EFI_RAW_SECTION2); } =20 // // The file size is the size of the file header + the section size // NewFileSize =3D sizeof (EFI_FFS_FILE_HEADER) + NewSectionSize; - FfsHdrLen =3D sizeof (EFI_FFS_FILE_HEADER); + FfsHdrLen =3D sizeof (EFI_FFS_FILE_HEADER); if (NewFileSize >=3D MAX_FFS_SIZE) { NewFileSize =3D sizeof (EFI_FFS_FILE_HEADER2) + NewSectionSize; - FfsHdrLen =3D sizeof (EFI_FFS_FILE_HEADER2); + FfsHdrLen =3D sizeof (EFI_FFS_FILE_HEADER2); } =20 // @@ -1082,18 +1095,20 @@ FvBufPackageFreeformRawFile ( if (NewFile =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } + CommonLibBinderSetMem (NewFile, NewFileSize, 0); =20 // // The NewSection follow right after the FFS file header // - NewSection =3D (EFI_RAW_SECTION*)((UINT8*)NewFile + FfsHdrLen); + NewSection =3D (EFI_RAW_SECTION *)((UINT8 *)NewFile + FfsHdrLen); if (NewSectionSize >=3D MAX_SECTION_SIZE) { FvBufCompact3ByteSize (NewSection->Size, 0xffffff); ((EFI_RAW_SECTION2 *)NewSection)->ExtendedSize =3D NewSectionSize; } else { FvBufCompact3ByteSize (NewSection->Size, NewSectionSize); } + NewSection->Type =3D EFI_SECTION_RAW; =20 // @@ -1109,18 +1124,19 @@ FvBufPackageFreeformRawFile ( if (NewFileSize >=3D MAX_FFS_SIZE) { FvBufCompact3ByteSize (NewFile->Size, 0x0); ((EFI_FFS_FILE_HEADER2 *)NewFile)->ExtendedSize =3D NewFileSize; - NewFile->Attributes |=3D FFS_ATTRIB_LARGE_FILE; + NewFile->Attributes |=3D FFS_ATTRIB_LARGE_F= ILE; } else { FvBufCompact3ByteSize (NewFile->Size, NewFileSize); } - NewFile->Type =3D EFI_FV_FILETYPE_FREEFORM; + + NewFile->Type =3D EFI_FV_FILETYPE_FREEFORM; NewFile->IntegrityCheck.Checksum.Header =3D - FvBufCalculateChecksum8 ((UINT8*)NewFile, FfsHdrLen); + FvBufCalculateChecksum8 ((UINT8 *)NewFile, FfsHdrLen); NewFile->IntegrityCheck.Checksum.File =3D FFS_FIXED_CHECKSUM; - NewFile->State =3D (UINT8)~( EFI_FILE_HEADER_CONSTRUCTION | - EFI_FILE_HEADER_VALID | - EFI_FILE_DATA_VALID - ); + NewFile->State =3D (UINT8) ~(EFI_FILE_HEADER_CONS= TRUCTION | + EFI_FILE_HEADER_VALID | + EFI_FILE_DATA_VALID + ); =20 *FfsFile =3D NewFile; =20 @@ -1145,14 +1161,14 @@ FvBufPackageFreeformRawFile ( **/ EFI_STATUS FvBufFindNextSection ( - IN VOID *SectionsStart, - IN UINTN TotalSectionsSize, - IN OUT UINTN *Key, - OUT VOID **Section + IN VOID *SectionsStart, + IN UINTN TotalSectionsSize, + IN OUT UINTN *Key, + OUT VOID **Section ) { - EFI_COMMON_SECTION_HEADER *sectionHdr; - UINTN sectionSize; + EFI_COMMON_SECTION_HEADER *sectionHdr; + UINTN sectionSize; =20 *Key =3D (UINTN)ALIGN_POINTER (*Key, 4); // Sections are DWORD aligned =20 @@ -1160,7 +1176,7 @@ FvBufFindNextSection ( return EFI_NOT_FOUND; } =20 - sectionHdr =3D (EFI_COMMON_SECTION_HEADER*)((UINT8*)SectionsStart + *Key= ); + sectionHdr =3D (EFI_COMMON_SECTION_HEADER *)((UINT8 *)SectionsStart + *= Key); sectionSize =3D FvBufGetSecFileLen (sectionHdr); =20 if (sectionSize < sizeof (EFI_COMMON_SECTION_HEADER)) { @@ -1171,10 +1187,9 @@ FvBufFindNextSection ( return EFI_NOT_FOUND; } =20 - *Section =3D (UINT8*)sectionHdr; - *Key =3D *Key + sectionSize; + *Section =3D (UINT8 *)sectionHdr; + *Key =3D *Key + sectionSize; return EFI_SUCCESS; - } =20 /** @@ -1190,21 +1205,21 @@ FvBufFindNextSection ( **/ EFI_STATUS FvBufCountSections ( - IN VOID* FfsFile, - IN UINTN* Count + IN VOID *FfsFile, + IN UINTN *Count ) { EFI_STATUS Status; UINTN Key; - VOID* SectionStart; + VOID *SectionStart; UINTN TotalSectionsSize; - EFI_COMMON_SECTION_HEADER* NextSection; + EFI_COMMON_SECTION_HEADER *NextSection; =20 - SectionStart =3D (VOID*)((UINTN)FfsFile + FvBufGetFfsHeaderSize(FfsFile)= ); + SectionStart =3D (VOID *)((UINTN)FfsFile + FvBufGetFfsHeaderSize (F= fsFile)); TotalSectionsSize =3D - FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)FfsFile) - - FvBufGetFfsHeaderSize(FfsFile); - Key =3D 0; + FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER *)FfsFile) - + FvBufGetFfsHeaderSize (FfsFile); + Key =3D 0; *Count =3D 0; while (TRUE) { Status =3D FvBufFindNextSection ( @@ -1223,7 +1238,6 @@ FvBufCountSections ( // Increment the section counter // *Count +=3D 1; - } =20 return EFI_NOT_FOUND; @@ -1245,21 +1259,21 @@ FvBufCountSections ( **/ EFI_STATUS FvBufFindSectionByType ( - IN VOID *FfsFile, - IN UINT8 Type, - OUT VOID **Section + IN VOID *FfsFile, + IN UINT8 Type, + OUT VOID **Section ) { - EFI_STATUS Status; - UINTN Key; - VOID* SectionStart; + EFI_STATUS Status; + UINTN Key; + VOID *SectionStart; UINTN TotalSectionsSize; - EFI_COMMON_SECTION_HEADER* NextSection; + EFI_COMMON_SECTION_HEADER *NextSection; =20 - SectionStart =3D (VOID*)((UINTN)FfsFile + FvBufGetFfsHeaderSize(FfsFile)= ); + SectionStart =3D (VOID *)((UINTN)FfsFile + FvBufGetFfsHeaderSize (F= fsFile)); TotalSectionsSize =3D - FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)FfsFile) - - FvBufGetFfsHeaderSize(FfsFile); + FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER *)FfsFile) - + FvBufGetFfsHeaderSize (FfsFile); Key =3D 0; while (TRUE) { Status =3D FvBufFindNextSection ( @@ -1276,6 +1290,7 @@ FvBufFindSectionByType ( if (Section !=3D NULL) { *Section =3D NextSection; } + return EFI_SUCCESS; } } @@ -1291,23 +1306,23 @@ FvBufFindSectionByType ( end of the extended FV. =20 @param Fv Firmware volume. - =20 + @retval EFI_SUCCESS **/ EFI_STATUS FvBufShrinkWrap ( - IN VOID *Fv + IN VOID *Fv ) { - EFI_STATUS Status; - UINTN OldSize; - UINT32 BlockCount; - UINT32 NewBlockSize =3D 128; - UINTN Key; - EFI_FFS_FILE_HEADER* FileIt; - VOID* EndOfLastFile; + EFI_STATUS Status; + UINTN OldSize; + UINT32 BlockCount; + UINT32 NewBlockSize =3D 128; + UINTN Key; + EFI_FFS_FILE_HEADER *FileIt; + VOID *EndOfLastFile; =20 - EFI_FIRMWARE_VOLUME_HEADER* FvHdr; + EFI_FIRMWARE_VOLUME_HEADER *FvHdr; =20 Status =3D FvBufGetSize (Fv, &OldSize); if (EFI_ERROR (Status)) { @@ -1322,16 +1337,16 @@ FvBufShrinkWrap ( // // Locate the block map in the fv header // - FvHdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; + FvHdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; =20 // // Find the end of the last file // - Key =3D 0; - EndOfLastFile =3D (UINT8*)FvHdr + FvHdr->FvLength; + Key =3D 0; + EndOfLastFile =3D (UINT8 *)FvHdr + FvHdr->FvLength; while (!EFI_ERROR (FvBufFindNextFile (Fv, &Key, (VOID **)&FileIt))) { EndOfLastFile =3D - (VOID*)((UINT8*)FileIt + FvBufGetFfsFileSize (FileIt)); + (VOID *)((UINT8 *)FileIt + FvBufGetFfsFileSize (FileIt)); } =20 // @@ -1345,7 +1360,7 @@ FvBufShrinkWrap ( // Adjust the block count to shrink the Fv in place. // FvHdr->BlockMap[0].NumBlocks =3D BlockCount; - FvHdr->FvLength =3D BlockCount * NewBlockSize; + FvHdr->FvLength =3D BlockCount * NewBlockSize; =20 // // Update the FV header checksum @@ -1353,7 +1368,6 @@ FvBufShrinkWrap ( FvBufChecksumHeader (Fv); =20 return EFI_SUCCESS; - } =20 /** @@ -1370,13 +1384,13 @@ FvBufShrinkWrap ( **/ EFI_STATUS FvBufUnifyBlockSizes ( - IN OUT VOID *Fv, - IN UINTN BlockSize + IN OUT VOID *Fv, + IN UINTN BlockSize ) { - EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER*)Fv; - EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; - UINT32 Size; + EFI_FIRMWARE_VOLUME_HEADER *hdr =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; + EFI_FV_BLOCK_MAP_ENTRY *blk =3D hdr->BlockMap; + UINT32 Size; =20 Size =3D 0; =20 @@ -1384,12 +1398,13 @@ FvBufUnifyBlockSizes ( // Scan through the block map list, performing error checking, and adding // up the total Fv size. // - while( blk->Length !=3D 0 || - blk->NumBlocks !=3D 0 - ) { + while ( blk->Length !=3D 0 || + blk->NumBlocks !=3D 0 + ) + { Size =3D Size + (blk->Length * blk->NumBlocks); blk++; - if ((UINT8*)blk > ((UINT8*)hdr + hdr->HeaderLength)) { + if ((UINT8 *)blk > ((UINT8 *)hdr + hdr->HeaderLength)) { return EFI_VOLUME_CORRUPTED; } } @@ -1413,7 +1428,7 @@ FvBufUnifyBlockSizes ( // // Write out the single block map entry. // - hdr->BlockMap[0].Length =3D (UINT32)BlockSize; + hdr->BlockMap[0].Length =3D (UINT32)BlockSize; hdr->BlockMap[0].NumBlocks =3D Size / (UINT32)BlockSize; =20 return EFI_SUCCESS; @@ -1430,8 +1445,8 @@ FvBufUnifyBlockSizes ( STATIC UINT16 FvBufCalculateSum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) { UINTN Index; @@ -1443,10 +1458,10 @@ FvBufCalculateSum16 ( // Perform the word sum for buffer // for (Index =3D 0; Index < Size; Index++) { - Sum =3D (UINT16) (Sum + Buffer[Index]); + Sum =3D (UINT16)(Sum + Buffer[Index]); } =20 - return (UINT16) Sum; + return (UINT16)Sum; } =20 /** @@ -1460,8 +1475,8 @@ FvBufCalculateSum16 ( STATIC UINT16 FvBufCalculateChecksum16 ( - IN UINT16 *Buffer, - IN UINTN Size + IN UINT16 *Buffer, + IN UINTN Size ) { return (UINT16)(0x10000 - FvBufCalculateSum16 (Buffer, Size)); @@ -1472,7 +1487,7 @@ FvBufCalculateChecksum16 ( =20 @param Buffer Pointer to buffer containing byte data of component. @param Size Size of the buffer -=20 + @return The 8 bit checksum value needed. **/ STATIC @@ -1482,8 +1497,8 @@ FvBufCalculateSum8 ( IN UINTN Size ) { - UINTN Index; - UINT8 Sum; + UINTN Index; + UINT8 Sum; =20 Sum =3D 0; =20 @@ -1491,7 +1506,7 @@ FvBufCalculateSum8 ( // Perform the byte sum for buffer // for (Index =3D 0; Index < Size; Index++) { - Sum =3D (UINT8) (Sum + Buffer[Index]); + Sum =3D (UINT8)(Sum + Buffer[Index]); } =20 return Sum; @@ -1508,11 +1523,9 @@ FvBufCalculateSum8 ( STATIC UINT8 FvBufCalculateChecksum8 ( - IN UINT8 *Buffer, - IN UINTN Size + IN UINT8 *Buffer, + IN UINTN Size ) { return (UINT8)(0x100 - FvBufCalculateSum8 (Buffer, Size)); } - - diff --git a/BaseTools/Source/C/Common/FvLib.c b/BaseTools/Source/C/Common/= FvLib.c index 37631f470f2a..f617ebdfde6d 100644 --- a/BaseTools/Source/C/Common/FvLib.c +++ b/BaseTools/Source/C/Common/FvLib.c @@ -16,8 +16,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Module global variables // -EFI_FIRMWARE_VOLUME_HEADER *mFvHeader =3D NULL; -UINT32 mFvLength =3D 0; +EFI_FIRMWARE_VOLUME_HEADER *mFvHeader =3D NULL; +UINT32 mFvLength =3D 0; =20 // // External function implementations @@ -35,8 +35,8 @@ UINT32 mFvLength =3D 0; **/ EFI_STATUS InitializeFvLib ( - IN VOID *Fv, - IN UINT32 FvLength + IN VOID *Fv, + IN UINT32 FvLength ) { // @@ -46,7 +46,7 @@ InitializeFvLib ( return EFI_INVALID_PARAMETER; } =20 - mFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) Fv; + mFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fv; mFvLength =3D FvLength; =20 return EFI_SUCCESS; @@ -71,9 +71,10 @@ GetFvHeader ( // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify input arguments // @@ -100,8 +101,8 @@ GetFvHeader ( **/ EFI_STATUS GetNextFile ( - IN EFI_FFS_FILE_HEADER *CurrentFile, - OUT EFI_FFS_FILE_HEADER **NextFile + IN EFI_FFS_FILE_HEADER *CurrentFile, + OUT EFI_FFS_FILE_HEADER **NextFile ) { EFI_STATUS Status; @@ -109,15 +110,17 @@ GetNextFile ( // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify input arguments // if (NextFile =3D=3D NULL) { return EFI_INVALID_PARAMETER; } + // // Verify FV header // @@ -125,11 +128,12 @@ GetNextFile ( if (EFI_ERROR (Status)) { return EFI_ABORTED; } + // // Get first file // if (CurrentFile =3D=3D NULL) { - CurrentFile =3D (EFI_FFS_FILE_HEADER *) ((UINTN) mFvHeader + mFvHeader= ->HeaderLength); + CurrentFile =3D (EFI_FFS_FILE_HEADER *)((UINTN)mFvHeader + mFvHeader->= HeaderLength); =20 // // Verify file is valid @@ -145,7 +149,7 @@ GetNextFile ( // // Verify file is in this FV. // - if ((UINTN) CurrentFile + GetFfsFileLength(CurrentFile) > (UINTN) mF= vHeader + mFvLength) { + if ((UINTN)CurrentFile + GetFfsFileLength (CurrentFile) > (UINTN)mFv= Header + mFvLength) { *NextFile =3D NULL; return EFI_SUCCESS; } @@ -154,28 +158,33 @@ GetNextFile ( return EFI_SUCCESS; } } + // // Verify current file is in range // - if (((UINTN) CurrentFile < (UINTN) mFvHeader + mFvHeader->HeaderLength) = || - ((UINTN) CurrentFile + GetFfsFileLength(CurrentFile) > (UINTN) mFvHe= ader + mFvLength) - ) { + if (((UINTN)CurrentFile < (UINTN)mFvHeader + mFvHeader->HeaderLength) || + ((UINTN)CurrentFile + GetFfsFileLength (CurrentFile) > (UINTN)mFvHea= der + mFvLength) + ) + { return EFI_INVALID_PARAMETER; } + // // Get next file, compensate for 8 byte alignment if necessary. // - *NextFile =3D (EFI_FFS_FILE_HEADER *) ((((UINTN) CurrentFile - (UINTN) m= FvHeader + GetFfsFileLength(CurrentFile) + 0x07) & (~(UINTN) 7)) + (UINT8 *= ) mFvHeader); + *NextFile =3D (EFI_FFS_FILE_HEADER *)((((UINTN)CurrentFile - (UINTN)mFvH= eader + GetFfsFileLength (CurrentFile) + 0x07) & (~(UINTN)7)) + (UINT8 *)mF= vHeader); =20 // // Verify file is in this FV. // - if (((UINTN) *NextFile + GetFfsHeaderLength(*NextFile) >=3D (UINTN) mFvH= eader + mFvLength) || - ((UINTN) *NextFile + GetFfsFileLength (*NextFile) > (UINTN) mFvHeade= r + mFvLength) - ) { + if (((UINTN)*NextFile + GetFfsHeaderLength (*NextFile) >=3D (UINTN)mFvHe= ader + mFvLength) || + ((UINTN)*NextFile + GetFfsFileLength (*NextFile) > (UINTN)mFvHeader = + mFvLength) + ) + { *NextFile =3D NULL; return EFI_SUCCESS; } + // // Verify file is valid // @@ -203,26 +212,28 @@ GetNextFile ( **/ EFI_STATUS GetFileByName ( - IN EFI_GUID *FileName, - OUT EFI_FFS_FILE_HEADER **File + IN EFI_GUID *FileName, + OUT EFI_FFS_FILE_HEADER **File ) { - EFI_FFS_FILE_HEADER *CurrentFile; - EFI_STATUS Status; - CHAR8 FileGuidString[80]; + EFI_FFS_FILE_HEADER *CurrentFile; + EFI_STATUS Status; + CHAR8 FileGuidString[80]; =20 // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify input parameters // - if (FileName =3D=3D NULL || File =3D=3D NULL) { + if ((FileName =3D=3D NULL) || (File =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } + // // File Guid String Name // @@ -234,6 +245,7 @@ GetFileByName ( if (EFI_ERROR (Status)) { return EFI_ABORTED; } + // // Get the first file // @@ -242,6 +254,7 @@ GetFileByName ( Error (NULL, 0, 0003, "error parsing FV image", "FFS file with Guid %s= can't be found", FileGuidString); return EFI_ABORTED; } + // // Loop as long as we have a valid file // @@ -257,6 +270,7 @@ GetFileByName ( return EFI_ABORTED; } } + // // File not found in this FV. // @@ -279,27 +293,29 @@ GetFileByName ( **/ EFI_STATUS GetFileByType ( - IN EFI_FV_FILETYPE FileType, - IN UINTN Instance, - OUT EFI_FFS_FILE_HEADER **File + IN EFI_FV_FILETYPE FileType, + IN UINTN Instance, + OUT EFI_FFS_FILE_HEADER **File ) { - EFI_FFS_FILE_HEADER *CurrentFile; - EFI_STATUS Status; - UINTN FileCount; + EFI_FFS_FILE_HEADER *CurrentFile; + EFI_STATUS Status; + UINTN FileCount; =20 // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify input parameters // if (File =3D=3D NULL) { return EFI_INVALID_PARAMETER; } + // // Verify FV header // @@ -307,6 +323,7 @@ GetFileByType ( if (EFI_ERROR (Status)) { return EFI_ABORTED; } + // // Initialize the number of matching files found. // @@ -320,11 +337,12 @@ GetFileByType ( Error (NULL, 0, 0003, "error parsing FV image", "FFS file with FileTyp= e 0x%x can't be found", FileType); return EFI_ABORTED; } + // // Loop as long as we have a valid file // while (CurrentFile) { - if (FileType =3D=3D EFI_FV_FILETYPE_ALL || CurrentFile->Type =3D=3D Fi= leType) { + if ((FileType =3D=3D EFI_FV_FILETYPE_ALL) || (CurrentFile->Type =3D=3D= FileType)) { FileCount++; } =20 @@ -363,12 +381,12 @@ GetFileByType ( **/ EFI_STATUS SearchSectionByType ( - IN EFI_FILE_SECTION_POINTER FirstSection, - IN UINT8 *SearchEnd, - IN EFI_SECTION_TYPE SectionType, - IN OUT UINTN *StartIndex, - IN UINTN Instance, - OUT EFI_FILE_SECTION_POINTER *Section + IN EFI_FILE_SECTION_POINTER FirstSection, + IN UINT8 *SearchEnd, + IN EFI_SECTION_TYPE SectionType, + IN OUT UINTN *StartIndex, + IN UINTN Instance, + OUT EFI_FILE_SECTION_POINTER *Section ) { EFI_FILE_SECTION_POINTER CurrentSection; @@ -378,11 +396,11 @@ SearchSectionByType ( UINT16 GuidSecAttr; UINT16 GuidDataOffset; =20 - GuidSecAttr =3D 0; + GuidSecAttr =3D 0; GuidDataOffset =3D 0; CurrentSection =3D FirstSection; =20 - while ((UINTN) CurrentSection.CommonHeader < (UINTN) SearchEnd) { + while ((UINTN)CurrentSection.CommonHeader < (UINTN)SearchEnd) { if (CurrentSection.CommonHeader->Type =3D=3D SectionType) { (*StartIndex)++; } @@ -391,6 +409,7 @@ SearchSectionByType ( *Section =3D CurrentSection; return EFI_SUCCESS; } + // // If the requesting section is not GUID-defined and // we find a GUID-defined section that doesn't need @@ -398,36 +417,39 @@ SearchSectionByType ( // section inside the GUID-defined section. // if (CurrentSection.CommonHeader->Type =3D=3D EFI_SECTION_GUID_DEFINED)= { - if (GetLength(CurrentSection.CommonHeader->Size) =3D=3D 0xffffff) { - GuidSecAttr =3D CurrentSection.GuidDefinedSection2->Attributes; + if (GetLength (CurrentSection.CommonHeader->Size) =3D=3D 0xffffff) { + GuidSecAttr =3D CurrentSection.GuidDefinedSection2->Attributes; GuidDataOffset =3D CurrentSection.GuidDefinedSection2->DataOffset; } else { - GuidSecAttr =3D CurrentSection.GuidDefinedSection->Attributes; + GuidSecAttr =3D CurrentSection.GuidDefinedSection->Attributes; GuidDataOffset =3D CurrentSection.GuidDefinedSection->DataOffset; } } - if (SectionType !=3D EFI_SECTION_GUID_DEFINED && - CurrentSection.CommonHeader->Type =3D=3D EFI_SECTION_GUID_DEFINED = && - !(GuidSecAttr & EFI_GUIDED_SECTION_PROCESSING_REQUIRED)) { + + if ((SectionType !=3D EFI_SECTION_GUID_DEFINED) && + (CurrentSection.CommonHeader->Type =3D=3D EFI_SECTION_GUID_DEFINED= ) && + !(GuidSecAttr & EFI_GUIDED_SECTION_PROCESSING_REQUIRED)) + { InnerSection.CommonHeader =3D (EFI_COMMON_SECTION_HEADER *) - ((UINTN) CurrentSection.CommonHeader + GuidDataOffset); - SectionSize =3D GetSectionFileLength(CurrentSection.CommonHeader); - Status =3D SearchSectionByType ( - InnerSection, - (UINT8 *) ((UINTN) CurrentSection.CommonHeader + SectionS= ize), - SectionType, - StartIndex, - Instance, - Section - ); + ((UINTN)CurrentSection.CommonHeader + Gu= idDataOffset); + SectionSize =3D GetSectionFileLength (CurrentSection.CommonHeader); + Status =3D SearchSectionByType ( + InnerSection, + (UINT8 *)((UINTN)CurrentSection.CommonHeader + Secti= onSize), + SectionType, + StartIndex, + Instance, + Section + ); if (!EFI_ERROR (Status)) { return EFI_SUCCESS; } } + // // Find next section (including compensating for alignment issues. // - CurrentSection.CommonHeader =3D (EFI_COMMON_SECTION_HEADER *) ((((UINT= N) CurrentSection.CommonHeader) + GetSectionFileLength(CurrentSection.Commo= nHeader) + 0x03) & (~(UINTN) 3)); + CurrentSection.CommonHeader =3D (EFI_COMMON_SECTION_HEADER *)((((UINTN= )CurrentSection.CommonHeader) + GetSectionFileLength (CurrentSection.Common= Header) + 0x03) & (~(UINTN)3)); } =20 return EFI_NOT_FOUND; @@ -451,10 +473,10 @@ SearchSectionByType ( **/ EFI_STATUS GetSectionByType ( - IN EFI_FFS_FILE_HEADER *File, - IN EFI_SECTION_TYPE SectionType, - IN UINTN Instance, - OUT EFI_FILE_SECTION_POINTER *Section + IN EFI_FFS_FILE_HEADER *File, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_FILE_SECTION_POINTER *Section ) { EFI_FILE_SECTION_POINTER CurrentSection; @@ -464,9 +486,10 @@ GetSectionByType ( // // Verify input parameters // - if (File =3D=3D NULL || Instance =3D=3D 0) { + if ((File =3D=3D NULL) || (Instance =3D=3D 0)) { return EFI_INVALID_PARAMETER; } + // // Verify FFS header // @@ -475,6 +498,7 @@ GetSectionByType ( Error (NULL, 0, 0006, "invalid FFS file", NULL); return EFI_ABORTED; } + // // Initialize the number of matching sections found. // @@ -483,14 +507,14 @@ GetSectionByType ( // // Get the first section // - CurrentSection.CommonHeader =3D (EFI_COMMON_SECTION_HEADER *) ((UINTN) F= ile + GetFfsHeaderLength(File)); + CurrentSection.CommonHeader =3D (EFI_COMMON_SECTION_HEADER *)((UINTN)Fil= e + GetFfsHeaderLength (File)); =20 // // Depth-first manner to find section file. // Status =3D SearchSectionByType ( CurrentSection, - (UINT8 *) ((UINTN) File + GetFfsFileLength (File)), + (UINT8 *)((UINTN)File + GetFfsFileLength (File)), SectionType, &SectionCount, Instance, @@ -524,7 +548,7 @@ GetSectionByType ( **/ EFI_STATUS VerifyFv ( - IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader ) { UINT16 Checksum; @@ -540,10 +564,11 @@ VerifyFv ( Error (NULL, 0, 0006, "invalid FV header signature", NULL); return EFI_VOLUME_CORRUPTED; } + // // Verify header checksum // - Checksum =3D CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength= / sizeof (UINT16)); + Checksum =3D CalculateSum16 ((UINT16 *)FvHeader, FvHeader->HeaderLength = / sizeof (UINT16)); =20 if (Checksum !=3D 0) { Error (NULL, 0, 0006, "invalid FV header checksum", NULL); @@ -568,22 +593,23 @@ VerifyFfsFile ( IN EFI_FFS_FILE_HEADER *FfsHeader ) { - BOOLEAN ErasePolarity; - EFI_STATUS Status; - EFI_FFS_FILE_HEADER2 BlankHeader; - UINT8 Checksum; - UINT32 FileLength; - UINT8 SavedChecksum; - UINT8 SavedState; - UINT8 FileGuidString[80]; - UINT32 FfsHeaderSize; + BOOLEAN ErasePolarity; + EFI_STATUS Status; + EFI_FFS_FILE_HEADER2 BlankHeader; + UINT8 Checksum; + UINT32 FileLength; + UINT8 SavedChecksum; + UINT8 SavedState; + UINT8 FileGuidString[80]; + UINT32 FfsHeaderSize; =20 // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify FV header // @@ -591,6 +617,7 @@ VerifyFfsFile ( if (EFI_ERROR (Status)) { return EFI_ABORTED; } + // // Get the erase polarity. // @@ -599,7 +626,7 @@ VerifyFfsFile ( return EFI_ABORTED; } =20 - FfsHeaderSize =3D GetFfsHeaderLength(FfsHeader); + FfsHeaderSize =3D GetFfsHeaderLength (FfsHeader); // // Check if we have free space // @@ -612,6 +639,7 @@ VerifyFfsFile ( if (memcmp (&BlankHeader, FfsHeader, FfsHeaderSize) =3D=3D 0) { return EFI_NOT_FOUND; } + // // Convert the GUID to a string so we can at least report which file // if we find an error. @@ -620,17 +648,18 @@ VerifyFfsFile ( // // Verify file header checksum // - SavedState =3D FfsHeader->State; - FfsHeader->State =3D 0; - SavedChecksum =3D FfsHeader->IntegrityCheck.Checksum.File; + SavedState =3D FfsHeader->State; + FfsHeader->State =3D 0; + SavedChecksum =3D FfsHeader->IntegrityCheck.Ch= ecksum.File; FfsHeader->IntegrityCheck.Checksum.File =3D 0; - Checksum =3D CalculateSum8 ((UINT8 *) FfsHeader, FfsHeaderSize); - FfsHeader->State =3D SavedState; + Checksum =3D CalculateSum8 ((UINT8 *)FfsH= eader, FfsHeaderSize); + FfsHeader->State =3D SavedState; FfsHeader->IntegrityCheck.Checksum.File =3D SavedChecksum; if (Checksum !=3D 0) { Error (NULL, 0, 0006, "invalid FFS file header checksum", "Ffs file wi= th Guid %s", FileGuidString); return EFI_ABORTED; } + // // Verify file checksum // @@ -638,9 +667,9 @@ VerifyFfsFile ( // // Verify file data checksum // - FileLength =3D GetFfsFileLength (FfsHeader); - Checksum =3D CalculateSum8 ((UINT8 *) ((UINT8 *)FfsHeader += FfsHeaderSize), FileLength - FfsHeaderSize); - Checksum =3D Checksum + FfsHeader->IntegrityCheck.Checksum.= File; + FileLength =3D GetFfsFileLength (FfsHeader); + Checksum =3D CalculateSum8 ((UINT8 *)((UINT8 *)FfsHeader + FfsHeader= Size), FileLength - FfsHeaderSize); + Checksum =3D Checksum + FfsHeader->IntegrityCheck.Checksum.File; if (Checksum !=3D 0) { Error (NULL, 0, 0006, "invalid FFS file checksum", "Ffs file with Gu= id %s", FileGuidString); return EFI_ABORTED; @@ -660,31 +689,35 @@ VerifyFfsFile ( } =20 UINT32 -GetFfsHeaderLength( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) +GetFfsHeaderLength ( + IN EFI_FFS_FILE_HEADER *FfsHeader + ) { if (FfsHeader =3D=3D NULL) { return 0; } + if (FfsHeader->Attributes & FFS_ATTRIB_LARGE_FILE) { - return sizeof(EFI_FFS_FILE_HEADER2); + return sizeof (EFI_FFS_FILE_HEADER2); } - return sizeof(EFI_FFS_FILE_HEADER); + + return sizeof (EFI_FFS_FILE_HEADER); } =20 UINT32 -GetSectionHeaderLength( - IN EFI_COMMON_SECTION_HEADER *SectionHeader - ) +GetSectionHeaderLength ( + IN EFI_COMMON_SECTION_HEADER *SectionHeader + ) { if (SectionHeader =3D=3D NULL) { return 0; } - if (GetLength(SectionHeader->Size) =3D=3D 0xffffff) { - return sizeof(EFI_COMMON_SECTION_HEADER2); + + if (GetLength (SectionHeader->Size) =3D=3D 0xffffff) { + return sizeof (EFI_COMMON_SECTION_HEADER2); } - return sizeof(EFI_COMMON_SECTION_HEADER); + + return sizeof (EFI_COMMON_SECTION_HEADER); } =20 /** @@ -696,32 +729,36 @@ GetSectionHeaderLength( **/ UINT32 GetFfsFileLength ( - EFI_FFS_FILE_HEADER *FfsHeader + EFI_FFS_FILE_HEADER *FfsHeader ) { if (FfsHeader =3D=3D NULL) { return 0; } + if (FfsHeader->Attributes & FFS_ATTRIB_LARGE_FILE) { - return (UINT32) ((EFI_FFS_FILE_HEADER2 *)FfsHeader)->ExtendedSize; + return (UINT32)((EFI_FFS_FILE_HEADER2 *)FfsHeader)->ExtendedSize; } else { - return GetLength(FfsHeader->Size); + return GetLength (FfsHeader->Size); } } =20 UINT32 GetSectionFileLength ( - EFI_COMMON_SECTION_HEADER *SectionHeader + EFI_COMMON_SECTION_HEADER *SectionHeader ) { - UINT32 Length; + UINT32 Length; + if (SectionHeader =3D=3D NULL) { return 0; } - Length =3D GetLength(SectionHeader->Size); + + Length =3D GetLength (SectionHeader->Size); if (Length =3D=3D 0xffffff) { Length =3D ((EFI_COMMON_SECTION_HEADER2 *)SectionHeader)->ExtendedSize; } + return Length; } =20 @@ -734,7 +771,7 @@ GetSectionFileLength ( **/ UINT32 GetLength ( - UINT8 *ThreeByteLength + UINT8 *ThreeByteLength ) { UINT32 Length; @@ -743,8 +780,8 @@ GetLength ( return 0; } =20 - Length =3D *((UINT32 *) ThreeByteLength); - Length =3D Length & 0x00FFFFFF; + Length =3D *((UINT32 *)ThreeByteLength); + Length =3D Length & 0x00FFFFFF; =20 return Length; } @@ -761,7 +798,7 @@ GetLength ( **/ EFI_STATUS GetErasePolarity ( - OUT BOOLEAN *ErasePolarity + OUT BOOLEAN *ErasePolarity ) { EFI_STATUS Status; @@ -769,9 +806,10 @@ GetErasePolarity ( // // Verify library has been initialized. // - if (mFvHeader =3D=3D NULL || mFvLength =3D=3D 0) { + if ((mFvHeader =3D=3D NULL) || (mFvLength =3D=3D 0)) { return EFI_ABORTED; } + // // Verify FV header // @@ -779,6 +817,7 @@ GetErasePolarity ( if (EFI_ERROR (Status)) { return EFI_ABORTED; } + // // Verify input parameters. // @@ -810,13 +849,13 @@ GetFileState ( IN EFI_FFS_FILE_HEADER *FfsHeader ) { - UINT8 FileState; - UINT8 HighestBit; + UINT8 FileState; + UINT8 HighestBit; =20 FileState =3D FfsHeader->State; =20 if (ErasePolarity) { - FileState =3D (UINT8)~FileState; + FileState =3D (UINT8) ~FileState; } =20 HighestBit =3D 0x80; diff --git a/BaseTools/Source/C/Common/MemoryFile.c b/BaseTools/Source/C/Co= mmon/MemoryFile.c index 47481326833e..a96aa7ab8d44 100644 --- a/BaseTools/Source/C/Common/MemoryFile.c +++ b/BaseTools/Source/C/Common/MemoryFile.c @@ -13,14 +13,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "CommonLib.h" #include "MemoryFile.h" =20 - // // Local (static) function prototypes // STATIC VOID CheckMemoryFileState ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ); =20 // @@ -39,14 +38,14 @@ CheckMemoryFileState ( **/ EFI_STATUS GetMemoryFile ( - IN CHAR8 *InputFileName, - OUT EFI_HANDLE *OutputMemoryFile + IN CHAR8 *InputFileName, + OUT EFI_HANDLE *OutputMemoryFile ) { - EFI_STATUS Status; - CHAR8 *InputFileImage; - UINT32 BytesRead; - MEMORY_FILE *NewMemoryFile; + EFI_STATUS Status; + CHAR8 *InputFileImage; + UINT32 BytesRead; + MEMORY_FILE *NewMemoryFile; =20 Status =3D GetFileImage (InputFileName, &InputFileImage, &BytesRead); if (EFI_ERROR (Status)) { @@ -59,9 +58,9 @@ GetMemoryFile ( return EFI_OUT_OF_RESOURCES; } =20 - NewMemoryFile->FileImage =3D InputFileImage; - NewMemoryFile->CurrentFilePointer =3D InputFileImage; - NewMemoryFile->Eof =3D InputFileImage + BytesRead; + NewMemoryFile->FileImage =3D InputFileImage; + NewMemoryFile->CurrentFilePointer =3D InputFileImage; + NewMemoryFile->Eof =3D InputFileImage + BytesRead; =20 *OutputMemoryFile =3D (EFI_HANDLE)NewMemoryFile; =20 @@ -79,14 +78,14 @@ GetMemoryFile ( **/ EFI_STATUS FreeMemoryFile ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ) { - MEMORY_FILE *MemoryFile; + MEMORY_FILE *MemoryFile; =20 CheckMemoryFileState (InputMemoryFile); =20 - MemoryFile =3D (MEMORY_FILE*)InputMemoryFile; + MemoryFile =3D (MEMORY_FILE *)InputMemoryFile; =20 free (MemoryFile->FileImage); =20 @@ -115,21 +114,21 @@ FreeMemoryFile ( **/ CHAR8 * ReadMemoryFileLine ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ) { - CHAR8 *EndOfLine; - UINTN CharsToCopy; - MEMORY_FILE *InputFile; - UINTN BytesToEof; - CHAR8 *OutputString; + CHAR8 *EndOfLine; + UINTN CharsToCopy; + MEMORY_FILE *InputFile; + UINTN BytesToEof; + CHAR8 *OutputString; =20 // // Verify input parameters are not null // CheckMemoryFileState (InputMemoryFile); =20 - InputFile =3D (MEMORY_FILE*)InputMemoryFile; + InputFile =3D (MEMORY_FILE *)InputMemoryFile; =20 // // Check for end of file condition @@ -177,13 +176,9 @@ ReadMemoryFileLine ( // Add the null termination over the 0x0D // if (OutputString[CharsToCopy - 1] =3D=3D '\r') { - OutputString[CharsToCopy - 1] =3D '\0'; - } else { - OutputString[CharsToCopy] =3D '\0'; - } =20 // @@ -193,6 +188,7 @@ ReadMemoryFileLine ( if (InputFile->CurrentFilePointer > InputFile->Eof) { InputFile->CurrentFilePointer =3D InputFile->Eof; } + CheckMemoryFileState (InputMemoryFile); =20 // @@ -201,18 +197,17 @@ ReadMemoryFileLine ( return OutputString; } =20 - STATIC VOID CheckMemoryFileState ( - IN EFI_HANDLE InputMemoryFile + IN EFI_HANDLE InputMemoryFile ) { - MEMORY_FILE *MemoryFile; + MEMORY_FILE *MemoryFile; =20 assert (InputMemoryFile !=3D NULL); =20 - MemoryFile =3D (MEMORY_FILE*)InputMemoryFile; + MemoryFile =3D (MEMORY_FILE *)InputMemoryFile; =20 assert (MemoryFile->FileImage !=3D NULL); assert (MemoryFile->CurrentFilePointer !=3D NULL); @@ -221,5 +216,3 @@ CheckMemoryFileState ( assert (MemoryFile->CurrentFilePointer >=3D MemoryFile->FileImage); assert (MemoryFile->CurrentFilePointer <=3D MemoryFile->Eof); } - - diff --git a/BaseTools/Source/C/Common/MyAlloc.c b/BaseTools/Source/C/Commo= n/MyAlloc.c index 17ff5cfbbd3e..2677f76c55cb 100644 --- a/BaseTools/Source/C/Common/MyAlloc.c +++ b/BaseTools/Source/C/Common/MyAlloc.c @@ -12,10 +12,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Get back to original alloc/free calls. // -#undef malloc -#undef calloc -#undef realloc -#undef free + #undef malloc + #undef calloc + #undef realloc + #undef free // // Start of allocation list. // @@ -24,8 +24,8 @@ STATIC MY_ALLOC_STRUCT *MyAllocData =3D NULL; // // // -STATIC UINT32 MyAllocHeadMagik =3D MYALLOC_HEAD_MAGIK; -STATIC UINT32 MyAllocTailMagik =3D MYALLOC_TAIL_MAGIK; +STATIC UINT32 MyAllocHeadMagik =3D MYALLOC_HEAD_MAGIK; +STATIC UINT32 MyAllocTailMagik =3D MYALLOC_TAIL_MAGIK; =20 /** Check for corruptions in the allocated memory chain. If a corruption @@ -40,12 +40,12 @@ STATIC UINT32 MyAllocTailMagik =3D MYALLOC_T= AIL_MAGIK; **/ VOID MyCheck ( - BOOLEAN Final, - UINT8 File[], - UINTN Line + BOOLEAN Final, + UINT8 File[], + UINTN Line ) { - MY_ALLOC_STRUCT *Tmp; + MY_ALLOC_STRUCT *Tmp; =20 // // Check parameters. @@ -84,34 +84,38 @@ MyCheck ( =20 exit (1); } + // // Check structure contents. // for (Tmp =3D MyAllocData; Tmp !=3D NULL; Tmp =3D Tmp->Next) { - if (memcmp(Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) || - memcmp(&Tmp->Buffer[Tmp->Size + sizeof(UINT32)], &MyAllocTailMagik= , sizeof MyAllocTailMagik)) { + if (memcmp (Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) || + memcmp (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)], &MyAllocTailMag= ik, sizeof MyAllocTailMagik)) + { break; } } + // // If Tmp is not NULL, the structure is corrupt. // if (Tmp !=3D NULL) { printf ( - "\nMyCheck(Final=3D%u, File=3D%s, Line=3D%u)""\nStructure corrupted!" - "\nFile=3D%s, Line=3D%u, nSize=3D%u, Head=3D%xh, Tail=3D%xh\n", + "\nMyCheck(Final=3D%u, File=3D%s, Line=3D%u)" "\nStructure corrupted= !" + "\nFile=3D%s, Line=3D%u, nSi= ze=3D%u, Head=3D%xh, Tail=3D%xh\n", Final, File, (unsigned)Line, Tmp->File, - (unsigned) Tmp->Line, - (unsigned) Tmp->Size, - (unsigned) *(UINT32 *) (Tmp->Buffer), - (unsigned) *(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)]) + (unsigned)Tmp->Line, + (unsigned)Tmp->Size, + (unsigned)*(UINT32 *)(Tmp->Buffer), + (unsigned)*(UINT32 *)(&Tmp->Buffer[Tmp->Size + sizeof (UINT32)]) ); =20 exit (1); } + // // If Final is TRUE, display the state of the structure chain. // @@ -129,10 +133,10 @@ MyCheck ( printf ( "File=3D%s, Line=3D%u, nSize=3D%u, Head=3D%xh, Tail=3D%xh\n", Tmp->File, - (unsigned) Tmp->Line, - (unsigned) Tmp->Size, - (unsigned) *(UINT32 *) (Tmp->Buffer), - (unsigned) *(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)= ]) + (unsigned)Tmp->Line, + (unsigned)Tmp->Size, + (unsigned)*(UINT32 *)(Tmp->Buffer), + (unsigned)*(UINT32 *)(&Tmp->Buffer[Tmp->Size + sizeof (UINT32)]) ); } } @@ -154,13 +158,13 @@ MyCheck ( **/ VOID * MyAlloc ( - UINTN Size, - UINT8 File[], - UINTN Line + UINTN Size, + UINT8 File[], + UINTN Line ) { - MY_ALLOC_STRUCT *Tmp; - UINTN Len; + MY_ALLOC_STRUCT *Tmp; + UINTN Len; =20 // // Check for invalid parameters. @@ -176,7 +180,7 @@ MyAlloc ( exit (1); } =20 - if (Size =3D=3D 0 || Line =3D=3D 0) { + if ((Size =3D=3D 0) || (Line =3D=3D 0)) { printf ( "\nMyAlloc(Size=3D%u, File=3D%s, Line=3D%u)" "\nInvalid parameter(s).\n", @@ -200,6 +204,7 @@ MyAlloc ( =20 exit (1); } + // // Check the allocation list for corruption. // @@ -224,14 +229,15 @@ MyAlloc ( =20 exit (1); } + // // Fill in the new entry. // - Tmp->File =3D ((UINT8 *) Tmp) + sizeof (MY_ALLOC_STRUCT); + Tmp->File =3D ((UINT8 *)Tmp) + sizeof (MY_ALLOC_STRUCT); strcpy ((CHAR8 *)Tmp->File, (CHAR8 *)File); Tmp->Line =3D Line; Tmp->Size =3D Size; - Tmp->Buffer =3D (UINT8 *) (((UINTN) Tmp + Len + 9) &~7); + Tmp->Buffer =3D (UINT8 *)(((UINTN)Tmp + Len + 9) &~7); =20 memcpy (Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik); =20 @@ -241,8 +247,8 @@ MyAlloc ( sizeof MyAllocTailMagik ); =20 - Tmp->Next =3D MyAllocData; - Tmp->Cksum =3D (UINTN) Tmp + (UINTN) (Tmp->Next) + Tmp->Line + Tmp->Siz= e + (UINTN) (Tmp->File) + (UINTN) (Tmp->Buffer); + Tmp->Next =3D MyAllocData; + Tmp->Cksum =3D (UINTN)Tmp + (UINTN)(Tmp->Next) + Tmp->Line + Tmp->Size += (UINTN)(Tmp->File) + (UINTN)(Tmp->Buffer); =20 MyAllocData =3D Tmp; =20 @@ -263,14 +269,14 @@ MyAlloc ( **/ VOID * MyRealloc ( - VOID *Ptr, - UINTN Size, - UINT8 File[], - UINTN Line + VOID *Ptr, + UINTN Size, + UINT8 File[], + UINTN Line ) { - MY_ALLOC_STRUCT *Tmp; - VOID *Buffer; + MY_ALLOC_STRUCT *Tmp; + VOID *Buffer; =20 // // Check for invalid parameter(s). @@ -287,7 +293,7 @@ MyRealloc ( exit (1); } =20 - if (Size =3D=3D 0 || Line =3D=3D 0) { + if ((Size =3D=3D 0) || (Line =3D=3D 0)) { printf ( "\nMyRealloc(Ptr=3D%p, Size=3D%u, File=3D%s, Line=3D%u)" "\nInvalid parameter(s).\n", @@ -312,6 +318,7 @@ MyRealloc ( =20 exit (1); } + // // Find existing buffer in allocation list. // @@ -320,7 +327,7 @@ MyRealloc ( } else if (&MyAllocData->Buffer[sizeof (UINT32)] =3D=3D Ptr) { Tmp =3D MyAllocData; } else { - for (Tmp =3D MyAllocData;; Tmp =3D Tmp->Next) { + for (Tmp =3D MyAllocData; ; Tmp =3D Tmp->Next) { if (Tmp->Next =3D=3D NULL) { printf ( "\nMyRealloc(Ptr=3D%p, Size=3D%u, File=3D%s, Line=3D%u)" @@ -337,12 +344,13 @@ MyRealloc ( Tmp =3D Tmp->Next; } } + // // Allocate new buffer, copy old data, free old buffer. // Buffer =3D MyAlloc (Size, File, Line); =20 - if (Buffer !=3D NULL && Tmp !=3D NULL) { + if ((Buffer !=3D NULL) && (Tmp !=3D NULL)) { memcpy ( Buffer, &Tmp->Buffer[sizeof (UINT32)], @@ -366,13 +374,13 @@ MyRealloc ( **/ VOID MyFree ( - VOID *Ptr, - UINT8 File[], - UINTN Line + VOID *Ptr, + UINT8 File[], + UINTN Line ) { - MY_ALLOC_STRUCT *Tmp; - MY_ALLOC_STRUCT *Tmp2; + MY_ALLOC_STRUCT *Tmp; + MY_ALLOC_STRUCT *Tmp2; =20 // // Check for invalid parameter(s). @@ -411,12 +419,14 @@ MyFree ( =20 exit (1); } + // // Freeing NULL is always valid. // if (Ptr =3D=3D NULL) { - return ; + return; } + // // Fail if nothing is allocated. // @@ -431,6 +441,7 @@ MyFree ( =20 exit (1); } + // // Check for corrupted allocation list. // @@ -449,7 +460,7 @@ MyFree ( // // Walk list looking for matching item. // - for (Tmp =3D MyAllocData;; Tmp =3D Tmp->Next) { + for (Tmp =3D MyAllocData; ; Tmp =3D Tmp->Next) { // // Fail if end of list is reached. // @@ -464,6 +475,7 @@ MyFree ( =20 exit (1); } + // // Leave loop when match is found. // @@ -471,6 +483,7 @@ MyFree ( break; } } + // // Unlink item from list. // @@ -478,6 +491,7 @@ MyFree ( Tmp->Next =3D Tmp->Next->Next; Tmp =3D Tmp2; } + // // Release item. // diff --git a/BaseTools/Source/C/Common/OsPath.c b/BaseTools/Source/C/Common= /OsPath.c index 9901f686c98f..8e7614e24f5c 100644 --- a/BaseTools/Source/C/Common/OsPath.c +++ b/BaseTools/Source/C/Common/OsPath.c @@ -17,9 +17,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // =20 #if 0 - // - // BUGBUG: Not fully implemented yet. - // +// +// BUGBUG: Not fully implemented yet. +// =20 /** This function returns the directory path which contains the particular p= ath. @@ -38,17 +38,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 @return NULL if error **/ -CHAR8* +CHAR8 * OsPathDirName ( - IN CHAR8 *FilePath + IN CHAR8 *FilePath ) =20 { - CHAR8 *Return; - CHAR8 *Pos; - CHAR8 Char; - UINTN Length; - INTN Offset; + CHAR8 *Return; + CHAR8 *Pos; + CHAR8 Char; + UINTN Length; + INTN Offset; =20 Length =3D strlen (FilePath); =20 @@ -60,9 +60,10 @@ OsPathDirName ( // Check for the root directory case // if ( - (Length =3D=3D 3 && isalpha (FilePath[0]) && (strcmp(FilePath + 1, ":\= \") =3D=3D 0)) || - (strcmp(FilePath, "/") =3D=3D 0) - ) { + ((Length =3D=3D 3) && isalpha (FilePath[0]) && (strcmp (FilePath + 1= , ":\\") =3D=3D 0)) || + (strcmp (FilePath, "/") =3D=3D 0) + ) + { return NULL; } =20 @@ -70,7 +71,7 @@ OsPathDirName ( // If the path ends with a path separator, then just append ".." // Char =3D FilePath[Length - 1]; - if (Char =3D=3D '/' || Char =3D=3D '\\') { + if ((Char =3D=3D '/') || (Char =3D=3D '\\')) { return OsPathJoin (FilePath, ".."); } =20 @@ -84,13 +85,13 @@ OsPathDirName ( } } } + #endif =20 - #if 0 - // - // BUGBUG: Not fully implemented yet. - // +// +// BUGBUG: Not fully implemented yet. +// =20 /** This function returns the directory path which contains the particular p= ath. @@ -107,19 +108,19 @@ OsPathDirName ( **/ VOID OsPathNormPathInPlace ( - IN CHAR8 *Path + IN CHAR8 *Path ) { - CHAR8 *Pos; - INTN Offset; - BOOLEAN TryAgain; - UINTN Length; - UINTN Remaining; - UINTN SubLength; + CHAR8 *Pos; + INTN Offset; + BOOLEAN TryAgain; + UINTN Length; + UINTN Remaining; + UINTN SubLength; =20 do { TryAgain =3D FALSE; - Length =3D strlen (Path); + Length =3D strlen (Path); =20 for (Offset =3D 0; Offset < Length; Offset++) { Remaining =3D Length - Offset; @@ -131,7 +132,8 @@ OsPathNormPathInPlace ( (Remaining >=3D 2) && ((Offset > 0) || (Path[0] !=3D '\\')) && IsDirSep (Path[Offset]) && IsDirSep (Path[Offset + 1]) - ) { + ) + { memmove (&Path[Offset], &Path[Offset + 1], Remaining); TryAgain =3D TRUE; break; @@ -141,8 +143,9 @@ OsPathNormPathInPlace ( // Collapse '/./' -> '/' // if ((Remaining >=3D 3) && IsDirSep (Path[Offset]) && - (Path[Offset + 1] =3D=3D '.') && IsDirSep (Path[Offset + 2]) - ) { + (Path[Offset + 1] =3D=3D '.') && IsDirSep (Path[Offset + 2]) + ) + { memmove (&Path[Offset], &Path[Offset + 1], Remaining); TryAgain =3D TRUE; break; @@ -152,9 +155,7 @@ OsPathNormPathInPlace ( // Collapse 'a/../b' -> 'b' // // BUGBUG: Not implemented yet - } - } while (TryAgain); =20 Return =3D CloneString (FilePath); @@ -168,9 +169,10 @@ OsPathNormPathInPlace ( // Check for the root directory case // if ( - (Length =3D=3D 3 && isalpha (Return[0]) && (strcmp(Return + 1, ":\\") = =3D=3D 0)) || - (strcmp(Return, "/") =3D=3D 0) - ) { + ((Length =3D=3D 3) && isalpha (Return[0]) && (strcmp (Return + 1, ":= \\") =3D=3D 0)) || + (strcmp (Return, "/") =3D=3D 0) + ) + { free (Return); return NULL; } @@ -185,6 +187,7 @@ OsPathNormPathInPlace ( } } } + #endif =20 /** @@ -202,16 +205,16 @@ OsPathNormPathInPlace ( =20 @return A CHAR8* string, which must be freed by the caller **/ -CHAR8* +CHAR8 * OsPathPeerFilePath ( - IN CHAR8 *OldPath, - IN CHAR8 *Peer + IN CHAR8 *OldPath, + IN CHAR8 *Peer ) { - CHAR8 *Result; - INTN Offset; + CHAR8 *Result; + INTN Offset; =20 - Result =3D (CHAR8 *) malloc (strlen (OldPath) + strlen (Peer) + 1); + Result =3D (CHAR8 *)malloc (strlen (OldPath) + strlen (Peer) + 1); if (Result =3D=3D NULL) { return NULL; } @@ -247,10 +250,11 @@ OsPathPeerFilePath ( **/ BOOLEAN OsPathExists ( - IN CHAR8 *InputFileName + IN CHAR8 *InputFileName ) { - FILE *InputFile; + FILE *InputFile; + InputFile =3D fopen (LongFilePath (InputFileName), "rb"); if (InputFile =3D=3D NULL) { return FALSE; @@ -259,6 +263,3 @@ OsPathExists ( return TRUE; } } - - - diff --git a/BaseTools/Source/C/Common/ParseGuidedSectionTools.c b/BaseTool= s/Source/C/Common/ParseGuidedSectionTools.c index e1e9a97e7bf6..566a22fe9036 100644 --- a/BaseTools/Source/C/Common/ParseGuidedSectionTools.c +++ b/BaseTools/Source/C/Common/ParseGuidedSectionTools.c @@ -17,16 +17,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "ParseGuidedSectionTools.h" #include "StringFuncs.h" =20 - // // Local types / structures // =20 typedef struct _GUID_SEC_TOOL_ENTRY { - EFI_GUID Guid; - CHAR8* Name; - CHAR8* Path; - struct _GUID_SEC_TOOL_ENTRY *Next; + EFI_GUID Guid; + CHAR8 *Name; + CHAR8 *Path; + struct _GUID_SEC_TOOL_ENTRY *Next; } GUID_SEC_TOOL_ENTRY; =20 // @@ -47,12 +46,12 @@ typedef struct _GUID_SEC_TOOL_ENTRY { **/ EFI_HANDLE ParseGuidedSectionToolsFile ( - IN CHAR8 *InputFile + IN CHAR8 *InputFile ) { - EFI_STATUS Status; - EFI_HANDLE MemoryFile; - EFI_HANDLE ParsedGuidedSectionTools; + EFI_STATUS Status; + EFI_HANDLE MemoryFile; + EFI_HANDLE ParsedGuidedSectionTools; =20 Status =3D GetMemoryFile (InputFile, &MemoryFile); if (EFI_ERROR (Status)) { @@ -80,16 +79,16 @@ ParseGuidedSectionToolsFile ( **/ EFI_HANDLE ParseGuidedSectionToolsMemoryFile ( - IN EFI_HANDLE InputFile + IN EFI_HANDLE InputFile ) { - EFI_STATUS Status; - CHAR8 *NextLine; - STRING_LIST *Tool; - EFI_GUID Guid; - GUID_SEC_TOOL_ENTRY *FirstGuidTool; - GUID_SEC_TOOL_ENTRY *LastGuidTool; - GUID_SEC_TOOL_ENTRY *NewGuidTool; + EFI_STATUS Status; + CHAR8 *NextLine; + STRING_LIST *Tool; + EFI_GUID Guid; + GUID_SEC_TOOL_ENTRY *FirstGuidTool; + GUID_SEC_TOOL_ENTRY *LastGuidTool; + GUID_SEC_TOOL_ENTRY *NewGuidTool; =20 FirstGuidTool =3D NULL; LastGuidTool =3D NULL; @@ -114,14 +113,15 @@ ParseGuidedSectionToolsMemoryFile ( Tool =3D SplitStringByWhitespace (NextLine); if ((Tool !=3D NULL) && (Tool->Count =3D=3D 3) - ) { + ) + { Status =3D StringToGuid (Tool->Strings[0], &Guid); if (!EFI_ERROR (Status)) { NewGuidTool =3D malloc (sizeof (GUID_SEC_TOOL_ENTRY)); if (NewGuidTool !=3D NULL) { memcpy (&(NewGuidTool->Guid), &Guid, sizeof (Guid)); - NewGuidTool->Name =3D CloneString(Tool->Strings[1]); - NewGuidTool->Path =3D CloneString(Tool->Strings[2]); + NewGuidTool->Name =3D CloneString (Tool->Strings[1]); + NewGuidTool->Path =3D CloneString (Tool->Strings[2]); NewGuidTool->Next =3D NULL; =20 if (FirstGuidTool =3D=3D NULL) { @@ -129,6 +129,7 @@ ParseGuidedSectionToolsMemoryFile ( } else { LastGuidTool->Next =3D NewGuidTool; } + LastGuidTool =3D NewGuidTool; } } @@ -137,6 +138,7 @@ ParseGuidedSectionToolsMemoryFile ( if (Tool !=3D NULL) { FreeStringList (Tool); } + free (NextLine); } =20 @@ -154,15 +156,15 @@ ParseGuidedSectionToolsMemoryFile ( @retval Non-NULL The tool to use to access the section contents. (The c= aller must free the memory associated with this string.) **/ -CHAR8* +CHAR8 * LookupGuidedSectionToolPath ( - IN EFI_HANDLE ParsedGuidedSectionToolsHandle, - IN EFI_GUID *SectionGuid + IN EFI_HANDLE ParsedGuidedSectionToolsHandle, + IN EFI_GUID *SectionGuid ) { - GUID_SEC_TOOL_ENTRY *GuidTool; + GUID_SEC_TOOL_ENTRY *GuidTool; =20 - GuidTool =3D (GUID_SEC_TOOL_ENTRY*)ParsedGuidedSectionToolsHandle; + GuidTool =3D (GUID_SEC_TOOL_ENTRY *)ParsedGuidedSectionToolsHandle; if (GuidTool =3D=3D NULL) { return NULL; } @@ -175,5 +177,3 @@ LookupGuidedSectionToolPath ( =20 return NULL; } - - diff --git a/BaseTools/Source/C/Common/ParseInf.c b/BaseTools/Source/C/Comm= on/ParseInf.c index 63da3d647cb7..c8b4c07c3b05 100644 --- a/BaseTools/Source/C/Common/ParseInf.c +++ b/BaseTools/Source/C/Common/ParseInf.c @@ -31,15 +31,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ CHAR8 * ReadLine ( - IN MEMORY_FILE *InputFile, - IN OUT CHAR8 *InputBuffer, - IN UINTN MaxLength + IN MEMORY_FILE *InputFile, + IN OUT CHAR8 *InputBuffer, + IN UINTN MaxLength ) =20 { - CHAR8 *CharPtr; - CHAR8 *EndOfLine; - UINTN CharsToCopy; + CHAR8 *CharPtr; + CHAR8 *EndOfLine; + UINTN CharsToCopy; =20 // // Verify input parameters are not null @@ -55,6 +55,7 @@ ReadLine ( if (InputFile->CurrentFilePointer >=3D InputFile->Eof) { return NULL; } + // // Find the next newline char // @@ -79,6 +80,7 @@ ReadLine ( // CharsToCopy =3D EndOfLine - InputFile->CurrentFilePointer; } + // // If the end of line is too big for the current buffer, set it to the m= ax // size of the buffer (leaving room for the \0. @@ -86,6 +88,7 @@ ReadLine ( if (CharsToCopy > MaxLength - 1) { CharsToCopy =3D MaxLength - 1; } + // // Copy the line. // @@ -95,13 +98,9 @@ ReadLine ( // Add the null termination over the 0x0D // if (InputBuffer[CharsToCopy - 1] =3D=3D '\r') { - InputBuffer[CharsToCopy - 1] =3D '\0'; - } else { - InputBuffer[CharsToCopy] =3D '\0'; - } =20 // @@ -116,6 +115,7 @@ ReadLine ( if (CharPtr !=3D 0) { CharPtr[0] =3D 0; } + // // Return the string // @@ -134,12 +134,12 @@ ReadLine ( **/ BOOLEAN FindSection ( - IN MEMORY_FILE *InputFile, - IN CHAR8 *Section + IN MEMORY_FILE *InputFile, + IN CHAR8 *Section ) { - CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; - CHAR8 *CurrentToken; + CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; + CHAR8 *CurrentToken; =20 // // Verify input is not NULL @@ -192,39 +192,41 @@ FindSection ( **/ EFI_STATUS FindToken ( - IN MEMORY_FILE *InputFile, - IN CHAR8 *Section, - IN CHAR8 *Token, - IN UINTN Instance, - OUT CHAR8 *Value + IN MEMORY_FILE *InputFile, + IN CHAR8 *Section, + IN CHAR8 *Token, + IN UINTN Instance, + OUT CHAR8 *Value ) { - CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; - CHAR8 *CurrentToken; - CHAR8 *Delimiter; - BOOLEAN ParseError; - BOOLEAN ReadError; - UINTN Occurrence; + CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; + CHAR8 *CurrentToken; + CHAR8 *Delimiter; + BOOLEAN ParseError; + BOOLEAN ReadError; + UINTN Occurrence; =20 // // Check input parameters // - if (InputFile->FileImage =3D=3D NULL || - InputFile->Eof =3D=3D NULL || - InputFile->CurrentFilePointer =3D=3D NULL || - Section =3D=3D NULL || - strlen (Section) =3D=3D 0 || - Token =3D=3D NULL || - strlen (Token) =3D=3D 0 || - Value =3D=3D NULL - ) { + if ((InputFile->FileImage =3D=3D NULL) || + (InputFile->Eof =3D=3D NULL) || + (InputFile->CurrentFilePointer =3D=3D NULL) || + (Section =3D=3D NULL) || + (strlen (Section) =3D=3D 0) || + (Token =3D=3D NULL) || + (strlen (Token) =3D=3D 0) || + (Value =3D=3D NULL) + ) + { return EFI_INVALID_PARAMETER; } + // // Initialize error codes // - ParseError =3D FALSE; - ReadError =3D FALSE; + ParseError =3D FALSE; + ReadError =3D FALSE; =20 // // Initialize our instance counter for the search token @@ -246,6 +248,7 @@ FindToken ( ReadError =3D TRUE; break; } + // // Get the first non-whitespace string // @@ -255,19 +258,21 @@ FindToken ( } =20 CurrentToken =3D strtok (InputBuffer, " \t\n"); - if (CurrentToken =3D=3D NULL || Delimiter =3D=3D NULL) { + if ((CurrentToken =3D=3D NULL) || (Delimiter =3D=3D NULL)) { // // Whitespace line found (or comment) so continue // CurrentToken =3D InputBuffer; continue; } + // // Make sure we have not reached the end of the current section // if (CurrentToken[0] =3D=3D '[') { break; } + // // Compare the current token with the desired token // @@ -295,6 +300,7 @@ FindToken ( while (*CurrentToken =3D=3D ' ' || *CurrentToken =3D=3D '\t') { CurrentToken++; } + // // Copy the current token to the output value // @@ -302,9 +308,10 @@ FindToken ( // // Strip trailing white space // - while (strlen(Value) > 0 && (*(Value + strlen(Value) - 1) =3D= =3D ' ' || *(Value + strlen(Value) - 1) =3D=3D '\t')) { - *(Value + strlen(Value) - 1) =3D 0; + while (strlen (Value) > 0 && (*(Value + strlen (Value) - 1) = =3D=3D ' ' || *(Value + strlen (Value) - 1) =3D=3D '\t')) { + *(Value + strlen (Value) - 1) =3D 0; } + return EFI_SUCCESS; } } else { @@ -315,13 +322,14 @@ FindToken ( } } } while ( - !ParseError && - !ReadError && - InputFile->CurrentFilePointer < InputFile->Eof && - CurrentToken[0] !=3D '[' && - Occurrence <=3D Instance - ); + !ParseError && + !ReadError && + InputFile->CurrentFilePointer < InputFile->Eof && + CurrentToken[0] !=3D '[' && + Occurrence <=3D Instance + ); } + // // Distinguish between read errors and INF file format errors. // @@ -353,27 +361,29 @@ StringToGuid ( OUT EFI_GUID *GuidBuffer ) { - INT32 Index; - int Data1; - int Data2; - int Data3; - int Data4[8]; + INT32 Index; + int Data1; + int Data2; + int Data3; + int Data4[8]; =20 - if (AsciiGuidBuffer =3D=3D NULL || GuidBuffer =3D=3D NULL) { + if ((AsciiGuidBuffer =3D=3D NULL) || (GuidBuffer =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } + // // Check Guid Format strictly xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx // - for (Index =3D 0; AsciiGuidBuffer[Index] !=3D '\0' && Index < 37; Index = ++) { - if (Index =3D=3D 8 || Index =3D=3D 13 || Index =3D=3D 18 || Index =3D= =3D 23) { + for (Index =3D 0; AsciiGuidBuffer[Index] !=3D '\0' && Index < 37; Index+= +) { + if ((Index =3D=3D 8) || (Index =3D=3D 13) || (Index =3D=3D 18) || (Ind= ex =3D=3D 23)) { if (AsciiGuidBuffer[Index] !=3D '-') { break; } } else { if (((AsciiGuidBuffer[Index] >=3D '0') && (AsciiGuidBuffer[Index] <= =3D '9')) || - ((AsciiGuidBuffer[Index] >=3D 'a') && (AsciiGuidBuffer[Index] <= =3D 'f')) || - ((AsciiGuidBuffer[Index] >=3D 'A') && (AsciiGuidBuffer[Index] <= =3D 'F'))) { + ((AsciiGuidBuffer[Index] >=3D 'a') && (AsciiGuidBuffer[Index] <= =3D 'f')) || + ((AsciiGuidBuffer[Index] >=3D 'A') && (AsciiGuidBuffer[Index] <= =3D 'F'))) + { continue; } else { break; @@ -381,7 +391,7 @@ StringToGuid ( } } =20 - if (Index < 36 || AsciiGuidBuffer[36] !=3D '\0') { + if ((Index < 36) || (AsciiGuidBuffer[36] !=3D '\0')) { Error (NULL, 0, 1003, "Invalid option value", "Incorrect GUID \"%s\"\n= Correct Format \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"", AsciiGuidBuffer= ); return EFI_ABORTED; } @@ -412,20 +422,21 @@ StringToGuid ( Error (NULL, 0, 1003, "Invalid option value", "Incorrect GUID \"%s\"\n= Correct Format \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"", AsciiGuidBuffer= ); return EFI_ABORTED; } + // // Copy the data into our GUID. // - GuidBuffer->Data1 =3D (UINT32) Data1; - GuidBuffer->Data2 =3D (UINT16) Data2; - GuidBuffer->Data3 =3D (UINT16) Data3; - GuidBuffer->Data4[0] =3D (UINT8) Data4[0]; - GuidBuffer->Data4[1] =3D (UINT8) Data4[1]; - GuidBuffer->Data4[2] =3D (UINT8) Data4[2]; - GuidBuffer->Data4[3] =3D (UINT8) Data4[3]; - GuidBuffer->Data4[4] =3D (UINT8) Data4[4]; - GuidBuffer->Data4[5] =3D (UINT8) Data4[5]; - GuidBuffer->Data4[6] =3D (UINT8) Data4[6]; - GuidBuffer->Data4[7] =3D (UINT8) Data4[7]; + GuidBuffer->Data1 =3D (UINT32)Data1; + GuidBuffer->Data2 =3D (UINT16)Data2; + GuidBuffer->Data3 =3D (UINT16)Data3; + GuidBuffer->Data4[0] =3D (UINT8)Data4[0]; + GuidBuffer->Data4[1] =3D (UINT8)Data4[1]; + GuidBuffer->Data4[2] =3D (UINT8)Data4[2]; + GuidBuffer->Data4[3] =3D (UINT8)Data4[3]; + GuidBuffer->Data4[4] =3D (UINT8)Data4[4]; + GuidBuffer->Data4[5] =3D (UINT8)Data4[5]; + GuidBuffer->Data4[6] =3D (UINT8)Data4[6]; + GuidBuffer->Data4[7] =3D (UINT8)Data4[7]; =20 return EFI_SUCCESS; } @@ -463,11 +474,12 @@ AsciiStringToUint64 ( // // Check input parameter // - if (AsciiString =3D=3D NULL || ReturnValue =3D=3D NULL || strlen(AsciiSt= ring) > 0xFF) { + if ((AsciiString =3D=3D NULL) || (ReturnValue =3D=3D NULL) || (strlen (A= sciiString) > 0xFF)) { return EFI_INVALID_PARAMETER; } + while (AsciiString[Index] =3D=3D ' ') { - Index ++; + Index++; } =20 // @@ -477,34 +489,37 @@ AsciiStringToUint64 ( // // Skip first two chars only if the string starts with '0x' or '0X' // - if (AsciiString[Index] =3D=3D '0' && (AsciiString[Index + 1] =3D=3D 'x' = || AsciiString[Index + 1] =3D=3D 'X')) { - IsHex =3D TRUE; + if ((AsciiString[Index] =3D=3D '0') && ((AsciiString[Index + 1] =3D=3D '= x') || (AsciiString[Index + 1] =3D=3D 'X'))) { + IsHex =3D TRUE; Index +=3D 2; } + if (IsHex) { // // Convert the hex string. // - for (; AsciiString[Index] !=3D '\0'; Index++) { + for ( ; AsciiString[Index] !=3D '\0'; Index++) { CurrentChar =3D AsciiString[Index]; if (CurrentChar =3D=3D ' ') { break; } + // // Verify Hex string // if (isxdigit ((int)CurrentChar) =3D=3D 0) { return EFI_ABORTED; } + // // Add hex value // Value *=3D 16; - if (CurrentChar >=3D '0' && CurrentChar <=3D '9') { + if ((CurrentChar >=3D '0') && (CurrentChar <=3D '9')) { Value +=3D CurrentChar - '0'; - } else if (CurrentChar >=3D 'a' && CurrentChar <=3D 'f') { + } else if ((CurrentChar >=3D 'a') && (CurrentChar <=3D 'f')) { Value +=3D CurrentChar - 'a' + 10; - } else if (CurrentChar >=3D 'A' && CurrentChar <=3D 'F') { + } else if ((CurrentChar >=3D 'A') && (CurrentChar <=3D 'F')) { Value +=3D CurrentChar - 'A' + 10; } } @@ -514,21 +529,23 @@ AsciiStringToUint64 ( // // Convert dec string is a number // - for (; Index < strlen (AsciiString); Index++) { + for ( ; Index < strlen (AsciiString); Index++) { CurrentChar =3D AsciiString[Index]; if (CurrentChar =3D=3D ' ') { break; } + // // Verify Dec string // if (isdigit ((int)CurrentChar) =3D=3D 0) { return EFI_ABORTED; } + // // Add dec value // - Value =3D Value * 10; + Value =3D Value * 10; Value +=3D CurrentChar - '0'; } =20 @@ -554,7 +571,7 @@ ReadLineInStream ( IN OUT CHAR8 *InputBuffer ) { - CHAR8 *CharPtr; + CHAR8 *CharPtr; =20 // // Verify input parameters are not null @@ -568,6 +585,7 @@ ReadLineInStream ( if (fgets (InputBuffer, MAX_LONG_FILE_PATH, InputFile) =3D=3D NULL) { return NULL; } + // // Strip any comments // @@ -580,6 +598,7 @@ ReadLineInStream ( if (CharPtr !=3D 0) { CharPtr[0] =3D 0; } + // // Return the string // @@ -599,12 +618,12 @@ ReadLineInStream ( **/ BOOLEAN FindSectionInStream ( - IN FILE *InputFile, - IN CHAR8 *Section + IN FILE *InputFile, + IN CHAR8 *Section ) { - CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; - CHAR8 *CurrentToken; + CHAR8 InputBuffer[MAX_LONG_FILE_PATH]; + CHAR8 *CurrentToken; =20 // // Verify input is not NULL @@ -618,6 +637,7 @@ FindSectionInStream ( if (fseek (InputFile, 0, SEEK_SET) !=3D 0) { return FALSE; } + // // Read lines until the section is found // diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c b/BaseTools/Source/= C/Common/PcdValueCommon.c index 591a7787828c..d93924132e68 100644 --- a/BaseTools/Source/C/Common/PcdValueCommon.c +++ b/BaseTools/Source/C/Common/PcdValueCommon.c @@ -23,13 +23,13 @@ typedef enum { } PCD_DATA_TYPE; =20 typedef struct { - CHAR8 *SkuName; - CHAR8 *DefaultValueName; - CHAR8 *TokenSpaceGuidName; - CHAR8 *TokenName; - CHAR8 *DataType; - CHAR8 *Value; - PCD_DATA_TYPE PcdDataType; + CHAR8 *SkuName; + CHAR8 *DefaultValueName; + CHAR8 *TokenSpaceGuidName; + CHAR8 *TokenName; + CHAR8 *DataType; + CHAR8 *Value; + PCD_DATA_TYPE PcdDataType; } PCD_ENTRY; =20 PCD_ENTRY *PcdList; @@ -61,43 +61,45 @@ RecordToken ( if (Token =3D=3D NULL) { return; } + memcpy (Token, &FileBuffer[TokenStart], TokenEnd - TokenStart); Token[TokenEnd - TokenStart] =3D 0; switch (TokenIndex) { - case 0: - PcdList[PcdIndex].SkuName =3D Token; - break; - case 1: - PcdList[PcdIndex].DefaultValueName =3D Token; - break; - case 2: - PcdList[PcdIndex].TokenSpaceGuidName =3D Token; - break; - case 3: - PcdList[PcdIndex].TokenName =3D Token; - break; - case 4: - PcdList[PcdIndex].DataType =3D Token; - if (strcmp (Token, "BOOLEAN") =3D=3D 0) { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypeBoolean; - } else if (strcmp (Token, "UINT8") =3D=3D 0) { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint8; - } else if (strcmp (Token, "UINT16") =3D=3D 0) { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint16; - } else if (strcmp (Token, "UINT32") =3D=3D 0) { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint32; - } else if (strcmp (Token, "UINT64") =3D=3D 0) { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint64; - } else { - PcdList[PcdIndex].PcdDataType =3D PcdDataTypePointer; - } - break; - case 5: - PcdList[PcdIndex].Value =3D Token; - break; - default: - free (Token); - break; + case 0: + PcdList[PcdIndex].SkuName =3D Token; + break; + case 1: + PcdList[PcdIndex].DefaultValueName =3D Token; + break; + case 2: + PcdList[PcdIndex].TokenSpaceGuidName =3D Token; + break; + case 3: + PcdList[PcdIndex].TokenName =3D Token; + break; + case 4: + PcdList[PcdIndex].DataType =3D Token; + if (strcmp (Token, "BOOLEAN") =3D=3D 0) { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypeBoolean; + } else if (strcmp (Token, "UINT8") =3D=3D 0) { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint8; + } else if (strcmp (Token, "UINT16") =3D=3D 0) { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint16; + } else if (strcmp (Token, "UINT32") =3D=3D 0) { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint32; + } else if (strcmp (Token, "UINT64") =3D=3D 0) { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypeUint64; + } else { + PcdList[PcdIndex].PcdDataType =3D PcdDataTypePointer; + } + + break; + case 5: + PcdList[PcdIndex].Value =3D Token; + break; + default: + free (Token); + break; } } =20 @@ -125,24 +127,31 @@ LookupPcdIndex ( if (SkuName =3D=3D NULL) { SkuName =3D "DEFAULT"; } + if (DefaultValueName =3D=3D NULL) { DefaultValueName =3D "DEFAULT"; } + for (Index =3D 0; Index < PcdListLength; Index++) { - if (strcmp(PcdList[Index].TokenSpaceGuidName, TokenSpaceGuidName) !=3D= 0) { + if (strcmp (PcdList[Index].TokenSpaceGuidName, TokenSpaceGuidName) != =3D 0) { continue; } - if (strcmp(PcdList[Index].TokenName, TokenName) !=3D 0) { + + if (strcmp (PcdList[Index].TokenName, TokenName) !=3D 0) { continue; } - if (strcmp(PcdList[Index].SkuName, SkuName) !=3D 0) { + + if (strcmp (PcdList[Index].SkuName, SkuName) !=3D 0) { continue; } - if (strcmp(PcdList[Index].DefaultValueName, DefaultValueName) !=3D 0) { + + if (strcmp (PcdList[Index].DefaultValueName, DefaultValueName) !=3D 0)= { continue; } + return Index; } + return -1; } =20 @@ -172,21 +181,23 @@ __PcdGet ( fprintf (stderr, "PCD %s.%s.%s.%s is not in database\n", SkuName, Defa= ultValueName, TokenSpaceGuidName, TokenName); exit (EXIT_FAILURE); } + switch (PcdList[Index].PcdDataType) { - case PcdDataTypeBoolean: - case PcdDataTypeUint8: - case PcdDataTypeUint16: - case PcdDataTypeUint32: - return (UINT64)strtoul(PcdList[Index].Value, &End, 16); - break; - case PcdDataTypeUint64: - return (UINT64)strtoul(PcdList[Index].Value, &End, 16); - break; - case PcdDataTypePointer: - fprintf (stderr, "PCD %s.%s.%s.%s is structure. Use PcdGetPtr()\n", S= kuName, DefaultValueName, TokenSpaceGuidName, TokenName); - exit (EXIT_FAILURE); - break; + case PcdDataTypeBoolean: + case PcdDataTypeUint8: + case PcdDataTypeUint16: + case PcdDataTypeUint32: + return (UINT64)strtoul (PcdList[Index].Value, &End, 16); + break; + case PcdDataTypeUint64: + return (UINT64)strtoul (PcdList[Index].Value, &End, 16); + break; + case PcdDataTypePointer: + fprintf (stderr, "PCD %s.%s.%s.%s is structure. Use PcdGetPtr()\n",= SkuName, DefaultValueName, TokenSpaceGuidName, TokenName); + exit (EXIT_FAILURE); + break; } + return 0; } =20 @@ -208,39 +219,41 @@ __PcdSet ( UINT64 Value ) { - int Index; + int Index; =20 Index =3D LookupPcdIndex (SkuName, DefaultValueName, TokenSpaceGuidName,= TokenName); if (Index < 0) { fprintf (stderr, "PCD %s.%s.%s.%s is not in database\n", SkuName, Defa= ultValueName, TokenSpaceGuidName, TokenName); exit (EXIT_FAILURE); } - free(PcdList[Index].Value); - PcdList[Index].Value =3D malloc(20); + + free (PcdList[Index].Value); + PcdList[Index].Value =3D malloc (20); switch (PcdList[Index].PcdDataType) { - case PcdDataTypeBoolean: - if (Value =3D=3D 0) { - strcpy (PcdList[Index].Value, "0x00"); - } else { - strcpy (PcdList[Index].Value, "0x01"); - } - break; - case PcdDataTypeUint8: - sprintf(PcdList[Index].Value, "0x%02x", (UINT8)(Value & 0xff)); - break; - case PcdDataTypeUint16: - sprintf(PcdList[Index].Value, "0x%04x", (UINT16)(Value & 0xffff)); - break; - case PcdDataTypeUint32: - sprintf(PcdList[Index].Value, "0x%08x", (UINT32)(Value & 0xffffffff)); - break; - case PcdDataTypeUint64: - sprintf(PcdList[Index].Value, "0x%016llx", (unsigned long long)Value); - break; - case PcdDataTypePointer: - fprintf (stderr, "PCD %s.%s.%s.%s is structure. Use PcdSetPtr()\n", S= kuName, DefaultValueName, TokenSpaceGuidName, TokenName); - exit (EXIT_FAILURE); - break; + case PcdDataTypeBoolean: + if (Value =3D=3D 0) { + strcpy (PcdList[Index].Value, "0x00"); + } else { + strcpy (PcdList[Index].Value, "0x01"); + } + + break; + case PcdDataTypeUint8: + sprintf (PcdList[Index].Value, "0x%02x", (UINT8)(Value & 0xff)); + break; + case PcdDataTypeUint16: + sprintf (PcdList[Index].Value, "0x%04x", (UINT16)(Value & 0xffff)); + break; + case PcdDataTypeUint32: + sprintf (PcdList[Index].Value, "0x%08x", (UINT32)(Value & 0xffffffff= )); + break; + case PcdDataTypeUint64: + sprintf (PcdList[Index].Value, "0x%016llx", (unsigned long long)Valu= e); + break; + case PcdDataTypePointer: + fprintf (stderr, "PCD %s.%s.%s.%s is structure. Use PcdSetPtr()\n",= SkuName, DefaultValueName, TokenSpaceGuidName, TokenName); + exit (EXIT_FAILURE); + break; } } =20 @@ -252,7 +265,7 @@ __PcdSet ( @param TokenSpaceGuidName TokenSpaceGuidName String @param TokenName TokenName String @param Size Size of PCD value buffer -=20 + @return PCD value buffer **/ VOID * @@ -265,40 +278,45 @@ __PcdGetPtr ( ) { int Index; - CHAR8 *Value; - UINT8 *Buffer; - CHAR8 *End; + CHAR8 *Value; + UINT8 *Buffer; + CHAR8 *End; =20 Index =3D LookupPcdIndex (SkuName, DefaultValueName, TokenSpaceGuidName,= TokenName); if (Index < 0) { fprintf (stderr, "PCD %s.%s.%s.%s is not in database\n", SkuName, Defa= ultValueName, TokenSpaceGuidName, TokenName); exit (EXIT_FAILURE); } + switch (PcdList[Index].PcdDataType) { - case PcdDataTypeBoolean: - case PcdDataTypeUint8: - case PcdDataTypeUint16: - case PcdDataTypeUint32: - case PcdDataTypeUint64: - fprintf (stderr, "PCD %s.%s.%s.%s is a value. Use PcdGet()\n", SkuNam= e, DefaultValueName, TokenSpaceGuidName, TokenName); - exit (EXIT_FAILURE); - break; - case PcdDataTypePointer: - Value =3D &PcdList[Index].Value[1]; - for (*Size =3D 0, strtoul(Value, &End, 16); Value !=3D End; strtoul(Va= lue, &End, 16), *Size =3D *Size + 1) { - Value =3D End + 1; - } - Buffer =3D malloc(*Size + 1); - if (Buffer =3D=3D NULL) { - *Size =3D 0; - return NULL; - } - Value =3D &PcdList[Index].Value[1]; - for (*Size =3D 0, Buffer[*Size] =3D (UINT8) strtoul(Value, &End, 16); = Value !=3D End; *Size =3D *Size + 1, Buffer[*Size] =3D (UINT8) strtoul(Valu= e, &End, 16)) { - Value =3D End + 1; - } - return Buffer; + case PcdDataTypeBoolean: + case PcdDataTypeUint8: + case PcdDataTypeUint16: + case PcdDataTypeUint32: + case PcdDataTypeUint64: + fprintf (stderr, "PCD %s.%s.%s.%s is a value. Use PcdGet()\n", SkuN= ame, DefaultValueName, TokenSpaceGuidName, TokenName); + exit (EXIT_FAILURE); + break; + case PcdDataTypePointer: + Value =3D &PcdList[Index].Value[1]; + for (*Size =3D 0, strtoul (Value, &End, 16); Value !=3D End; strtoul= (Value, &End, 16), *Size =3D *Size + 1) { + Value =3D End + 1; + } + + Buffer =3D malloc (*Size + 1); + if (Buffer =3D=3D NULL) { + *Size =3D 0; + return NULL; + } + + Value =3D &PcdList[Index].Value[1]; + for (*Size =3D 0, Buffer[*Size] =3D (UINT8)strtoul (Value, &End, 16)= ; Value !=3D End; *Size =3D *Size + 1, Buffer[*Size] =3D (UINT8)strtoul (Va= lue, &End, 16)) { + Value =3D End + 1; + } + + return Buffer; } + *Size =3D 0; return 0; } @@ -323,7 +341,7 @@ __PcdSetPtr ( UINT8 *Value ) { - int Index; + int Index; UINT32 ValueIndex; =20 Index =3D LookupPcdIndex (SkuName, DefaultValueName, TokenSpaceGuidName,= TokenName); @@ -331,31 +349,33 @@ __PcdSetPtr ( fprintf (stderr, "PCD %s.%s.%s.%s is not in database\n", SkuName, Defa= ultValueName, TokenSpaceGuidName, TokenName); exit (EXIT_FAILURE); } + switch (PcdList[Index].PcdDataType) { - case PcdDataTypeBoolean: - case PcdDataTypeUint8: - case PcdDataTypeUint16: - case PcdDataTypeUint32: - case PcdDataTypeUint64: - fprintf (stderr, "PCD %s.%s.%s.%s is a value. Use PcdGet()\n", SkuNam= e, DefaultValueName, TokenSpaceGuidName, TokenName); - exit (EXIT_FAILURE); - break; - case PcdDataTypePointer: - free(PcdList[Index].Value); - PcdList[Index].Value =3D malloc(Size * 5 + 3); - PcdList[Index].Value[0] =3D '{'; - for (ValueIndex =3D 0; ValueIndex < Size; ValueIndex++) { - sprintf(&PcdList[Index].Value[1 + ValueIndex * 5], "0x%02x,", Value[= ValueIndex]); - } - PcdList[Index].Value[1 + Size * 5 - 1] =3D '}'; - PcdList[Index].Value[1 + Size * 5 ] =3D 0; - break; + case PcdDataTypeBoolean: + case PcdDataTypeUint8: + case PcdDataTypeUint16: + case PcdDataTypeUint32: + case PcdDataTypeUint64: + fprintf (stderr, "PCD %s.%s.%s.%s is a value. Use PcdGet()\n", SkuN= ame, DefaultValueName, TokenSpaceGuidName, TokenName); + exit (EXIT_FAILURE); + break; + case PcdDataTypePointer: + free (PcdList[Index].Value); + PcdList[Index].Value =3D malloc (Size * 5 + 3); + PcdList[Index].Value[0] =3D '{'; + for (ValueIndex =3D 0; ValueIndex < Size; ValueIndex++) { + sprintf (&PcdList[Index].Value[1 + ValueIndex * 5], "0x%02x,", Val= ue[ValueIndex]); + } + + PcdList[Index].Value[1 + Size * 5 - 1] =3D '}'; + PcdList[Index].Value[1 + Size * 5] =3D 0; + break; } } =20 /** Read the file buffer from the input file. -=20 + @param InputFileName Point to the input file name. @param FileBuffer Point to the input file buffer. @param FileSize Size of the file buffer. @@ -459,15 +479,17 @@ ParseFile ( NumLines++; } } - PcdList =3D malloc((NumLines + 1) * sizeof(PcdList[0])); + + PcdList =3D malloc ((NumLines + 1) * sizeof (PcdList[0])); =20 for (Index =3D 0, TokenIndex =3D 0, PcdListLength =3D 0, TokenStart =3D = 0; Index < FileSize; Index++) { if (FileBuffer[Index] =3D=3D ' ') { continue; } - if (FileBuffer[Index] =3D=3D '|' || FileBuffer[Index] =3D=3D '.' || Fi= leBuffer[Index] =3D=3D '\n' || FileBuffer[Index] =3D=3D '\r') { + + if ((FileBuffer[Index] =3D=3D '|') || (FileBuffer[Index] =3D=3D '.') |= | (FileBuffer[Index] =3D=3D '\n') || (FileBuffer[Index] =3D=3D '\r')) { RecordToken (FileBuffer, PcdListLength, TokenIndex, TokenStart, Inde= x); - if (FileBuffer[Index] =3D=3D '\n' || FileBuffer[Index] =3D=3D '\r') { + if ((FileBuffer[Index] =3D=3D '\n') || (FileBuffer[Index] =3D=3D '\r= ')) { if (TokenIndex !=3D 0) { PcdListLength++; TokenIndex =3D 0; @@ -475,10 +497,12 @@ ParseFile ( } else { TokenIndex++; } + TokenStart =3D Index + 1; continue; } } + if (Index > TokenStart) { RecordToken (FileBuffer, PcdListLength, TokenIndex, TokenStart, Index); if (TokenIndex !=3D 0) { @@ -495,7 +519,7 @@ ParseFile ( VOID STATIC WriteOutputFile ( - CHAR8 *OutputFileName + CHAR8 *OutputFileName ) { FILE *OutputFile; @@ -584,24 +608,26 @@ ParseArguments ( =20 while (argc > 0) { if ((stricmp (argv[0], "-i") =3D=3D 0) || (stricmp (argv[0], "--input"= ) =3D=3D 0)) { - if (argv[1] =3D=3D NULL || argv[1][0] =3D=3D '-') { + if ((argv[1] =3D=3D NULL) || (argv[1][0] =3D=3D '-')) { fprintf (stderr, "Invalid option value. Input File name is missin= g for -i option\n"); exit (EXIT_FAILURE); } + *InputFileName =3D argv[1]; - argc -=3D 2; - argv +=3D 2; + argc -=3D 2; + argv +=3D 2; continue; } =20 if ((stricmp (argv[0], "-o") =3D=3D 0) || (stricmp (argv[0], "--output= ") =3D=3D 0)) { - if (argv[1] =3D=3D NULL || argv[1][0] =3D=3D '-') { + if ((argv[1] =3D=3D NULL) || (argv[1][0] =3D=3D '-')) { fprintf (stderr, "Invalid option value. Output File name is missi= ng for -i option\n"); exit (EXIT_FAILURE); } + *OutputFileName =3D argv[1]; - argc -=3D 2; - argv +=3D 2; + argc -=3D 2; + argv +=3D 2; continue; } =20 @@ -609,8 +635,9 @@ ParseArguments ( fprintf (stderr, "Unknown option %s\n", argv[0]); exit (EXIT_FAILURE); } - argc --; - argv ++; + + argc--; + argv++; } =20 // @@ -646,7 +673,7 @@ PcdValueMain ( UINT8 *FileBuffer; UINT32 FileSize; =20 - InputFileName =3D NULL; + InputFileName =3D NULL; OutputFileName =3D NULL; =20 // diff --git a/BaseTools/Source/C/Common/PeCoffLoaderEx.c b/BaseTools/Source/= C/Common/PeCoffLoaderEx.c index 181192035ef1..5865b825357c 100644 --- a/BaseTools/Source/C/Common/PeCoffLoaderEx.c +++ b/BaseTools/Source/C/Common/PeCoffLoaderEx.c @@ -15,7 +15,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "CommonLib.h" #include "EfiUtilityMsgs.h" =20 - #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \ Value |=3D (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) -= 1))) << ValPos) =20 @@ -23,47 +22,47 @@ SPDX-License-Identifier: BSD-2-Clause-Patent *(UINT32*)Address =3D (*(UINT32*)Address & ~(((1 << Size) - 1) << Inst= Pos)) | \ ((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1)= )) << InstPos) =20 -#define IMM64_IMM7B_INST_WORD_X 3 -#define IMM64_IMM7B_SIZE_X 7 -#define IMM64_IMM7B_INST_WORD_POS_X 4 -#define IMM64_IMM7B_VAL_POS_X 0 - -#define IMM64_IMM9D_INST_WORD_X 3 -#define IMM64_IMM9D_SIZE_X 9 -#define IMM64_IMM9D_INST_WORD_POS_X 18 -#define IMM64_IMM9D_VAL_POS_X 7 - -#define IMM64_IMM5C_INST_WORD_X 3 -#define IMM64_IMM5C_SIZE_X 5 -#define IMM64_IMM5C_INST_WORD_POS_X 13 -#define IMM64_IMM5C_VAL_POS_X 16 - -#define IMM64_IC_INST_WORD_X 3 -#define IMM64_IC_SIZE_X 1 -#define IMM64_IC_INST_WORD_POS_X 12 -#define IMM64_IC_VAL_POS_X 21 - -#define IMM64_IMM41a_INST_WORD_X 1 -#define IMM64_IMM41a_SIZE_X 10 -#define IMM64_IMM41a_INST_WORD_POS_X 14 -#define IMM64_IMM41a_VAL_POS_X 22 - -#define IMM64_IMM41b_INST_WORD_X 1 -#define IMM64_IMM41b_SIZE_X 8 -#define IMM64_IMM41b_INST_WORD_POS_X 24 -#define IMM64_IMM41b_VAL_POS_X 32 - -#define IMM64_IMM41c_INST_WORD_X 2 -#define IMM64_IMM41c_SIZE_X 23 -#define IMM64_IMM41c_INST_WORD_POS_X 0 -#define IMM64_IMM41c_VAL_POS_X 40 - -#define IMM64_SIGN_INST_WORD_X 3 -#define IMM64_SIGN_SIZE_X 1 -#define IMM64_SIGN_INST_WORD_POS_X 27 -#define IMM64_SIGN_VAL_POS_X 63 - -UINT32 *RiscVHi20Fixup =3D NULL; +#define IMM64_IMM7B_INST_WORD_X 3 +#define IMM64_IMM7B_SIZE_X 7 +#define IMM64_IMM7B_INST_WORD_POS_X 4 +#define IMM64_IMM7B_VAL_POS_X 0 + +#define IMM64_IMM9D_INST_WORD_X 3 +#define IMM64_IMM9D_SIZE_X 9 +#define IMM64_IMM9D_INST_WORD_POS_X 18 +#define IMM64_IMM9D_VAL_POS_X 7 + +#define IMM64_IMM5C_INST_WORD_X 3 +#define IMM64_IMM5C_SIZE_X 5 +#define IMM64_IMM5C_INST_WORD_POS_X 13 +#define IMM64_IMM5C_VAL_POS_X 16 + +#define IMM64_IC_INST_WORD_X 3 +#define IMM64_IC_SIZE_X 1 +#define IMM64_IC_INST_WORD_POS_X 12 +#define IMM64_IC_VAL_POS_X 21 + +#define IMM64_IMM41a_INST_WORD_X 1 +#define IMM64_IMM41a_SIZE_X 10 +#define IMM64_IMM41a_INST_WORD_POS_X 14 +#define IMM64_IMM41a_VAL_POS_X 22 + +#define IMM64_IMM41b_INST_WORD_X 1 +#define IMM64_IMM41b_SIZE_X 8 +#define IMM64_IMM41b_INST_WORD_POS_X 24 +#define IMM64_IMM41b_VAL_POS_X 32 + +#define IMM64_IMM41c_INST_WORD_X 2 +#define IMM64_IMM41c_SIZE_X 23 +#define IMM64_IMM41c_INST_WORD_POS_X 0 +#define IMM64_IMM41c_VAL_POS_X 40 + +#define IMM64_SIGN_INST_WORD_X 3 +#define IMM64_SIGN_SIZE_X 1 +#define IMM64_SIGN_INST_WORD_POS_X 27 +#define IMM64_SIGN_VAL_POS_X 63 + +UINT32 *RiscVHi20Fixup =3D NULL; =20 /** Performs an IA-32 specific relocation fixup @@ -77,10 +76,10 @@ UINT32 *RiscVHi20Fixup =3D NULL; **/ RETURN_STATUS PeCoffLoaderRelocateIa32Image ( - IN UINT16 *Reloc, - IN OUT CHAR8 *Fixup, - IN OUT CHAR8 **FixupData, - IN UINT64 Adjust + IN UINT16 *Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust ) { return RETURN_UNSUPPORTED; @@ -98,61 +97,65 @@ PeCoffLoaderRelocateIa32Image ( **/ RETURN_STATUS PeCoffLoaderRelocateRiscVImage ( - IN UINT16 *Reloc, - IN OUT CHAR8 *Fixup, - IN OUT CHAR8 **FixupData, - IN UINT64 Adjust + IN UINT16 *Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust ) { - UINT32 Value; - UINT32 Value2; + UINT32 Value; + UINT32 Value2; =20 switch ((*Reloc) >> 12) { - case EFI_IMAGE_REL_BASED_RISCV_HI20: - RiscVHi20Fixup =3D (UINT32 *) Fixup; + case EFI_IMAGE_REL_BASED_RISCV_HI20: + RiscVHi20Fixup =3D (UINT32 *)Fixup; break; =20 - case EFI_IMAGE_REL_BASED_RISCV_LOW12I: + case EFI_IMAGE_REL_BASED_RISCV_LOW12I: if (RiscVHi20Fixup !=3D NULL) { - Value =3D (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12); - Value2 =3D (UINT32)(RV_X(*(UINT32 *)Fixup, 20, 12)); + Value =3D (UINT32)(RV_X (*RiscVHi20Fixup, 12, 20) << 12); + Value2 =3D (UINT32)(RV_X (*(UINT32 *)Fixup, 20, 12)); if (Value2 & (RISCV_IMM_REACH/2)) { Value2 |=3D ~(RISCV_IMM_REACH-1); } - Value +=3D Value2; - Value +=3D (UINT32)Adjust; - Value2 =3D RISCV_CONST_HIGH_PART (Value); + + Value +=3D Value2; + Value +=3D (UINT32)Adjust; + Value2 =3D RISCV_CONST_HIGH_PART (Value); *(UINT32 *)RiscVHi20Fixup =3D (RV_X (Value2, 12, 20) << 12) | \ - (RV_X (*(UINT32 *)RiscVHi20Fixu= p, 0, 12)); + (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 1= 2)); *(UINT32 *)Fixup =3D (RV_X (Value, 0, 12) << 20) | \ (RV_X (*(UINT32 *)Fixup, 0, 20)); } + RiscVHi20Fixup =3D NULL; break; =20 - case EFI_IMAGE_REL_BASED_RISCV_LOW12S: + case EFI_IMAGE_REL_BASED_RISCV_LOW12S: if (RiscVHi20Fixup !=3D NULL) { - Value =3D (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12); - Value2 =3D (UINT32)(RV_X(*(UINT32 *)Fixup, 7, 5) | (RV_X(*(UINT32 = *)Fixup, 25, 7) << 5)); + Value =3D (UINT32)(RV_X (*RiscVHi20Fixup, 12, 20) << 12); + Value2 =3D (UINT32)(RV_X (*(UINT32 *)Fixup, 7, 5) | (RV_X (*(UINT3= 2 *)Fixup, 25, 7) << 5)); if (Value2 & (RISCV_IMM_REACH/2)) { Value2 |=3D ~(RISCV_IMM_REACH-1); } - Value +=3D Value2; - Value +=3D (UINT32)Adjust; - Value2 =3D RISCV_CONST_HIGH_PART (Value); + + Value +=3D Value2; + Value +=3D (UINT32)Adjust; + Value2 =3D RISCV_CONST_HIGH_PART (Value); *(UINT32 *)RiscVHi20Fixup =3D (RV_X (Value2, 12, 20) << 12) | \ - (RV_X (*(UINT32 *)RiscVHi20Fixu= p, 0, 12)); - Value2 =3D *(UINT32 *)Fixup & 0x01fff07f; - Value &=3D RISCV_IMM_REACH - 1; - *(UINT32 *)Fixup =3D Value2 | (UINT32)(((RV_X(Value, 0, 5) << 7) |= (RV_X(Value, 5, 7) << 25))); + (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 1= 2)); + Value2 =3D *(UINT32 *)Fixup & 0x01fff07f; + Value &=3D RISCV_IMM_REACH - 1; + *(UINT32 *)Fixup =3D Value2 | (UINT32)(((RV_X (Value, 0, 5) << 7) = | (RV_X (Value, 5, 7) << 25))); } + RiscVHi20Fixup =3D NULL; break; =20 - default: + default: return EFI_UNSUPPORTED; - } + return RETURN_SUCCESS; } =20 @@ -167,7 +170,7 @@ PeCoffLoaderRelocateRiscVImage ( **/ UINT16 ThumbMovtImmediateAddress ( - IN UINT16 *Instruction + IN UINT16 *Instruction ) { UINT32 Movt; @@ -188,7 +191,6 @@ ThumbMovtImmediateAddress ( return Address; } =20 - /** Update an ARM MOVT or MOVW immediate instruction immediate data. =20 @@ -197,15 +199,15 @@ ThumbMovtImmediateAddress ( **/ VOID ThumbMovtImmediatePatch ( - IN OUT UINT16 *Instruction, - IN UINT16 Address + IN OUT UINT16 *Instruction, + IN UINT16 Address ) { UINT16 Patch; =20 // First 16-bit chunk of instruction - Patch =3D ((Address >> 12) & 0x000f); // imm4 - Patch |=3D (((Address & BIT11) !=3D 0) ? BIT10 : 0); // i + Patch =3D ((Address >> 12) & 0x000f); // imm4 + Patch |=3D (((Address & BIT11) !=3D 0) ? BIT10 : 0); // i *Instruction =3D (*Instruction & ~0x040f) | Patch; =20 // Second 16-bit chunk of instruction @@ -227,7 +229,7 @@ ThumbMovtImmediatePatch ( UINT32 EFIAPI ThumbMovwMovtImmediateAddress ( - IN UINT16 *Instructions + IN UINT16 *Instructions ) { UINT16 *Word; @@ -239,7 +241,6 @@ ThumbMovwMovtImmediateAddress ( return (ThumbMovtImmediateAddress (Top) << 16) + ThumbMovtImmediateAddre= ss (Word); } =20 - /** Update an ARM MOVW/MOVT immediate instruction instruction pair. =20 @@ -249,8 +250,8 @@ ThumbMovwMovtImmediateAddress ( VOID EFIAPI ThumbMovwMovtImmediatePatch ( - IN OUT UINT16 *Instructions, - IN UINT32 Address + IN OUT UINT16 *Instructions, + IN UINT32 Address ) { UINT16 *Word; @@ -263,7 +264,6 @@ ThumbMovwMovtImmediatePatch ( ThumbMovtImmediatePatch (Top, (UINT16)(Address >> 16)); } =20 - /** Performs an ARM-based specific relocation fixup and is a no-op on other instruction sets. @@ -278,35 +278,34 @@ ThumbMovwMovtImmediatePatch ( **/ RETURN_STATUS PeCoffLoaderRelocateArmImage ( - IN UINT16 **Reloc, - IN OUT CHAR8 *Fixup, - IN OUT CHAR8 **FixupData, - IN UINT64 Adjust + IN UINT16 **Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust ) { - UINT16 *Fixup16; - UINT32 FixupVal; + UINT16 *Fixup16; + UINT32 FixupVal; =20 - Fixup16 =3D (UINT16 *) Fixup; + Fixup16 =3D (UINT16 *)Fixup; =20 switch ((**Reloc) >> 12) { + case EFI_IMAGE_REL_BASED_ARM_MOV32T: + FixupVal =3D ThumbMovwMovtImmediateAddress (Fixup16) + (UINT32)Adjus= t; + ThumbMovwMovtImmediatePatch (Fixup16, FixupVal); =20 - case EFI_IMAGE_REL_BASED_ARM_MOV32T: - FixupVal =3D ThumbMovwMovtImmediateAddress (Fixup16) + (UINT32)Adjust; - ThumbMovwMovtImmediatePatch (Fixup16, FixupVal); + if (*FixupData !=3D NULL) { + *FixupData =3D ALIGN_POINTER (*FixupData, sizeof (UINT64)); + CopyMem (*FixupData, Fixup16, sizeof (UINT64)); + *FixupData =3D *FixupData + sizeof (UINT64); + } =20 + break; =20 - if (*FixupData !=3D NULL) { - *FixupData =3D ALIGN_POINTER(*FixupData, sizeof(UINT64)); - CopyMem (*FixupData, Fixup16, sizeof (UINT64)); - *FixupData =3D *FixupData + sizeof(UINT64); - } - break; - - case EFI_IMAGE_REL_BASED_ARM_MOV32A: - // break omitted - ARM instruction encoding not implemented - default: - return RETURN_UNSUPPORTED; + case EFI_IMAGE_REL_BASED_ARM_MOV32A: + // break omitted - ARM instruction encoding not implemented + default: + return RETURN_UNSUPPORTED; } =20 return RETURN_SUCCESS; @@ -330,10 +329,10 @@ PeCoffLoaderRelocateLoongArch64Image ( IN UINT64 Adjust ) { - UINT8 RelocType; - UINT64 Value; - UINT64 Tmp1; - UINT64 Tmp2; + UINT8 RelocType; + UINT64 Value; + UINT64 Tmp1; + UINT64 Tmp2; =20 RelocType =3D ((*Reloc) >> 12); Value =3D 0; diff --git a/BaseTools/Source/C/Common/SimpleFileParsing.c b/BaseTools/Sour= ce/C/Common/SimpleFileParsing.c index 51d59cf4a765..cec82b540569 100644 --- a/BaseTools/Source/C/Common/SimpleFileParsing.c +++ b/BaseTools/Source/C/Common/SimpleFileParsing.c @@ -27,46 +27,46 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // #define MAX_STRING_IDENTIFIER_NAME 100 =20 -#define T_CHAR_SPACE ' ' -#define T_CHAR_NULL 0 -#define T_CHAR_CR '\r' -#define T_CHAR_TAB '\t' -#define T_CHAR_LF '\n' -#define T_CHAR_SLASH '/' -#define T_CHAR_BACKSLASH '\\' -#define T_CHAR_DOUBLE_QUOTE '"' -#define T_CHAR_LC_X 'x' -#define T_CHAR_0 '0' -#define T_CHAR_STAR '*' +#define T_CHAR_SPACE ' ' +#define T_CHAR_NULL 0 +#define T_CHAR_CR '\r' +#define T_CHAR_TAB '\t' +#define T_CHAR_LF '\n' +#define T_CHAR_SLASH '/' +#define T_CHAR_BACKSLASH '\\' +#define T_CHAR_DOUBLE_QUOTE '"' +#define T_CHAR_LC_X 'x' +#define T_CHAR_0 '0' +#define T_CHAR_STAR '*' =20 // // We keep a linked list of these for the source files we process // typedef struct _SOURCE_FILE { - FILE *Fptr; - CHAR8 *FileBuffer; - CHAR8 *FileBufferPtr; - UINTN FileSize; - CHAR8 FileName[MAX_PATH]; - UINTN LineNum; - BOOLEAN EndOfFile; - BOOLEAN SkipToHash; - struct _SOURCE_FILE *Previous; - struct _SOURCE_FILE *Next; - CHAR8 ControlCharacter; + FILE *Fptr; + CHAR8 *FileBuffer; + CHAR8 *FileBufferPtr; + UINTN FileSize; + CHAR8 FileName[MAX_PATH]; + UINTN LineNum; + BOOLEAN EndOfFile; + BOOLEAN SkipToHash; + struct _SOURCE_FILE *Previous; + struct _SOURCE_FILE *Next; + CHAR8 ControlCharacter; } SOURCE_FILE; =20 typedef struct { - CHAR8 *FileBufferPtr; + CHAR8 *FileBufferPtr; } FILE_POSITION; =20 // // Keep all our module globals in this structure // STATIC struct { - SOURCE_FILE SourceFile; - BOOLEAN VerboseFile; - BOOLEAN VerboseToken; + SOURCE_FILE SourceFile; + BOOLEAN VerboseFile; + BOOLEAN VerboseToken; } mGlobals; =20 STATIC @@ -81,7 +81,7 @@ UINTN t_strncmp ( CHAR8 *Str1, CHAR8 *Str2, - INTN Len + INTN Len ); =20 STATIC @@ -93,31 +93,31 @@ t_strlen ( STATIC VOID RewindFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC BOOLEAN IsWhiteSpace ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC UINTN SkipWhiteSpace ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC BOOLEAN EndOfFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC VOID PreprocessFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC @@ -130,26 +130,26 @@ t_strcpy ( STATIC STATUS ProcessIncludeFile ( - SOURCE_FILE *SourceFile, - SOURCE_FILE *ParentSourceFile + SOURCE_FILE *SourceFile, + SOURCE_FILE *ParentSourceFile ); =20 STATIC STATUS ProcessFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ); =20 STATIC STATUS GetFilePosition ( - FILE_POSITION *Fpos + FILE_POSITION *Fpos ); =20 STATIC STATUS SetFilePosition ( - FILE_POSITION *Fpos + FILE_POSITION *Fpos ); =20 /** @@ -160,7 +160,7 @@ SFPInit ( VOID ) { - memset ((VOID *) &mGlobals, 0, sizeof (mGlobals)); + memset ((VOID *)&mGlobals, 0, sizeof (mGlobals)); return STATUS_SUCCESS; } =20 @@ -204,10 +204,11 @@ SFPGetFileName ( **/ STATUS SFPOpenFile ( - CHAR8 *FileName + CHAR8 *FileName ) { STATUS Status; + t_strcpy (mGlobals.SourceFile.FileName, FileName); Status =3D ProcessIncludeFile (&mGlobals.SourceFile, NULL); return Status; @@ -223,7 +224,7 @@ SFPOpenFile ( is not a subset of some other token. =20 The file pointer is advanced past the token in the input file. -=20 + @param Str the token to look for =20 @retval TRUE the token is next @@ -235,6 +236,7 @@ SFPIsToken ( ) { UINTN Len; + SkipWhiteSpace (&mGlobals.SourceFile); if (EndOfFile (&mGlobals.SourceFile)) { return FALSE; @@ -259,7 +261,7 @@ SFPIsToken ( @note: A keyword is defined as a "special" string that has a non-alphanumeric character following it. -=20 + @param Str keyword to look for =20 @retval TRUE the keyword is next @@ -271,6 +273,7 @@ SFPIsKeyword ( ) { UINTN Len; + SkipWhiteSpace (&mGlobals.SourceFile); if (EndOfFile (&mGlobals.SourceFile)) { return FALSE; @@ -299,7 +302,7 @@ SFPIsKeyword ( Preceding white space is ignored. The parser's buffer pointer is advanced past the end of the token. -=20 + @param Str pointer to a copy of the next token @param Len size of buffer pointed to by Str =20 @@ -319,12 +322,14 @@ SFPGetNextToken ( if (EndOfFile (&mGlobals.SourceFile)) { return FALSE; } + // // Have to have enough string for at least one char and a null-terminator // if (Len < 2) { return FALSE; } + // // Look at the first character. If it's an identifier, then treat it // as such @@ -340,7 +345,8 @@ SFPGetNextToken ( ((TempChar >=3D 'A') && (TempChar <=3D 'Z')) || ((TempChar >=3D '0') && (TempChar <=3D '9')) || (TempChar =3D=3D '_') - ) { + ) + { Str[Index] =3D mGlobals.SourceFile.FileBufferPtr[0]; mGlobals.SourceFile.FileBufferPtr++; Index++; @@ -351,6 +357,7 @@ SFPGetNextToken ( break; } } + // // Null terminate and return success // @@ -380,6 +387,7 @@ SFPGetNextToken ( Index++; } } + // // See if we just ran out of file contents, but did find a token // @@ -403,11 +411,12 @@ SFPGetNextToken ( **/ BOOLEAN SFPGetGuidToken ( - CHAR8 *Str, - UINT32 Len + CHAR8 *Str, + UINT32 Len ) { UINT32 Index; + SkipWhiteSpace (&mGlobals.SourceFile); if (EndOfFile (&mGlobals.SourceFile)) { return FALSE; @@ -438,7 +447,8 @@ SFPSkipToToken ( ) { UINTN Len; - CHAR8 *SavePos; + CHAR8 *SavePos; + Len =3D t_strlen (Str); SavePos =3D mGlobals.SourceFile.FileBufferPtr; SkipWhiteSpace (&mGlobals.SourceFile); @@ -467,10 +477,10 @@ SFPSkipToToken ( **/ BOOLEAN SFPGetNumber ( - UINTN *Value + UINTN *Value ) { - int Val; + int Val; =20 SkipWhiteSpace (&mGlobals.SourceFile); if (EndOfFile (&mGlobals.SourceFile)) { @@ -488,7 +498,7 @@ SFPGetNumber ( =20 mGlobals.SourceFile.FileBufferPtr +=3D 2; sscanf (mGlobals.SourceFile.FileBufferPtr, "%x", &Val); - *Value =3D (UINT32) Val; + *Value =3D (UINT32)Val; while (isxdigit ((int)mGlobals.SourceFile.FileBufferPtr[0])) { mGlobals.SourceFile.FileBufferPtr++; } @@ -538,13 +548,13 @@ SFPCloseFile ( STATIC STATUS ProcessIncludeFile ( - SOURCE_FILE *SourceFile, - SOURCE_FILE *ParentSourceFile + SOURCE_FILE *SourceFile, + SOURCE_FILE *ParentSourceFile ) { - STATIC UINTN NestDepth =3D 0; - CHAR8 FoundFileName[MAX_PATH]; - STATUS Status; + STATIC UINTN NestDepth =3D 0; + CHAR8 FoundFileName[MAX_PATH]; + STATUS Status; =20 Status =3D STATUS_SUCCESS; NestDepth++; @@ -561,10 +571,11 @@ ProcessIncludeFile ( // Make sure we didn't exceed our maximum nesting depth // if (NestDepth > MAX_NEST_DEPTH) { - Error (NULL, 0, 3001, "Not Supported", "%s exceeds max nesting depth (= %u)", SourceFile->FileName, (unsigned) NestDepth); + Error (NULL, 0, 3001, "Not Supported", "%s exceeds max nesting depth (= %u)", SourceFile->FileName, (unsigned)NestDepth); Status =3D STATUS_ERROR; goto Finish; } + // // Try to open the file locally, and if that fails try along our include= paths. // @@ -572,6 +583,7 @@ ProcessIncludeFile ( if ((SourceFile->Fptr =3D fopen (LongFilePath (FoundFileName), "rb")) = =3D=3D NULL) { return STATUS_ERROR; } + // // Process the file found // @@ -599,7 +611,7 @@ ProcessIncludeFile ( STATIC STATUS ProcessFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { // @@ -609,18 +621,18 @@ ProcessFile ( fseek (SourceFile->Fptr, 0, SEEK_END); SourceFile->FileSize =3D ftell (SourceFile->Fptr); if (mGlobals.VerboseFile) { - printf ("FileSize =3D %u (0x%X)\n", (unsigned) SourceFile->FileSize, (= unsigned) SourceFile->FileSize); + printf ("FileSize =3D %u (0x%X)\n", (unsigned)SourceFile->FileSize, (u= nsigned)SourceFile->FileSize); } =20 fseek (SourceFile->Fptr, 0, SEEK_SET); - SourceFile->FileBuffer =3D (CHAR8 *) malloc (SourceFile->FileSize + siz= eof (CHAR8 )); + SourceFile->FileBuffer =3D (CHAR8 *)malloc (SourceFile->FileSize + size= of (CHAR8)); if (SourceFile->FileBuffer =3D=3D NULL) { Error (NULL, 0, 4001, "Resource: memory cannot be allocated", NULL); return STATUS_ERROR; } =20 - fread ((VOID *) SourceFile->FileBuffer, SourceFile->FileSize, 1, SourceF= ile->Fptr); - SourceFile->FileBuffer[(SourceFile->FileSize / sizeof (CHAR8 ))] =3D T_C= HAR_NULL; + fread ((VOID *)SourceFile->FileBuffer, SourceFile->FileSize, 1, SourceFi= le->Fptr); + SourceFile->FileBuffer[(SourceFile->FileSize / sizeof (CHAR8))] =3D T_CH= AR_NULL; // // Pre-process the file to replace comments with spaces // @@ -638,12 +650,12 @@ ProcessFile ( STATIC VOID PreprocessFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { - BOOLEAN InComment; - BOOLEAN SlashSlashComment; - int LineNum; + BOOLEAN InComment; + BOOLEAN SlashSlashComment; + int LineNum; =20 RewindFile (SourceFile); InComment =3D FALSE; @@ -669,10 +681,11 @@ PreprocessFile ( // Check for */ comment end // } else if (InComment && - !SlashSlashComment && - (SourceFile->FileBufferPtr[0] =3D=3D T_CHAR_STAR) && - (SourceFile->FileBufferPtr[1] =3D=3D T_CHAR_SLASH) - ) { + !SlashSlashComment && + (SourceFile->FileBufferPtr[0] =3D=3D T_CHAR_STAR) && + (SourceFile->FileBufferPtr[1] =3D=3D T_CHAR_SLASH) + ) + { SourceFile->FileBufferPtr[0] =3D T_CHAR_SPACE; SourceFile->FileBufferPtr++; SourceFile->FileBufferPtr[0] =3D T_CHAR_SPACE; @@ -701,6 +714,7 @@ PreprocessFile ( SourceFile->FileBufferPtr++; } } + // // Could check for end-of-file and still in a comment, but // should not be necessary. So just restore the file pointers. @@ -740,8 +754,8 @@ PreprocessFile ( **/ BOOLEAN SFPGetQuotedString ( - CHAR8 *Str, - INTN Length + CHAR8 *Str, + INTN Length ) { SkipWhiteSpace (&mGlobals.SourceFile); @@ -755,6 +769,7 @@ SFPGetQuotedString ( if (EndOfFile (&mGlobals.SourceFile)) { return FALSE; } + // // Check for closing quote // @@ -770,6 +785,7 @@ SFPGetQuotedString ( mGlobals.SourceFile.FileBufferPtr++; } } + // // First character was not a quote, or the input string length was // insufficient to contain the quoted string, so return failure code. @@ -797,15 +813,15 @@ SFPIsEOF ( STATIC CHAR8 * GetQuotedString ( - SOURCE_FILE *SourceFile, - BOOLEAN Optional + SOURCE_FILE *SourceFile, + BOOLEAN Optional ) { - CHAR8 *String; - CHAR8 *Start; - CHAR8 *Ptr; - UINTN Len; - BOOLEAN PreviousBackslash; + CHAR8 *String; + CHAR8 *Start; + CHAR8 *Ptr; + UINTN Len; + BOOLEAN PreviousBackslash; =20 if (SourceFile->FileBufferPtr[0] !=3D T_CHAR_DOUBLE_QUOTE) { if (Optional =3D=3D FALSE) { @@ -840,14 +856,16 @@ GetQuotedString ( } else { SourceFile->FileBufferPtr++; } + // // Now allocate memory for the string and save it off // - String =3D (CHAR8 *) malloc ((Len + 1) * sizeof (CHAR8 )); + String =3D (CHAR8 *)malloc ((Len + 1) * sizeof (CHAR8)); if (String =3D=3D NULL) { Error (NULL, 0, 4001, "Resource: memory cannot be allocated", NULL); return NULL; } + // // Copy the string from the file buffer to the local copy. // We do no reformatting of it whatsoever at this point. @@ -863,18 +881,19 @@ GetQuotedString ( *Ptr =3D 0; return String; } + #endif STATIC BOOLEAN EndOfFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { // // The file buffer pointer will typically get updated before the End-of-= file flag in the // source file structure, so check it first. // - if (SourceFile->FileBufferPtr >=3D SourceFile->FileBuffer + SourceFile->= FileSize / sizeof (CHAR8 )) { + if (SourceFile->FileBufferPtr >=3D SourceFile->FileBuffer + SourceFile->= FileSize / sizeof (CHAR8)) { SourceFile->EndOfFile =3D TRUE; return TRUE; } @@ -890,19 +909,20 @@ EndOfFile ( STATIC VOID ProcessTokenInclude ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { - CHAR8 IncludeFileName[MAX_PATH]; - CHAR8 *To; - UINTN Len; - BOOLEAN ReportedError; - SOURCE_FILE IncludedSourceFile; + CHAR8 IncludeFileName[MAX_PATH]; + CHAR8 *To; + UINTN Len; + BOOLEAN ReportedError; + SOURCE_FILE IncludedSourceFile; =20 ReportedError =3D FALSE; if (SkipWhiteSpace (SourceFile) =3D=3D 0) { Warning (SourceFile->FileName, SourceFile->LineNum, 0, "expected white= space following #include keyword", NULL); } + // // Should be quoted file name // @@ -927,6 +947,7 @@ ProcessTokenInclude ( SourceFile->FileBufferPtr++; break; } + // // If too long, then report the error once and process until the closi= ng quote // @@ -937,7 +958,7 @@ ProcessTokenInclude ( } =20 if (!ReportedError) { - *To =3D (CHAR8 ) SourceFile->FileBufferPtr[0]; + *To =3D (CHAR8)SourceFile->FileBufferPtr[0]; To++; } =20 @@ -946,65 +967,67 @@ ProcessTokenInclude ( =20 if (!ReportedError) { *To =3D 0; - memset ((CHAR8 *) &IncludedSourceFile, 0, sizeof (SOURCE_FILE)); + memset ((CHAR8 *)&IncludedSourceFile, 0, sizeof (SOURCE_FILE)); strcpy (IncludedSourceFile.FileName, IncludeFileName); ProcessIncludeFile (&IncludedSourceFile, SourceFile); } =20 - return ; + return; FailDone: // // Error recovery -- skip to next # // SourceFile->SkipToHash =3D TRUE; } + #endif STATIC BOOLEAN IsWhiteSpace ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { switch (*SourceFile->FileBufferPtr) { - case T_CHAR_NULL: - case T_CHAR_CR: - case T_CHAR_SPACE: - case T_CHAR_TAB: - case T_CHAR_LF: - return TRUE; - - default: - return FALSE; - } -} - -UINTN -SkipWhiteSpace ( - SOURCE_FILE *SourceFile - ) -{ - UINTN Count; - - Count =3D 0; - while (!EndOfFile (SourceFile)) { - Count++; - switch (*SourceFile->FileBufferPtr) { case T_CHAR_NULL: case T_CHAR_CR: case T_CHAR_SPACE: case T_CHAR_TAB: - SourceFile->FileBufferPtr++; - break; - case T_CHAR_LF: - SourceFile->FileBufferPtr++; - SourceFile->LineNum++; - break; + return TRUE; =20 default: - return Count - 1; + return FALSE; + } +} + +UINTN +SkipWhiteSpace ( + SOURCE_FILE *SourceFile + ) +{ + UINTN Count; + + Count =3D 0; + while (!EndOfFile (SourceFile)) { + Count++; + switch (*SourceFile->FileBufferPtr) { + case T_CHAR_NULL: + case T_CHAR_CR: + case T_CHAR_SPACE: + case T_CHAR_TAB: + SourceFile->FileBufferPtr++; + break; + + case T_CHAR_LF: + SourceFile->FileBufferPtr++; + SourceFile->LineNum++; + break; + + default: + return Count - 1; } } + // // Some tokens require trailing whitespace. If we're at the end of the // file, then we count that as well. @@ -1056,6 +1079,7 @@ t_strlen ( ) { UINTN Len; + Len =3D 0; while (*Str) { Len++; @@ -1070,7 +1094,7 @@ UINTN t_strncmp ( CHAR8 *Str1, CHAR8 *Str2, - INTN Len + INTN Len ) { while (Len > 0) { @@ -1093,7 +1117,8 @@ t_strcpy ( CHAR8 *Src ) { - CHAR8 *SaveDest; + CHAR8 *SaveDest; + SaveDest =3D Dest; while (*Src) { *Dest =3D *Src; @@ -1108,7 +1133,7 @@ t_strcpy ( STATIC VOID RewindFile ( - SOURCE_FILE *SourceFile + SOURCE_FILE *SourceFile ) { SourceFile->LineNum =3D 1; @@ -1119,11 +1144,12 @@ RewindFile ( STATIC UINT32 GetHexChars ( - CHAR8 *Buffer, - UINT32 BufferLen + CHAR8 *Buffer, + UINT32 BufferLen ) { UINT32 Len; + Len =3D 0; while (!EndOfFile (&mGlobals.SourceFile) && (Len < BufferLen)) { if (isxdigit ((int)mGlobals.SourceFile.FileBufferPtr[0])) { @@ -1134,6 +1160,7 @@ GetHexChars ( break; } } + // // Null terminate if we can // @@ -1158,19 +1185,19 @@ GetHexChars ( **/ BOOLEAN SFPGetGuid ( - INTN GuidStyle, - EFI_GUID *Value + INTN GuidStyle, + EFI_GUID *Value ) { - INT32 Value32; - UINT32 Index; - FILE_POSITION FPos; - CHAR8 TempString[20]; - CHAR8 TempString2[3]; - CHAR8 *From; - CHAR8 *To; - UINT32 Len; - BOOLEAN Status; + INT32 Value32; + UINT32 Index; + FILE_POSITION FPos; + CHAR8 TempString[20]; + CHAR8 TempString2[3]; + CHAR8 *From; + CHAR8 *To; + UINT32 Len; + BOOLEAN Status; =20 Status =3D FALSE; // @@ -1207,7 +1234,7 @@ SFPGetGuid ( } =20 sscanf (TempString, "%x", &Value32); - Value->Data2 =3D (UINT16) Value32; + Value->Data2 =3D (UINT16)Value32; =20 if (mGlobals.SourceFile.FileBufferPtr[0] !=3D '-') { goto Done; @@ -1220,7 +1247,7 @@ SFPGetGuid ( } =20 sscanf (TempString, "%x", &Value32); - Value->Data3 =3D (UINT16) Value32; + Value->Data3 =3D (UINT16)Value32; // // Parse the "AAAA" as two bytes // @@ -1235,8 +1262,8 @@ SFPGetGuid ( } =20 sscanf (TempString, "%x", &Value32); - Value->Data4[0] =3D (UINT8) (Value32 >> 8); - Value->Data4[1] =3D (UINT8) Value32; + Value->Data4[0] =3D (UINT8)(Value32 >> 8); + Value->Data4[1] =3D (UINT8)Value32; if (mGlobals.SourceFile.FileBufferPtr[0] !=3D '-') { goto Done; } @@ -1250,13 +1277,14 @@ SFPGetGuid ( if ((Len =3D=3D 0) || (Len > 12)) { goto Done; } + // // Insert leading 0's to make life easier // if (Len !=3D 12) { - From =3D TempString + Len - 1; - To =3D TempString + 11; - TempString[12] =3D 0; + From =3D TempString + Len - 1; + To =3D TempString + 11; + TempString[12] =3D 0; while (From >=3D TempString) { *To =3D *From; To--; @@ -1268,6 +1296,7 @@ SFPGetGuid ( To--; } } + // // Now parse each byte // @@ -1277,10 +1306,10 @@ SFPGetGuid ( // Copy the two characters from the input string to something // we can parse. // - TempString2[0] =3D TempString[Index * 2]; - TempString2[1] =3D TempString[Index * 2 + 1]; + TempString2[0] =3D TempString[Index * 2]; + TempString2[1] =3D TempString[Index * 2 + 1]; sscanf (TempString2, "%x", &Value32); - Value->Data4[Index + 2] =3D (UINT8) Value32; + Value->Data4[Index + 2] =3D (UINT8)Value32; } =20 Status =3D TRUE; @@ -1302,7 +1331,7 @@ SFPGetGuid ( STATIC STATUS GetFilePosition ( - FILE_POSITION *Fpos + FILE_POSITION *Fpos ) { Fpos->FileBufferPtr =3D mGlobals.SourceFile.FileBufferPtr; @@ -1312,7 +1341,7 @@ GetFilePosition ( STATIC STATUS SetFilePosition ( - FILE_POSITION *Fpos + FILE_POSITION *Fpos ) { // diff --git a/BaseTools/Source/C/Common/StringFuncs.c b/BaseTools/Source/C/C= ommon/StringFuncs.c index bc85ba012440..b39b907a9571 100644 --- a/BaseTools/Source/C/Common/StringFuncs.c +++ b/BaseTools/Source/C/Common/StringFuncs.c @@ -21,12 +21,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 @return CHAR8* - NULL if there are not enough resources **/ -CHAR8* +CHAR8 * CloneString ( - IN CHAR8 *String + IN CHAR8 *String ) { - CHAR8* NewString; + CHAR8 *NewString; =20 NewString =3D malloc (strlen (String) + 1); if (NewString !=3D NULL) { @@ -45,10 +45,10 @@ CloneString ( **/ EFI_STATUS StripInfDscStringInPlace ( - IN CHAR8 *String + IN CHAR8 *String ) { - CHAR8 *Pos; + CHAR8 *Pos; =20 if (String =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -59,6 +59,7 @@ StripInfDscStringInPlace ( // for (Pos =3D String; isspace ((int)*Pos); Pos++) { } + if (Pos !=3D String) { memmove (String, Pos, strlen (Pos) + 1); } @@ -70,12 +71,12 @@ StripInfDscStringInPlace ( // What about multiline comments? // =20 - Pos =3D (CHAR8 *) strstr (String, "//"); + Pos =3D (CHAR8 *)strstr (String, "//"); if (Pos !=3D NULL) { *Pos =3D '\0'; } =20 - Pos =3D (CHAR8 *) strchr (String, '#'); + Pos =3D (CHAR8 *)strchr (String, '#'); if (Pos !=3D NULL) { *Pos =3D '\0'; } @@ -86,8 +87,10 @@ StripInfDscStringInPlace ( for (Pos =3D String + strlen (String); ((Pos - 1) >=3D String) && (isspace ((int)*(Pos - 1))); Pos-- - ) { + ) + { } + *Pos =3D '\0'; =20 return EFI_SUCCESS; @@ -101,21 +104,22 @@ StripInfDscStringInPlace ( =20 @return EFI_STATUS **/ -STRING_LIST* +STRING_LIST * SplitStringByWhitespace ( - IN CHAR8 *String + IN CHAR8 *String ) { - CHAR8 *Pos; - CHAR8 *EndOfSubString; - CHAR8 *EndOfString; - STRING_LIST *Output; - UINTN Item; + CHAR8 *Pos; + CHAR8 *EndOfSubString; + CHAR8 *EndOfString; + STRING_LIST *Output; + UINTN Item; =20 String =3D CloneString (String); if (String =3D=3D NULL) { return NULL; } + EndOfString =3D String + strlen (String); =20 Output =3D NewStringList (); @@ -125,10 +129,11 @@ SplitStringByWhitespace ( Pos++; } =20 - for (EndOfSubString=3DPos; + for (EndOfSubString =3D Pos; (*EndOfSubString !=3D '\0') && !isspace ((int)*EndOfSubString); EndOfSubString++ - ) { + ) + { } =20 if (EndOfSubString =3D=3D Pos) { @@ -151,15 +156,17 @@ SplitStringByWhitespace ( =20 @return STRING_LIST* - Null if there is not enough resources to create t= he object. **/ -STRING_LIST* +STRING_LIST * NewStringList ( ) { - STRING_LIST *NewList; + STRING_LIST *NewList; + NewList =3D AllocateStringListStruct (0); if (NewList !=3D NULL) { NewList->Count =3D 0; } + return NewList; } =20 @@ -171,13 +178,13 @@ NewStringList ( **/ EFI_STATUS AppendCopyOfStringToList ( - IN OUT STRING_LIST **StringList, - IN CHAR8 *String + IN OUT STRING_LIST **StringList, + IN CHAR8 *String ) { - STRING_LIST *OldList; - STRING_LIST *NewList; - CHAR8 *NewString; + STRING_LIST *OldList; + STRING_LIST *NewList; + CHAR8 *NewString; =20 OldList =3D *StringList; NewList =3D AllocateStringListStruct (OldList->Count + 1); @@ -196,7 +203,7 @@ AppendCopyOfStringToList ( OldList->Strings, sizeof (OldList->Strings[0]) * OldList->Count ); - NewList->Count =3D OldList->Count + 1; + NewList->Count =3D OldList->Count + 1; NewList->Strings[OldList->Count] =3D NewString; =20 *StringList =3D NewList; @@ -215,7 +222,7 @@ AppendCopyOfStringToList ( **/ EFI_STATUS RemoveLastStringFromList ( - IN STRING_LIST *StringList + IN STRING_LIST *StringList ) { if (StringList->Count =3D=3D 0) { @@ -234,12 +241,12 @@ RemoveLastStringFromList ( =20 @return EFI_STATUS **/ -STRING_LIST* +STRING_LIST * AllocateStringListStruct ( - IN UINTN StringCount + IN UINTN StringCount ) { - return malloc (OFFSET_OF(STRING_LIST, Strings[StringCount + 1])); + return malloc (OFFSET_OF (STRING_LIST, Strings[StringCount + 1])); } =20 /** @@ -249,7 +256,7 @@ AllocateStringListStruct ( **/ VOID FreeStringList ( - IN STRING_LIST *StringList + IN STRING_LIST *StringList ) { while (StringList->Count > 0) { @@ -267,20 +274,21 @@ FreeStringList ( @return CHAR8* - The string list represented with a single string. The = returned string must be freed by the caller. **/ -CHAR8* +CHAR8 * StringListToString ( - IN STRING_LIST *StringList + IN STRING_LIST *StringList ) { - UINTN Count; - UINTN Length; - CHAR8 *NewString; + UINTN Count; + UINTN Length; + CHAR8 *NewString; =20 Length =3D 2; for (Count =3D 0; Count < StringList->Count; Count++) { if (Count > 0) { Length +=3D 2; } + Length +=3D strlen (StringList->Strings[Count]) + 2; } =20 @@ -288,6 +296,7 @@ StringListToString ( if (NewString =3D=3D NULL) { return NewString; } + NewString[0] =3D '\0'; =20 strcat (NewString, "["); @@ -295,10 +304,12 @@ StringListToString ( if (Count > 0) { strcat (NewString, ", "); } + strcat (NewString, "\""); strcat (NewString, StringList->Strings[Count]); strcat (NewString, "\""); } + strcat (NewString, "]"); =20 return NewString; @@ -308,20 +319,19 @@ StringListToString ( Prints out the string list =20 @param StringList The string list to print -=20 + @return EFI_STATUS **/ VOID PrintStringList ( - IN STRING_LIST *StringList + IN STRING_LIST *StringList ) { - CHAR8* String; + CHAR8 *String; + String =3D StringListToString (StringList); if (String !=3D NULL) { printf ("%s", String); free (String); } } - - diff --git a/BaseTools/Source/C/Common/TianoCompress.c b/BaseTools/Source/C= /Common/TianoCompress.c index 2f484b9731dc..5df6947258d7 100644 --- a/BaseTools/Source/C/Common/TianoCompress.c +++ b/BaseTools/Source/C/Common/TianoCompress.c @@ -28,9 +28,9 @@ typedef INT32 NODE; #define CODE_BIT 16 #define NIL 0 #define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX) -#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2) -#define CRCPOLY 0xA001 -#define UPDATE_CRC(c) mCrc =3D mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> U= INT8_BIT) +#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2) +#define CRCPOLY 0xA001 +#define UPDATE_CRC(c) mCrc =3D mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> = UINT8_BIT) =20 // // C: the Char&Len Set; P: the Position Set; T: the exTra Set @@ -42,9 +42,9 @@ typedef INT32 NODE; #define NT (CODE_BIT + 3) #define TBIT 5 #if NT > NP -#define NPT NT +#define NPT NT #else -#define NPT NP +#define NPT NP #endif // // Function Prototypes @@ -52,8 +52,8 @@ typedef INT32 NODE; =20 STATIC VOID -PutDword( - IN UINT32 Data +PutDword ( + IN UINT32 Data ); =20 STATIC @@ -84,15 +84,15 @@ Child ( STATIC VOID MakeChild ( - IN NODE NodeQ, - IN UINT8 CharC, - IN NODE NodeR + IN NODE NodeQ, + IN UINT8 CharC, + IN NODE NodeR ); =20 STATIC VOID Split ( - IN NODE Old + IN NODE Old ); =20 STATIC @@ -128,9 +128,9 @@ CountTFreq ( STATIC VOID WritePTLen ( - IN INT32 Number, - IN INT32 nbit, - IN INT32 Special + IN INT32 Number, + IN INT32 nbit, + IN INT32 Special ); =20 STATIC @@ -142,13 +142,13 @@ WriteCLen ( STATIC VOID EncodeC ( - IN INT32 Value + IN INT32 Value ); =20 STATIC VOID EncodeP ( - IN UINT32 Value + IN UINT32 Value ); =20 STATIC @@ -160,8 +160,8 @@ SendBlock ( STATIC VOID Output ( - IN UINT32 c, - IN UINT32 p + IN UINT32 c, + IN UINT32 p ); =20 STATIC @@ -185,15 +185,15 @@ MakeCrcTable ( STATIC VOID PutBits ( - IN INT32 Number, - IN UINT32 Value + IN INT32 Number, + IN UINT32 Value ); =20 STATIC INT32 FreadCrc ( - OUT UINT8 *Pointer, - IN INT32 Number + OUT UINT8 *Pointer, + IN INT32 Number ); =20 STATIC @@ -205,35 +205,35 @@ InitPutBits ( STATIC VOID CountLen ( - IN INT32 Index + IN INT32 Index ); =20 STATIC VOID MakeLen ( - IN INT32 Root + IN INT32 Root ); =20 STATIC VOID DownHeap ( - IN INT32 Index + IN INT32 Index ); =20 STATIC VOID MakeCode ( - IN INT32 Number, - IN UINT8 Len[ ], - OUT UINT16 Code[] + IN INT32 Number, + IN UINT8 Len[], + OUT UINT16 Code[] ); =20 STATIC INT32 MakeTree ( - IN INT32 NParm, + IN INT32 NParm, IN UINT16 FreqParm[], - OUT UINT8 LenParm[ ], + OUT UINT8 LenParm[], OUT UINT16 CodeParm[] ); =20 @@ -242,16 +242,16 @@ MakeTree ( // STATIC UINT8 *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit; =20 -STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT]= , *mLen; -STATIC INT16 mHeap[NC + 1]; -STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN; -STATIC UINT32 mBufSiz =3D 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc; -STATIC UINT32 mCompSize, mOrigSize; +STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT= ], *mLen; +STATIC INT16 mHeap[NC + 1]; +STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN; +STATIC UINT32 mBufSiz =3D 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc; +STATIC UINT32 mCompSize, mOrigSize; =20 -STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2 = * NC - 1], mCrcTable[UINT8_MAX + 1], - mCFreq[2 * NC - 1], mCCode[NC], mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq= [2 * NT - 1]; +STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2= * NC - 1], mCrcTable[UINT8_MAX + 1], + mCFreq[2 * NC - 1], mCCode[NC], mPFreq[2 * NP - 1], mPTCode= [NPT], mTFreq[2 * NT - 1]; =20 -STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNex= t =3D NULL; +STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNext= =3D NULL; =20 // // functions @@ -288,28 +288,28 @@ TianoCompress ( // // Initializations // - mBufSiz =3D 0; - mBuf =3D NULL; - mText =3D NULL; - mLevel =3D NULL; - mChildCount =3D NULL; - mPosition =3D NULL; - mParent =3D NULL; - mPrev =3D NULL; - mNext =3D NULL; + mBufSiz =3D 0; + mBuf =3D NULL; + mText =3D NULL; + mLevel =3D NULL; + mChildCount =3D NULL; + mPosition =3D NULL; + mParent =3D NULL; + mPrev =3D NULL; + mNext =3D NULL; =20 - mSrc =3D SrcBuffer; - mSrcUpperLimit =3D mSrc + SrcSize; - mDst =3D DstBuffer; - mDstUpperLimit =3D mDst +*DstSize; + mSrc =3D SrcBuffer; + mSrcUpperLimit =3D mSrc + SrcSize; + mDst =3D DstBuffer; + mDstUpperLimit =3D mDst +*DstSize; =20 PutDword (0L); PutDword (0L); =20 MakeCrcTable (); =20 - mOrigSize =3D mCompSize =3D 0; - mCrc =3D INIT_CRC; + mOrigSize =3D mCompSize =3D 0; + mCrc =3D INIT_CRC; =20 // // Compress it @@ -318,12 +318,14 @@ TianoCompress ( if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } + // // Null terminate the compressed data // if (mDst < mDstUpperLimit) { *mDst++ =3D 0; } + // // Fill in compressed size and original size // @@ -341,7 +343,6 @@ TianoCompress ( *DstSize =3D mCompSize + 1 + 8; return EFI_SUCCESS; } - } =20 /** @@ -352,23 +353,23 @@ TianoCompress ( STATIC VOID PutDword ( - IN UINT32 Data + IN UINT32 Data ) { if (mDst < mDstUpperLimit) { - *mDst++ =3D (UINT8) (((UINT8) (Data)) & 0xff); + *mDst++ =3D (UINT8)(((UINT8)(Data)) & 0xff); } =20 if (mDst < mDstUpperLimit) { - *mDst++ =3D (UINT8) (((UINT8) (Data >> 0x08)) & 0xff); + *mDst++ =3D (UINT8)(((UINT8)(Data >> 0x08)) & 0xff); } =20 if (mDst < mDstUpperLimit) { - *mDst++ =3D (UINT8) (((UINT8) (Data >> 0x10)) & 0xff); + *mDst++ =3D (UINT8)(((UINT8)(Data >> 0x10)) & 0xff); } =20 if (mDst < mDstUpperLimit) { - *mDst++ =3D (UINT8) (((UINT8) (Data >> 0x18)) & 0xff); + *mDst++ =3D (UINT8)(((UINT8)(Data >> 0x18)) & 0xff); } } =20 @@ -390,6 +391,7 @@ AllocateMemory ( if (mText =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } + for (Index =3D 0; Index < WNDSIZ * 2 + MAXMATCH; Index++) { mText[Index] =3D 0; } @@ -400,13 +402,14 @@ AllocateMemory ( mParent =3D malloc (WNDSIZ * 2 * sizeof (*mParent)); mPrev =3D malloc (WNDSIZ * 2 * sizeof (*mPrev)); mNext =3D malloc ((MAX_HASH_VAL + 1) * sizeof (*mNext)); - if (mLevel =3D=3D NULL || mChildCount =3D=3D NULL || mPosition =3D=3D NU= LL || - mParent =3D=3D NULL || mPrev =3D=3D NULL || mNext =3D=3D NULL) { + if ((mLevel =3D=3D NULL) || (mChildCount =3D=3D NULL) || (mPosition =3D= =3D NULL) || + (mParent =3D=3D NULL) || (mPrev =3D=3D NULL) || (mNext =3D=3D NULL)) + { return EFI_OUT_OF_RESOURCES; } =20 - mBufSiz =3D BLKSIZ; - mBuf =3D malloc (mBufSiz); + mBufSiz =3D BLKSIZ; + mBuf =3D malloc (mBufSiz); while (mBuf =3D=3D NULL) { mBufSiz =3D (mBufSiz / 10U) * 9U; if (mBufSiz < 4 * 1024U) { @@ -461,7 +464,7 @@ FreeMemory ( free (mBuf); } =20 - return ; + return; } =20 /** @@ -476,8 +479,8 @@ InitSlide ( NODE Index; =20 for (Index =3D WNDSIZ; Index <=3D WNDSIZ + UINT8_MAX; Index++) { - mLevel[Index] =3D 1; - mPosition[Index] =3D NIL; /* sentinel */ + mLevel[Index] =3D 1; + mPosition[Index] =3D NIL; /* sentinel */ } =20 for (Index =3D WNDSIZ; Index < WNDSIZ * 2; Index++) { @@ -486,7 +489,7 @@ InitSlide ( =20 mAvail =3D 1; for (Index =3D 1; Index < WNDSIZ - 1; Index++) { - mNext[Index] =3D (NODE) (Index + 1); + mNext[Index] =3D (NODE)(Index + 1); } =20 mNext[WNDSIZ - 1] =3D NIL; @@ -506,8 +509,8 @@ InitSlide ( STATIC NODE Child ( - IN NODE NodeQ, - IN UINT8 CharC + IN NODE NodeQ, + IN UINT8 CharC ) { NODE NodeR; @@ -534,21 +537,21 @@ Child ( STATIC VOID MakeChild ( - IN NODE Parent, - IN UINT8 CharC, - IN NODE Child + IN NODE Parent, + IN UINT8 CharC, + IN NODE Child ) { NODE Node1; NODE Node2; =20 - Node1 =3D (NODE) HASH (Parent, CharC); - Node2 =3D mNext[Node1]; - mNext[Node1] =3D Child; - mNext[Child] =3D Node2; - mPrev[Node2] =3D Child; - mPrev[Child] =3D Node1; - mParent[Child] =3D Parent; + Node1 =3D (NODE)HASH (Parent, CharC); + Node2 =3D mNext[Node1]; + mNext[Node1] =3D Child; + mNext[Child] =3D Node2; + mPrev[Node2] =3D Child; + mPrev[Child] =3D Node1; + mParent[Child] =3D Parent; mChildCount[Parent]++; } =20 @@ -560,24 +563,24 @@ MakeChild ( STATIC VOID Split ( - NODE Old + NODE Old ) { NODE New; NODE TempNode; =20 - New =3D mAvail; - mAvail =3D mNext[New]; - mChildCount[New] =3D 0; - TempNode =3D mPrev[Old]; - mPrev[New] =3D TempNode; - mNext[TempNode] =3D New; - TempNode =3D mNext[Old]; - mNext[New] =3D TempNode; - mPrev[TempNode] =3D New; - mParent[New] =3D mParent[Old]; - mLevel[New] =3D (UINT8) mMatchLen; - mPosition[New] =3D mPos; + New =3D mAvail; + mAvail =3D mNext[New]; + mChildCount[New] =3D 0; + TempNode =3D mPrev[Old]; + mPrev[New] =3D TempNode; + mNext[TempNode] =3D New; + TempNode =3D mNext[Old]; + mNext[New] =3D TempNode; + mPrev[TempNode] =3D New; + mParent[New] =3D mParent[Old]; + mLevel[New] =3D (UINT8)mMatchLen; + mPosition[New] =3D mPos; MakeChild (New, mText[mMatchPos + mMatchLen], Old); MakeChild (New, mText[mPos + mMatchLen], mPos); } @@ -591,13 +594,13 @@ InsertNode ( VOID ) { - NODE NodeQ; - NODE NodeR; - NODE Index2; - NODE NodeT; - UINT8 CharC; - UINT8 *t1; - UINT8 *t2; + NODE NodeQ; + NODE NodeR; + NODE Index2; + NODE NodeT; + UINT8 CharC; + UINT8 *t1; + UINT8 *t2; =20 if (mMatchLen >=3D 4) { // @@ -608,7 +611,7 @@ InsertNode ( // in DeleteNode() later. // mMatchLen--; - NodeR =3D (NODE) ((mMatchPos + 1) | WNDSIZ); + NodeR =3D (NODE)((mMatchPos + 1) | WNDSIZ); NodeQ =3D mParent[NodeR]; while (NodeQ =3D=3D NIL) { NodeR =3D mNext[NodeR]; @@ -622,52 +625,53 @@ InsertNode ( =20 NodeT =3D NodeQ; while (mPosition[NodeT] < 0) { - mPosition[NodeT] =3D mPos; - NodeT =3D mParent[NodeT]; + mPosition[NodeT] =3D mPos; + NodeT =3D mParent[NodeT]; } =20 if (NodeT < WNDSIZ) { - mPosition[NodeT] =3D (NODE) (mPos | (UINT32) PERC_FLAG); + mPosition[NodeT] =3D (NODE)(mPos | (UINT32)PERC_FLAG); } } else { // // Locate the target tree // - NodeQ =3D (NODE) (mText[mPos] + WNDSIZ); + NodeQ =3D (NODE)(mText[mPos] + WNDSIZ); CharC =3D mText[mPos + 1]; NodeR =3D Child (NodeQ, CharC); if (NodeR =3D=3D NIL) { MakeChild (NodeQ, CharC, mPos); mMatchLen =3D 1; - return ; + return; } =20 mMatchLen =3D 2; } + // // Traverse down the tree to find a match. // Update Position value along the route. // Node split or creation is involved. // - for (;;) { + for ( ; ;) { if (NodeR >=3D WNDSIZ) { Index2 =3D MAXMATCH; mMatchPos =3D NodeR; } else { Index2 =3D mLevel[NodeR]; - mMatchPos =3D (NODE) (mPosition[NodeR] & (UINT32)~PERC_FLAG); + mMatchPos =3D (NODE)(mPosition[NodeR] & (UINT32) ~PERC_FLAG); } =20 if (mMatchPos >=3D mPos) { mMatchPos -=3D WNDSIZ; } =20 - t1 =3D &mText[mPos + mMatchLen]; - t2 =3D &mText[mMatchPos + mMatchLen]; + t1 =3D &mText[mPos + mMatchLen]; + t2 =3D &mText[mMatchPos + mMatchLen]; while (mMatchLen < Index2) { if (*t1 !=3D *t2) { Split (NodeR); - return ; + return; } =20 mMatchLen++; @@ -679,31 +683,30 @@ InsertNode ( break; } =20 - mPosition[NodeR] =3D mPos; - NodeQ =3D NodeR; - NodeR =3D Child (NodeQ, *t1); + mPosition[NodeR] =3D mPos; + NodeQ =3D NodeR; + NodeR =3D Child (NodeQ, *t1); if (NodeR =3D=3D NIL) { MakeChild (NodeQ, *t1, mPos); - return ; + return; } =20 mMatchLen++; } =20 - NodeT =3D mPrev[NodeR]; - mPrev[mPos] =3D NodeT; - mNext[NodeT] =3D mPos; - NodeT =3D mNext[NodeR]; - mNext[mPos] =3D NodeT; - mPrev[NodeT] =3D mPos; - mParent[mPos] =3D NodeQ; - mParent[NodeR] =3D NIL; + NodeT =3D mPrev[NodeR]; + mPrev[mPos] =3D NodeT; + mNext[NodeT] =3D mPos; + NodeT =3D mNext[NodeR]; + mNext[mPos] =3D NodeT; + mPrev[NodeT] =3D mPos; + mParent[mPos] =3D NodeQ; + mParent[NodeR] =3D NIL; =20 // // Special usage of 'next' // mNext[NodeR] =3D mPos; - } =20 /** @@ -723,7 +726,7 @@ DeleteNode ( NODE NodeU; =20 if (mParent[mPos] =3D=3D NIL) { - return ; + return; } =20 NodeR =3D mPrev[mPos]; @@ -733,15 +736,15 @@ DeleteNode ( NodeR =3D mParent[mPos]; mParent[mPos] =3D NIL; if (NodeR >=3D WNDSIZ) { - return ; + return; } =20 mChildCount[NodeR]--; if (mChildCount[NodeR] > 1) { - return ; + return; } =20 - NodeT =3D (NODE) (mPosition[NodeR] & (UINT32)~PERC_FLAG); + NodeT =3D (NODE)(mPosition[NodeR] & (UINT32) ~PERC_FLAG); if (NodeT >=3D mPos) { NodeT -=3D WNDSIZ; } @@ -749,8 +752,8 @@ DeleteNode ( NodeS =3D NodeT; NodeQ =3D mParent[NodeR]; NodeU =3D mPosition[NodeQ]; - while (NodeU & (UINT32) PERC_FLAG) { - NodeU &=3D (UINT32)~PERC_FLAG; + while (NodeU & (UINT32)PERC_FLAG) { + NodeU &=3D (UINT32) ~PERC_FLAG; if (NodeU >=3D mPos) { NodeU -=3D WNDSIZ; } @@ -759,9 +762,9 @@ DeleteNode ( NodeS =3D NodeU; } =20 - mPosition[NodeQ] =3D (NODE) (NodeS | WNDSIZ); - NodeQ =3D mParent[NodeQ]; - NodeU =3D mPosition[NodeQ]; + mPosition[NodeQ] =3D (NODE)(NodeS | WNDSIZ); + NodeQ =3D mParent[NodeQ]; + NodeU =3D mPosition[NodeQ]; } =20 if (NodeQ < WNDSIZ) { @@ -773,24 +776,24 @@ DeleteNode ( NodeS =3D NodeU; } =20 - mPosition[NodeQ] =3D (NODE) (NodeS | WNDSIZ | (UINT32) PERC_FLAG); + mPosition[NodeQ] =3D (NODE)(NodeS | WNDSIZ | (UINT32)PERC_FLAG); } =20 - NodeS =3D Child (NodeR, mText[NodeT + mLevel[NodeR]]); - NodeT =3D mPrev[NodeS]; - NodeU =3D mNext[NodeS]; - mNext[NodeT] =3D NodeU; - mPrev[NodeU] =3D NodeT; - NodeT =3D mPrev[NodeR]; - mNext[NodeT] =3D NodeS; - mPrev[NodeS] =3D NodeT; - NodeT =3D mNext[NodeR]; - mPrev[NodeT] =3D NodeS; - mNext[NodeS] =3D NodeT; - mParent[NodeS] =3D mParent[NodeR]; - mParent[NodeR] =3D NIL; - mNext[NodeR] =3D mAvail; - mAvail =3D NodeR; + NodeS =3D Child (NodeR, mText[NodeT + mLevel[NodeR]]); + NodeT =3D mPrev[NodeS]; + NodeU =3D mNext[NodeS]; + mNext[NodeT] =3D NodeU; + mPrev[NodeU] =3D NodeT; + NodeT =3D mPrev[NodeR]; + mNext[NodeT] =3D NodeS; + mPrev[NodeS] =3D NodeT; + NodeT =3D mNext[NodeR]; + mPrev[NodeT] =3D NodeS; + mNext[NodeS] =3D NodeT; + mParent[NodeS] =3D mParent[NodeR]; + mParent[NodeR] =3D NIL; + mNext[NodeR] =3D mAvail; + mAvail =3D NodeR; } =20 /** @@ -803,15 +806,15 @@ GetNextMatch ( VOID ) { - INT32 Number; + INT32 Number; =20 mRemainder--; mPos++; if (mPos =3D=3D WNDSIZ * 2) { memmove (&mText[0], &mText[WNDSIZ], WNDSIZ + MAXMATCH); - Number =3D FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ); + Number =3D FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ); mRemainder +=3D Number; - mPos =3D WNDSIZ; + mPos =3D WNDSIZ; } =20 DeleteNode (); @@ -844,38 +847,37 @@ Encode ( =20 HufEncodeStart (); =20 - mRemainder =3D FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH); + mRemainder =3D FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH); =20 - mMatchLen =3D 0; - mPos =3D WNDSIZ; + mMatchLen =3D 0; + mPos =3D WNDSIZ; InsertNode (); if (mMatchLen > mRemainder) { mMatchLen =3D mRemainder; } =20 while (mRemainder > 0) { - LastMatchLen =3D mMatchLen; - LastMatchPos =3D mMatchPos; + LastMatchLen =3D mMatchLen; + LastMatchPos =3D mMatchPos; GetNextMatch (); if (mMatchLen > mRemainder) { mMatchLen =3D mRemainder; } =20 - if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) { + if ((mMatchLen > LastMatchLen) || (LastMatchLen < THRESHOLD)) { // // Not enough benefits are gained by outputting a pointer, // so just output the original character // Output (mText[mPos - 1], 0); - } else { - if (LastMatchLen =3D=3D THRESHOLD) { if (((mPos - LastMatchPos - 2) & (WNDSIZ - 1)) > (1U << 11)) { Output (mText[mPos - 1], 0); continue; } } + // // Outputting a pointer is beneficial enough, do it. // @@ -909,10 +911,10 @@ CountTFreq ( VOID ) { - INT32 Index; - INT32 Index3; - INT32 Number; - INT32 Count; + INT32 Index; + INT32 Index3; + INT32 Number; + INT32 Count; =20 for (Index =3D 0; Index < NT; Index++) { mTFreq[Index] =3D 0; @@ -934,7 +936,7 @@ CountTFreq ( } =20 if (Count <=3D 2) { - mTFreq[0] =3D (UINT16) (mTFreq[0] + Count); + mTFreq[0] =3D (UINT16)(mTFreq[0] + Count); } else if (Count <=3D 18) { mTFreq[1]++; } else if (Count =3D=3D 19) { @@ -959,13 +961,13 @@ CountTFreq ( STATIC VOID WritePTLen ( - IN INT32 Number, - IN INT32 nbit, - IN INT32 Special + IN INT32 Number, + IN INT32 nbit, + IN INT32 Special ) { - INT32 Index; - INT32 Index3; + INT32 Index; + INT32 Index3; =20 while (Number > 0 && mPTLen[Number - 1] =3D=3D 0) { Number--; @@ -1000,10 +1002,10 @@ WriteCLen ( VOID ) { - INT32 Index; - INT32 Index3; - INT32 Number; - INT32 Count; + INT32 Index; + INT32 Index3; + INT32 Number; + INT32 Count; =20 Number =3D NC; while (Number > 0 && mCLen[Number - 1] =3D=3D 0) { @@ -1045,7 +1047,7 @@ WriteCLen ( STATIC VOID EncodeC ( - IN INT32 Value + IN INT32 Value ) { PutBits (mCLen[Value], mCCode[Value]); @@ -1054,7 +1056,7 @@ EncodeC ( STATIC VOID EncodeP ( - IN UINT32 Value + IN UINT32 Value ) { UINT32 Index; @@ -1089,10 +1091,11 @@ SendBlock ( UINT32 Root; UINT32 Pos; UINT32 Size; + Flags =3D 0; =20 - Root =3D MakeTree (NC, mCFreq, mCLen, mCCode); - Size =3D mCFreq[Root]; + Root =3D MakeTree (NC, mCFreq, mCLen, mCCode); + Size =3D mCFreq[Root]; PutBits (16, Size); if (Root >=3D NC) { CountTFreq (); @@ -1133,7 +1136,7 @@ SendBlock ( Index3 =3D mBuf[Pos++]; for (Index2 =3D 0; Index2 < 3; Index2++) { Index3 <<=3D UINT8_BIT; - Index3 +=3D mBuf[Pos++]; + Index3 +=3D mBuf[Pos++]; } =20 EncodeP (Index3); @@ -1160,11 +1163,11 @@ SendBlock ( STATIC VOID Output ( - IN UINT32 CharC, - IN UINT32 Pos + IN UINT32 CharC, + IN UINT32 Pos ) { - STATIC UINT32 CPos; + STATIC UINT32 CPos; =20 if ((mOutputMask >>=3D 1) =3D=3D 0) { mOutputMask =3D 1U << (UINT8_BIT - 1); @@ -1178,19 +1181,19 @@ Output ( mOutputPos =3D 0; } =20 - CPos =3D mOutputPos++; - mBuf[CPos] =3D 0; + CPos =3D mOutputPos++; + mBuf[CPos] =3D 0; } =20 - mBuf[mOutputPos++] =3D (UINT8) CharC; + mBuf[mOutputPos++] =3D (UINT8)CharC; mCFreq[CharC]++; if (CharC >=3D (1U << UINT8_BIT)) { - mBuf[CPos] |=3D mOutputMask; - mBuf[mOutputPos++] =3D (UINT8) (Pos >> 24); - mBuf[mOutputPos++] =3D (UINT8) (Pos >> 16); - mBuf[mOutputPos++] =3D (UINT8) (Pos >> (UINT8_BIT)); - mBuf[mOutputPos++] =3D (UINT8) Pos; - CharC =3D 0; + mBuf[CPos] |=3D mOutputMask; + mBuf[mOutputPos++] =3D (UINT8)(Pos >> 24); + mBuf[mOutputPos++] =3D (UINT8)(Pos >> 16); + mBuf[mOutputPos++] =3D (UINT8)(Pos >> (UINT8_BIT)); + mBuf[mOutputPos++] =3D (UINT8)Pos; + CharC =3D 0; while (Pos) { Pos >>=3D 1; CharC++; @@ -1206,7 +1209,7 @@ HufEncodeStart ( VOID ) { - INT32 Index; + INT32 Index; =20 for (Index =3D 0; Index < NC; Index++) { mCFreq[Index] =3D 0; @@ -1218,7 +1221,7 @@ HufEncodeStart ( =20 mOutputPos =3D mOutputMask =3D 0; InitPutBits (); - return ; + return; } =20 STATIC @@ -1234,7 +1237,7 @@ HufEncodeEnd ( // PutBits (UINT8_BIT - 1, 0); =20 - return ; + return; } =20 STATIC @@ -1257,37 +1260,37 @@ MakeCrcTable ( } } =20 - mCrcTable[Index] =3D (UINT16) Temp; + mCrcTable[Index] =3D (UINT16)Temp; } } =20 /** Outputs rightmost n bits of x -=20 + @param Number the rightmost n bits of the data is used @param x the data **/ STATIC VOID PutBits ( - IN INT32 Number, - IN UINT32 Value + IN INT32 Number, + IN UINT32 Value ) { - UINT8 Temp; + UINT8 Temp; =20 while (Number >=3D mBitCount) { // // Number -=3D mBitCount should never equal to 32 // - Temp =3D (UINT8) (mSubBitBuf | (Value >> (Number -=3D mBitCount))); + Temp =3D (UINT8)(mSubBitBuf | (Value >> (Number -=3D mBitCount))); if (mDst < mDstUpperLimit) { *mDst++ =3D Temp; } =20 mCompSize++; - mSubBitBuf =3D 0; - mBitCount =3D UINT8_BIT; + mSubBitBuf =3D 0; + mBitCount =3D UINT8_BIT; } =20 mSubBitBuf |=3D Value << (mBitCount -=3D Number); @@ -1304,11 +1307,11 @@ PutBits ( STATIC INT32 FreadCrc ( - OUT UINT8 *Pointer, - IN INT32 Number + OUT UINT8 *Pointer, + IN INT32 Number ) { - INT32 Index; + INT32 Index; =20 for (Index =3D 0; mSrc < mSrcUpperLimit && Index < Number; Index++) { *Pointer++ =3D *mSrc++; @@ -1316,7 +1319,7 @@ FreadCrc ( =20 Number =3D Index; =20 - Pointer -=3D Number; + Pointer -=3D Number; mOrigSize +=3D Number; Index--; while (Index >=3D 0) { @@ -1333,8 +1336,8 @@ InitPutBits ( VOID ) { - mBitCount =3D UINT8_BIT; - mSubBitBuf =3D 0; + mBitCount =3D UINT8_BIT; + mSubBitBuf =3D 0; } =20 /** @@ -1345,7 +1348,7 @@ InitPutBits ( STATIC VOID CountLen ( - IN INT32 Index + IN INT32 Index ) { STATIC INT32 Depth =3D 0; @@ -1368,7 +1371,7 @@ CountLen ( STATIC VOID MakeLen ( - IN INT32 Root + IN INT32 Root ) { INT32 Index; @@ -1407,7 +1410,7 @@ MakeLen ( Index3 =3D mLenCnt[Index]; Index3--; while (Index3 >=3D 0) { - mLen[*mSortPtr++] =3D (UINT8) Index; + mLen[*mSortPtr++] =3D (UINT8)Index; Index3--; } } @@ -1416,19 +1419,19 @@ MakeLen ( STATIC VOID DownHeap ( - IN INT32 Index + IN INT32 Index ) { - INT32 Index2; - INT32 Index3; + INT32 Index2; + INT32 Index3; =20 // // priority queue: send Index-th entry down heap // - Index3 =3D mHeap[Index]; - Index2 =3D 2 * Index; + Index3 =3D mHeap[Index]; + Index2 =3D 2 * Index; while (Index2 <=3D mHeapSize) { - if (Index2 < mHeapSize && mFreq[mHeap[Index2]] > mFreq[mHeap[Index2 + = 1]]) { + if ((Index2 < mHeapSize) && (mFreq[mHeap[Index2]] > mFreq[mHeap[Index2= + 1]])) { Index2++; } =20 @@ -1436,12 +1439,12 @@ DownHeap ( break; } =20 - mHeap[Index] =3D mHeap[Index2]; - Index =3D Index2; - Index2 =3D 2 * Index; + mHeap[Index] =3D mHeap[Index2]; + Index =3D Index2; + Index2 =3D 2 * Index; } =20 - mHeap[Index] =3D (INT16) Index3; + mHeap[Index] =3D (INT16)Index3; } =20 /** @@ -1454,9 +1457,9 @@ DownHeap ( STATIC VOID MakeCode ( - IN INT32 Number, - IN UINT8 Len[ ], - OUT UINT16 Code[] + IN INT32 Number, + IN UINT8 Len[], + OUT UINT16 Code[] ) { INT32 Index; @@ -1464,7 +1467,7 @@ MakeCode ( =20 Start[1] =3D 0; for (Index =3D 1; Index <=3D 16; Index++) { - Start[Index + 1] =3D (UINT16) ((Start[Index] + mLenCnt[Index]) << 1); + Start[Index + 1] =3D (UINT16)((Start[Index] + mLenCnt[Index]) << 1); } =20 for (Index =3D 0; Index < Number; Index++) { @@ -1485,16 +1488,16 @@ MakeCode ( STATIC INT32 MakeTree ( - IN INT32 NParm, + IN INT32 NParm, IN UINT16 FreqParm[], - OUT UINT8 LenParm[ ], + OUT UINT8 LenParm[], OUT UINT16 CodeParm[] ) { - INT32 Index; - INT32 Index2; - INT32 Index3; - INT32 Avail; + INT32 Index; + INT32 Index2; + INT32 Index3; + INT32 Avail; =20 // // make tree, calculate len[], return root @@ -1509,7 +1512,7 @@ MakeTree ( mLen[Index] =3D 0; if (mFreq[Index]) { mHeapSize++; - mHeap[mHeapSize] =3D (INT16) Index; + mHeap[mHeapSize] =3D (INT16)Index; } } =20 @@ -1529,22 +1532,22 @@ MakeTree ( do { Index =3D mHeap[1]; if (Index < mN) { - *mSortPtr++ =3D (UINT16) Index; + *mSortPtr++ =3D (UINT16)Index; } =20 mHeap[1] =3D mHeap[mHeapSize--]; DownHeap (1); Index2 =3D mHeap[1]; if (Index2 < mN) { - *mSortPtr++ =3D (UINT16) Index2; + *mSortPtr++ =3D (UINT16)Index2; } =20 Index3 =3D Avail++; - mFreq[Index3] =3D (UINT16) (mFreq[Index] + mFreq[Index2]); - mHeap[1] =3D (INT16) Index3; + mFreq[Index3] =3D (UINT16)(mFreq[Index] + mFreq[Index2]); + mHeap[1] =3D (INT16)Index3; DownHeap (1); - mLeft[Index3] =3D (UINT16) Index; - mRight[Index3] =3D (UINT16) Index2; + mLeft[Index3] =3D (UINT16)Index; + mRight[Index3] =3D (UINT16)Index2; } while (mHeapSize > 1); =20 mSortPtr =3D CodeParm; --=20 2.37.1 (Apple Git-137.1) -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100500): https://edk2.groups.io/g/devel/message/100500 Mute This Topic: https://groups.io/mt/97218962/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-