]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
Make EdkModulePkg pass Intel IPF compiler with /W4 /WX switches, solving warning...
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / SectionExtraction / CoreSectionExtraction.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 CoreSectionExtraction.c\r
15 \r
16Abstract:\r
17\r
18 Section Extraction Protocol implementation.\r
19 \r
20 Stream database is implemented as a linked list of section streams,\r
21 where each stream contains a linked list of children, which may be leaves or\r
22 encapsulations. \r
23 \r
24 Children that are encapsulations generate new stream entries\r
25 when they are created. Streams can also be created by calls to \r
26 SEP->OpenSectionStream().\r
27 \r
28 The database is only created far enough to return the requested data from\r
29 any given stream, or to determine that the requested data is not found.\r
30 \r
31 If a GUIDed encapsulation is encountered, there are three possiblilites.\r
32 \r
33 1) A support protocol is found, in which the stream is simply processed with\r
34 the support protocol.\r
35 \r
36 2) A support protocol is not found, but the data is available to be read\r
37 without processing. In this case, the database is built up through the\r
38 recursions to return the data, and a RPN event is set that will enable\r
39 the stream in question to be refreshed if and when the required section\r
40 extraction protocol is published.This insures the AuthenticationStatus \r
41 does not become stale in the cache.\r
42 \r
43 3) A support protocol is not found, and the data is not available to be read\r
44 without it. This results in EFI_PROTOCOL_ERROR.\r
45 \r
46--*/\r
47\r
48#include <DxeMain.h>\r
49\r
50//\r
51// Local defines and typedefs\r
52//\r
53#define CORE_SECTION_CHILD_SIGNATURE EFI_SIGNATURE_32('S','X','C','S')\r
54#define CHILD_SECTION_NODE_FROM_LINK(Node) \\r
55 CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)\r
56\r
57typedef struct {\r
58 UINT32 Signature;\r
59 LIST_ENTRY Link;\r
60 UINT32 Type;\r
61 UINT32 Size;\r
62 //\r
63 // StreamBase + OffsetInStream == pointer to section header in stream. The\r
64 // stream base is always known when walking the sections within.\r
65 //\r
66 UINT32 OffsetInStream;\r
67 //\r
68 // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an\r
69 // encapsulating section. Otherwise, it contains the stream handle\r
70 // of the encapsulated stream. This handle is ALWAYS produced any time an\r
71 // encapsulating child is encountered, irrespective of whether the\r
72 // encapsulated stream is processed further.\r
73 //\r
74 UINTN EncapsulatedStreamHandle;\r
75 EFI_GUID *EncapsulationGuid;\r
76} CORE_SECTION_CHILD_NODE;\r
77\r
78#define CORE_SECTION_STREAM_SIGNATURE EFI_SIGNATURE_32('S','X','S','S')\r
79#define STREAM_NODE_FROM_LINK(Node) \\r
80 CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)\r
81\r
82typedef struct {\r
83 UINT32 Signature;\r
84 LIST_ENTRY Link;\r
85 UINTN StreamHandle;\r
86 UINT8 *StreamBuffer;\r
87 UINTN StreamLength;\r
88 LIST_ENTRY Children;\r
89 //\r
90 // Authentication status is from GUIDed encapsulations.\r
91 //\r
92 UINT32 AuthenticationStatus;\r
93} CORE_SECTION_STREAM_NODE;\r
94\r
95#define NULL_STREAM_HANDLE 0\r
96\r
97typedef struct {\r
98 CORE_SECTION_CHILD_NODE *ChildNode;\r
99 CORE_SECTION_STREAM_NODE *ParentStream;\r
100 VOID *Registration;\r
101 EFI_EVENT Event;\r
102} RPN_EVENT_CONTEXT;\r
103 \r
104 \r
105\r
106//\r
107// Local prototypes\r
108//\r
109\r
110STATIC\r
111BOOLEAN\r
112ChildIsType (\r
113 IN CORE_SECTION_STREAM_NODE *Stream,\r
114 IN CORE_SECTION_CHILD_NODE *Child,\r
115 IN EFI_SECTION_TYPE SearchType,\r
116 IN EFI_GUID *SectionDefinitionGuid\r
117 );\r
118\r
119STATIC\r
120VOID\r
121EFIAPI\r
122NotifyGuidedExtraction (\r
123 IN EFI_EVENT Event,\r
124 IN VOID *RpnContext\r
125 );\r
126\r
127STATIC\r
128VOID\r
129CreateGuidedExtractionRpnEvent (\r
130 IN CORE_SECTION_STREAM_NODE *ParentStream,\r
131 IN CORE_SECTION_CHILD_NODE *ChildNode\r
132 );\r
133\r
92dda53e 134STATIC\r
878ddf1f 135EFI_STATUS\r
136EFIAPI\r
137OpenSectionStream (\r
138 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
139 IN UINTN SectionStreamLength,\r
140 IN VOID *SectionStream,\r
141 OUT UINTN *SectionStreamHandle\r
142 );\r
143 \r
92dda53e 144STATIC\r
878ddf1f 145EFI_STATUS\r
146EFIAPI\r
147GetSection (\r
148 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
149 IN UINTN SectionStreamHandle,\r
150 IN EFI_SECTION_TYPE *SectionType,\r
151 IN EFI_GUID *SectionDefinitionGuid,\r
152 IN UINTN SectionInstance,\r
153 IN VOID **Buffer,\r
154 IN OUT UINTN *BufferSize,\r
155 OUT UINT32 *AuthenticationStatus\r
156 );\r
157 \r
92dda53e 158STATIC\r
878ddf1f 159EFI_STATUS\r
160EFIAPI\r
161CloseSectionStream (\r
162 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
163 IN UINTN StreamHandleToClose\r
164 );\r
165 \r
166STATIC\r
167EFI_STATUS\r
168FindStreamNode (\r
169 IN UINTN SearchHandle,\r
170 OUT CORE_SECTION_STREAM_NODE **FoundStream\r
171 );\r
172 \r
173STATIC\r
174EFI_STATUS\r
175FindChildNode (\r
176 IN CORE_SECTION_STREAM_NODE *SourceStream,\r
177 IN EFI_SECTION_TYPE SearchType,\r
178 IN UINTN *SectionInstance,\r
179 IN EFI_GUID *SectionDefinitionGuid,\r
180 OUT CORE_SECTION_CHILD_NODE **FoundChild,\r
181 OUT CORE_SECTION_STREAM_NODE **FoundStream,\r
182 OUT UINT32 *AuthenticationStatus\r
183 );\r
184 \r
185STATIC\r
186EFI_STATUS\r
187CreateChildNode (\r
188 IN CORE_SECTION_STREAM_NODE *Stream,\r
189 IN UINT32 ChildOffset,\r
190 OUT CORE_SECTION_CHILD_NODE **ChildNode\r
191 );\r
192 \r
193STATIC\r
194VOID\r
195FreeChildNode (\r
196 IN CORE_SECTION_CHILD_NODE *ChildNode\r
197 );\r
198 \r
199STATIC\r
200EFI_STATUS\r
201OpenSectionStreamEx (\r
202 IN UINTN SectionStreamLength,\r
203 IN VOID *SectionStream,\r
204 IN BOOLEAN AllocateBuffer,\r
205 IN UINT32 AuthenticationStatus, \r
206 OUT UINTN *SectionStreamHandle\r
207 );\r
208 \r
209STATIC\r
210BOOLEAN\r
211IsValidSectionStream (\r
212 IN VOID *SectionStream,\r
213 IN UINTN SectionStreamLength\r
214 );\r
215 \r
216//\r
217// Module globals\r
218//\r
219LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);\r
220\r
221EFI_HANDLE mSectionExtractionHandle = NULL;\r
222\r
223EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = { \r
224 OpenSectionStream, \r
225 GetSection, \r
226 CloseSectionStream\r
227};\r
228\r
229 \r
230EFI_STATUS\r
231EFIAPI\r
232InitializeSectionExtraction (\r
233 IN EFI_HANDLE ImageHandle,\r
234 IN EFI_SYSTEM_TABLE *SystemTable\r
235 )\r
236/*++\r
237\r
238Routine Description: \r
239 Entry point of the section extraction code. Initializes an instance of the \r
240 section extraction interface and installs it on a new handle.\r
241\r
242Arguments: \r
243 ImageHandle EFI_HANDLE: A handle for the image that is initializing this driver\r
244 SystemTable EFI_SYSTEM_TABLE: A pointer to the EFI system table \r
245\r
246Returns: \r
247 EFI_SUCCESS: Driver initialized successfully\r
248 EFI_OUT_OF_RESOURCES: Could not allocate needed resources\r
249\r
250--*/\r
251{\r
252 EFI_STATUS Status;\r
253\r
254 //\r
255 // Install SEP to a new handle\r
256 //\r
257 Status = CoreInstallProtocolInterface (\r
258 &mSectionExtractionHandle,\r
259 &gEfiSectionExtractionProtocolGuid,\r
260 EFI_NATIVE_INTERFACE,\r
261 &mSectionExtraction\r
262 );\r
263 ASSERT_EFI_ERROR (Status);\r
264\r
265 return Status;\r
266}\r
267\r
92dda53e 268STATIC\r
878ddf1f 269EFI_STATUS\r
270EFIAPI\r
271OpenSectionStream (\r
272 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
273 IN UINTN SectionStreamLength,\r
274 IN VOID *SectionStream,\r
275 OUT UINTN *SectionStreamHandle\r
276 )\r
277/*++\r
278\r
279Routine Description:\r
280 SEP member function. This function creates and returns a new section stream\r
281 handle to represent the new section stream.\r
282\r
283Arguments:\r
284 This - Indicates the calling context.\r
285 SectionStreamLength - Size in bytes of the section stream.\r
286 SectionStream - Buffer containing the new section stream.\r
287 SectionStreamHandle - A pointer to a caller allocated UINTN that on output\r
288 contains the new section stream handle.\r
289\r
290Returns:\r
291 EFI_SUCCESS\r
292 EFI_OUT_OF_RESOURCES - memory allocation failed.\r
293 EFI_INVALID_PARAMETER - section stream does not end concident with end of\r
294 last section.\r
295\r
296--*/\r
297{\r
298 //\r
299 // Check to see section stream looks good...\r
300 //\r
301 if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {\r
302 return EFI_INVALID_PARAMETER;\r
303 }\r
304 \r
305 return OpenSectionStreamEx ( \r
306 SectionStreamLength, \r
307 SectionStream,\r
308 TRUE,\r
309 0,\r
310 SectionStreamHandle\r
311 );\r
312}\r
313 \r
92dda53e 314STATIC\r
878ddf1f 315EFI_STATUS\r
316EFIAPI\r
317GetSection (\r
318 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
319 IN UINTN SectionStreamHandle,\r
320 IN EFI_SECTION_TYPE *SectionType,\r
321 IN EFI_GUID *SectionDefinitionGuid,\r
322 IN UINTN SectionInstance,\r
323 IN VOID **Buffer,\r
324 IN OUT UINTN *BufferSize,\r
325 OUT UINT32 *AuthenticationStatus\r
326 )\r
327/*++\r
328\r
329Routine Description:\r
330 SEP member function. Retrieves requested section from section stream.\r
331\r
332Arguments: \r
333 This: Pointer to SEP instance.\r
334 SectionStreamHandle: The section stream from which to extract the requested\r
335 section.\r
336 SectionType: A pointer to the type of section to search for.\r
337 SectionDefinitionGuid: If the section type is EFI_SECTION_GUID_DEFINED, then\r
338 SectionDefinitionGuid indicates which of these types\r
339 of sections to search for.\r
340 SectionInstance: Indicates which instance of the requested section to\r
341 return.\r
342 Buffer: Double indirection to buffer. If *Buffer is non-null on\r
343 input, then the buffer is caller allocated. If\r
344 *Buffer is NULL, then the buffer is callee allocated.\r
345 In either case, the requried buffer size is returned\r
346 in *BufferSize.\r
347 BufferSize: On input, indicates the size of *Buffer if *Buffer is\r
348 non-null on input. On output, indicates the required\r
349 size (allocated size if callee allocated) of *Buffer.\r
350 AuthenticationStatus: Indicates the authentication status of the retrieved\r
351 section.\r
352\r
353Returns: \r
354 EFI_SUCCESS: Section was retrieved successfully\r
355 EFI_PROTOCOL_ERROR: A GUID defined section was encountered in the section \r
356 stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED\r
357 bit set, but there was no corresponding GUIDed Section \r
358 Extraction Protocol in the handle database. *Buffer is \r
359 unmodified.\r
360 EFI_NOT_FOUND: An error was encountered when parsing the SectionStream.\r
361 This indicates the SectionStream is not correctly \r
362 formatted.\r
363 EFI_NOT_FOUND: The requested section does not exist.\r
364 EFI_OUT_OF_RESOURCES: The system has insufficient resources to process the \r
365 request.\r
366 EFI_INVALID_PARAMETER: The SectionStreamHandle does not exist.\r
367 EFI_WARN_TOO_SMALL: The size of the caller allocated input buffer is \r
368 insufficient to contain the requested section. The \r
369 input buffer is filled and contents are section contents\r
370 are truncated.\r
371\r
372--*/\r
373{\r
374 CORE_SECTION_STREAM_NODE *StreamNode;\r
375 EFI_TPL OldTpl;\r
376 EFI_STATUS Status;\r
377 CORE_SECTION_CHILD_NODE *ChildNode;\r
378 CORE_SECTION_STREAM_NODE *ChildStreamNode;\r
379 UINTN CopySize;\r
380 UINT32 ExtractedAuthenticationStatus;\r
381 UINTN Instance;\r
382 UINT8 *CopyBuffer;\r
383 UINTN SectionSize;\r
384 \r
385\r
386 OldTpl = CoreRaiseTpl (EFI_TPL_NOTIFY);\r
387 Instance = SectionInstance + 1;\r
388 \r
389 //\r
390 // Locate target stream\r
391 //\r
392 Status = FindStreamNode (SectionStreamHandle, &StreamNode);\r
393 if (EFI_ERROR (Status)) {\r
394 Status = EFI_INVALID_PARAMETER;\r
395 goto GetSection_Done;\r
396 }\r
397 \r
398 //\r
399 // Found the stream, now locate and return the appropriate section\r
400 //\r
401 if (SectionType == NULL) {\r
402 //\r
403 // SectionType == NULL means return the WHOLE section stream...\r
404 //\r
405 CopySize = StreamNode->StreamLength;\r
406 CopyBuffer = StreamNode->StreamBuffer;\r
407 *AuthenticationStatus = StreamNode->AuthenticationStatus;\r
408 } else {\r
409 //\r
410 // There's a requested section type, so go find it and return it...\r
411 //\r
412 Status = FindChildNode (\r
413 StreamNode, \r
414 *SectionType, \r
415 &Instance, \r
416 SectionDefinitionGuid,\r
417 &ChildNode,\r
418 &ChildStreamNode, \r
419 &ExtractedAuthenticationStatus\r
420 );\r
421 if (EFI_ERROR (Status)) {\r
422 goto GetSection_Done;\r
423 }\r
424 CopySize = ChildNode->Size - sizeof (EFI_COMMON_SECTION_HEADER);\r
425 CopyBuffer = ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream + sizeof (EFI_COMMON_SECTION_HEADER);\r
426 *AuthenticationStatus = ExtractedAuthenticationStatus;\r
427 } \r
428 \r
429 SectionSize = CopySize; \r
430 if (*Buffer != NULL) {\r
431 //\r
432 // Caller allocated buffer. Fill to size and return required size...\r
433 //\r
434 if (*BufferSize < CopySize) {\r
435 Status = EFI_WARN_BUFFER_TOO_SMALL;\r
436 CopySize = *BufferSize;\r
437 }\r
438 } else {\r
439 //\r
440 // Callee allocated buffer. Allocate buffer and return size.\r
441 //\r
442 *Buffer = CoreAllocateBootServicesPool (CopySize);\r
443 if (*Buffer == NULL) {\r
444 Status = EFI_OUT_OF_RESOURCES;\r
445 goto GetSection_Done;\r
446 }\r
447 }\r
448 CopyMem (*Buffer, CopyBuffer, CopySize);\r
449 *BufferSize = SectionSize;\r
450 \r
451GetSection_Done:\r
452 CoreRestoreTpl (OldTpl);\r
453 return Status;\r
454}\r
455\r
456\r
92dda53e 457STATIC\r
878ddf1f 458EFI_STATUS\r
459EFIAPI\r
460CloseSectionStream (\r
461 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,\r
462 IN UINTN StreamHandleToClose\r
463 )\r
464/*++\r
465\r
466Routine Description:\r
467 SEP member function. Deletes an existing section stream\r
468\r
469Arguments:\r
470 This - Indicates the calling context.\r
471 StreamHandleToClose - Indicates the stream to close\r
472\r
473Returns:\r
474 EFI_SUCCESS\r
475 EFI_OUT_OF_RESOURCES - memory allocation failed.\r
476 EFI_INVALID_PARAMETER - section stream does not end concident with end of\r
477 last section.\r
478\r
479--*/\r
480{\r
481 CORE_SECTION_STREAM_NODE *StreamNode;\r
482 EFI_TPL OldTpl;\r
483 EFI_STATUS Status;\r
484 LIST_ENTRY *Link;\r
485 CORE_SECTION_CHILD_NODE *ChildNode;\r
486 \r
487 OldTpl = CoreRaiseTpl (EFI_TPL_NOTIFY);\r
488 \r
489 //\r
490 // Locate target stream\r
491 //\r
492 Status = FindStreamNode (StreamHandleToClose, &StreamNode);\r
493 if (!EFI_ERROR (Status)) {\r
494 //\r
495 // Found the stream, so close it\r
496 //\r
497 RemoveEntryList (&StreamNode->Link);\r
498 while (!IsListEmpty (&StreamNode->Children)) {\r
499 Link = GetFirstNode (&StreamNode->Children);\r
500 ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);\r
501 FreeChildNode (ChildNode);\r
502 }\r
503 CoreFreePool (StreamNode->StreamBuffer);\r
504 CoreFreePool (StreamNode);\r
505 Status = EFI_SUCCESS;\r
506 } else {\r
507 Status = EFI_INVALID_PARAMETER;\r
508 }\r
509 \r
510 CoreRestoreTpl (OldTpl);\r
511 return Status;\r
512}\r
513\r
514\r
515STATIC\r
516BOOLEAN\r
517ChildIsType (\r
518 IN CORE_SECTION_STREAM_NODE *Stream,\r
519 IN CORE_SECTION_CHILD_NODE *Child,\r
520 IN EFI_SECTION_TYPE SearchType,\r
521 IN EFI_GUID *SectionDefinitionGuid\r
522 )\r
523/*++\r
524\r
525Routine Description:\r
526 Worker function. Determine if the input stream:child matches the input type.\r
527\r
528Arguments:\r
529 Stream - Indicates the section stream associated with the child\r
530 Child - Indicates the child to check\r
531 SearchType - Indicates the type of section to check against for\r
532 SectionDefinitionGuid - Indicates the GUID to check against if the type is\r
533 EFI_SECTION_GUID_DEFINED\r
534Returns:\r
535 TRUE - The child matches\r
536 FALSE - The child doesn't match\r
537\r
538--*/\r
539{\r
540 EFI_GUID_DEFINED_SECTION *GuidedSection;\r
541 \r
542 if (SearchType == EFI_SECTION_ALL) {\r
543 return TRUE;\r
544 }\r
545 if (Child->Type != SearchType) {\r
546 return FALSE;\r
547 }\r
548 if (SearchType != EFI_SECTION_GUID_DEFINED) {\r
549 return TRUE;\r
550 }\r
551 GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);\r
552 return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
553}\r
554\r
555\r
556STATIC\r
557EFI_STATUS\r
558FindChildNode (\r
559 IN CORE_SECTION_STREAM_NODE *SourceStream,\r
560 IN EFI_SECTION_TYPE SearchType,\r
561 IN OUT UINTN *SectionInstance,\r
562 IN EFI_GUID *SectionDefinitionGuid,\r
563 OUT CORE_SECTION_CHILD_NODE **FoundChild,\r
564 OUT CORE_SECTION_STREAM_NODE **FoundStream,\r
565 OUT UINT32 *AuthenticationStatus\r
566 )\r
567/*++\r
568\r
569Routine Description:\r
570 Worker function Recursively searches / builds section stream database\r
571 looking for requested section.\r
572\r
573Arguments:\r
574 SourceStream - Indicates the section stream in which to do the search.\r
575 SearchType - Indicates the type of section to search for.\r
576 SectionInstance - Indicates which instance of section to find. This is\r
577 an in/out parameter to deal with recursions.\r
578 SectionDefinitionGuid - Guid of section definition\r
579 FoundChild - Output indicating the child node that is found.\r
580 FoundStream - Output indicating which section stream the child was\r
581 found in. If this stream was generated as a result of\r
582 an encapsulation section, the streamhandle is visible\r
583 within the SEP driver only.\r
584 AuthenticationStatus- Indicates the authentication status of the found section.\r
585\r
586Returns:\r
587 EFI_SUCCESS - Child node was found and returned.\r
588 EFI_OUT_OF_RESOURCES- Memory allocation failed.\r
589 EFI_NOT_FOUND - Requested child node does not exist.\r
590 EFI_PROTOCOL_ERROR - a required GUIDED section extraction protocol does not\r
591 exist\r
592\r
593--*/\r
594{\r
595 CORE_SECTION_CHILD_NODE *CurrentChildNode;\r
596 CORE_SECTION_CHILD_NODE *RecursedChildNode;\r
597 CORE_SECTION_STREAM_NODE *RecursedFoundStream;\r
598 UINT32 NextChildOffset;\r
599 EFI_STATUS ErrorStatus;\r
600 EFI_STATUS Status;\r
601 \r
602 CurrentChildNode = NULL;\r
603 ErrorStatus = EFI_NOT_FOUND;\r
604 \r
605 if (SourceStream->StreamLength == 0) {\r
606 return EFI_NOT_FOUND;\r
607 }\r
608 \r
609 if (IsListEmpty (&SourceStream->Children) && \r
610 SourceStream->StreamLength > sizeof (EFI_COMMON_SECTION_HEADER)) {\r
611 //\r
612 // This occurs when a section stream exists, but no child sections\r
613 // have been parsed out yet. Therefore, extract the first child and add it\r
614 // to the list of children so we can get started.\r
615 //\r
616 Status = CreateChildNode (SourceStream, 0, &CurrentChildNode);\r
617 if (EFI_ERROR (Status)) {\r
618 return Status;\r
619 }\r
620 }\r
621 \r
622 //\r
623 // At least one child has been parsed out of the section stream. So, walk\r
624 // through the sections that have already been parsed out looking for the\r
625 // requested section, if necessary, continue parsing section stream and\r
626 // adding children until either the requested section is found, or we run\r
627 // out of data\r
628 //\r
629 CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));\r
630\r
631 for (;;) {\r
632 if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {\r
633 //\r
634 // The type matches, so check the instance count to see if it's the one we want\r
635 //\r
636 (*SectionInstance)--;\r
637 if (*SectionInstance == 0) {\r
638 //\r
639 // Got it!\r
640 //\r
641 *FoundChild = CurrentChildNode;\r
642 *FoundStream = SourceStream;\r
643 *AuthenticationStatus = SourceStream->AuthenticationStatus;\r
644 return EFI_SUCCESS;\r
645 }\r
646 }\r
647 \r
648 if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
649 //\r
650 // If the current node is an encapsulating node, recurse into it...\r
651 //\r
652 Status = FindChildNode (\r
653 (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,\r
654 SearchType,\r
655 SectionInstance,\r
656 SectionDefinitionGuid,\r
657 &RecursedChildNode,\r
658 &RecursedFoundStream,\r
659 AuthenticationStatus\r
660 );\r
661 //\r
662 // If the status is not EFI_SUCCESS, just save the error code and continue\r
663 // to find the request child node in the rest stream.\r
664 //\r
665 if (*SectionInstance == 0) {\r
666 ASSERT_EFI_ERROR (Status);\r
667 *FoundChild = RecursedChildNode;\r
668 *FoundStream = RecursedFoundStream;\r
669 return EFI_SUCCESS;\r
670 } else {\r
671 ErrorStatus = Status;\r
672 }\r
673 }\r
674 \r
675 if (!IsNodeAtEnd (&SourceStream->Children, &CurrentChildNode->Link)) {\r
676 //\r
677 // We haven't found the child node we're interested in yet, but there's\r
678 // still more nodes that have already been parsed so get the next one\r
679 // and continue searching..\r
680 //\r
681 CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream->Children, &CurrentChildNode->Link));\r
682 } else {\r
683 //\r
684 // We've exhausted children that have already been parsed, so see if\r
685 // there's any more data and continue parsing out more children if there\r
686 // is.\r
687 //\r
688 NextChildOffset = CurrentChildNode->OffsetInStream + CurrentChildNode->Size;\r
689 //\r
690 // Round up to 4 byte boundary\r
691 //\r
692 NextChildOffset += 3;\r
693 NextChildOffset &= ~(UINTN)3;\r
694 if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {\r
695 //\r
696 // There's an unparsed child remaining in the stream, so create a new child node\r
697 //\r
698 Status = CreateChildNode (SourceStream, NextChildOffset, &CurrentChildNode);\r
699 if (EFI_ERROR (Status)) {\r
700 return Status;\r
701 }\r
702 } else {\r
703 ASSERT (EFI_ERROR (ErrorStatus));\r
704 return ErrorStatus;\r
705 }\r
706 }\r
707 }\r
708}\r
709\r
710\r
711STATIC\r
712EFI_STATUS\r
713CreateChildNode (\r
714 IN CORE_SECTION_STREAM_NODE *Stream,\r
715 IN UINT32 ChildOffset,\r
716 OUT CORE_SECTION_CHILD_NODE **ChildNode\r
717 )\r
718/*++\r
719\r
720Routine Description:\r
721 Worker function. Constructor for new child nodes.\r
722\r
723Arguments:\r
724 Stream - Indicates the section stream in which to add the child.\r
725 ChildOffset - Indicates the offset in Stream that is the beginning\r
726 of the child section.\r
727 ChildNode - Indicates the Callee allocated and initialized child.\r
728\r
729Returns:\r
730 EFI_SUCCESS - Child node was found and returned.\r
731 EFI_OUT_OF_RESOURCES- Memory allocation failed.\r
732 EFI_PROTOCOL_ERROR - Encapsulation sections produce new stream handles when\r
733 the child node is created. If the section type is GUID\r
734 defined, and the extraction GUID does not exist, and\r
735 producing the stream requires the GUID, then a protocol\r
736 error is generated and no child is produced.\r
737 Values returned by OpenSectionStreamEx.\r
738\r
739--*/\r
740{\r
741 EFI_STATUS Status;\r
742 EFI_COMMON_SECTION_HEADER *SectionHeader;\r
743 EFI_COMPRESSION_SECTION *CompressionHeader;\r
744 EFI_GUID_DEFINED_SECTION *GuidedHeader;\r
745 EFI_TIANO_DECOMPRESS_PROTOCOL *Decompress;\r
746 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;\r
747 VOID *NewStreamBuffer;\r
748 VOID *ScratchBuffer;\r
749 UINT32 ScratchSize;\r
750 UINTN NewStreamBufferSize;\r
751 UINT32 AuthenticationStatus;\r
752 UINT32 SectionLength;\r
753 \r
754 CORE_SECTION_CHILD_NODE *Node;\r
755\r
756 SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);\r
757\r
758 //\r
759 // Allocate a new node\r
760 //\r
761 *ChildNode = CoreAllocateBootServicesPool (sizeof (CORE_SECTION_CHILD_NODE));\r
762 Node = *ChildNode;\r
763 if (Node == NULL) {\r
764 return EFI_OUT_OF_RESOURCES;\r
765 }\r
766 \r
767 //\r
768 // Now initialize it\r
769 //\r
770 Node->Signature = CORE_SECTION_CHILD_SIGNATURE;\r
771 Node->Type = SectionHeader->Type;\r
772 Node->Size = SECTION_SIZE (SectionHeader);\r
773 Node->OffsetInStream = ChildOffset;\r
774 Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;\r
775 Node->EncapsulationGuid = NULL;\r
776 \r
777 //\r
778 // If it's an encapsulating section, then create the new section stream also\r
779 //\r
780 switch (Node->Type) {\r
781 case EFI_SECTION_COMPRESSION:\r
782 //\r
783 // Get the CompressionSectionHeader\r
784 //\r
785 ASSERT (Node->Size >= sizeof (EFI_COMPRESSION_SECTION));\r
786 \r
787 CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;\r
788 \r
789 //\r
790 // Allocate space for the new stream\r
791 //\r
792 if (CompressionHeader->UncompressedLength > 0) {\r
793 NewStreamBufferSize = CompressionHeader->UncompressedLength;\r
794 NewStreamBuffer = CoreAllocateBootServicesPool (NewStreamBufferSize);\r
795 if (NewStreamBuffer == NULL) {\r
796 CoreFreePool (Node);\r
797 return EFI_OUT_OF_RESOURCES;\r
798 }\r
799 \r
800 if (CompressionHeader->CompressionType == EFI_NOT_COMPRESSED) {\r
801 //\r
802 // stream is not actually compressed, just encapsulated. So just copy it.\r
803 //\r
804 CopyMem (NewStreamBuffer, CompressionHeader + 1, NewStreamBufferSize);\r
805 } else if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION ||\r
806 CompressionHeader->CompressionType == EFI_CUSTOMIZED_COMPRESSION) {\r
807 //\r
808 // Decompress the stream\r
809 //\r
810 if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION) {\r
4afc6a7b 811 Status = CoreLocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
878ddf1f 812 } else {\r
813 Status = CoreLocateProtocol (&gEfiCustomizedDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
814 }\r
815 \r
816 ASSERT_EFI_ERROR (Status);\r
817 \r
818 Status = Decompress->GetInfo (\r
819 Decompress,\r
820 CompressionHeader + 1,\r
821 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
822 (UINT32 *)&NewStreamBufferSize,\r
823 &ScratchSize\r
824 );\r
825 ASSERT_EFI_ERROR (Status);\r
826 ASSERT (NewStreamBufferSize == CompressionHeader->UncompressedLength);\r
827\r
828 ScratchBuffer = CoreAllocateBootServicesPool (ScratchSize);\r
829 if (ScratchBuffer == NULL) {\r
830 CoreFreePool (Node);\r
831 CoreFreePool (NewStreamBuffer);\r
832 return EFI_OUT_OF_RESOURCES;\r
833 }\r
834\r
835 Status = Decompress->Decompress (\r
836 Decompress,\r
837 CompressionHeader + 1,\r
838 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
839 NewStreamBuffer,\r
840 (UINT32)NewStreamBufferSize,\r
841 ScratchBuffer,\r
842 ScratchSize\r
843 );\r
844 ASSERT_EFI_ERROR (Status);\r
845 CoreFreePool (ScratchBuffer); \r
846 }\r
847 } else {\r
848 NewStreamBuffer = NULL;\r
849 NewStreamBufferSize = 0;\r
850 }\r
851 \r
852 Status = OpenSectionStreamEx (\r
853 NewStreamBufferSize,\r
854 NewStreamBuffer,\r
855 FALSE,\r
856 Stream->AuthenticationStatus,\r
857 &Node->EncapsulatedStreamHandle\r
858 );\r
859 if (EFI_ERROR (Status)) {\r
860 CoreFreePool (Node);\r
861 CoreFreePool (NewStreamBuffer);\r
862 return Status;\r
863 }\r
864 break;\r
865\r
866 case EFI_SECTION_GUID_DEFINED:\r
867 GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;\r
868 Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
869 Status = CoreLocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
870 if (!EFI_ERROR (Status)) {\r
871 //\r
872 // NewStreamBuffer is always allocated by ExtractSection... No caller\r
873 // allocation here.\r
874 //\r
875 Status = GuidedExtraction->ExtractSection (\r
876 GuidedExtraction,\r
877 GuidedHeader,\r
878 &NewStreamBuffer,\r
879 &NewStreamBufferSize,\r
880 &AuthenticationStatus\r
881 );\r
882 if (EFI_ERROR (Status)) {\r
883 CoreFreePool (*ChildNode);\r
884 return EFI_PROTOCOL_ERROR;\r
885 }\r
886 \r
887 //\r
888 // Make sure we initialize the new stream with the correct \r
889 // authentication status for both aggregate and local status fields.\r
890 //\r
891 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r
892 //\r
893 // OR in the parent stream's aggregate status.\r
894 //\r
895 AuthenticationStatus |= Stream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
896 } else {\r
897 //\r
898 // since there's no authentication data contributed by the section,\r
899 // just inherit the full value from our immediate parent.\r
900 //\r
901 AuthenticationStatus = Stream->AuthenticationStatus;\r
902 }\r
903 \r
904 Status = OpenSectionStreamEx (\r
905 NewStreamBufferSize,\r
906 NewStreamBuffer,\r
907 FALSE,\r
908 AuthenticationStatus,\r
909 &Node->EncapsulatedStreamHandle\r
910 );\r
911 if (EFI_ERROR (Status)) {\r
912 CoreFreePool (*ChildNode);\r
913 CoreFreePool (NewStreamBuffer);\r
914 return Status;\r
915 }\r
916 } else {\r
917 //\r
918 // There's no GUIDed section extraction protocol available.\r
919 //\r
920 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {\r
921 //\r
922 // If the section REQUIRES an extraction protocol, then we're toast\r
923 //\r
924 CoreFreePool (*ChildNode);\r
925 return EFI_PROTOCOL_ERROR;\r
926 }\r
927 \r
928 //\r
929 // Figure out the proper authentication status\r
930 //\r
931 AuthenticationStatus = Stream->AuthenticationStatus;\r
932 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r
933 //\r
934 // The local status of the new stream is contained in \r
935 // AuthenticaionStatus. This value needs to be ORed into the\r
936 // Aggregate bits also...\r
937 //\r
938 \r
939 //\r
940 // Clear out and initialize the local status\r
941 //\r
942 AuthenticationStatus &= ~EFI_LOCAL_AUTH_STATUS_ALL;\r
943 AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED;\r
944 //\r
945 // OR local status into aggregate status\r
946 //\r
947 AuthenticationStatus |= AuthenticationStatus >> 16;\r
948 }\r
949 \r
950 SectionLength = SECTION_SIZE (GuidedHeader);\r
951 Status = OpenSectionStreamEx (\r
952 SectionLength - GuidedHeader->DataOffset,\r
953 (UINT8 *) GuidedHeader + GuidedHeader->DataOffset,\r
954 TRUE,\r
955 AuthenticationStatus,\r
956 &Node->EncapsulatedStreamHandle\r
957 );\r
958 if (EFI_ERROR (Status)) {\r
959 CoreFreePool (Node);\r
960 return Status;\r
961 }\r
962 }\r
963 \r
964 if ((AuthenticationStatus & EFI_LOCAL_AUTH_STATUS_ALL) == \r
965 (EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED)) {\r
966 //\r
967 // Need to register for RPN for when the required GUIDed extraction\r
968 // protocol becomes available. This will enable us to refresh the\r
969 // AuthenticationStatus cached in the Stream if it's ever requested\r
970 // again.\r
971 //\r
972 CreateGuidedExtractionRpnEvent (Stream, Node);\r
973 }\r
974 \r
975 break;\r
976\r
977 default:\r
978 \r
979 //\r
980 // Nothing to do if it's a leaf\r
981 //\r
982 break;\r
983 }\r
984 \r
985 //\r
986 // Last, add the new child node to the stream\r
987 //\r
988 InsertTailList (&Stream->Children, &Node->Link);\r
989\r
990 return EFI_SUCCESS;\r
991}\r
992\r
993\r
994STATIC\r
995VOID\r
996CreateGuidedExtractionRpnEvent (\r
997 IN CORE_SECTION_STREAM_NODE *ParentStream,\r
998 IN CORE_SECTION_CHILD_NODE *ChildNode\r
999 )\r
1000/*++\r
1001\r
1002Routine Description:\r
1003 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus\r
1004 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
1005\r
1006Arguments:\r
1007 ParentStream - Indicates the parent of the ecnapsulation section (child)\r
1008 ChildNode - Indicates the child node that is the encapsulation section.\r
1009\r
1010Returns:\r
1011 None\r
1012\r
1013--*/\r
1014{\r
1015 RPN_EVENT_CONTEXT *Context;\r
1016 \r
1017 //\r
1018 // Allocate new event structure and context\r
1019 //\r
1020 Context = CoreAllocateBootServicesPool (sizeof (RPN_EVENT_CONTEXT));\r
1021 ASSERT (Context != NULL);\r
1022 \r
1023 Context->ChildNode = ChildNode;\r
1024 Context->ParentStream = ParentStream;\r
1025 \r
1026 Context->Event = CoreCreateProtocolNotifyEvent (\r
1027 Context->ChildNode->EncapsulationGuid,\r
1028 EFI_TPL_NOTIFY,\r
1029 NotifyGuidedExtraction,\r
1030 Context,\r
1031 &Context->Registration,\r
1032 FALSE\r
1033 );\r
1034}\r
1035 \r
1036 \r
1037STATIC\r
1038VOID\r
1039EFIAPI\r
1040NotifyGuidedExtraction (\r
1041 IN EFI_EVENT Event,\r
1042 IN VOID *RpnContext\r
1043 )\r
1044/*++\r
1045\r
1046Routine Description:\r
1047 RPN callback function. Removes a stale section stream and re-initializes it\r
1048 with an updated AuthenticationStatus.\r
1049\r
1050Arguments:\r
1051 Event - The event that fired\r
1052 RpnContext - A pointer to the context that allows us to identify\r
1053 the relevent encapsulation...\r
1054\r
1055Returns:\r
1056 None\r
1057\r
1058--*/\r
1059{\r
1060 EFI_STATUS Status;\r
1061 EFI_GUID_DEFINED_SECTION *GuidedHeader;\r
1062 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;\r
1063 VOID *NewStreamBuffer;\r
1064 UINTN NewStreamBufferSize;\r
1065 UINT32 AuthenticationStatus;\r
1066 RPN_EVENT_CONTEXT *Context;\r
1067 \r
1068 Context = RpnContext;\r
1069 \r
1070 Status = CloseSectionStream (&mSectionExtraction, Context->ChildNode->EncapsulatedStreamHandle);\r
1071 if (!EFI_ERROR (Status)) {\r
1072 //\r
1073 // The stream closed successfully, so re-open the stream with correct AuthenticationStatus\r
1074 //\r
1075 \r
1076 GuidedHeader = (EFI_GUID_DEFINED_SECTION *) \r
1077 (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
1078 ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
1079 \r
1080 Status = CoreLocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
1081 ASSERT_EFI_ERROR (Status);\r
1082\r
1083 \r
1084 Status = GuidedExtraction->ExtractSection (\r
1085 GuidedExtraction,\r
1086 GuidedHeader,\r
1087 &NewStreamBuffer,\r
1088 &NewStreamBufferSize,\r
1089 &AuthenticationStatus\r
1090 );\r
1091 ASSERT_EFI_ERROR (Status);\r
1092 //\r
1093 // OR in the parent stream's aggregagate status.\r
1094 //\r
1095 AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
1096 Status = OpenSectionStreamEx (\r
1097 NewStreamBufferSize,\r
1098 NewStreamBuffer,\r
1099 FALSE,\r
1100 AuthenticationStatus,\r
1101 &Context->ChildNode->EncapsulatedStreamHandle\r
1102 );\r
1103 ASSERT_EFI_ERROR (Status);\r
1104 }\r
1105\r
1106 //\r
1107 // If above, the stream did not close successfully, it indicates it's\r
1108 // alread been closed by someone, so just destroy the event and be done with\r
1109 // it.\r
1110 //\r
1111 \r
1112 CoreCloseEvent (Event);\r
1113 CoreFreePool (Context);\r
1114} \r
1115 \r
1116\r
1117STATIC\r
1118VOID\r
1119FreeChildNode (\r
1120 IN CORE_SECTION_CHILD_NODE *ChildNode\r
1121 )\r
1122/*++\r
1123\r
1124Routine Description:\r
1125 Worker function. Destructor for child nodes.\r
1126\r
1127Arguments:\r
1128 ChildNode - Indicates the node to destroy\r
1129\r
1130Returns:\r
1131 none\r
1132\r
1133--*/\r
1134{\r
1135 ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);\r
1136 //\r
1137 // Remove the child from it's list\r
1138 //\r
1139 RemoveEntryList (&ChildNode->Link);\r
1140 \r
1141 if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
1142 //\r
1143 // If it's an encapsulating section, we close the resulting section stream.\r
1144 // CloseSectionStream will free all memory associated with the stream.\r
1145 //\r
1146 CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);\r
1147 }\r
1148 //\r
1149 // Last, free the child node itself\r
1150 //\r
1151 CoreFreePool (ChildNode);\r
1152} \r
1153\r
1154\r
1155STATIC\r
1156EFI_STATUS\r
1157OpenSectionStreamEx (\r
1158 IN UINTN SectionStreamLength,\r
1159 IN VOID *SectionStream,\r
1160 IN BOOLEAN AllocateBuffer,\r
1161 IN UINT32 AuthenticationStatus, \r
1162 OUT UINTN *SectionStreamHandle\r
1163 )\r
1164/*++\r
1165\r
1166 Routine Description:\r
1167 Worker function. Constructor for section streams.\r
1168\r
1169 Arguments:\r
1170 SectionStreamLength - Size in bytes of the section stream.\r
1171 SectionStream - Buffer containing the new section stream.\r
1172 AllocateBuffer - Indicates whether the stream buffer is to be copied\r
1173 or the input buffer is to be used in place.\r
1174 AuthenticationStatus- Indicates the default authentication status for the\r
1175 new stream.\r
1176 SectionStreamHandle - A pointer to a caller allocated section stream handle.\r
1177\r
1178 Returns:\r
1179 EFI_SUCCESS - Stream was added to stream database.\r
1180 EFI_OUT_OF_RESOURCES - memory allocation failed.\r
1181\r
1182--*/\r
1183{\r
1184 CORE_SECTION_STREAM_NODE *NewStream;\r
1185 EFI_TPL OldTpl;\r
1186 \r
1187 //\r
1188 // Allocate a new stream\r
1189 //\r
1190 NewStream = CoreAllocateBootServicesPool (sizeof (CORE_SECTION_STREAM_NODE));\r
1191 if (NewStream == NULL) {\r
1192 return EFI_OUT_OF_RESOURCES;\r
1193 }\r
1194 \r
1195 if (AllocateBuffer) { \r
1196 //\r
1197 // if we're here, we're double buffering, allocate the buffer and copy the\r
1198 // data in\r
1199 //\r
1200 if (SectionStreamLength > 0) {\r
1201 NewStream->StreamBuffer = CoreAllocateBootServicesPool (SectionStreamLength); \r
1202 if (NewStream->StreamBuffer == NULL) {\r
1203 CoreFreePool (NewStream);\r
1204 return EFI_OUT_OF_RESOURCES;\r
1205 }\r
1206 //\r
1207 // Copy in stream data\r
1208 //\r
1209 CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);\r
1210 } else {\r
1211 //\r
1212 // It's possible to have a zero length section stream.\r
1213 //\r
1214 NewStream->StreamBuffer = NULL;\r
1215 }\r
1216 } else {\r
1217 //\r
1218 // If were here, the caller has supplied the buffer (it's an internal call)\r
1219 // so just assign the buffer. This happens when we open section streams\r
1220 // as a result of expanding an encapsulating section.\r
1221 //\r
1222 NewStream->StreamBuffer = SectionStream;\r
1223 }\r
1224 \r
1225 //\r
1226 // Initialize the rest of the section stream\r
1227 //\r
1228 NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;\r
1229 NewStream->StreamHandle = (UINTN) NewStream;\r
1230 NewStream->StreamLength = SectionStreamLength;\r
1231 InitializeListHead (&NewStream->Children);\r
1232 NewStream->AuthenticationStatus = AuthenticationStatus;\r
1233 \r
1234 //\r
1235 // Add new stream to stream list\r
1236 //\r
1237 OldTpl = CoreRaiseTpl (EFI_TPL_NOTIFY);\r
1238 InsertTailList (&mStreamRoot, &NewStream->Link);\r
1239 CoreRestoreTpl (OldTpl);\r
1240\r
1241 *SectionStreamHandle = NewStream->StreamHandle;\r
1242 \r
1243 return EFI_SUCCESS;\r
1244}\r
1245\r
1246\r
1247STATIC\r
1248EFI_STATUS\r
1249FindStreamNode (\r
1250 IN UINTN SearchHandle,\r
1251 OUT CORE_SECTION_STREAM_NODE **FoundStream\r
1252 )\r
1253/*++\r
1254\r
1255 Routine Description:\r
1256 Worker function. Search stream database for requested stream handle.\r
1257\r
1258 Arguments:\r
1259 SearchHandle - Indicates which stream to look for.\r
1260 FoundStream - Output pointer to the found stream.\r
1261\r
1262 Returns:\r
1263 EFI_SUCCESS - StreamHandle was found and *FoundStream contains\r
1264 the stream node.\r
1265 EFI_NOT_FOUND - SearchHandle was not found in the stream database.\r
1266\r
1267--*/\r
1268{ \r
1269 CORE_SECTION_STREAM_NODE *StreamNode;\r
1270 \r
1271 if (!IsListEmpty (&mStreamRoot)) {\r
1272 StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));\r
1273 for (;;) {\r
1274 if (StreamNode->StreamHandle == SearchHandle) {\r
1275 *FoundStream = StreamNode;\r
1276 return EFI_SUCCESS;\r
1277 } else if (IsNodeAtEnd (&mStreamRoot, &StreamNode->Link)) {\r
1278 break;\r
1279 } else {\r
1280 StreamNode = STREAM_NODE_FROM_LINK (GetNextNode (&mStreamRoot, &StreamNode->Link));\r
1281 }\r
1282 }\r
1283 }\r
1284 \r
1285 return EFI_NOT_FOUND;\r
1286}\r
1287\r
1288\r
1289STATIC\r
1290BOOLEAN\r
1291IsValidSectionStream (\r
1292 IN VOID *SectionStream,\r
1293 IN UINTN SectionStreamLength\r
1294 )\r
1295/*++\r
1296\r
1297Routine Description:\r
1298 Check if a stream is valid.\r
1299\r
1300Arguments:\r
1301 SectionStream - The section stream to be checked\r
1302 SectionStreamLength - The length of section stream\r
1303\r
1304Returns:\r
1305 TRUE\r
1306 FALSE\r
1307\r
1308--*/\r
1309{\r
1310 UINTN TotalLength;\r
1311 UINTN SectionLength;\r
1312 EFI_COMMON_SECTION_HEADER *SectionHeader;\r
1313 EFI_COMMON_SECTION_HEADER *NextSectionHeader;\r
1314\r
1315 TotalLength = 0;\r
1316 SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
1317 \r
1318 while (TotalLength < SectionStreamLength) {\r
1319 SectionLength = SECTION_SIZE (SectionHeader);\r
1320 TotalLength += SectionLength;\r
1321\r
1322 if (TotalLength == SectionStreamLength) {\r
1323 return TRUE; \r
1324 }\r
1325\r
1326 //\r
1327 // Move to the next byte following the section...\r
1328 //\r
1329 SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);\r
1330 \r
1331 //\r
1332 // Figure out where the next section begins\r
1333 //\r
1334 NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) SectionHeader + 3);\r
1335 NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) NextSectionHeader & ~(UINTN)3);\r
1336 TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;\r
1337 SectionHeader = NextSectionHeader;\r
1338 }\r
1339\r
1340 ASSERT (FALSE);\r
1341 return FALSE;\r
1342}\r