1 /* -----------------------------------------------------------------------------
3 * (c) The University of Glasgow 2006
5 * OS-specific memory management
7 * ---------------------------------------------------------------------------*/
13 #include <sys/types.h>
16 /* no C99 header stdint.h on OpenBSD? */
17 #if defined(openbsd_HOST_OS)
18 typedef unsigned long my_uintptr_t;
21 typedef uintptr_t my_uintptr_t;
24 lnat getPageSize (void)
26 static lnat pageSize = 0;
31 ret = sysconf(_SC_PAGESIZE);
33 barf("getPageSize: cannot get page size");
39 void setExecutable (void *p, lnat len, rtsBool exec)
41 my_uintptr_t pageSize = getPageSize();
43 /* malloced memory isn't executable by default on OpenBSD */
44 my_uintptr_t mask = ~(pageSize - 1);
45 my_uintptr_t startOfFirstPage = ((my_uintptr_t)p ) & mask;
46 my_uintptr_t startOfLastPage = ((my_uintptr_t)p + len - 1) & mask;
47 my_uintptr_t size = startOfLastPage - startOfFirstPage + pageSize;
48 if (mprotect((void*)startOfFirstPage, (size_t)size,
49 (exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) {
50 barf("makeExecutable: failed to protect 0x%p\n", p);