Skip to content

Fix for core_2gb.test_fs_js_api_wasmfs. NFC #23885

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

Merged
merged 1 commit into from
Mar 11, 2025
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ jobs:
wasm64
core_2gb.test_*em_asm*
core_2gb.test_*embind*
core_2gb.test_fs_js_api_wasmfs
wasm64l.test_hello_world
wasm64l.test_bigswitch
wasm64l.test_module_wasm_memory
Expand Down
8 changes: 6 additions & 2 deletions src/lib/libwasmfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ addToLibrary({
__wasmfs_symlink(stringToUTF8OnStack(target), stringToUTF8OnStack(linkpath))
)),
readlink(path) {
var readBuffer = FS.handleError(withStackSave(() => __wasmfs_readlink(stringToUTF8OnStack(path))));
return UTF8ToString(readBuffer);
return withStackSave(() => {
var bufPtr = stackAlloc({{{ POINTER_SIZE }}});
FS.handleError(__wasmfs_readlink(stringToUTF8OnStack(path), bufPtr));
var readBuffer = {{{ makeGetValue('bufPtr', '0', '*') }}};
return UTF8ToString(readBuffer);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is where a new multi-value ABI could be useful! See WebAssembly/tool-conventions#247

CC @alexcrichton

});
},
statBufToObject(statBuf) {
// i53/u53 are enough for times and ino in practice.
Expand Down
5 changes: 3 additions & 2 deletions system/lib/wasmfs/js_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ int _wasmfs_symlink(const char* old_path, const char* new_path) {
return __syscall_symlinkat((intptr_t)old_path, AT_FDCWD, (intptr_t)new_path);
}

intptr_t _wasmfs_readlink(const char* path) {
int _wasmfs_readlink(const char* path, char** out_ptr) {
static thread_local char* readBuf = (char*)malloc(PATH_MAX);
int bytes =
__syscall_readlinkat(AT_FDCWD, (intptr_t)path, (intptr_t)readBuf, PATH_MAX);
if (bytes < 0) {
return bytes;
}
readBuf[bytes] = '\0';
return (intptr_t)readBuf;
*out_ptr = readBuf;
return 0;
}

int _wasmfs_write(int fd, void* buf, size_t count) {
Expand Down
2 changes: 1 addition & 1 deletion tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ def create_pointer_conversion_wrappers(metadata):
'_emscripten_proxy_dlsync_async': '_pp',
'_emscripten_wasm_worker_initialize': '_p_',
'_wasmfs_rename': '_pp',
'_wasmfs_readlink': 'pp',
'_wasmfs_readlink': '_pp',
'_wasmfs_truncate': '_p_',
'_wasmfs_mmap': 'pp____',
'_wasmfs_munmap': '_pp',
Expand Down