2008-05-09 09:08:30 +02:00
|
|
|
/** @file
|
2007-07-04 12:51:54 +02:00
|
|
|
Section Extraction Protocol implementation.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Stream database is implemented as a linked list of section streams,
|
|
|
|
where each stream contains a linked list of children, which may be leaves or
|
2008-07-24 04:54:45 +02:00
|
|
|
encapsulations.
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Children that are encapsulations generate new stream entries
|
2008-07-24 04:54:45 +02:00
|
|
|
when they are created. Streams can also be created by calls to
|
2007-07-04 12:51:54 +02:00
|
|
|
SEP->OpenSectionStream().
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
The database is only created far enough to return the requested data from
|
|
|
|
any given stream, or to determine that the requested data is not found.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
If a GUIDed encapsulation is encountered, there are three possiblilites.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
1) A support protocol is found, in which the stream is simply processed with
|
|
|
|
the support protocol.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
2) A support protocol is not found, but the data is available to be read
|
|
|
|
without processing. In this case, the database is built up through the
|
|
|
|
recursions to return the data, and a RPN event is set that will enable
|
|
|
|
the stream in question to be refreshed if and when the required section
|
2008-07-24 04:54:45 +02:00
|
|
|
extraction protocol is published.This insures the AuthenticationStatus
|
2007-07-04 12:51:54 +02:00
|
|
|
does not become stale in the cache.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
3) A support protocol is not found, and the data is not available to be read
|
|
|
|
without it. This results in EFI_PROTOCOL_ERROR.
|
2008-05-21 03:40:12 +02:00
|
|
|
|
2016-07-08 08:21:04 +02:00
|
|
|
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2008-05-21 03:40:12 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-12-10 04:47:56 +01:00
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Local defines and typedefs
|
|
|
|
//
|
2008-12-16 16:34:21 +01:00
|
|
|
#define CORE_SECTION_CHILD_SIGNATURE SIGNATURE_32('S','X','C','S')
|
2007-07-04 12:51:54 +02:00
|
|
|
#define CHILD_SECTION_NODE_FROM_LINK(Node) \
|
|
|
|
CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UINT32 Signature;
|
|
|
|
LIST_ENTRY Link;
|
|
|
|
UINT32 Type;
|
|
|
|
UINT32 Size;
|
|
|
|
//
|
|
|
|
// StreamBase + OffsetInStream == pointer to section header in stream. The
|
|
|
|
// stream base is always known when walking the sections within.
|
|
|
|
//
|
|
|
|
UINT32 OffsetInStream;
|
|
|
|
//
|
|
|
|
// Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
|
|
|
|
// encapsulating section. Otherwise, it contains the stream handle
|
|
|
|
// of the encapsulated stream. This handle is ALWAYS produced any time an
|
|
|
|
// encapsulating child is encountered, irrespective of whether the
|
|
|
|
// encapsulated stream is processed further.
|
|
|
|
//
|
|
|
|
UINTN EncapsulatedStreamHandle;
|
|
|
|
EFI_GUID *EncapsulationGuid;
|
2012-07-27 04:35:24 +02:00
|
|
|
//
|
|
|
|
// If the section REQUIRES an extraction protocol, register for RPN
|
|
|
|
// when the required GUIDed extraction protocol becomes available.
|
|
|
|
//
|
|
|
|
EFI_EVENT Event;
|
2007-07-04 12:51:54 +02:00
|
|
|
} CORE_SECTION_CHILD_NODE;
|
|
|
|
|
2008-12-16 16:34:21 +01:00
|
|
|
#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
|
2007-07-04 12:51:54 +02:00
|
|
|
#define STREAM_NODE_FROM_LINK(Node) \
|
|
|
|
CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UINT32 Signature;
|
|
|
|
LIST_ENTRY Link;
|
|
|
|
UINTN StreamHandle;
|
|
|
|
UINT8 *StreamBuffer;
|
|
|
|
UINTN StreamLength;
|
|
|
|
LIST_ENTRY Children;
|
|
|
|
//
|
|
|
|
// Authentication status is from GUIDed encapsulations.
|
|
|
|
//
|
|
|
|
UINT32 AuthenticationStatus;
|
|
|
|
} CORE_SECTION_STREAM_NODE;
|
|
|
|
|
|
|
|
#define NULL_STREAM_HANDLE 0
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
CORE_SECTION_CHILD_NODE *ChildNode;
|
|
|
|
CORE_SECTION_STREAM_NODE *ParentStream;
|
|
|
|
VOID *Registration;
|
|
|
|
} RPN_EVENT_CONTEXT;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
The ExtractSection() function processes the input section and
|
|
|
|
allocates a buffer from the pool in which it returns the section
|
|
|
|
contents. If the section being extracted contains
|
|
|
|
authentication information (the section's
|
|
|
|
GuidedSectionHeader.Attributes field has the
|
|
|
|
EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values
|
|
|
|
returned in AuthenticationStatus must reflect the results of
|
|
|
|
the authentication operation. Depending on the algorithm and
|
|
|
|
size of the encapsulated data, the time that is required to do
|
|
|
|
a full authentication may be prohibitively long for some
|
|
|
|
classes of systems. To indicate this, use
|
|
|
|
EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by
|
|
|
|
the security policy driver (see the Platform Initialization
|
|
|
|
Driver Execution Environment Core Interface Specification for
|
|
|
|
more details and the GUID definition). If the
|
|
|
|
EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle
|
|
|
|
database, then, if possible, full authentication should be
|
|
|
|
skipped and the section contents simply returned in the
|
|
|
|
OutputBuffer. In this case, the
|
|
|
|
EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus
|
|
|
|
must be set on return. ExtractSection() is callable only from
|
|
|
|
TPL_NOTIFY and below. Behavior of ExtractSection() at any
|
|
|
|
EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is
|
|
|
|
defined in RaiseTPL() in the UEFI 2.0 specification.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@param This Indicates the
|
|
|
|
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.
|
|
|
|
@param InputSection Buffer containing the input GUIDed section
|
|
|
|
to be processed. OutputBuffer OutputBuffer
|
|
|
|
is allocated from boot services pool
|
|
|
|
memory and contains the new section
|
|
|
|
stream. The caller is responsible for
|
|
|
|
freeing this buffer.
|
|
|
|
@param OutputBuffer *OutputBuffer is allocated from boot services
|
|
|
|
pool memory and contains the new section stream.
|
|
|
|
The caller is responsible for freeing this buffer.
|
|
|
|
@param OutputSize A pointer to a caller-allocated UINTN in
|
|
|
|
which the size of OutputBuffer allocation
|
|
|
|
is stored. If the function returns
|
|
|
|
anything other than EFI_SUCCESS, the value
|
|
|
|
of OutputSize is undefined.
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@param AuthenticationStatus A pointer to a caller-allocated
|
|
|
|
UINT32 that indicates the
|
|
|
|
authentication status of the
|
|
|
|
output buffer. If the input
|
|
|
|
section's
|
|
|
|
GuidedSectionHeader.Attributes
|
|
|
|
field has the
|
|
|
|
EFI_GUIDED_SECTION_AUTH_STATUS_VAL
|
|
|
|
bit as clear, AuthenticationStatus
|
|
|
|
must return zero. Both local bits
|
|
|
|
(19:16) and aggregate bits (3:0)
|
|
|
|
in AuthenticationStatus are
|
|
|
|
returned by ExtractSection().
|
|
|
|
These bits reflect the status of
|
|
|
|
the extraction operation. The bit
|
|
|
|
pattern in both regions must be
|
|
|
|
the same, as the local and
|
|
|
|
aggregate authentication statuses
|
|
|
|
have equivalent meaning at this
|
|
|
|
level. If the function returns
|
|
|
|
anything other than EFI_SUCCESS,
|
|
|
|
the value of AuthenticationStatus
|
|
|
|
is undefined.
|
|
|
|
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The InputSection was successfully
|
|
|
|
processed and the section contents were
|
|
|
|
returned.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES The system has insufficient
|
|
|
|
resources to process the
|
|
|
|
request.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER The GUID in InputSection does
|
|
|
|
not match this instance of the
|
|
|
|
GUIDed Section Extraction
|
|
|
|
Protocol.
|
|
|
|
|
|
|
|
**/
|
2007-08-08 12:17:57 +02:00
|
|
|
EFI_STATUS
|
2007-12-10 04:47:56 +01:00
|
|
|
EFIAPI
|
2007-09-29 10:04:29 +02:00
|
|
|
CustomGuidedSectionExtract (
|
2008-05-21 03:40:12 +02:00
|
|
|
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
|
2007-08-08 12:17:57 +02:00
|
|
|
IN CONST VOID *InputSection,
|
|
|
|
OUT VOID **OutputBuffer,
|
|
|
|
OUT UINTN *OutputSize,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
2008-07-24 04:54:45 +02:00
|
|
|
);
|
2008-07-18 11:50:09 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Module globals
|
|
|
|
//
|
|
|
|
LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
|
|
|
|
|
|
|
|
EFI_HANDLE mSectionExtractionHandle = NULL;
|
|
|
|
|
2007-09-29 10:04:29 +02:00
|
|
|
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
|
|
|
|
CustomGuidedSectionExtract
|
2007-08-08 12:17:57 +02:00
|
|
|
};
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Entry point of the section extraction code. Initializes an instance of the
|
|
|
|
section extraction interface and installs it on a new handle.
|
|
|
|
|
|
|
|
@param ImageHandle A handle for the image that is initializing this driver
|
|
|
|
@param SystemTable A pointer to the EFI system table
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Driver initialized successfully
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InitializeSectionExtraction (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2007-09-29 10:04:29 +02:00
|
|
|
EFI_GUID *ExtractHandlerGuidTable;
|
|
|
|
UINTN ExtractHandlerNumber;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// Get custom extract guided section method guid list
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-12-10 04:47:56 +01:00
|
|
|
Status = EFI_SUCCESS;
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// Install custom guided extraction protocol
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
while (ExtractHandlerNumber-- > 0) {
|
2007-08-08 12:17:57 +02:00
|
|
|
Status = CoreInstallProtocolInterface (
|
|
|
|
&mSectionExtractionHandle,
|
2007-09-29 10:04:29 +02:00
|
|
|
&ExtractHandlerGuidTable [ExtractHandlerNumber],
|
2007-08-08 12:17:57 +02:00
|
|
|
EFI_NATIVE_INTERFACE,
|
2007-09-29 10:04:29 +02:00
|
|
|
&mCustomGuidedSectionExtractionProtocol
|
2007-08-08 12:17:57 +02:00
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
2008-08-28 04:53:16 +02:00
|
|
|
Check if a stream is valid.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@param SectionStream The section stream to be checked
|
|
|
|
@param SectionStreamLength The length of section stream
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@return A boolean value indicating the validness of the section stream.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
**/
|
2008-08-28 04:53:16 +02:00
|
|
|
BOOLEAN
|
|
|
|
IsValidSectionStream (
|
|
|
|
IN VOID *SectionStream,
|
|
|
|
IN UINTN SectionStreamLength
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
2008-08-28 04:53:16 +02:00
|
|
|
UINTN TotalLength;
|
|
|
|
UINTN SectionLength;
|
|
|
|
EFI_COMMON_SECTION_HEADER *SectionHeader;
|
|
|
|
EFI_COMMON_SECTION_HEADER *NextSectionHeader;
|
|
|
|
|
|
|
|
TotalLength = 0;
|
|
|
|
SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;
|
|
|
|
|
|
|
|
while (TotalLength < SectionStreamLength) {
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (SectionHeader)) {
|
|
|
|
SectionLength = SECTION2_SIZE (SectionHeader);
|
|
|
|
} else {
|
|
|
|
SectionLength = SECTION_SIZE (SectionHeader);
|
|
|
|
}
|
2008-08-28 04:53:16 +02:00
|
|
|
TotalLength += SectionLength;
|
|
|
|
|
|
|
|
if (TotalLength == SectionStreamLength) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Move to the next byte following the section...
|
|
|
|
//
|
|
|
|
SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Figure out where the next section begins
|
|
|
|
//
|
|
|
|
NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);
|
|
|
|
TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;
|
|
|
|
SectionHeader = NextSectionHeader;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
ASSERT (FALSE);
|
|
|
|
return FALSE;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
2008-08-28 04:53:16 +02:00
|
|
|
Worker function. Constructor for section streams.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@param SectionStreamLength Size in bytes of the section stream.
|
|
|
|
@param SectionStream Buffer containing the new section stream.
|
|
|
|
@param AllocateBuffer Indicates whether the stream buffer is to be
|
|
|
|
copied or the input buffer is to be used in
|
|
|
|
place. AuthenticationStatus- Indicates the
|
|
|
|
default authentication status for the new
|
|
|
|
stream.
|
|
|
|
@param AuthenticationStatus A pointer to a caller-allocated UINT32 that
|
|
|
|
indicates the authentication status of the
|
|
|
|
output buffer. If the input section's
|
|
|
|
GuidedSectionHeader.Attributes field
|
|
|
|
has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
|
|
|
|
bit as clear, AuthenticationStatus must return
|
|
|
|
zero. Both local bits (19:16) and aggregate
|
|
|
|
bits (3:0) in AuthenticationStatus are returned
|
|
|
|
by ExtractSection(). These bits reflect the
|
|
|
|
status of the extraction operation. The bit
|
|
|
|
pattern in both regions must be the same, as
|
|
|
|
the local and aggregate authentication statuses
|
|
|
|
have equivalent meaning at this level. If the
|
|
|
|
function returns anything other than
|
|
|
|
EFI_SUCCESS, the value of *AuthenticationStatus
|
|
|
|
is undefined.
|
|
|
|
@param SectionStreamHandle A pointer to a caller allocated section stream
|
|
|
|
handle.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@retval EFI_SUCCESS Stream was added to stream database.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES memory allocation failed.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
2008-08-28 04:53:16 +02:00
|
|
|
OpenSectionStreamEx (
|
|
|
|
IN UINTN SectionStreamLength,
|
|
|
|
IN VOID *SectionStream,
|
|
|
|
IN BOOLEAN AllocateBuffer,
|
|
|
|
IN UINT32 AuthenticationStatus,
|
|
|
|
OUT UINTN *SectionStreamHandle
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
2008-08-28 04:53:16 +02:00
|
|
|
CORE_SECTION_STREAM_NODE *NewStream;
|
|
|
|
EFI_TPL OldTpl;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// Allocate a new stream
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
NewStream = AllocatePool (sizeof (CORE_SECTION_STREAM_NODE));
|
|
|
|
if (NewStream == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2008-07-24 04:54:45 +02:00
|
|
|
}
|
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
if (AllocateBuffer) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// if we're here, we're double buffering, allocate the buffer and copy the
|
|
|
|
// data in
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
if (SectionStreamLength > 0) {
|
|
|
|
NewStream->StreamBuffer = AllocatePool (SectionStreamLength);
|
|
|
|
if (NewStream->StreamBuffer == NULL) {
|
|
|
|
CoreFreePool (NewStream);
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Copy in stream data
|
|
|
|
//
|
|
|
|
CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// It's possible to have a zero length section stream.
|
|
|
|
//
|
|
|
|
NewStream->StreamBuffer = NULL;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// If were here, the caller has supplied the buffer (it's an internal call)
|
|
|
|
// so just assign the buffer. This happens when we open section streams
|
|
|
|
// as a result of expanding an encapsulating section.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
NewStream->StreamBuffer = SectionStream;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
//
|
|
|
|
// Initialize the rest of the section stream
|
|
|
|
//
|
|
|
|
NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;
|
|
|
|
NewStream->StreamHandle = (UINTN) NewStream;
|
|
|
|
NewStream->StreamLength = SectionStreamLength;
|
|
|
|
InitializeListHead (&NewStream->Children);
|
|
|
|
NewStream->AuthenticationStatus = AuthenticationStatus;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add new stream to stream list
|
|
|
|
//
|
|
|
|
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
|
|
|
|
InsertTailList (&mStreamRoot, &NewStream->Link);
|
2007-07-04 12:51:54 +02:00
|
|
|
CoreRestoreTpl (OldTpl);
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
*SectionStreamHandle = NewStream->StreamHandle;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2008-08-28 04:53:16 +02:00
|
|
|
SEP member function. This function creates and returns a new section stream
|
|
|
|
handle to represent the new section stream.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@param SectionStreamLength Size in bytes of the section stream.
|
|
|
|
@param SectionStream Buffer containing the new section stream.
|
|
|
|
@param SectionStreamHandle A pointer to a caller allocated UINTN that on
|
|
|
|
output contains the new section stream handle.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@retval EFI_SUCCESS The section stream is created successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES memory allocation failed.
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Section stream does not end concident with end
|
2008-05-09 09:08:30 +02:00
|
|
|
of last section.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-08-28 04:53:16 +02:00
|
|
|
OpenSectionStream (
|
|
|
|
IN UINTN SectionStreamLength,
|
|
|
|
IN VOID *SectionStream,
|
|
|
|
OUT UINTN *SectionStreamHandle
|
2008-05-09 09:08:30 +02:00
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// Check to see section stream looks good...
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
return OpenSectionStreamEx (
|
|
|
|
SectionStreamLength,
|
|
|
|
SectionStream,
|
2014-08-27 10:31:44 +02:00
|
|
|
FALSE,
|
2008-08-28 04:53:16 +02:00
|
|
|
0,
|
|
|
|
SectionStreamHandle
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Worker function. Determine if the input stream:child matches the input type.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Stream Indicates the section stream associated with the
|
|
|
|
child
|
|
|
|
@param Child Indicates the child to check
|
|
|
|
@param SearchType Indicates the type of section to check against
|
|
|
|
for
|
|
|
|
@param SectionDefinitionGuid Indicates the GUID to check against if the type
|
|
|
|
is EFI_SECTION_GUID_DEFINED
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval TRUE The child matches
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval FALSE The child doesn't match
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
BOOLEAN
|
|
|
|
ChildIsType (
|
|
|
|
IN CORE_SECTION_STREAM_NODE *Stream,
|
|
|
|
IN CORE_SECTION_CHILD_NODE *Child,
|
|
|
|
IN EFI_SECTION_TYPE SearchType,
|
|
|
|
IN EFI_GUID *SectionDefinitionGuid
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_GUID_DEFINED_SECTION *GuidedSection;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (SearchType == EFI_SECTION_ALL) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (Child->Type != SearchType) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-21 04:40:36 +02:00
|
|
|
if ((SearchType != EFI_SECTION_GUID_DEFINED) || (SectionDefinitionGuid == NULL)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (GuidedSection)) {
|
|
|
|
return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
|
|
|
|
} else {
|
|
|
|
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-08 02:12:56 +01:00
|
|
|
/**
|
|
|
|
Verify the Guided Section GUID by checking if there is the Guided Section GUID configuration table recorded the GUID itself.
|
|
|
|
|
|
|
|
@param GuidedSectionGuid The Guided Section GUID.
|
|
|
|
@param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Protocol
|
|
|
|
for the Guided Section.
|
|
|
|
|
|
|
|
@return TRUE The GuidedSectionGuid could be identified, and the pointer to
|
|
|
|
the Guided Section Extraction Protocol will be returned to *GuidedSectionExtraction.
|
|
|
|
@return FALSE The GuidedSectionGuid could not be identified, or
|
|
|
|
the Guided Section Extraction Protocol has not been installed yet.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
VerifyGuidedSectionGuid (
|
|
|
|
IN EFI_GUID *GuidedSectionGuid,
|
|
|
|
OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_GUID *GuidRecorded;
|
|
|
|
VOID *Interface;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2014-07-28 09:52:57 +02:00
|
|
|
Interface = NULL;
|
|
|
|
|
2012-11-08 02:12:56 +01:00
|
|
|
//
|
|
|
|
// Check if there is the Guided Section GUID configuration table recorded the GUID itself.
|
|
|
|
//
|
|
|
|
Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **) &GuidRecorded);
|
|
|
|
if (Status == EFI_SUCCESS) {
|
|
|
|
if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {
|
|
|
|
//
|
|
|
|
// Found the recorded GuidedSectionGuid.
|
|
|
|
//
|
|
|
|
Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **) &Interface);
|
|
|
|
if (!EFI_ERROR (Status) && Interface != NULL) {
|
|
|
|
//
|
|
|
|
// Found the supported Guided Section Extraction Porotocol for the Guided Section.
|
|
|
|
//
|
|
|
|
*GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *) Interface;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-28 03:12:18 +02:00
|
|
|
/**
|
|
|
|
RPN callback function. Initializes the section stream
|
|
|
|
when GUIDED_SECTION_EXTRACTION_PROTOCOL is installed.
|
|
|
|
|
|
|
|
@param Event The event that fired
|
|
|
|
@param RpnContext A pointer to the context that allows us to identify
|
|
|
|
the relevent encapsulation.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
NotifyGuidedExtraction (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *RpnContext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_GUID_DEFINED_SECTION *GuidedHeader;
|
|
|
|
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
|
|
|
|
VOID *NewStreamBuffer;
|
|
|
|
UINTN NewStreamBufferSize;
|
|
|
|
UINT32 AuthenticationStatus;
|
|
|
|
RPN_EVENT_CONTEXT *Context;
|
|
|
|
|
|
|
|
Context = RpnContext;
|
|
|
|
|
|
|
|
GuidedHeader = (EFI_GUID_DEFINED_SECTION *) (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
|
|
|
|
ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);
|
2012-11-08 02:12:56 +01:00
|
|
|
|
|
|
|
if (!VerifyGuidedSectionGuid (Context->ChildNode->EncapsulationGuid, &GuidedExtraction)) {
|
2010-07-28 03:12:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-11-08 02:12:56 +01:00
|
|
|
|
2010-07-28 03:12:18 +02:00
|
|
|
Status = GuidedExtraction->ExtractSection (
|
|
|
|
GuidedExtraction,
|
|
|
|
GuidedHeader,
|
|
|
|
&NewStreamBuffer,
|
|
|
|
&NewStreamBufferSize,
|
|
|
|
&AuthenticationStatus
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Make sure we initialize the new stream with the correct
|
|
|
|
// authentication status for both aggregate and local status fields.
|
|
|
|
//
|
|
|
|
if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {
|
|
|
|
//
|
|
|
|
// OR in the parent stream's aggregate status.
|
|
|
|
//
|
|
|
|
AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AUTH_STATUS_ALL;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// since there's no authentication data contributed by the section,
|
|
|
|
// just inherit the full value from our immediate parent.
|
|
|
|
//
|
|
|
|
AuthenticationStatus = Context->ParentStream->AuthenticationStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = OpenSectionStreamEx (
|
|
|
|
NewStreamBufferSize,
|
|
|
|
NewStreamBuffer,
|
|
|
|
FALSE,
|
|
|
|
AuthenticationStatus,
|
|
|
|
&Context->ChildNode->EncapsulatedStreamHandle
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Close the event when done.
|
|
|
|
//
|
|
|
|
gBS->CloseEvent (Event);
|
2012-07-27 04:35:24 +02:00
|
|
|
Context->ChildNode->Event = NULL;
|
2010-07-28 03:12:18 +02:00
|
|
|
FreePool (Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor for RPN event when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...
|
|
|
|
|
|
|
|
@param ParentStream Indicates the parent of the ecnapsulation section (child)
|
|
|
|
@param ChildNode Indicates the child node that is the encapsulation section.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CreateGuidedExtractionRpnEvent (
|
|
|
|
IN CORE_SECTION_STREAM_NODE *ParentStream,
|
|
|
|
IN CORE_SECTION_CHILD_NODE *ChildNode
|
|
|
|
)
|
|
|
|
{
|
|
|
|
RPN_EVENT_CONTEXT *Context;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate new event structure and context
|
|
|
|
//
|
|
|
|
Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));
|
|
|
|
ASSERT (Context != NULL);
|
|
|
|
|
|
|
|
Context->ChildNode = ChildNode;
|
|
|
|
Context->ParentStream = ParentStream;
|
|
|
|
|
2012-07-27 04:35:24 +02:00
|
|
|
Context->ChildNode->Event = EfiCreateProtocolNotifyEvent (
|
|
|
|
Context->ChildNode->EncapsulationGuid,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
NotifyGuidedExtraction,
|
|
|
|
Context,
|
|
|
|
&Context->Registration
|
|
|
|
);
|
2010-07-28 03:12:18 +02:00
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Worker function. Constructor for new child nodes.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Stream Indicates the section stream in which to add the
|
|
|
|
child.
|
|
|
|
@param ChildOffset Indicates the offset in Stream that is the
|
|
|
|
beginning of the child section.
|
|
|
|
@param ChildNode Indicates the Callee allocated and initialized
|
|
|
|
child.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Child node was found and returned.
|
|
|
|
EFI_OUT_OF_RESOURCES- Memory allocation failed.
|
|
|
|
@retval EFI_PROTOCOL_ERROR Encapsulation sections produce new stream
|
|
|
|
handles when the child node is created. If the
|
|
|
|
section type is GUID defined, and the extraction
|
|
|
|
GUID does not exist, and producing the stream
|
|
|
|
requires the GUID, then a protocol error is
|
|
|
|
generated and no child is produced. Values
|
2008-05-09 09:08:30 +02:00
|
|
|
returned by OpenSectionStreamEx.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
CreateChildNode (
|
|
|
|
IN CORE_SECTION_STREAM_NODE *Stream,
|
|
|
|
IN UINT32 ChildOffset,
|
2012-03-13 09:06:16 +01:00
|
|
|
OUT CORE_SECTION_CHILD_NODE **ChildNode
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_COMMON_SECTION_HEADER *SectionHeader;
|
|
|
|
EFI_COMPRESSION_SECTION *CompressionHeader;
|
|
|
|
EFI_GUID_DEFINED_SECTION *GuidedHeader;
|
2007-08-08 12:17:57 +02:00
|
|
|
EFI_DECOMPRESS_PROTOCOL *Decompress;
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
|
|
|
|
VOID *NewStreamBuffer;
|
|
|
|
VOID *ScratchBuffer;
|
|
|
|
UINT32 ScratchSize;
|
|
|
|
UINTN NewStreamBufferSize;
|
|
|
|
UINT32 AuthenticationStatus;
|
2011-10-27 11:23:19 +02:00
|
|
|
VOID *CompressionSource;
|
|
|
|
UINT32 CompressionSourceSize;
|
|
|
|
UINT32 UncompressedLength;
|
|
|
|
UINT8 CompressionType;
|
|
|
|
UINT16 GuidedSectionAttributes;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
CORE_SECTION_CHILD_NODE *Node;
|
|
|
|
|
|
|
|
SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate a new node
|
|
|
|
//
|
2012-07-27 04:35:24 +02:00
|
|
|
*ChildNode = AllocateZeroPool (sizeof (CORE_SECTION_CHILD_NODE));
|
2007-07-04 12:51:54 +02:00
|
|
|
Node = *ChildNode;
|
|
|
|
if (Node == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Now initialize it
|
|
|
|
//
|
|
|
|
Node->Signature = CORE_SECTION_CHILD_SIGNATURE;
|
|
|
|
Node->Type = SectionHeader->Type;
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (SectionHeader)) {
|
|
|
|
Node->Size = SECTION2_SIZE (SectionHeader);
|
|
|
|
} else {
|
|
|
|
Node->Size = SECTION_SIZE (SectionHeader);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
Node->OffsetInStream = ChildOffset;
|
|
|
|
Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;
|
|
|
|
Node->EncapsulationGuid = NULL;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// If it's an encapsulating section, then create the new section stream also
|
|
|
|
//
|
|
|
|
switch (Node->Type) {
|
|
|
|
case EFI_SECTION_COMPRESSION:
|
|
|
|
//
|
|
|
|
// Get the CompressionSectionHeader
|
|
|
|
//
|
2012-03-13 09:06:16 +01:00
|
|
|
if (Node->Size < sizeof (EFI_COMPRESSION_SECTION)) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (CompressionHeader)) {
|
|
|
|
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
|
|
|
|
CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
|
|
|
|
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;
|
|
|
|
CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;
|
|
|
|
} else {
|
|
|
|
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
|
|
|
|
CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
|
|
|
|
UncompressedLength = CompressionHeader->UncompressedLength;
|
|
|
|
CompressionType = CompressionHeader->CompressionType;
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Allocate space for the new stream
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
if (UncompressedLength > 0) {
|
|
|
|
NewStreamBufferSize = UncompressedLength;
|
2008-08-27 16:29:23 +02:00
|
|
|
NewStreamBuffer = AllocatePool (NewStreamBufferSize);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (NewStreamBuffer == NULL) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2011-10-27 11:23:19 +02:00
|
|
|
if (CompressionType == EFI_NOT_COMPRESSED) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// stream is not actually compressed, just encapsulated. So just copy it.
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
CopyMem (NewStreamBuffer, CompressionSource, NewStreamBufferSize);
|
|
|
|
} else if (CompressionType == EFI_STANDARD_COMPRESSION) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Only support the EFI_SATNDARD_COMPRESSION algorithm.
|
2008-07-24 04:54:45 +02:00
|
|
|
//
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Decompress the stream
|
|
|
|
//
|
|
|
|
Status = CoreLocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2009-02-16 03:07:32 +01:00
|
|
|
ASSERT (Decompress != NULL);
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = Decompress->GetInfo (
|
|
|
|
Decompress,
|
2011-10-27 11:23:19 +02:00
|
|
|
CompressionSource,
|
|
|
|
CompressionSourceSize,
|
2007-07-04 12:51:54 +02:00
|
|
|
(UINT32 *)&NewStreamBufferSize,
|
|
|
|
&ScratchSize
|
|
|
|
);
|
2012-03-13 09:06:16 +01:00
|
|
|
if (EFI_ERROR (Status) || (NewStreamBufferSize != UncompressedLength)) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
CoreFreePool (NewStreamBuffer);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_BAD_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
ScratchBuffer = AllocatePool (ScratchSize);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (ScratchBuffer == NULL) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
CoreFreePool (NewStreamBuffer);
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = Decompress->Decompress (
|
|
|
|
Decompress,
|
2011-10-27 11:23:19 +02:00
|
|
|
CompressionSource,
|
|
|
|
CompressionSourceSize,
|
2007-07-04 12:51:54 +02:00
|
|
|
NewStreamBuffer,
|
|
|
|
(UINT32)NewStreamBufferSize,
|
|
|
|
ScratchBuffer,
|
|
|
|
ScratchSize
|
|
|
|
);
|
2008-07-24 04:54:45 +02:00
|
|
|
CoreFreePool (ScratchBuffer);
|
2012-03-13 09:06:16 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
CoreFreePool (NewStreamBuffer);
|
|
|
|
return Status;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NewStreamBuffer = NULL;
|
|
|
|
NewStreamBufferSize = 0;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = OpenSectionStreamEx (
|
|
|
|
NewStreamBufferSize,
|
|
|
|
NewStreamBuffer,
|
|
|
|
FALSE,
|
|
|
|
Stream->AuthenticationStatus,
|
|
|
|
&Node->EncapsulatedStreamHandle
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
CoreFreePool (NewStreamBuffer);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_SECTION_GUID_DEFINED:
|
|
|
|
GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (GuidedHeader)) {
|
|
|
|
Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);
|
|
|
|
GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;
|
|
|
|
} else {
|
|
|
|
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
|
|
|
|
GuidedSectionAttributes = GuidedHeader->Attributes;
|
|
|
|
}
|
2012-11-08 02:12:56 +01:00
|
|
|
if (VerifyGuidedSectionGuid (Node->EncapsulationGuid, &GuidedExtraction)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// NewStreamBuffer is always allocated by ExtractSection... No caller
|
|
|
|
// allocation here.
|
|
|
|
//
|
|
|
|
Status = GuidedExtraction->ExtractSection (
|
|
|
|
GuidedExtraction,
|
|
|
|
GuidedHeader,
|
|
|
|
&NewStreamBuffer,
|
|
|
|
&NewStreamBufferSize,
|
|
|
|
&AuthenticationStatus
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CoreFreePool (*ChildNode);
|
|
|
|
return EFI_PROTOCOL_ERROR;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// Make sure we initialize the new stream with the correct
|
2007-07-04 12:51:54 +02:00
|
|
|
// authentication status for both aggregate and local status fields.
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// OR in the parent stream's aggregate status.
|
|
|
|
//
|
2007-12-10 04:47:56 +01:00
|
|
|
AuthenticationStatus |= Stream->AuthenticationStatus & EFI_AUTH_STATUS_ALL;
|
2007-07-04 12:51:54 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// since there's no authentication data contributed by the section,
|
|
|
|
// just inherit the full value from our immediate parent.
|
|
|
|
//
|
|
|
|
AuthenticationStatus = Stream->AuthenticationStatus;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = OpenSectionStreamEx (
|
|
|
|
NewStreamBufferSize,
|
|
|
|
NewStreamBuffer,
|
|
|
|
FALSE,
|
|
|
|
AuthenticationStatus,
|
|
|
|
&Node->EncapsulatedStreamHandle
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CoreFreePool (*ChildNode);
|
|
|
|
CoreFreePool (NewStreamBuffer);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// There's no GUIDed section extraction protocol available.
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2010-07-28 03:12:18 +02:00
|
|
|
// If the section REQUIRES an extraction protocol, register for RPN
|
|
|
|
// when the required GUIDed extraction protocol becomes available.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2010-07-28 03:12:18 +02:00
|
|
|
CreateGuidedExtractionRpnEvent (Stream, Node);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Figure out the proper authentication status
|
|
|
|
//
|
|
|
|
AuthenticationStatus = Stream->AuthenticationStatus;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2014-08-11 07:40:40 +02:00
|
|
|
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {
|
|
|
|
AuthenticationStatus |= EFI_AUTH_STATUS_IMAGE_SIGNED | EFI_AUTH_STATUS_NOT_TESTED;
|
|
|
|
}
|
|
|
|
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_SECTION2 (GuidedHeader)) {
|
|
|
|
Status = OpenSectionStreamEx (
|
|
|
|
SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
|
|
|
|
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
|
|
|
|
TRUE,
|
|
|
|
AuthenticationStatus,
|
|
|
|
&Node->EncapsulatedStreamHandle
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Status = OpenSectionStreamEx (
|
|
|
|
SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
|
|
|
|
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
|
|
|
|
TRUE,
|
|
|
|
AuthenticationStatus,
|
|
|
|
&Node->EncapsulatedStreamHandle
|
|
|
|
);
|
|
|
|
}
|
2010-07-28 03:12:18 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CoreFreePool (Node);
|
|
|
|
return Status;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Nothing to do if it's a leaf
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Last, add the new child node to the stream
|
|
|
|
//
|
|
|
|
InsertTailList (&Stream->Children, &Node->Link);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2008-08-28 04:53:16 +02:00
|
|
|
Worker function Recursively searches / builds section stream database
|
|
|
|
looking for requested section.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@param SourceStream Indicates the section stream in which to do the
|
|
|
|
search.
|
|
|
|
@param SearchType Indicates the type of section to search for.
|
|
|
|
@param SectionInstance Indicates which instance of section to find.
|
|
|
|
This is an in/out parameter to deal with
|
|
|
|
recursions.
|
|
|
|
@param SectionDefinitionGuid Guid of section definition
|
|
|
|
@param FoundChild Output indicating the child node that is found.
|
|
|
|
@param FoundStream Output indicating which section stream the child
|
|
|
|
was found in. If this stream was generated as a
|
|
|
|
result of an encapsulation section, the
|
|
|
|
streamhandle is visible within the SEP driver
|
|
|
|
only.
|
|
|
|
@param AuthenticationStatus Indicates the authentication status of the found section.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Child node was found and returned.
|
|
|
|
EFI_OUT_OF_RESOURCES- Memory allocation failed.
|
|
|
|
@retval EFI_NOT_FOUND Requested child node does not exist.
|
|
|
|
@retval EFI_PROTOCOL_ERROR a required GUIDED section extraction protocol
|
|
|
|
does not exist
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
2008-08-28 04:53:16 +02:00
|
|
|
EFI_STATUS
|
|
|
|
FindChildNode (
|
|
|
|
IN CORE_SECTION_STREAM_NODE *SourceStream,
|
|
|
|
IN EFI_SECTION_TYPE SearchType,
|
|
|
|
IN OUT UINTN *SectionInstance,
|
|
|
|
IN EFI_GUID *SectionDefinitionGuid,
|
|
|
|
OUT CORE_SECTION_CHILD_NODE **FoundChild,
|
|
|
|
OUT CORE_SECTION_STREAM_NODE **FoundStream,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
2008-08-28 04:53:16 +02:00
|
|
|
CORE_SECTION_CHILD_NODE *CurrentChildNode;
|
|
|
|
CORE_SECTION_CHILD_NODE *RecursedChildNode;
|
|
|
|
CORE_SECTION_STREAM_NODE *RecursedFoundStream;
|
|
|
|
UINT32 NextChildOffset;
|
|
|
|
EFI_STATUS ErrorStatus;
|
|
|
|
EFI_STATUS Status;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
CurrentChildNode = NULL;
|
|
|
|
ErrorStatus = EFI_NOT_FOUND;
|
|
|
|
|
|
|
|
if (SourceStream->StreamLength == 0) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsListEmpty (&SourceStream->Children) &&
|
|
|
|
SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// This occurs when a section stream exists, but no child sections
|
|
|
|
// have been parsed out yet. Therefore, extract the first child and add it
|
|
|
|
// to the list of children so we can get started.
|
|
|
|
// Section stream may contain an array of zero or more bytes.
|
|
|
|
// So, its size should be >= the size of commen section header.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
Status = CreateChildNode (SourceStream, 0, &CurrentChildNode);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-08-28 04:53:16 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// At least one child has been parsed out of the section stream. So, walk
|
|
|
|
// through the sections that have already been parsed out looking for the
|
|
|
|
// requested section, if necessary, continue parsing section stream and
|
|
|
|
// adding children until either the requested section is found, or we run
|
|
|
|
// out of data
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
for (;;) {
|
2010-03-03 10:40:16 +01:00
|
|
|
ASSERT (CurrentChildNode != NULL);
|
2008-08-28 04:53:16 +02:00
|
|
|
if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {
|
|
|
|
//
|
|
|
|
// The type matches, so check the instance count to see if it's the one we want
|
|
|
|
//
|
|
|
|
(*SectionInstance)--;
|
|
|
|
if (*SectionInstance == 0) {
|
|
|
|
//
|
|
|
|
// Got it!
|
|
|
|
//
|
|
|
|
*FoundChild = CurrentChildNode;
|
|
|
|
*FoundStream = SourceStream;
|
|
|
|
*AuthenticationStatus = SourceStream->AuthenticationStatus;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {
|
|
|
|
//
|
|
|
|
// If the current node is an encapsulating node, recurse into it...
|
|
|
|
//
|
|
|
|
Status = FindChildNode (
|
|
|
|
(CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
|
|
|
|
SearchType,
|
|
|
|
SectionInstance,
|
|
|
|
SectionDefinitionGuid,
|
|
|
|
&RecursedChildNode,
|
|
|
|
&RecursedFoundStream,
|
|
|
|
AuthenticationStatus
|
|
|
|
);
|
|
|
|
//
|
|
|
|
// If the status is not EFI_SUCCESS, just save the error code and continue
|
|
|
|
// to find the request child node in the rest stream.
|
|
|
|
//
|
|
|
|
if (*SectionInstance == 0) {
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
*FoundChild = RecursedChildNode;
|
|
|
|
*FoundStream = RecursedFoundStream;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
ErrorStatus = Status;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2010-07-28 03:12:18 +02:00
|
|
|
} else if ((CurrentChildNode->Type == EFI_SECTION_GUID_DEFINED) && (SearchType != EFI_SECTION_GUID_DEFINED)) {
|
|
|
|
//
|
|
|
|
// When Node Type is GUIDED section, but Node has no encapsulated data, Node data should not be parsed
|
|
|
|
// because a required GUIDED section extraction protocol does not exist.
|
|
|
|
// If SearchType is not GUIDED section, EFI_PROTOCOL_ERROR should return.
|
|
|
|
//
|
|
|
|
ErrorStatus = EFI_PROTOCOL_ERROR;
|
2008-08-28 04:53:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsNodeAtEnd (&SourceStream->Children, &CurrentChildNode->Link)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// We haven't found the child node we're interested in yet, but there's
|
|
|
|
// still more nodes that have already been parsed so get the next one
|
|
|
|
// and continue searching..
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream->Children, &CurrentChildNode->Link));
|
2007-07-04 12:51:54 +02:00
|
|
|
} else {
|
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// We've exhausted children that have already been parsed, so see if
|
|
|
|
// there's any more data and continue parsing out more children if there
|
|
|
|
// is.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
NextChildOffset = CurrentChildNode->OffsetInStream + CurrentChildNode->Size;
|
|
|
|
//
|
|
|
|
// Round up to 4 byte boundary
|
|
|
|
//
|
|
|
|
NextChildOffset += 3;
|
|
|
|
NextChildOffset &= ~(UINTN) 3;
|
|
|
|
if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {
|
|
|
|
//
|
|
|
|
// There's an unparsed child remaining in the stream, so create a new child node
|
|
|
|
//
|
|
|
|
Status = CreateChildNode (SourceStream, NextChildOffset, &CurrentChildNode);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT (EFI_ERROR (ErrorStatus));
|
|
|
|
return ErrorStatus;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Worker function. Search stream database for requested stream handle.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param SearchHandle Indicates which stream to look for.
|
|
|
|
@param FoundStream Output pointer to the found stream.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_SUCCESS StreamHandle was found and *FoundStream contains
|
|
|
|
the stream node.
|
|
|
|
@retval EFI_NOT_FOUND SearchHandle was not found in the stream
|
2008-05-09 09:08:30 +02:00
|
|
|
database.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
FindStreamNode (
|
|
|
|
IN UINTN SearchHandle,
|
|
|
|
OUT CORE_SECTION_STREAM_NODE **FoundStream
|
|
|
|
)
|
2008-07-24 04:54:45 +02:00
|
|
|
{
|
2007-07-04 12:51:54 +02:00
|
|
|
CORE_SECTION_STREAM_NODE *StreamNode;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (!IsListEmpty (&mStreamRoot)) {
|
|
|
|
StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));
|
|
|
|
for (;;) {
|
|
|
|
if (StreamNode->StreamHandle == SearchHandle) {
|
|
|
|
*FoundStream = StreamNode;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else if (IsNodeAtEnd (&mStreamRoot, &StreamNode->Link)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
StreamNode = STREAM_NODE_FROM_LINK (GetNextNode (&mStreamRoot, &StreamNode->Link));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2008-08-28 04:53:16 +02:00
|
|
|
SEP member function. Retrieves requested section from section stream.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@param SectionStreamHandle The section stream from which to extract the
|
|
|
|
requested section.
|
|
|
|
@param SectionType A pointer to the type of section to search for.
|
|
|
|
@param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED,
|
|
|
|
then SectionDefinitionGuid indicates which of
|
|
|
|
these types of sections to search for.
|
|
|
|
@param SectionInstance Indicates which instance of the requested
|
|
|
|
section to return.
|
|
|
|
@param Buffer Double indirection to buffer. If *Buffer is
|
|
|
|
non-null on input, then the buffer is caller
|
|
|
|
allocated. If Buffer is NULL, then the buffer
|
|
|
|
is callee allocated. In either case, the
|
2016-07-08 08:21:04 +02:00
|
|
|
required buffer size is returned in *BufferSize.
|
2008-08-28 04:53:16 +02:00
|
|
|
@param BufferSize On input, indicates the size of *Buffer if
|
|
|
|
*Buffer is non-null on input. On output,
|
|
|
|
indicates the required size (allocated size if
|
|
|
|
callee allocated) of *Buffer.
|
|
|
|
@param AuthenticationStatus A pointer to a caller-allocated UINT32 that
|
|
|
|
indicates the authentication status of the
|
|
|
|
output buffer. If the input section's
|
|
|
|
GuidedSectionHeader.Attributes field
|
|
|
|
has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
|
|
|
|
bit as clear, AuthenticationStatus must return
|
|
|
|
zero. Both local bits (19:16) and aggregate
|
|
|
|
bits (3:0) in AuthenticationStatus are returned
|
|
|
|
by ExtractSection(). These bits reflect the
|
|
|
|
status of the extraction operation. The bit
|
|
|
|
pattern in both regions must be the same, as
|
|
|
|
the local and aggregate authentication statuses
|
|
|
|
have equivalent meaning at this level. If the
|
|
|
|
function returns anything other than
|
|
|
|
EFI_SUCCESS, the value of *AuthenticationStatus
|
|
|
|
is undefined.
|
2011-10-27 11:23:19 +02:00
|
|
|
@param IsFfs3Fv Indicates the FV format.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
@retval EFI_SUCCESS Section was retrieved successfully
|
|
|
|
@retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the
|
|
|
|
section stream with its
|
|
|
|
EFI_GUIDED_SECTION_PROCESSING_REQUIRED bit set,
|
|
|
|
but there was no corresponding GUIDed Section
|
|
|
|
Extraction Protocol in the handle database.
|
|
|
|
*Buffer is unmodified.
|
|
|
|
@retval EFI_NOT_FOUND An error was encountered when parsing the
|
|
|
|
SectionStream. This indicates the SectionStream
|
|
|
|
is not correctly formatted.
|
|
|
|
@retval EFI_NOT_FOUND The requested section does not exist.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES The system has insufficient resources to process
|
|
|
|
the request.
|
|
|
|
@retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
|
|
|
|
@retval EFI_WARN_TOO_SMALL The size of the caller allocated input buffer is
|
|
|
|
insufficient to contain the requested section.
|
|
|
|
The input buffer is filled and section contents
|
|
|
|
are truncated.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
**/
|
2008-08-28 04:53:16 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
GetSection (
|
|
|
|
IN UINTN SectionStreamHandle,
|
|
|
|
IN EFI_SECTION_TYPE *SectionType,
|
|
|
|
IN EFI_GUID *SectionDefinitionGuid,
|
|
|
|
IN UINTN SectionInstance,
|
|
|
|
IN VOID **Buffer,
|
|
|
|
IN OUT UINTN *BufferSize,
|
2011-10-27 11:23:19 +02:00
|
|
|
OUT UINT32 *AuthenticationStatus,
|
|
|
|
IN BOOLEAN IsFfs3Fv
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
2008-08-28 04:53:16 +02:00
|
|
|
CORE_SECTION_STREAM_NODE *StreamNode;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
CORE_SECTION_CHILD_NODE *ChildNode;
|
|
|
|
CORE_SECTION_STREAM_NODE *ChildStreamNode;
|
|
|
|
UINTN CopySize;
|
|
|
|
UINT32 ExtractedAuthenticationStatus;
|
|
|
|
UINTN Instance;
|
|
|
|
UINT8 *CopyBuffer;
|
|
|
|
UINTN SectionSize;
|
2011-10-27 11:23:19 +02:00
|
|
|
EFI_COMMON_SECTION_HEADER *Section;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2014-07-28 09:52:57 +02:00
|
|
|
ChildStreamNode = NULL;
|
2008-08-28 04:53:16 +02:00
|
|
|
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
|
|
|
|
Instance = SectionInstance + 1;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
//
|
|
|
|
// Locate target stream
|
|
|
|
//
|
|
|
|
Status = FindStreamNode (SectionStreamHandle, &StreamNode);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto GetSection_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Found the stream, now locate and return the appropriate section
|
|
|
|
//
|
|
|
|
if (SectionType == NULL) {
|
|
|
|
//
|
|
|
|
// SectionType == NULL means return the WHOLE section stream...
|
|
|
|
//
|
|
|
|
CopySize = StreamNode->StreamLength;
|
|
|
|
CopyBuffer = StreamNode->StreamBuffer;
|
|
|
|
*AuthenticationStatus = StreamNode->AuthenticationStatus;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// There's a requested section type, so go find it and return it...
|
|
|
|
//
|
|
|
|
Status = FindChildNode (
|
|
|
|
StreamNode,
|
|
|
|
*SectionType,
|
|
|
|
&Instance,
|
|
|
|
SectionDefinitionGuid,
|
|
|
|
&ChildNode,
|
|
|
|
&ChildStreamNode,
|
|
|
|
&ExtractedAuthenticationStatus
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto GetSection_Done;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2011-10-27 11:23:19 +02:00
|
|
|
|
|
|
|
Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
|
|
|
|
|
|
|
|
if (IS_SECTION2 (Section)) {
|
|
|
|
ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);
|
|
|
|
if (!IsFfs3Fv) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "It is a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
goto GetSection_Done;
|
|
|
|
}
|
|
|
|
CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
|
|
|
|
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);
|
|
|
|
} else {
|
|
|
|
CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
|
|
|
|
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);
|
|
|
|
}
|
2008-08-28 04:53:16 +02:00
|
|
|
*AuthenticationStatus = ExtractedAuthenticationStatus;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
SectionSize = CopySize;
|
|
|
|
if (*Buffer != NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// Caller allocated buffer. Fill to size and return required size...
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
if (*BufferSize < CopySize) {
|
|
|
|
Status = EFI_WARN_BUFFER_TOO_SMALL;
|
|
|
|
CopySize = *BufferSize;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Callee allocated buffer. Allocate buffer and return size.
|
|
|
|
//
|
|
|
|
*Buffer = AllocatePool (CopySize);
|
|
|
|
if (*Buffer == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto GetSection_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CopyMem (*Buffer, CopyBuffer, CopySize);
|
|
|
|
*BufferSize = SectionSize;
|
|
|
|
|
|
|
|
GetSection_Done:
|
|
|
|
CoreRestoreTpl (OldTpl);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Worker function. Destructor for child nodes.
|
|
|
|
|
|
|
|
@param ChildNode Indicates the node to destroy
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
FreeChildNode (
|
|
|
|
IN CORE_SECTION_CHILD_NODE *ChildNode
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);
|
|
|
|
//
|
|
|
|
// Remove the child from it's list
|
|
|
|
//
|
|
|
|
RemoveEntryList (&ChildNode->Link);
|
|
|
|
|
|
|
|
if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-28 04:53:16 +02:00
|
|
|
// If it's an encapsulating section, we close the resulting section stream.
|
|
|
|
// CloseSectionStream will free all memory associated with the stream.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2014-08-27 10:31:44 +02:00
|
|
|
CloseSectionStream (ChildNode->EncapsulatedStreamHandle, TRUE);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2012-07-27 04:35:24 +02:00
|
|
|
|
|
|
|
if (ChildNode->Event != NULL) {
|
|
|
|
gBS->CloseEvent (ChildNode->Event);
|
|
|
|
}
|
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
//
|
|
|
|
// Last, free the child node itself
|
|
|
|
//
|
|
|
|
CoreFreePool (ChildNode);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
SEP member function. Deletes an existing section stream
|
|
|
|
|
|
|
|
@param StreamHandleToClose Indicates the stream to close
|
2014-08-27 10:31:44 +02:00
|
|
|
@param FreeStreamBuffer TRUE - Need to free stream buffer;
|
|
|
|
FALSE - No need to free stream buffer.
|
2008-08-28 04:53:16 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The section stream is closed sucessfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
|
|
|
|
@retval EFI_INVALID_PARAMETER Section stream does not end concident with end
|
|
|
|
of last section.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CloseSectionStream (
|
2014-08-27 10:31:44 +02:00
|
|
|
IN UINTN StreamHandleToClose,
|
|
|
|
IN BOOLEAN FreeStreamBuffer
|
2008-08-28 04:53:16 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
CORE_SECTION_STREAM_NODE *StreamNode;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
CORE_SECTION_CHILD_NODE *ChildNode;
|
|
|
|
|
|
|
|
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate target stream
|
|
|
|
//
|
|
|
|
Status = FindStreamNode (StreamHandleToClose, &StreamNode);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Found the stream, so close it
|
|
|
|
//
|
|
|
|
RemoveEntryList (&StreamNode->Link);
|
|
|
|
while (!IsListEmpty (&StreamNode->Children)) {
|
|
|
|
Link = GetFirstNode (&StreamNode->Children);
|
|
|
|
ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
|
|
|
|
FreeChildNode (ChildNode);
|
|
|
|
}
|
2014-08-27 10:31:44 +02:00
|
|
|
if (FreeStreamBuffer) {
|
|
|
|
CoreFreePool (StreamNode->StreamBuffer);
|
|
|
|
}
|
2008-08-28 04:53:16 +02:00
|
|
|
CoreFreePool (StreamNode);
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreRestoreTpl (OldTpl);
|
|
|
|
return Status;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2007-08-08 12:17:57 +02:00
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
/**
|
|
|
|
The ExtractSection() function processes the input section and
|
|
|
|
allocates a buffer from the pool in which it returns the section
|
|
|
|
contents. If the section being extracted contains
|
|
|
|
authentication information (the section's
|
|
|
|
GuidedSectionHeader.Attributes field has the
|
|
|
|
EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values
|
|
|
|
returned in AuthenticationStatus must reflect the results of
|
|
|
|
the authentication operation. Depending on the algorithm and
|
|
|
|
size of the encapsulated data, the time that is required to do
|
|
|
|
a full authentication may be prohibitively long for some
|
|
|
|
classes of systems. To indicate this, use
|
|
|
|
EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by
|
|
|
|
the security policy driver (see the Platform Initialization
|
|
|
|
Driver Execution Environment Core Interface Specification for
|
|
|
|
more details and the GUID definition). If the
|
|
|
|
EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle
|
|
|
|
database, then, if possible, full authentication should be
|
|
|
|
skipped and the section contents simply returned in the
|
|
|
|
OutputBuffer. In this case, the
|
|
|
|
EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus
|
|
|
|
must be set on return. ExtractSection() is callable only from
|
|
|
|
TPL_NOTIFY and below. Behavior of ExtractSection() at any
|
|
|
|
EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is
|
|
|
|
defined in RaiseTPL() in the UEFI 2.0 specification.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@param This Indicates the
|
|
|
|
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.
|
2007-08-08 12:17:57 +02:00
|
|
|
@param InputSection Buffer containing the input GUIDed section
|
|
|
|
to be processed. OutputBuffer OutputBuffer
|
|
|
|
is allocated from boot services pool
|
|
|
|
memory and contains the new section
|
|
|
|
stream. The caller is responsible for
|
|
|
|
freeing this buffer.
|
2008-05-09 09:08:30 +02:00
|
|
|
@param OutputBuffer *OutputBuffer is allocated from boot services
|
|
|
|
pool memory and contains the new section stream.
|
|
|
|
The caller is responsible for freeing this buffer.
|
2007-08-08 12:17:57 +02:00
|
|
|
@param OutputSize A pointer to a caller-allocated UINTN in
|
|
|
|
which the size of OutputBuffer allocation
|
|
|
|
is stored. If the function returns
|
|
|
|
anything other than EFI_SUCCESS, the value
|
|
|
|
of OutputSize is undefined.
|
|
|
|
|
|
|
|
@param AuthenticationStatus A pointer to a caller-allocated
|
|
|
|
UINT32 that indicates the
|
|
|
|
authentication status of the
|
|
|
|
output buffer. If the input
|
|
|
|
section's
|
|
|
|
GuidedSectionHeader.Attributes
|
|
|
|
field has the
|
|
|
|
EFI_GUIDED_SECTION_AUTH_STATUS_VAL
|
|
|
|
bit as clear, AuthenticationStatus
|
|
|
|
must return zero. Both local bits
|
|
|
|
(19:16) and aggregate bits (3:0)
|
|
|
|
in AuthenticationStatus are
|
|
|
|
returned by ExtractSection().
|
|
|
|
These bits reflect the status of
|
|
|
|
the extraction operation. The bit
|
|
|
|
pattern in both regions must be
|
|
|
|
the same, as the local and
|
|
|
|
aggregate authentication statuses
|
|
|
|
have equivalent meaning at this
|
|
|
|
level. If the function returns
|
|
|
|
anything other than EFI_SUCCESS,
|
|
|
|
the value of AuthenticationStatus
|
|
|
|
is undefined.
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_SUCCESS The InputSection was successfully
|
|
|
|
processed and the section contents were
|
|
|
|
returned.
|
2007-08-08 12:17:57 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES The system has insufficient
|
|
|
|
resources to process the
|
|
|
|
request.
|
2007-08-08 12:17:57 +02:00
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER The GUID in InputSection does
|
|
|
|
not match this instance of the
|
|
|
|
GUIDed Section Extraction
|
|
|
|
Protocol.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2007-12-10 04:47:56 +01:00
|
|
|
EFIAPI
|
2007-09-29 10:04:29 +02:00
|
|
|
CustomGuidedSectionExtract (
|
2007-08-08 12:17:57 +02:00
|
|
|
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
|
|
|
|
IN CONST VOID *InputSection,
|
|
|
|
OUT VOID **OutputBuffer,
|
|
|
|
OUT UINTN *OutputSize,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2007-09-29 10:04:29 +02:00
|
|
|
VOID *ScratchBuffer;
|
|
|
|
VOID *AllocatedOutputBuffer;
|
|
|
|
UINT32 OutputBufferSize;
|
|
|
|
UINT32 ScratchBufferSize;
|
|
|
|
UINT16 SectionAttribute;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
// Init local variable
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
ScratchBuffer = NULL;
|
|
|
|
AllocatedOutputBuffer = NULL;
|
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
// Call GetInfo to get the size and attribute of input guided section data.
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
Status = ExtractGuidedSectionGetInfo (
|
2008-05-09 09:08:30 +02:00
|
|
|
InputSection,
|
|
|
|
&OutputBufferSize,
|
|
|
|
&ScratchBufferSize,
|
|
|
|
&SectionAttribute
|
|
|
|
);
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));
|
2007-09-29 10:04:29 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-08-28 04:53:16 +02:00
|
|
|
if (ScratchBufferSize > 0) {
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
// Allocate scratch buffer
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
ScratchBuffer = AllocatePool (ScratchBufferSize);
|
2007-09-29 10:04:29 +02:00
|
|
|
if (ScratchBuffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2007-08-08 12:17:57 +02:00
|
|
|
}
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
if (OutputBufferSize > 0) {
|
2007-09-29 10:04:29 +02:00
|
|
|
//
|
|
|
|
// Allocate output buffer
|
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
AllocatedOutputBuffer = AllocatePool (OutputBufferSize);
|
2007-09-29 10:04:29 +02:00
|
|
|
if (AllocatedOutputBuffer == NULL) {
|
2008-08-28 04:53:16 +02:00
|
|
|
FreePool (ScratchBuffer);
|
2007-09-29 10:04:29 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
*OutputBuffer = AllocatedOutputBuffer;
|
2007-08-08 12:17:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
// Call decode function to extract raw data from the guided section.
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
Status = ExtractGuidedSectionDecode (
|
2008-07-24 04:54:45 +02:00
|
|
|
InputSection,
|
2007-09-29 10:04:29 +02:00
|
|
|
OutputBuffer,
|
|
|
|
ScratchBuffer,
|
|
|
|
AuthenticationStatus
|
2008-07-18 11:50:09 +02:00
|
|
|
);
|
2007-08-08 12:17:57 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
// Decode failed
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
if (AllocatedOutputBuffer != NULL) {
|
|
|
|
CoreFreePool (AllocatedOutputBuffer);
|
|
|
|
}
|
|
|
|
if (ScratchBuffer != NULL) {
|
|
|
|
CoreFreePool (ScratchBuffer);
|
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
|
2007-08-08 12:17:57 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2007-09-29 10:04:29 +02:00
|
|
|
|
|
|
|
if (*OutputBuffer != AllocatedOutputBuffer) {
|
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// OutputBuffer was returned as a different value,
|
2007-09-29 10:04:29 +02:00
|
|
|
// so copy section contents to the allocated memory buffer.
|
2008-07-24 04:54:45 +02:00
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
CopyMem (AllocatedOutputBuffer, *OutputBuffer, OutputBufferSize);
|
|
|
|
*OutputBuffer = AllocatedOutputBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set real size of output buffer.
|
|
|
|
//
|
|
|
|
*OutputSize = (UINTN) OutputBufferSize;
|
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
//
|
|
|
|
// Free unused scratch buffer.
|
|
|
|
//
|
2007-09-29 10:04:29 +02:00
|
|
|
if (ScratchBuffer != NULL) {
|
|
|
|
CoreFreePool (ScratchBuffer);
|
|
|
|
}
|
|
|
|
|
2007-08-08 12:17:57 +02:00
|
|
|
return EFI_SUCCESS;
|
2007-08-22 10:42:13 +02:00
|
|
|
}
|