-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix WASI fd_readdir on big-endian #3016
Conversation
Subscribe to Label Actioncc @kubkon
This 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.