diff options
author | jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-05-05 19:46:28 +0000 |
---|---|---|
committer | jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-05-05 19:46:28 +0000 |
commit | 57cca89e0aa24d3feb6322c556038edd3aad830f (patch) | |
tree | d61326acd5aacded2bdf856b463b60bbc76ec84f /IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib | |
parent | de29c94afc10e4f52675ae8c691e1cef736b43cb (diff) | |
download | edk2-platforms-57cca89e0aa24d3feb6322c556038edd3aad830f.tar.xz |
Remove usage of MemoryAllocationLib, and use a simplistic allocation
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
Diffstat (limited to 'IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib')
-rw-r--r-- | IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf | 1 | ||||
-rw-r--r-- | IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c | 41 |
2 files changed, 31 insertions, 11 deletions
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf index 9b4d78447d..ebf8b9de18 100644 --- a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf +++ b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf @@ -49,6 +49,5 @@ BaseLib
DebugLib
BaseMemoryLib
- MemoryAllocationLib
ExtractGuidedSectionLib
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c index 439e15beab..8497440f3f 100644 --- a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c +++ b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c @@ -20,7 +20,6 @@ #include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
#include <Library/UefiDecompressLib.h>
#include <Library/ExtractGuidedSectionLib.h>
#include <Guid/LzmaDecompress.h>
@@ -29,6 +28,17 @@ #include "Sdk/C/7zVersion.h"
#include "Sdk/C/LzmaDec.h"
+//
+// Global data
+//
+
+STATIC CONST VOID *mSourceLastUsedWithGetInfo;
+STATIC UINT32 mSizeOfLastSource;
+STATIC UINT32 mDecompressedSizeForLastSource;
+STATIC VOID *mScratchBuffer;
+STATIC UINTN mScratchBufferSize;
+#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB
+
/**
Allocation routine used by LZMA decompression.
@@ -44,7 +54,17 @@ SzAlloc ( size_t size
)
{
- return AllocatePool (size);
+ VOID *addr;
+
+ if (mScratchBufferSize >= size) {
+ addr = mScratchBuffer;
+ mScratchBuffer = (VOID*) ((UINT8*)addr + size);
+ mScratchBufferSize -= size;
+ return addr;
+ } else {
+ ASSERT (FALSE);
+ return NULL;
+ }
}
/**
@@ -60,9 +80,11 @@ SzFree ( void *address
)
{
- if (address != NULL) {
- FreePool (address);
- }
+ //
+ // We use the 'scratch buffer' for allocations, so there is no free
+ // operation required. The scratch buffer will be freed by the caller
+ // of the decompression code.
+ //
}
STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };
@@ -90,10 +112,6 @@ GetDecodedSizeOfBuf( // LZMA functions and data as defined in local LzmaDecompress.h
//
-STATIC CONST VOID *mSourceLastUsedWithGetInfo;
-STATIC UINT32 mSizeOfLastSource;
-STATIC UINT32 mDecompressedSizeForLastSource;
-
/**
The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
@@ -124,7 +142,7 @@ LzmaUefiDecompressGetInfo ( mSizeOfLastSource = SourceSize;
mDecompressedSizeForLastSource = (UInt32)DecodedSize;
*DestinationSize = mDecompressedSizeForLastSource;
- *ScratchSize = 0x10;
+ *ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
return RETURN_SUCCESS;
}
@@ -159,6 +177,9 @@ LzmaUefiDecompress ( decodedBufSize = (SizeT)mDecompressedSizeForLastSource;
encodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);
+ mScratchBuffer = Scratch;
+ mScratchBufferSize = SCRATCH_BUFFER_REQUEST_SIZE;
+
lzmaResult = LzmaDecode(
Destination,
&decodedBufSize,
|