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
2 changes: 1 addition & 1 deletion src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ function wrapSyscallFunction(x, library, isWasi) {
post = handler + post;

if (pre || post) {
t = modifyJSFunction(t, (args, body) => `function (${args}) {\n${pre}${body}${post}}\n`);
t = modifyJSFunction(t, (args, body, async_) => `${async_}function (${args}) {\n${pre}${body}${post}}\n`);
}

library[x] = eval('(' + t + ')');
Expand Down
23 changes: 14 additions & 9 deletions src/lib/libwasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,27 +540,32 @@ var WasiLibrary = {
return 0;
},

#if SYSCALLS_REQUIRE_FILESYSTEM
fd_sync__async: 'auto',
fd_sync: (fd) => {
#if SYSCALLS_REQUIRE_FILESYSTEM
var stream = SYSCALLS.getStreamFromFD(fd);
var rtn = stream.stream_ops?.fsync?.(stream);
#if ASYNCIFY
var mount = stream.node.mount;
if (mount.type.syncfs) {
return new Promise((resolve) => {
#if ASYNCIFY || PTHREADS
return new Promise((resolve) => {
var mount = stream.node.mount;
if (mount?.type.syncfs) {
mount.type.syncfs(mount, false, (err) => resolve(err ? {{{ cDefs.EIO }}} : 0));
});
}
#endif // ASYNCIFY
} else {
resolve(rtn);
}
});
#else
return rtn;
#endif // ASYNCIFY || PTHREADS
},
#else // SYSCALLS_REQUIRE_FILESYSTEM
fd_sync: (fd) => {
#if ASSERTIONS
abort('fd_sync called without SYSCALLS_REQUIRE_FILESYSTEM');
#endif
return {{{ cDefs.ENOSYS }}};
#endif // SYSCALLS_REQUIRE_FILESYSTEM
},
#endif // SYSCALLS_REQUIRE_FILESYSTEM

// random.h

Expand Down
5 changes: 3 additions & 2 deletions test/fs/test_memfs_fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ int main() {
struct stat st;

// a file whose contents are just 'az'
rtn = stat("/wakaka.txt", &st);
rtn = stat("wakaka.txt", &st);
assert(rtn == -1 && errno == ENOENT);

fd = open("/wakaka.txt", O_RDWR | O_CREAT, 0666);
fd = open("wakaka.txt", O_RDWR | O_CREAT, 0666);
assert(fd >= 0);

rtn = write(fd, "az", 2);
Expand All @@ -38,5 +38,6 @@ int main() {
rtn = close(fd);
assert(rtn == 0);

printf("success\n");
return 0;
}
12 changes: 11 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
also_with_asan,
also_with_minimal_runtime,
also_with_modularize,
also_with_nodefs_both,
also_with_noderawfs,
also_with_standalone_wasm,
also_with_wasm2js,
Expand Down Expand Up @@ -5525,7 +5526,16 @@ def test_dashM_respect_dashO(self):
@with_all_fs
@crossplatform
def test_fs_bad_lookup(self):
self.do_runf(path_from_root('test/fs/test_fs_bad_lookup.c'), expected_output='ok')
self.do_runf('fs/test_fs_bad_lookup.c', 'ok')

@also_with_nodefs_both
@crossplatform
@parameterized({
'': ([],),
'pthreads': (['-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],),
})
def test_fsync(self, args):
self.do_runf('fs/test_memfs_fsync.c', 'success', cflags=args)

@with_all_fs
@crossplatform
Expand Down