diff options
author | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-24 14:48:38 +0000 |
---|---|---|
committer | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-24 14:48:38 +0000 |
commit | c217506815e1a769ef9ac3ab6dbf3e68ba5f00e0 (patch) | |
tree | e3e6b53f66766445c59f75f1736e654aa827d874 | |
parent | 54e0b04c74a1e55ccfd3b428415eb419b975de8b (diff) | |
download | edk2-c217506815e1a769ef9ac3ab6dbf3e68ba5f00e0.zip edk2-c217506815e1a769ef9ac3ab6dbf3e68ba5f00e0.tar.gz edk2-c217506815e1a769ef9ac3ab6dbf3e68ba5f00e0.tar.bz2 |
[InOSEmPkg] Add OS malloc and free to the Thunk.
Added OS malloc and free so we can make MemoryAllocationLib instance that uses OS guard malloc. This will allow all the debug support built into the OS for finding malloc bugs to be used with a driver in the emulator.
Signed-off-by: andrewfish
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11883 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r-- | InOsEmuPkg/Include/Protocol/EmuThunk.h | 19 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/EmuThunk.c | 19 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/Gasket.h | 10 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/Ia32/Gasket.S | 28 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/X64/Gasket.S | 28 |
5 files changed, 104 insertions, 0 deletions
diff --git a/InOsEmuPkg/Include/Protocol/EmuThunk.h b/InOsEmuPkg/Include/Protocol/EmuThunk.h index ed4df3a..6c1190c 100644 --- a/InOsEmuPkg/Include/Protocol/EmuThunk.h +++ b/InOsEmuPkg/Include/Protocol/EmuThunk.h @@ -78,6 +78,18 @@ BOOLEAN );
+typedef
+VOID *
+(EFIAPI *EMU_OS_MALLOC) (
+ IN UINTN Size
+ );
+
+typedef
+VOID
+(EFIAPI *EMU_OS_FREE) (
+ IN VOID *Ptr
+ );
+
typedef
EFI_STATUS
@@ -205,6 +217,13 @@ struct _EMU_THUNK_PROTOCOL { EMU_READ_STD_IN ReadStdIn;
EMU_POLL_STD_IN PollStdIn;
+ //
+ // Map OS malloc/free so we can use OS based guard malloc
+ //
+ EMU_OS_MALLOC Malloc;
+ EMU_OS_FREE Free;
+
+
///
/// PE/COFF loader hooks to get symbols loaded
///
diff --git a/InOsEmuPkg/Unix/Sec/EmuThunk.c b/InOsEmuPkg/Unix/Sec/EmuThunk.c index 97c339d..50afbb5 100644 --- a/InOsEmuPkg/Unix/Sec/EmuThunk.c +++ b/InOsEmuPkg/Unix/Sec/EmuThunk.c @@ -118,6 +118,23 @@ SecPollStdIn ( } +VOID * +SecMalloc ( + IN UINTN Size + ) +{ + return malloc ((size_t)Size); +} + +VOID +SecFree ( + IN VOID *Ptr + ) +{ + free (Ptr); + return; +} + void settimer_handler (int sig) @@ -370,6 +387,8 @@ EMU_THUNK_PROTOCOL gEmuThunkProtocol = { GasketSecWriteStdOut, GasketSecReadStdIn, GasketSecPollStdIn, + GasketSecMalloc, + GasketSecFree, GasketSecPeCoffGetEntryPoint, GasketSecPeCoffRelocateImageExtraAction, GasketSecPeCoffUnloadImageExtraAction, diff --git a/InOsEmuPkg/Unix/Sec/Gasket.h b/InOsEmuPkg/Unix/Sec/Gasket.h index 725e250..90c2aa8 100644 --- a/InOsEmuPkg/Unix/Sec/Gasket.h +++ b/InOsEmuPkg/Unix/Sec/Gasket.h @@ -53,6 +53,16 @@ GasketSecPollStdIn ( VOID
);
+VOID *
+EFIAPI
+GasketSecMalloc (
+ IN UINTN Size
+ );
+
+VOID
+GasketSecFree (
+ IN VOID *Ptr
+ );
RETURN_STATUS
diff --git a/InOsEmuPkg/Unix/Sec/Ia32/Gasket.S b/InOsEmuPkg/Unix/Sec/Ia32/Gasket.S index f1b974e..b8d9c04 100644 --- a/InOsEmuPkg/Unix/Sec/Ia32/Gasket.S +++ b/InOsEmuPkg/Unix/Sec/Ia32/Gasket.S @@ -107,6 +107,34 @@ ASM_PFX(GasketSecPollStdIn): leave ret +ASM_GLOBAL ASM_PFX(GasketSecMalloc) +ASM_PFX(GasketSecMalloc): + pushl %ebp + movl %esp, %ebp + subl $24, %esp // sub extra 16 from the stack for alignment + and $-16, %esp // stack needs to end in 0xFFFFFFF0 before call + movl 8(%ebp), %eax + movl %eax, (%esp) + + call ASM_PFX(SecMalloc) + + leave + ret + +ASM_GLOBAL ASM_PFX(GasketSecFree) +ASM_PFX(GasketSecFree): + pushl %ebp + movl %esp, %ebp + subl $24, %esp // sub extra 16 from the stack for alignment + and $-16, %esp // stack needs to end in 0xFFFFFFF0 before call + movl 8(%ebp), %eax + movl %eax, (%esp) + + call ASM_PFX(SecFree) + + leave + ret + ASM_GLOBAL ASM_PFX(GasketSecSetTimer) ASM_PFX(GasketSecSetTimer): diff --git a/InOsEmuPkg/Unix/Sec/X64/Gasket.S b/InOsEmuPkg/Unix/Sec/X64/Gasket.S index d30aed6..6b5e782 100644 --- a/InOsEmuPkg/Unix/Sec/X64/Gasket.S +++ b/InOsEmuPkg/Unix/Sec/X64/Gasket.S @@ -126,6 +126,34 @@ ASM_PFX(GasketSecPollStdIn): popq %rbp ret +ASM_GLOBAL ASM_PFX(GasketSecMalloc) +ASM_PFX(GasketSecMalloc): + pushq %rbp // stack frame is for the debugger + movq %rsp, %rbp + + pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI + + call ASM_PFX(SecMalloc) + + popq %rdi // restore state + popq %rsi + popq %rbp + ret + +ASM_GLOBAL ASM_PFX(GasketSecFree) +ASM_PFX(GasketSecFree): + pushq %rbp // stack frame is for the debugger + movq %rsp, %rbp + + pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI + + call ASM_PFX(SecFree) + + popq %rdi // restore state + popq %rsi + popq %rbp + ret + ASM_GLOBAL ASM_PFX(GasketSecSetTimer) ASM_PFX(GasketSecSetTimer): |