[Sanitizer] Add sanitizer_win.cc for windows-specific implementations of libc functions. Add internal_open.

llvm-svn: 157985
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
index fd24b65..ec26332 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
@@ -29,10 +29,11 @@
 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 f105ff0..aa0558c 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 <fcntl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -32,6 +34,11 @@
 #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 432abed..84fd11b 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 <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
 
 namespace __sanitizer {
 
@@ -26,6 +29,11 @@
   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 0000000..a2f8ece
--- /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 <windows.h>
+
+#include <assert.h>
+
+#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