@ai-ecoverse/slicc-kernel 1.41.3 → 1.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,6 +69,11 @@ var init_loopback_names = __esm({
69
69
  });
70
70
 
71
71
  // src/kernel/signals.ts
72
+ function defaultAction(sig) {
73
+ if (sig === SIG.CONT) return "continue";
74
+ if (STOPPING.has(sig)) return "stop";
75
+ return IGNORED_BY_DEFAULT.has(sig) ? "ignore" : "terminate";
76
+ }
72
77
  function sigbit(sig) {
73
78
  return 1 << sig;
74
79
  }
@@ -417,6 +422,9 @@ function wasiErrnoOf(code2) {
417
422
  if (name === "NOMEDIUM") return E.NODEV;
418
423
  return E[name] ?? E.IO;
419
424
  }
425
+ function wasixSignal(sig) {
426
+ return Number.isInteger(sig) && sig >= 1 && sig <= 31 ? sig : void 0;
427
+ }
420
428
  var E, FILETYPE, RIGHTS, OFLAGS, FDFLAGS, LOOKUP_SYMLINK_FOLLOW, WHENCE, CLOCK, FSTFLAGS, EVENTTYPE, SUBCLOCK_ABSTIME, EVENT_FD_READWRITE_HANGUP, RIFLAGS, SDFLAGS, PREOPENTYPE_DIR, SIZE, WASI_SIGNAL_TO_POSIX;
421
429
  var init_wasi_abi = __esm({
422
430
  "src/process/wasi/wasi-abi.ts"() {
@@ -1454,7 +1462,7 @@ var init_sync_sab_wire = __esm({
1454
1462
  });
1455
1463
 
1456
1464
  // src/realm/sync-sab-bridge.ts
1457
- function createSyncSabTransport(sab, port, deps = {}) {
1465
+ function createSyncSabTransport(sab, port2, deps = {}) {
1458
1466
  const views = sabViews(sab);
1459
1467
  const { header, window } = views;
1460
1468
  const wait = deps.wait ?? ((a, i, v, t) => Atomics.wait(a, i, v, t));
@@ -1485,8 +1493,8 @@ function createSyncSabTransport(sab, port, deps = {}) {
1485
1493
  Atomics.store(header, SAB_I_STATE, SAB_STATE_PENDING);
1486
1494
  const msg = offset === 0 ? { type: SYNC_SAB_REQ_MSG, id, req } : { type: SYNC_SAB_NEXT_MSG, id, offset };
1487
1495
  try {
1488
- if (offset === 0 && transfer.length > 0) port.postMessage(msg, transfer);
1489
- else port.postMessage(msg);
1496
+ if (offset === 0 && transfer.length > 0) port2.postMessage(msg, transfer);
1497
+ else port2.postMessage(msg);
1490
1498
  } catch {
1491
1499
  throw syncError("EIO", label);
1492
1500
  }
@@ -3962,9 +3970,9 @@ function reportGrowth(imports, publish) {
3962
3970
  return grown;
3963
3971
  };
3964
3972
  }
3965
- async function runWasmProcess(init, port, deps = {}) {
3973
+ async function runWasmProcess(init, port2, deps = {}) {
3966
3974
  const signals = new SignalGate(
3967
- createSyncSabTransport(init.sab, port, {
3975
+ createSyncSabTransport(init.sab, port2, {
3968
3976
  memory: () => memory?.buffer.byteLength ?? 0
3969
3977
  }),
3970
3978
  new Int32Array(init.sab, 0, SAB_HEADER_I32),
@@ -6207,18 +6215,18 @@ var init_wasi_module = __esm({
6207
6215
  });
6208
6216
 
6209
6217
  // src/process/wasi/wasi-signals.ts
6210
- var DELIVERED, DELIVERED_MASK, WasiSignals;
6218
+ var DELIVERED_MASK, WasiSignals;
6211
6219
  var init_wasi_signals = __esm({
6212
6220
  "src/process/wasi/wasi-signals.ts"() {
6213
6221
  "use strict";
6214
6222
  init_signals();
6215
- DELIVERED = [SIG.HUP, SIG.INT, SIG.QUIT, SIG.USR1, SIG.USR2, SIG.ALRM, SIG.TERM];
6216
- DELIVERED_MASK = DELIVERED.reduce((m, sig) => m | sigbit(sig), 0);
6223
+ DELIVERED_MASK = Object.values(SIG).filter((sig) => sig !== SIG.KILL && sig !== SIG.STOP).reduce((m, sig) => m | sigbit(sig), 0);
6217
6224
  WasiSignals = class {
6218
6225
  exports;
6219
6226
  callback;
6220
6227
  uncaught = 0;
6221
6228
  delivering;
6229
+ defaulted = false;
6222
6230
  fallBack;
6223
6231
  onKilled;
6224
6232
  constructor(fallBack, onKilled) {
@@ -6241,25 +6249,29 @@ var init_wasi_signals = __esm({
6241
6249
  raise(sig) {
6242
6250
  const handler = this.handler();
6243
6251
  if (!handler) return;
6244
- const outer = this.delivering;
6252
+ const outer = { sig: this.delivering, defaulted: this.defaulted };
6245
6253
  this.delivering = sig;
6254
+ this.defaulted = false;
6246
6255
  try {
6247
6256
  handler(sig);
6248
6257
  } catch (e) {
6249
6258
  if (!(e instanceof WebAssembly.RuntimeError)) throw e;
6250
- this.defaultAction(sig);
6259
+ if (!this.defaulted) this.defaultAction(sig);
6251
6260
  } finally {
6252
- this.delivering = outer;
6261
+ this.delivering = outer.sig;
6262
+ this.defaulted = outer.defaulted;
6253
6263
  }
6254
6264
  }
6255
6265
  raised(sig) {
6256
6266
  if (sig !== SIG.ABRT || this.delivering === void 0) return false;
6257
- this.defaultAction(this.delivering);
6267
+ if (!this.defaulted) this.defaultAction(this.delivering);
6258
6268
  return true;
6259
6269
  }
6260
6270
  defaultAction(sig) {
6271
+ this.defaulted = true;
6261
6272
  this.uncaught |= sigbit(sig);
6262
6273
  this.fallBack(sig);
6274
+ if (defaultAction(sig) !== "terminate") this.uncaught &= ~sigbit(sig);
6263
6275
  }
6264
6276
  handler() {
6265
6277
  const fn = this.callback ? this.exports?.[this.callback] : void 0;
@@ -6350,8 +6362,8 @@ var init_wasi_threads = __esm({
6350
6362
  memory;
6351
6363
  cap;
6352
6364
  tid;
6353
- constructor(port, memory, cap, tid, ids) {
6354
- this.port = port;
6365
+ constructor(port2, memory, cap, tid, ids) {
6366
+ this.port = port2;
6355
6367
  this.memory = memory;
6356
6368
  this.cap = cap;
6357
6369
  this.tid = tid;
@@ -6900,17 +6912,13 @@ var init_physical_path = __esm({
6900
6912
  function resolveFrom(cwd, path) {
6901
6913
  return normalize(path.startsWith("/") ? path : `${cwd}/${path}`);
6902
6914
  }
6903
- var POSIX_TO_WASI_SIGNAL, O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
6915
+ var O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
6904
6916
  var init_wasix_process = __esm({
6905
6917
  "src/process/wasi/wasix-process.ts"() {
6906
6918
  "use strict";
6907
6919
  init_physical_path();
6908
- init_wasi_abi();
6909
6920
  init_wasi_files();
6910
6921
  init_wasi_host();
6911
- POSIX_TO_WASI_SIGNAL = Object.fromEntries(
6912
- Object.entries(WASI_SIGNAL_TO_POSIX).map(([wasi, posix]) => [posix, Number(wasi)])
6913
- );
6914
6922
  O_WRONLY5 = 1;
6915
6923
  O_RDWR5 = 2;
6916
6924
  O_APPEND2 = 1024;
@@ -7046,7 +7054,7 @@ var init_wasix_process = __esm({
7046
7054
  const sig = status2 & 127;
7047
7055
  if (sig) {
7048
7056
  v.setUint8(statusPtr, 2);
7049
- v.setUint8(statusPtr + 4, POSIX_TO_WASI_SIGNAL[sig] ?? sig);
7057
+ v.setUint8(statusPtr + 4, sig);
7050
7058
  } else {
7051
7059
  v.setUint8(statusPtr, 1);
7052
7060
  v.setUint16(statusPtr + 2, status2 >> 8 & 255, true);
@@ -7153,13 +7161,13 @@ function readAddr(view, ptr) {
7153
7161
  );
7154
7162
  return { family: "unix", path };
7155
7163
  }
7156
- const port = view.getUint16(ptr + 2, true);
7164
+ const port2 = view.getUint16(ptr + 2, true);
7157
7165
  if (tag === INET4) {
7158
7166
  const host = [0, 1, 2, 3].map((i) => view.getUint8(ptr + 4 + i)).join(".");
7159
- return { family: "inet", host, port };
7167
+ return { family: "inet", host, port: port2 };
7160
7168
  }
7161
7169
  if (tag === INET6) {
7162
- return { family: "inet", host: ipv6Host(new Uint8Array(view.buffer, ptr + 4, 16)), port };
7170
+ return { family: "inet", host: ipv6Host(new Uint8Array(view.buffer, ptr + 4, 16)), port: port2 };
7163
7171
  }
7164
7172
  throw new WasiError("EAFNOSUPPORT");
7165
7173
  }
@@ -7355,7 +7363,7 @@ var init_wasix_sockets = __esm({
7355
7363
 
7356
7364
  // src/process/wasi/wasix-host.ts
7357
7365
  function posixSignal(sig) {
7358
- const posix = WASI_SIGNAL_TO_POSIX[sig];
7366
+ const posix = wasixSignal(sig);
7359
7367
  if (posix === void 0) throw new WasiError("EINVAL");
7360
7368
  return posix;
7361
7369
  }
@@ -7558,7 +7566,7 @@ var init_wasix_host = __esm({
7558
7566
  stack_restore: (snapPtr, val) => void this.driver.restore(snapPtr, val),
7559
7567
  proc_join: (pidPtr, flags, statusPtr) => void process.join(pidPtr, flags, statusPtr),
7560
7568
  proc_signal: (pid, sig) => {
7561
- const posix = sig === 0 ? 0 : WASI_SIGNAL_TO_POSIX[sig];
7569
+ const posix = sig === 0 ? 0 : wasixSignal(sig);
7562
7570
  if (posix === void 0) throw new WasiError("EINVAL");
7563
7571
  if (pid === this.host.o.pid && posix !== 0 && this.host.onRaise?.(posix)) return;
7564
7572
  this.host.o.kernel.call({ op: "proc-kill", pid, sig: posix });
@@ -7659,8 +7667,7 @@ var init_wasix_host = __esm({
7659
7667
  },
7660
7668
  thread_signal: (tid, sig) => {
7661
7669
  if (!(this.threads?.known(tid) ?? tid === MAIN_TID)) throw new WasiError("ESRCH");
7662
- const posix = WASI_SIGNAL_TO_POSIX[sig];
7663
- if (posix === void 0) throw new WasiError("EINVAL");
7670
+ const posix = posixSignal(sig);
7664
7671
  if (host.onRaise?.(posix)) return;
7665
7672
  host.o.kernel.call({ op: "proc-kill", pid: host.o.pid, sig: posix });
7666
7673
  },
@@ -7919,10 +7926,10 @@ function sizeOf(main) {
7919
7926
  function memoryOf(instance, imported) {
7920
7927
  return imported ?? instance.exports.memory;
7921
7928
  }
7922
- function kernelOf(init, port, hooks = { masks: () => null, raise: () => {
7929
+ function kernelOf(init, port2, hooks = { masks: () => null, raise: () => {
7923
7930
  } }, memory) {
7924
7931
  const transport = new SignalGate(
7925
- createSyncSabTransport(init.sab, port, memory ? { memory } : {}),
7932
+ createSyncSabTransport(init.sab, port2, memory ? { memory } : {}),
7926
7933
  new Int32Array(init.sab, 0, SAB_HEADER_I32),
7927
7934
  hooks
7928
7935
  ).transport();
@@ -8046,19 +8053,19 @@ function descriptors(init, fork, threads) {
8046
8053
  if (fork) return { forked: { fds: fork.fds, cloexec: fork.cloexec } };
8047
8054
  return { inherited: init.fds ?? [], ...init.program.preopenRoot ? { preopenRoot: true } : {} };
8048
8055
  }
8049
- async function runWasiProcess(init, port) {
8056
+ async function runWasiProcess(init, port2) {
8050
8057
  captureBacktraces(init.env);
8051
8058
  const signals = new WasiSignals(
8052
8059
  (sig) => {
8053
8060
  call2({ op: "proc-kill", pid: init.pid, sig });
8054
- throw new WasiExit(128 + sig);
8061
+ if (defaultAction(sig) === "terminate") throw new WasiExit(128 + sig);
8055
8062
  },
8056
8063
  (code2) => {
8057
8064
  throw new WasiExit(code2);
8058
8065
  }
8059
8066
  );
8060
8067
  const main = {};
8061
- const { transport, sys, call: kernelCall, say } = kernelOf(init, port, signals, sizeOf(main));
8068
+ const { transport, sys, call: kernelCall, say } = kernelOf(init, port2, signals, sizeOf(main));
8062
8069
  const id = identify(transport, init);
8063
8070
  const stats = init.env.SLICC_WASI_STATS === "1" ? new WasiStats() : void 0;
8064
8071
  const call2 = stats ? timedCalls(stats, kernelCall) : kernelCall;
@@ -8075,7 +8082,7 @@ async function runWasiProcess(init, port) {
8075
8082
  }
8076
8083
  const fork = init.fork?.wasi;
8077
8084
  const memory = createImportedMemory(init.program.memory, fork ? init.fork?.memory : void 0);
8078
- const threads = memory?.buffer instanceof SharedArrayBuffer && spawnsThreads(module) ? new WasiThreads(port, memory, threadCap(init.env), MAIN_TID) : void 0;
8085
+ const threads = memory?.buffer instanceof SharedArrayBuffer && spawnsThreads(module) ? new WasiThreads(port2, memory, threadCap(init.env), MAIN_TID) : void 0;
8079
8086
  const host = new WasiHost({
8080
8087
  args: [init.argv0, ...init.args],
8081
8088
  env: init.env,
@@ -8150,11 +8157,11 @@ function captureBacktraces(env) {
8150
8157
  const v8 = Error;
8151
8158
  v8.stackTraceLimit = Math.max(v8.stackTraceLimit ?? 0, BACKTRACE_FRAMES + 20);
8152
8159
  }
8153
- async function runWasiThread(init, port) {
8160
+ async function runWasiThread(init, port2) {
8154
8161
  captureBacktraces(init.env);
8155
- const { transport, sys, call: call2, say } = kernelOf(init, port);
8162
+ const { transport, sys, call: call2, say } = kernelOf(init, port2);
8156
8163
  const { thread } = init;
8157
- const threads = new WasiThreads(port, thread.memory, threadCap(init.env), thread.tid, thread.ids);
8164
+ const threads = new WasiThreads(port2, thread.memory, threadCap(init.env), thread.tid, thread.ids);
8158
8165
  threads.received = thread.modules;
8159
8166
  const id = identify(transport, init);
8160
8167
  const host = new WasiHost({
@@ -8184,7 +8191,7 @@ async function runWasiThread(init, port) {
8184
8191
  return;
8185
8192
  }
8186
8193
  if (e instanceof WasiExit) {
8187
- port.postMessage({ type: WASM_PROCESS_EXIT, code: e.code });
8194
+ port2.postMessage({ type: WASM_PROCESS_EXIT, code: e.code });
8188
8195
  return;
8189
8196
  }
8190
8197
  if (e instanceof WebAssembly.RuntimeError) {
@@ -8192,7 +8199,7 @@ async function runWasiThread(init, port) {
8192
8199
  say(trapMessage(e, init.env, ` in thread ${thread.tid}`, programNames(host, init.program)));
8193
8200
  } catch {
8194
8201
  }
8195
- port.postMessage({ type: WASM_PROCESS_EXIT, code: TRAPPED });
8202
+ port2.postMessage({ type: WASM_PROCESS_EXIT, code: TRAPPED });
8196
8203
  return;
8197
8204
  }
8198
8205
  throw e;
@@ -8203,6 +8210,7 @@ var init_wasi_runtime = __esm({
8203
8210
  "src/process/wasi/wasi-runtime.ts"() {
8204
8211
  "use strict";
8205
8212
  init_protocol();
8213
+ init_signals();
8206
8214
  init_sync_sab_bridge();
8207
8215
  init_sync_sab_wire();
8208
8216
  init_kernel_streams();
@@ -8279,7 +8287,7 @@ async function changed(header, index2, seen, waitAsync = defaultWaitAsync) {
8279
8287
  const waited = waitAsync(header, index2, seen);
8280
8288
  if (waited.async) await waited.value;
8281
8289
  }
8282
- function createAsyncSabTransport(sab, port, waitAsync = defaultWaitAsync) {
8290
+ function createAsyncSabTransport(sab, port2, waitAsync = defaultWaitAsync) {
8283
8291
  const { header, window } = sabViews(sab);
8284
8292
  let seq = 0;
8285
8293
  let tail = Promise.resolve();
@@ -8301,7 +8309,7 @@ function createAsyncSabTransport(sab, port, waitAsync = defaultWaitAsync) {
8301
8309
  try {
8302
8310
  for (; ; ) {
8303
8311
  Atomics.store(header, SAB_I_STATE, SAB_STATE_PENDING);
8304
- port.postMessage(
8312
+ port2.postMessage(
8305
8313
  offset === 0 ? { type: SYNC_SAB_REQ_MSG, id, req } : { type: SYNC_SAB_NEXT_MSG, id, offset }
8306
8314
  );
8307
8315
  await ready(id);
@@ -8706,6 +8714,145 @@ var init_js_io = __esm({
8706
8714
  }
8707
8715
  });
8708
8716
 
8717
+ // src/process/js/js-net.ts
8718
+ function errnoName(errno2) {
8719
+ const found = Object.entries(E).find(([, n]) => n === errno2);
8720
+ return found ? `E${found[0]}` : "EIO";
8721
+ }
8722
+ function addressOf(addr) {
8723
+ const inet = addr;
8724
+ return { host: inet.host, port: inet.port };
8725
+ }
8726
+ function port(n) {
8727
+ if (!Number.isInteger(n) || n < 0 || n > 65535) throw new JsCallError("EINVAL", `port ${n}`);
8728
+ return n;
8729
+ }
8730
+ function netOps(kernel, io) {
8731
+ const name = async (fd, peer) => addressOf(await kernel.json({ op: "sock-name", fd, peer }));
8732
+ const connection = async (fd) => {
8733
+ const [local, remote] = [await name(fd, false), await name(fd, true)];
8734
+ const stop = new AbortController();
8735
+ let closed;
8736
+ const close = () => {
8737
+ stop.abort(new JsCallError("EBADF", "socket closed"));
8738
+ closed ??= io.close(fd);
8739
+ return closed;
8740
+ };
8741
+ const shut = (how) => kernel.raw({ op: "sock-shutdown", fd, how });
8742
+ const readable2 = new ReadableStream(
8743
+ {
8744
+ async pull(controller) {
8745
+ const chunk = await io.read(fd, void 0, stop.signal);
8746
+ if (chunk.length > 0) controller.enqueue(chunk);
8747
+ else controller.close();
8748
+ },
8749
+ cancel: async () => void await shut(SHUT_RD)
8750
+ },
8751
+ { highWaterMark: 0 }
8752
+ );
8753
+ const writable2 = new WritableStream({
8754
+ write: (chunk, controller) => io.send(fd, chunk, AbortSignal.any([controller.signal, stop.signal])),
8755
+ close: async () => void await shut(SHUT_WR),
8756
+ abort: () => close()
8757
+ });
8758
+ return { fd, local, remote, readable: readable2, writable: writable2, close };
8759
+ };
8760
+ const resolve = async (host, signal) => {
8761
+ if (IPV4.test(host)) return host;
8762
+ const r = await kernel.blocking({ op: "sock-resolve", name: host, family: 4 }, signal);
8763
+ return (r.ok && r.kind === "json" ? r.json : [])[0];
8764
+ };
8765
+ const opened = async (use) => {
8766
+ const fd = await kernel.json({ op: "sock-open", domain: "inet" });
8767
+ try {
8768
+ return await use(fd);
8769
+ } catch (err) {
8770
+ await io.close(fd);
8771
+ throw err;
8772
+ }
8773
+ };
8774
+ const listener = (fd, at) => {
8775
+ const stop = new AbortController();
8776
+ const accept = async (options = {}) => {
8777
+ const signal = AbortSignal.any([options.signal ?? NEVER, stop.signal]);
8778
+ for (; ; ) {
8779
+ signal.throwIfAborted();
8780
+ const r = await kernel.raw({ op: "sock-accept", fd, nonblock: true });
8781
+ if (r.ok) return connection((r.kind === "json" ? r.json : {}).fd);
8782
+ if (r.errno !== "EAGAIN") throw new JsCallError(r.errno, "accept");
8783
+ await kernel.blocking({ op: "fd-select", read: [fd], write: [], timeoutMs: -1 }, signal);
8784
+ }
8785
+ };
8786
+ return {
8787
+ fd,
8788
+ ...at,
8789
+ accept,
8790
+ async close() {
8791
+ stop.abort(new JsCallError("EBADF", "listener closed"));
8792
+ await io.close(fd);
8793
+ },
8794
+ async *[Symbol.asyncIterator]() {
8795
+ for (; ; ) {
8796
+ try {
8797
+ yield await accept();
8798
+ } catch (err) {
8799
+ if (stop.signal.aborted) return;
8800
+ throw err;
8801
+ }
8802
+ }
8803
+ }
8804
+ };
8805
+ };
8806
+ return {
8807
+ listen: (options = {}) => opened(async (fd) => {
8808
+ const addr = {
8809
+ family: "inet",
8810
+ host: options.host ?? "127.0.0.1",
8811
+ port: port(options.port ?? 0)
8812
+ };
8813
+ await kernel.call({ op: "sock-bind", fd, addr });
8814
+ await kernel.call({ op: "sock-listen", fd, backlog: options.backlog ?? 128 });
8815
+ return listener(fd, await name(fd, false));
8816
+ }),
8817
+ connect: async (options) => {
8818
+ const signal = options.signal ?? NEVER;
8819
+ signal.throwIfAborted();
8820
+ const addr = {
8821
+ family: "inet",
8822
+ host: await resolve(options.host, signal),
8823
+ port: port(options.port)
8824
+ };
8825
+ return opened(async (fd) => {
8826
+ const r = await kernel.raw({ op: "sock-connect", fd, addr, nonblock: true });
8827
+ if (!r.ok && r.errno !== "EINPROGRESS") throw new JsCallError(r.errno, "connect");
8828
+ await kernel.blocking({ op: "fd-select", read: [], write: [fd], timeoutMs: -1 }, signal);
8829
+ const failed2 = await kernel.json({
8830
+ op: "sock-getopt",
8831
+ fd,
8832
+ level: SOL_SOCKET,
8833
+ name: SO_ERROR
8834
+ });
8835
+ if (failed2 !== 0) throw new JsCallError(errnoName(failed2), "connect");
8836
+ return connection(fd);
8837
+ });
8838
+ }
8839
+ };
8840
+ }
8841
+ var SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET, SO_ERROR;
8842
+ var init_js_net = __esm({
8843
+ "src/process/js/js-net.ts"() {
8844
+ "use strict";
8845
+ init_wasi_abi();
8846
+ init_js_kernel();
8847
+ SHUT_RD = 0;
8848
+ SHUT_WR = 1;
8849
+ IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
8850
+ NEVER = new AbortController().signal;
8851
+ SOL_SOCKET = 1;
8852
+ SO_ERROR = 4;
8853
+ }
8854
+ });
8855
+
8709
8856
  // src/process/js/js-sync.ts
8710
8857
  function laneOf(lane) {
8711
8858
  if (!lane) return () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
@@ -9048,11 +9195,8 @@ function createContext(o) {
9048
9195
  infos,
9049
9196
  handles
9050
9197
  });
9051
- const children = childOps(
9052
- kernel,
9053
- { read, send: writeAll, close: (fd) => ctx.close(fd) },
9054
- { env: o.env, cwd: o.cwd, signal: signalNumber }
9055
- );
9198
+ const io = { read, send: writeAll, close: (fd) => ctx.close(fd) };
9199
+ const children = childOps(kernel, io, { env: o.env, cwd: o.cwd, signal: signalNumber });
9056
9200
  const ctx = {
9057
9201
  argv: o.argv,
9058
9202
  env: o.env,
@@ -9096,6 +9240,7 @@ function createContext(o) {
9096
9240
  },
9097
9241
  sync,
9098
9242
  ...children,
9243
+ net: netOps(kernel, io),
9099
9244
  exit
9100
9245
  };
9101
9246
  const drain2 = async () => {
@@ -9231,6 +9376,7 @@ var init_js_context = __esm({
9231
9376
  init_js_children();
9232
9377
  init_js_io();
9233
9378
  init_js_kernel();
9379
+ init_js_net();
9234
9380
  init_js_sync();
9235
9381
  JsExit = class extends Error {
9236
9382
  status;
@@ -9338,8 +9484,8 @@ function mainOf(module) {
9338
9484
  const main = typeof module.default === "function" ? module.default : module.main;
9339
9485
  return typeof main === "function" ? main : void 0;
9340
9486
  }
9341
- async function runJsProcess(init, port, deps = {}) {
9342
- const transport = createAsyncSabTransport(init.sab, port, deps.waitAsync);
9487
+ async function runJsProcess(init, port2, deps = {}) {
9488
+ const transport = createAsyncSabTransport(init.sab, port2, deps.waitAsync);
9343
9489
  let resolveExit;
9344
9490
  const exit = new Promise((resolve) => resolveExit = resolve);
9345
9491
  let exitedWith;
@@ -9418,29 +9564,29 @@ init_protocol();
9418
9564
  init_process_runtime();
9419
9565
  var loadWasi = () => Promise.resolve().then(() => (init_wasi_runtime(), wasi_runtime_exports));
9420
9566
  var loadJs = () => Promise.resolve().then(() => (init_js_runtime(), js_runtime_exports));
9421
- function started(init, port, run, wasi, js) {
9567
+ function started(init, port2, run, wasi, js) {
9422
9568
  if (init.program?.abi === "js") {
9423
9569
  const jsInit = init;
9424
- return js().then((m) => m.runJsProcess(jsInit, port));
9570
+ return js().then((m) => m.runJsProcess(jsInit, port2));
9425
9571
  }
9426
9572
  const wasmInit = init;
9427
- if (wasmInit.program?.abi === "wasi") return wasi().then((m) => m.runWasiProcess(wasmInit, port));
9428
- return run(wasmInit, port);
9573
+ if (wasmInit.program?.abi === "wasi") return wasi().then((m) => m.runWasiProcess(wasmInit, port2));
9574
+ return run(wasmInit, port2);
9429
9575
  }
9430
- function processEntry(port, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
9431
- const failed2 = (err) => port.postMessage({
9576
+ function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
9577
+ const failed2 = (err) => port2.postMessage({
9432
9578
  type: WASM_PROCESS_ERROR,
9433
9579
  message: err instanceof Error ? err.stack ?? err.message : String(err)
9434
9580
  });
9435
9581
  return (data) => {
9436
9582
  const type = data?.type;
9437
9583
  if (type === WASM_THREAD_INIT) {
9438
- wasi().then((m) => m.runWasiThread(data, port)).catch(failed2);
9584
+ wasi().then((m) => m.runWasiThread(data, port2)).catch(failed2);
9439
9585
  return;
9440
9586
  }
9441
9587
  if (type !== WASM_PROCESS_INIT) return;
9442
- started(data, port, run, wasi, js).then(
9443
- (code2) => port.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
9588
+ started(data, port2, run, wasi, js).then(
9589
+ (code2) => port2.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
9444
9590
  failed2
9445
9591
  );
9446
9592
  };