Skip to content
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

executor: add cover protection support to OpenBSD #1215

Merged
merged 1 commit into from Jun 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions executor/executor_bsd.h
Expand Up @@ -10,6 +10,10 @@
#include <sys/types.h>
#include <unistd.h>

#if GOOS_openbsd
#include <sys/sysctl.h>
#endif

static void os_init(int argc, char** argv, void* data, size_t data_size)
{
#if GOOS_openbsd
Expand Down Expand Up @@ -88,6 +92,16 @@ static void cover_protect(cover_t* cov)
if (page_size > 0)
mprotect(cov->data + page_size, mmap_alloc_size - page_size,
PROT_READ);
#elif GOOS_openbsd
int mib[2], page_size;
size_t len;
size_t mmap_alloc_size = kCoverSize * sizeof(uintptr_t);
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
len = sizeof(page_size);
if (sysctl(mib, ARRAY_SIZE(mib), &page_size, &len, NULL, 0) != -1)
mprotect(cov->data + page_size, mmap_alloc_size - page_size,
PROT_READ);
#endif
}

Expand All @@ -96,6 +110,9 @@ static void cover_unprotect(cover_t* cov)
#if GOOS_freebsd
size_t mmap_alloc_size = kCoverSize * KCOV_ENTRY_SIZE;
mprotect(cov->data, mmap_alloc_size, PROT_READ | PROT_WRITE);
#elif GOOS_openbsd
size_t mmap_alloc_size = kCoverSize * sizeof(uintptr_t);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a global const shared with above patch?

mprotect(cov->data, mmap_alloc_size, PROT_READ | PROT_WRITE);
#endif
}

Expand Down