From dde1f11fe62736901fb6ce98c40ed573de7c61a4 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Tue, 5 Jun 2012 07:05:10 +0000 Subject: [PATCH] [Sanitizer] Add sanitizer_win.cc for windows-specific implementations of libc functions. Add internal_open. llvm-svn: 157985 --- .../lib/sanitizer_common/sanitizer_libc.h | 5 ++- .../lib/sanitizer_common/sanitizer_linux.cc | 7 ++++ .../lib/sanitizer_common/sanitizer_mac.cc | 8 ++++ .../lib/sanitizer_common/sanitizer_win.cc | 39 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 compiler-rt/lib/sanitizer_common/sanitizer_win.cc diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h index fd24b65e506f..ec26332e6eee 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h @@ -29,10 +29,11 @@ void MiniLibcStub(); int internal_strcmp(const char *s1, const char *s2); char *internal_strncpy(char *dst, const char *src, uptr n); -#ifndef _WIN32 void *internal_mmap(void *addr, uptr length, int prot, int flags, int fd, u64 offset); -#endif // _WIN32 + +typedef int fd_t; +fd_t internal_open(const char *filename, bool write); } // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index f105ff040cbc..aa0558c5e2f3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -16,7 +16,9 @@ #include "sanitizer_defs.h" #include "sanitizer_libc.h" +#include #include +#include #include #include #include @@ -32,6 +34,11 @@ void *internal_mmap(void *addr, uptr length, int prot, int flags, #endif } +fd_t internal_open(const char *filename, bool write) { + return syscall(__NR_open, filename, + write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660); +} + } // namespace __sanitizer #endif // __linux__ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc index 432abed1ecfd..84fd11b39b65 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc @@ -18,6 +18,9 @@ #include "sanitizer_libc.h" #include +#include +#include +#include namespace __sanitizer { @@ -26,6 +29,11 @@ void *internal_mmap(void *addr, size_t length, int prot, int flags, return mmap(addr, length, prot, flags, fd, offset); } +fd_t internal_open(const char *filename, bool write) { + return open(filename, + write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660); +} + } // namespace __sanitizer #endif // __APPLE__ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc new file mode 100644 index 000000000000..a2f8ece43ba5 --- /dev/null +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -0,0 +1,39 @@ +//===-- sanitizer_win.cc ------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is shared between AddressSanitizer and ThreadSanitizer +// run-time libraries and implements windows-specific functions from +// sanitizer_libc.h. +//===----------------------------------------------------------------------===// +#ifdef _WIN32 +#include + +#include + +#include "sanitizer_defs.h" +#include "sanitizer_libc.h" + +#define UNIMPLEMENTED_WIN() assert(false) + +namespace __sanitizer { + +void *internal_mmap(void *addr, uptr length, int prot, int flags, + int fd, u64 offset) { + UNIMPLEMENTED_WIN(); + return 0; +} + +fd_t internal_open(const char *filename, bool write) { + UNIMPLEMENTED_WIN(); + return 0; +} + +} // namespace __sanitizer + +#endif // _WIN32