add serdes API - #94
Conversation
Fixes: nodejs#69
ae3518f to
5a04d29
Compare
|
Thanks Anna, fixed! :) |
cjihrig
left a comment
There was a problem hiding this comment.
LGTM, and thank you very much for picking this up!
|
@cjihrig Is this what you had in mind for the scalar types? (I intentionally left out |
|
Yes, thank you. LGTM. |
| STRUCT(filestat_t) | ||
|
|
||
| #define UVWASI_SERDES_SIZE_prestat_t 8 | ||
| STRUCT(prestat_t) |
There was a problem hiding this comment.
UVWASI_SERDES_SIZE_prestat_t doesn't look correct to me. I see that you're serializing u.dir.pr_name_len as a uint32_t but its type is size_t (i.e., 64 bits on 64 bits architectures.)
I suppose that realistically it always fits in a uint32_t but I'd still add some kind of range check.
There was a problem hiding this comment.
I am confused about this part myself. WASI requires it to be a size_t, but I am not sure if that's a host type size_t or a WASM type size_t. Node.js currently uses 32 bits.
There was a problem hiding this comment.
I went with 32 bits because that's what the wasi-libc did here.
Also, according to this ABI doc, size_t is defined as unsigned long, which has a sizeof four, and is represented as a wasm i32.
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl>
|
@bnoordhuis If I am not mistaken, these sizes and types are mandated by the WASI C ABI, but @cjihrig will know for sure. Edit: Didn't see #94 (comment). |
|
@tniessen just checking in - is this just waiting on |
|
Yes, I would like to check the serialized outputs against known correct serializations. I just don't have that data at hand, I guess I'll have to compile some WASI code to WebAssembly and then extract the data from memory. |
|
@cjihrig I lost access to the machine that I worked on this PR on :( I am switching this to "ready for review" so you can merge it if you feel like it (or if anyone else wants to improve the unit tests). I don't know when I will find time to re-do this myself. |
|
I'll look into using this with the current Node.js integration. If that works, then I'll land this. |
|
Squashed and landed in 306e6fa. Also added support for the newly added I integrated this with Node.js locally, and everything seemed to work. I'm going to leave #69 open though, as there are a couple missing pieces left to address. Thanks for the PR Tobias, and thanks for the reviews Anna and Ben. |
This implements the first suggestion from #69 plus a few utilities:
uvwasi_serdes_{read,write}_X,UVWASI_SERDES_SIZE_X,UVWASI_SERDES_CHECK_BOUNDS(offset, size, X)andUVWASI_SERDES_CHECK_ARRAY_BOUNDS(offset, size, X, count).Where
Xis any offdstat_t,filestat_t,prestat_t,event_t,subscription_t,uint8_t,uint16_t,uint32_t,uint64_t.The read/write functions take a const-correct
void*base pointer and asize_toffset to remove the need for pointer casting and arithmetic on the embedder's size.TODO:
Fixes: #69