Skip to content

add serdes API - #94

Closed
tniessen wants to merge 6 commits into
nodejs:masterfrom
tniessen:add-serdes-api
Closed

add serdes API#94
tniessen wants to merge 6 commits into
nodejs:masterfrom
tniessen:add-serdes-api

Conversation

@tniessen

@tniessen tniessen commented Jan 25, 2020

Copy link
Copy Markdown
Member

This implements the first suggestion from #69 plus a few utilities:

  • functions uvwasi_serdes_{read,write}_X,
  • constants UVWASI_SERDES_SIZE_X,
  • macros UVWASI_SERDES_CHECK_BOUNDS(offset, size, X) and UVWASI_SERDES_CHECK_ARRAY_BOUNDS(offset, size, X, count).

Where X is any of fdstat_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 a size_t offset to remove the need for pointer casting and arithmetic on the embedder's size.

TODO:

  • Add expected serialized data to the test case

Fixes: #69

@tniessen tniessen added the enhancement New feature or request label Jan 25, 2020
@tniessen
tniessen requested a review from cjihrig January 25, 2020 22:33
Comment thread include/serdes.h Outdated
Comment thread include/serdes.h Outdated
@tniessen

Copy link
Copy Markdown
Member Author

Thanks Anna, fixed! :)

@cjihrig cjihrig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, and thank you very much for picking this up!

Comment thread include/serdes.h Outdated
Comment thread include/serdes.h Outdated
Comment thread src/serdes.c Outdated
@tniessen

Copy link
Copy Markdown
Member Author

@cjihrig Is this what you had in mind for the scalar types? (I intentionally left out uvwasi_filedelta_t because it makes it unnecessarily complicated, and should never be written to or read from WebAssembly memory.)

@cjihrig

cjihrig commented Jan 26, 2020

Copy link
Copy Markdown
Collaborator

Yes, thank you. LGTM.

Comment thread include/serdes.h
STRUCT(filestat_t)

#define UVWASI_SERDES_SIZE_prestat_t 8
STRUCT(prestat_t)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/serdes.c Outdated
Comment thread include/serdes.h
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl>
@tniessen

tniessen commented Jan 27, 2020

Copy link
Copy Markdown
Member Author

@bnoordhuis If I am not mistaken, these sizes and types are mandated by the WASI C ABI, but @cjihrig will know for sure. UVWASI_SERDES_SIZE_event_t etc. don't actually represent the size required to serialize the data, but to properly align them in an array (e.g., event_t[n] should be laid out using n * UVWASI_SERDES_SIZE_event_t bytes by the C compiler).

Edit: Didn't see #94 (comment).

@cjihrig

cjihrig commented Feb 7, 2020

Copy link
Copy Markdown
Collaborator

@tniessen just checking in - is this just waiting on Add expected serialized data to the test case? No rush, I just wanted to make sure you weren't blocked or anything.

@tniessen

tniessen commented Feb 8, 2020

Copy link
Copy Markdown
Member Author

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.

@tniessen
tniessen marked this pull request as ready for review April 13, 2020 08:09
@tniessen

Copy link
Copy Markdown
Member Author

@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.

@cjihrig

cjihrig commented Apr 15, 2020

Copy link
Copy Markdown
Collaborator

I'll look into using this with the current Node.js integration. If that works, then I'll land this.

cjihrig pushed a commit that referenced this pull request May 14, 2020
This commit adds serialization and deserialization functions
for converting between WASI data structures and WASM memory.

Refs: #69
PR-URL: #94
cjihrig added a commit that referenced this pull request May 14, 2020
UVWASIS --> UVWASI

Refs: #69
Refs: #94
@cjihrig

cjihrig commented May 14, 2020

Copy link
Copy Markdown
Collaborator

Squashed and landed in 306e6fa. Also added support for the newly added uvwasi_size_t in 209edc1, and fixed up some typos in 7c9a5dd.

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.

@cjihrig cjihrig closed this May 14, 2020
This was referenced May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add serdes API

4 participants