From a547defcdc2fffb71a997c3bff70cecbc1572c3d Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Thu, 6 Jun 2019 04:13:28 +0200 Subject: executor: add cover protection support to OpenBSD (#1215) --- executor/executor_bsd.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'executor/executor_bsd.h') diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h index 45d0cfe84..9acd12bb9 100644 --- a/executor/executor_bsd.h +++ b/executor/executor_bsd.h @@ -10,6 +10,10 @@ #include #include +#if GOOS_openbsd +#include +#endif + static void os_init(int argc, char** argv, void* data, size_t data_size) { #if GOOS_openbsd @@ -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 } @@ -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); + mprotect(cov->data, mmap_alloc_size, PROT_READ | PROT_WRITE); #endif } -- cgit mrf-deployment