blob: 752300b7e0f5498a35295e3d963781e4c0f2a903 [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//===----------------------------------------------------------------------===//
14
15#include "asan_internal.h"
16
17#include <sys/mman.h>
18#include <sys/syscall.h>
19#include <unistd.h>
20
21extern char _DYNAMIC[];
22
23namespace __asan {
24
25void *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
35void *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
44ssize_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