diff options
author | Stephen Crane <sjc@immunant.com> | 2021-01-13 14:05:41 -0800 |
---|---|---|
committer | Stephen Crane <sjc@immunant.com> | 2021-01-13 16:09:31 -0800 |
commit | 6bd77df8fc37c0633388aede21a0c6beffcc835c (patch) | |
tree | b4657a2216a4e3606a16e0ad38aeedd41cf6b9e2 /trusty/coverage/coverage.cpp | |
parent | 0d67131dd967de4db19ec69874ae4e855e176018 (diff) |
trusty: Write out sancov file when fuzzer exits
Add emission of sancov file when CoverageRecord is destroyed. This
will occur when a fuzzer driver exits cleanly, i.e. -runs=0 with an
existing corpus.
Test: make trusty_gatekeeper_fuzzer
Test: adb shell ./trusty_gatekeeper_fuzzer -runs=0 corpus
Bug: 175221942
Change-Id: I6bd1c8b2f2091e894c35f7a4874b54577a91c8fc
Diffstat (limited to 'trusty/coverage/coverage.cpp')
-rw-r--r-- | trusty/coverage/coverage.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/trusty/coverage/coverage.cpp b/trusty/coverage/coverage.cpp index ff2bcaa11..185abe549 100644 --- a/trusty/coverage/coverage.cpp +++ b/trusty/coverage/coverage.cpp @@ -21,6 +21,7 @@ #include <android-base/logging.h> #include <android-base/unique_fd.h> #include <assert.h> +#include <log/log.h> #include <stdio.h> #include <sys/mman.h> #include <sys/uio.h> @@ -38,6 +39,7 @@ namespace coverage { using android::base::ErrnoError; using android::base::Error; using std::string; +using std::unique_ptr; static inline uintptr_t RoundPageUp(uintptr_t val) { return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); @@ -47,12 +49,29 @@ CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid) : tipc_dev_(std::move(tipc_dev)), coverage_srv_fd_(-1), uuid_(*uuid), + sancov_filename_(), + record_len_(0), + shm_(NULL), + shm_len_(0) {} + +CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid, string sancov_filename) + : tipc_dev_(std::move(tipc_dev)), + coverage_srv_fd_(-1), + uuid_(*uuid), + sancov_filename_(sancov_filename), record_len_(0), shm_(NULL), shm_len_(0) {} CoverageRecord::~CoverageRecord() { if (shm_) { + if (sancov_filename_) { + auto res = SaveSancovFile(*sancov_filename_); + if (!res.ok()) { + ALOGE("Could not write sancov file for module: %s\n", sancov_filename_->c_str()); + } + } + munmap((void*)shm_, shm_len_); } } |