-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[WasmFS] Fix FS.readFile + WASM_BIGINT #17316
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
Changes from all commits
4f6b0a5
567cfd3
adc486a
c464b53
638c30d
f19dcad
04c373f
15112a4
8efae3e
19f049a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ __wasi_fd_t wasmfs_create_file(char* pathname, mode_t mode, backend_t backend); | |
| // The buffer will also contain the file length. | ||
| // Caller must free the returned pointer. | ||
| void* _wasmfs_read_file(char* path) { | ||
| static_assert(sizeof(off_t) == 8, "File offset type must be 64-bit"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this assert here.. I'm pretty sure if this ever changed all kind of stuff would break.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly the assert is a little redundant, but it's static so no overhead, and also it is helpful for the reader, I think, as it indicates this is a contract with the JS side that must not change. |
||
|
|
||
| struct stat file; | ||
| int err = 0; | ||
| err = stat(path, &file); | ||
|
|
@@ -34,8 +36,8 @@ void* _wasmfs_read_file(char* path) { | |
| // first 8 bytes. The remaining bytes will contain the buffer contents. This | ||
| // allows the caller to use HEAPU8.subarray(buf + 8, buf + 8 + length). | ||
| off_t size = file.st_size; | ||
| uint8_t* result = (uint8_t*)malloc((size + sizeof(size))); | ||
| *(uint32_t*)result = size; | ||
| uint8_t* result = (uint8_t*)malloc(size + sizeof(size)); | ||
| *(off_t*)result = size; | ||
|
|
||
| int fd = open(path, O_RDONLY); | ||
| if (fd < 0) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| Success | ||
|
|
||
| Length: 8 | ||
| Fatal error in FS.readFile | ||
| Aborted(native code called abort()) | ||
| Fatal error in FS.readFile | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already have another use of this in #17459 !