1 | Apply Santtu++'s 01_exec_memory_alloc.diff from TT #18. |
---|
2 | |
---|
3 | From: Mark Glines <mark@glines.org> |
---|
4 | |
---|
5 | Updated Infinoid's 01 patch to work in HEAD |
---|
6 | --- |
---|
7 | |
---|
8 | config/gen/platform/generic/memexec.c | 8 +++++--- |
---|
9 | config/gen/platform/openbsd/memexec.c | 6 ++++-- |
---|
10 | config/gen/platform/platform_interface.h | 8 ++++---- |
---|
11 | src/jit.c | 4 ++-- |
---|
12 | src/jit/i386/jit_defs.c | 6 +++--- |
---|
13 | 5 files changed, 18 insertions(+), 14 deletions(-) |
---|
14 | |
---|
15 | |
---|
16 | diff --git a/config/gen/platform/generic/memexec.c b/config/gen/platform/generic/memexec.c |
---|
17 | index 813673c..ebcb911 100644 |
---|
18 | --- a/config/gen/platform/generic/memexec.c |
---|
19 | +++ b/config/gen/platform/generic/memexec.c |
---|
20 | @@ -47,14 +47,16 @@ mem_alloc_executable(size_t size) |
---|
21 | |
---|
22 | /* |
---|
23 | |
---|
24 | -=item C<void mem_free_executable(void *p)> |
---|
25 | +=item C<void mem_free_executable(void *p, size_t)> |
---|
26 | + |
---|
27 | +Free a buffer allocated with mem_alloc_executable(). |
---|
28 | |
---|
29 | =cut |
---|
30 | |
---|
31 | */ |
---|
32 | |
---|
33 | void |
---|
34 | -mem_free_executable(void *p) |
---|
35 | +mem_free_executable(void *p, size_t size) |
---|
36 | { |
---|
37 | free(p); |
---|
38 | } |
---|
39 | @@ -72,7 +74,7 @@ The intermediate temp is required because we don't know the old size |
---|
40 | */ |
---|
41 | |
---|
42 | void * |
---|
43 | -mem_realloc_executable(void* oldp, size_t newsize) |
---|
44 | +mem_realloc_executable(void* oldp, size_t oldsize, size_t newsize) |
---|
45 | { |
---|
46 | void *temp; |
---|
47 | void *newp; |
---|
48 | diff --git a/config/gen/platform/openbsd/memexec.c b/config/gen/platform/openbsd/memexec.c |
---|
49 | index 8488bc2..95bfd3e 100644 |
---|
50 | --- a/config/gen/platform/openbsd/memexec.c |
---|
51 | +++ b/config/gen/platform/openbsd/memexec.c |
---|
52 | @@ -49,14 +49,16 @@ mem_alloc_executable(size_t size) |
---|
53 | |
---|
54 | /* |
---|
55 | |
---|
56 | -=item C<void mem_free_executable(void *p)> |
---|
57 | +=item C<void mem_free_executable(void *p, size_t size)> |
---|
58 | + |
---|
59 | +Free a buffer allocated with mem_alloc_executable(). |
---|
60 | |
---|
61 | =cut |
---|
62 | |
---|
63 | */ |
---|
64 | |
---|
65 | void |
---|
66 | -mem_free_executable(void *p) |
---|
67 | +mem_free_executable(void *p, size_t size) |
---|
68 | { |
---|
69 | free(p); |
---|
70 | } |
---|
71 | diff --git a/config/gen/platform/platform_interface.h b/config/gen/platform/platform_interface.h |
---|
72 | index 9985244..7712ea8 100644 |
---|
73 | --- a/config/gen/platform/platform_interface.h |
---|
74 | +++ b/config/gen/platform/platform_interface.h |
---|
75 | @@ -40,12 +40,12 @@ void Parrot_free_memalign(void *); |
---|
76 | |
---|
77 | #ifdef PARROT_HAS_EXEC_PROTECT |
---|
78 | void *mem_alloc_executable(size_t); |
---|
79 | -void mem_free_executable(void *); |
---|
80 | -void *mem_realloc_executable(void *, size_t); |
---|
81 | +void mem_free_executable(void *, size_t); |
---|
82 | +void *mem_realloc_executable(void *, size_t, size_t); |
---|
83 | #else |
---|
84 | # define mem_alloc_executable mem_sys_allocate |
---|
85 | -# define mem_free_executable mem_sys_free |
---|
86 | -# define mem_realloc_executable mem_sys_realloc |
---|
87 | +# define mem_free_executable(a, b) mem_sys_free(a) |
---|
88 | +# define mem_realloc_executable(a, b, c) mem_sys_realloc((a), (c)) |
---|
89 | #endif |
---|
90 | |
---|
91 | void* Parrot_memcpy_aligned(void*, void*, size_t); |
---|
92 | diff --git a/src/jit.c b/src/jit.c |
---|
93 | index 956ba5c..70756d8 100644 |
---|
94 | --- a/src/jit.c |
---|
95 | +++ b/src/jit.c |
---|
96 | @@ -1257,7 +1257,7 @@ Parrot_destroy_jit(void *ptr) |
---|
97 | } |
---|
98 | /* arena stuff */ |
---|
99 | mem_sys_free(jit_info->arena.op_map); |
---|
100 | - mem_free_executable(jit_info->arena.start); |
---|
101 | + mem_free_executable(jit_info->arena.start, jit_info->arena.size); |
---|
102 | fixup = jit_info->arena.fixups; |
---|
103 | while (fixup) { |
---|
104 | next_f = fixup->next; |
---|
105 | @@ -1525,7 +1525,7 @@ parrot_build_asm(PARROT_INTERP, ARGIN(opcode_t *code_start), ARGIN(opcode_t *cod |
---|
106 | Parrot_jit_extend_arena(jit_info); |
---|
107 | #else |
---|
108 | new_arena = (char *)mem_realloc_executable(jit_info->arena.start, |
---|
109 | - (size_t)jit_info->arena.size * 2); |
---|
110 | + jit_info->arena.size, (size_t)jit_info->arena.size * 2); |
---|
111 | jit_info->arena.size *= 2; |
---|
112 | jit_info->native_ptr = new_arena + |
---|
113 | (jit_info->native_ptr - jit_info->arena.start); |
---|
114 | diff --git a/src/jit/i386/jit_defs.c b/src/jit/i386/jit_defs.c |
---|
115 | index dac55fa..0278a71 100644 |
---|
116 | --- a/src/jit/i386/jit_defs.c |
---|
117 | +++ b/src/jit/i386/jit_defs.c |
---|
118 | @@ -2289,7 +2289,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) |
---|
119 | case '2': |
---|
120 | case '3': |
---|
121 | case '4': |
---|
122 | - mem_free_executable(jit_info.native_ptr); |
---|
123 | + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); |
---|
124 | return NULL; |
---|
125 | break; |
---|
126 | /* This might be right. Or not... */ |
---|
127 | @@ -2306,7 +2306,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) |
---|
128 | * oops unknown signature: |
---|
129 | * cleanup and try nci.c |
---|
130 | */ |
---|
131 | - mem_free_executable(jit_info.native_ptr); |
---|
132 | + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); |
---|
133 | return NULL; |
---|
134 | } |
---|
135 | args_offset +=4; |
---|
136 | @@ -2435,7 +2435,7 @@ Parrot_jit_build_call_func(PARROT_INTERP, PMC *pmc_nci, STRING *signature) |
---|
137 | * oops unknown signature: |
---|
138 | * cleanup and try nci.c |
---|
139 | */ |
---|
140 | - mem_free_executable(jit_info.native_ptr); |
---|
141 | + mem_free_executable(jit_info.native_ptr, JIT_ALLOC_SIZE); |
---|
142 | return NULL; |
---|
143 | } |
---|
144 | |
---|