forked from OSchip/llvm-project
[asan] move more code into OS-specific files
llvm-svn: 147671
This commit is contained in:
parent
9b7022e570
commit
25d6c1b3c3
|
@ -100,6 +100,7 @@ void *AsanMmapSomewhereOrDie(size_t size, const char *where);
|
|||
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);
|
||||
|
|
|
@ -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 @@ void *AsanDoesNotSupportStaticLinkage() {
|
|||
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
|
||||
|
|
|
@ -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_barrier_async_f_f real_dispatch_barrier_async_f;
|
|||
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;
|
||||
|
|
|
@ -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 @@ static void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
|
|||
}
|
||||
|
||||
// -------------------------- 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 @@ static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
|
|||
}
|
||||
// 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);
|
||||
|
|
Loading…
Reference in New Issue