summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>2019-07-29 16:02:37 (GMT)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>2019-07-29 16:02:37 (GMT)
commit89fbd58106571efb5b927f662ecf4a41c08f4197 (patch)
treeb4473fdb41603b0770732ecf4e7f54764e6e9434
parent58f37b76b0a094cf5a1e7211ce3f745f41d2888b (diff)
downloadcoreclr-89fbd58106571efb5b927f662ecf4a41c08f4197.zip
coreclr-89fbd58106571efb5b927f662ecf4a41c08f4197.tar.gz
coreclr-89fbd58106571efb5b927f662ecf4a41c08f4197.tar.bz2
ASan: add AMD64 support
Change-Id: I48446ce7c8771a4c75149512bb7d8a8cb3fae8e5 Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r--src/vm/CMakeLists.txt11
-rw-r--r--src/vm/amd64/tizenasanenv.S155
-rw-r--r--src/vm/tizenasanenv.cpp33
-rw-r--r--src/vm/tizenasanenv.h4
4 files changed, 203 insertions, 0 deletions
diff --git a/src/vm/CMakeLists.txt b/src/vm/CMakeLists.txt
index e391e1d..c062139 100644
--- a/src/vm/CMakeLists.txt
+++ b/src/vm/CMakeLists.txt
@@ -719,6 +719,17 @@ else(WIN32)
${ARCH_SOURCES_DIR}/umthunkstub.S
${ARCH_SOURCES_DIR}/virtualcallstubamd64.S
)
+ if (TIZEN_ASAN_ENVIRONMENT)
+ list(APPEND VM_SOURCES_WKS
+ tizenasanenv.cpp
+ )
+ list(APPEND VM_HEADERS_WKS
+ tizenasanenv.h
+ )
+ list(APPEND VM_SOURCES_WKS_ARCH_ASM
+ ${ARCH_SOURCES_DIR}/tizenasanenv.S
+ )
+ endif()
elseif(CLR_CMAKE_TARGET_ARCH_I386)
set(VM_SOURCES_WKS_ARCH_ASM
${ARCH_SOURCES_DIR}/ehhelpers.S
diff --git a/src/vm/amd64/tizenasanenv.S b/src/vm/amd64/tizenasanenv.S
new file mode 100644
index 0000000..dc4e7e7
--- /dev/null
+++ b/src/vm/amd64/tizenasanenv.S
@@ -0,0 +1,155 @@
+RETADDR_OFFSET=8*15
+
+.macro PUSH_REGS
+ push %rdi # 0, arg0
+ push %rsi # 1, arg1
+ push %rdx # 2, arg2
+ push %rcx # 3, arg3
+ push %r8 # 4, arg4
+ push %r9 # 5, arg5
+ push %r10 # 6, ...
+ push %r11 # 7, temprory reg
+ push %rax # 8
+
+ push %rbp
+ push %rbx
+ push %r15
+ push %r14
+ push %r13
+ push %r12
+.endm
+
+.macro POP_REGS
+ pop %r12
+ pop %r13
+ pop %r14
+ pop %r15
+ pop %rbx
+ pop %rbp
+
+
+ pop %rax
+ pop %r11
+ pop %r10
+ pop %r9
+ pop %r8
+ pop %rcx
+ pop %rdx
+ pop %rsi
+ pop %rdi
+.endm
+
+ .global hex_wrapper
+ .global hex_wrapper_size
+ .global hex_wrapper_entry_offset
+
+ # Extern functions
+ .global asan_enable_addr_offset
+ .global asan_disable_addr_offset
+ .global target_addr_offset
+ .global get_return_addr_offset
+
+// Export symbols
+.global tizenASanWrapper
+.global tizenASanWrapperSize
+.global tizenASanWrapperEntryOffset
+
+.text
+.code64
+
+tizenASanWrapper:
+// !!! ATTENTION !!!
+// Don't move this labels (target, pushAddr, popAddr)
+// because they mapped to AuxiliaryCalls struct from src/vm/tizenasanenv.cpp
+target: .quad 0xdeadbeef0badc0de
+pushAddr: .quad 0xdeadbeef0badc0de // void pushAddr(LPVOID addr)
+popAddr: .quad 0xdeadbeef0badc0de // LPVOID popAddr()
+
+
+entryPointer:
+ // Save context
+ PUSH_REGS
+
+ // Save the return address and call 'pre handler'
+ mov RETADDR_OFFSET(%rsp), %rdi // rdi: get return address
+ call *pushAddr(%rsp) // save the return address
+
+ // Change the return address
+ call next
+next: pop %rax // rax: get current rip
+ add $(postLabel - next), %rax // rax: add offset to 'postLabel'
+ mov %rax, RETADDR_OFFSET(%rsp) // change the return address
+
+ // Restore context
+ POP_REGS
+
+ // Call original function
+ jmp *target(%rip)
+postLabel:
+ // Save context
+ PUSH_REGS
+
+ // Get the return address and call 'post handler'
+ add $8, %rsp // align stack
+ call *popAddr(%rip) // rdi: get the return address
+ sub $8, %rsp // restore stack
+ mov %rdi, RETADDR_OFFSET(%rsp) // restore the return address
+
+ // Restore context
+ POP_REGS
+
+ // Return
+ ret
+
+tizenASanWrapperSize: .word . - tizenASanWrapper
+tizenASanWrapperEntryOffset: .word entryPointer - tizenASanWrapper
+
+
+
+tizenASanWrapperJmp:
+// !!! ATTENTION !!!
+// Don't move this labels (target, pushAddr, popAddr)
+// because they mapped to AuxiliaryCalls struct from src/vm/tizenasanenv.cpp
+targetJmp: .quad 0xdeadbeef0badc0de
+pushAddrJmp: .quad 0xdeadbeef0badc0de // void pushAddr(LPVOID addr)
+popAddrJmp: .quad 0xdeadbeef0badc0de // LPVOID popAddr()
+
+
+entryPointerJmp:
+ // Save context
+ PUSH_REGS
+
+ // Save the return address and call 'pre handler'
+ mov RETADDR_OFFSET(%rsp), %rdi // rdi: get return address
+ call *pushAddrJmp(%rsp) // save the return address
+
+ // Change the return address
+ call nextJmp
+nextJmp:
+ pop %rax // rax: get current rip
+ add $(postLabelJmp - nextJmp), %rax // rax: add offset to 'postLabel'
+ mov %rax, RETADDR_OFFSET(%rsp) // change the return address
+
+ // Restore context
+ POP_REGS
+
+ // Call original function
+ jmp *targetJmp(%rip)
+postLabelJmp:
+ sub $8, %rsp // add space for the return addr
+
+ // Save context
+ PUSH_REGS
+
+ // Get the return address and call 'post handler'
+ call *popAddr(%rip) // rdi: get the return address
+ mov %rdi, RETADDR_OFFSET(%rsp) // restore the return address
+
+ // Restore context
+ POP_REGS
+
+ // Return
+ ret
+
+tizenASanWrapperSizeJmp: .word . - tizenASanWrapperJmp
+tizenASanWrapperEntryOffsetJmp: .word entryPointerJmp - tizenASanWrapperJmp
diff --git a/src/vm/tizenasanenv.cpp b/src/vm/tizenasanenv.cpp
index afb78ae..34fffea 100644
--- a/src/vm/tizenasanenv.cpp
+++ b/src/vm/tizenasanenv.cpp
@@ -170,4 +170,37 @@ LPVOID CreateWrapper(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popA
dprintf(1, "#### CreateWrapper E\n");
return entryPointer;
}
+
+#ifdef _AMD64_
+extern LPVOID ::tizenASanWrapperJmp;
+extern UINT32 ::tizenASanWrapperJmpSize;
+extern UINT32 ::tizenASanWrapperJmpEntryOffset;
+
+LPVOID CreateWrapperJmp(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popAddr)())
+{
+ _ASSERTE(tizenASanWrapperJmpEntryOffset == sizeof(AuxiliaryCalls));
+
+ LPVOID wrapperSpace = (LPVOID)SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->AllocMem(S_SIZE_T(tizenASanWrapperJmpSize));
+
+ AuxiliaryCalls calls = {
+ .target = target,
+ .pushAddr = pushAddr,
+ .popAddr = popAddr,
+ };
+
+ // copy auxiliary calls
+ memcpy(wrapperSpace, &calls, sizeof(calls));
+
+ LPVOID entryPointer = (LPVOID)((UINT_PTR)wrapperSpace + tizenASanWrapperJmpEntryOffset);
+ LPVOID wrapperEntryPointer = (LPVOID)((UINT_PTR)&tizenASanWrapperJmp + tizenASanWrapperJmpEntryOffset);
+ UINT32 wrapperCodeSize = tizenASanWrapperJmpSize - tizenASanWrapperJmpEntryOffset;
+
+ // copy executable code wrapper
+ memcpy(entryPointer, wrapperEntryPointer, wrapperCodeSize);
+
+ FlushInstructionCache(GetCurrentProcess(), wrapperSpace, tizenASanWrapperJmpSize);
+
+ return entryPointer;
+}
+#endif // _AMD64_
} // namespace TizenASanEnv
diff --git a/src/vm/tizenasanenv.h b/src/vm/tizenasanenv.h
index 7200936..1a4412c 100644
--- a/src/vm/tizenasanenv.h
+++ b/src/vm/tizenasanenv.h
@@ -10,6 +10,10 @@ LPVOID PopAndDisableASan();
LPVOID CreateWrapper(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popAddr)());
+#ifdef _AMD64_
+LPVOID CreateWrapperJmp(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popAddr)());
+#endif // _AMD64_
+
} // namespace TizenASanEnv
#endif // TIZENASANENV_H_