Skip to content

Commit

Permalink
implement wasi-filesystem::readdir and related functions (bytecodea…
Browse files Browse the repository at this point in the history
…lliance#45)

* implement `wasi-filesystem::readdir` and related functions

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>

* fix memory corruption in `fd_readdir` polyfill

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>

* check type of entry in `Table::delete`

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

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej authored Jan 4, 2023
1 parent 21ba68b commit 359a796
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ pub unsafe extern "C" fn fd_readdir(
state.dirent_cache.cookie.set(cookie - 1);
state.dirent_cache.cached_dirent.set(dirent);
std::ptr::copy(
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,
name.len(),
);
break;
Expand Down

0 comments on commit 359a796

Please sign in to comment.