Apply Santtu++'s 01_exec_memory_alloc.diff from TT #18. From: Mark Glines Updated Infinoid's 01 patch to work in HEAD --- config/gen/platform/generic/memexec.c | 8 +++++--- config/gen/platform/openbsd/memexec.c | 6 ++++-- config/gen/platform/platform_interface.h | 8 ++++---- src/jit.c | 4 ++-- src/jit/i386/jit_defs.c | 6 +++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/config/gen/platform/generic/memexec.c b/config/gen/platform/generic/memexec.c index 813673c..ebcb911 100644 --- a/config/gen/platform/generic/memexec.c +++ b/config/gen/platform/generic/memexec.c @@ -47,14 +47,16 @@ mem_alloc_executable(size_t size) /* -=item C +=item C + +Free a buffer allocated with mem_alloc_executable(). =cut */ void -mem_free_executable(void *p) +mem_free_executable(void *p, size_t size) { free(p); } @@ -72,7 +74,7 @@ The intermediate temp is required because we don't know the old size */ void * -mem_realloc_executable(void* oldp, size_t newsize) +mem_realloc_executable(void* oldp, size_t oldsize, size_t newsize) { void *temp; void *newp; diff --git a/config/gen/platform/openbsd/memexec.c b/config/gen/platform/openbsd/memexec.c index 8488bc2..95bfd3e 100644 --- a/config/gen/platform/openbsd/memexec.c +++ b/config/gen/platform/openbsd/memexec.c @@ -49,14 +49,16 @@ mem_alloc_executable(size_t size) /* -=item C +=item C + +Free a buffer allocated with mem_alloc_executable(). =cut */ void -mem_free_executable(void *p) +mem_free_executable(void *p, size_t size) { free(p); } diff --git a/config/gen/platform/platform_interface.h b/config/gen/platform/platform_interface.h index 9985244..7712ea8 100644 --- a/config/gen/platform/platform_interface.h +++ b/config/gen/platform/platform_interface.h @@ -40,12 +40,12 @@ void Parrot_free_memalign(void *); #ifdef PARROT_HAS_EXEC_PROTECT void *mem_alloc_executable(size_t); -void mem_free_executable(void *); -void *mem_realloc_executable(void *, size_t); +void mem_free_executable(void *, size_t); +void *mem_realloc_executable(void *, size_t, size_t); #else # define mem_alloc_executable mem_sys_allocate -# define mem_free_executable mem_sys_free -# define mem_realloc_executable mem_sys_realloc +# define mem_free_executable(a, b) mem_sys_free(a) +# define mem_realloc_executable(a, b, c) mem_sys_realloc((a), (c)) #endif void* Parrot_memcpy_aligned(void*, void*, size_t); diff --git a/src/jit.c b/src/jit.c index 956ba5c..70756d8 100644 --- a/src/jit.c +++ b/src/jit.c @@ -1257,7 +1257,7 @@ Parrot_destroy_jit(void *ptr) } /* arena stuff */ mem_sys_free(jit_info->arena.op_map); - mem_free_executable(jit_info->arena.start); + mem_free_executable(jit_info->arena.start, jit_info->arena.size); fixup = jit_info->arena.fixups; while (fixup) { next_f = fixup->next; @@ -1525,7 +1525,7 @@ parrot_build_asm(PARROT_INTERP, ARGIN(opcode_t *code_start), ARGIN(opcode_t *cod Parrot_jit_extend_arena(jit_info); #else new_arena = (char *)mem_realloc_executable(jit_info->arena.start, - (size_t)jit_info->arena.size * 2); + jit_info->arena.size, (size_t)jit_info->arena.size * 2); jit_info->arena.size *= 2; jit_info->native_ptr = new_arena + (jit_info->native_ptr - jit_info->arena.start); diff --git a/src/jit/i386/jit_defs.c b/src/jit/i386/jit_defs.c index dac55fa..0278a71 100644 --- a/src/jit/i386/jit_defs.c +++ b/src/jit/i386/jit_defs.c @@ -2289,7 +2289,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) case '2': case '3': case '4': - mem_free_executable(jit_info.native_ptr); + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); return NULL; break; /* This might be right. Or not... */ @@ -2306,7 +2306,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) * oops unknown signature: * cleanup and try nci.c */ - mem_free_executable(jit_info.native_ptr); + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); return NULL; } args_offset +=4; @@ -2435,7 +2435,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) * oops unknown signature: * cleanup and try nci.c */ - mem_free_executable(jit_info.native_ptr); + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); return NULL; }