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
);\r
\r
\r
+typedef\r
+VOID *\r
+(EFIAPI *EMU_OS_MALLOC) (\r
+ IN UINTN Size\r
+ );\r
+ \r
+typedef \r
+VOID\r
+(EFIAPI *EMU_OS_FREE) (\r
+ IN VOID *Ptr\r
+ );\r
+\r
\r
typedef \r
EFI_STATUS\r
EMU_READ_STD_IN ReadStdIn;\r
EMU_POLL_STD_IN PollStdIn;\r
\r
+ //\r
+ // Map OS malloc/free so we can use OS based guard malloc\r
+ //\r
+ EMU_OS_MALLOC Malloc;\r
+ EMU_OS_FREE Free;\r
+ \r
+ \r
///\r
/// PE/COFF loader hooks to get symbols loaded\r
///\r
}
+VOID *
+SecMalloc (
+ IN UINTN Size
+ )
+{
+ return malloc ((size_t)Size);
+}
+
+VOID
+SecFree (
+ IN VOID *Ptr
+ )
+{
+ free (Ptr);
+ return;
+}
+
void
settimer_handler (int sig)
GasketSecWriteStdOut,
GasketSecReadStdIn,
GasketSecPollStdIn,
+ GasketSecMalloc,
+ GasketSecFree,
GasketSecPeCoffGetEntryPoint,
GasketSecPeCoffRelocateImageExtraAction,
GasketSecPeCoffUnloadImageExtraAction,
VOID\r
);\r
\r
+VOID *\r
+EFIAPI\r
+GasketSecMalloc (\r
+ IN UINTN Size\r
+ );\r
+ \r
+VOID\r
+GasketSecFree (\r
+ IN VOID *Ptr\r
+ );\r
\r
\r
RETURN_STATUS\r
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):
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):