1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 21:10:27 +02:00

Add a simple memory management wrapper.

* lib/jit_memory.c: Implement a simple memory allocation wrapper
	to allow overriding calls to malloc/calloc/realloc/free, as well
	as ensuring all memory containing pointers is zero or points to
	allocated memory.

	* include/lightning.h, include/lightning/jit_private.h: Definitions
	for the memory allocation wrapper.

	* lib/Makefile.am: Update for new jit_memory.c file.

	* lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips.c, lib/jit_note.c,
	lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c:
	Use the new memory allocation wrapper code.
This commit is contained in:
pcpa 2013-03-29 12:10:36 -03:00
parent be9068f2ee
commit c39def9dce
13 changed files with 263 additions and 148 deletions

View file

@ -215,11 +215,9 @@ _jit_prolog(jit_state_t *_jit)
jit_regset_set_ui(_jitc->regsav, 0);
offset = _jitc->functions.offset;
if (offset >= _jitc->functions.length) {
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jitc->functions.length + 16) *
sizeof(jit_function_t));
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
16 * sizeof(jit_function_t));
jit_realloc((jit_pointer_t *)&_jitc->functions.ptr,
_jitc->functions.length * sizeof(jit_function_t),
(_jitc->functions.length + 16) * sizeof(jit_function_t));
_jitc->functions.length += 16;
}
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
@ -234,7 +232,8 @@ _jit_prolog(jit_state_t *_jit)
else
_jitc->function->self.aoff = 0;
_jitc->function->self.call = jit_call_default;
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
_jitc->reglen * sizeof(jit_int32_t));
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jitc->function->prolog);
@ -1748,11 +1747,10 @@ _flush_consts(jit_state_t *_jit)
if (_jitc->data_info.ptr) {
if (_jitc->data_info.offset >= _jitc->data_info.length) {
_jitc->data_info.ptr = realloc(_jitc->data_info.ptr,
(_jitc->data_info.length + 1024) *
sizeof(jit_data_info_t));
memset(_jitc->data_info.ptr + _jitc->data_info.length, 0,
1024 * sizeof(jit_data_info_t));
jit_realloc((jit_pointer_t *)&_jitc->data_info.ptr,
_jitc->data_info.length * sizeof(jit_data_info_t),
(_jitc->data_info.length + 1024) *
sizeof(jit_data_info_t));
_jitc->data_info.length += 1024;
}
_jitc->data_info.ptr[_jitc->data_info.offset].code = word;
@ -1796,11 +1794,9 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
assert(!(flag & jit_flag_patch));
kind |= arm_patch_node;
if (_jitc->patches.offset >= _jitc->patches.length) {
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jitc->patches.length + 1024) *
sizeof(jit_patch_t));
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
1024 * sizeof(jit_patch_t));
jit_realloc((jit_pointer_t *)&_jitc->patches.ptr,
_jitc->patches.length * sizeof(jit_patch_t),
(_jitc->patches.length + 1024) * sizeof(jit_patch_t));
_jitc->patches.length += 1024;
}
_jitc->patches.ptr[_jitc->patches.offset].kind = kind;