[llvm-commits] [compiler-rt] r162834 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_common.h sanitizer_printf.cc sanitizer_stacktrace.cc
Kostya Serebryany
kcc at google.com
Wed Aug 29 01:40:36 PDT 2012
Author: kcc
Date: Wed Aug 29 03:40:36 2012
New Revision: 162834
URL: http://llvm.org/viewvc/llvm-project?rev=162834&view=rev
Log:
[asan/tsan] use InternalScopedBuffer instead of stack arrays. Use mmap inseted of InternalAlloc in InternalScopedBuffer
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.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=162834&r1=162833&r2=162834&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Aug 29 03:40:36 2012
@@ -55,15 +55,17 @@
// InternalScopedBuffer can be used instead of large stack arrays to
// keep frame size low.
+// FIXME: use InternalAlloc instead of MmapOrDie once
+// InternalAlloc is made libc-free.
template<typename T>
class InternalScopedBuffer {
public:
explicit InternalScopedBuffer(uptr cnt) {
cnt_ = cnt;
- ptr_ = (T*)InternalAlloc(cnt * sizeof(T));
+ ptr_ = (T*)MmapOrDie(cnt * sizeof(T), "InternalScopedBuffer");
}
~InternalScopedBuffer() {
- InternalFree(ptr_);
+ UnmapOrDie(ptr_, cnt_ * sizeof(T));
}
operator T*() { return ptr_; }
T &operator[](uptr i) { return ptr_[i]; }
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=162834&r1=162833&r2=162834&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc Wed Aug 29 03:40:36 2012
@@ -149,16 +149,15 @@
void Printf(const char *format, ...) {
const int kLen = 1024 * 4;
- char *buffer = (char*)MmapOrDie(kLen, __FUNCTION__);
+ InternalScopedBuffer<char> buffer(kLen);
va_list args;
va_start(args, format);
- int needed_length = VSNPrintf(buffer, kLen, format, args);
+ int needed_length = VSNPrintf(buffer.data(), kLen, format, args);
va_end(args);
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Printf is too short!\n");
- RawWrite(buffer);
+ RawWrite(buffer.data());
if (PrintfAndReportCallback)
- PrintfAndReportCallback(buffer);
- UnmapOrDie(buffer, kLen);
+ PrintfAndReportCallback(buffer.data());
}
// Writes at most "length" symbols to "buffer" (including trailing '\0').
@@ -176,19 +175,19 @@
// Like Printf, but prints the current PID before the output string.
void Report(const char *format, ...) {
const int kLen = 1024 * 4;
- char *buffer = (char*)MmapOrDie(kLen, __FUNCTION__);
- int needed_length = internal_snprintf(buffer, kLen, "==%d== ", GetPid());
+ InternalScopedBuffer<char> buffer(kLen);
+ int needed_length = internal_snprintf(buffer.data(),
+ kLen, "==%d== ", GetPid());
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
va_list args;
va_start(args, format);
- needed_length += VSNPrintf(buffer + needed_length, kLen - needed_length,
- format, args);
+ needed_length += VSNPrintf(buffer.data() + needed_length,
+ kLen - needed_length, format, args);
va_end(args);
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
- RawWrite(buffer);
+ RawWrite(buffer.data());
if (PrintfAndReportCallback)
- PrintfAndReportCallback(buffer);
- UnmapOrDie(buffer, kLen);
+ PrintfAndReportCallback(buffer.data());
}
} // namespace __sanitizer
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=162834&r1=162833&r2=162834&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Wed Aug 29 03:40:36 2012
@@ -40,23 +40,23 @@
bool symbolize, const char *strip_file_prefix,
SymbolizeCallback symbolize_callback ) {
MemoryMappingLayout proc_maps;
+ InternalScopedBuffer<char> buff(kPageSize * 2);
+ InternalScopedBuffer<AddressInfo> addr_frames(64);
uptr frame_num = 0;
for (uptr i = 0; i < size && addr[i]; i++) {
uptr pc = patch_pc(addr[i]);
if (symbolize_callback) {
- char buff[4096];
- symbolize_callback((void*)pc, buff, sizeof(buff));
+ symbolize_callback((void*)pc, buff.data(), buff.size());
// We can't know anything about the string returned by external
// symbolizer, but if it starts with filename, try to strip path prefix
// from it.
Printf(" #%zu 0x%zx %s\n", frame_num, pc,
- StripPathPrefix(buff, strip_file_prefix));
+ StripPathPrefix(buff.data(), strip_file_prefix));
frame_num++;
continue;
}
- AddressInfo addr_frames[64];
uptr addr_frames_num =
- symbolize ? SymbolizeCode(pc, addr_frames, ARRAY_SIZE(addr_frames)) : 0;
+ symbolize ? SymbolizeCode(pc, addr_frames.data(), addr_frames.size()) : 0;
if (addr_frames_num > 0) {
for (uptr j = 0; j < addr_frames_num; j++) {
AddressInfo &info = addr_frames[j];
@@ -77,11 +77,10 @@
}
} else {
uptr offset;
- char filename[4096];
if (proc_maps.GetObjectNameAndOffset(pc, &offset,
- filename, sizeof(filename))) {
+ buff.data(), buff.size())) {
Printf(" #%zu 0x%zx (%s+0x%zx)\n", frame_num, pc,
- StripPathPrefix(filename, strip_file_prefix), offset);
+ StripPathPrefix(buff.data(), strip_file_prefix), offset);
} else {
Printf(" #%zu 0x%zx\n", frame_num, pc);
}
More information about the llvm-commits
mailing list