Skip to content

executor: fix cover_protect() on FreeBSD #5799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions executor/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,13 @@ class CoverAccessScope final
if (used_)
fail("recursion in CoverAccessScope");
used_ = true;
cover_unprotect(cov_);
if (flag_coverage)
cover_unprotect(cov_);
}
~CoverAccessScope()
{
cover_protect(cov_);
if (flag_coverage)
cover_protect(cov_);
used_ = false;
}

Expand Down
4 changes: 4 additions & 0 deletions executor/executor_bsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static void cover_mmap(cover_t* cov)

static void cover_protect(cover_t* cov)
{
if (cov->data == NULL)
fail("cover_protect invoked on an unmapped cover_t object");
#if GOOS_freebsd
size_t mmap_alloc_size = kCoverSize * KCOV_ENTRY_SIZE;
long page_size = sysconf(_SC_PAGESIZE);
Expand All @@ -139,6 +141,8 @@ static void cover_protect(cover_t* cov)

static void cover_unprotect(cover_t* cov)
{
if (cov->data == NULL)
fail("cover_unprotect invoked on an unmapped cover_t object");
#if GOOS_freebsd
size_t mmap_alloc_size = kCoverSize * KCOV_ENTRY_SIZE;
mprotect(cov->data, mmap_alloc_size, PROT_READ | PROT_WRITE);
Expand Down