Skip to content

Commit

Permalink
wasi: fix poll_oneoff memory interface
Browse files Browse the repository at this point in the history
The WASM memory interfacing logic was wrong (particularly around
the size of __wasi_subscription_t). This commit fixes the logic.

PR-URL: #33250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
  • Loading branch information
cjihrig authored and codebytere committed Jun 7, 2020
1 parent ed62d43 commit 22f2c2c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/node_wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1455,21 +1455,21 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) {
}

for (uint32_t i = 0; i < nsubscriptions; ++i) {
uvwasi_subscription_t sub = in[i];
wasi->readUInt64(memory, &sub.userdata, in_ptr);
wasi->readUInt8(memory, &sub.type, in_ptr + 8);

if (sub.type == UVWASI_EVENTTYPE_CLOCK) {
wasi->readUInt32(memory, &sub.u.clock.clock_id, in_ptr + 16);
wasi->readUInt64(memory, &sub.u.clock.timeout, in_ptr + 24);
wasi->readUInt64(memory, &sub.u.clock.precision, in_ptr + 32);
wasi->readUInt16(memory, &sub.u.clock.flags, in_ptr + 40);
} else if (sub.type == UVWASI_EVENTTYPE_FD_READ ||
sub.type == UVWASI_EVENTTYPE_FD_WRITE) {
wasi->readUInt32(memory, &sub.u.fd_readwrite.fd, in_ptr + 16);
uvwasi_subscription_t* sub = &in[i];
wasi->readUInt64(memory, &sub->userdata, in_ptr);
wasi->readUInt8(memory, &sub->type, in_ptr + 8);

if (sub->type == UVWASI_EVENTTYPE_CLOCK) {
wasi->readUInt32(memory, &sub->u.clock.clock_id, in_ptr + 16);
wasi->readUInt64(memory, &sub->u.clock.timeout, in_ptr + 24);
wasi->readUInt64(memory, &sub->u.clock.precision, in_ptr + 32);
wasi->readUInt16(memory, &sub->u.clock.flags, in_ptr + 40);
} else if (sub->type == UVWASI_EVENTTYPE_FD_READ ||
sub->type == UVWASI_EVENTTYPE_FD_WRITE) {
wasi->readUInt32(memory, &sub->u.fd_readwrite.fd, in_ptr + 16);
}

in_ptr += 56;
in_ptr += 48;
}

size_t nevents;
Expand Down

0 comments on commit 22f2c2c

Please sign in to comment.