@ai-ecoverse/slicc-kernel 1.91.0 → 1.92.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.
@@ -44,17 +44,20 @@ function hide(target, names) {
44
44
  }
45
45
  function vacate(target, names) {
46
46
  for (const name2 of names) {
47
- for (let at = target; at && at !== Object.prototype; ) {
48
- if (Object.getOwnPropertyDescriptor(at, name2)?.configurable) Reflect.deleteProperty(at, name2);
49
- at = Object.getPrototypeOf(at);
47
+ const holders = chain(target);
48
+ for (const holder of holders) {
49
+ if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
50
+ Reflect.deleteProperty(holder, name2);
51
+ }
50
52
  }
51
- Reflect.defineProperty(target, name2, {
53
+ const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
54
+ const opened2 = Reflect.defineProperty(target, name2, {
52
55
  value: void 0,
53
56
  writable: true,
54
57
  enumerable: false,
55
58
  configurable: true
56
59
  });
57
- if (Reflect.get(target, name2) !== void 0) {
60
+ if (kept || !opened2 || Reflect.get(target, name2) !== void 0) {
58
61
  throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
59
62
  }
60
63
  }
@@ -80,7 +83,6 @@ var init_lockdown = __esm({
80
83
  "cookieStore",
81
84
  "Worker",
82
85
  "SharedWorker",
83
- "BroadcastChannel",
84
86
  "postMessage",
85
87
  "close",
86
88
  "webkitRequestFileSystem",
@@ -97,7 +99,7 @@ var init_lockdown = __esm({
97
99
  "hid",
98
100
  "serial"
99
101
  ];
100
- OPEN_SLOTS = ["fetch", "WebSocket"];
102
+ OPEN_SLOTS = ["fetch", "WebSocket", "BroadcastChannel"];
101
103
  }
102
104
  });
103
105
 
@@ -3638,6 +3640,7 @@ function importsContext({
3638
3640
  fs,
3639
3641
  fds,
3640
3642
  syscall: call2,
3643
+ net: network(raw, call2),
3641
3644
  ...processes(host, call2, tid !== MAIN_TID),
3642
3645
  async: {
3643
3646
  submit: (req) => call2({ op: "async-submit", req }),
@@ -3673,6 +3676,30 @@ function importsContext({
3673
3676
  gid: { get: () => live().gid, enumerable: true }
3674
3677
  });
3675
3678
  }
3679
+ function loopbackHost(host) {
3680
+ if (host === "localhost") return "127.0.0.1";
3681
+ if (typeof host === "string" && LOOPBACK.test(host)) return host;
3682
+ throw new WasiError("EINVAL");
3683
+ }
3684
+ function network(raw, call2) {
3685
+ return {
3686
+ connect({ host, port: port3, nonblock = false }) {
3687
+ const to = loopbackHost(host);
3688
+ if (!Number.isInteger(port3) || port3 < 1 || port3 > 65535) throw new WasiError("EINVAL");
3689
+ const fd = call2({ op: "sock-open", domain: "inet" });
3690
+ const addr = { family: "inet", host: to, port: port3 };
3691
+ const r = raw({ op: "sock-connect", fd, addr, ...nonblock ? { nonblock: true } : {} });
3692
+ if (r.ok || nonblock && r.errno === "EINPROGRESS") return fd;
3693
+ raw({ op: "fd-close", fd });
3694
+ throw new WasiError(r.errno);
3695
+ },
3696
+ ready(fd) {
3697
+ const sel = call2({ op: "fd-select", read: [], write: [fd], timeoutMs: 0 });
3698
+ if (!sel.write.includes(fd)) return E.INPROGRESS;
3699
+ return call2({ op: "sock-getopt", fd, level: SOL_SOCKET, name: SO_ERROR });
3700
+ }
3701
+ };
3702
+ }
3676
3703
  function processes(host, call2, inThread) {
3677
3704
  const close = (fd) => void call2({ op: "fd-close", fd });
3678
3705
  const slot2 = (n, how, mine, theirs) => {
@@ -3730,7 +3757,7 @@ function processes(host, call2, inThread) {
3730
3757
  }
3731
3758
  };
3732
3759
  }
3733
- var UID, STDIO;
3760
+ var UID, LOOPBACK, SOL_SOCKET, SO_ERROR, STDIO;
3734
3761
  var init_wasi_imports = __esm({
3735
3762
  "src/process/wasi/wasi-imports.ts"() {
3736
3763
  "use strict";
@@ -3739,6 +3766,9 @@ var init_wasi_imports = __esm({
3739
3766
  init_wasi_threads();
3740
3767
  init_wasix_process();
3741
3768
  UID = 1e3;
3769
+ LOOPBACK = /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
3770
+ SOL_SOCKET = 1;
3771
+ SO_ERROR = 4;
3742
3772
  STDIO = ["stdin", "stdout", "stderr"];
3743
3773
  }
3744
3774
  });
@@ -3884,12 +3914,19 @@ var KERNEL_VERSION, OS_RELEASE;
3884
3914
  var init_version = __esm({
3885
3915
  "src/version.ts"() {
3886
3916
  "use strict";
3887
- KERNEL_VERSION = true ? "1.91.0" : "0.0.0-dev";
3917
+ KERNEL_VERSION = true ? "1.92.0" : "0.0.0-dev";
3888
3918
  OS_RELEASE = "6.0.0-slicc";
3889
3919
  }
3890
3920
  });
3891
3921
 
3892
3922
  // src/process/js/js-kernel.ts
3923
+ function umaskRequest(mask) {
3924
+ if (mask === void 0) return { op: "proc-umask" };
3925
+ if (!Number.isInteger(mask) || mask < 0 || mask > 511) {
3926
+ throw new JsCallError("EINVAL", "umask");
3927
+ }
3928
+ return { op: "proc-umask", mask };
3929
+ }
3893
3930
  function modeOf(mode) {
3894
3931
  if (!Number.isInteger(mode) || mode < 0 || mode > 4095) {
3895
3932
  throw new JsCallError("EINVAL", "chmod");
@@ -4371,7 +4408,8 @@ function openRequest(abs, o) {
4371
4408
  flags: flagsOf(o),
4372
4409
  position: 0,
4373
4410
  ...isExclusive(o) ? { exclusive: true } : o.create ? { create: true } : { existing: true },
4374
- ...o.truncate ? { truncate: true } : {}
4411
+ ...o.truncate ? { truncate: true } : {},
4412
+ ...o.create || isExclusive(o) ? { mode: o.mode === void 0 ? 438 : modeOf(o.mode) } : {}
4375
4413
  };
4376
4414
  }
4377
4415
  function index2(n, what) {
@@ -5348,8 +5386,8 @@ function netOps(kernel, io) {
5348
5386
  const failed5 = await kernel.json({
5349
5387
  op: "sock-getopt",
5350
5388
  fd,
5351
- level: SOL_SOCKET,
5352
- name: SO_ERROR
5389
+ level: SOL_SOCKET2,
5390
+ name: SO_ERROR2
5353
5391
  });
5354
5392
  if (failed5 !== 0) throw new JsCallError(errnoName(failed5), "connect");
5355
5393
  return connection(fd);
@@ -5357,7 +5395,7 @@ function netOps(kernel, io) {
5357
5395
  }
5358
5396
  };
5359
5397
  }
5360
- var SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET, SO_ERROR;
5398
+ var SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
5361
5399
  var init_js_net = __esm({
5362
5400
  "src/process/js/js-net.ts"() {
5363
5401
  "use strict";
@@ -5367,8 +5405,8 @@ var init_js_net = __esm({
5367
5405
  SHUT_WR = 1;
5368
5406
  IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
5369
5407
  NEVER = new AbortController().signal;
5370
- SOL_SOCKET = 1;
5371
- SO_ERROR = 4;
5408
+ SOL_SOCKET2 = 1;
5409
+ SO_ERROR2 = 4;
5372
5410
  }
5373
5411
  });
5374
5412
 
@@ -5646,6 +5684,7 @@ function toMs(v) {
5646
5684
  return v instanceof Date ? v.getTime() : v;
5647
5685
  }
5648
5686
  function wantOf2(flags) {
5687
+ if (flags & O_PATH) return 0;
5649
5688
  const mode = flags & O_ACCMODE;
5650
5689
  const read2 = mode === 1 ? 0 : HOLD_READ;
5651
5690
  const write2 = mode !== 0 || (flags & O_TRUNC) !== 0 ? HOLD_WRITE : 0;
@@ -8484,7 +8523,8 @@ function syncPathOps(kernel, resolve, statOf, open) {
8484
8523
  mkdir: (path, options) => void kernel.call({
8485
8524
  op: "mkdir",
8486
8525
  path: resolve(path),
8487
- ...options?.recursive === false ? { exclusive: true } : {}
8526
+ ...options?.recursive === false ? { exclusive: true } : {},
8527
+ mode: options?.mode === void 0 ? 511 : modeOf(options.mode)
8488
8528
  }),
8489
8529
  rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
8490
8530
  unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
@@ -8508,8 +8548,14 @@ function syncPathOps(kernel, resolve, statOf, open) {
8508
8548
  kernel.call({ op: "fd-path-flush", path: abs });
8509
8549
  return kernel.bytes({ op: "read", path: abs });
8510
8550
  },
8511
- writeFile(path, data) {
8512
- const file = open(path, { write: true, create: true, truncate: true });
8551
+ writeFile(path, data, options) {
8552
+ const mode = options?.mode;
8553
+ const file = open(path, {
8554
+ write: true,
8555
+ create: true,
8556
+ truncate: true,
8557
+ ...mode !== void 0 ? { mode } : {}
8558
+ });
8513
8559
  try {
8514
8560
  file.write(0, typeof data === "string" ? encoder3.encode(data) : data);
8515
8561
  } finally {
@@ -9008,6 +9054,7 @@ function createContext(o) {
9008
9054
  },
9009
9055
  kill: killer({ self: o.pid, kernel, syncKernel, lane, writes, modes: terminal.modes }),
9010
9056
  cred: () => syncKernel.json({ op: "proc-cred" }),
9057
+ umask: (mask) => syncKernel.json(umaskRequest(mask)),
9011
9058
  setcred(change) {
9012
9059
  if (typeof change !== "object" || change === null || Array.isArray(change)) {
9013
9060
  throw new JsCallError("EINVAL", "setcred");
@@ -9054,6 +9101,7 @@ function createContext(o) {
9054
9101
  },
9055
9102
  sync,
9056
9103
  fetch: fetchOp(kernel),
9104
+ umask: async (mask) => await kernel.json(umaskRequest(mask)),
9057
9105
  sudo: async (args) => await kernel.json({
9058
9106
  op: "proc-sudo",
9059
9107
  args: [...args],
@@ -9203,7 +9251,8 @@ function pathOps(kernel, resolve, statOf, open) {
9203
9251
  mkdir: async (path, options) => void await kernel.call({
9204
9252
  op: "mkdir",
9205
9253
  path: resolve(path),
9206
- ...options?.recursive === false ? { exclusive: true } : {}
9254
+ ...options?.recursive === false ? { exclusive: true } : {},
9255
+ mode: options?.mode === void 0 ? 511 : modeOf(options.mode)
9207
9256
  }),
9208
9257
  rm: async (path) => void await kernel.call({ op: "rm", path: resolve(path) }),
9209
9258
  unlink: async (path) => void await kernel.call({ op: "unlink", path: resolve(path) }),
@@ -9227,8 +9276,14 @@ function pathOps(kernel, resolve, statOf, open) {
9227
9276
  await kernel.call({ op: "fd-path-flush", path: abs });
9228
9277
  return kernel.bytes({ op: "read", path: abs });
9229
9278
  },
9230
- async writeFile(path, data) {
9231
- const file = await open(path, { write: true, create: true, truncate: true });
9279
+ async writeFile(path, data, options) {
9280
+ const mode = options?.mode;
9281
+ const file = await open(path, {
9282
+ write: true,
9283
+ create: true,
9284
+ truncate: true,
9285
+ ...mode !== void 0 ? { mode } : {}
9286
+ });
9232
9287
  try {
9233
9288
  await file.write(0, typeof data === "string" ? encoder4.encode(data) : data);
9234
9289
  } finally {
@@ -12869,7 +12924,7 @@ function readAddr(view, ptr) {
12869
12924
  function ipv6Host(bytes) {
12870
12925
  const zeros = (n) => bytes.subarray(0, n).every((b) => b === 0);
12871
12926
  if (zeros(16)) return "0.0.0.0";
12872
- if (zeros(15) && bytes[15] === 1) return LOOPBACK;
12927
+ if (zeros(15) && bytes[15] === 1) return LOOPBACK2;
12873
12928
  if (zeros(10) && bytes[10] === 255 && bytes[11] === 255) return bytes.subarray(12).join(".");
12874
12929
  const groups = [0, 2, 4, 6, 8, 10, 12, 14].map(
12875
12930
  (i) => (bytes[i] << 8 | bytes[i + 1]).toString(16)
@@ -13026,7 +13081,7 @@ function wasixSocketImports(host, preview1) {
13026
13081
  }
13027
13082
  };
13028
13083
  }
13029
- var INET4, INET6, UNIX, STREAM, ADDR_IP_SIZE, LOOPBACK, OPTIONS;
13084
+ var INET4, INET6, UNIX, STREAM, ADDR_IP_SIZE, LOOPBACK2, OPTIONS;
13030
13085
  var init_wasix_sockets = __esm({
13031
13086
  "src/process/wasi/wasix-sockets.ts"() {
13032
13087
  "use strict";
@@ -13038,7 +13093,7 @@ var init_wasix_sockets = __esm({
13038
13093
  UNIX = 3;
13039
13094
  STREAM = 1;
13040
13095
  ADDR_IP_SIZE = 18;
13041
- LOOPBACK = "127.0.0.1";
13096
+ LOOPBACK2 = "127.0.0.1";
13042
13097
  OPTIONS = {
13043
13098
  1: [1, 15],
13044
13099
  2: [1, 2],