summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-01-03 02:07:58 +0000
committerKostya Serebryany <kcc@google.com>2015-01-03 02:07:58 +0000
commitc5576ae946ba193b49efba22f9d2549f4b338218 (patch)
tree1e20e4148f6cd56638f77ae10f04fdc62d870c38 /lib/sanitizer_common
parent105651aba0277bd52a4987c6e48a8c2dc84fb13e (diff)
downloadcompiler-rt-c5576ae946ba193b49efba22f9d2549f4b338218.tar.gz
[asan/tracing] extend the test a bit more, simplify the tracing code, add a guard page to trace array, fix the trace IDs before dumping
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r--lib/sanitizer_common/sanitizer_coverage_libcdep.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
index 0639dc090..2a6b4d122 100644
--- a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
@@ -165,9 +165,12 @@ void CoverageData::Init() {
atomic_store(&cc_array_size, kCcArrayMaxSize, memory_order_relaxed);
atomic_store(&cc_array_index, 0, memory_order_relaxed);
- tr_event_array = reinterpret_cast<u32 *>(
- MmapNoReserveOrDie(sizeof(tr_event_array[0]) * kTrEventArrayMaxSize,
- "CovInit::tr_event_array"));
+ // Allocate tr_event_array with a guard page at the end.
+ tr_event_array = reinterpret_cast<u32 *>(MmapNoReserveOrDie(
+ sizeof(tr_event_array[0]) * kTrEventArrayMaxSize + GetMmapGranularity(),
+ "CovInit::tr_event_array"));
+ Mprotect(reinterpret_cast<uptr>(&tr_event_array[kTrEventArrayMaxSize]),
+ GetMmapGranularity());
tr_event_array_size = kTrEventArrayMaxSize;
tr_event_array_index = 0;
}
@@ -416,6 +419,8 @@ void CoverageData::DumpTrace() {
fd = CovOpenFile(false, "trace-events");
if (fd < 0) return;
+ for (uptr i = 0; i < max_idx; i++)
+ tr_event_array[i]--; // Fix the IDs.
internal_write(fd, tr_event_array, max_idx * sizeof(tr_event_array[0]));
internal_close(fd);
VReport(1, " CovDump: Trace: %zd PCs written\n", size());
@@ -464,12 +469,16 @@ void CoverageData::DumpCallerCalleePairs() {
// Record the current PC into the event buffer.
// Every event is a u32 value (index in tr_pc_array_index) so we compute
// it once and then cache in the provided 'cache' storage.
+//
+// This function will eventually be inlined by the compiler.
void CoverageData::TraceBasicBlock(s32 *id) {
- CHECK(coverage_enabled);
- uptr idx = *id;
- CHECK_LT(tr_event_array_index, tr_event_array_size);
- tr_event_array[tr_event_array_index] = static_cast<u32>(idx);
- tr_event_array_index++;
+ // CHECK(coverage_enabled);
+ // CHECK_LT(tr_event_array_index, tr_event_array_size);
+ //
+ // Will trap here if
+ // 1. coverage is not enabled at run-time.
+ // 2. The array tr_event_array is full.
+ tr_event_array[tr_event_array_index++] = static_cast<u32>(*id);
}
static void CovDumpAsBitSet() {