aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-08-22 07:25:52 +0000
committerAlexey Samsonov <samsonov@google.com>2012-08-22 07:25:52 +0000
commit75e5fc3e57c98baf3f06e64e558971d3e0f9870c (patch)
tree6218d2e579bb2586fcdd31cdb9fcae712364cc7d
parent62698881669072ca047b9e5182be8fcc6c427a11 (diff)
downloadllvm-75e5fc3e57c98baf3f06e64e558971d3e0f9870c.zip
llvm-75e5fc3e57c98baf3f06e64e558971d3e0f9870c.tar.gz
llvm-75e5fc3e57c98baf3f06e64e558971d3e0f9870c.tar.bz2
[TSan] switch tsan to using InternalScopedBuffer from sanitizer_common
llvm-svn: 162351
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common.h1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_mman.h40
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_printf.cc7
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_rtl.cc12
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc2
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_suppressions.cc12
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_symbolize.cc2
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc12
8 files changed, 25 insertions, 63 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index c4b4a83..0e9371f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -65,6 +65,7 @@ class InternalScopedBuffer {
~InternalScopedBuffer() {
InternalFree(ptr_);
}
+ operator T*() { return ptr_; }
T &operator[](uptr i) { return ptr_[i]; }
T *data() { return ptr_; }
uptr size() { return cnt_ * sizeof(T); }
diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.h b/compiler-rt/lib/tsan/rtl/tsan_mman.h
index 2d361cb..a3546a7 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mman.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_mman.h
@@ -71,45 +71,5 @@ void DestroyAndFree(T *&p) {
p = 0;
}
-template<typename T>
-class InternalScopedBuf {
- public:
- explicit InternalScopedBuf(uptr cnt) {
- cnt_ = cnt;
- ptr_ = (T*)internal_alloc(MBlockScopedBuf, cnt * sizeof(T));
- }
-
- ~InternalScopedBuf() {
- internal_free(ptr_);
- }
-
- operator T *() {
- return ptr_;
- }
-
- T &operator[](uptr i) {
- return ptr_[i];
- }
-
- T *Ptr() {
- return ptr_;
- }
-
- uptr Count() {
- return cnt_;
- }
-
- uptr Size() {
- return cnt_ * sizeof(T);
- }
-
- private:
- T *ptr_;
- uptr cnt_;
-
- InternalScopedBuf(const InternalScopedBuf&);
- void operator = (const InternalScopedBuf&);
-};
-
} // namespace __tsan
#endif // TSAN_MMAN_H
diff --git a/compiler-rt/lib/tsan/rtl/tsan_printf.cc b/compiler-rt/lib/tsan/rtl/tsan_printf.cc
index 6f41440..eb2d297b9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_printf.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_printf.cc
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "tsan_defs.h"
#include "tsan_mman.h"
@@ -27,13 +28,13 @@ namespace __tsan {
void TsanPrintf(const char *format, ...) {
ScopedInRtl in_rtl;
const uptr kMaxLen = 16 * 1024;
- InternalScopedBuf<char> buffer(kMaxLen);
+ InternalScopedBuffer<char> buffer(kMaxLen);
va_list args;
va_start(args, format);
- uptr len = VSNPrintf(buffer, buffer.Size(), format, args);
+ uptr len = VSNPrintf(buffer, buffer.size(), format, args);
va_end(args);
internal_write(CTX() ? flags()->log_fileno : 2,
- buffer, len < buffer.Size() ? len : buffer.Size() - 1);
+ buffer, len < buffer.size() ? len : buffer.size() - 1);
}
} // namespace __tsan
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc
index 2263a66..57cdf44 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc
@@ -120,9 +120,9 @@ static void MemoryProfileThread(void *arg) {
ScopedInRtl in_rtl;
fd_t fd = (fd_t)(uptr)arg;
for (int i = 0; ; i++) {
- InternalScopedBuf<char> buf(4096);
- WriteMemoryProfile(buf.Ptr(), buf.Size(), i);
- internal_write(fd, buf.Ptr(), internal_strlen(buf.Ptr()));
+ InternalScopedBuffer<char> buf(4096);
+ WriteMemoryProfile(buf, buf.size(), i);
+ internal_write(fd, buf, internal_strlen(buf));
SleepForSeconds(1);
}
}
@@ -130,10 +130,10 @@ static void MemoryProfileThread(void *arg) {
static void InitializeMemoryProfile() {
if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
return;
- InternalScopedBuf<char> filename(4096);
- internal_snprintf(filename.Ptr(), filename.Size(), "%s.%d",
+ InternalScopedBuffer<char> filename(4096);
+ internal_snprintf(filename, filename.size(), "%s.%d",
flags()->profile_memory, GetPid());
- fd_t fd = internal_open(filename.Ptr(), true);
+ fd_t fd = internal_open(filename, true);
if (fd == kInvalidFd) {
TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]);
Die();
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc
index 6d1d49b..f1d7f22 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc
@@ -213,7 +213,7 @@ void RestoreStack(int tid, const u64 epoch, StackTrace *stk) {
const u64 ebegin = eend / kTracePartSize * kTracePartSize;
DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx);
- InternalScopedBuf<uptr> stack(1024); // FIXME: de-hardcode 1024
+ InternalScopedBuffer<uptr> stack(1024); // FIXME: de-hardcode 1024
for (uptr i = 0; i < hdr->stack0.Size(); i++) {
stack[i] = hdr->stack0.Get(i);
DPrintf2(" #%02lu: pc=%zx\n", i, stack[i]);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
index 7549a4f..f442fe1 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
@@ -26,27 +26,27 @@ static Suppression *g_suppressions;
static char *ReadFile(const char *filename) {
if (filename == 0 || filename[0] == 0)
return 0;
- InternalScopedBuf<char> tmp(4*1024);
+ InternalScopedBuffer<char> tmp(4*1024);
if (filename[0] == '/')
- internal_snprintf(tmp, tmp.Size(), "%s", filename);
+ internal_snprintf(tmp, tmp.size(), "%s", filename);
else
- internal_snprintf(tmp, tmp.Size(), "%s/%s", GetPwd(), filename);
+ internal_snprintf(tmp, tmp.size(), "%s/%s", GetPwd(), filename);
fd_t fd = internal_open(tmp, false);
if (fd == kInvalidFd) {
TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",
- tmp.Ptr());
+ tmp.data());
Die();
}
const uptr fsize = internal_filesize(fd);
if (fsize == (uptr)-1) {
TsanPrintf("ThreadSanitizer: failed to stat suppressions file '%s'\n",
- tmp.Ptr());
+ tmp.data());
Die();
}
char *buf = (char*)internal_alloc(MBlockSuppression, fsize + 1);
if (fsize != internal_read(fd, buf, fsize)) {
TsanPrintf("ThreadSanitizer: failed to read suppressions file '%s'\n",
- tmp.Ptr());
+ tmp.data());
Die();
}
internal_close(fd);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc
index f757d07..66e4e1e 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc
@@ -47,7 +47,7 @@ static ReportStack *NewReportStackEntry(const AddressInfo &info) {
ReportStack *SymbolizeCode(uptr addr) {
if (flags()->use_internal_symbolizer) {
static const uptr kMaxAddrFrames = 16;
- InternalScopedBuf<AddressInfo> addr_frames(kMaxAddrFrames);
+ InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);
for (uptr i = 0; i < kMaxAddrFrames; i++)
new(&addr_frames[i]) AddressInfo();
uptr addr_frames_num = __sanitizer::SymbolizeCode(addr, addr_frames,
diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
index 5eed977..ab2b01c 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
@@ -85,10 +85,10 @@ static void NOINLINE InitModule(ModuleDesc *m) {
static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
- InternalScopedBuf<char> tmp(128);
+ InternalScopedBuffer<char> tmp(128);
if (ctx->is_first) {
- internal_snprintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid());
- info->dlpi_name = tmp.Ptr();
+ internal_snprintf(tmp, tmp.size(), "/proc/%d/exe", GetPid());
+ info->dlpi_name = tmp.data();
}
ctx->is_first = false;
if (info->dlpi_name == 0 || info->dlpi_name[0] == 0)
@@ -159,14 +159,14 @@ ReportStack *SymbolizeCodeAddr2Line(uptr addr) {
m->out_fd, errno);
Die();
}
- InternalScopedBuf<char> func(1024);
- ssize_t len = internal_read(m->inp_fd, func, func.Size() - 1);
+ InternalScopedBuffer<char> func(1024);
+ ssize_t len = internal_read(m->inp_fd, func, func.size() - 1);
if (len <= 0) {
TsanPrintf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n",
m->inp_fd, errno);
Die();
}
- func.Ptr()[len] = 0;
+ func.data()[len] = 0;
ReportStack *res = NewReportStackEntry(addr);
res->module = internal_strdup(m->name);
res->offset = offset;