[llvm-commits] [compiler-rt] r147671 - in /compiler-rt/trunk/lib/asan: asan_internal.h asan_linux.cc asan_mac.cc asan_rtl.cc
Kostya Serebryany
kcc at google.com
Fri Jan 6 11:11:10 PST 2012
Author: kcc
Date: Fri Jan 6 13:11:09 2012
New Revision: 147671
URL: http://llvm.org/viewvc/llvm-project?rev=147671&view=rev
Log:
[asan] move more code into OS-specific files
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_linux.cc
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=147671&r1=147670&r2=147671&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Fri Jan 6 13:11:09 2012
@@ -100,6 +100,7 @@
void AsanUnmapOrDie(void *ptr, size_t size);
void AsanDisableCoreDumper();
+void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp);
ssize_t AsanRead(int fd, void *buf, size_t count);
ssize_t AsanWrite(int fd, const void *buf, size_t count);
Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=147671&r1=147670&r2=147671&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Fri Jan 6 13:11:09 2012
@@ -29,6 +29,11 @@
#include <stdio.h>
#include <unistd.h>
+#ifndef ANDROID
+// FIXME: where to get ucontext on Android?
+#include <sys/ucontext.h>
+#endif
+
namespace __asan {
void *AsanDoesNotSupportStaticLinkage() {
@@ -36,6 +41,29 @@
return &_DYNAMIC; // defined in link.h
}
+void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) {
+#ifdef ANDROID
+ *pc = *sp = *bp = 0;
+#elif defined(__arm__)
+ ucontext_t *ucontext = (ucontext_t*)context;
+ *pc = ucontext->uc_mcontext.arm_pc;
+ *bp = ucontext->uc_mcontext.arm_fp;
+ *sp = ucontext->uc_mcontext.arm_sp;
+# elif defined(__x86_64__)
+ ucontext_t *ucontext = (ucontext_t*)context;
+ *pc = ucontext->uc_mcontext.gregs[REG_RIP];
+ *bp = ucontext->uc_mcontext.gregs[REG_RBP];
+ *sp = ucontext->uc_mcontext.gregs[REG_RSP];
+# elif defined(__i386__)
+ ucontext_t *ucontext = (ucontext_t*)context;
+ *pc = ucontext->uc_mcontext.gregs[REG_EIP];
+ *bp = ucontext->uc_mcontext.gregs[REG_EBP];
+ *sp = ucontext->uc_mcontext.gregs[REG_ESP];
+#else
+# error "Unsupported arch"
+#endif
+}
+
static void *asan_mmap(void *addr, size_t length, int prot, int flags,
int fd, uint64_t offset) {
# if __WORDSIZE == 64
Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=147671&r1=147670&r2=147671&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Fri Jan 6 13:11:09 2012
@@ -23,6 +23,7 @@
#include <sys/mman.h>
#include <sys/resource.h>
+#include <sys/ucontext.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
@@ -38,6 +39,20 @@
extern dispatch_group_async_f_f real_dispatch_group_async_f;
extern pthread_workqueue_additem_np_f real_pthread_workqueue_additem_np;
+void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) {
+ ucontext_t *ucontext = (ucontext_t*)context;
+# if __WORDSIZE == 64
+ *pc = ucontext->uc_mcontext->__ss.__rip;
+ *bp = ucontext->uc_mcontext->__ss.__rbp;
+ *sp = ucontext->uc_mcontext->__ss.__rsp;
+# else
+ *pc = ucontext->uc_mcontext->__ss.__eip;
+ *bp = ucontext->uc_mcontext->__ss.__ebp;
+ *sp = ucontext->uc_mcontext->__ss.__esp;
+# endif // __WORDSIZE
+}
+
+
// No-op. Mac does not support static linkage anyway.
void *AsanDoesNotSupportStaticLinkage() {
return NULL;
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=147671&r1=147670&r2=147671&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Fri Jan 6 13:11:09 2012
@@ -36,9 +36,6 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
-#ifndef ANDROID
-#include <sys/ucontext.h>
-#endif
// must not include <setjmp.h> on Linux
namespace __asan {
@@ -271,45 +268,6 @@
}
// -------------------------- Run-time entry ------------------- {{{1
-void GetPcSpBpAx(void *context,
- uintptr_t *pc, uintptr_t *sp, uintptr_t *bp, uintptr_t *ax) {
-#ifndef ANDROID
- ucontext_t *ucontext = (ucontext_t*)context;
-#endif
-#ifdef __APPLE__
-# if __WORDSIZE == 64
- *pc = ucontext->uc_mcontext->__ss.__rip;
- *bp = ucontext->uc_mcontext->__ss.__rbp;
- *sp = ucontext->uc_mcontext->__ss.__rsp;
- *ax = ucontext->uc_mcontext->__ss.__rax;
-# else
- *pc = ucontext->uc_mcontext->__ss.__eip;
- *bp = ucontext->uc_mcontext->__ss.__ebp;
- *sp = ucontext->uc_mcontext->__ss.__esp;
- *ax = ucontext->uc_mcontext->__ss.__eax;
-# endif // __WORDSIZE
-#else // assume linux
-# if defined (ANDROID)
- *pc = *sp = *bp = *ax = 0;
-# elif defined(__arm__)
- *pc = ucontext->uc_mcontext.arm_pc;
- *bp = ucontext->uc_mcontext.arm_fp;
- *sp = ucontext->uc_mcontext.arm_sp;
- *ax = ucontext->uc_mcontext.arm_r0;
-# elif __WORDSIZE == 64
- *pc = ucontext->uc_mcontext.gregs[REG_RIP];
- *bp = ucontext->uc_mcontext.gregs[REG_RBP];
- *sp = ucontext->uc_mcontext.gregs[REG_RSP];
- *ax = ucontext->uc_mcontext.gregs[REG_RAX];
-# else
- *pc = ucontext->uc_mcontext.gregs[REG_EIP];
- *bp = ucontext->uc_mcontext.gregs[REG_EBP];
- *sp = ucontext->uc_mcontext.gregs[REG_ESP];
- *ax = ucontext->uc_mcontext.gregs[REG_EAX];
-# endif // __WORDSIZE
-#endif
-}
-
static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
uintptr_t addr = (uintptr_t)siginfo->si_addr;
if (AddrIsInShadow(addr) && FLAG_lazy_shadow) {
@@ -322,11 +280,11 @@
}
// Write the first message using the bullet-proof write.
if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) ASAN_DIE;
- uintptr_t pc, sp, bp, ax;
- GetPcSpBpAx(context, &pc, &sp, &bp, &ax);
+ uintptr_t pc, sp, bp;
+ GetPcSpBp(context, &pc, &sp, &bp);
Report("ERROR: AddressSanitizer crashed on unknown address %p"
- " (pc %p sp %p bp %p ax %p T%d)\n",
- addr, pc, sp, bp, ax,
+ " (pc %p sp %p bp %p T%d)\n",
+ addr, pc, sp, bp,
asanThreadRegistry().GetCurrentTidOrMinusOne());
Printf("AddressSanitizer can not provide additional info. ABORTING\n");
GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, false, pc, bp);
More information about the llvm-commits
mailing list