Samsung / walrus

WebAssembly Lightweight RUntime
Apache License 2.0
35 stars 10 forks source link

Fix unaligned memory access in Interp on ARM32 #226

Closed GorogPeter closed 4 months ago

GorogPeter commented 4 months ago

Walrus Interp uses reinterpret_cast for data movement in load and store instructions. On ARM32, if the size of the data to be moved is 8 bytes, then compiler generates LDRD and STRD instructions. Address for these instructions has to be word-aligned, whilst Walrus has to support non-aligned data movement.

To achieve this, Walrus now uses memcpyEndianAware function for moving 8 byte-long data (int64, uint64 and double) in Interp on ARM32. This function generates two LDR and two STR instructions that can cope with non-aligned addresses.

Moreover, memory.wast test has been improved in order to check unaligned memory access.

Unfortunately Qemu-arm doesn't care about memory alignment, therefor it won't cause BUS ERROR (but it does occure on arm hardware).

GorogPeter commented 4 months ago

Don't merge! I've found some errors.

GorogPeter commented 4 months ago

Nevermind. Problem solved. (It was a local problem.)