]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
MdeModulePkg: Fix MSFT C4255 warning
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
841b2590
SB
1/** @file\r
2 BROTLI Decompress GUIDed Section Extraction Library.\r
3 It wraps Brotli decompress interfaces to GUIDed Section Extraction interfaces\r
4 and registers them into GUIDed handler table.\r
5\r
6 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <BrotliDecompressLibInternal.h>\r
18\r
19/**\r
20 Examines a GUIDed section and returns the size of the decoded buffer and the\r
21 size of an scratch buffer required to actually decode the data in a GUIDed section.\r
22\r
23 Examines a GUIDed section specified by InputSection.\r
24 If GUID for InputSection does not match the GUID that this handler supports,\r
25 then RETURN_UNSUPPORTED is returned.\r
26 If the required information can not be retrieved from InputSection,\r
27 then RETURN_INVALID_PARAMETER is returned.\r
28 If the GUID of InputSection does match the GUID that this handler supports,\r
29 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
30 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
31 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
32\r
33 If InputSection is NULL, then ASSERT().\r
34 If OutputBufferSize is NULL, then ASSERT().\r
35 If ScratchBufferSize is NULL, then ASSERT().\r
36 If SectionAttribute is NULL, then ASSERT().\r
37\r
38\r
39 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
40 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
41 if the buffer specified by InputSection were decoded.\r
42 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
43 if the buffer specified by InputSection were decoded.\r
44 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
45 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
46\r
47 @retval RETURN_SUCCESS The information about InputSection was returned.\r
48 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
49 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
50\r
51**/\r
52RETURN_STATUS\r
53EFIAPI\r
54BrotliGuidedSectionGetInfo (\r
55 IN CONST VOID *InputSection,\r
56 OUT UINT32 *OutputBufferSize,\r
57 OUT UINT32 *ScratchBufferSize,\r
58 OUT UINT16 *SectionAttribute\r
59 )\r
60{\r
61 ASSERT (InputSection != NULL);\r
62 ASSERT (OutputBufferSize != NULL);\r
63 ASSERT (ScratchBufferSize != NULL);\r
64 ASSERT (SectionAttribute != NULL);\r
65\r
66 if (IS_SECTION2 (InputSection)) {\r
67 if (!CompareGuid (\r
68 &gBrotliCustomDecompressGuid,\r
69 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
70 return RETURN_INVALID_PARAMETER;\r
71 }\r
72\r
73 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
74\r
75 return BrotliUefiDecompressGetInfo (\r
76 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
77 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
78 OutputBufferSize,\r
79 ScratchBufferSize\r
80 );\r
81 } else {\r
82 if (!CompareGuid (\r
83 &gBrotliCustomDecompressGuid,\r
84 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
85 return RETURN_INVALID_PARAMETER;\r
86 }\r
87\r
88 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
89\r
90 return BrotliUefiDecompressGetInfo (\r
91 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
92 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
93 OutputBufferSize,\r
94 ScratchBufferSize\r
95 );\r
96 }\r
97}\r
98\r
99/**\r
100 Decompress a BROTLI compressed GUIDed section into a caller allocated output buffer.\r
101\r
102 Decodes the GUIDed section specified by InputSection.\r
103 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
104 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
105 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
106 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
107 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
108 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
109 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
110\r
111 If InputSection is NULL, then ASSERT().\r
112 If OutputBuffer is NULL, then ASSERT().\r
113 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
114 If AuthenticationStatus is NULL, then ASSERT().\r
115\r
116 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
117 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
118 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
119 as a scratch buffer to perform the decode operation.\r
120 @param[out] AuthenticationStatus\r
121 A pointer to the authentication status of the decoded output buffer.\r
122 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
123 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
124 never be set by this handler.\r
125\r
126 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
127 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
128 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
129\r
130**/\r
131RETURN_STATUS\r
132EFIAPI\r
133BrotliGuidedSectionExtraction (\r
134 IN CONST VOID *InputSection,\r
135 OUT VOID **OutputBuffer,\r
136 OUT VOID *ScratchBuffer, OPTIONAL\r
137 OUT UINT32 *AuthenticationStatus\r
138 )\r
139{\r
140 ASSERT (OutputBuffer != NULL);\r
141 ASSERT (InputSection != NULL);\r
142\r
143 if (IS_SECTION2 (InputSection)) {\r
144 if (!CompareGuid (\r
145 &gBrotliCustomDecompressGuid,\r
146 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
147 return RETURN_INVALID_PARAMETER;\r
148 }\r
149 //\r
150 // Authentication is set to Zero, which may be ignored.\r
151 //\r
152 *AuthenticationStatus = 0;\r
153\r
154 return BrotliUefiDecompress (\r
155 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
156 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
157 *OutputBuffer,\r
158 ScratchBuffer\r
159 );\r
160 } else {\r
161 if (!CompareGuid (\r
162 &gBrotliCustomDecompressGuid,\r
163 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
164 return RETURN_INVALID_PARAMETER;\r
165 }\r
166 //\r
167 // Authentication is set to Zero, which may be ignored.\r
168 //\r
169 *AuthenticationStatus = 0;\r
170\r
171 return BrotliUefiDecompress (\r
172 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
173 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
174 *OutputBuffer,\r
175 ScratchBuffer\r
176 );\r
177 }\r
178}\r
179\r
180/**\r
181 Register BrotliDecompress and BrotliDecompressGetInfo handlers with BrotliCustomerDecompressGuid.\r
182\r
183 @retval EFI_SUCCESS Register successfully.\r
184 @retval EFI_OUT_OF_RESOURCES No enough memory to store this handler.\r
185**/\r
186EFI_STATUS\r
187EFIAPI\r
188BrotliDecompressLibConstructor (\r
f826516d 189 VOID\r
841b2590
SB
190 )\r
191{\r
192 return ExtractGuidedSectionRegisterHandlers (\r
193 &gBrotliCustomDecompressGuid,\r
194 BrotliGuidedSectionGetInfo,\r
195 BrotliGuidedSectionExtraction\r
196 );\r
197}\r