asan_linux.cc revision d6567c5166412f6acdde851e767c26f332d51d3d
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#ifdef __linux__
15
16#include "asan_internal.h"
17
18#include <sys/mman.h>
19#include <sys/syscall.h>
20#include <unistd.h>
21
22extern char _DYNAMIC[];
23
24namespace __asan {
25
26void *AsanDoesNotSupportStaticLinkage() {
27  // This will fail to link with -static.
28  return &_DYNAMIC;
29}
30
31#ifdef ANDROID
32#define SYS_mmap2 __NR_mmap2
33#define SYS_write __NR_write
34#endif
35
36void *asan_mmap(void *addr, size_t length, int prot, int flags,
37                int fd, uint64_t offset) {
38# if __WORDSIZE == 64
39  return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
40# else
41  return (void *)syscall(SYS_mmap2, addr, length, prot, flags, fd, offset);
42# endif
43}
44
45ssize_t asan_write(int fd, const void *buf, size_t count) {
46  return (ssize_t)syscall(SYS_write, fd, buf, count);
47}
48
49}  // namespace __asan
50
51#endif  // __linux__
52