From 10a9b180ee41f88056b50327fb898dca93a1dbb1 Mon Sep 17 00:00:00 2001 From: dons Date: Mon, 13 Sep 2004 09:19:16 +0000 Subject: [PATCH 1/1] [project @ 2004-09-13 09:19:16 by dons] malloc memory isn't executable by default on OpenBSD, so mprotect pages in execPage for that platform. Enables the FFI. Merge to stable --- ghc/rts/Adjustor.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ghc/rts/Adjustor.c b/ghc/rts/Adjustor.c index 3b93989..bf1002d 100644 --- a/ghc/rts/Adjustor.c +++ b/ghc/rts/Adjustor.c @@ -46,6 +46,11 @@ Haskell side. #include #endif +#if defined(openbsd_TARGET_OS) +#include +#include +#endif + /* Heavily arch-specific, I'm afraid.. */ typedef enum { @@ -79,6 +84,15 @@ execPage (void* addr, pageMode mode) barf("execPage: failed to protect 0x%p; error=%lu; old protection: %lu\n", addr, rc, dwOldProtect); } #else + +#if defined(openbsd_TARGET_OS) + /* malloc memory isn't executable by default on OpenBSD */ + unsigned long pagesize = sysconf(_SC_PAGESIZE); + unsigned long round = (unsigned long)addr & (pagesize - 1); + if (mprotect(addr - round, pagesize, PROT_EXEC|PROT_READ|PROT_WRITE) == -1) + barf("execPage: failed to protect 0x%p\n", addr); +#endif + (void)addr; (void)mode; /* keep gcc -Wall happy */ #endif } -- 1.7.10.4