Leopold Toetsch wrote: > So we need: > > 1) a config test/option/whatever (e.g. mallocing some mem, fill in a > "ret" instruction and call that. > 2) Some means to allocate executable memory. > > Could you please have a look at fedora (kernel) docs?
There are two ways to flag memory as executable: 1) A flag to mmap 2) Calling mprotect after the memory has been allocated The second method is POSIX-compliant only when used with mmap'd memory. It does however work with malloc'd memory under Linux, with the caveat that if the memory is released and reallocated (within the same process), the executable flag remains set. As a quick test, I added the following to src/jit.c (based on 'man mprotect'): jit_info->native_ptr = jit_info->arena.start = mem_sys_allocate_zeroed((size_t)jit_info->arena.size); { #include <limits.h> /* for PAGESIZE */ #ifndef PAGESIZE #define PAGESIZE 4096 #endif char *p = (char *)((int) jit_info->native_ptr & ~(PAGESIZE-1)); size_t len = ((int) jit_info->native_ptr + jit_info->arena.size - (int)p); mprotect(p, len, PROT_READ|PROT_WRITE|PROT_EXEC); } With this addition, parrot -j runs without segfaulting, so the above could be used as a basis for a mem_alloc_executable function. Note that the pointer passed to mprotect must start on a PAGESIZE boundary, so we get some area of memory marked executable when it need not be. I don't think we need to check whether exec-shield is active, only that there is an mprotect function with the appropriate attribute constants. Regards Peter Gibbs EmKel Systems