Stream: git-wasmtime

Topic: wasmtime / PR #2384 Fix WasmTy/WasmRet on big-endian hosts


view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 16:29):

uweigand opened PR #2384 from endian-funcargs to main:

When invoking a WebAssembly routine from Rust code, arguments
are stored into an array of u128, and read from a piece of
generated trampoline code before calling the compiled target
function using the platform ABI calling convention.

The WasmTy/WasmRet routines handle the conversion between Rust
data types and those u128 buffers. This currently works by
in effect converting the Rust object to a u128 and then storing
this u128 into the buffer. The generated trampoline code will
then read an object of appropriate type from the beginning of
that buffer.

This does not work on big-endian platforms, since the above
approach causes the value to be stored into the rightmost
bytes of the u128 buffer, while the trampoline code reads
the leftmost bytes.

This patch fixes the problem by changing WasmTy/WasmRet to
use the leftmost bytes as well, by casting the u128 pointer
to a pointer of the correct type before storing to it (or
reading from it).

(Note that it is not necessary to actually byte-swap the
values since the trampoline code will not treat them like
WebAssembly little-endian memory, but simply access them
in native byte order.)

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 16:38):

alexcrichton submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 17:14):

alexcrichton merged PR #2384.


Last updated: Dec 23 2024 at 12:05 UTC