summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2015-01-12 17:13:20 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2015-01-12 17:13:20 +0000
commit3f4a1150ed1384deacca0cfcc419fdd56bf6ac3d (patch)
treefd7fe7382bc6a4349a0d9fc19a4458760471210f
parent44ecfd34bd80c036b9dfa3503fab669463769f46 (diff)
downloadcompiler-rt-3f4a1150ed1384deacca0cfcc419fdd56bf6ac3d.tar.gz
[asan] Fix uninit in coverage.
pc_fd was not initialized to (-1) on some code paths, resulting in the program erroneously closing stdin when reinitializing coverage. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225637 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/sanitizer_coverage_libcdep.cc36
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
index 2df188da6..0048f6791 100644
--- a/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
@@ -66,6 +66,8 @@ namespace __sanitizer {
class CoverageData {
public:
void Init();
+ void Enable();
+ void Disable();
void ReInit();
void BeforeFork();
void AfterFork(int child_pid);
@@ -150,10 +152,13 @@ void CoverageData::DirectOpen() {
}
void CoverageData::Init() {
+ pc_fd = kInvalidFd;
+}
+
+void CoverageData::Enable() {
CHECK_EQ(pc_array, nullptr);
pc_array = reinterpret_cast<uptr *>(
MmapNoReserveOrDie(sizeof(uptr) * kPcArrayMaxSize, "CovInit"));
- pc_fd = kInvalidFd;
atomic_store(&pc_array_index, 0, memory_order_relaxed);
if (common_flags()->coverage_direct) {
atomic_store(&pc_array_size, 0, memory_order_relaxed);
@@ -184,22 +189,40 @@ void CoverageData::InitializeGuardArray(s32 *guards) {
}
}
-void CoverageData::ReInit() {
+void CoverageData::Disable() {
if (pc_array) {
internal_munmap(pc_array, sizeof(uptr) * kPcArrayMaxSize);
pc_array = nullptr;
}
- if (pc_fd != kInvalidFd) internal_close(pc_fd);
+ if (cc_array) {
+ internal_munmap(cc_array, sizeof(uptr *) * kCcArrayMaxSize);
+ cc_array = nullptr;
+ }
+ if (tr_event_array) {
+ internal_munmap(tr_event_array,
+ sizeof(tr_event_array[0]) * kTrEventArrayMaxSize +
+ GetMmapGranularity());
+ tr_event_array = nullptr;
+ tr_event_pointer = nullptr;
+ }
+ if (pc_fd != kInvalidFd) {
+ internal_close(pc_fd);
+ pc_fd = kInvalidFd;
+ }
+}
+
+void CoverageData::ReInit() {
+ Disable();
if (coverage_enabled) {
if (common_flags()->coverage_direct) {
// In memory-mapped mode we must extend the new file to the known array
// size.
uptr size = atomic_load(&pc_array_size, memory_order_relaxed);
- Init();
+ Enable();
if (size) Extend(size);
if (coverage_enabled) CovUpdateMapping(coverage_dir);
} else {
- Init();
+ Enable();
}
}
// Re-initialize the guards.
@@ -602,7 +625,8 @@ void InitializeCoverage(bool enabled, const char *dir) {
return; // May happen if two sanitizer enable coverage in the same process.
coverage_enabled = enabled;
coverage_dir = dir;
- if (enabled) coverage_data.Init();
+ coverage_data.Init();
+ if (enabled) coverage_data.Enable();
#if !SANITIZER_WINDOWS
if (!common_flags()->coverage_direct) Atexit(__sanitizer_cov_dump);
#endif