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.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'executor/executor.cc') diff --git a/executor/executor.cc b/executor/executor.cc index fb73efc5c..704a284a9 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -348,8 +348,16 @@ struct call_t { struct cover_t { int fd; uint32 size; + // mmap_alloc_ptr is the internal pointer to KCOV mapping, possibly with guard pages. + // It is only used to allocate/deallocate the buffer of mmap_alloc_size. + char* mmap_alloc_ptr; uint32 mmap_alloc_size; + // data is the pointer to the kcov buffer containing the recorded PCs. + // data may differ from mmap_alloc_ptr. char* data; + // data_size is set by cover_open(). This is the requested kcov buffer size. + uint32 data_size; + // data_end is simply data + data_size. char* data_end; // Currently collecting comparisons. bool collect_comps; -- cgit mrf-deployment