]> git.proxmox.com Git - mirror_edk2.git/commitdiff
[InOSEmPkg] Add OS malloc and free to the Thunk.
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Jun 2011 14:48:38 +0000 (14:48 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Jun 2011 14:48:38 +0000 (14:48 +0000)
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

InOsEmuPkg/Include/Protocol/EmuThunk.h
InOsEmuPkg/Unix/Sec/EmuThunk.c
InOsEmuPkg/Unix/Sec/Gasket.h
InOsEmuPkg/Unix/Sec/Ia32/Gasket.S
InOsEmuPkg/Unix/Sec/X64/Gasket.S

index ed4df3a942e934a3d0b415541e0fa105be8a2c4c..6c1190c14115a99a6b29e4310624b7f71c557e4a 100644 (file)
@@ -78,6 +78,18 @@ BOOLEAN
   );\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
@@ -205,6 +217,13 @@ struct _EMU_THUNK_PROTOCOL {
   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
index 97c339d24129ce22f04238330ad3064ea90c3f22..50afbb5cd6bf2a69ae3af00dec9a24594742dc4e 100644 (file)
@@ -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,
index 725e250eb3af349ab7f2806dfa18da416856ebe1..90c2aa8ee7ed25c0edfe53f469fdf6b70dfb57b8 100644 (file)
@@ -53,6 +53,16 @@ GasketSecPollStdIn (
   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
index f1b974e18a942c35b809ca938b1476037f32011a..b8d9c0470f6ce9a1b50d565befb152d15212812f 100644 (file)
@@ -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):
index d30aed617b5274ba854d66a790e3ec5f4a736441..6b5e78241398d5f04d10617129cef8d5015258d6 100644 (file)
@@ -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):