summaryrefslogtreecommitdiff
path: root/InOsEmuPkg/Unix/Sec
diff options
context:
space:
mode:
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-20 21:58:05 +0000
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-20 21:58:05 +0000
commitb8800fc547440d8648e49c189a60547bfc4a1615 (patch)
tree107dfd9ca56bb3d31a08a7428b96b15a1873d830 /InOsEmuPkg/Unix/Sec
parent7af94c1d0af9b8595ef536c8a2f7ff930b54a43a (diff)
downloadedk2-b8800fc547440d8648e49c189a60547bfc4a1615.zip
edk2-b8800fc547440d8648e49c189a60547bfc4a1615.tar.gz
edk2-b8800fc547440d8648e49c189a60547bfc4a1615.tar.bz2
InOsEmuPkg/Unix/Sec: Add BaseMemoryLib implementation to thunk layer
This implementation only covers a few BaseMemoryLib functions. The implementation leverates malloc/free in stdlib. Signed-off-by: jljusten git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11866 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'InOsEmuPkg/Unix/Sec')
-rw-r--r--InOsEmuPkg/Unix/Sec/MemoryAllocationLib.c145
-rw-r--r--InOsEmuPkg/Unix/Sec/SecMain.c14
-rw-r--r--InOsEmuPkg/Unix/Sec/SecMain.h1
-rw-r--r--InOsEmuPkg/Unix/Sec/SecMain.inf5
4 files changed, 158 insertions, 7 deletions
diff --git a/InOsEmuPkg/Unix/Sec/MemoryAllocationLib.c b/InOsEmuPkg/Unix/Sec/MemoryAllocationLib.c
new file mode 100644
index 0000000..76b7271
--- /dev/null
+++ b/InOsEmuPkg/Unix/Sec/MemoryAllocationLib.c
@@ -0,0 +1,145 @@
+/*++ @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "Base.h"
+#include "Library/BaseMemoryLib.h"
+#include "Library/MemoryAllocationLib.h"
+
+#include <stdlib.h>
+
+/**
+ Allocates a buffer of type EfiBootServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
+ pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
+ returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePool (
+ IN UINTN AllocationSize
+ )
+{
+ return (VOID*) malloc (AllocationSize);
+}
+
+
+/**
+ Allocates and zeros a buffer of type EfiBootServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
+ buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
+ valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
+ request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate and zero.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateZeroPool (
+ IN UINTN AllocationSize
+ )
+{
+ VOID *Buffer;
+
+ Buffer = AllocatePool (AllocationSize);
+ if (Buffer == NULL) {
+ return NULL;
+ }
+
+ ZeroMem (Buffer, AllocationSize);
+
+ return Buffer;
+}
+
+
+/**
+ Reallocates a buffer of type EfiBootServicesData.
+
+ Allocates and zeros the number bytes specified by NewSize from memory of type
+ EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
+ NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
+ OldBuffer is freed. A pointer to the newly allocated buffer is returned.
+ If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
+ enough memory remaining to satisfy the request, then NULL is returned.
+
+ If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
+ is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
+
+ @param OldSize The size, in bytes, of OldBuffer.
+ @param NewSize The size, in bytes, of the buffer to reallocate.
+ @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
+ parameter that may be NULL.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+ReallocatePool (
+ IN UINTN OldSize,
+ IN UINTN NewSize,
+ IN VOID *OldBuffer OPTIONAL
+ )
+{
+ VOID *NewBuffer;
+
+ NewBuffer = AllocatePool (NewSize);
+ if (NewBuffer == NULL) {
+ return NULL;
+ }
+
+ if (OldBuffer != NULL) {
+ if (OldSize > 0) {
+ CopyMem (NewBuffer, OldBuffer, OldSize);
+ }
+
+ FreePool (OldBuffer);
+ }
+
+ return NewBuffer;
+}
+
+
+/**
+ Frees a buffer that was previously allocated with one of the pool allocation functions in the
+ Memory Allocation Library.
+
+ Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
+ pool allocation services of the Memory Allocation Library. If it is not possible to free pool
+ resources, then this function will perform no actions.
+
+ If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
+ then ASSERT().
+
+ @param Buffer Pointer to the buffer to free.
+
+**/
+VOID
+EFIAPI
+FreePool (
+ IN VOID *Buffer
+ )
+{
+ free ((void *) Buffer);
+}
+
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.c b/InOsEmuPkg/Unix/Sec/SecMain.c
index e22f5b9..86554ed 100644
--- a/InOsEmuPkg/Unix/Sec/SecMain.c
+++ b/InOsEmuPkg/Unix/Sec/SecMain.c
@@ -136,7 +136,7 @@ main (
// symbols when we load every PE/COFF image.
//
Index = strlen (*Argv);
- gGdbWorkingFileName = malloc (Index + strlen(".gdb") + 1);
+ gGdbWorkingFileName = AllocatePool (Index + strlen(".gdb") + 1);
strcpy (gGdbWorkingFileName, *Argv);
strcat (gGdbWorkingFileName, ".gdb");
#endif
@@ -146,7 +146,7 @@ main (
// Allocate space for gSystemMemory Array
//
gSystemMemoryCount = CountSeperatorsInString (MemorySizeStr, '!') + 1;
- gSystemMemory = calloc (gSystemMemoryCount, sizeof (EMU_SYSTEM_MEMORY));
+ gSystemMemory = AllocateZeroPool (gSystemMemoryCount * sizeof (EMU_SYSTEM_MEMORY));
if (gSystemMemory == NULL) {
printf ("ERROR : Can not allocate memory for system. Exiting.\n");
exit (1);
@@ -155,7 +155,7 @@ main (
// Allocate space for gSystemMemory Array
//
gFdInfoCount = CountSeperatorsInString (FirmwareVolumesStr, '!') + 1;
- gFdInfo = calloc (gFdInfoCount, sizeof (EMU_FD_INFO));
+ gFdInfo = AllocateZeroPool (gFdInfoCount * sizeof (EMU_FD_INFO));
if (gFdInfo == NULL) {
printf ("ERROR : Can not allocate memory for fd info. Exiting.\n");
exit (1);
@@ -192,7 +192,7 @@ main (
//
// Open All the firmware volumes and remember the info in the gFdInfo global
//
- FileName = (CHAR8 *)malloc (StrLen (FirmwareVolumesStr) + 1);
+ FileName = (CHAR8 *) AllocatePool (StrLen (FirmwareVolumesStr) + 1);
if (FileName == NULL) {
printf ("ERROR : Can not allocate memory for firmware volume string\n");
exit (1);
@@ -870,7 +870,11 @@ AddHandle (
PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE);
mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE;
- mImageContextModHandleArray = realloc (mImageContextModHandleArray, mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
+ mImageContextModHandleArray = ReallocatePool (
+ (mImageContextModHandleArraySize - 1) * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE),
+ mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE),
+ mImageContextModHandleArray
+ );
if (mImageContextModHandleArray == NULL) {
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.h b/InOsEmuPkg/Unix/Sec/SecMain.h
index 81970ed..01254de 100644
--- a/InOsEmuPkg/Unix/Sec/SecMain.h
+++ b/InOsEmuPkg/Unix/Sec/SecMain.h
@@ -90,6 +90,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/PeCoffLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/PcdLib.h>
#include <Library/DebugLib.h>
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.inf b/InOsEmuPkg/Unix/Sec/SecMain.inf
index e3ceb99..4dc0a67 100644
--- a/InOsEmuPkg/Unix/Sec/SecMain.inf
+++ b/InOsEmuPkg/Unix/Sec/SecMain.inf
@@ -35,8 +35,9 @@
Pthreads.c
PosixFileSystem.c
BlockIo.c
- LinuxPacketFilter.c
- BerkeleyPacketFilter.c
+ LinuxPacketFilter.c
+ BerkeleyPacketFilter.c
+ MemoryAllocationLib.c
[Sources.X64]
X64/Gasket.S # convert between Emu x86_64 ABI and EFI X64 ABI