[llvm-commits] [compiler-rt] r147811 - in /compiler-rt/trunk/lib/asan: asan_internal.h asan_linux.cc asan_mac.cc asan_posix.cc asan_printf.cc asan_rtl.cc

Kostya Serebryany kcc at google.com
Mon Jan 9 15:11:26 PST 2012


Author: kcc
Date: Mon Jan  9 17:11:26 2012
New Revision: 147811

URL: http://llvm.org/viewvc/llvm-project?rev=147811&view=rev
Log:
[asan] don't include unistd.h in the headers

Modified:
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_linux.cc
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_posix.cc
    compiler-rt/trunk/lib/asan/asan_printf.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon Jan  9 17:11:26 2012
@@ -20,7 +20,6 @@
 
 #include <stdint.h>  // for __WORDSIZE
 #include <stdlib.h>  // for size_t
-#include <unistd.h>  // for _exit
 
 // If __WORDSIZE was undefined by the platform, define it in terms of the
 // compiler built-in __LP64__.
@@ -102,19 +101,20 @@
 void AsanDisableCoreDumper();
 void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp);
 
-ssize_t AsanRead(int fd, void *buf, size_t count);
-ssize_t AsanWrite(int fd, const void *buf, size_t count);
+size_t AsanRead(int fd, void *buf, size_t count);
+size_t AsanWrite(int fd, const void *buf, size_t count);
 int AsanClose(int fd);
 
 bool AsanInterceptsSignal(int signum);
 void InstallSignalHandlers();
+int GetPid();
 
 // Opens the file 'file_name" and reads up to 'max_len' bytes.
 // The resulting buffer is mmaped and stored in '*buff'.
 // The size of the mmaped region is stored in '*buff_size',
-// Returns the number of read bytes or -1 if file can not be opened.
-ssize_t ReadFileToBuffer(const char *file_name, char **buff,
-                         size_t *buff_size, size_t max_len);
+// Returns the number of read bytes or 0 if file can not be opened.
+size_t ReadFileToBuffer(const char *file_name, char **buff,
+                        size_t *buff_size, size_t max_len);
 
 // asan_printf.cc
 void RawWrite(const char *buffer);
@@ -162,9 +162,7 @@
 
 enum LinkerInitialized { LINKER_INITIALIZED = 0 };
 
-#ifndef ASAN_DIE
-#define ASAN_DIE _exit(FLAG_exitcode)
-#endif  // ASAN_DIE
+void AsanDie();
 
 #define CHECK(cond) do { if (!(cond)) { \
   CheckFailed(#cond, __FILE__, __LINE__); \
@@ -173,7 +171,7 @@
 #define RAW_CHECK_MSG(expr, msg) do { \
   if (!(expr)) { \
     RawWrite(msg); \
-    ASAN_DIE; \
+    AsanDie(); \
   } \
 } while (0)
 

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Mon Jan  9 17:11:26 2012
@@ -114,20 +114,20 @@
   int res = syscall(__NR_munmap, addr, size);
   if (res != 0) {
     Report("Failed to unmap\n");
-    ASAN_DIE;
+    AsanDie();
   }
 }
 
-ssize_t AsanWrite(int fd, const void *buf, size_t count) {
-  return (ssize_t)syscall(__NR_write, fd, buf, count);
+size_t AsanWrite(int fd, const void *buf, size_t count) {
+  return (size_t)syscall(__NR_write, fd, buf, count);
 }
 
 int AsanOpenReadonly(const char* filename) {
   return open(filename, O_RDONLY);
 }
 
-ssize_t AsanRead(int fd, void *buf, size_t count) {
-  return (ssize_t)syscall(__NR_read, fd, buf, count);
+size_t AsanRead(int fd, void *buf, size_t count) {
+  return (size_t)syscall(__NR_read, fd, buf, count);
 }
 
 int AsanClose(int fd) {
@@ -202,8 +202,8 @@
   if (count == 0) {
     // The first item (the main executable) does not have a so name,
     // but we can just read it from /proc/self/exe.
-    ssize_t path_len = readlink("/proc/self/exe",
-                                data->filename, data->filename_size - 1);
+    size_t path_len = readlink("/proc/self/exe",
+                               data->filename, data->filename_size - 1);
     data->filename[path_len] = 0;
   } else {
     CHECK(info->dlpi_name);

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Mon Jan  9 17:11:26 2012
@@ -50,7 +50,6 @@
 # endif  // __WORDSIZE
 }
 
-
 // No-op. Mac does not support static linkage anyway.
 void *AsanDoesNotSupportStaticLinkage() {
   return NULL;
@@ -65,7 +64,7 @@
   return mmap(addr, length, prot, flags, fd, offset);
 }
 
-ssize_t AsanWrite(int fd, const void *buf, size_t count) {
+size_t AsanWrite(int fd, const void *buf, size_t count) {
   return write(fd, buf, count);
 }
 
@@ -106,7 +105,7 @@
   int res = munmap(addr, size);
   if (res != 0) {
     Report("Failed to unmap\n");
-    ASAN_DIE;
+    AsanDie();
   }
 }
 
@@ -114,7 +113,7 @@
   return open(filename, O_RDONLY);
 }
 
-ssize_t AsanRead(int fd, void *buf, size_t count) {
+size_t AsanRead(int fd, void *buf, size_t count) {
   return read(fd, buf, count);
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Mon Jan  9 17:11:26 2012
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <unistd.h>
 
 namespace __asan {
 
@@ -38,7 +39,7 @@
 static void     ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
   uintptr_t addr = (uintptr_t)siginfo->si_addr;
   // Write the first message using the bullet-proof write.
-  if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) ASAN_DIE;
+  if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) AsanDie();
   uintptr_t pc, sp, bp;
   GetPcSpBp(context, &pc, &sp, &bp);
   Report("ERROR: AddressSanitizer crashed on unknown address %p"
@@ -63,6 +64,14 @@
   setrlimit(RLIMIT_CORE, &nocore);
 }
 
+void AsanDie() {
+  _exit(FLAG_exitcode);
+}
+
+int GetPid() {
+  return getpid();
+}
+
 }  // namespace __asan
 
 #endif  // __linux__ || __APPLE_

Modified: compiler-rt/trunk/lib/asan/asan_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_printf.cc?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_printf.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_printf.cc Mon Jan  9 17:11:26 2012
@@ -24,10 +24,10 @@
 
 void RawWrite(const char *buffer) {
   static const char *kRawWriteError = "RawWrite can't output requested buffer!";
-  ssize_t length = (ssize_t)internal_strlen(buffer);
+  size_t length = (size_t)internal_strlen(buffer);
   if (length != AsanWrite(2, buffer, length)) {
     AsanWrite(2, kRawWriteError, internal_strlen(kRawWriteError));
-    ASAN_DIE;
+    AsanDie();
   }
 }
 
@@ -168,7 +168,7 @@
 void Report(const char *format, ...) {
   const int kLen = 1024 * 4;
   char buffer[kLen];
-  int needed_length = SNPrintf(buffer, kLen, "==%d== ", getpid());
+  int needed_length = SNPrintf(buffer, kLen, "==%d== ", GetPid());
   RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
   va_list args;
   va_start(args, format);

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=147811&r1=147810&r2=147811&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Jan  9 17:11:26 2012
@@ -57,7 +57,7 @@
 // -------------------------- Misc ---------------- {{{1
 void ShowStatsAndAbort() {
   __asan_print_accumulated_stats();
-  ASAN_DIE;
+  AsanDie();
 }
 
 static void PrintBytes(const char *before, uintptr_t *a) {
@@ -70,10 +70,10 @@
   Printf("\n");
 }
 
-ssize_t ReadFileToBuffer(const char *file_name, char **buff,
+size_t ReadFileToBuffer(const char *file_name, char **buff,
                          size_t *buff_size, size_t max_len) {
   const size_t kMinFileLen = kPageSize;
-  ssize_t read_len = -1;
+  size_t read_len = 0;
   *buff = 0;
   *buff_size = 0;
   // The files we usually open are not seekable, so try different buffer sizes.
@@ -386,7 +386,7 @@
   PrintBytes("  ", (uintptr_t*)(aligned_shadow+2*kWordSize));
   PrintBytes("  ", (uintptr_t*)(aligned_shadow+3*kWordSize));
   PrintBytes("  ", (uintptr_t*)(aligned_shadow+4*kWordSize));
-  ASAN_DIE;
+  AsanDie();
 }
 
 void __asan_init() {





More information about the llvm-commits mailing list