#349 dynrec endianness unsafe access to Segs.val[x]

open
nobody
None
5
2012-09-07
2010-05-14
Michael Buesch
No

The dynrec core performs implicit casts of Segs.val[x] to Bit16u * inside of the MOV_SEG_VAL_TO_HOST_REG macro and the macros used therein.
This breaks on Big-endian, because Segs.val[x] is a Bitu, which is 32bit. So on casting of the pointer to the value we end up accessing the wrong word on big-endian machines.

This is fixed by declaring Segs.val as Bit16u. This gets rid of the the implicit pointer casting.
We could also make the pointer casting endianness-safe in this case, but this requires more intrusive changes. I also don't see an issue with making Segs.val being Bit16u anyway. I think it's a good idea anyway to have Segs.val have an explicit size constraint instead of using the loosely defined Bitu type (which is 32bits in practice, though)

The attached patch is tested on x86 and on PowerPC (to some degree, as I don't have a working PPC dynrec, yet).

Discussion