]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
MdeModulePkg: Fix MSFT C4255 warning
[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
6 Copyright (c) 2009 - 2011, 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 "LzmaDecompressLibInternal.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
54LzmaGuidedSectionGetInfo (\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 &gLzmaCustomDecompressGuid,\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 LzmaUefiDecompressGetInfo (\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 &gLzmaCustomDecompressGuid,\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 LzmaUefiDecompressGetInfo (\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 LZAM 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\r
117 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
118 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation. \r
119 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
120 as a scratch buffer to perform the decode operation. \r
121 @param[out] AuthenticationStatus \r
122 A pointer to the authentication status of the decoded output buffer.\r
123 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
124 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
125 never be set by this handler.\r
126\r
127 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
128 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
129 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
130\r
131**/\r
132RETURN_STATUS\r
133EFIAPI\r
134LzmaGuidedSectionExtraction (\r
135 IN CONST VOID *InputSection,\r
136 OUT VOID **OutputBuffer,\r
137 OUT VOID *ScratchBuffer, OPTIONAL\r
138 OUT UINT32 *AuthenticationStatus\r
139 )\r
140{\r
141 ASSERT (OutputBuffer != NULL);\r
142 ASSERT (InputSection != NULL);\r
143\r
144 if (IS_SECTION2 (InputSection)) {\r
145 if (!CompareGuid (\r
146 &gLzmaCustomDecompressGuid,\r
147 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
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
157 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
158 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
159 *OutputBuffer,\r
160 ScratchBuffer\r
161 );\r
162 } else {\r
163 if (!CompareGuid (\r
164 &gLzmaCustomDecompressGuid,\r
165 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
166 return RETURN_INVALID_PARAMETER;\r
167 }\r
168\r
169 //\r
170 // Authentication is set to Zero, which may be ignored.\r
171 //\r
172 *AuthenticationStatus = 0;\r
173\r
174 return LzmaUefiDecompress (\r
175 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
176 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
177 *OutputBuffer,\r
178 ScratchBuffer\r
179 );\r
180 }\r
181}\r
182\r
183\r
184/**\r
185 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.\r
186\r
187 @retval RETURN_SUCCESS Register successfully.\r
188 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r
189**/\r
190EFI_STATUS\r
191EFIAPI\r
192LzmaDecompressLibConstructor (\r
f826516d 193 VOID\r
11ff2c71
LG
194 )\r
195{\r
196 return ExtractGuidedSectionRegisterHandlers (\r
197 &gLzmaCustomDecompressGuid,\r
198 LzmaGuidedSectionGetInfo,\r
199 LzmaGuidedSectionExtraction\r
200 ); \r
201}\r
202\r