]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Remove usage of MemoryAllocationLib, and use a simplistic allocation
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 May 2009 19:46:28 +0000 (19:46 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 May 2009 19:46:28 +0000 (19:46 +0000)
routine which makes use of the decompression scratch buffer.

This resolves a potential issue where the usage of the LZMA library
in the PEI phase may not have enough memory for the AllocatePool
function call.  (Some platforms may be extremely constrained in
heap space for the PEI phase.)

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8242 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c

index 9b4d78447ddc735ea84027e4ae61f4473f52792b..ebf8b9de18443e205372ec7ddb77e2ad0308b942 100644 (file)
@@ -49,6 +49,5 @@
   BaseLib\r
   DebugLib\r
   BaseMemoryLib\r
   BaseLib\r
   DebugLib\r
   BaseMemoryLib\r
-  MemoryAllocationLib\r
   ExtractGuidedSectionLib\r
 \r
   ExtractGuidedSectionLib\r
 \r
index 439e15beaba74b594dc9167b6a62c7c53032beb6..8497440f3f602b9ea4641f7c16e6cf9833521bb1 100644 (file)
@@ -20,7 +20,6 @@
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiDecompressLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 #include <Guid/LzmaDecompress.h>\r
 #include <Library/UefiDecompressLib.h>\r
 #include <Library/ExtractGuidedSectionLib.h>\r
 #include <Guid/LzmaDecompress.h>\r
 #include "Sdk/C/7zVersion.h"\r
 #include "Sdk/C/LzmaDec.h"\r
 \r
 #include "Sdk/C/7zVersion.h"\r
 #include "Sdk/C/LzmaDec.h"\r
 \r
+//\r
+// Global data\r
+//\r
+\r
+STATIC CONST VOID  *mSourceLastUsedWithGetInfo;\r
+STATIC UINT32      mSizeOfLastSource;\r
+STATIC UINT32      mDecompressedSizeForLastSource;\r
+STATIC VOID        *mScratchBuffer;\r
+STATIC UINTN       mScratchBufferSize;\r
+#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB\r
+\r
 /**\r
   Allocation routine used by LZMA decompression.\r
 \r
 /**\r
   Allocation routine used by LZMA decompression.\r
 \r
@@ -44,7 +54,17 @@ SzAlloc (
   size_t size\r
   )\r
 {\r
   size_t size\r
   )\r
 {\r
-  return AllocatePool (size);\r
+  VOID *addr;\r
+\r
+  if (mScratchBufferSize >= size) {\r
+    addr = mScratchBuffer;\r
+    mScratchBuffer = (VOID*) ((UINT8*)addr + size);\r
+    mScratchBufferSize -= size;\r
+    return addr;\r
+  } else {\r
+    ASSERT (FALSE);\r
+    return NULL;\r
+  }\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -60,9 +80,11 @@ SzFree (
   void *address\r
   )\r
 {\r
   void *address\r
   )\r
 {\r
-  if (address != NULL) {\r
-    FreePool (address);\r
-  }\r
+  //\r
+  // We use the 'scratch buffer' for allocations, so there is no free\r
+  // operation required.  The scratch buffer will be freed by the caller\r
+  // of the decompression code.\r
+  //\r
 }\r
 \r
 STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
 }\r
 \r
 STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
@@ -90,10 +112,6 @@ GetDecodedSizeOfBuf(
 // LZMA functions and data as defined in local LzmaDecompress.h\r
 //\r
 \r
 // LZMA functions and data as defined in local LzmaDecompress.h\r
 //\r
 \r
-STATIC CONST VOID  *mSourceLastUsedWithGetInfo;\r
-STATIC UINT32      mSizeOfLastSource;\r
-STATIC UINT32      mDecompressedSizeForLastSource;\r
-\r
 /**\r
   The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
   \r
 /**\r
   The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
   \r
@@ -124,7 +142,7 @@ LzmaUefiDecompressGetInfo (
   mSizeOfLastSource = SourceSize;\r
   mDecompressedSizeForLastSource = (UInt32)DecodedSize;\r
   *DestinationSize = mDecompressedSizeForLastSource;\r
   mSizeOfLastSource = SourceSize;\r
   mDecompressedSizeForLastSource = (UInt32)DecodedSize;\r
   *DestinationSize = mDecompressedSizeForLastSource;\r
-  *ScratchSize = 0x10;\r
+  *ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;\r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -159,6 +177,9 @@ LzmaUefiDecompress (
   decodedBufSize = (SizeT)mDecompressedSizeForLastSource;\r
   encodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);\r
 \r
   decodedBufSize = (SizeT)mDecompressedSizeForLastSource;\r
   encodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);\r
 \r
+  mScratchBuffer = Scratch;\r
+  mScratchBufferSize = SCRATCH_BUFFER_REQUEST_SIZE;\r
+\r
   lzmaResult = LzmaDecode(\r
     Destination,\r
     &decodedBufSize,\r
   lzmaResult = LzmaDecode(\r
     Destination,\r
     &decodedBufSize,\r