blob: ceb722bf9f88bdece42e70dcd54ed75cf23d0dfe [file] [log] [blame]
Kostya Serebryany019b76f2011-11-30 01:07:02 +00001//===-- 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//===----------------------------------------------------------------------===//
Kostya Serebryany5dfa4da2011-12-01 21:40:52 +000014#ifdef __linux__
Kostya Serebryany019b76f2011-11-30 01:07:02 +000015
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
Kostya Serebryany5dfa4da2011-12-01 21:40:52 +000050
51#endif // __linux__