diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-07-15 23:51:42 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-07-15 23:51:42 +0200 |
commit | 5bd047cefa9ffcf17751dbeda1fa56ae56f45199 (patch) | |
tree | e8366eeef4629bc64fa58cebda08bd6cbb10ebc3 /libguile | |
parent | b67cb2864e0de124bd7c4f9b0fda442329e09f3f (diff) | |
download | guile-5bd047cefa9ffcf17751dbeda1fa56ae56f45199.tar.gz |
Fix unaligned access in the VM code.
* libguile/vm.c (struct t_32bit_aligned): New.
(really_make_boot_program)[bytes]: Use it. This fixes possibly
unaligned accesses, which cause a "bus error" on some platforms (e.g.,
sparc-*).
Diffstat (limited to 'libguile')
-rw-r--r-- | libguile/vm.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/libguile/vm.c b/libguile/vm.c index 514ff8d4e..f753ea251 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -227,21 +227,41 @@ static SCM make_u8vector (const scm_t_uint8 *bytes, size_t len) return scm_take_u8vector (new_bytes, len); } +/* Dummy structure to guarantee 32-bit alignment. */ +struct t_32bit_aligned +{ + scm_t_int32 dummy; + scm_t_uint8 bytes[18]; +}; + static SCM really_make_boot_program (long nargs) { - scm_byte_t bytes[] = {0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - scm_op_mv_call, 0, 0, 1, scm_op_make_int8_1, scm_op_halt}; + SCM u8vec; + struct t_32bit_aligned bytes = + { + .dummy = 0, + .bytes = { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + scm_op_mv_call, 0, 0, 1, + scm_op_make_int8_1, scm_op_halt } + }; + SCM ret; - ((scm_t_uint32*)bytes)[1] = 6; /* set len in current endianness, no meta */ + + /* Set length in current endianness, no meta. */ + ((scm_t_uint32 *) bytes.bytes)[1] = 6; + if (SCM_UNLIKELY (nargs > 255 || nargs < 0)) abort (); - bytes[13] = (scm_byte_t)nargs; - ret = scm_make_program (scm_bytecode_to_objcode (make_u8vector (bytes, sizeof(bytes))), + bytes.bytes[13] = (scm_byte_t) nargs; + + u8vec = make_u8vector (bytes.bytes, sizeof (bytes.bytes)); + ret = scm_make_program (scm_bytecode_to_objcode (u8vec), SCM_BOOL_F, SCM_EOL); SCM_SET_SMOB_FLAGS (ret, SCM_F_PROGRAM_IS_BOOT); + return ret; } #define NUM_BOOT_PROGS 8 |