]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Library / LzmaCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
11ff2c71
LG
1/** @file\r
2 LZMA Decompress GUIDed Section Extraction Library.\r
3 It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces\r
4 and registers them into GUIDed handler table.\r
5\r
d1102dba 6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
11ff2c71
LG
8\r
9**/\r
10\r
11#include "LzmaDecompressLibInternal.h"\r
12\r
13/**\r
14 Examines a GUIDed section and returns the size of the decoded buffer and the\r
15 size of an scratch buffer required to actually decode the data in a GUIDed section.\r
16\r
d1102dba 17 Examines a GUIDed section specified by InputSection.\r
11ff2c71 18 If GUID for InputSection does not match the GUID that this handler supports,\r
d1102dba 19 then RETURN_UNSUPPORTED is returned.\r
11ff2c71
LG
20 If the required information can not be retrieved from InputSection,\r
21 then RETURN_INVALID_PARAMETER is returned.\r
22 If the GUID of InputSection does match the GUID that this handler supports,\r
23 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
24 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
25 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
d1102dba 26\r
11ff2c71
LG
27 If InputSection is NULL, then ASSERT().\r
28 If OutputBufferSize is NULL, then ASSERT().\r
29 If ScratchBufferSize is NULL, then ASSERT().\r
30 If SectionAttribute is NULL, then ASSERT().\r
31\r
32\r
33 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
34 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
35 if the buffer specified by InputSection were decoded.\r
36 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
37 if the buffer specified by InputSection were decoded.\r
38 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
39 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
40\r
41 @retval RETURN_SUCCESS The information about InputSection was returned.\r
42 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
43 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
44\r
45**/\r
46RETURN_STATUS\r
47EFIAPI\r
48LzmaGuidedSectionGetInfo (\r
49 IN CONST VOID *InputSection,\r
50 OUT UINT32 *OutputBufferSize,\r
51 OUT UINT32 *ScratchBufferSize,\r
52 OUT UINT16 *SectionAttribute\r
53 )\r
54{\r
55 ASSERT (InputSection != NULL);\r
56 ASSERT (OutputBufferSize != NULL);\r
57 ASSERT (ScratchBufferSize != NULL);\r
58 ASSERT (SectionAttribute != NULL);\r
59\r
60 if (IS_SECTION2 (InputSection)) {\r
61 if (!CompareGuid (\r
1436aea4
MK
62 &gLzmaCustomDecompressGuid,\r
63 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r
64 ))\r
65 {\r
11ff2c71
LG
66 return RETURN_INVALID_PARAMETER;\r
67 }\r
68\r
1436aea4 69 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;\r
11ff2c71
LG
70\r
71 return LzmaUefiDecompressGetInfo (\r
1436aea4
MK
72 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
73 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
11ff2c71
LG
74 OutputBufferSize,\r
75 ScratchBufferSize\r
76 );\r
77 } else {\r
78 if (!CompareGuid (\r
1436aea4
MK
79 &gLzmaCustomDecompressGuid,\r
80 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r
81 ))\r
82 {\r
11ff2c71
LG
83 return RETURN_INVALID_PARAMETER;\r
84 }\r
85\r
1436aea4 86 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;\r
11ff2c71
LG
87\r
88 return LzmaUefiDecompressGetInfo (\r
1436aea4
MK
89 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
90 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
11ff2c71
LG
91 OutputBufferSize,\r
92 ScratchBufferSize\r
93 );\r
94 }\r
95}\r
96\r
97/**\r
98 Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.\r
d1102dba
LG
99\r
100 Decodes the GUIDed section specified by InputSection.\r
101 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
11ff2c71
LG
102 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
103 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
104 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
105 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
106 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
107 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
d1102dba 108\r
11ff2c71
LG
109 If InputSection is NULL, then ASSERT().\r
110 If OutputBuffer is NULL, then ASSERT().\r
111 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
112 If AuthenticationStatus is NULL, then ASSERT().\r
113\r
114\r
115 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
d1102dba 116 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
11ff2c71 117 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
d1102dba
LG
118 as a scratch buffer to perform the decode operation.\r
119 @param[out] AuthenticationStatus\r
11ff2c71
LG
120 A pointer to the authentication status of the decoded output buffer.\r
121 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
122 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
123 never be set by this handler.\r
124\r
125 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
126 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
127 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
128\r
129**/\r
130RETURN_STATUS\r
131EFIAPI\r
132LzmaGuidedSectionExtraction (\r
133 IN CONST VOID *InputSection,\r
134 OUT VOID **OutputBuffer,\r
e3917e22 135 OUT VOID *ScratchBuffer OPTIONAL,\r
11ff2c71
LG
136 OUT UINT32 *AuthenticationStatus\r
137 )\r
138{\r
139 ASSERT (OutputBuffer != NULL);\r
140 ASSERT (InputSection != NULL);\r
141\r
142 if (IS_SECTION2 (InputSection)) {\r
143 if (!CompareGuid (\r
1436aea4
MK
144 &gLzmaCustomDecompressGuid,\r
145 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r
146 ))\r
147 {\r
11ff2c71
LG
148 return RETURN_INVALID_PARAMETER;\r
149 }\r
150\r
151 //\r
152 // Authentication is set to Zero, which may be ignored.\r
153 //\r
154 *AuthenticationStatus = 0;\r
155\r
156 return LzmaUefiDecompress (\r
1436aea4
MK
157 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
158 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
11ff2c71
LG
159 *OutputBuffer,\r
160 ScratchBuffer\r
161 );\r
162 } else {\r
163 if (!CompareGuid (\r
1436aea4
MK
164 &gLzmaCustomDecompressGuid,\r
165 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r
166 ))\r
167 {\r
11ff2c71
LG
168 return RETURN_INVALID_PARAMETER;\r
169 }\r
170\r
171 //\r
172 // Authentication is set to Zero, which may be ignored.\r
173 //\r
174 *AuthenticationStatus = 0;\r
175\r
176 return LzmaUefiDecompress (\r
1436aea4
MK
177 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
178 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
11ff2c71
LG
179 *OutputBuffer,\r
180 ScratchBuffer\r
1436aea4 181 );\r
11ff2c71
LG
182 }\r
183}\r
184\r
11ff2c71
LG
185/**\r
186 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.\r
187\r
188 @retval RETURN_SUCCESS Register successfully.\r
189 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r
190**/\r
191EFI_STATUS\r
192EFIAPI\r
193LzmaDecompressLibConstructor (\r
f826516d 194 VOID\r
11ff2c71
LG
195 )\r
196{\r
197 return ExtractGuidedSectionRegisterHandlers (\r
1436aea4
MK
198 &gLzmaCustomDecompressGuid,\r
199 LzmaGuidedSectionGetInfo,\r
200 LzmaGuidedSectionExtraction\r
201 );\r
11ff2c71 202}\r