+foreign import ccall "static stdlib.h"
+ memalign :: CUInt -> CUInt -> IO (Ptr a)
+
+foreign import ccall "static sys/mman.h"
+ mprotect :: CUInt -> CUInt -> Int -> IO Int
+
+mallocExecBytes :: Int -> IO (Ptr a)
+mallocExecBytes size' = do
+ arr <- memalign 0x1000 size
+ -- 0x7 = PROT_{READ,WRITE,EXEC}
+ _ <- mprotect (fromIntegral $ ptrToIntPtr arr) size 0x7
+ return arr
+ where size = fromIntegral size'
+