Peter Gibbs <[EMAIL PROTECTED]> wrote:
>   Log:
>   Prevent attempts to reallocate mmap'd executable memory until somebody
>     works out how to do it.

For linux/fedora, I'd go with this scheme:

- mem_alloc_executable uses valloc() that is memalign(getpagesize(),
    size) with size rounded up to the next page size.
- mem_realloc_executable tries to realloc the memory region, and if
    a different (unaligned) pointer is returned, then valloc(), memcpy and
    free old.
- mem_prepare_executable (called after the code is prepared and before
    execution starts, does mprotect(p, n, PROT_EXEC|PROT_READ) on fedora
    or flush these memory region on ARM and PPC.
- mem_free_executable is just free - the current also has a missing
  (wrong) length argument.

And finally generic platforms that don't have this executable protection
just map these function to the plain allocation functions.

The current mmap() approach is probably not suited for allocating a lot
of different small code pieces, there is for sure some OS limit. This
scheme is probably only usable as base for an own allocator.

I'll check in a test if malloced memory is executable RSN.

leo

Reply via email to