2 Section Extraction Protocol implementation.
4 Stream database is implemented as a linked list of section streams,
5 where each stream contains a linked list of children, which may be leaves or
8 Children that are encapsulations generate new stream entries
9 when they are created. Streams can also be created by calls to
10 SEP->OpenSectionStream().
12 The database is only created far enough to return the requested data from
13 any given stream, or to determine that the requested data is not found.
15 If a GUIDed encapsulation is encountered, there are three possiblilites.
17 1) A support protocol is found, in which the stream is simply processed with
20 2) A support protocol is not found, but the data is available to be read
21 without processing. In this case, the database is built up through the
22 recursions to return the data, and a RPN event is set that will enable
23 the stream in question to be refreshed if and when the required section
24 extraction protocol is published.This insures the AuthenticationStatus
25 does not become stale in the cache.
27 3) A support protocol is not found, and the data is not available to be read
28 without it. This results in EFI_PROTOCOL_ERROR.
30 Copyright (c) 2006 - 2008, Intel Corporation
31 All rights reserved. This program and the accompanying materials
32 are licensed and made available under the terms and conditions of the BSD License
33 which accompanies this distribution. The full text of the license may be found at
34 http://opensource.org/licenses/bsd-license.php
36 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
37 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
44 // Local defines and typedefs
46 #define CORE_SECTION_CHILD_SIGNATURE EFI_SIGNATURE_32('S','X','C','S')
47 #define CHILD_SECTION_NODE_FROM_LINK(Node) \
48 CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)
56 // StreamBase + OffsetInStream == pointer to section header in stream. The
57 // stream base is always known when walking the sections within.
59 UINT32 OffsetInStream
;
61 // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
62 // encapsulating section. Otherwise, it contains the stream handle
63 // of the encapsulated stream. This handle is ALWAYS produced any time an
64 // encapsulating child is encountered, irrespective of whether the
65 // encapsulated stream is processed further.
67 UINTN EncapsulatedStreamHandle
;
68 EFI_GUID
*EncapsulationGuid
;
69 } CORE_SECTION_CHILD_NODE
;
71 #define CORE_SECTION_STREAM_SIGNATURE EFI_SIGNATURE_32('S','X','S','S')
72 #define STREAM_NODE_FROM_LINK(Node) \
73 CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)
83 // Authentication status is from GUIDed encapsulations.
85 UINT32 AuthenticationStatus
;
86 } CORE_SECTION_STREAM_NODE
;
88 #define NULL_STREAM_HANDLE 0
91 CORE_SECTION_CHILD_NODE
*ChildNode
;
92 CORE_SECTION_STREAM_NODE
*ParentStream
;
104 Worker function. Determine if the input stream:child matches the input type.
106 @param Stream Indicates the section stream associated with the
108 @param Child Indicates the child to check
109 @param SearchType Indicates the type of section to check against
111 @param SectionDefinitionGuid Indicates the GUID to check against if the type
112 is EFI_SECTION_GUID_DEFINED
114 @retval TRUE The child matches
115 @retval FALSE The child doesn't match
121 IN CORE_SECTION_STREAM_NODE
*Stream
,
122 IN CORE_SECTION_CHILD_NODE
*Child
,
123 IN EFI_SECTION_TYPE SearchType
,
124 IN EFI_GUID
*SectionDefinitionGuid
129 RPN callback function. Removes a stale section stream and re-initializes it
130 with an updated AuthenticationStatus.
132 @param Event The event that fired
133 @param RpnContext A pointer to the context that allows us to
134 identify the relevent encapsulation...
140 NotifyGuidedExtraction (
148 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus
149 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears.
151 @param ParentStream Indicates the parent of the ecnapsulation
153 @param ChildNode Indicates the child node that is the
154 encapsulation section.
159 CreateGuidedExtractionRpnEvent (
160 IN CORE_SECTION_STREAM_NODE
*ParentStream
,
161 IN CORE_SECTION_CHILD_NODE
*ChildNode
166 Worker function. Search stream database for requested stream handle.
168 @param SearchHandle Indicates which stream to look for.
169 @param FoundStream Output pointer to the found stream.
171 @retval EFI_SUCCESS StreamHandle was found and *FoundStream contains
173 @retval EFI_NOT_FOUND SearchHandle was not found in the stream
180 IN UINTN SearchHandle
,
181 OUT CORE_SECTION_STREAM_NODE
**FoundStream
185 Worker function Recursively searches / builds section stream database
186 looking for requested section.
188 @param SourceStream Indicates the section stream in which to do the
190 @param SearchType Indicates the type of section to search for.
191 @param SectionInstance Indicates which instance of section to find.
192 This is an in/out parameter to deal with
194 @param SectionDefinitionGuid Guid of section definition
195 @param FoundChild Output indicating the child node that is found.
196 @param FoundStream Output indicating which section stream the child
197 was found in. If this stream was generated as a
198 result of an encapsulation section, the
199 streamhandle is visible within the SEP driver
201 @param AuthenticationStatus Indicates the authentication status of the found section.
203 @retval EFI_SUCCESS Child node was found and returned.
204 EFI_OUT_OF_RESOURCES- Memory allocation failed.
205 @retval EFI_NOT_FOUND Requested child node does not exist.
206 @retval EFI_PROTOCOL_ERROR a required GUIDED section extraction protocol
213 IN CORE_SECTION_STREAM_NODE
*SourceStream
,
214 IN EFI_SECTION_TYPE SearchType
,
215 IN UINTN
*SectionInstance
,
216 IN EFI_GUID
*SectionDefinitionGuid
,
217 OUT CORE_SECTION_CHILD_NODE
**FoundChild
,
218 OUT CORE_SECTION_STREAM_NODE
**FoundStream
,
219 OUT UINT32
*AuthenticationStatus
223 Worker function. Constructor for new child nodes.
225 @param Stream Indicates the section stream in which to add the
227 @param ChildOffset Indicates the offset in Stream that is the
228 beginning of the child section.
229 @param ChildNode Indicates the Callee allocated and initialized
232 @retval EFI_SUCCESS Child node was found and returned.
233 EFI_OUT_OF_RESOURCES- Memory allocation failed.
234 @retval EFI_PROTOCOL_ERROR Encapsulation sections produce new stream
235 handles when the child node is created. If the
236 section type is GUID defined, and the extraction
237 GUID does not exist, and producing the stream
238 requires the GUID, then a protocol error is
239 generated and no child is produced. Values
240 returned by OpenSectionStreamEx.
246 IN CORE_SECTION_STREAM_NODE
*Stream
,
247 IN UINT32 ChildOffset
,
248 OUT CORE_SECTION_CHILD_NODE
**ChildNode
252 Worker function. Destructor for child nodes.
254 @param ChildNode Indicates the node to destroy
260 IN CORE_SECTION_CHILD_NODE
*ChildNode
264 Worker function. Constructor for section streams.
266 @param SectionStreamLength Size in bytes of the section stream.
267 @param SectionStream Buffer containing the new section stream.
268 @param AllocateBuffer Indicates whether the stream buffer is to be
269 copied or the input buffer is to be used in
270 place. AuthenticationStatus- Indicates the
271 default authentication status for the new
273 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that
274 indicates the authentication status of the
275 output buffer. If the input section¡¯s
276 GuidedSectionHeader.Attributes field
277 has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
278 bit as clear, AuthenticationStatus must return
279 zero. Both local bits (19:16) and aggregate
280 bits (3:0) in AuthenticationStatus are returned
281 by ExtractSection(). These bits reflect the
282 status of the extraction operation. The bit
283 pattern in both regions must be the same, as
284 the local and aggregate authentication statuses
285 have equivalent meaning at this level. If the
286 function returns anything other than
287 EFI_SUCCESS, the value of *AuthenticationStatus
289 @param SectionStreamHandle A pointer to a caller allocated section stream
292 @retval EFI_SUCCESS Stream was added to stream database.
293 @retval EFI_OUT_OF_RESOURCES memory allocation failed.
298 OpenSectionStreamEx (
299 IN UINTN SectionStreamLength
,
300 IN VOID
*SectionStream
,
301 IN BOOLEAN AllocateBuffer
,
302 IN UINT32 AuthenticationStatus
,
303 OUT UINTN
*SectionStreamHandle
307 Check if a stream is valid.
309 @param SectionStream The section stream to be checked
310 @param SectionStreamLength The length of section stream
312 @return A boolean value indicating the validness of the section stream.
317 IsValidSectionStream (
318 IN VOID
*SectionStream
,
319 IN UINTN SectionStreamLength
323 The ExtractSection() function processes the input section and
324 allocates a buffer from the pool in which it returns the section
325 contents. If the section being extracted contains
326 authentication information (the section's
327 GuidedSectionHeader.Attributes field has the
328 EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values
329 returned in AuthenticationStatus must reflect the results of
330 the authentication operation. Depending on the algorithm and
331 size of the encapsulated data, the time that is required to do
332 a full authentication may be prohibitively long for some
333 classes of systems. To indicate this, use
334 EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by
335 the security policy driver (see the Platform Initialization
336 Driver Execution Environment Core Interface Specification for
337 more details and the GUID definition). If the
338 EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle
339 database, then, if possible, full authentication should be
340 skipped and the section contents simply returned in the
341 OutputBuffer. In this case, the
342 EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus
343 must be set on return. ExtractSection() is callable only from
344 TPL_NOTIFY and below. Behavior of ExtractSection() at any
345 EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is
346 defined in RaiseTPL() in the UEFI 2.0 specification.
349 @param This Indicates the
350 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.
352 @param InputSection Buffer containing the input GUIDed section
353 to be processed. OutputBuffer OutputBuffer
354 is allocated from boot services pool
355 memory and contains the new section
356 stream. The caller is responsible for
358 @param OutputBuffer *OutputBuffer is allocated from boot services
359 pool memory and contains the new section stream.
360 The caller is responsible for freeing this buffer.
361 @param OutputSize A pointer to a caller-allocated UINTN in
362 which the size of OutputBuffer allocation
363 is stored. If the function returns
364 anything other than EFI_SUCCESS, the value
365 of OutputSize is undefined.
367 @param AuthenticationStatus A pointer to a caller-allocated
368 UINT32 that indicates the
369 authentication status of the
370 output buffer. If the input
372 GuidedSectionHeader.Attributes
374 EFI_GUIDED_SECTION_AUTH_STATUS_VAL
375 bit as clear, AuthenticationStatus
376 must return zero. Both local bits
377 (19:16) and aggregate bits (3:0)
378 in AuthenticationStatus are
379 returned by ExtractSection().
380 These bits reflect the status of
381 the extraction operation. The bit
382 pattern in both regions must be
383 the same, as the local and
384 aggregate authentication statuses
385 have equivalent meaning at this
386 level. If the function returns
387 anything other than EFI_SUCCESS,
388 the value of AuthenticationStatus
392 @retval EFI_SUCCESS The InputSection was successfully
393 processed and the section contents were
396 @retval EFI_OUT_OF_RESOURCES The system has insufficient
397 resources to process the
400 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
401 not match this instance of the
402 GUIDed Section Extraction
408 CustomGuidedSectionExtract (
409 IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*This
,
410 IN CONST VOID
*InputSection
,
411 OUT VOID
**OutputBuffer
,
412 OUT UINTN
*OutputSize
,
413 OUT UINT32
*AuthenticationStatus
418 LIST_ENTRY mStreamRoot
= INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot
);
420 EFI_HANDLE mSectionExtractionHandle
= NULL
;
422 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol
= {
423 CustomGuidedSectionExtract
428 Entry point of the section extraction code. Initializes an instance of the
429 section extraction interface and installs it on a new handle.
431 @param ImageHandle A handle for the image that is initializing this driver
432 @param SystemTable A pointer to the EFI system table
434 @retval EFI_SUCCESS Driver initialized successfully
435 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
440 InitializeSectionExtraction (
441 IN EFI_HANDLE ImageHandle
,
442 IN EFI_SYSTEM_TABLE
*SystemTable
446 EFI_GUID
*ExtractHandlerGuidTable
;
447 UINTN ExtractHandlerNumber
;
450 // Get custom extract guided section method guid list
452 ExtractHandlerNumber
= ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable
);
454 Status
= EFI_SUCCESS
;
456 // Install custom guided extraction protocol
458 while (ExtractHandlerNumber
-- > 0) {
459 Status
= CoreInstallProtocolInterface (
460 &mSectionExtractionHandle
,
461 &ExtractHandlerGuidTable
[ExtractHandlerNumber
],
462 EFI_NATIVE_INTERFACE
,
463 &mCustomGuidedSectionExtractionProtocol
465 ASSERT_EFI_ERROR (Status
);
473 SEP member function. This function creates and returns a new section stream
474 handle to represent the new section stream.
476 @param SectionStreamLength Size in bytes of the section stream.
477 @param SectionStream Buffer containing the new section stream.
478 @param SectionStreamHandle A pointer to a caller allocated UINTN that on
479 output contains the new section stream handle.
481 @retval EFI_SUCCESS The section stream is created successfully.
482 @retval EFI_OUT_OF_RESOURCES memory allocation failed.
483 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end
490 IN UINTN SectionStreamLength
,
491 IN VOID
*SectionStream
,
492 OUT UINTN
*SectionStreamHandle
496 // Check to see section stream looks good...
498 if (!IsValidSectionStream (SectionStream
, SectionStreamLength
)) {
499 return EFI_INVALID_PARAMETER
;
502 return OpenSectionStreamEx (
513 SEP member function. Retrieves requested section from section stream.
515 @param SectionStreamHandle The section stream from which to extract the
517 @param SectionType A pointer to the type of section to search for.
518 @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED,
519 then SectionDefinitionGuid indicates which of
520 these types of sections to search for.
521 @param SectionInstance Indicates which instance of the requested
523 @param Buffer Double indirection to buffer. If *Buffer is
524 non-null on input, then the buffer is caller
525 allocated. If Buffer is NULL, then the buffer
526 is callee allocated. In either case, the
527 requried buffer size is returned in *BufferSize.
528 @param BufferSize On input, indicates the size of *Buffer if
529 *Buffer is non-null on input. On output,
530 indicates the required size (allocated size if
531 callee allocated) of *Buffer.
532 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that
533 indicates the authentication status of the
534 output buffer. If the input section¡¯s
535 GuidedSectionHeader.Attributes field
536 has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
537 bit as clear, AuthenticationStatus must return
538 zero. Both local bits (19:16) and aggregate
539 bits (3:0) in AuthenticationStatus are returned
540 by ExtractSection(). These bits reflect the
541 status of the extraction operation. The bit
542 pattern in both regions must be the same, as
543 the local and aggregate authentication statuses
544 have equivalent meaning at this level. If the
545 function returns anything other than
546 EFI_SUCCESS, the value of *AuthenticationStatus
549 @retval EFI_SUCCESS Section was retrieved successfully
550 @retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the
551 section stream with its
552 EFI_GUIDED_SECTION_PROCESSING_REQUIRED bit set,
553 but there was no corresponding GUIDed Section
554 Extraction Protocol in the handle database.
555 *Buffer is unmodified.
556 @retval EFI_NOT_FOUND An error was encountered when parsing the
557 SectionStream. This indicates the SectionStream
558 is not correctly formatted.
559 @retval EFI_NOT_FOUND The requested section does not exist.
560 @retval EFI_OUT_OF_RESOURCES The system has insufficient resources to process
562 @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
563 @retval EFI_WARN_TOO_SMALL The size of the caller allocated input buffer is
564 insufficient to contain the requested section.
565 The input buffer is filled and section contents
572 IN UINTN SectionStreamHandle
,
573 IN EFI_SECTION_TYPE
*SectionType
,
574 IN EFI_GUID
*SectionDefinitionGuid
,
575 IN UINTN SectionInstance
,
577 IN OUT UINTN
*BufferSize
,
578 OUT UINT32
*AuthenticationStatus
581 CORE_SECTION_STREAM_NODE
*StreamNode
;
584 CORE_SECTION_CHILD_NODE
*ChildNode
;
585 CORE_SECTION_STREAM_NODE
*ChildStreamNode
;
587 UINT32 ExtractedAuthenticationStatus
;
593 OldTpl
= CoreRaiseTpl (TPL_NOTIFY
);
594 Instance
= SectionInstance
+ 1;
597 // Locate target stream
599 Status
= FindStreamNode (SectionStreamHandle
, &StreamNode
);
600 if (EFI_ERROR (Status
)) {
601 Status
= EFI_INVALID_PARAMETER
;
602 goto GetSection_Done
;
606 // Found the stream, now locate and return the appropriate section
608 if (SectionType
== NULL
) {
610 // SectionType == NULL means return the WHOLE section stream...
612 CopySize
= StreamNode
->StreamLength
;
613 CopyBuffer
= StreamNode
->StreamBuffer
;
614 *AuthenticationStatus
= StreamNode
->AuthenticationStatus
;
617 // There's a requested section type, so go find it and return it...
619 Status
= FindChildNode (
623 SectionDefinitionGuid
,
626 &ExtractedAuthenticationStatus
628 if (EFI_ERROR (Status
)) {
629 goto GetSection_Done
;
631 CopySize
= ChildNode
->Size
- sizeof (EFI_COMMON_SECTION_HEADER
);
632 CopyBuffer
= ChildStreamNode
->StreamBuffer
+ ChildNode
->OffsetInStream
+ sizeof (EFI_COMMON_SECTION_HEADER
);
633 *AuthenticationStatus
= ExtractedAuthenticationStatus
;
636 SectionSize
= CopySize
;
637 if (*Buffer
!= NULL
) {
639 // Caller allocated buffer. Fill to size and return required size...
641 if (*BufferSize
< CopySize
) {
642 Status
= EFI_WARN_BUFFER_TOO_SMALL
;
643 CopySize
= *BufferSize
;
647 // Callee allocated buffer. Allocate buffer and return size.
649 *Buffer
= CoreAllocateBootServicesPool (CopySize
);
650 if (*Buffer
== NULL
) {
651 Status
= EFI_OUT_OF_RESOURCES
;
652 goto GetSection_Done
;
655 CopyMem (*Buffer
, CopyBuffer
, CopySize
);
656 *BufferSize
= SectionSize
;
659 CoreRestoreTpl (OldTpl
);
666 SEP member function. Deletes an existing section stream
668 @param StreamHandleToClose Indicates the stream to close
670 @retval EFI_SUCCESS The section stream is closed sucessfully.
671 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
672 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end
679 IN UINTN StreamHandleToClose
682 CORE_SECTION_STREAM_NODE
*StreamNode
;
686 CORE_SECTION_CHILD_NODE
*ChildNode
;
688 OldTpl
= CoreRaiseTpl (TPL_NOTIFY
);
691 // Locate target stream
693 Status
= FindStreamNode (StreamHandleToClose
, &StreamNode
);
694 if (!EFI_ERROR (Status
)) {
696 // Found the stream, so close it
698 RemoveEntryList (&StreamNode
->Link
);
699 while (!IsListEmpty (&StreamNode
->Children
)) {
700 Link
= GetFirstNode (&StreamNode
->Children
);
701 ChildNode
= CHILD_SECTION_NODE_FROM_LINK (Link
);
702 FreeChildNode (ChildNode
);
704 CoreFreePool (StreamNode
->StreamBuffer
);
705 CoreFreePool (StreamNode
);
706 Status
= EFI_SUCCESS
;
708 Status
= EFI_INVALID_PARAMETER
;
711 CoreRestoreTpl (OldTpl
);
718 Worker function. Determine if the input stream:child matches the input type.
720 @param Stream Indicates the section stream associated with the
722 @param Child Indicates the child to check
723 @param SearchType Indicates the type of section to check against
725 @param SectionDefinitionGuid Indicates the GUID to check against if the type
726 is EFI_SECTION_GUID_DEFINED
728 @retval TRUE The child matches
729 @retval FALSE The child doesn't match
735 IN CORE_SECTION_STREAM_NODE
*Stream
,
736 IN CORE_SECTION_CHILD_NODE
*Child
,
737 IN EFI_SECTION_TYPE SearchType
,
738 IN EFI_GUID
*SectionDefinitionGuid
741 EFI_GUID_DEFINED_SECTION
*GuidedSection
;
743 if (SearchType
== EFI_SECTION_ALL
) {
746 if (Child
->Type
!= SearchType
) {
749 if (SearchType
!= EFI_SECTION_GUID_DEFINED
) {
752 GuidedSection
= (EFI_GUID_DEFINED_SECTION
* )(Stream
->StreamBuffer
+ Child
->OffsetInStream
);
753 return CompareGuid (&GuidedSection
->SectionDefinitionGuid
, SectionDefinitionGuid
);
759 Worker function Recursively searches / builds section stream database
760 looking for requested section.
762 @param SourceStream Indicates the section stream in which to do the
764 @param SearchType Indicates the type of section to search for.
765 @param SectionInstance Indicates which instance of section to find.
766 This is an in/out parameter to deal with
768 @param SectionDefinitionGuid Guid of section definition
769 @param FoundChild Output indicating the child node that is found.
770 @param FoundStream Output indicating which section stream the child
771 was found in. If this stream was generated as a
772 result of an encapsulation section, the
773 streamhandle is visible within the SEP driver
775 @param AuthenticationStatus Indicates the authentication status of the found section.
777 @retval EFI_SUCCESS Child node was found and returned.
778 EFI_OUT_OF_RESOURCES- Memory allocation failed.
779 @retval EFI_NOT_FOUND Requested child node does not exist.
780 @retval EFI_PROTOCOL_ERROR a required GUIDED section extraction protocol
787 IN CORE_SECTION_STREAM_NODE
*SourceStream
,
788 IN EFI_SECTION_TYPE SearchType
,
789 IN OUT UINTN
*SectionInstance
,
790 IN EFI_GUID
*SectionDefinitionGuid
,
791 OUT CORE_SECTION_CHILD_NODE
**FoundChild
,
792 OUT CORE_SECTION_STREAM_NODE
**FoundStream
,
793 OUT UINT32
*AuthenticationStatus
796 CORE_SECTION_CHILD_NODE
*CurrentChildNode
;
797 CORE_SECTION_CHILD_NODE
*RecursedChildNode
;
798 CORE_SECTION_STREAM_NODE
*RecursedFoundStream
;
799 UINT32 NextChildOffset
;
800 EFI_STATUS ErrorStatus
;
803 CurrentChildNode
= NULL
;
804 ErrorStatus
= EFI_NOT_FOUND
;
806 if (SourceStream
->StreamLength
== 0) {
807 return EFI_NOT_FOUND
;
810 if (IsListEmpty (&SourceStream
->Children
) &&
811 SourceStream
->StreamLength
>= sizeof (EFI_COMMON_SECTION_HEADER
)) {
813 // This occurs when a section stream exists, but no child sections
814 // have been parsed out yet. Therefore, extract the first child and add it
815 // to the list of children so we can get started.
816 // Section stream may contain an array of zero or more bytes.
817 // So, its size should be >= the size of commen section header.
819 Status
= CreateChildNode (SourceStream
, 0, &CurrentChildNode
);
820 if (EFI_ERROR (Status
)) {
826 // At least one child has been parsed out of the section stream. So, walk
827 // through the sections that have already been parsed out looking for the
828 // requested section, if necessary, continue parsing section stream and
829 // adding children until either the requested section is found, or we run
832 CurrentChildNode
= CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream
->Children
));
835 if (ChildIsType (SourceStream
, CurrentChildNode
, SearchType
, SectionDefinitionGuid
)) {
837 // The type matches, so check the instance count to see if it's the one we want
839 (*SectionInstance
)--;
840 if (*SectionInstance
== 0) {
844 *FoundChild
= CurrentChildNode
;
845 *FoundStream
= SourceStream
;
846 *AuthenticationStatus
= SourceStream
->AuthenticationStatus
;
851 if (CurrentChildNode
->EncapsulatedStreamHandle
!= NULL_STREAM_HANDLE
) {
853 // If the current node is an encapsulating node, recurse into it...
855 Status
= FindChildNode (
856 (CORE_SECTION_STREAM_NODE
*)CurrentChildNode
->EncapsulatedStreamHandle
,
859 SectionDefinitionGuid
,
861 &RecursedFoundStream
,
865 // If the status is not EFI_SUCCESS, just save the error code and continue
866 // to find the request child node in the rest stream.
868 if (*SectionInstance
== 0) {
869 ASSERT_EFI_ERROR (Status
);
870 *FoundChild
= RecursedChildNode
;
871 *FoundStream
= RecursedFoundStream
;
874 ErrorStatus
= Status
;
878 if (!IsNodeAtEnd (&SourceStream
->Children
, &CurrentChildNode
->Link
)) {
880 // We haven't found the child node we're interested in yet, but there's
881 // still more nodes that have already been parsed so get the next one
882 // and continue searching..
884 CurrentChildNode
= CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream
->Children
, &CurrentChildNode
->Link
));
887 // We've exhausted children that have already been parsed, so see if
888 // there's any more data and continue parsing out more children if there
891 NextChildOffset
= CurrentChildNode
->OffsetInStream
+ CurrentChildNode
->Size
;
893 // Round up to 4 byte boundary
895 NextChildOffset
+= 3;
896 NextChildOffset
&= ~(UINTN
)3;
897 if (NextChildOffset
<= SourceStream
->StreamLength
- sizeof (EFI_COMMON_SECTION_HEADER
)) {
899 // There's an unparsed child remaining in the stream, so create a new child node
901 Status
= CreateChildNode (SourceStream
, NextChildOffset
, &CurrentChildNode
);
902 if (EFI_ERROR (Status
)) {
906 ASSERT (EFI_ERROR (ErrorStatus
));
916 Worker function. Constructor for new child nodes.
918 @param Stream Indicates the section stream in which to add the
920 @param ChildOffset Indicates the offset in Stream that is the
921 beginning of the child section.
922 @param ChildNode Indicates the Callee allocated and initialized
925 @retval EFI_SUCCESS Child node was found and returned.
926 EFI_OUT_OF_RESOURCES- Memory allocation failed.
927 @retval EFI_PROTOCOL_ERROR Encapsulation sections produce new stream
928 handles when the child node is created. If the
929 section type is GUID defined, and the extraction
930 GUID does not exist, and producing the stream
931 requires the GUID, then a protocol error is
932 generated and no child is produced. Values
933 returned by OpenSectionStreamEx.
939 IN CORE_SECTION_STREAM_NODE
*Stream
,
940 IN UINT32 ChildOffset
,
941 OUT CORE_SECTION_CHILD_NODE
**ChildNode
945 EFI_COMMON_SECTION_HEADER
*SectionHeader
;
946 EFI_COMPRESSION_SECTION
*CompressionHeader
;
947 EFI_GUID_DEFINED_SECTION
*GuidedHeader
;
948 EFI_DECOMPRESS_PROTOCOL
*Decompress
;
949 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*GuidedExtraction
;
950 VOID
*NewStreamBuffer
;
953 UINTN NewStreamBufferSize
;
954 UINT32 AuthenticationStatus
;
955 UINT32 SectionLength
;
957 CORE_SECTION_CHILD_NODE
*Node
;
959 SectionHeader
= (EFI_COMMON_SECTION_HEADER
*) (Stream
->StreamBuffer
+ ChildOffset
);
962 // Allocate a new node
964 *ChildNode
= CoreAllocateBootServicesPool (sizeof (CORE_SECTION_CHILD_NODE
));
967 return EFI_OUT_OF_RESOURCES
;
973 Node
->Signature
= CORE_SECTION_CHILD_SIGNATURE
;
974 Node
->Type
= SectionHeader
->Type
;
975 Node
->Size
= SECTION_SIZE (SectionHeader
);
976 Node
->OffsetInStream
= ChildOffset
;
977 Node
->EncapsulatedStreamHandle
= NULL_STREAM_HANDLE
;
978 Node
->EncapsulationGuid
= NULL
;
981 // If it's an encapsulating section, then create the new section stream also
983 switch (Node
->Type
) {
984 case EFI_SECTION_COMPRESSION
:
986 // Get the CompressionSectionHeader
988 ASSERT (Node
->Size
>= sizeof (EFI_COMPRESSION_SECTION
));
990 CompressionHeader
= (EFI_COMPRESSION_SECTION
*) SectionHeader
;
993 // Allocate space for the new stream
995 if (CompressionHeader
->UncompressedLength
> 0) {
996 NewStreamBufferSize
= CompressionHeader
->UncompressedLength
;
997 NewStreamBuffer
= CoreAllocateBootServicesPool (NewStreamBufferSize
);
998 if (NewStreamBuffer
== NULL
) {
1000 return EFI_OUT_OF_RESOURCES
;
1003 if (CompressionHeader
->CompressionType
== EFI_NOT_COMPRESSED
) {
1005 // stream is not actually compressed, just encapsulated. So just copy it.
1007 CopyMem (NewStreamBuffer
, CompressionHeader
+ 1, NewStreamBufferSize
);
1008 } else if (CompressionHeader
->CompressionType
== EFI_STANDARD_COMPRESSION
) {
1010 // Only support the EFI_SATNDARD_COMPRESSION algorithm.
1014 // Decompress the stream
1016 Status
= CoreLocateProtocol (&gEfiDecompressProtocolGuid
, NULL
, (VOID
**)&Decompress
);
1018 ASSERT_EFI_ERROR (Status
);
1020 Status
= Decompress
->GetInfo (
1022 CompressionHeader
+ 1,
1023 Node
->Size
- sizeof (EFI_COMPRESSION_SECTION
),
1024 (UINT32
*)&NewStreamBufferSize
,
1027 ASSERT_EFI_ERROR (Status
);
1028 ASSERT (NewStreamBufferSize
== CompressionHeader
->UncompressedLength
);
1030 ScratchBuffer
= CoreAllocateBootServicesPool (ScratchSize
);
1031 if (ScratchBuffer
== NULL
) {
1032 CoreFreePool (Node
);
1033 CoreFreePool (NewStreamBuffer
);
1034 return EFI_OUT_OF_RESOURCES
;
1037 Status
= Decompress
->Decompress (
1039 CompressionHeader
+ 1,
1040 Node
->Size
- sizeof (EFI_COMPRESSION_SECTION
),
1042 (UINT32
)NewStreamBufferSize
,
1046 ASSERT_EFI_ERROR (Status
);
1047 CoreFreePool (ScratchBuffer
);
1050 NewStreamBuffer
= NULL
;
1051 NewStreamBufferSize
= 0;
1054 Status
= OpenSectionStreamEx (
1055 NewStreamBufferSize
,
1058 Stream
->AuthenticationStatus
,
1059 &Node
->EncapsulatedStreamHandle
1061 if (EFI_ERROR (Status
)) {
1062 CoreFreePool (Node
);
1063 CoreFreePool (NewStreamBuffer
);
1068 case EFI_SECTION_GUID_DEFINED
:
1069 GuidedHeader
= (EFI_GUID_DEFINED_SECTION
*) SectionHeader
;
1070 Node
->EncapsulationGuid
= &GuidedHeader
->SectionDefinitionGuid
;
1071 Status
= CoreLocateProtocol (Node
->EncapsulationGuid
, NULL
, (VOID
**)&GuidedExtraction
);
1072 if (!EFI_ERROR (Status
)) {
1074 // NewStreamBuffer is always allocated by ExtractSection... No caller
1077 Status
= GuidedExtraction
->ExtractSection (
1081 &NewStreamBufferSize
,
1082 &AuthenticationStatus
1084 if (EFI_ERROR (Status
)) {
1085 CoreFreePool (*ChildNode
);
1086 return EFI_PROTOCOL_ERROR
;
1090 // Make sure we initialize the new stream with the correct
1091 // authentication status for both aggregate and local status fields.
1093 if (GuidedHeader
->Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
) {
1095 // OR in the parent stream's aggregate status.
1097 AuthenticationStatus
|= Stream
->AuthenticationStatus
& EFI_AUTH_STATUS_ALL
;
1100 // since there's no authentication data contributed by the section,
1101 // just inherit the full value from our immediate parent.
1103 AuthenticationStatus
= Stream
->AuthenticationStatus
;
1106 Status
= OpenSectionStreamEx (
1107 NewStreamBufferSize
,
1110 AuthenticationStatus
,
1111 &Node
->EncapsulatedStreamHandle
1113 if (EFI_ERROR (Status
)) {
1114 CoreFreePool (*ChildNode
);
1115 CoreFreePool (NewStreamBuffer
);
1120 // There's no GUIDed section extraction protocol available.
1122 if (GuidedHeader
->Attributes
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) {
1124 // If the section REQUIRES an extraction protocol, then we're toast
1126 CoreFreePool (*ChildNode
);
1127 return EFI_PROTOCOL_ERROR
;
1131 // Figure out the proper authentication status
1133 AuthenticationStatus
= Stream
->AuthenticationStatus
;
1135 SectionLength
= SECTION_SIZE (GuidedHeader
);
1136 Status
= OpenSectionStreamEx (
1137 SectionLength
- GuidedHeader
->DataOffset
,
1138 (UINT8
*) GuidedHeader
+ GuidedHeader
->DataOffset
,
1140 AuthenticationStatus
,
1141 &Node
->EncapsulatedStreamHandle
1143 if (EFI_ERROR (Status
)) {
1144 CoreFreePool (Node
);
1154 // Nothing to do if it's a leaf
1160 // Last, add the new child node to the stream
1162 InsertTailList (&Stream
->Children
, &Node
->Link
);
1170 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus
1171 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...
1173 @param ParentStream Indicates the parent of the ecnapsulation
1175 @param ChildNode Indicates the child node that is the
1176 encapsulation section.
1181 CreateGuidedExtractionRpnEvent (
1182 IN CORE_SECTION_STREAM_NODE
*ParentStream
,
1183 IN CORE_SECTION_CHILD_NODE
*ChildNode
1186 RPN_EVENT_CONTEXT
*Context
;
1189 // Allocate new event structure and context
1191 Context
= CoreAllocateBootServicesPool (sizeof (RPN_EVENT_CONTEXT
));
1192 ASSERT (Context
!= NULL
);
1194 Context
->ChildNode
= ChildNode
;
1195 Context
->ParentStream
= ParentStream
;
1197 Context
->Event
= CoreCreateProtocolNotifyEvent (
1198 Context
->ChildNode
->EncapsulationGuid
,
1200 NotifyGuidedExtraction
,
1202 &Context
->Registration
,
1211 RPN callback function. Removes a stale section stream and re-initializes it
1212 with an updated AuthenticationStatus.
1214 @param Event The event that fired
1215 @param RpnContext A pointer to the context that allows us to
1216 identify the relevent encapsulation...
1222 NotifyGuidedExtraction (
1228 EFI_GUID_DEFINED_SECTION
*GuidedHeader
;
1229 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*GuidedExtraction
;
1230 VOID
*NewStreamBuffer
;
1231 UINTN NewStreamBufferSize
;
1232 UINT32 AuthenticationStatus
;
1233 RPN_EVENT_CONTEXT
*Context
;
1235 Context
= RpnContext
;
1237 Status
= CloseSectionStream (Context
->ChildNode
->EncapsulatedStreamHandle
);
1238 if (!EFI_ERROR (Status
)) {
1240 // The stream closed successfully, so re-open the stream with correct AuthenticationStatus
1243 GuidedHeader
= (EFI_GUID_DEFINED_SECTION
*)
1244 (Context
->ParentStream
->StreamBuffer
+ Context
->ChildNode
->OffsetInStream
);
1245 ASSERT (GuidedHeader
->CommonHeader
.Type
== EFI_SECTION_GUID_DEFINED
);
1247 Status
= CoreLocateProtocol (Context
->ChildNode
->EncapsulationGuid
, NULL
, (VOID
**)&GuidedExtraction
);
1248 ASSERT_EFI_ERROR (Status
);
1251 Status
= GuidedExtraction
->ExtractSection (
1255 &NewStreamBufferSize
,
1256 &AuthenticationStatus
1258 ASSERT_EFI_ERROR (Status
);
1260 // OR in the parent stream's aggregagate status.
1262 AuthenticationStatus
|= Context
->ParentStream
->AuthenticationStatus
& EFI_AUTH_STATUS_ALL
;
1263 Status
= OpenSectionStreamEx (
1264 NewStreamBufferSize
,
1267 AuthenticationStatus
,
1268 &Context
->ChildNode
->EncapsulatedStreamHandle
1270 ASSERT_EFI_ERROR (Status
);
1274 // If above, the stream did not close successfully, it indicates it's
1275 // alread been closed by someone, so just destroy the event and be done with
1279 CoreCloseEvent (Event
);
1280 CoreFreePool (Context
);
1285 Worker function. Destructor for child nodes.
1287 @param ChildNode Indicates the node to destroy
1293 IN CORE_SECTION_CHILD_NODE
*ChildNode
1296 ASSERT (ChildNode
->Signature
== CORE_SECTION_CHILD_SIGNATURE
);
1298 // Remove the child from it's list
1300 RemoveEntryList (&ChildNode
->Link
);
1302 if (ChildNode
->EncapsulatedStreamHandle
!= NULL_STREAM_HANDLE
) {
1304 // If it's an encapsulating section, we close the resulting section stream.
1305 // CloseSectionStream will free all memory associated with the stream.
1307 CloseSectionStream (ChildNode
->EncapsulatedStreamHandle
);
1310 // Last, free the child node itself
1312 CoreFreePool (ChildNode
);
1318 Worker function. Constructor for section streams.
1320 @param SectionStreamLength Size in bytes of the section stream.
1321 @param SectionStream Buffer containing the new section stream.
1322 @param AllocateBuffer Indicates whether the stream buffer is to be
1323 copied or the input buffer is to be used in
1324 place. AuthenticationStatus- Indicates the
1325 default authentication status for the new
1327 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that
1328 indicates the authentication status of the
1329 output buffer. If the input section¡¯s
1330 GuidedSectionHeader.Attributes field
1331 has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
1332 bit as clear, AuthenticationStatus must return
1333 zero. Both local bits (19:16) and aggregate
1334 bits (3:0) in AuthenticationStatus are returned
1335 by ExtractSection(). These bits reflect the
1336 status of the extraction operation. The bit
1337 pattern in both regions must be the same, as
1338 the local and aggregate authentication statuses
1339 have equivalent meaning at this level. If the
1340 function returns anything other than
1341 EFI_SUCCESS, the value of *AuthenticationStatus
1343 @param SectionStreamHandle A pointer to a caller allocated section stream
1346 @retval EFI_SUCCESS Stream was added to stream database.
1347 @retval EFI_OUT_OF_RESOURCES memory allocation failed.
1352 OpenSectionStreamEx (
1353 IN UINTN SectionStreamLength
,
1354 IN VOID
*SectionStream
,
1355 IN BOOLEAN AllocateBuffer
,
1356 IN UINT32 AuthenticationStatus
,
1357 OUT UINTN
*SectionStreamHandle
1360 CORE_SECTION_STREAM_NODE
*NewStream
;
1364 // Allocate a new stream
1366 NewStream
= CoreAllocateBootServicesPool (sizeof (CORE_SECTION_STREAM_NODE
));
1367 if (NewStream
== NULL
) {
1368 return EFI_OUT_OF_RESOURCES
;
1371 if (AllocateBuffer
) {
1373 // if we're here, we're double buffering, allocate the buffer and copy the
1376 if (SectionStreamLength
> 0) {
1377 NewStream
->StreamBuffer
= CoreAllocateBootServicesPool (SectionStreamLength
);
1378 if (NewStream
->StreamBuffer
== NULL
) {
1379 CoreFreePool (NewStream
);
1380 return EFI_OUT_OF_RESOURCES
;
1383 // Copy in stream data
1385 CopyMem (NewStream
->StreamBuffer
, SectionStream
, SectionStreamLength
);
1388 // It's possible to have a zero length section stream.
1390 NewStream
->StreamBuffer
= NULL
;
1394 // If were here, the caller has supplied the buffer (it's an internal call)
1395 // so just assign the buffer. This happens when we open section streams
1396 // as a result of expanding an encapsulating section.
1398 NewStream
->StreamBuffer
= SectionStream
;
1402 // Initialize the rest of the section stream
1404 NewStream
->Signature
= CORE_SECTION_STREAM_SIGNATURE
;
1405 NewStream
->StreamHandle
= (UINTN
) NewStream
;
1406 NewStream
->StreamLength
= SectionStreamLength
;
1407 InitializeListHead (&NewStream
->Children
);
1408 NewStream
->AuthenticationStatus
= AuthenticationStatus
;
1411 // Add new stream to stream list
1413 OldTpl
= CoreRaiseTpl (TPL_NOTIFY
);
1414 InsertTailList (&mStreamRoot
, &NewStream
->Link
);
1415 CoreRestoreTpl (OldTpl
);
1417 *SectionStreamHandle
= NewStream
->StreamHandle
;
1425 Worker function. Search stream database for requested stream handle.
1427 @param SearchHandle Indicates which stream to look for.
1428 @param FoundStream Output pointer to the found stream.
1430 @retval EFI_SUCCESS StreamHandle was found and *FoundStream contains
1432 @retval EFI_NOT_FOUND SearchHandle was not found in the stream
1439 IN UINTN SearchHandle
,
1440 OUT CORE_SECTION_STREAM_NODE
**FoundStream
1443 CORE_SECTION_STREAM_NODE
*StreamNode
;
1445 if (!IsListEmpty (&mStreamRoot
)) {
1446 StreamNode
= STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot
));
1448 if (StreamNode
->StreamHandle
== SearchHandle
) {
1449 *FoundStream
= StreamNode
;
1451 } else if (IsNodeAtEnd (&mStreamRoot
, &StreamNode
->Link
)) {
1454 StreamNode
= STREAM_NODE_FROM_LINK (GetNextNode (&mStreamRoot
, &StreamNode
->Link
));
1459 return EFI_NOT_FOUND
;
1465 Check if a stream is valid.
1467 @param SectionStream The section stream to be checked
1468 @param SectionStreamLength The length of section stream
1470 @return A boolean value indicating the validness of the section stream.
1475 IsValidSectionStream (
1476 IN VOID
*SectionStream
,
1477 IN UINTN SectionStreamLength
1481 UINTN SectionLength
;
1482 EFI_COMMON_SECTION_HEADER
*SectionHeader
;
1483 EFI_COMMON_SECTION_HEADER
*NextSectionHeader
;
1486 SectionHeader
= (EFI_COMMON_SECTION_HEADER
*)SectionStream
;
1488 while (TotalLength
< SectionStreamLength
) {
1489 SectionLength
= SECTION_SIZE (SectionHeader
);
1490 TotalLength
+= SectionLength
;
1492 if (TotalLength
== SectionStreamLength
) {
1497 // Move to the next byte following the section...
1499 SectionHeader
= (EFI_COMMON_SECTION_HEADER
*) ((UINT8
*) SectionHeader
+ SectionLength
);
1502 // Figure out where the next section begins
1504 NextSectionHeader
= (EFI_COMMON_SECTION_HEADER
*) ((UINTN
) SectionHeader
+ 3);
1505 NextSectionHeader
= (EFI_COMMON_SECTION_HEADER
*) ((UINTN
) NextSectionHeader
& ~(UINTN
)3);
1506 TotalLength
+= (UINTN
) NextSectionHeader
- (UINTN
) SectionHeader
;
1507 SectionHeader
= NextSectionHeader
;
1515 The ExtractSection() function processes the input section and
1516 allocates a buffer from the pool in which it returns the section
1517 contents. If the section being extracted contains
1518 authentication information (the section's
1519 GuidedSectionHeader.Attributes field has the
1520 EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values
1521 returned in AuthenticationStatus must reflect the results of
1522 the authentication operation. Depending on the algorithm and
1523 size of the encapsulated data, the time that is required to do
1524 a full authentication may be prohibitively long for some
1525 classes of systems. To indicate this, use
1526 EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by
1527 the security policy driver (see the Platform Initialization
1528 Driver Execution Environment Core Interface Specification for
1529 more details and the GUID definition). If the
1530 EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle
1531 database, then, if possible, full authentication should be
1532 skipped and the section contents simply returned in the
1533 OutputBuffer. In this case, the
1534 EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus
1535 must be set on return. ExtractSection() is callable only from
1536 TPL_NOTIFY and below. Behavior of ExtractSection() at any
1537 EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is
1538 defined in RaiseTPL() in the UEFI 2.0 specification.
1541 @param This Indicates the
1542 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.
1544 @param InputSection Buffer containing the input GUIDed section
1545 to be processed. OutputBuffer OutputBuffer
1546 is allocated from boot services pool
1547 memory and contains the new section
1548 stream. The caller is responsible for
1549 freeing this buffer.
1550 @param OutputBuffer *OutputBuffer is allocated from boot services
1551 pool memory and contains the new section stream.
1552 The caller is responsible for freeing this buffer.
1553 @param OutputSize A pointer to a caller-allocated UINTN in
1554 which the size of OutputBuffer allocation
1555 is stored. If the function returns
1556 anything other than EFI_SUCCESS, the value
1557 of OutputSize is undefined.
1559 @param AuthenticationStatus A pointer to a caller-allocated
1560 UINT32 that indicates the
1561 authentication status of the
1562 output buffer. If the input
1564 GuidedSectionHeader.Attributes
1566 EFI_GUIDED_SECTION_AUTH_STATUS_VAL
1567 bit as clear, AuthenticationStatus
1568 must return zero. Both local bits
1569 (19:16) and aggregate bits (3:0)
1570 in AuthenticationStatus are
1571 returned by ExtractSection().
1572 These bits reflect the status of
1573 the extraction operation. The bit
1574 pattern in both regions must be
1575 the same, as the local and
1576 aggregate authentication statuses
1577 have equivalent meaning at this
1578 level. If the function returns
1579 anything other than EFI_SUCCESS,
1580 the value of AuthenticationStatus
1584 @retval EFI_SUCCESS The InputSection was successfully
1585 processed and the section contents were
1588 @retval EFI_OUT_OF_RESOURCES The system has insufficient
1589 resources to process the
1592 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
1593 not match this instance of the
1594 GUIDed Section Extraction
1600 CustomGuidedSectionExtract (
1601 IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*This
,
1602 IN CONST VOID
*InputSection
,
1603 OUT VOID
**OutputBuffer
,
1604 OUT UINTN
*OutputSize
,
1605 OUT UINT32
*AuthenticationStatus
1609 VOID
*ScratchBuffer
;
1610 VOID
*AllocatedOutputBuffer
;
1611 UINT32 OutputBufferSize
;
1612 UINT32 ScratchBufferSize
;
1613 UINT16 SectionAttribute
;
1616 // Init local variable
1618 ScratchBuffer
= NULL
;
1619 AllocatedOutputBuffer
= NULL
;
1622 // Call GetInfo to get the size and attribute of input guided section data.
1624 Status
= ExtractGuidedSectionGetInfo (
1631 if (EFI_ERROR (Status
)) {
1632 DEBUG ((DEBUG_ERROR
, "GetInfo from guided section Failed - %r\n", Status
));
1636 if (ScratchBufferSize
!= 0) {
1638 // Allocate scratch buffer
1640 ScratchBuffer
= CoreAllocateBootServicesPool (ScratchBufferSize
);
1641 if (ScratchBuffer
== NULL
) {
1642 return EFI_OUT_OF_RESOURCES
;
1646 if (OutputBufferSize
> 0) {
1648 // Allocate output buffer
1650 AllocatedOutputBuffer
= CoreAllocateBootServicesPool (OutputBufferSize
);
1651 if (AllocatedOutputBuffer
== NULL
) {
1652 return EFI_OUT_OF_RESOURCES
;
1654 *OutputBuffer
= AllocatedOutputBuffer
;
1658 // Call decode function to extract raw data from the guided section.
1660 Status
= ExtractGuidedSectionDecode (
1664 AuthenticationStatus
1666 if (EFI_ERROR (Status
)) {
1670 if (AllocatedOutputBuffer
!= NULL
) {
1671 CoreFreePool (AllocatedOutputBuffer
);
1673 if (ScratchBuffer
!= NULL
) {
1674 CoreFreePool (ScratchBuffer
);
1676 DEBUG ((DEBUG_ERROR
, "Extract guided section Failed - %r\n", Status
));
1680 if (*OutputBuffer
!= AllocatedOutputBuffer
) {
1682 // OutputBuffer was returned as a different value,
1683 // so copy section contents to the allocated memory buffer.
1685 CopyMem (AllocatedOutputBuffer
, *OutputBuffer
, OutputBufferSize
);
1686 *OutputBuffer
= AllocatedOutputBuffer
;
1690 // Set real size of output buffer.
1692 *OutputSize
= (UINTN
) OutputBufferSize
;
1695 // Free unused scratch buffer.
1697 if (ScratchBuffer
!= NULL
) {
1698 CoreFreePool (ScratchBuffer
);