[llvm-commits] [compiler-rt] r157930 - in /compiler-rt/trunk/lib: asan/asan_linux.cc asan/asan_mac.cc sanitizer_common/sanitizer_libc.h sanitizer_common/sanitizer_linux.cc sanitizer_common/sanitizer_mac.cc
Alexey Samsonov
samsonov at google.com
Mon Jun 4 07:27:50 PDT 2012
Author: samsonov
Date: Mon Jun 4 09:27:50 2012
New Revision: 157930
URL: http://llvm.org/viewvc/llvm-project?rev=157930&view=rev
Log:
Created files sanitizer_linux.cc and sanitizer_mac.cc for platform-specific implementations of common functions. Turned asan_mmap into __sanitizer::internal_mmap.
Added:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
Modified:
compiler-rt/trunk/lib/asan/asan_linux.cc
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
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=157930&r1=157929&r2=157930&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Mon Jun 4 09:27:50 2012
@@ -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 @@
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 *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) {
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=157930&r1=157929&r2=157930&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Mon Jun 4 09:27:50 2012
@@ -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 @@
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 *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 @@
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;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=157930&r1=157929&r2=157930&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Mon Jun 4 09:27:50 2012
@@ -29,6 +29,11 @@
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
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=157930&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon Jun 4 09:27:50 2012
@@ -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__
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=157930&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Jun 4 09:27:50 2012
@@ -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__
More information about the llvm-commits
mailing list