forked from OSchip/llvm-project
Created files sanitizer_linux.cc and sanitizer_mac.cc for platform-specific implementations of common functions. Turned asan_mmap into __sanitizer::internal_mmap.
llvm-svn: 157930
This commit is contained in:
parent
245917b536
commit
2c5fc3bb11
|
@ -18,6 +18,7 @@
|
|||
#include "asan_lock.h"
|
||||
#include "asan_procmaps.h"
|
||||
#include "asan_thread.h"
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
@ -35,6 +36,8 @@
|
|||
#include <sys/ucontext.h>
|
||||
#endif
|
||||
|
||||
using namespace __sanitizer; // NOLINT
|
||||
|
||||
extern "C" void* _DYNAMIC;
|
||||
|
||||
namespace __asan {
|
||||
|
@ -73,20 +76,11 @@ bool AsanInterceptsSignal(int signum) {
|
|||
return signum == SIGSEGV && FLAG_handle_segv;
|
||||
}
|
||||
|
||||
static void *asan_mmap(void *addr, uptr length, int prot, int flags,
|
||||
int fd, u64 offset) {
|
||||
# if __WORDSIZE == 64
|
||||
return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
|
||||
# else
|
||||
return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset);
|
||||
# endif
|
||||
}
|
||||
|
||||
void *AsanMmapSomewhereOrDie(uptr size, const char *mem_type) {
|
||||
size = RoundUpTo(size, kPageSize);
|
||||
void *res = asan_mmap(0, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
void *res = internal_mmap(0, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
if (res == (void*)-1) {
|
||||
OutOfMemoryMessageAndDie(mem_type, size);
|
||||
}
|
||||
|
@ -94,17 +88,17 @@ void *AsanMmapSomewhereOrDie(uptr size, const char *mem_type) {
|
|||
}
|
||||
|
||||
void *AsanMmapFixedNoReserve(uptr fixed_addr, uptr size) {
|
||||
return asan_mmap((void*)fixed_addr, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
return internal_mmap((void*)fixed_addr, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void *AsanMprotect(uptr fixed_addr, uptr size) {
|
||||
return asan_mmap((void*)fixed_addr, size,
|
||||
PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
return internal_mmap((void*)fixed_addr, size,
|
||||
PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void AsanUnmapOrDie(void *addr, uptr size) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "asan_stack.h"
|
||||
#include "asan_thread.h"
|
||||
#include "asan_thread_registry.h"
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
|
||||
#include <crt_externs.h> // for _NSGetEnviron
|
||||
#include <mach-o/dyld.h>
|
||||
|
@ -35,6 +36,8 @@
|
|||
#include <libkern/OSAtomic.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
|
||||
using namespace __sanitizer; // NOLINT
|
||||
|
||||
namespace __asan {
|
||||
|
||||
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
|
||||
|
@ -97,20 +100,15 @@ bool AsanInterceptsSignal(int signum) {
|
|||
return (signum == SIGSEGV || signum == SIGBUS) && FLAG_handle_segv;
|
||||
}
|
||||
|
||||
static void *asan_mmap(void *addr, size_t length, int prot, int flags,
|
||||
int fd, u64 offset) {
|
||||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
size_t AsanWrite(int fd, const void *buf, size_t count) {
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
|
||||
void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
|
||||
size = RoundUpTo(size, kPageSize);
|
||||
void *res = asan_mmap(0, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
void *res = internal_mmap(0, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
if (res == (void*)-1) {
|
||||
OutOfMemoryMessageAndDie(mem_type, size);
|
||||
}
|
||||
|
@ -118,17 +116,17 @@ void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
|
|||
}
|
||||
|
||||
void *AsanMmapFixedNoReserve(uptr fixed_addr, size_t size) {
|
||||
return asan_mmap((void*)fixed_addr, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
return internal_mmap((void*)fixed_addr, size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void *AsanMprotect(uptr fixed_addr, size_t size) {
|
||||
return asan_mmap((void*)fixed_addr, size,
|
||||
PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
return internal_mmap((void*)fixed_addr, size,
|
||||
PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void AsanUnmapOrDie(void *addr, size_t size) {
|
||||
|
@ -351,10 +349,10 @@ mach_error_t __interception_allocate_island(void **ptr,
|
|||
void *unused_hint) {
|
||||
if (!island_allocator_pos) {
|
||||
island_allocator_pos =
|
||||
asan_mmap((void*)kIslandBeg, kIslandEnd - kIslandBeg,
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
|
||||
-1, 0);
|
||||
internal_mmap((void*)kIslandBeg, kIslandEnd - kIslandBeg,
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
|
||||
-1, 0);
|
||||
if (island_allocator_pos != (void*)kIslandBeg) {
|
||||
return KERN_NO_SPACE;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ void MiniLibcStub();
|
|||
int internal_strcmp(const char *s1, const char *s2);
|
||||
char *internal_strncpy(char *dst, const char *src, uptr n);
|
||||
|
||||
#ifndef _WIN32
|
||||
void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
int fd, u64 offset);
|
||||
#endif // _WIN32
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // SANITIZER_LIBC_H
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
//===-- sanitizer_linux.cc ------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file is shared between AddressSanitizer and ThreadSanitizer
|
||||
// run-time libraries and implements linux-specific functions from
|
||||
// sanitizer_libc.h.
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifdef __linux__
|
||||
|
||||
#include "sanitizer_defs.h"
|
||||
#include "sanitizer_libc.h"
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
int fd, u64 offset) {
|
||||
#if __WORDSIZE == 64
|
||||
return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
|
||||
#else
|
||||
return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __linux__
|
|
@ -0,0 +1,31 @@
|
|||
//===-- sanitizer_mac.cc --------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file is shared between AddressSanitizer and ThreadSanitizer
|
||||
// run-time libraries and implements mac-specific functions from
|
||||
// sanitizer_libc.h.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "sanitizer_defs.h"
|
||||
#include "sanitizer_libc.h"
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
void *internal_mmap(void *addr, size_t length, int prot, int flags,
|
||||
int fd, u64 offset) {
|
||||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __APPLE__
|
Loading…
Reference in New Issue