From 16fbfbe152ff14247e0c6be9b38a8dcea5b6cef0 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 30 Jan 2023 15:52:09 -0500 Subject: [PATCH] wasi: add wasi sock_accept stub Refs: https://github.com/nodejs/uvwasi/pull/185 Add stub for sock_accept so that we have stubs for all of the sock methods in wasi_snapshot_preview1. Its a bit awkward as the method was added after the initial definitial of wasi_snapshot-preview1 but I think it should be semver minor at most to add the method. Depends on https://github.com/nodejs/uvwasi/pull/185 being landed in uvwasi first and an updated version of uvwasi that includes that being pulled into Node.js Signed-off-by: Michael Dawson --- src/node_wasi.cc | 16 ++++++++++++++++ src/node_wasi.h | 1 + test/wasi/c/sock.c | 17 +++++++++++++++++ test/wasi/test-wasi.js | 1 + test/wasi/wasm/sock.wasm | Bin 0 -> 18983 bytes 5 files changed, 35 insertions(+) create mode 100644 test/wasi/c/sock.c create mode 100755 test/wasi/wasm/sock.wasm diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 5d7f5a4dff50ec6..5c8679b3f242b50 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -1234,6 +1234,21 @@ uint32_t WASI::SockShutdown(WASI& wasi, return uvwasi_sock_shutdown(&wasi.uvw_, sock, how); } +uint32_t WASI::SockAccept(WASI& wasi, + WasmMemory memory, + uint32_t sock, + uint32_t flags, + uint32_t fd_ptr) { + Debug(wasi, "sock_accept(%d, %d, %d)\n", sock, flags, fd_ptr); + uvwasi_fd_t fd; + uvwasi_errno_t err = uvwasi_sock_accept(&wasi.uvw_, sock, flags, &fd); + + if (err == UVWASI_ESUCCESS) + uvwasi_serdes_write_size_t(memory.data, fd_ptr, fd); + + return err; +} + void WASI::_SetMemory(const FunctionCallbackInfo& args) { WASI* wasi; ASSIGN_OR_RETURN_UNWRAP(&wasi, args.This()); @@ -1306,6 +1321,7 @@ static void Initialize(Local target, V(SockRecv, "sock_recv") V(SockSend, "sock_send") V(SockShutdown, "sock_shutdown") + V(SockAccept, "sock_accept") #undef V SetInstanceMethod(isolate, tmpl, "_setMemory", WASI::_SetMemory); diff --git a/src/node_wasi.h b/src/node_wasi.h index a28bdd8ad1bfa64..f29dfc0fc02a050 100644 --- a/src/node_wasi.h +++ b/src/node_wasi.h @@ -142,6 +142,7 @@ class WASI : public BaseObject, static uint32_t SockSend( WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); static uint32_t SockShutdown(WASI&, WasmMemory, uint32_t, uint32_t); + static uint32_t SockAccept(WASI&, WasmMemory, uint32_t, uint32_t, uint32_t); static void _SetMemory(const v8::FunctionCallbackInfo& args); diff --git a/test/wasi/c/sock.c b/test/wasi/c/sock.c new file mode 100644 index 000000000000000..2b415c25ea87d13 --- /dev/null +++ b/test/wasi/c/sock.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include + +int main(void) { + + int fd = 0 ; + socklen_t addrlen = 0; + int flags = 0; + int ret = accept(0, NULL, &addrlen); + assert(ret == -1); + assert(errno == 58); + + return 0; +} diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index e262d4a45c3718b..31ff4f2ae1d85ab 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -98,6 +98,7 @@ if (process.argv[2] === 'wasi-child') { stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`, }); runWASI({ test: 'stat' }); + runWASI({ test: 'sock' }); runWASI({ test: 'write_file' }); // Tests that are currently unsupported on Windows. diff --git a/test/wasi/wasm/sock.wasm b/test/wasi/wasm/sock.wasm new file mode 100755 index 0000000000000000000000000000000000000000..367c0621a0477fd586a21f67fcad73852695f170 GIT binary patch literal 18983 zcmc(H3vgW5dEUAA?i0I9EV0Kuc+4n;`a{d+vY!^S}T9oO>3k+}UuHQqJEz^sLwG^_(6qH+#;_ zXC1a9XxpoO=JeFF3jgI1y416-JddIs4rZsl#lz=&&hzdUooL}&xl>!|G|QWvtF7+J zX1lsmt6sZ5v9`KWX|y_3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