Fix WASI fd_readdir on big-endian - #3016
Conversation
Subscribe to Label Actioncc @kubkon DetailsThis issue or pull request has been labeled: "wasi"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
alexcrichton
left a comment
There was a problem hiding this comment.
This is definitely a preexisting bug in wiggle that it never tried to handle endidanness, and this is something that we'll ideally be fixing at the bindings generation layer since in general host-code shouldn't have to care about endianness. I suspect this isn't the last endian bug in the WASI bindings, but I'm hoping that we can survive long enough to get to the point where we can properly fix this.
FWIW the semi-replacement of wiggle (more like the next stage in evolution) at https://github.com/bytecodealliance/witx-bindgen/ should fix issues like this.
| let guest_dirent = types::Dirent { | ||
| d_ino: dirent.d_ino.to_le(), | ||
| d_namlen: dirent.d_namlen.to_le(), | ||
| d_type: dirent.d_type, // endian-invariant |
There was a problem hiding this comment.
Could this assert that the size of this field is 1 so the endianness is known to not matter?
There was a problem hiding this comment.
Like this? Patch updated.
This code assumes that the Dirent structure has the same memory layout on the host (Rust code) as in wasm code. This is not true if the host is big-endian, as wasm is always little-endian. Fixed by always byte-swapping Dirent fields to little-endian before passing them on to wasm code.
e9a30a8 to
7167df0
Compare
|
👍 |
This code assumes that the Dirent structure has the same memory
layout on the host (Rust code) as in wasm code. This is not true
if the host is big-endian, as wasm is always little-endian.
Fixed by always byte-swapping Dirent fields to little-endian
before passing them on to wasm code.