blob: aa0558c5e2f30d738c6a83e6b7cd5f1ca6e5b0a5 [file] [log] [blame]
Alexey Samsonov2c5fc3b2012-06-04 14:27:50 +00001//===-- sanitizer_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 shared between AddressSanitizer and ThreadSanitizer
11// run-time libraries and implements linux-specific functions from
12// sanitizer_libc.h.
13//===----------------------------------------------------------------------===//
14#ifdef __linux__
15
16#include "sanitizer_defs.h"
17#include "sanitizer_libc.h"
18
Alexey Samsonovdde1f112012-06-05 07:05:10 +000019#include <fcntl.h>
Alexey Samsonov2c5fc3b2012-06-04 14:27:50 +000020#include <sys/mman.h>
Alexey Samsonovdde1f112012-06-05 07:05:10 +000021#include <sys/stat.h>
Alexey Samsonov2c5fc3b2012-06-04 14:27:50 +000022#include <sys/syscall.h>
23#include <sys/types.h>
24#include <unistd.h>
25
26namespace __sanitizer {
27
28void *internal_mmap(void *addr, uptr length, int prot, int flags,
29 int fd, u64 offset) {
30#if __WORDSIZE == 64
31 return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
32#else
33 return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset);
34#endif
35}
36
Alexey Samsonovdde1f112012-06-05 07:05:10 +000037fd_t internal_open(const char *filename, bool write) {
38 return syscall(__NR_open, filename,
39 write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660);
40}
41
Alexey Samsonov2c5fc3b2012-06-04 14:27:50 +000042} // namespace __sanitizer
43
44#endif // __linux__