]> git.proxmox.com Git - mirror_edk2.git/blobdiff - InOsEmuPkg/Unix/Sec/EmuThunk.c
InOsEmuPkg: Add an OS malloc/valloc/free based implementation of the MemoryAllocation...
[mirror_edk2.git] / InOsEmuPkg / Unix / Sec / EmuThunk.c
index 50afbb5cd6bf2a69ae3af00dec9a24594742dc4e..fe68603d3f678e3660040de9f6bbee9c899c6b73 100644 (file)
@@ -126,13 +126,27 @@ SecMalloc (
   return malloc ((size_t)Size);
 }
 
-VOID
+VOID *
+SecValloc (
+  IN  UINTN Size
+  )
+{
+  return valloc ((size_t)Size);
+}
+
+BOOLEAN
 SecFree (
   IN  VOID *Ptr
   )
 {
+  if (EfiSystemMemoryRange (Ptr)) {
+    // If an address range is in the EFI memory map it was alloced via EFI.
+    // So don't free those ranges and let the caller know.
+    return FALSE;
+  }
+  
   free (Ptr);
-  return;
+  return TRUE;
 }
 
 
@@ -388,6 +402,7 @@ EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
   GasketSecReadStdIn,
   GasketSecPollStdIn,
   GasketSecMalloc,
+  GasketSecValloc,
   GasketSecFree,
   GasketSecPeCoffGetEntryPoint,
   GasketSecPeCoffRelocateImageExtraAction,