3) A support protocol is not found, and the data is not available to be read\r
without it. This results in EFI_PROTOCOL_ERROR.\r
\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)\r
\r
typedef struct {\r
- UINT32 Signature;\r
- LIST_ENTRY Link;\r
- UINT32 Type;\r
- UINT32 Size;\r
+ UINT32 Signature;\r
+ LIST_ENTRY Link;\r
+ UINT32 Type;\r
+ UINT32 Size;\r
//\r
// StreamBase + OffsetInStream == pointer to section header in stream. The\r
// stream base is always known when walking the sections within.\r
//\r
- UINT32 OffsetInStream;\r
+ UINT32 OffsetInStream;\r
//\r
// Then EncapsulatedStreamHandle below is always 0 if the section is NOT an\r
// encapsulating section. Otherwise, it contains the stream handle\r
// encapsulating child is encountered, irrespective of whether the\r
// encapsulated stream is processed further.\r
//\r
- UINTN EncapsulatedStreamHandle;\r
- EFI_GUID *EncapsulationGuid;\r
+ UINTN EncapsulatedStreamHandle;\r
+ EFI_GUID *EncapsulationGuid;\r
//\r
- // If the section REQUIRES an extraction protocol, register for RPN \r
+ // If the section REQUIRES an extraction protocol, register for RPN\r
// when the required GUIDed extraction protocol becomes available.\r
//\r
- EFI_EVENT Event;\r
+ EFI_EVENT Event;\r
} CORE_SECTION_CHILD_NODE;\r
\r
-#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')\r
+#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')\r
#define STREAM_NODE_FROM_LINK(Node) \\r
CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)\r
\r
typedef struct {\r
- UINT32 Signature;\r
- LIST_ENTRY Link;\r
- UINTN StreamHandle;\r
- UINT8 *StreamBuffer;\r
- UINTN StreamLength;\r
- LIST_ENTRY Children;\r
+ UINT32 Signature;\r
+ LIST_ENTRY Link;\r
+ UINTN StreamHandle;\r
+ UINT8 *StreamBuffer;\r
+ UINTN StreamLength;\r
+ LIST_ENTRY Children;\r
//\r
// Authentication status is from GUIDed encapsulations.\r
//\r
- UINT32 AuthenticationStatus;\r
+ UINT32 AuthenticationStatus;\r
} CORE_SECTION_STREAM_NODE;\r
\r
-#define NULL_STREAM_HANDLE 0\r
+#define NULL_STREAM_HANDLE 0\r
\r
typedef struct {\r
CORE_SECTION_CHILD_NODE *ChildNode;\r
VOID *Registration;\r
} RPN_EVENT_CONTEXT;\r
\r
-\r
/**\r
The ExtractSection() function processes the input section and\r
allocates a buffer from the pool in which it returns the section\r
EFI_STATUS\r
EFIAPI\r
CustomGuidedSectionExtract (\r
- IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
- IN CONST VOID *InputSection,\r
- OUT VOID **OutputBuffer,\r
- OUT UINTN *OutputSize,\r
- OUT UINT32 *AuthenticationStatus\r
+ IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+ IN CONST VOID *InputSection,\r
+ OUT VOID **OutputBuffer,\r
+ OUT UINTN *OutputSize,\r
+ OUT UINT32 *AuthenticationStatus\r
);\r
\r
//\r
// Module globals\r
//\r
-LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);\r
+LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);\r
\r
-EFI_HANDLE mSectionExtractionHandle = NULL;\r
+EFI_HANDLE mSectionExtractionHandle = NULL;\r
\r
-EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {\r
+EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {\r
CustomGuidedSectionExtract\r
};\r
\r
-\r
/**\r
Entry point of the section extraction code. Initializes an instance of the\r
section extraction interface and installs it on a new handle.\r
EFI_STATUS\r
EFIAPI\r
InitializeSectionExtraction (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_GUID *ExtractHandlerGuidTable;\r
- UINTN ExtractHandlerNumber;\r
+ EFI_STATUS Status;\r
+ EFI_GUID *ExtractHandlerGuidTable;\r
+ UINTN ExtractHandlerNumber;\r
\r
//\r
// Get custom extract guided section method guid list\r
//\r
while (ExtractHandlerNumber-- > 0) {\r
Status = CoreInstallProtocolInterface (\r
- &mSectionExtractionHandle,\r
- &ExtractHandlerGuidTable [ExtractHandlerNumber],\r
- EFI_NATIVE_INTERFACE,\r
- &mCustomGuidedSectionExtractionProtocol\r
- );\r
+ &mSectionExtractionHandle,\r
+ &ExtractHandlerGuidTable[ExtractHandlerNumber],\r
+ EFI_NATIVE_INTERFACE,\r
+ &mCustomGuidedSectionExtractionProtocol\r
+ );\r
ASSERT_EFI_ERROR (Status);\r
}\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Check if a stream is valid.\r
\r
**/\r
BOOLEAN\r
IsValidSectionStream (\r
- IN VOID *SectionStream,\r
- IN UINTN SectionStreamLength\r
+ IN VOID *SectionStream,\r
+ IN UINTN SectionStreamLength\r
)\r
{\r
- UINTN TotalLength;\r
- UINTN SectionLength;\r
- EFI_COMMON_SECTION_HEADER *SectionHeader;\r
- EFI_COMMON_SECTION_HEADER *NextSectionHeader;\r
+ UINTN TotalLength;\r
+ UINTN SectionLength;\r
+ EFI_COMMON_SECTION_HEADER *SectionHeader;\r
+ EFI_COMMON_SECTION_HEADER *NextSectionHeader;\r
\r
- TotalLength = 0;\r
+ TotalLength = 0;\r
SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
\r
while (TotalLength < SectionStreamLength) {\r
} else {\r
SectionLength = SECTION_SIZE (SectionHeader);\r
}\r
+\r
TotalLength += SectionLength;\r
\r
if (TotalLength == SectionStreamLength) {\r
//\r
// Move to the next byte following the section...\r
//\r
- SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);\r
+ SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)SectionHeader + SectionLength);\r
\r
//\r
// Figure out where the next section begins\r
//\r
- NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);\r
- TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;\r
- SectionHeader = NextSectionHeader;\r
+ NextSectionHeader = ALIGN_POINTER (SectionHeader, 4);\r
+ TotalLength += (UINTN)NextSectionHeader - (UINTN)SectionHeader;\r
+ SectionHeader = NextSectionHeader;\r
}\r
\r
ASSERT (FALSE);\r
return FALSE;\r
}\r
\r
-\r
/**\r
Worker function. Constructor for section streams.\r
\r
**/\r
EFI_STATUS\r
OpenSectionStreamEx (\r
- IN UINTN SectionStreamLength,\r
- IN VOID *SectionStream,\r
- IN BOOLEAN AllocateBuffer,\r
- IN UINT32 AuthenticationStatus,\r
- OUT UINTN *SectionStreamHandle\r
+ IN UINTN SectionStreamLength,\r
+ IN VOID *SectionStream,\r
+ IN BOOLEAN AllocateBuffer,\r
+ IN UINT32 AuthenticationStatus,\r
+ OUT UINTN *SectionStreamHandle\r
)\r
{\r
- CORE_SECTION_STREAM_NODE *NewStream;\r
- EFI_TPL OldTpl;\r
+ CORE_SECTION_STREAM_NODE *NewStream;\r
+ EFI_TPL OldTpl;\r
\r
//\r
// Allocate a new stream\r
CoreFreePool (NewStream);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
+\r
//\r
// Copy in stream data\r
//\r
//\r
// Initialize the rest of the section stream\r
//\r
- NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;\r
- NewStream->StreamHandle = (UINTN) NewStream;\r
+ NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;\r
+ NewStream->StreamHandle = (UINTN)NewStream;\r
NewStream->StreamLength = SectionStreamLength;\r
InitializeListHead (&NewStream->Children);\r
NewStream->AuthenticationStatus = AuthenticationStatus;\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
SEP member function. This function creates and returns a new section stream\r
handle to represent the new section stream.\r
EFI_STATUS\r
EFIAPI\r
OpenSectionStream (\r
- IN UINTN SectionStreamLength,\r
- IN VOID *SectionStream,\r
- OUT UINTN *SectionStreamHandle\r
+ IN UINTN SectionStreamLength,\r
+ IN VOID *SectionStream,\r
+ OUT UINTN *SectionStreamHandle\r
)\r
{\r
//\r
);\r
}\r
\r
-\r
-\r
/**\r
Worker function. Determine if the input stream:child matches the input type.\r
\r
**/\r
BOOLEAN\r
ChildIsType (\r
- IN CORE_SECTION_STREAM_NODE *Stream,\r
- IN CORE_SECTION_CHILD_NODE *Child,\r
- IN EFI_SECTION_TYPE SearchType,\r
- IN EFI_GUID *SectionDefinitionGuid\r
+ IN CORE_SECTION_STREAM_NODE *Stream,\r
+ IN CORE_SECTION_CHILD_NODE *Child,\r
+ IN EFI_SECTION_TYPE SearchType,\r
+ IN EFI_GUID *SectionDefinitionGuid\r
)\r
{\r
- EFI_GUID_DEFINED_SECTION *GuidedSection;\r
+ EFI_GUID_DEFINED_SECTION *GuidedSection;\r
\r
if (SearchType == EFI_SECTION_ALL) {\r
return TRUE;\r
}\r
+\r
if (Child->Type != SearchType) {\r
return FALSE;\r
}\r
+\r
if ((SearchType != EFI_SECTION_GUID_DEFINED) || (SectionDefinitionGuid == NULL)) {\r
return TRUE;\r
}\r
- GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);\r
+\r
+ GuidedSection = (EFI_GUID_DEFINED_SECTION *)(Stream->StreamBuffer + Child->OffsetInStream);\r
if (IS_SECTION2 (GuidedSection)) {\r
- return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);\r
+ return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *)GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);\r
} else {\r
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
}\r
\r
@return TRUE The GuidedSectionGuid could be identified, and the pointer to\r
the Guided Section Extraction Protocol will be returned to *GuidedSectionExtraction.\r
- @return FALSE The GuidedSectionGuid could not be identified, or \r
+ @return FALSE The GuidedSectionGuid could not be identified, or\r
the Guided Section Extraction Protocol has not been installed yet.\r
\r
**/\r
BOOLEAN\r
VerifyGuidedSectionGuid (\r
- IN EFI_GUID *GuidedSectionGuid,\r
- OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction\r
+ IN EFI_GUID *GuidedSectionGuid,\r
+ OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction\r
)\r
{\r
- EFI_GUID *GuidRecorded;\r
- VOID *Interface;\r
- EFI_STATUS Status;\r
+ EFI_GUID *GuidRecorded;\r
+ VOID *Interface;\r
+ EFI_STATUS Status;\r
\r
Interface = NULL;\r
\r
//\r
// Check if there is the Guided Section GUID configuration table recorded the GUID itself.\r
//\r
- Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **) &GuidRecorded);\r
+ Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **)&GuidRecorded);\r
if (Status == EFI_SUCCESS) {\r
if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {\r
//\r
// Found the recorded GuidedSectionGuid.\r
//\r
- Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **) &Interface);\r
- if (!EFI_ERROR (Status) && Interface != NULL) {\r
+ Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **)&Interface);\r
+ if (!EFI_ERROR (Status) && (Interface != NULL)) {\r
//\r
// Found the supported Guided Section Extraction Porotocol for the Guided Section.\r
//\r
- *GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *) Interface;\r
+ *GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *)Interface;\r
return TRUE;\r
}\r
+\r
return FALSE;\r
}\r
}\r
VOID\r
EFIAPI\r
NotifyGuidedExtraction (\r
- IN EFI_EVENT Event,\r
- IN VOID *RpnContext\r
+ IN EFI_EVENT Event,\r
+ IN VOID *RpnContext\r
)\r
{\r
EFI_STATUS Status;\r
UINTN NewStreamBufferSize;\r
UINT32 AuthenticationStatus;\r
RPN_EVENT_CONTEXT *Context;\r
- \r
+\r
Context = RpnContext;\r
- \r
- GuidedHeader = (EFI_GUID_DEFINED_SECTION *) (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
+\r
+ GuidedHeader = (EFI_GUID_DEFINED_SECTION *)(Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
\r
if (!VerifyGuidedSectionGuid (Context->ChildNode->EncapsulationGuid, &GuidedExtraction)) {\r
gBS->CloseEvent (Event);\r
Context->ChildNode->Event = NULL;\r
FreePool (Context);\r
-} \r
+}\r
\r
/**\r
Constructor for RPN event when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
**/\r
VOID\r
CreateGuidedExtractionRpnEvent (\r
- IN CORE_SECTION_STREAM_NODE *ParentStream,\r
- IN CORE_SECTION_CHILD_NODE *ChildNode\r
+ IN CORE_SECTION_STREAM_NODE *ParentStream,\r
+ IN CORE_SECTION_CHILD_NODE *ChildNode\r
)\r
{\r
- RPN_EVENT_CONTEXT *Context;\r
- \r
+ RPN_EVENT_CONTEXT *Context;\r
+\r
//\r
// Allocate new event structure and context\r
//\r
Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));\r
ASSERT (Context != NULL);\r
- \r
- Context->ChildNode = ChildNode;\r
+\r
+ Context->ChildNode = ChildNode;\r
Context->ParentStream = ParentStream;\r
- \r
+\r
Context->ChildNode->Event = EfiCreateProtocolNotifyEvent (\r
Context->ChildNode->EncapsulationGuid,\r
TPL_NOTIFY,\r
**/\r
EFI_STATUS\r
CreateChildNode (\r
- IN CORE_SECTION_STREAM_NODE *Stream,\r
- IN UINT32 ChildOffset,\r
- OUT CORE_SECTION_CHILD_NODE **ChildNode\r
+ IN CORE_SECTION_STREAM_NODE *Stream,\r
+ IN UINT32 ChildOffset,\r
+ OUT CORE_SECTION_CHILD_NODE **ChildNode\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_COMMON_SECTION_HEADER *SectionHeader;\r
- EFI_COMPRESSION_SECTION *CompressionHeader;\r
- EFI_GUID_DEFINED_SECTION *GuidedHeader;\r
- EFI_DECOMPRESS_PROTOCOL *Decompress;\r
- EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;\r
- VOID *NewStreamBuffer;\r
- VOID *ScratchBuffer;\r
- UINT32 ScratchSize;\r
- UINTN NewStreamBufferSize;\r
- UINT32 AuthenticationStatus;\r
- VOID *CompressionSource;\r
- UINT32 CompressionSourceSize;\r
- UINT32 UncompressedLength;\r
- UINT8 CompressionType;\r
- UINT16 GuidedSectionAttributes;\r
-\r
- CORE_SECTION_CHILD_NODE *Node;\r
-\r
- SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);\r
+ EFI_STATUS Status;\r
+ EFI_COMMON_SECTION_HEADER *SectionHeader;\r
+ EFI_COMPRESSION_SECTION *CompressionHeader;\r
+ EFI_GUID_DEFINED_SECTION *GuidedHeader;\r
+ EFI_DECOMPRESS_PROTOCOL *Decompress;\r
+ EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;\r
+ VOID *NewStreamBuffer;\r
+ VOID *ScratchBuffer;\r
+ UINT32 ScratchSize;\r
+ UINTN NewStreamBufferSize;\r
+ UINT32 AuthenticationStatus;\r
+ VOID *CompressionSource;\r
+ UINT32 CompressionSourceSize;\r
+ UINT32 UncompressedLength;\r
+ UINT8 CompressionType;\r
+ UINT16 GuidedSectionAttributes;\r
+\r
+ CORE_SECTION_CHILD_NODE *Node;\r
+\r
+ SectionHeader = (EFI_COMMON_SECTION_HEADER *)(Stream->StreamBuffer + ChildOffset);\r
\r
//\r
// Allocate a new node\r
//\r
*ChildNode = AllocateZeroPool (sizeof (CORE_SECTION_CHILD_NODE));\r
- Node = *ChildNode;\r
+ Node = *ChildNode;\r
if (Node == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
// Now initialize it\r
//\r
Node->Signature = CORE_SECTION_CHILD_SIGNATURE;\r
- Node->Type = SectionHeader->Type;\r
+ Node->Type = SectionHeader->Type;\r
if (IS_SECTION2 (SectionHeader)) {\r
Node->Size = SECTION2_SIZE (SectionHeader);\r
} else {\r
Node->Size = SECTION_SIZE (SectionHeader);\r
}\r
- Node->OffsetInStream = ChildOffset;\r
+\r
+ Node->OffsetInStream = ChildOffset;\r
Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;\r
- Node->EncapsulationGuid = NULL;\r
+ Node->EncapsulationGuid = NULL;\r
\r
//\r
// If it's an encapsulating section, then create the new section stream also\r
return EFI_NOT_FOUND;\r
}\r
\r
- CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;\r
+ CompressionHeader = (EFI_COMPRESSION_SECTION *)SectionHeader;\r
\r
if (IS_SECTION2 (CompressionHeader)) {\r
- CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));\r
- CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));\r
- UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;\r
- CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;\r
+ CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));\r
+ CompressionSourceSize = (UINT32)(SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));\r
+ UncompressedLength = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->UncompressedLength;\r
+ CompressionType = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->CompressionType;\r
} else {\r
- CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));\r
- CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));\r
- UncompressedLength = CompressionHeader->UncompressedLength;\r
- CompressionType = CompressionHeader->CompressionType;\r
+ CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));\r
+ CompressionSourceSize = (UINT32)(SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));\r
+ UncompressedLength = CompressionHeader->UncompressedLength;\r
+ CompressionType = CompressionHeader->CompressionType;\r
}\r
\r
//\r
//\r
if (UncompressedLength > 0) {\r
NewStreamBufferSize = UncompressedLength;\r
- NewStreamBuffer = AllocatePool (NewStreamBufferSize);\r
+ NewStreamBuffer = AllocatePool (NewStreamBufferSize);\r
if (NewStreamBuffer == NULL) {\r
CoreFreePool (Node);\r
return EFI_OUT_OF_RESOURCES;\r
if (!EFI_ERROR (Status)) {\r
Status = EFI_BAD_BUFFER_SIZE;\r
}\r
+\r
return Status;\r
}\r
\r
}\r
}\r
} else {\r
- NewStreamBuffer = NULL;\r
+ NewStreamBuffer = NULL;\r
NewStreamBufferSize = 0;\r
}\r
\r
CoreFreePool (NewStreamBuffer);\r
return Status;\r
}\r
+\r
break;\r
\r
case EFI_SECTION_GUID_DEFINED:\r
- GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;\r
+ GuidedHeader = (EFI_GUID_DEFINED_SECTION *)SectionHeader;\r
if (IS_SECTION2 (GuidedHeader)) {\r
- Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);\r
- GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;\r
+ Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->SectionDefinitionGuid);\r
+ GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->Attributes;\r
} else {\r
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
GuidedSectionAttributes = GuidedHeader->Attributes;\r
}\r
+\r
if (VerifyGuidedSectionGuid (Node->EncapsulationGuid, &GuidedExtraction)) {\r
//\r
// NewStreamBuffer is always allocated by ExtractSection... No caller\r
//\r
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {\r
//\r
- // If the section REQUIRES an extraction protocol, register for RPN \r
- // when the required GUIDed extraction protocol becomes available. \r
+ // If the section REQUIRES an extraction protocol, register for RPN\r
+ // when the required GUIDed extraction protocol becomes available.\r
//\r
CreateGuidedExtractionRpnEvent (Stream, Node);\r
} else {\r
\r
if (IS_SECTION2 (GuidedHeader)) {\r
Status = OpenSectionStreamEx (\r
- SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,\r
- (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,\r
+ SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,\r
+ (UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,\r
TRUE,\r
AuthenticationStatus,\r
&Node->EncapsulatedStreamHandle\r
);\r
} else {\r
Status = OpenSectionStreamEx (\r
- SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,\r
- (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,\r
+ SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,\r
+ (UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,\r
TRUE,\r
AuthenticationStatus,\r
&Node->EncapsulatedStreamHandle\r
);\r
}\r
+\r
if (EFI_ERROR (Status)) {\r
CoreFreePool (Node);\r
return Status;\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Worker function Recursively searches / builds section stream database\r
looking for requested section.\r
search.\r
@param SearchType Indicates the type of section to search for.\r
@param SectionInstance Indicates which instance of section to find.\r
- This is an in/out parameter to deal with\r
- recursions.\r
+ This is an in/out parameter and it is 1-based,\r
+ to deal with recursions.\r
@param SectionDefinitionGuid Guid of section definition\r
+ @param Depth Nesting depth of encapsulation sections.\r
+ Callers different from FindChildNode() are\r
+ responsible for passing in a zero Depth.\r
@param FoundChild Output indicating the child node that is found.\r
@param FoundStream Output indicating which section stream the child\r
was found in. If this stream was generated as a\r
@retval EFI_NOT_FOUND Requested child node does not exist.\r
@retval EFI_PROTOCOL_ERROR a required GUIDED section extraction protocol\r
does not exist\r
+ @retval EFI_ABORTED Recursion aborted because Depth has been\r
+ greater than or equal to\r
+ PcdFwVolDxeMaxEncapsulationDepth.\r
\r
**/\r
EFI_STATUS\r
FindChildNode (\r
- IN CORE_SECTION_STREAM_NODE *SourceStream,\r
- IN EFI_SECTION_TYPE SearchType,\r
- IN OUT UINTN *SectionInstance,\r
- IN EFI_GUID *SectionDefinitionGuid,\r
- OUT CORE_SECTION_CHILD_NODE **FoundChild,\r
- OUT CORE_SECTION_STREAM_NODE **FoundStream,\r
- OUT UINT32 *AuthenticationStatus\r
+ IN CORE_SECTION_STREAM_NODE *SourceStream,\r
+ IN EFI_SECTION_TYPE SearchType,\r
+ IN OUT UINTN *SectionInstance,\r
+ IN EFI_GUID *SectionDefinitionGuid,\r
+ IN UINT32 Depth,\r
+ OUT CORE_SECTION_CHILD_NODE **FoundChild,\r
+ OUT CORE_SECTION_STREAM_NODE **FoundStream,\r
+ OUT UINT32 *AuthenticationStatus\r
)\r
{\r
- CORE_SECTION_CHILD_NODE *CurrentChildNode;\r
- CORE_SECTION_CHILD_NODE *RecursedChildNode;\r
- CORE_SECTION_STREAM_NODE *RecursedFoundStream;\r
- UINT32 NextChildOffset;\r
- EFI_STATUS ErrorStatus;\r
- EFI_STATUS Status;\r
+ CORE_SECTION_CHILD_NODE *CurrentChildNode;\r
+ CORE_SECTION_CHILD_NODE *RecursedChildNode;\r
+ CORE_SECTION_STREAM_NODE *RecursedFoundStream;\r
+ UINT32 NextChildOffset;\r
+ EFI_STATUS ErrorStatus;\r
+ EFI_STATUS Status;\r
+\r
+ ASSERT (*SectionInstance > 0);\r
+\r
+ if (Depth >= PcdGet32 (PcdFwVolDxeMaxEncapsulationDepth)) {\r
+ return EFI_ABORTED;\r
+ }\r
\r
CurrentChildNode = NULL;\r
- ErrorStatus = EFI_NOT_FOUND;\r
+ ErrorStatus = EFI_NOT_FOUND;\r
\r
if (SourceStream->StreamLength == 0) {\r
return EFI_NOT_FOUND;\r
}\r
\r
if (IsListEmpty (&SourceStream->Children) &&\r
- SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {\r
+ (SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)))\r
+ {\r
//\r
// This occurs when a section stream exists, but no child sections\r
// have been parsed out yet. Therefore, extract the first child and add it\r
// adding children until either the requested section is found, or we run\r
// out of data\r
//\r
- CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));\r
+ CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode (&SourceStream->Children));\r
\r
- for (;;) {\r
+ for ( ; ;) {\r
ASSERT (CurrentChildNode != NULL);\r
if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {\r
//\r
//\r
// Got it!\r
//\r
- *FoundChild = CurrentChildNode;\r
- *FoundStream = SourceStream;\r
+ *FoundChild = CurrentChildNode;\r
+ *FoundStream = SourceStream;\r
*AuthenticationStatus = SourceStream->AuthenticationStatus;\r
return EFI_SUCCESS;\r
}\r
}\r
\r
+ //\r
+ // Type mismatch, or we haven't found the desired instance yet.\r
+ //\r
+ ASSERT (*SectionInstance > 0);\r
+\r
if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
//\r
// If the current node is an encapsulating node, recurse into it...\r
//\r
Status = FindChildNode (\r
- (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,\r
- SearchType,\r
- SectionInstance,\r
- SectionDefinitionGuid,\r
- &RecursedChildNode,\r
- &RecursedFoundStream,\r
- AuthenticationStatus\r
- );\r
- //\r
- // If the status is not EFI_SUCCESS, just save the error code and continue\r
- // to find the request child node in the rest stream.\r
- //\r
+ (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,\r
+ SearchType,\r
+ SectionInstance,\r
+ SectionDefinitionGuid,\r
+ Depth + 1,\r
+ &RecursedChildNode,\r
+ &RecursedFoundStream,\r
+ AuthenticationStatus\r
+ );\r
if (*SectionInstance == 0) {\r
+ //\r
+ // The recursive FindChildNode() call decreased (*SectionInstance) to\r
+ // zero.\r
+ //\r
ASSERT_EFI_ERROR (Status);\r
- *FoundChild = RecursedChildNode;\r
+ *FoundChild = RecursedChildNode;\r
*FoundStream = RecursedFoundStream;\r
return EFI_SUCCESS;\r
} else {\r
+ if (Status == EFI_ABORTED) {\r
+ //\r
+ // If the recursive call was aborted due to nesting depth, stop\r
+ // looking for the requested child node. The skipped subtree could\r
+ // throw off the instance counting.\r
+ //\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Save the error code and continue to find the requested child node in\r
+ // the rest of the stream.\r
+ //\r
ErrorStatus = Status;\r
}\r
} else if ((CurrentChildNode->Type == EFI_SECTION_GUID_DEFINED) && (SearchType != EFI_SECTION_GUID_DEFINED)) {\r
// Round up to 4 byte boundary\r
//\r
NextChildOffset += 3;\r
- NextChildOffset &= ~(UINTN) 3;\r
+ NextChildOffset &= ~(UINTN)3;\r
if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {\r
//\r
// There's an unparsed child remaining in the stream, so create a new child node\r
}\r
}\r
\r
-\r
/**\r
Worker function. Search stream database for requested stream handle.\r
\r
**/\r
EFI_STATUS\r
FindStreamNode (\r
- IN UINTN SearchHandle,\r
- OUT CORE_SECTION_STREAM_NODE **FoundStream\r
+ IN UINTN SearchHandle,\r
+ OUT CORE_SECTION_STREAM_NODE **FoundStream\r
)\r
{\r
- CORE_SECTION_STREAM_NODE *StreamNode;\r
+ CORE_SECTION_STREAM_NODE *StreamNode;\r
\r
if (!IsListEmpty (&mStreamRoot)) {\r
StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));\r
- for (;;) {\r
+ for ( ; ;) {\r
if (StreamNode->StreamHandle == SearchHandle) {\r
*FoundStream = StreamNode;\r
return EFI_SUCCESS;\r
return EFI_NOT_FOUND;\r
}\r
\r
-\r
/**\r
SEP member function. Retrieves requested section from section stream.\r
\r
non-null on input, then the buffer is caller\r
allocated. If Buffer is NULL, then the buffer\r
is callee allocated. In either case, the\r
- requried buffer size is returned in *BufferSize.\r
+ required buffer size is returned in *BufferSize.\r
@param BufferSize On input, indicates the size of *Buffer if\r
*Buffer is non-null on input. On output,\r
indicates the required size (allocated size if\r
EFI_STATUS\r
EFIAPI\r
GetSection (\r
- IN UINTN SectionStreamHandle,\r
- IN EFI_SECTION_TYPE *SectionType,\r
- IN EFI_GUID *SectionDefinitionGuid,\r
- IN UINTN SectionInstance,\r
- IN VOID **Buffer,\r
- IN OUT UINTN *BufferSize,\r
- OUT UINT32 *AuthenticationStatus,\r
- IN BOOLEAN IsFfs3Fv\r
+ IN UINTN SectionStreamHandle,\r
+ IN EFI_SECTION_TYPE *SectionType,\r
+ IN EFI_GUID *SectionDefinitionGuid,\r
+ IN UINTN SectionInstance,\r
+ IN VOID **Buffer,\r
+ IN OUT UINTN *BufferSize,\r
+ OUT UINT32 *AuthenticationStatus,\r
+ IN BOOLEAN IsFfs3Fv\r
)\r
{\r
- CORE_SECTION_STREAM_NODE *StreamNode;\r
- EFI_TPL OldTpl;\r
- EFI_STATUS Status;\r
- CORE_SECTION_CHILD_NODE *ChildNode;\r
- CORE_SECTION_STREAM_NODE *ChildStreamNode;\r
- UINTN CopySize;\r
- UINT32 ExtractedAuthenticationStatus;\r
- UINTN Instance;\r
- UINT8 *CopyBuffer;\r
- UINTN SectionSize;\r
- EFI_COMMON_SECTION_HEADER *Section;\r
-\r
+ CORE_SECTION_STREAM_NODE *StreamNode;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+ CORE_SECTION_CHILD_NODE *ChildNode;\r
+ CORE_SECTION_STREAM_NODE *ChildStreamNode;\r
+ UINTN CopySize;\r
+ UINT32 ExtractedAuthenticationStatus;\r
+ UINTN Instance;\r
+ UINT8 *CopyBuffer;\r
+ UINTN SectionSize;\r
+ EFI_COMMON_SECTION_HEADER *Section;\r
\r
ChildStreamNode = NULL;\r
- OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
- Instance = SectionInstance + 1;\r
+ OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
+ Instance = SectionInstance + 1;\r
\r
//\r
// Locate target stream\r
//\r
// SectionType == NULL means return the WHOLE section stream...\r
//\r
- CopySize = StreamNode->StreamLength;\r
- CopyBuffer = StreamNode->StreamBuffer;\r
+ CopySize = StreamNode->StreamLength;\r
+ CopyBuffer = StreamNode->StreamBuffer;\r
*AuthenticationStatus = StreamNode->AuthenticationStatus;\r
} else {\r
//\r
*SectionType,\r
&Instance,\r
SectionDefinitionGuid,\r
+ 0, // encapsulation depth\r
&ChildNode,\r
&ChildStreamNode,\r
&ExtractedAuthenticationStatus\r
);\r
if (EFI_ERROR (Status)) {\r
+ if (Status == EFI_ABORTED) {\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: recursion aborted due to nesting depth\n",\r
+ __FUNCTION__\r
+ ));\r
+ //\r
+ // Map "aborted" to "not found".\r
+ //\r
+ Status = EFI_NOT_FOUND;\r
+ }\r
+\r
goto GetSection_Done;\r
}\r
\r
- Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);\r
+ Section = (EFI_COMMON_SECTION_HEADER *)(ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);\r
\r
if (IS_SECTION2 (Section)) {\r
ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);\r
Status = EFI_NOT_FOUND;\r
goto GetSection_Done;\r
}\r
- CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);\r
- CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);\r
+\r
+ CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);\r
+ CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2);\r
} else {\r
- CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);\r
- CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);\r
+ CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);\r
+ CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER);\r
}\r
+\r
*AuthenticationStatus = ExtractedAuthenticationStatus;\r
}\r
\r
// Caller allocated buffer. Fill to size and return required size...\r
//\r
if (*BufferSize < CopySize) {\r
- Status = EFI_WARN_BUFFER_TOO_SMALL;\r
+ Status = EFI_WARN_BUFFER_TOO_SMALL;\r
CopySize = *BufferSize;\r
}\r
} else {\r
goto GetSection_Done;\r
}\r
}\r
+\r
CopyMem (*Buffer, CopyBuffer, CopySize);\r
*BufferSize = SectionSize;\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Worker function. Destructor for child nodes.\r
\r
**/\r
VOID\r
FreeChildNode (\r
- IN CORE_SECTION_CHILD_NODE *ChildNode\r
+ IN CORE_SECTION_CHILD_NODE *ChildNode\r
)\r
{\r
ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);\r
CoreFreePool (ChildNode);\r
}\r
\r
-\r
/**\r
SEP member function. Deletes an existing section stream\r
\r
EFI_STATUS\r
EFIAPI\r
CloseSectionStream (\r
- IN UINTN StreamHandleToClose,\r
- IN BOOLEAN FreeStreamBuffer\r
+ IN UINTN StreamHandleToClose,\r
+ IN BOOLEAN FreeStreamBuffer\r
)\r
{\r
- CORE_SECTION_STREAM_NODE *StreamNode;\r
- EFI_TPL OldTpl;\r
- EFI_STATUS Status;\r
- LIST_ENTRY *Link;\r
- CORE_SECTION_CHILD_NODE *ChildNode;\r
+ CORE_SECTION_STREAM_NODE *StreamNode;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+ LIST_ENTRY *Link;\r
+ CORE_SECTION_CHILD_NODE *ChildNode;\r
\r
OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
\r
//\r
RemoveEntryList (&StreamNode->Link);\r
while (!IsListEmpty (&StreamNode->Children)) {\r
- Link = GetFirstNode (&StreamNode->Children);\r
+ Link = GetFirstNode (&StreamNode->Children);\r
ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);\r
FreeChildNode (ChildNode);\r
}\r
+\r
if (FreeStreamBuffer) {\r
CoreFreePool (StreamNode->StreamBuffer);\r
}\r
+\r
CoreFreePool (StreamNode);\r
Status = EFI_SUCCESS;\r
} else {\r
return Status;\r
}\r
\r
-\r
/**\r
The ExtractSection() function processes the input section and\r
allocates a buffer from the pool in which it returns the section\r
EFI_STATUS\r
EFIAPI\r
CustomGuidedSectionExtract (\r
- IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
- IN CONST VOID *InputSection,\r
- OUT VOID **OutputBuffer,\r
- OUT UINTN *OutputSize,\r
- OUT UINT32 *AuthenticationStatus\r
+ IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+ IN CONST VOID *InputSection,\r
+ OUT VOID **OutputBuffer,\r
+ OUT UINTN *OutputSize,\r
+ OUT UINT32 *AuthenticationStatus\r
)\r
{\r
- EFI_STATUS Status;\r
- VOID *ScratchBuffer;\r
- VOID *AllocatedOutputBuffer;\r
- UINT32 OutputBufferSize;\r
- UINT32 ScratchBufferSize;\r
- UINT16 SectionAttribute;\r
+ EFI_STATUS Status;\r
+ VOID *ScratchBuffer;\r
+ VOID *AllocatedOutputBuffer;\r
+ UINT32 OutputBufferSize;\r
+ UINT32 ScratchBufferSize;\r
+ UINT16 SectionAttribute;\r
\r
//\r
// Init local variable\r
//\r
AllocatedOutputBuffer = AllocatePool (OutputBufferSize);\r
if (AllocatedOutputBuffer == NULL) {\r
- FreePool (ScratchBuffer);\r
+ if (ScratchBuffer != NULL) {\r
+ FreePool (ScratchBuffer);\r
+ }\r
+\r
return EFI_OUT_OF_RESOURCES;\r
}\r
+\r
*OutputBuffer = AllocatedOutputBuffer;\r
}\r
\r
if (AllocatedOutputBuffer != NULL) {\r
CoreFreePool (AllocatedOutputBuffer);\r
}\r
+\r
if (ScratchBuffer != NULL) {\r
CoreFreePool (ScratchBuffer);\r
}\r
+\r
DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r
return Status;\r
}\r
//\r
// Set real size of output buffer.\r
//\r
- *OutputSize = (UINTN) OutputBufferSize;\r
+ *OutputSize = (UINTN)OutputBufferSize;\r
\r
//\r
// Free unused scratch buffer.\r