Skip to content
Merged
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
14 changes: 14 additions & 0 deletions cmake/bindings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,23 @@ add_custom_target(
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.metadata-hash"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.metadata-hash-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.stat"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.stat-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.get-flags"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.open-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.read-directory"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.create-directory-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.remove-directory-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.unlink-file-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.advise"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.sync-data"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.sync"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.set-size"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.symlink-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.link-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.readlink-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.rename-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.set-times-at"
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.set-times"
"--async=-wasi:clocks/monotonic-clock@${wasip3-version}#wait-until"
"--async=-wasi:clocks/monotonic-clock@${wasip3-version}#wait-for"
${CMAKE_SOURCE_DIR}/wasi/p3/wit
Expand Down
2 changes: 2 additions & 0 deletions libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct _DIR {
size_t offset;
#elif defined(__wasip3__)
filesystem_tuple2_stream_directory_entry_future_result_void_error_code_t stream;
bool stream_done;
size_t skip;
size_t offset;
#else
Expand All @@ -53,6 +54,7 @@ static inline void dirent_close_streams(DIR *dirp) {
if (dirp->stream.f0 != 0) {
filesystem_stream_directory_entry_drop_readable(dirp->stream.f0);
dirp->stream.f0 = 0;
dirp->stream_done = false;
}
if (dirp->stream.f1 != 0) {
filesystem_future_result_void_error_code_drop_readable(dirp->stream.f1);
Expand Down
1 change: 1 addition & 0 deletions libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ DIR *fdopendir(int fd) {
dirp->stream = result;
#elif defined(__wasip3__)
filesystem_method_descriptor_read_directory(file_handle, &dirp->stream);
dirp->stream_done = false;
#endif
dirp->fd = fd;
dirp->skip = 0;
Expand Down
15 changes: 9 additions & 6 deletions libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,24 @@ static struct dirent *readdir_next(DIR *dirp) {
#elif defined(__wasip3__)
filesystem_directory_entry_t dir_entry;

// Don't try to keep reading once the stream is closed.
if (dirp->stream_done)
return NULL;

// Loop until at least one stream entry is read, or until the stream is closed.
bool closed = false;
while (1) {
while (!dirp->stream_done) {
size_t amount =
__wasilibc_stream_block_on(
filesystem_stream_directory_entry_read(dirp->stream.f0, &dir_entry, 1),
dirp->stream.f0,
&closed);
&dirp->stream_done);

// If something was read, then break out and process that below.
if (amount > 0)
break;

// If nothing was read and the stream isn't finished yet, try again.
if (!closed)
if (!dirp->stream_done)
continue;

// If the stream's result future hasn't been read yet, do so here.
Expand All @@ -263,8 +266,8 @@ static struct dirent *readdir_next(DIR *dirp) {
translate_error(result.val.err);
}

// The stream is closed, so return NULL. This'll set `errno` based on the
// result of the future above.
// The stream is closed, so return NULL. If `errno` needs to be set it'll
// have been done above with `f1`.
return NULL;
}
#else
Expand Down
8 changes: 1 addition & 7 deletions libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) {

#if defined(__wasip1__)
return __wasi_fd_advise(fd, offset, len, advice);
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
return EBADF;
Expand Down Expand Up @@ -71,12 +71,6 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
return errno;
}
return 0;
#elif defined(__wasip3__)
(void) fd;
(void) advice;
// TODO(wasip3)
errno = ENOTSUP;
return ENOTSUP;
#else
# error "Unsupported WASI version"
#endif
Expand Down
12 changes: 2 additions & 10 deletions libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char
errno = error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptors to internal handles
filesystem_borrow_descriptor_t old_file_handle;
if (fd_to_file_handle(oldfd, &old_file_handle) < 0)
Expand All @@ -30,7 +30,7 @@ int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char
return -1;

// Convert the strings into WASI strings
wasip2_string_t old_path, new_path;
wasi_string_t old_path, new_path;
if (wasi_string_from_c(old, &old_path) < 0)
return -1;
if (wasi_string_from_c(new, &new_path) < 0)
Expand All @@ -47,14 +47,6 @@ int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char
translate_error(error_code);
return -1;
}
#elif defined(__wasip3__)
(void) oldfd;
(void) old;
(void) newfd;
(void) new;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unknown WASI version"
#endif
Expand Down
8 changes: 1 addition & 7 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ int fstat(int fildes, struct stat *buf) {
}
to_public_stat(&internal_stat, buf);
return 0;
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes);
if (!entry)
return -1;
return entry->vtable->fstat(entry->data, buf);
#elif defined(__wasip3__)
(void) fildes;
(void) buf;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
12 changes: 2 additions & 10 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *res
to_public_stat(&internal_stat, buf);

return 0;
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
return -1;

// Convert the string into a Wasm string
wasip2_string_t path_wasm_string;
wasi_string_t path_wasm_string;
if (wasi_string_from_c(path, &path_wasm_string) < 0)
return -1;

Expand Down Expand Up @@ -80,14 +80,6 @@ int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *res
// Convert the internal data to an external struct
to_public_stat(&metadata, &internal_stat, buf);
return 0;
#elif defined(__wasip3__)
(void) fd;
(void) path;
(void) buf;
(void) flag;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
8 changes: 1 addition & 7 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int futimens(int fd, const struct timespec *times) {
errno = error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
Expand All @@ -52,12 +52,6 @@ int futimens(int fd, const struct timespec *times) {
translate_error(error);
return -1;
}
#elif defined(__wasip3__)
(void) fd;
(void) times;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
10 changes: 2 additions & 8 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) {
return -1;
}
return 0;
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
return -1;

// Create the directory
filesystem_error_code_t error;
wasip2_string_t path2;
wasi_string_t path2;
if (wasi_string_from_c(path, &path2) < 0)
return -1;
bool ok = filesystem_method_descriptor_create_directory_at(file_handle,
Expand All @@ -40,12 +40,6 @@ int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) {
return -1;
}
return 0;
#elif defined(__wasip3__)
(void) fd;
(void) path;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
12 changes: 2 additions & 10 deletions libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec t
errno = error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
Expand All @@ -58,7 +58,7 @@ int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec t
lookup_flags |= FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW;

// Convert the string into a Wasm string
wasip2_string_t path_wasm_string;
wasi_string_t path_wasm_string;
if (wasi_string_from_c(path, &path_wasm_string) < 0)
return -1;

Expand All @@ -74,14 +74,6 @@ int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec t
translate_error(error);
return -1;
}
#elif defined(__wasip3__)
(void) fd;
(void) path;
(void) times;
(void) flag;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
10 changes: 2 additions & 8 deletions libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) {
return -1;
}
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fd, &file_handle) < 0)
return -1;

// Convert the string into a WASI string
wasip2_string_t wasi_path;
wasi_string_t wasi_path;
if (wasi_string_from_c(path, &wasi_path) < 0)
return -1;

Expand Down Expand Up @@ -109,12 +109,6 @@ int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) {
return -1;
}
}
#elif defined(__wasip3__)
(void) fd;
(void) path;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
7 changes: 1 addition & 6 deletions libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int fdatasync(int fildes) {
errno = error == ENOTCAPABLE ? EBADF : error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fildes, &file_handle) < 0)
Expand All @@ -31,11 +31,6 @@ int fdatasync(int fildes) {
translate_error(error_code);
return -1;
}
#elif defined(__wasip3__)
(void) fildes;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
7 changes: 1 addition & 6 deletions libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int fsync(int fildes) {
errno = error == ENOTCAPABLE ? EINVAL : error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fildes, &file_handle) < 0)
Expand All @@ -30,11 +30,6 @@ int fsync(int fildes) {
translate_error(error_code);
return -1;
}
#elif defined(__wasip3__)
(void) fildes;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
7 changes: 1 addition & 6 deletions libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int ftruncate(int fildes, off_t length) {
errno = error;
return -1;
}
#elif defined(__wasip2__)
#elif defined(__wasip2__) || defined(__wasip3__)
// Translate the file descriptor to an internal file handle
filesystem_borrow_descriptor_t file_handle;
if (fd_to_file_handle(fildes, &file_handle) < 0)
Expand All @@ -35,11 +35,6 @@ int ftruncate(int fildes, off_t length) {
translate_error(error_code);
return -1;
}
#elif defined(__wasip3__)
(void) fildes;
// TODO(wasip3)
errno = ENOTSUP;
return -1;
#else
# error "Unsupported WASI version"
#endif
Expand Down
Loading