[llvm-commits] [compiler-rt] r157990 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_libc.h sanitizer_linux.cc sanitizer_mac.cc sanitizer_win.cc

Alexey Samsonov samsonov at google.com
Tue Jun 5 01:32:53 PDT 2012


Author: samsonov
Date: Tue Jun  5 03:32:53 2012
New Revision: 157990

URL: http://llvm.org/viewvc/llvm-project?rev=157990&view=rev
Log:
[Sanitizer] add internal_{close,read,write} functions to sanitizer_libc

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=157990&r1=157989&r2=157990&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Tue Jun  5 03:32:53 2012
@@ -33,7 +33,11 @@
                     int fd, u64 offset);
 
 typedef int fd_t;
+const fd_t kInvalidFd = -1;
+int internal_close(fd_t fd);
 fd_t internal_open(const char *filename, bool write);
+uptr internal_read(fd_t fd, void *buf, uptr count);
+uptr internal_write(fd_t fd, const void *buf, uptr count);
 
 }  // namespace __sanitizer
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=157990&r1=157989&r2=157990&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Tue Jun  5 03:32:53 2012
@@ -34,11 +34,23 @@
 #endif
 }
 
+int internal_close(fd_t fd) {
+  return syscall(__NR_close, fd);
+}
+
 fd_t internal_open(const char *filename, bool write) {
   return syscall(__NR_open, filename,
       write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660);
 }
 
+uptr internal_read(fd_t fd, void *buf, uptr count) {
+  return (uptr)syscall(__NR_read, fd, buf, count);
+}
+
+uptr internal_write(fd_t fd, const void *buf, uptr count) {
+  return (uptr)syscall(__NR_write, fd, buf, count);
+}
+
 }  // namespace __sanitizer
 
 #endif  // __linux__

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=157990&r1=157989&r2=157990&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Tue Jun  5 03:32:53 2012
@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 namespace __sanitizer {
 
@@ -29,11 +30,23 @@
   return mmap(addr, length, prot, flags, fd, offset);
 }
 
+int internal_close(fd_t fd) {
+  return close(fd);
+}
+
 fd_t internal_open(const char *filename, bool write) {
   return open(filename,
               write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660);
 }
 
+uptr internal_read(fd_t fd, void *buf, uptr count) {
+  return read(fd, buf, count);
+}
+
+uptr internal_write(fd_t fd, const void *buf, uptr count) {
+  return write(fd, buf, count);
+}
+
 }  // namespace __sanitizer
 
 #endif  // __APPLE__

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=157990&r1=157989&r2=157990&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Tue Jun  5 03:32:53 2012
@@ -29,11 +29,35 @@
   return 0;
 }
 
+int internal_close(fd_t fd) {
+  UNIMPLEMENTED_WIN();
+  return 0;
+}
+
 fd_t internal_open(const char *filename, bool write) {
   UNIMPLEMENTED_WIN();
   return 0;
 }
 
+uptr internal_read(fd_t fd, void *buf, uptr count) {
+  UNIMPLEMENTED_WIN();
+  return 0;
+}
+
+uptr internal_write(fd_t fd, const void *buf, uptr count) {
+  if (fd != 2) {
+    UNIMPLEMENTED_WIN();
+    return 0;
+  }
+  HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
+  if (err == 0)
+    return 0;  // FIXME: this might not work on some apps.
+  DWORD ret;
+  if (!WriteFile(err, buf, count, &ret, 0))
+    return 0;
+  return ret;
+}
+
 }  // namespace __sanitizer
 
 #endif  // _WIN32





More information about the llvm-commits mailing list