Skip to content

Commit c689297

Browse files
committed
wasip3: Implement functions related to removing files/dirs
Gets a few more tests passing
1 parent 2d3a0a5 commit c689297

File tree

7 files changed

+150
-41
lines changed

7 files changed

+150
-41
lines changed

cmake/bindings.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ add_custom_target(
113113
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.metadata-hash"
114114
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.metadata-hash-at"
115115
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.stat"
116+
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.stat-at"
116117
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.get-flags"
117118
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.open-at"
118119
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.read-directory"
120+
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.remove-directory-at"
121+
"--async=-wasi:filesystem/types@${wasip3-version}#[method]descriptor.unlink-file-at"
119122
"--async=-wasi:clocks/monotonic-clock@${wasip3-version}#wait-until"
120123
"--async=-wasi:clocks/monotonic-clock@${wasip3-version}#wait-for"
121124
${CMAKE_SOURCE_DIR}/wasi/p3/wit

libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) {
5555
return -1;
5656
}
5757
}
58-
#elif defined(__wasip2__)
58+
#elif defined(__wasip2__) || defined(__wasip3__)
5959
// Translate the file descriptor to an internal handle
6060
// Translate the file descriptor to an internal handle
6161
filesystem_borrow_descriptor_t file_handle;
6262
if (fd_to_file_handle(fd, &file_handle) < 0)
6363
return -1;
6464

6565
// Convert the string into a WASI string
66-
wasip2_string_t wasi_path;
66+
wasi_string_t wasi_path;
6767
if (wasi_string_from_c(path, &wasi_path) < 0)
6868
return -1;
6969

@@ -109,10 +109,6 @@ int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) {
109109
return -1;
110110
}
111111
}
112-
#elif defined(__wasip3__)
113-
// TODO(wasip3)
114-
errno = ENOTSUP;
115-
return -1;
116112
#else
117113
# error "Unsupported WASI version"
118114
#endif

libc-bottom-half/headers/public/wasi/__generated_wasip3.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libc-bottom-half/sources/__wasilibc_rmdirat.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) {
1515
errno = error;
1616
return -1;
1717
}
18-
#elif defined(__wasip2__)
18+
#elif defined(__wasip2__) || defined(__wasip3__)
1919
// Translate the file descriptor to an internal handle
2020
filesystem_borrow_descriptor_t file_handle;
2121
if (fd_to_file_handle(fd, &file_handle) < 0)
2222
return -1;
2323

2424
// Create a WASI string for the path
25-
wasip2_string_t wasi_path;
25+
wasi_string_t wasi_path;
2626
if (wasi_string_from_c(path, &wasi_path) < 0)
2727
return -1;
2828
filesystem_error_code_t error_code;
@@ -34,10 +34,6 @@ int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) {
3434
translate_error(error_code);
3535
return -1;
3636
}
37-
#elif defined(__wasip3__)
38-
// TODO(wasip3)
39-
errno = ENOTSUP;
40-
return -1;
4137
#else
4238
#error "Unsupported WASI version"
4339
#endif

libc-bottom-half/sources/__wasilibc_unlinkat.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) {
1616
return -1;
1717
}
1818
return 0;
19-
#elif defined(__wasip2__)
19+
#elif defined(__wasip2__) || defined(__wasip3__)
2020
// Translate the file descriptor to an internal handle
2121
descriptor_table_entry_t *entry = descriptor_table_get_ref(fd);
2222
if (!entry)
@@ -33,7 +33,7 @@ int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) {
3333
return -1;
3434

3535
// Create a Wasm string from the path
36-
wasip2_string_t wasi_path;
36+
wasi_string_t wasi_path;
3737
if (wasi_string_from_c(path, &wasi_path) < 0)
3838
return -1;
3939

@@ -47,10 +47,6 @@ int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) {
4747
}
4848

4949
return 0;
50-
#elif defined(__wasip3__)
51-
// TODO(wasip3)
52-
errno = ENOTSUP;
53-
return -1;
5450
#else
5551
#error "Unknown WASI version"
5652
#endif

libc-bottom-half/sources/wasip3.c

Lines changed: 130 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ endfunction()
243243
# TODO: this test fails with `-Sthreads` in Wasmtime since that uses a different
244244
# implementation of WASI which causes this test to fail.
245245
if (NOT TARGET_TRIPLE MATCHES "-threads")
246-
add_wasilibc_test(access.c FS FAILP3)
246+
add_wasilibc_test(access.c FS)
247247
endif()
248248
add_wasilibc_test(append.c FS FAILP3)
249249
add_wasilibc_test(argv_two_args.c ARGV foo bar)
@@ -252,23 +252,23 @@ add_wasilibc_test(chdir.c FS FAILP3)
252252
add_wasilibc_test(close.c FS)
253253
add_wasilibc_test(external_env.c ENV VAR1=foo VAR2=bar)
254254
add_wasilibc_test(fadvise.c FS FAILP3)
255-
add_wasilibc_test(fallocate.c FS FAILP3)
256-
add_wasilibc_test(fcntl.c FS FAILP3)
255+
add_wasilibc_test(fallocate.c FS)
256+
add_wasilibc_test(fcntl.c FS)
257257
add_wasilibc_test(fdatasync.c FS FAILP3)
258-
add_wasilibc_test(fdopen.c FS FAILP3)
258+
add_wasilibc_test(fdopen.c FS)
259259
add_wasilibc_test(feof.c FS)
260-
add_wasilibc_test(file_permissions.c FS FAILP3)
260+
add_wasilibc_test(file_permissions.c FS)
261261
add_wasilibc_test(file_nonblocking.c FS)
262-
add_wasilibc_test(fseek.c FS FAILP3)
262+
add_wasilibc_test(fseek.c FS)
263263
add_wasilibc_test(fstat.c FS FAILP3)
264264
add_wasilibc_test(fsync.c FS FAILP3)
265265
add_wasilibc_test(ftruncate.c FS FAILP3)
266266
add_wasilibc_test(fts.c FS FAILP3)
267267
add_wasilibc_test(fwscanf.c FS)
268268
add_wasilibc_test(getentropy.c)
269269
add_wasilibc_test(hello.c PASS_REGULAR_EXPRESSION "Hello, World!")
270-
add_wasilibc_test(ioctl.c FS FAILP3)
271-
add_wasilibc_test(isatty.c FS FAILP3)
270+
add_wasilibc_test(ioctl.c FS)
271+
add_wasilibc_test(isatty.c FS)
272272
add_wasilibc_test(link.c FS FAILP3)
273273
add_wasilibc_test(lseek.c FS)
274274
add_wasilibc_test(memchr.c LDFLAGS -Wl,--stack-first -Wl,--initial-memory=327680)

0 commit comments

Comments
 (0)