Skip to content

Commit d381a1f

Browse files
authored
wasip3: Improve/fix handling of buffered reads (#793)
This updates the code path that performs a buffered read for a stream when zero-length reads/writes are determined to not signal readiness correctly. Specifically a defensive assertion that this is a nonzero-length read is added and additionally in the case that I/O completes immediately the return code is handled appropriately. Unfortunately I don't know of a way to test this as it's not testable from Wasmtime today and the file streams implementation in Wasmtime ends up sort of accidentally respecting the zero-length protocol (sort of). Thus, for now, this is just a code change until more comprehensive testing such as #766 is implemented.
1 parent 6024e11 commit d381a1f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

libc-bottom-half/sources/file_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ static int wasip3_read_start_nonzero(wasip3_io_state_t *state, size_t length) {
238238
assert(!(state->flags & WASIP3_IO_ZERO_INPROGRESS));
239239
assert(!(state->flags & WASIP3_IO_DONE));
240240
assert(state->buf == NULL);
241+
assert(length);
241242
state->buf = malloc(length);
242243
if (!state->buf) {
243244
errno = ENOMEM;
@@ -252,7 +253,7 @@ static int wasip3_read_start_nonzero(wasip3_io_state_t *state, size_t length) {
252253
errno = EWOULDBLOCK;
253254
return -1;
254255
}
255-
256+
state->buf_end = wasip3_io_update_code(state, status);
256257
return 0;
257258
}
258259

0 commit comments

Comments
 (0)