summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg
diff options
context:
space:
mode:
Diffstat (limited to 'IntelFrameworkModulePkg')
-rw-r--r--IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf1
-rw-r--r--IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c41
2 files changed, 31 insertions, 11 deletions
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
index 9b4d784..ebf8b9d 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 439e15b..8497440 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,