[llvm-commits] [compiler-rt] r158148 - in /compiler-rt/trunk/lib: sanitizer_common/sanitizer_libc.cc sanitizer_common/sanitizer_libc.h tsan/rtl/tsan_defs.h tsan/rtl/tsan_interceptors.cc tsan/rtl/tsan_mman.cc

Alexey Samsonov samsonov at google.com
Thu Jun 7 04:54:09 PDT 2012


Author: samsonov
Date: Thu Jun  7 06:54:08 2012
New Revision: 158148

URL: http://llvm.org/viewvc/llvm-project?rev=158148&view=rev
Log:
[Sanitizer] move internal_strdup and internal_memcpy to common runtime. Make internal allocations from TSan runtime call InternalAlloc from common runtime

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc?rev=158148&r1=158147&r2=158148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc Thu Jun  7 06:54:08 2012
@@ -10,7 +10,7 @@
 // This file is shared between AddressSanitizer and ThreadSanitizer
 // run-time libraries. See sanitizer_libc.h for details.
 //===----------------------------------------------------------------------===//
-#include "sanitizer_internal_defs.h"
+#include "sanitizer_common.h"
 #include "sanitizer_libc.h"
 
 namespace __sanitizer {
@@ -26,6 +26,22 @@
   return 0;
 }
 
+void *internal_memcpy(void *dest, const void *src, uptr n) {
+  char *d = (char*)dest;
+  char *s = (char*)src;
+  for (uptr i = 0; i < n; ++i)
+    d[i] = s[i];
+  return dest;
+}
+
+char* internal_strdup(const char *s) {
+  uptr len = internal_strlen(s);
+  char *s2 = (char*)InternalAlloc(len + 1);
+  internal_memcpy(s2, s, len);
+  s2[len] = 0;
+  return s2;
+}
+
 int internal_strcmp(const char *s1, const char *s2) {
   while (true) {
     unsigned c1 = *s1;

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=158148&r1=158147&r2=158148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Thu Jun  7 06:54:08 2012
@@ -25,7 +25,9 @@
 
 // String functions
 void *internal_memchr(const void *s, int c, uptr n);
+void *internal_memcpy(void *dest, const void *src, uptr n);
 int internal_strcmp(const char *s1, const char *s2);
+char *internal_strdup(const char *s);
 uptr internal_strlen(const char *s);
 char *internal_strncpy(char *dst, const char *src, uptr n);
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h?rev=158148&r1=158147&r2=158148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h Thu Jun  7 06:54:08 2012
@@ -15,6 +15,7 @@
 #define TSAN_DEFS_H
 
 #include "sanitizer_common/sanitizer_internal_defs.h"
+#include "sanitizer_common/sanitizer_libc.h"
 #include "tsan_stat.h"
 
 #ifndef TSAN_DEBUG
@@ -134,11 +135,9 @@
 }
 
 void internal_memset(void *ptr, int c, uptr size);
-void internal_memcpy(void *dst, const void *src, uptr size);
 int internal_memcmp(const void *s1, const void *s2, uptr size);
 int internal_strncmp(const char *s1, const char *s2, uptr size);
 void internal_strcpy(char *s1, const char *s2);
-char* internal_strdup(const char *s);
 const char *internal_strstr(const char *where, const char *what);
 const char *internal_strchr(const char *where, char what);
 const char *internal_strrchr(const char *where, char what);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=158148&r1=158147&r2=158148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Jun  7 06:54:08 2012
@@ -1525,10 +1525,6 @@
   REAL(memset)(ptr, c, size);
 }
 
-void internal_memcpy(void *dst, const void *src, uptr size) {
-  REAL(memcpy)(dst, src, size);
-}
-
 int internal_memcmp(const void *s1, const void *s2, uptr size) {
   return REAL(memcmp)(s1, s2, size);
 }
@@ -1541,14 +1537,6 @@
   REAL(strcpy)(s1, s2);  // NOLINT
 }
 
-char* internal_strdup(const char *s) {
-  uptr len = internal_strlen(s);
-  char *s2 = (char*)internal_alloc(MBlockString, len + 1);
-  internal_memcpy(s2, s, len);
-  s2[len] = 0;
-  return s2;
-}
-
 const char *internal_strstr(const char *where, const char *what) {
   return REAL(strstr)(where, what);
 }

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc?rev=158148&r1=158147&r2=158148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Thu Jun  7 06:54:08 2012
@@ -10,6 +10,7 @@
 // This file is a part of ThreadSanitizer (TSan), a race detector.
 //
 //===----------------------------------------------------------------------===//
+#include "sanitizer_common/sanitizer_common.h"
 #include "tsan_mman.h"
 #include "tsan_allocator.h"
 #include "tsan_rtl.h"
@@ -103,13 +104,13 @@
 void *internal_alloc(MBlockType typ, uptr sz) {
   ThreadState *thr = cur_thread();
   CHECK_GT(thr->in_rtl, 0);
-  return Alloc(sz);
+  return InternalAlloc(sz);
 }
 
 void internal_free(void *p) {
   ThreadState *thr = cur_thread();
   CHECK_GT(thr->in_rtl, 0);
-  Free(p);
+  InternalFree(p);
 }
 
 }  // namespace __tsan





More information about the llvm-commits mailing list