3 * Copyright (C) 2004-2010, Parrot Foundation.
14 Memory protection functions.
24 #ifdef PARROT_HAS_EXEC_PROTECT
27 =item C<void * mem_alloc_executable(size_t size)>
29 Allocate executable memory
30 Round up to page size because the whole page will be marked as executable
31 malloc() under OpenBSD page-aligns allocations >= page size
38 mem_alloc_executable(size_t size
)
41 size_t pagesize
= sysconf(_SC_PAGESIZE
);
42 size
= (size
+ pagesize
- 1) & ~(pagesize
-1);
45 mprotect(p
, size
, PROT_READ
|PROT_WRITE
|PROT_EXEC
);
52 =item C<void mem_free_executable(void *p, size_t size)>
54 Free a buffer allocated with mem_alloc_executable().
61 mem_free_executable(void *p
, size_t size
)
68 =item C<void * mem_realloc_executable(void* oldp, size_t oldsize, size_t
71 Reallocate executable memory
72 Round up to page size because the whole page will be marked as executable
79 mem_realloc_executable(void* oldp
, size_t oldsize
, size_t newsize
)
81 size_t pagesize
= sysconf(_SC_PAGESIZE
);
82 size_t roundup
= (newsize
+ pagesize
- 1) & ~(pagesize
-1);
83 void *newp
= realloc(oldp
, roundup
);
85 mprotect(newp
, roundup
, PROT_READ
|PROT_WRITE
|PROT_EXEC
);
101 * c-file-style: "parrot"
103 * vim: expandtab shiftwidth=4: