]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
Changed the library class name to HiiLibFramework
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / SectionExtraction / CoreSectionExtraction.c
CommitLineData
28a00297 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
134STATIC\r
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
144STATIC\r
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
158STATIC\r
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
268STATIC\r
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
314STATIC\r
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 (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
457STATIC\r
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 (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 //\r
807 // Only support the EFI_SATNDARD_COMPRESSION algorithm.\r
808 // \r
809\r
810 //\r
811 // Decompress the stream\r
812 //\r
813 Status = CoreLocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
814 \r
815 ASSERT_EFI_ERROR (Status);\r
816 \r
817 Status = Decompress->GetInfo (\r
818 Decompress,\r
819 CompressionHeader + 1,\r
820 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
821 (UINT32 *)&NewStreamBufferSize,\r
822 &ScratchSize\r
823 );\r
824 ASSERT_EFI_ERROR (Status);\r
825 ASSERT (NewStreamBufferSize == CompressionHeader->UncompressedLength);\r
826\r
827 ScratchBuffer = CoreAllocateBootServicesPool (ScratchSize);\r
828 if (ScratchBuffer == NULL) {\r
829 CoreFreePool (Node);\r
830 CoreFreePool (NewStreamBuffer);\r
831 return EFI_OUT_OF_RESOURCES;\r
832 }\r
833\r
834 Status = Decompress->Decompress (\r
835 Decompress,\r
836 CompressionHeader + 1,\r
837 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
838 NewStreamBuffer,\r
839 (UINT32)NewStreamBufferSize,\r
840 ScratchBuffer,\r
841 ScratchSize\r
842 );\r
843 ASSERT_EFI_ERROR (Status);\r
844 CoreFreePool (ScratchBuffer); \r
845 }\r
846 } else {\r
847 NewStreamBuffer = NULL;\r
848 NewStreamBufferSize = 0;\r
849 }\r
850 \r
851 Status = OpenSectionStreamEx (\r
852 NewStreamBufferSize,\r
853 NewStreamBuffer,\r
854 FALSE,\r
855 Stream->AuthenticationStatus,\r
856 &Node->EncapsulatedStreamHandle\r
857 );\r
858 if (EFI_ERROR (Status)) {\r
859 CoreFreePool (Node);\r
860 CoreFreePool (NewStreamBuffer);\r
861 return Status;\r
862 }\r
863 break;\r
864\r
865 case EFI_SECTION_GUID_DEFINED:\r
866 GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;\r
867 Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
868 Status = CoreLocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
869 if (!EFI_ERROR (Status)) {\r
870 //\r
871 // NewStreamBuffer is always allocated by ExtractSection... No caller\r
872 // allocation here.\r
873 //\r
874 Status = GuidedExtraction->ExtractSection (\r
875 GuidedExtraction,\r
876 GuidedHeader,\r
877 &NewStreamBuffer,\r
878 &NewStreamBufferSize,\r
879 &AuthenticationStatus\r
880 );\r
881 if (EFI_ERROR (Status)) {\r
882 CoreFreePool (*ChildNode);\r
883 return EFI_PROTOCOL_ERROR;\r
884 }\r
885 \r
886 //\r
887 // Make sure we initialize the new stream with the correct \r
888 // authentication status for both aggregate and local status fields.\r
889 //\r
890 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r
891 //\r
892 // OR in the parent stream's aggregate status.\r
893 //\r
894 AuthenticationStatus |= Stream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
895 } else {\r
896 //\r
897 // since there's no authentication data contributed by the section,\r
898 // just inherit the full value from our immediate parent.\r
899 //\r
900 AuthenticationStatus = Stream->AuthenticationStatus;\r
901 }\r
902 \r
903 Status = OpenSectionStreamEx (\r
904 NewStreamBufferSize,\r
905 NewStreamBuffer,\r
906 FALSE,\r
907 AuthenticationStatus,\r
908 &Node->EncapsulatedStreamHandle\r
909 );\r
910 if (EFI_ERROR (Status)) {\r
911 CoreFreePool (*ChildNode);\r
912 CoreFreePool (NewStreamBuffer);\r
913 return Status;\r
914 }\r
915 } else {\r
916 //\r
917 // There's no GUIDed section extraction protocol available.\r
918 //\r
919 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {\r
920 //\r
921 // If the section REQUIRES an extraction protocol, then we're toast\r
922 //\r
923 CoreFreePool (*ChildNode);\r
924 return EFI_PROTOCOL_ERROR;\r
925 }\r
926 \r
927 //\r
928 // Figure out the proper authentication status\r
929 //\r
930 AuthenticationStatus = Stream->AuthenticationStatus;\r
931 if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r
932 //\r
933 // The local status of the new stream is contained in \r
934 // AuthenticaionStatus. This value needs to be ORed into the\r
935 // Aggregate bits also...\r
936 //\r
937 \r
938 //\r
939 // Clear out and initialize the local status\r
940 //\r
941 AuthenticationStatus &= ~EFI_LOCAL_AUTH_STATUS_ALL;\r
942 AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED;\r
943 //\r
944 // OR local status into aggregate status\r
945 //\r
946 AuthenticationStatus |= AuthenticationStatus >> 16;\r
947 }\r
948 \r
949 SectionLength = SECTION_SIZE (GuidedHeader);\r
950 Status = OpenSectionStreamEx (\r
951 SectionLength - GuidedHeader->DataOffset,\r
952 (UINT8 *) GuidedHeader + GuidedHeader->DataOffset,\r
953 TRUE,\r
954 AuthenticationStatus,\r
955 &Node->EncapsulatedStreamHandle\r
956 );\r
957 if (EFI_ERROR (Status)) {\r
958 CoreFreePool (Node);\r
959 return Status;\r
960 }\r
961 }\r
962 \r
963 if ((AuthenticationStatus & EFI_LOCAL_AUTH_STATUS_ALL) == \r
964 (EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED)) {\r
965 //\r
966 // Need to register for RPN for when the required GUIDed extraction\r
967 // protocol becomes available. This will enable us to refresh the\r
968 // AuthenticationStatus cached in the Stream if it's ever requested\r
969 // again.\r
970 //\r
971 CreateGuidedExtractionRpnEvent (Stream, Node);\r
972 }\r
973 \r
974 break;\r
975\r
976 default:\r
977 \r
978 //\r
979 // Nothing to do if it's a leaf\r
980 //\r
981 break;\r
982 }\r
983 \r
984 //\r
985 // Last, add the new child node to the stream\r
986 //\r
987 InsertTailList (&Stream->Children, &Node->Link);\r
988\r
989 return EFI_SUCCESS;\r
990}\r
991\r
992\r
993STATIC\r
994VOID\r
995CreateGuidedExtractionRpnEvent (\r
996 IN CORE_SECTION_STREAM_NODE *ParentStream,\r
997 IN CORE_SECTION_CHILD_NODE *ChildNode\r
998 )\r
999/*++\r
1000\r
1001Routine Description:\r
1002 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus\r
1003 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
1004\r
1005Arguments:\r
1006 ParentStream - Indicates the parent of the ecnapsulation section (child)\r
1007 ChildNode - Indicates the child node that is the encapsulation section.\r
1008\r
1009Returns:\r
1010 None\r
1011\r
1012--*/\r
1013{\r
1014 RPN_EVENT_CONTEXT *Context;\r
1015 \r
1016 //\r
1017 // Allocate new event structure and context\r
1018 //\r
1019 Context = CoreAllocateBootServicesPool (sizeof (RPN_EVENT_CONTEXT));\r
1020 ASSERT (Context != NULL);\r
1021 \r
1022 Context->ChildNode = ChildNode;\r
1023 Context->ParentStream = ParentStream;\r
1024 \r
1025 Context->Event = CoreCreateProtocolNotifyEvent (\r
1026 Context->ChildNode->EncapsulationGuid,\r
1027 TPL_NOTIFY,\r
1028 NotifyGuidedExtraction,\r
1029 Context,\r
1030 &Context->Registration,\r
1031 FALSE\r
1032 );\r
1033}\r
1034 \r
1035 \r
1036STATIC\r
1037VOID\r
1038EFIAPI\r
1039NotifyGuidedExtraction (\r
1040 IN EFI_EVENT Event,\r
1041 IN VOID *RpnContext\r
1042 )\r
1043/*++\r
1044\r
1045Routine Description:\r
1046 RPN callback function. Removes a stale section stream and re-initializes it\r
1047 with an updated AuthenticationStatus.\r
1048\r
1049Arguments:\r
1050 Event - The event that fired\r
1051 RpnContext - A pointer to the context that allows us to identify\r
1052 the relevent encapsulation...\r
1053\r
1054Returns:\r
1055 None\r
1056\r
1057--*/\r
1058{\r
1059 EFI_STATUS Status;\r
1060 EFI_GUID_DEFINED_SECTION *GuidedHeader;\r
1061 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;\r
1062 VOID *NewStreamBuffer;\r
1063 UINTN NewStreamBufferSize;\r
1064 UINT32 AuthenticationStatus;\r
1065 RPN_EVENT_CONTEXT *Context;\r
1066 \r
1067 Context = RpnContext;\r
1068 \r
1069 Status = CloseSectionStream (&mSectionExtraction, Context->ChildNode->EncapsulatedStreamHandle);\r
1070 if (!EFI_ERROR (Status)) {\r
1071 //\r
1072 // The stream closed successfully, so re-open the stream with correct AuthenticationStatus\r
1073 //\r
1074 \r
1075 GuidedHeader = (EFI_GUID_DEFINED_SECTION *) \r
1076 (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
1077 ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
1078 \r
1079 Status = CoreLocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
1080 ASSERT_EFI_ERROR (Status);\r
1081\r
1082 \r
1083 Status = GuidedExtraction->ExtractSection (\r
1084 GuidedExtraction,\r
1085 GuidedHeader,\r
1086 &NewStreamBuffer,\r
1087 &NewStreamBufferSize,\r
1088 &AuthenticationStatus\r
1089 );\r
1090 ASSERT_EFI_ERROR (Status);\r
1091 //\r
1092 // OR in the parent stream's aggregagate status.\r
1093 //\r
1094 AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
1095 Status = OpenSectionStreamEx (\r
1096 NewStreamBufferSize,\r
1097 NewStreamBuffer,\r
1098 FALSE,\r
1099 AuthenticationStatus,\r
1100 &Context->ChildNode->EncapsulatedStreamHandle\r
1101 );\r
1102 ASSERT_EFI_ERROR (Status);\r
1103 }\r
1104\r
1105 //\r
1106 // If above, the stream did not close successfully, it indicates it's\r
1107 // alread been closed by someone, so just destroy the event and be done with\r
1108 // it.\r
1109 //\r
1110 \r
1111 CoreCloseEvent (Event);\r
1112 CoreFreePool (Context);\r
1113} \r
1114 \r
1115\r
1116STATIC\r
1117VOID\r
1118FreeChildNode (\r
1119 IN CORE_SECTION_CHILD_NODE *ChildNode\r
1120 )\r
1121/*++\r
1122\r
1123Routine Description:\r
1124 Worker function. Destructor for child nodes.\r
1125\r
1126Arguments:\r
1127 ChildNode - Indicates the node to destroy\r
1128\r
1129Returns:\r
1130 none\r
1131\r
1132--*/\r
1133{\r
1134 ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);\r
1135 //\r
1136 // Remove the child from it's list\r
1137 //\r
1138 RemoveEntryList (&ChildNode->Link);\r
1139 \r
1140 if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
1141 //\r
1142 // If it's an encapsulating section, we close the resulting section stream.\r
1143 // CloseSectionStream will free all memory associated with the stream.\r
1144 //\r
1145 CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);\r
1146 }\r
1147 //\r
1148 // Last, free the child node itself\r
1149 //\r
1150 CoreFreePool (ChildNode);\r
1151} \r
1152\r
1153\r
1154STATIC\r
1155EFI_STATUS\r
1156OpenSectionStreamEx (\r
1157 IN UINTN SectionStreamLength,\r
1158 IN VOID *SectionStream,\r
1159 IN BOOLEAN AllocateBuffer,\r
1160 IN UINT32 AuthenticationStatus, \r
1161 OUT UINTN *SectionStreamHandle\r
1162 )\r
1163/*++\r
1164\r
1165 Routine Description:\r
1166 Worker function. Constructor for section streams.\r
1167\r
1168 Arguments:\r
1169 SectionStreamLength - Size in bytes of the section stream.\r
1170 SectionStream - Buffer containing the new section stream.\r
1171 AllocateBuffer - Indicates whether the stream buffer is to be copied\r
1172 or the input buffer is to be used in place.\r
1173 AuthenticationStatus- Indicates the default authentication status for the\r
1174 new stream.\r
1175 SectionStreamHandle - A pointer to a caller allocated section stream handle.\r
1176\r
1177 Returns:\r
1178 EFI_SUCCESS - Stream was added to stream database.\r
1179 EFI_OUT_OF_RESOURCES - memory allocation failed.\r
1180\r
1181--*/\r
1182{\r
1183 CORE_SECTION_STREAM_NODE *NewStream;\r
1184 EFI_TPL OldTpl;\r
1185 \r
1186 //\r
1187 // Allocate a new stream\r
1188 //\r
1189 NewStream = CoreAllocateBootServicesPool (sizeof (CORE_SECTION_STREAM_NODE));\r
1190 if (NewStream == NULL) {\r
1191 return EFI_OUT_OF_RESOURCES;\r
1192 }\r
1193 \r
1194 if (AllocateBuffer) { \r
1195 //\r
1196 // if we're here, we're double buffering, allocate the buffer and copy the\r
1197 // data in\r
1198 //\r
1199 if (SectionStreamLength > 0) {\r
1200 NewStream->StreamBuffer = CoreAllocateBootServicesPool (SectionStreamLength); \r
1201 if (NewStream->StreamBuffer == NULL) {\r
1202 CoreFreePool (NewStream);\r
1203 return EFI_OUT_OF_RESOURCES;\r
1204 }\r
1205 //\r
1206 // Copy in stream data\r
1207 //\r
1208 CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);\r
1209 } else {\r
1210 //\r
1211 // It's possible to have a zero length section stream.\r
1212 //\r
1213 NewStream->StreamBuffer = NULL;\r
1214 }\r
1215 } else {\r
1216 //\r
1217 // If were here, the caller has supplied the buffer (it's an internal call)\r
1218 // so just assign the buffer. This happens when we open section streams\r
1219 // as a result of expanding an encapsulating section.\r
1220 //\r
1221 NewStream->StreamBuffer = SectionStream;\r
1222 }\r
1223 \r
1224 //\r
1225 // Initialize the rest of the section stream\r
1226 //\r
1227 NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;\r
1228 NewStream->StreamHandle = (UINTN) NewStream;\r
1229 NewStream->StreamLength = SectionStreamLength;\r
1230 InitializeListHead (&NewStream->Children);\r
1231 NewStream->AuthenticationStatus = AuthenticationStatus;\r
1232 \r
1233 //\r
1234 // Add new stream to stream list\r
1235 //\r
1236 OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
1237 InsertTailList (&mStreamRoot, &NewStream->Link);\r
1238 CoreRestoreTpl (OldTpl);\r
1239\r
1240 *SectionStreamHandle = NewStream->StreamHandle;\r
1241 \r
1242 return EFI_SUCCESS;\r
1243}\r
1244\r
1245\r
1246STATIC\r
1247EFI_STATUS\r
1248FindStreamNode (\r
1249 IN UINTN SearchHandle,\r
1250 OUT CORE_SECTION_STREAM_NODE **FoundStream\r
1251 )\r
1252/*++\r
1253\r
1254 Routine Description:\r
1255 Worker function. Search stream database for requested stream handle.\r
1256\r
1257 Arguments:\r
1258 SearchHandle - Indicates which stream to look for.\r
1259 FoundStream - Output pointer to the found stream.\r
1260\r
1261 Returns:\r
1262 EFI_SUCCESS - StreamHandle was found and *FoundStream contains\r
1263 the stream node.\r
1264 EFI_NOT_FOUND - SearchHandle was not found in the stream database.\r
1265\r
1266--*/\r
1267{ \r
1268 CORE_SECTION_STREAM_NODE *StreamNode;\r
1269 \r
1270 if (!IsListEmpty (&mStreamRoot)) {\r
1271 StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));\r
1272 for (;;) {\r
1273 if (StreamNode->StreamHandle == SearchHandle) {\r
1274 *FoundStream = StreamNode;\r
1275 return EFI_SUCCESS;\r
1276 } else if (IsNodeAtEnd (&mStreamRoot, &StreamNode->Link)) {\r
1277 break;\r
1278 } else {\r
1279 StreamNode = STREAM_NODE_FROM_LINK (GetNextNode (&mStreamRoot, &StreamNode->Link));\r
1280 }\r
1281 }\r
1282 }\r
1283 \r
1284 return EFI_NOT_FOUND;\r
1285}\r
1286\r
1287\r
1288STATIC\r
1289BOOLEAN\r
1290IsValidSectionStream (\r
1291 IN VOID *SectionStream,\r
1292 IN UINTN SectionStreamLength\r
1293 )\r
1294/*++\r
1295\r
1296Routine Description:\r
1297 Check if a stream is valid.\r
1298\r
1299Arguments:\r
1300 SectionStream - The section stream to be checked\r
1301 SectionStreamLength - The length of section stream\r
1302\r
1303Returns:\r
1304 TRUE\r
1305 FALSE\r
1306\r
1307--*/\r
1308{\r
1309 UINTN TotalLength;\r
1310 UINTN SectionLength;\r
1311 EFI_COMMON_SECTION_HEADER *SectionHeader;\r
1312 EFI_COMMON_SECTION_HEADER *NextSectionHeader;\r
1313\r
1314 TotalLength = 0;\r
1315 SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
1316 \r
1317 while (TotalLength < SectionStreamLength) {\r
1318 SectionLength = SECTION_SIZE (SectionHeader);\r
1319 TotalLength += SectionLength;\r
1320\r
1321 if (TotalLength == SectionStreamLength) {\r
1322 return TRUE; \r
1323 }\r
1324\r
1325 //\r
1326 // Move to the next byte following the section...\r
1327 //\r
1328 SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);\r
1329 \r
1330 //\r
1331 // Figure out where the next section begins\r
1332 //\r
1333 NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) SectionHeader + 3);\r
1334 NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) NextSectionHeader & ~(UINTN)3);\r
1335 TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;\r
1336 SectionHeader = NextSectionHeader;\r
1337 }\r
1338\r
1339 ASSERT (FALSE);\r
1340 return FALSE;\r
1341}\r