emitbc: Fix structure field alignment issue.

dummy_data field is accessed as uint value (e.g.
in emit_write_bytecode_byte_ptr), but is not aligned as such, which causes
bus errors or incorrect behavior on any arch requiring strictly aligned
data (ARM pre-v7, MIPS, etc, etc).
pull/747/head
Paul Sokolovsky 2014-07-12 14:51:48 +03:00
rodzic 2097c8b1e1
commit 58c9586c34
1 zmienionych plików z 4 dodań i 1 usunięć

Wyświetl plik

@ -50,7 +50,6 @@
struct _emit_t {
pass_kind_t pass : 8;
uint last_emit_was_return_value : 8;
byte dummy_data[DUMMY_DATA_SIZE];
int stack_size;
@ -67,6 +66,8 @@ struct _emit_t {
uint bytecode_offset;
uint bytecode_size;
byte *code_base; // stores both byte code and code info
// Accessed as uint, so must be aligned as such
byte dummy_data[DUMMY_DATA_SIZE];
};
STATIC void emit_bc_rot_two(emit_t *emit);
@ -207,6 +208,8 @@ STATIC void emit_write_bytecode_byte_ptr(emit_t* emit, byte b, void *ptr) {
emit_write_bytecode_byte(emit, b);
emit_align_bytecode_to_machine_word(emit);
mp_uint_t *c = (mp_uint_t*)emit_get_cur_to_write_bytecode(emit, sizeof(mp_uint_t));
// Verify thar c is already uint-aligned
assert(c == MP_ALIGN(c, sizeof(mp_uint_t)));
*c = (mp_uint_t)ptr;
}