summaryrefslogtreecommitdiff
path: root/InOsEmuPkg/Unix/Sec
diff options
context:
space:
mode:
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-24 14:48:38 +0000
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-24 14:48:38 +0000
commitc217506815e1a769ef9ac3ab6dbf3e68ba5f00e0 (patch)
treee3e6b53f66766445c59f75f1736e654aa827d874 /InOsEmuPkg/Unix/Sec
parent54e0b04c74a1e55ccfd3b428415eb419b975de8b (diff)
downloadedk2-platforms-c217506815e1a769ef9ac3ab6dbf3e68ba5f00e0.tar.xz
[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
Diffstat (limited to 'InOsEmuPkg/Unix/Sec')
-rw-r--r--InOsEmuPkg/Unix/Sec/EmuThunk.c19
-rw-r--r--InOsEmuPkg/Unix/Sec/Gasket.h10
-rw-r--r--InOsEmuPkg/Unix/Sec/Ia32/Gasket.S28
-rw-r--r--InOsEmuPkg/Unix/Sec/X64/Gasket.S28
4 files changed, 85 insertions, 0 deletions
diff --git a/InOsEmuPkg/Unix/Sec/EmuThunk.c b/InOsEmuPkg/Unix/Sec/EmuThunk.c
index 97c339d241..50afbb5cd6 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 725e250eb3..90c2aa8ee7 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 f1b974e18a..b8d9c0470f 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 d30aed617b..6b5e782413 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):