mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-05 15:10:27 +02:00
Do not pass null for free, memcpy and memmove
* lib/jit_memory.c: Do not call free on NULL pointers. * include/lightning/jit_private.h, lib/jit_note.c, lib/lightning.c: Add a wrapper to memcpy and memmove to not actually call those functions with a zero size argument, and likely also a null src or dst.
This commit is contained in:
parent
a8c180a926
commit
0d9ac79a12
6 changed files with 52 additions and 19 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2014-07-28 Paulo Andrade <pcpa@gnu.org>
|
||||||
|
|
||||||
|
* lib/jit_memory.c: Do not call free on NULL pointers.
|
||||||
|
|
||||||
|
* include/lightning/jit_private.h, lib/jit_note.c,
|
||||||
|
lib/lightning.c: Add a wrapper to memcpy and memmove
|
||||||
|
to not actually call those functions with a zero size
|
||||||
|
argument, and likely also a null src or dst.
|
||||||
|
|
||||||
2014-07-27 Paulo Andrade <pcpa@gnu.org>
|
2014-07-27 Paulo Andrade <pcpa@gnu.org>
|
||||||
|
|
||||||
* include/lightning/jit_private.h, lib/jit_disasm.c,
|
* include/lightning/jit_private.h, lib/jit_disasm.c,
|
||||||
|
|
|
@ -592,6 +592,8 @@ extern void _jit_set_note(jit_state_t*, jit_note_t*, char*, int, jit_int32_t);
|
||||||
#define jit_annotate() _jit_annotate(_jit)
|
#define jit_annotate() _jit_annotate(_jit)
|
||||||
extern void _jit_annotate(jit_state_t*);
|
extern void _jit_annotate(jit_state_t*);
|
||||||
|
|
||||||
|
extern jit_pointer_t jit_memcpy(jit_pointer_t,jit_pointer_t,jit_word_t);
|
||||||
|
extern jit_pointer_t jit_memmove(jit_pointer_t,jit_pointer_t,jit_word_t);
|
||||||
extern void jit_alloc(jit_pointer_t*, jit_word_t);
|
extern void jit_alloc(jit_pointer_t*, jit_word_t);
|
||||||
extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t);
|
extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t);
|
||||||
void jit_free(jit_pointer_t*);
|
void jit_free(jit_pointer_t*);
|
||||||
|
|
|
@ -1750,7 +1750,7 @@ _flush_consts(jit_state_t *_jit)
|
||||||
_jitc->consts.size = _jitc->consts.length << 2;
|
_jitc->consts.size = _jitc->consts.length << 2;
|
||||||
/* FIXME check will not overrun, otherwise, need to reallocate
|
/* FIXME check will not overrun, otherwise, need to reallocate
|
||||||
* code buffer and start over */
|
* code buffer and start over */
|
||||||
memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
|
jit_memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
|
||||||
_jit->pc.w += _jitc->consts.size;
|
_jit->pc.w += _jitc->consts.size;
|
||||||
|
|
||||||
#if DISASSEMBLER
|
#if DISASSEMBLER
|
||||||
|
|
|
@ -38,6 +38,22 @@ static jit_free_func_ptr jit_free_ptr = jit_default_free_func;
|
||||||
/*
|
/*
|
||||||
* Implementation
|
* Implementation
|
||||||
*/
|
*/
|
||||||
|
jit_pointer_t
|
||||||
|
jit_memcpy(jit_pointer_t dst, jit_pointer_t src, jit_word_t size)
|
||||||
|
{
|
||||||
|
if (size)
|
||||||
|
return (memcpy(dst, src, size));
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
jit_pointer_t
|
||||||
|
jit_memmove(jit_pointer_t dst, jit_pointer_t src , jit_word_t size)
|
||||||
|
{
|
||||||
|
if (size)
|
||||||
|
return (memmove(dst, src, size));
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
jit_set_memory_functions(jit_alloc_func_ptr alloc_ptr,
|
jit_set_memory_functions(jit_alloc_func_ptr alloc_ptr,
|
||||||
jit_realloc_func_ptr realloc_ptr,
|
jit_realloc_func_ptr realloc_ptr,
|
||||||
|
@ -82,8 +98,10 @@ jit_realloc(jit_pointer_t *ptr, jit_word_t old_size, jit_word_t new_size)
|
||||||
void
|
void
|
||||||
jit_free(jit_pointer_t *ptr)
|
jit_free(jit_pointer_t *ptr)
|
||||||
{
|
{
|
||||||
(*jit_free_ptr)(*ptr);
|
if (*ptr) {
|
||||||
*ptr = NULL;
|
(*jit_free_ptr)(*ptr);
|
||||||
|
*ptr = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
|
|
@ -126,16 +126,17 @@ _jit_annotate(jit_state_t *_jit)
|
||||||
note->size = _jit->pc.uc - note->code;
|
note->size = _jit->pc.uc - note->code;
|
||||||
|
|
||||||
/* annotations may be very complex with conditions to extend
|
/* annotations may be very complex with conditions to extend
|
||||||
* or ignore redudant notes, as well as add entries to earlier
|
* or ignore redundant notes, as well as add entries to earlier
|
||||||
* notes, so, relocate the information to the data buffer,
|
* notes, so, relocate the information to the data buffer,
|
||||||
* with likely over allocated reserved space */
|
* with likely over allocated reserved space */
|
||||||
|
|
||||||
/* relocate jit_line_t objects */
|
/* relocate jit_line_t objects */
|
||||||
for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
|
for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
|
||||||
note = _jit->note.ptr + note_offset;
|
note = _jit->note.ptr + note_offset;
|
||||||
length = sizeof(jit_line_t) * note->length;
|
if ((length = sizeof(jit_line_t) * note->length) == 0)
|
||||||
|
continue;
|
||||||
assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
|
assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
|
||||||
memcpy(_jitc->note.base, note->lines, length);
|
jit_memcpy(_jitc->note.base, note->lines, length);
|
||||||
jit_free((jit_pointer_t *)¬e->lines);
|
jit_free((jit_pointer_t *)¬e->lines);
|
||||||
note->lines = (jit_line_t *)_jitc->note.base;
|
note->lines = (jit_line_t *)_jitc->note.base;
|
||||||
_jitc->note.base += length;
|
_jitc->note.base += length;
|
||||||
|
@ -149,13 +150,13 @@ _jit_annotate(jit_state_t *_jit)
|
||||||
length = sizeof(jit_int32_t) * line->length;
|
length = sizeof(jit_int32_t) * line->length;
|
||||||
assert(_jitc->note.base + length <
|
assert(_jitc->note.base + length <
|
||||||
_jit->data.ptr + _jit->data.length);
|
_jit->data.ptr + _jit->data.length);
|
||||||
memcpy(_jitc->note.base, line->linenos, length);
|
jit_memcpy(_jitc->note.base, line->linenos, length);
|
||||||
jit_free((jit_pointer_t *)&line->linenos);
|
jit_free((jit_pointer_t *)&line->linenos);
|
||||||
line->linenos = (jit_int32_t *)_jitc->note.base;
|
line->linenos = (jit_int32_t *)_jitc->note.base;
|
||||||
_jitc->note.base += length;
|
_jitc->note.base += length;
|
||||||
assert(_jitc->note.base + length <
|
assert(_jitc->note.base + length <
|
||||||
_jit->data.ptr + _jit->data.length);
|
_jit->data.ptr + _jit->data.length);
|
||||||
memcpy(_jitc->note.base, line->offsets, length);
|
jit_memcpy(_jitc->note.base, line->offsets, length);
|
||||||
jit_free((jit_pointer_t *)&line->offsets);
|
jit_free((jit_pointer_t *)&line->offsets);
|
||||||
line->offsets = (jit_int32_t *)_jitc->note.base;
|
line->offsets = (jit_int32_t *)_jitc->note.base;
|
||||||
_jitc->note.base += length;
|
_jitc->note.base += length;
|
||||||
|
@ -200,10 +201,10 @@ _jit_set_note(jit_state_t *_jit, jit_note_t *note,
|
||||||
(line->length + 17) * sizeof(jit_int32_t));
|
(line->length + 17) * sizeof(jit_int32_t));
|
||||||
}
|
}
|
||||||
if (index < note->length) {
|
if (index < note->length) {
|
||||||
memmove(line->linenos + index + 1, line->linenos + index,
|
jit_memmove(line->linenos + index + 1, line->linenos + index,
|
||||||
sizeof(jit_int32_t) * (line->length - index));
|
sizeof(jit_int32_t) * (line->length - index));
|
||||||
memmove(line->offsets + index + 1, line->offsets + index,
|
jit_memmove(line->offsets + index + 1, line->offsets + index,
|
||||||
sizeof(jit_int32_t) * (line->length - index));
|
sizeof(jit_int32_t) * (line->length - index));
|
||||||
}
|
}
|
||||||
line->linenos[index] = lineno;
|
line->linenos[index] = lineno;
|
||||||
line->offsets[index] = offset;
|
line->offsets[index] = offset;
|
||||||
|
@ -280,8 +281,8 @@ new_line(jit_int32_t index, jit_note_t *note,
|
||||||
(note->length + 17) * sizeof(jit_line_t));
|
(note->length + 17) * sizeof(jit_line_t));
|
||||||
|
|
||||||
if (index < note->length)
|
if (index < note->length)
|
||||||
memmove(note->lines + index + 1, note->lines + index,
|
jit_memmove(note->lines + index + 1, note->lines + index,
|
||||||
sizeof(jit_line_t) * (note->length - index));
|
sizeof(jit_line_t) * (note->length - index));
|
||||||
line = note->lines + index;
|
line = note->lines + index;
|
||||||
++note->length;
|
++note->length;
|
||||||
|
|
||||||
|
|
|
@ -610,7 +610,7 @@ _jit_data(jit_state_t *_jit, jit_pointer_t data,
|
||||||
}
|
}
|
||||||
node->u.w = _jitc->data.offset;
|
node->u.w = _jitc->data.offset;
|
||||||
node->v.w = length;
|
node->v.w = length;
|
||||||
memcpy(_jitc->data.ptr + _jitc->data.offset, data, length);
|
jit_memcpy(_jitc->data.ptr + _jitc->data.offset, data, length);
|
||||||
_jitc->data.offset += length;
|
_jitc->data.offset += length;
|
||||||
|
|
||||||
node->next = _jitc->data.table[key];
|
node->next = _jitc->data.table[key];
|
||||||
|
@ -1722,9 +1722,12 @@ _jit_dataset(jit_state_t *_jit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_jitc->no_data)
|
if (!_jitc->no_data)
|
||||||
memcpy(_jit->data.ptr, _jitc->data.ptr, _jitc->data.offset);
|
jit_memcpy(_jit->data.ptr, _jitc->data.ptr, _jitc->data.offset);
|
||||||
|
|
||||||
if (_jitc->no_note) {
|
if (_jitc->no_note) {
|
||||||
|
/* Space for one note is always allocated, so revert it here
|
||||||
|
* if after jit_new_state was called, it is also requested to
|
||||||
|
* not generate annotation information */
|
||||||
_jit->note.length = 0;
|
_jit->note.length = 0;
|
||||||
_jitc->note.size = 0;
|
_jitc->note.size = 0;
|
||||||
}
|
}
|
||||||
|
@ -2581,7 +2584,7 @@ _simplify_movr(jit_state_t *_jit, jit_node_t *prev, jit_node_t *node,
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (_jitc->values[right].kind == jit_kind_word)
|
if (_jitc->values[right].kind == jit_kind_word)
|
||||||
memcpy(value, _jitc->values + right, sizeof(jit_value_t));
|
jit_memcpy(value, _jitc->values + right, sizeof(jit_value_t));
|
||||||
else {
|
else {
|
||||||
value->kind = jit_kind_register;
|
value->kind = jit_kind_register;
|
||||||
value->base.q.l = right;
|
value->base.q.l = right;
|
||||||
|
@ -2630,14 +2633,14 @@ _simplify_movi(jit_state_t *_jit, jit_node_t *prev, jit_node_t *node,
|
||||||
else
|
else
|
||||||
node->code = jit_code_movr_d;
|
node->code = jit_code_movr_d;
|
||||||
node->v.w = offset;
|
node->v.w = offset;
|
||||||
memcpy(value, _jitc->values + offset, sizeof(jit_value_t));
|
jit_memcpy(value, _jitc->values + offset, sizeof(jit_value_t));
|
||||||
++_jitc->gen[regno];
|
++_jitc->gen[regno];
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value->kind = kind;
|
value->kind = kind;
|
||||||
memcpy(&value->base.w, &node->v.w, size);
|
jit_memcpy(&value->base.w, &node->v.w, size);
|
||||||
++_jitc->gen[regno];
|
++_jitc->gen[regno];
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue