@ai-ecoverse/slicc-kernel 1.64.1 → 1.64.2

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.
@@ -13,6 +13,94 @@ var __export = (target, all) => {
13
13
  __defProp(target, name2, { get: all[name2], enumerable: true });
14
14
  };
15
15
 
16
+ // src/process/js/lockdown.ts
17
+ function chain(target) {
18
+ const out = [];
19
+ for (let at = target; at && at !== Object.prototype; ) {
20
+ out.push(at);
21
+ at = Object.getPrototypeOf(at);
22
+ }
23
+ return out;
24
+ }
25
+ function hide(target, names) {
26
+ for (const name2 of names) {
27
+ const holders = chain(target);
28
+ for (const holder of holders) {
29
+ if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
30
+ Reflect.deleteProperty(holder, name2);
31
+ }
32
+ }
33
+ const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
34
+ const defined = Reflect.defineProperty(target, name2, {
35
+ value: void 0,
36
+ writable: false,
37
+ enumerable: false,
38
+ configurable: false
39
+ });
40
+ if (kept || !defined && Reflect.get(target, name2) !== void 0) {
41
+ throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
42
+ }
43
+ }
44
+ }
45
+ function vacate(target, names) {
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);
50
+ }
51
+ Reflect.defineProperty(target, name2, {
52
+ value: void 0,
53
+ writable: true,
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ if (Reflect.get(target, name2) !== void 0) {
58
+ throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
59
+ }
60
+ }
61
+ }
62
+ function lockdown(scope2 = globalThis) {
63
+ hide(scope2, BLOCKED_GLOBALS);
64
+ vacate(scope2, OPEN_SLOTS);
65
+ const navigator = scope2.navigator;
66
+ if (navigator && typeof navigator === "object") hide(navigator, BLOCKED_NAVIGATOR);
67
+ }
68
+ var BLOCKED_GLOBALS, BLOCKED_NAVIGATOR, OPEN_SLOTS;
69
+ var init_lockdown = __esm({
70
+ "src/process/js/lockdown.ts"() {
71
+ "use strict";
72
+ BLOCKED_GLOBALS = [
73
+ "XMLHttpRequest",
74
+ "WebSocketStream",
75
+ "WebTransport",
76
+ "EventSource",
77
+ "importScripts",
78
+ "indexedDB",
79
+ "caches",
80
+ "cookieStore",
81
+ "Worker",
82
+ "SharedWorker",
83
+ "BroadcastChannel",
84
+ "postMessage",
85
+ "close",
86
+ "webkitRequestFileSystem",
87
+ "webkitRequestFileSystemSync",
88
+ "webkitResolveLocalFileSystemURL",
89
+ "webkitResolveLocalFileSystemSyncURL"
90
+ ];
91
+ BLOCKED_NAVIGATOR = [
92
+ "storage",
93
+ "storageBuckets",
94
+ "locks",
95
+ "serviceWorker",
96
+ "usb",
97
+ "hid",
98
+ "serial"
99
+ ];
100
+ OPEN_SLOTS = ["fetch", "WebSocket"];
101
+ }
102
+ });
103
+
16
104
  // src/kernel/protocol.ts
17
105
  var WASM_PROCESS_INIT, WASM_PROCESS_EXIT, WASM_PROCESS_ERROR, WASM_THREAD_SPAWN, WASM_THREAD_INIT, WASM_THREAD_EXIT, WASM_MAX_THREADS, WASM_DEFAULT_THREADS;
18
106
  var init_protocol = __esm({
@@ -2827,8 +2915,11 @@ function useDevFd(Fs) {
2827
2915
  return fstat.call(Fs, fd);
2828
2916
  };
2829
2917
  }
2918
+ function pinRootKind() {
2919
+ pinnedRoot = rootKind();
2920
+ }
2830
2921
  function mountTable(mounts = []) {
2831
- const root = globalThis.navigator?.storage ? "opfs" : "memory";
2922
+ const root = pinnedRoot ?? rootKind();
2832
2923
  const lines = [`${root} / ${root} rw 0 0`, "devfs /dev devfs rw 0 0", "proc /proc proc rw 0 0"];
2833
2924
  for (const m of mounts) {
2834
2925
  const options = Object.entries(m.options).map(([k, v]) => v === "" ? k : `${k}=${v}`);
@@ -2934,7 +3025,7 @@ function linuxDevices(Fs) {
2934
3025
  }
2935
3026
  }
2936
3027
  }
2937
- var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, NAME, AT_FDCWD, AT_EACCESS, DEVICE_MODES;
3028
+ var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, pinnedRoot, rootKind, NAME, AT_FDCWD, AT_EACCESS, DEVICE_MODES;
2938
3029
  var init_process_fds = __esm({
2939
3030
  "src/process/process-fds.ts"() {
2940
3031
  "use strict";
@@ -2976,6 +3067,7 @@ var init_process_fds = __esm({
2976
3067
  O_ACCMODE2 = 3;
2977
3068
  O_CREAT2 = 64;
2978
3069
  field = (text) => (text || "none").replace(/[\s\\]/g, (c) => `\\${c.charCodeAt(0).toString(8).padStart(3, "0")}`);
3070
+ rootKind = () => globalThis.navigator?.storage ? "opfs" : "memory";
2979
3071
  NAME = /^[a-z_][a-z0-9_-]*$/i;
2980
3072
  AT_FDCWD = -100;
2981
3073
  AT_EACCESS = 512;
@@ -12231,82 +12323,6 @@ var init_js_context = __esm({
12231
12323
  }
12232
12324
  });
12233
12325
 
12234
- // src/process/js/lockdown.ts
12235
- function chain(target) {
12236
- const out = [];
12237
- for (let at = target; at && at !== Object.prototype; ) {
12238
- out.push(at);
12239
- at = Object.getPrototypeOf(at);
12240
- }
12241
- return out;
12242
- }
12243
- function hide(target, names) {
12244
- for (const name2 of names) {
12245
- const holders = chain(target);
12246
- for (const holder of holders) {
12247
- if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
12248
- Reflect.deleteProperty(holder, name2);
12249
- }
12250
- }
12251
- const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
12252
- const defined = Reflect.defineProperty(target, name2, {
12253
- value: void 0,
12254
- writable: false,
12255
- enumerable: false,
12256
- configurable: false
12257
- });
12258
- if (kept || !defined && Reflect.get(target, name2) !== void 0) {
12259
- throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
12260
- }
12261
- }
12262
- }
12263
- function vacate(target, names) {
12264
- for (const name2 of names) {
12265
- for (let at = target; at && at !== Object.prototype; ) {
12266
- if (Object.getOwnPropertyDescriptor(at, name2)?.configurable) Reflect.deleteProperty(at, name2);
12267
- at = Object.getPrototypeOf(at);
12268
- }
12269
- Reflect.defineProperty(target, name2, {
12270
- value: void 0,
12271
- writable: true,
12272
- enumerable: false,
12273
- configurable: true
12274
- });
12275
- if (Reflect.get(target, name2) !== void 0) {
12276
- throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
12277
- }
12278
- }
12279
- }
12280
- function lockdown(scope2 = globalThis) {
12281
- hide(scope2, BLOCKED_GLOBALS);
12282
- vacate(scope2, OPEN_SLOTS);
12283
- const navigator = scope2.navigator;
12284
- if (navigator && typeof navigator === "object") hide(navigator, BLOCKED_NAVIGATOR);
12285
- }
12286
- var BLOCKED_GLOBALS, BLOCKED_NAVIGATOR, OPEN_SLOTS;
12287
- var init_lockdown = __esm({
12288
- "src/process/js/lockdown.ts"() {
12289
- "use strict";
12290
- BLOCKED_GLOBALS = [
12291
- "XMLHttpRequest",
12292
- "WebSocketStream",
12293
- "WebTransport",
12294
- "EventSource",
12295
- "importScripts",
12296
- "indexedDB",
12297
- "caches",
12298
- "cookieStore",
12299
- "Worker",
12300
- "SharedWorker",
12301
- "BroadcastChannel",
12302
- "postMessage",
12303
- "close"
12304
- ];
12305
- BLOCKED_NAVIGATOR = ["storage", "locks", "serviceWorker"];
12306
- OPEN_SLOTS = ["fetch", "WebSocket"];
12307
- }
12308
- });
12309
-
12310
12326
  // src/process/js/js-runtime.ts
12311
12327
  var js_runtime_exports = {};
12312
12328
  __export(js_runtime_exports, {
@@ -12429,11 +12445,15 @@ var init_js_runtime = __esm({
12429
12445
  }
12430
12446
  });
12431
12447
 
12448
+ // src/process-worker.ts
12449
+ init_lockdown();
12450
+
12432
12451
  // src/process/process-entry.ts
12433
12452
  init_protocol();
12434
12453
  init_process_runtime();
12435
12454
  var loadWasi = () => Promise.resolve().then(() => (init_wasi_runtime(), wasi_runtime_exports));
12436
12455
  var loadJs = () => Promise.resolve().then(() => (init_js_runtime(), js_runtime_exports));
12456
+ var NOT_RUNNABLE2 = 126;
12437
12457
  function started(init, port2, run, wasi, js) {
12438
12458
  if (init.program?.abi === "js") {
12439
12459
  const jsInit = init;
@@ -12443,18 +12463,35 @@ function started(init, port2, run, wasi, js) {
12443
12463
  if (wasmInit.program?.abi === "wasi") return wasi().then((m) => m.runWasiProcess(wasmInit, port2));
12444
12464
  return run(wasmInit, port2);
12445
12465
  }
12446
- function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
12447
- const failed5 = (err) => port2.postMessage({
12466
+ function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs, seal = () => {
12467
+ }) {
12468
+ const failed5 = (err, code2) => port2.postMessage({
12448
12469
  type: WASM_PROCESS_ERROR,
12449
- message: err instanceof Error ? err.stack ?? err.message : String(err)
12470
+ message: err instanceof Error ? err.stack ?? err.message : String(err),
12471
+ ...code2 === void 0 ? {} : { code: code2 }
12450
12472
  });
12473
+ let refused;
12474
+ const sealOnce = () => {
12475
+ if (refused === void 0) {
12476
+ try {
12477
+ seal();
12478
+ refused = null;
12479
+ } catch (error) {
12480
+ refused = { error };
12481
+ }
12482
+ }
12483
+ return refused;
12484
+ };
12451
12485
  return (data) => {
12452
12486
  const type = data?.type;
12487
+ if (type !== WASM_THREAD_INIT && type !== WASM_PROCESS_INIT) return;
12488
+ const refusal2 = sealOnce();
12453
12489
  if (type === WASM_THREAD_INIT) {
12490
+ if (refusal2) return failed5(refusal2.error);
12454
12491
  wasi().then((m) => m.runWasiThread(data, port2)).catch(failed5);
12455
12492
  return;
12456
12493
  }
12457
- if (type !== WASM_PROCESS_INIT) return;
12494
+ if (refusal2) return failed5(refusal2.error, NOT_RUNNABLE2);
12458
12495
  started(data, port2, run, wasi, js).then(
12459
12496
  (code2) => port2.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
12460
12497
  failed5
@@ -12463,8 +12500,18 @@ function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs)
12463
12500
  }
12464
12501
 
12465
12502
  // src/process-worker.ts
12503
+ init_process_fds();
12466
12504
  var scope = globalThis;
12467
12505
  var post = scope.postMessage.bind(scope);
12468
- var onMessage = processEntry({ postMessage: (message2) => post(message2) });
12506
+ var onMessage = processEntry(
12507
+ { postMessage: (message2) => post(message2) },
12508
+ void 0,
12509
+ void 0,
12510
+ void 0,
12511
+ () => {
12512
+ pinRootKind();
12513
+ lockdown();
12514
+ }
12515
+ );
12469
12516
  scope.addEventListener("message", (event) => onMessage(event.data));
12470
12517
  //# sourceMappingURL=process-worker.js.map