From 77ff614fa0319f7b4e99df29822d0590128bf00c Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Fri, 1 Aug 2025 12:12:42 +0200 Subject: 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. --- executor/executor_darwin.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'executor/executor_darwin.h') diff --git a/executor/executor_darwin.h b/executor/executor_darwin.h index bb7956c20..d555eeb02 100644 --- a/executor/executor_darwin.h +++ b/executor/executor_darwin.h @@ -73,7 +73,7 @@ static void cover_open(cover_t* cov, bool extra) 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"); uintptr_t mmap_ptr = 0; if (ksancov_map(cov->fd, &mmap_ptr, &cov->mmap_alloc_size)) @@ -84,6 +84,7 @@ static void cover_mmap(cover_t* cov) if (cov->mmap_alloc_size > kCoverSize) fail("mmap allocation size larger than anticipated"); + cov->mmap_alloc_ptr = (char*)mmap_ptr; cov->data = (char*)mmap_ptr; cov->data_end = cov->data + cov->mmap_alloc_size; } -- cgit mrf-deployment