]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.c
Update the copyright notice format
[mirror_edk2.git] / MdePkg / Library / DxeExtractGuidedSectionLib / DxeExtractGuidedSectionLib.c
index 9e9cc009abd69db76a3e8b46acde07b7ce5a7894..e0a07835d709d406aa522be9b8090f836d018dc7 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Provide generic extract guided section functions for Dxe phase.\r
 \r
-  Copyright (c) 2007 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<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
   http://opensource.org/licenses/bsd-license.php\r
 #include <PiDxe.h>\r
 \r
 #include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 \r
-GUID                 *mExtractHandlerGuidTable;\r
+#define EXTRACT_HANDLER_TABLE_SIZE   0x10\r
+\r
 UINT32               mNumberOfExtractHandler = 0;\r
+UINT32               mMaxNumberOfExtractHandler = 0;\r
 \r
-EXTRACT_GUIDED_SECTION_DECODE_HANDLER   *mExtractDecodeHandlerTable;\r
-EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r
+GUID                 *mExtractHandlerGuidTable = NULL;\r
+EXTRACT_GUIDED_SECTION_DECODE_HANDLER   *mExtractDecodeHandlerTable = NULL;\r
+EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable = NULL;\r
 \r
 /**\r
-  Constructor allocates the global memory to store the registered guid and Handler list.\r
+  Reallocates more global memory to store the registered guid and Handler list.\r
 \r
-  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
-  @param  SystemTable   A pointer to the EFI System Table.\r
-\r
-  @retval  RETURN_SUCCESS            Allocate the global memory space to store guid and function tables.\r
+  @retval  RETURN_SUCCESS            Reallocate more global memory space to store guid and function tables.\r
   @retval  RETURN_OUT_OF_RESOURCES   No enough memory to allocated.\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-DxeExtractGuidedSectionLibConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
+ReallocateExtractHandlerTable (\r
   )\r
-{\r
+{ \r
   //\r
-  // Allocate global pool space to store the registered handler and its guid value.\r
+  // Reallocate memory for GuidTable\r
   //\r
-  mExtractHandlerGuidTable    = (GUID *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));\r
+  mExtractHandlerGuidTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (GUID), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (GUID), \r
+                               mExtractHandlerGuidTable\r
+                             );\r
+\r
   if (mExtractHandlerGuidTable == NULL) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
+    goto Done;\r
   }\r
-  \r
-  mExtractDecodeHandlerTable  = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r
+\r
+  //\r
+  // Reallocate memory for Decode handler Table\r
+  //\r
+  mExtractDecodeHandlerTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r
+                               mExtractDecodeHandlerTable\r
+                             );\r
+\r
   if (mExtractDecodeHandlerTable == NULL) {\r
-    FreePool (mExtractHandlerGuidTable);\r
-    return RETURN_OUT_OF_RESOURCES;\r
+    goto Done;\r
   }\r
 \r
-  mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r
+  //\r
+  // Reallocate memory for GetInfo handler Table\r
+  //\r
+  mExtractGetInfoHandlerTable = ReallocatePool (\r
+                               mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r
+                               (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r
+                               mExtractGetInfoHandlerTable\r
+                             );\r
+\r
   if (mExtractGetInfoHandlerTable == NULL) {\r
+    goto Done;\r
+  }\r
+  \r
+  //\r
+  // Increase max handler number\r
+  //\r
+  mMaxNumberOfExtractHandler = mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE;\r
+  return RETURN_SUCCESS;\r
+\r
+Done:\r
+  if (mExtractHandlerGuidTable != NULL) {\r
     FreePool (mExtractHandlerGuidTable);\r
+  }\r
+  if (mExtractDecodeHandlerTable != NULL) {\r
     FreePool (mExtractDecodeHandlerTable);\r
-    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+  if (mExtractGetInfoHandlerTable != NULL) {\r
+    FreePool (mExtractGetInfoHandlerTable);\r
   }\r
   \r
-  return RETURN_SUCCESS;\r
+  return RETURN_OUT_OF_RESOURCES;\r
+}\r
+/**\r
+  Constructor allocates the global memory to store the registered guid and Handler list.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval  RETURN_SUCCESS            Allocate the global memory space to store guid and function tables.\r
+  @retval  RETURN_OUT_OF_RESOURCES   No enough memory to allocated.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+DxeExtractGuidedSectionLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return ReallocateExtractHandlerTable ();\r
 }\r
 \r
 /**\r
@@ -99,6 +149,7 @@ ExtractGuidedSectionGetGuidList (
   Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.\r
   If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.\r
   If there are not enough resources available to register the handlers  then RETURN_OUT_OF_RESOURCES is returned.\r
+  \r
   If SectionGuid is NULL, then ASSERT().\r
   If GetInfoHandler is NULL, then ASSERT().\r
   If DecodeHandler is NULL, then ASSERT().\r
@@ -112,7 +163,6 @@ ExtractGuidedSectionGetGuidList (
                              allocated output buffer. \r
 \r
   @retval  RETURN_SUCCESS           The handlers were registered.\r
-  @retval  RETURN_ALREADY_STARTED   Handlers have already been registered for the GUID specified by SectionGuid. \r
   @retval  RETURN_OUT_OF_RESOURCES  There are not enough resources available to register the handlers.\r
 \r
 **/\r
@@ -149,8 +199,10 @@ ExtractGuidedSectionRegisterHandlers (
   //\r
   // Check the global table is enough to contain new Handler.\r
   //\r
-  if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
+  if (mNumberOfExtractHandler >= mMaxNumberOfExtractHandler) {\r
+    if (ReallocateExtractHandlerTable () != RETURN_SUCCESS) {\r
+      return RETURN_OUT_OF_RESOURCES;\r
+    }\r
   }\r
   \r
   //\r
@@ -176,6 +228,7 @@ ExtractGuidedSectionRegisterHandlers (
   of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r
   is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of\r
   type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.\r
+  \r
   If InputSection is NULL, then ASSERT().\r
   If OutputBufferSize is NULL, then ASSERT().\r
   If ScratchBufferSize is NULL, then ASSERT().\r
@@ -250,7 +303,8 @@ ExtractGuidedSectionGetInfo (
   decode operation is returned in AuthenticationStatus.  If the decoded buffer is identical to the data in InputSection,\r
   then OutputBuffer is set to point at the data in InputSection.  Otherwise, the decoded data will be placed in caller\r
   allocated buffer specified by OutputBuffer.    This function is responsible for computing the  EFI_AUTH_STATUS_PLATFORM_OVERRIDE\r
-  bit of in AuthenticationStatus.  The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned.  \r
+  bit of in AuthenticationStatus.  The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned. \r
+   \r
   If InputSection is NULL, then ASSERT().\r
   If OutputBuffer is NULL, then ASSERT().\r
   If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r