summaryrefslogtreecommitdiff
path: root/InOsEmuPkg/Unix/Sec/EmuThunk.c
diff options
context:
space:
mode:
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-24 23:59:51 +0000
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-24 23:59:51 +0000
commit1d7ac5a617fba582abfddb4ce240b81b2c24742f (patch)
treef00432f48f9827b3ca0342beaddd5a813aa6cd8f /InOsEmuPkg/Unix/Sec/EmuThunk.c
parent0de7effb732dfd9f286e1ecaf9dcb35711ee1d78 (diff)
downloadedk2-platforms-1d7ac5a617fba582abfddb4ce240b81b2c24742f.tar.xz
InOsEmuPkg: Add an OS malloc/valloc/free based implementation of the MemoryAllocationLib. Requires extra Thunk APIs.
I've got this working. The tricky part was a driver/application can mix malloc forms. If the driver links against this library all the allocations come from the OS service, but if a protocol or EFI boot service return an allocated buffer it will still use the EFI allocation. The gasket code can detect this and do the right thing, as the emulator is passing up the memory map to EFI. You can now use the OS based malloc debugging tools in an EFI driver or appliaction. On OS X this is libgmalloc, also called guard malloc. Signed-off-by: andrewfish. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11886 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'InOsEmuPkg/Unix/Sec/EmuThunk.c')
-rw-r--r--InOsEmuPkg/Unix/Sec/EmuThunk.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/InOsEmuPkg/Unix/Sec/EmuThunk.c b/InOsEmuPkg/Unix/Sec/EmuThunk.c
index 50afbb5cd6..fe68603d3f 100644
--- a/InOsEmuPkg/Unix/Sec/EmuThunk.c
+++ b/InOsEmuPkg/Unix/Sec/EmuThunk.c
@@ -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,