Skip to content

Add CWD handling to standalone WASI mode, and some related syscalls #24247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c606386
Implement `open`/`stat`/`mkdir`/`symlink` for standalone WASI mode
jiixyj May 1, 2025
f696ac8
Add CWD handling to standalone WASI mode, and some related syscalls
jiixyj May 2, 2025
4aad338
test_unistd_cwd test only works in toywasm
jiixyj May 2, 2025
46b7fa4
remove unneeded list comprehension
jiixyj May 2, 2025
16b1925
skip standalone WASM tests when no engines are configured
jiixyj May 2, 2025
e12df0f
update wasmtime version in CI
jiixyj May 2, 2025
65bec88
try to fix 'test_time' and 'test_console_out' tests
jiixyj May 2, 2025
ca3f795
add stubbed out path_filestat_get to libwasi.js
jiixyj May 3, 2025
52a4e03
do preopen handling only in PURE_WASI mode
jiixyj May 3, 2025
53c309b
add path_filestat_get__nothrow: true
jiixyj May 3, 2025
65e8c96
run standalone WASM tests in a subdirectory of 'out/test' for each en…
jiixyj May 3, 2025
5303f12
try to fix CI
jiixyj May 3, 2025
95eab07
refactor to avoid 'allow_wasm_engines' parameter
jiixyj May 3, 2025
bd4a07c
remove hack by adding a stubbed out path_symlink to libwasi.js
jiixyj May 3, 2025
73e982e
Merge remote-tracking branch 'origin/main' into fcntl-open-test
jiixyj May 4, 2025
36e66d8
add attribution to wasi-libc
jiixyj May 4, 2025
cc87f5d
should be wasm_engines instead of self.wasm_engines here
jiixyj May 4, 2025
09b9437
Merge branch 'fcntl-open-test' into cwd-handling
jiixyj May 4, 2025
fbc28fd
add stubbed out fd_readdir to libwasi.js
jiixyj May 4, 2025
fff5c26
don't need this logic in delete_contents anymore
jiixyj May 4, 2025
8bf03f1
implement F_GETFD/F_SETFD/F_GETFL/F_SETFL for WASI standalone mode
jiixyj May 4, 2025
0bb6a3c
Merge branch 'fcntl-standalone' into cwd-handling
jiixyj May 4, 2025
9e7acff
implement readdir for standalone WASM mode
jiixyj May 4, 2025
0d6e4ef
Merge branch 'readdir-standalone' into cwd-handling
jiixyj May 4, 2025
29348a0
don't guard lseek in rewinddir behind ifdef
jiixyj May 4, 2025
2dcdba1
implement fstatat for standalone WASM mode
jiixyj May 4, 2025
257476e
Merge branch 'fstat-standalone' into cwd-handling
jiixyj May 4, 2025
c44c820
remove special case in chdir
jiixyj May 4, 2025
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ jobs:
name: get wasmtime
command: |
# use a pinned version due to https://github.com/bytecodealliance/wasmtime/issues/714
export VERSION=v0.33.0
export VERSION=v32.0.0
wget https://github.com/bytecodealliance/wasmtime/releases/download/$VERSION/wasmtime-$VERSION-x86_64-linux.tar.xz
tar -xf wasmtime-$VERSION-x86_64-linux.tar.xz
cp wasmtime-$VERSION-x86_64-linux/wasmtime ~/vms
Expand Down
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,31 @@ The third_party/ subdirectory contains code with other licenses. None of it is
used by default, but certain options use it (e.g., the optional closure compiler
flag will run closure compiler from third_party/).

Files in system/lib/standalone/ contain code derived from wasi-libc, in
accordance with the terms of the MIT license. wasi-libc's license follows:

"""
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
4 changes: 4 additions & 0 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ sigs = {
fd_pread__sig: 'iippjp',
fd_pwrite__sig: 'iippjp',
fd_read__sig: 'iippp',
fd_readdir__sig: 'iippjp',
fd_seek__sig: 'iijip',
fd_sync__sig: 'ii',
fd_write__sig: 'iippp',
Expand Down Expand Up @@ -1536,6 +1537,9 @@ sigs = {
lineColor__sig: 'ipiiiii',
lineRGBA__sig: 'ipiiiiiiii',
llvm_eh_typeid_for__sig: 'vp',
path_create_directory__sig: 'iipp',
path_filestat_get__sig: 'iiippp',
path_symlink__sig: 'ippipp',
pixelRGBA__sig: 'ipiiiiii',
proc_exit__sig: 'vi',
random_get__sig: 'ipp',
Expand Down
20 changes: 20 additions & 0 deletions src/lib/libwasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,26 @@ var WasiLibrary = {
randomFill(HEAPU8.subarray(buffer, buffer + size));
return 0;
},

path_filestat_get__nothrow: true,
path_filestat_get: (fd, flags, path, path_len, buf) => {
return {{{ cDefs.ENOSYS }}};
},

path_create_directory__nothrow: true,
path_create_directory: (fd, path, path_len) => {
return {{{ cDefs.ENOSYS }}};
},

path_symlink__nothrow: true,
path_symlink: (old_path, old_path_len, fd, new_path, new_path_len) => {
return {{{ cDefs.ENOSYS }}};
},

fd_readdir__nothrow: true,
fd_readdir: (fd, buf, buf_len, cookie, bufused) => {
return {{{ cDefs.ENOSYS }}};
},
};

for (var x in WasiLibrary) {
Expand Down
5 changes: 5 additions & 0 deletions system/lib/libc/musl/src/dirent/seekdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ void seekdir(DIR *dir, long off)
{
LOCK(dir->lock);
dir->tell = lseek(dir->fd, off, SEEK_SET);
#if defined(__EMSCRIPTEN__)
// The above relies on `lseek` to work on a directory fd, which is not
// guaranteed on WASI. Just set `off` again if the above failed.
dir->tell = off;
#endif
dir->buf_pos = dir->buf_end = 0;
UNLOCK(dir->lock);
}
Loading