[llvm-commits] [compiler-rt] r162351 - in /compiler-rt/trunk/lib: sanitizer_common/sanitizer_common.h tsan/rtl/tsan_mman.h tsan/rtl/tsan_printf.cc tsan/rtl/tsan_rtl.cc tsan/rtl/tsan_rtl_report.cc tsan/rtl/tsan_suppressions.cc tsan/rtl/tsan_symbolize.cc tsan/rtl/tsan_symbolize_addr2line_linux.cc
Alexey Samsonov
samsonov at google.com
Wed Aug 22 00:25:52 PDT 2012
Author: samsonov
Date: Wed Aug 22 02:25:52 2012
New Revision: 162351
URL: http://llvm.org/viewvc/llvm-project?rev=162351&view=rev
Log:
[TSan] switch tsan to using InternalScopedBuffer from sanitizer_common
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
compiler-rt/trunk/lib/tsan/rtl/tsan_printf.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Aug 22 02:25:52 2012
@@ -65,6 +65,7 @@
~InternalScopedBuffer() {
InternalFree(ptr_);
}
+ operator T*() { return ptr_; }
T &operator[](uptr i) { return ptr_[i]; }
T *data() { return ptr_; }
uptr size() { return cnt_ * sizeof(T); }
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h Wed Aug 22 02:25:52 2012
@@ -71,45 +71,5 @@
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
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_printf.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_printf.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_printf.cc Wed Aug 22 02:25:52 2012
@@ -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 @@
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
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Wed Aug 22 02:25:52 2012
@@ -120,9 +120,9 @@
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 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();
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Wed Aug 22 02:25:52 2012
@@ -213,7 +213,7 @@
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]);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Wed Aug 22 02:25:52 2012
@@ -26,27 +26,27 @@
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);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc Wed Aug 22 02:25:52 2012
@@ -47,7 +47,7 @@
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,
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc?rev=162351&r1=162350&r2=162351&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc Wed Aug 22 02:25:52 2012
@@ -85,10 +85,10 @@
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 @@
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;
More information about the llvm-commits
mailing list