Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/wasi/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,27 @@ impl File {
advice: system_interface::fs::Advice,
) -> Result<(), ErrorCode> {
use system_interface::fs::FileIoExt as _;
self.run_blocking(move |f| f.advise(offset, len, advice))
.await?;
Ok(())
let is_emulated_willneed = cfg!(any(target_os = "macos", target_os = "ios"))
&& advice == system_interface::fs::Advice::WillNeed;
match self
.run_blocking(move |f| f.advise(offset, len, advice))
.await
{
Err(err) => {
let code: ErrorCode = err.into();

// Paper over a difference in behavior; we implement
// MADV_WILLNEED on macos via the F_RDADVISE fnctl,
// which errors on out-of-bounds ranges whereas POSIX
// silently succeeds.
if is_emulated_willneed && matches!(code, ErrorCode::FileTooLarge) {
return Ok(());
}

Err(code)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this patch to be pretty gross, for a few reasons:

  • advice doesn't implement copy, so it gets moved into the closure; have to check it beforehand, making it less amenable to #[cfg]
  • the whole system error vs errorcode thing; can't match on FileTooLarge directly, only on err.into()
  • ErrorCode doesn't implement PartialEq, so no ==

Any style tips are very welcome.

}
Ok(()) => Ok(()),
}
}

pub(crate) async fn set_size(&self, size: u64) -> Result<(), ErrorCode> {
Expand Down
2 changes: 0 additions & 2 deletions tests/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const KNOWN_FAILURES: &[&str] = &[
"filesystem-read-directory",
// FIXME(#11524)
"remove_directory_trailing_slashes",
#[cfg(target_vendor = "apple")]
"filesystem-advise",
// FIXME(WebAssembly/wasi-testsuite#128)
#[cfg(windows)]
"fd_fdstat_set_rights",
Expand Down
Loading