Port to OpenBSD

This commit is contained in:
Rupert Carmichael 2021-07-05 17:09:30 -04:00 committed by Screwtapello
parent c2481ac115
commit 52d9bfde94
1 changed files with 24 additions and 0 deletions

View File

@ -85,6 +85,30 @@
#define LIBCO_ASSERT assert #define LIBCO_ASSERT assert
#endif #endif
#if defined (__OpenBSD__)
#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
#include <unistd.h>
#include <sys/mman.h>
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) #if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
#include <stdlib.h> #include <stdlib.h>
#define LIBCO_MALLOC malloc #define LIBCO_MALLOC malloc