diff options
| author | Alexander Potapenko <glider@google.com> | 2025-08-01 12:12:42 +0200 |
|---|---|---|
| committer | Alexander Potapenko <glider@google.com> | 2025-08-05 13:16:45 +0000 |
| commit | 77ff614fa0319f7b4e99df29822d0590128bf00c (patch) | |
| tree | 8103f61472890a7b8f9eaf417b3f185fa0d1c537 /executor/executor_test.h | |
| parent | 0931f9bfa8eacf9840a2bd3f9def3cfb4349431e (diff) | |
executor: decouple kcov memory allocation from the trace
On different platforms and in different coverage collection modes
the pointer to the beginning of kcov buffer may or may not differ
from the pointer to the region that mmap() returned.
Decouple these two pointers, so that the memory is always allocated
and deallocated with cov->mmap_alloc_ptr and cov->mmap_alloc_size, and the
buffer is accessed via cov->data and cov->data_size.
I tried my best to not break Darwin and BSD, but I did not test them.
Diffstat (limited to 'executor/executor_test.h')
| -rw-r--r-- | executor/executor_test.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/executor/executor_test.h b/executor/executor_test.h index e2a2002bb..d8471e6b5 100644 --- a/executor/executor_test.h +++ b/executor/executor_test.h @@ -75,7 +75,7 @@ static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs]) static void cover_open(cover_t* cov, bool extra) { - cov->mmap_alloc_size = kCoverSize * sizeof(unsigned long); + cov->data_size = kCoverSize * sizeof(unsigned long); } static void cover_enable(cover_t* cov, bool collect_comps, bool extra) @@ -102,14 +102,16 @@ static void cover_protect(cover_t* cov) static void cover_mmap(cover_t* cov) { - if (cov->data != NULL) + if (cov->mmap_alloc_ptr != NULL) fail("cover_mmap invoked on an already mmapped cover_t object"); - if (cov->mmap_alloc_size == 0) + if (cov->data_size == 0) fail("cover_t structure is corrupted"); - cov->data = (char*)mmap(NULL, cov->mmap_alloc_size, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (cov->data == MAP_FAILED) + cov->mmap_alloc_size = cov->data_size; + cov->mmap_alloc_ptr = (char*)mmap(NULL, cov->mmap_alloc_size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + if (cov->mmap_alloc_ptr == MAP_FAILED) exitf("cover mmap failed"); + cov->data = cov->mmap_alloc_ptr; cov->data_end = cov->data + cov->mmap_alloc_size; cov->data_offset = is_kernel_64_bit ? sizeof(uint64_t) : sizeof(uint32_t); // We don't care about the specific PC values for now. @@ -125,9 +127,9 @@ static long inject_cover(cover_t* cov, long a, long b) { if (cov->data == nullptr) return ENOENT; - uint32 size = std::min((uint32)b, cov->mmap_alloc_size); + uint32 size = std::min((uint32)b, cov->data_size); memcpy(cov->data, (void*)a, size); - memset(cov->data + size, 0xcd, std::min<uint64>(100, cov->mmap_alloc_size - size)); + memset(cov->data + size, 0xcd, std::min<uint64>(100, cov->data_size - size)); return 0; } |
