Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 1 | //===-- asan_linux.cc -----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // Linux-specific details. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "asan_internal.h" |
| 16 | |
| 17 | #include <sys/mman.h> |
| 18 | #include <sys/syscall.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | extern char _DYNAMIC[]; |
| 22 | |
| 23 | namespace __asan { |
| 24 | |
| 25 | void *AsanDoesNotSupportStaticLinkage() { |
| 26 | // This will fail to link with -static. |
| 27 | return &_DYNAMIC; |
| 28 | } |
| 29 | |
| 30 | #ifdef ANDROID |
| 31 | #define SYS_mmap2 __NR_mmap2 |
| 32 | #define SYS_write __NR_write |
| 33 | #endif |
| 34 | |
| 35 | void *asan_mmap(void *addr, size_t length, int prot, int flags, |
| 36 | int fd, uint64_t offset) { |
| 37 | # if __WORDSIZE == 64 |
| 38 | return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset); |
| 39 | # else |
| 40 | return (void *)syscall(SYS_mmap2, addr, length, prot, flags, fd, offset); |
| 41 | # endif |
| 42 | } |
| 43 | |
| 44 | ssize_t asan_write(int fd, const void *buf, size_t count) { |
| 45 | return (ssize_t)syscall(SYS_write, fd, buf, count); |
| 46 | } |
| 47 | |
| 48 | } // namespace __asan |