Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

implement wasi-filesystem::readdir and related functions #45

Merged
merged 3 commits into from
Jan 4, 2023

Conversation

dicej
Copy link
Collaborator

@dicej dicej commented Jan 3, 2023

This adds a directory_list test and provides the required host implementation.

I've also added a file length check to the file_read test, just to cover a bit more of the API.

Signed-off-by: Joel Dice joel.dice@fermyon.com

This adds a `directory_list` test and provides the required host implementation.

I've also added a file length check to the `file_read` test, just to cover a bit
more of the API.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej requested a review from sunfishcode January 3, 2023 21:26
@dicej
Copy link
Collaborator Author

dicej commented Jan 3, 2023

Hmm... tests are passing with cargo +nightly but not with stable -- will investigate.

We were copying `name.len() * 256` bytes instead of just `name.len()` bytes,
which was overwriting other parts of `State` and causing untold havoc.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej
Copy link
Collaborator Author

dicej commented Jan 3, 2023

Ah, debugging memory corruption without a debugger -- just like the good old days of C++ on weird platforms. At least it was deterministic this time.

host/src/filesystem.rs Outdated Show resolved Hide resolved
name.as_ptr().cast(),
(*state.dirent_cache.path_data.get()).as_mut_ptr(),
name.as_ptr().cast::<u8>(),
(*state.dirent_cache.path_data.get()).as_mut_ptr() as *mut u8,
Copy link
Member

Choose a reason for hiding this comment

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

Can this use .cast instead of as?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cast yields a *const T, not a *mut T. I tried using a combination of cast and cast_mut, but the compiler claims it can't find the latter method at all even though I seem to be using a recent enough version of Rust. 🤷

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants