From 52d9bfde9428c26a0593a3a55d079ac2149d34c6 Mon Sep 17 00:00:00 2001 From: Rupert Carmichael <5050061-carmiker@users.noreply.gitlab.com> Date: Mon, 5 Jul 2021 17:09:30 -0400 Subject: [PATCH] Port to OpenBSD --- settings.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/settings.h b/settings.h index 8dbcec5a..48d6c39d 100644 --- a/settings.h +++ b/settings.h @@ -85,6 +85,30 @@ #define LIBCO_ASSERT assert #endif +#if defined (__OpenBSD__) + #if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #include + + static void* malloc_obsd(size_t size) { + long pagesize = sysconf(_SC_PAGESIZE); + char* memory = (char*)mmap(NULL, size + pagesize, PROT_READ|PROT_WRITE, MAP_STACK|MAP_PRIVATE|MAP_ANON, -1, 0); + if (memory == MAP_FAILED) return NULL; + *(size_t*)memory = size + pagesize; + memory += pagesize; + return (void*)memory; + } + + static void free_obsd(void *ptr) { + char* memory = (char*)ptr - sysconf(_SC_PAGESIZE); + munmap(memory, *(size_t*)memory); + } + + #define LIBCO_MALLOC malloc_obsd + #define LIBCO_FREE free_obsd + #endif +#endif + #if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) #include #define LIBCO_MALLOC malloc