]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg PeiCore: Reset PeimNeedingDispatch when its security violation
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
index 7480b662c579cbb86a0c915736f5d38480566ea7..ff43a90ba53c66543789e919183059d7f034ab8f 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   EFI PEI Core dispatch services\r
   \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -670,8 +671,8 @@ PeiCheckAndSwitchStack (
 \r
   if (Private->SwitchStackSignal) {\r
     //\r
-    // Before switch stack from temporary memory to permenent memory, calculate the heap and stack\r
-    // usage in temporary memory for debuging.\r
+    // Before switch stack from temporary memory to permanent memory, calculate the heap and stack\r
+    // usage in temporary memory for debugging.\r
     //\r
     DEBUG_CODE_BEGIN ();\r
       UINT32  *StackPointer;\r
@@ -681,15 +682,15 @@ PeiCheckAndSwitchStack (
            && (*StackPointer == INIT_CAR_VALUE);\r
            StackPointer ++);\r
 \r
-        DEBUG ((EFI_D_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
-        DEBUG ((EFI_D_INFO, "Temp Heap  : BaseAddress=0x%p Length=0x%X\n", Private->HobList.Raw, (UINT32)((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN) Private->HobList.Raw)));\r
-        DEBUG ((EFI_D_INFO, "Total temporary memory:    %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
-        DEBUG ((EFI_D_INFO, "  temporary memory stack ever used: %d bytes.\n",\r
-               (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
-              ));\r
-        DEBUG ((EFI_D_INFO, "  temporary memory heap used:       %d bytes.\n",\r
-               (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
-              ));\r
+      DEBUG ((EFI_D_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
+      DEBUG ((EFI_D_INFO, "Temp Heap  : BaseAddress=0x%p Length=0x%X\n", Private->HobList.Raw, (UINT32)((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryTop - (UINTN) Private->HobList.Raw)));\r
+      DEBUG ((EFI_D_INFO, "Total temporary memory:    %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
+      DEBUG ((EFI_D_INFO, "  temporary memory stack ever used: %d bytes.\n",\r
+             (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
+            ));\r
+      DEBUG ((EFI_D_INFO, "  temporary memory heap used:       %d bytes.\n",\r
+             (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
+            ));\r
     DEBUG_CODE_END ();\r
 \r
     if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
@@ -708,10 +709,10 @@ PeiCheckAndSwitchStack (
     //\r
     // Reserve the size of new stack at bottom of physical memory\r
     //\r
-    // The size of new stack in permenent memory must be the same size \r
+    // The size of new stack in permanent memory must be the same size\r
     // or larger than the size of old stack in temporary memory.\r
     // But if new stack is smaller than the size of old stack, we also reserve\r
-    // the size of old stack at bottom of permenent memory.\r
+    // the size of old stack at bottom of permanent memory.\r
     //\r
     NewStackSize = RShiftU64 (Private->PhysicalMemoryLength, 1);\r
     NewStackSize = ALIGN_VALUE (NewStackSize, EFI_PAGE_SIZE);\r
@@ -788,7 +789,7 @@ PeiCheckAndSwitchStack (
 \r
       //\r
       // Temporary Ram Support PPI is provided by platform, it will copy \r
-      // temporary memory to permenent memory and do stack switching.\r
+      // temporary memory to permanent memory and do stack switching.\r
       // After invoking Temporary Ram Support PPI, the following code's \r
       // stack is in permanent memory.\r
       //\r
@@ -1056,7 +1057,7 @@ PeiDispatcher (
             ASSERT_EFI_ERROR (Status);\r
             if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
               //\r
-              // For Fv type file, Produce new FV PPI and FV hob\r
+              // For Fv type file, Produce new FvInfo PPI and FV hob\r
               //\r
               Status = ProcessFvFile (Private, &Private->Fv[FvCount], PeimFileHandle);\r
               if (Status == EFI_SUCCESS) {\r
@@ -1065,6 +1066,13 @@ PeiDispatcher (
                 //\r
                 Private->Fv[FvCount].PeimState[PeimCount]++;\r
                 Private->PeimDispatchOnThisPass = TRUE;\r
+              } else {\r
+                //\r
+                // The related GuidedSectionExtraction/Decompress PPI for the\r
+                // encapsulated FV image section may be installed in the rest\r
+                // of this do-while loop, so need to make another pass.\r
+                //\r
+                Private->PeimNeedingDispatch = TRUE;\r
               }\r
             } else {\r
               //\r
@@ -1103,6 +1111,13 @@ PeiDispatcher (
                   PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
                   PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
                   Private->PeimDispatchOnThisPass = TRUE;\r
+                } else {\r
+                  //\r
+                  // The related GuidedSectionExtraction PPI for the\r
+                  // signed PEIM image section may be installed in the rest\r
+                  // of this do-while loop, so need to make another pass.\r
+                  //\r
+                  Private->PeimNeedingDispatch = TRUE;\r
                 }\r
 \r
                 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
@@ -1134,7 +1149,7 @@ PeiDispatcher (
             if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) &&   \\r
                 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
               //\r
-              // If memory is availble we shadow images by default for performance reasons.\r
+              // If memory is available we shadow images by default for performance reasons.\r
               // We call the entry point a 2nd time so the module knows it's shadowed.\r
               //\r
               //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
@@ -1192,11 +1207,11 @@ PeiDispatcher (
     Private->CurrentPeimFvCount = 0;\r
 \r
     //\r
-    // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r
+    // PeimNeedingDispatch being TRUE means we found a PEIM/FV that did not get\r
     //  dispatched. So we need to make another pass\r
     //\r
-    // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r
-    //  pass. If we did not dispatch a PEIM there is no point in trying again\r
+    // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM/FV on this\r
+    //  pass. If we did not dispatch a PEIM/FV there is no point in trying again\r
     //  as it will fail the next time too (nothing has changed).\r
     //\r
   } while (Private->PeimNeedingDispatch && Private->PeimDispatchOnThisPass);\r