@threadedstack/wmd-web 0.1.56 → 0.1.57

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.
package/RELEASE.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wmd-web",
3
3
  "version": "0.5.1",
4
- "commit": "463e95761838ed52762c879bae9518a33eb677b5",
4
+ "commit": "b2494d5ce63e0e690a906bee35b2bada872d5c16",
5
5
  "previous": null,
6
6
  "decisions": [
7
7
  "D-388",
@@ -180,7 +180,7 @@
180
180
  "package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
181
181
  "src/base.js": "c79df2c3d4a6519fb9a6ef5cda39d66a5b9bc1a6dd009d21e7455e141943079f",
182
182
  "src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
183
- "src/boot.js": "d6d45757bbae9949de7ce0dad18c5acd3c50c64bb30cb7b1c9c155a8231ab671",
183
+ "src/boot.js": "d9d8f46bb69400cd8b659eace150ebc5fc14190d8eb84a421b1c9f2f3cda9b71",
184
184
  "src/build/builder.js": "57a8436acc00147d031a42cccffe508f8deb3735b0ab4f9efcc2aa1cf7c6859c",
185
185
  "src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
186
186
  "src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
@@ -292,7 +292,7 @@
292
292
  "src/host/ckpt-chain.js": "c208a882da772acafe1373ea1d7e04723e26e870396d4202ef330d4eaf758596",
293
293
  "src/host/ckpt-file.js": "709344bfadf7c8151d51f70787b9e9d4b074ed1f5f80af113f11215851b9c28a",
294
294
  "src/host/ckpt-io.js": "92e437fb3b118c4269ecc4aafec6e17cf99936d3fc0c410e38f48b9146e791fb",
295
- "src/host/ckpt-point.js": "e08441b52d65b18c91f7e14b6ab3ad347572a0ac96a6642cf8072b47dde404eb",
295
+ "src/host/ckpt-point.js": "b0b204f40b7e292c3f1694f7308af570d52af728e574cd2c44bbc8f945b99625",
296
296
  "src/host/ckpt-save.js": "7bb07f536005fb5e7d9db6a09169a5ce1e3865d337ab65ce798a111334c6aa07",
297
297
  "src/host/ckpt.js": "371acb574e31e94201ae1ff32a7cfad85801ae3eae2896cde7d53a96430c502d",
298
298
  "src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
@@ -315,7 +315,7 @@
315
315
  "src/host/jit-hub.js": "cf3fc9f9d4e3fb50c41d6de5e2523f380d3c6c1feaf61c15d90cde89aec2f4c3",
316
316
  "src/host/jit-snap.js": "3932f36047c9edeb7f59282d1c37fef19c8f5a9fe4bd0192fb93aa64030fe51d",
317
317
  "src/host/jit.js": "72ef7334506fde2b3724cee93b52a987fbd6d45473b8de93d914db8a80ae9e17",
318
- "src/host/layout.js": "c878b8da956da3ebc2391cf802869f12b3d74c131ffbcb9879536617728beeac",
318
+ "src/host/layout.js": "287f9f86da57506a7fa706a2ff401a49902dca6ccb9b9dfa78eb6aebfcf4a6cc",
319
319
  "src/host/monitor.js": "ae1741ba35668bcc6192642246494433b175668933921634c699af5a0a69acc0",
320
320
  "src/host/opfs-avail.js": "a98945c0f1792f29bc0147de662173cc9275a43dbeb44ec575ecb8ee44d5f122",
321
321
  "src/host/p9mount.js": "cd27abd769b19ed8b26050ddd8b6d61f81faa5a431924217dd0bf2593258d5b9",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd-web",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/threadedstack/wmd-releases",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
11
11
  "wmd": {
12
- "tag": "v0.1.56",
13
- "commit": "463e95761838ed52762c879bae9518a33eb677b5",
12
+ "tag": "v0.1.57",
13
+ "commit": "b2494d5ce63e0e690a906bee35b2bada872d5c16",
14
14
  "web": "0.5.1"
15
15
  },
16
16
  "type": "module",
package/src/boot.js CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  CTL_POOL_N,
24
24
  CTL_CK_ATTACHES,
25
25
  CTL_CK_GO,
26
+ CTL_CK_GO_MS,
26
27
  CTL_CK_RESTORED,
27
28
  CTL_CK_STREAM,
28
29
  CTL_SPAWN_FAIL,
@@ -47,7 +48,7 @@ import {
47
48
  } from './host/chan.js'
48
49
  import { ControlClient } from './host/ctl.js'
49
50
  import { chooseTwin, eventsOf, putBackTwin, specKeysDiffering, twinForBoot } from './gowasm/boot-setup.js'
50
- import { PAGE as CKPT_PAGE, requestCheckpoint } from './host/ckpt-point.js'
51
+ import { PAGE as CKPT_PAGE, giveGo, requestCheckpoint } from './host/ckpt-point.js'
51
52
  import {
52
53
  CheckpointError, serviceErrorCode, assembleCheckpoint, memChunksOf, bootKeyForChoice, specChoice, bootKeyOf, checkCheckpointFits, checkPacksFit, checkVmKeyFits, checkArgvFits, packDigestsOf, fdTableBytes, parseCheckpoint, restoreFdTable, resumePorts, sha256Hex, validateFdTable,
53
54
  } from './host/ckpt.js'
@@ -1006,6 +1007,8 @@ export function diskArgs(args, disk) {
1006
1007
  * checkpoint(): memory 0, the 9P service's files and fids, the JIT slot list and the fd table, taken while the
1007
1008
  * guest is stopped at its checkpoint point. Needs channels with a 9P service, and the same options to restore.
1008
1009
  * @param {boolean} [o.checkpointHeapTop] P-B9: bound the scan at vm.wasm's vm_heap_top() (default on, W58: false reads all of memory 0)
1010
+ * @param {number} [o.ckptGoTimeoutMs] IOS-6 (a): how long the guest's vCPU 0 waits at a checkpoint for the page (default 60 s). A streamed save that
1011
+ * takes longer fails (code 'gave-up'): the guest goes on, the file the save wrote is removed
1009
1012
  * @param {number} [o.checkpointScanLimit] P-B9: bytes of memory 0 a checkpoint reads (default all). Above it pages are taken as zero:
1010
1013
  * only safe with the guest's real heap top (WebKit commits every page a scan reads, W34)
1011
1014
  * @param {object} [o.restore] P-B9: a checkpoint ({header, sections}, from vm.checkpoint() or a store's load())
@@ -1421,6 +1424,7 @@ async function bootMachine(o) {
1421
1424
  const memoryInitialBytes = memory.buffer.byteLength
1422
1425
  const ctlSab = createControl()
1423
1426
  const ctl = new Int32Array(ctlSab)
1427
+ if (o.ckptGoTimeoutMs > 0) Atomics.store(ctl, CTL_CK_GO_MS, Math.min(o.ckptGoTimeoutMs, 2 ** 31 - 1) | 0)
1424
1428
  if (restoreIn) {
1425
1429
  // The fd table now; the memory pages when the main thread has made its instance (restoreMemory, from the
1426
1430
  // 'resume-instantiated' message): vm.wasm's start function must see an untouched memory (worker.js).
@@ -2178,6 +2182,7 @@ async function bootMachine(o) {
2178
2182
  case 'ckpt-point':
2179
2183
  case 'ckpt-mem':
2180
2184
  case 'ckpt-failed':
2185
+ case 'ckpt-gaveup':
2181
2186
  case 'ckpt-mem-error':
2182
2187
  ckptEvent(m)
2183
2188
  break
@@ -2430,7 +2435,8 @@ async function bootMachine(o) {
2430
2435
  clearTimeout(c.timer)
2431
2436
  clearInterval(c.poll)
2432
2437
  if (c.atPoint && !c.went) {
2433
- Atomics.store(ctl, CTL_CK_GO, 2) // the guest's vCPU 0 is waiting for us: tell it the checkpoint failed
2438
+ // the guest's vCPU 0 is waiting for us: tell it the checkpoint failed (unless it has given up already: that value stays, IOS-6)
2439
+ Atomics.compareExchange(ctl, CTL_CK_GO, 0, 2)
2434
2440
  Atomics.notify(ctl, CTL_CK_GO)
2435
2441
  }
2436
2442
  c.reject(err)
@@ -2440,6 +2446,7 @@ async function bootMachine(o) {
2440
2446
  const c = ck
2441
2447
  if (!c) return // a point nobody asked for (or one that timed out): nothing to do
2442
2448
  if (m.t === 'ckpt-failed') return ckptFail(new CheckpointError('point', `the guest could not take the checkpoint: ${m.why} (the machine goes on)`))
2449
+ if (m.t === 'ckpt-gaveup') return ckptGaveUp(m.waitedMs)
2443
2450
  if (m.t === 'ckpt-mem-error') return ckptFail(new CheckpointError('memory', `copying the guest's memory failed: ${m.message}`))
2444
2451
  if (m.t === 'ckpt-point') {
2445
2452
  c.atPoint = true
@@ -2511,10 +2518,9 @@ async function bootMachine(o) {
2511
2518
  return
2512
2519
  }
2513
2520
  Atomics.store(ctl, CTL_CK_STREAM, 0)
2521
+ if (!giveGo(ctl)) return ckptGaveUp(null) // vCPU 0 stopped waiting before this go (IOS-6): what was read is not one instant
2514
2522
  c.went = true
2515
2523
  c.goAt = gnow()
2516
- Atomics.store(ctl, CTL_CK_GO, 1)
2517
- Atomics.notify(ctl, CTL_CK_GO, 1)
2518
2524
  // the guest runs again when its ctl thread attaches once more (the end of the pause)
2519
2525
  c.poll = setInterval(() => {
2520
2526
  if (Atomics.load(ctl, CTL_CK_ATTACHES) > c.attachesBefore || gnow() - c.goAt > 15000) {
@@ -2625,6 +2631,26 @@ async function bootMachine(o) {
2625
2631
  * memory (vCPU 0 found the non-zero pages and copied none), the store's Worker pulls them one at a time through its one reused buffer, and only
2626
2632
  * then does the guest go on. The page never holds a copy of the guest's memory.
2627
2633
  */
2634
+ /**
2635
+ * IOS-6 (a): vCPU 0 stopped waiting for the page's go (CTL_CK_GO_MS, 60 s) and the guest went on: what a save read after that is not the
2636
+ * frozen machine. The checkpoint fails at once (`ck` is cleared: the next one can run) and the file this save wrote is removed, now when
2637
+ * it was written, else when its save ends (a save that fails removes its own partial file, ckpt-file.js saveVersioned).
2638
+ */
2639
+ function ckptGaveUp(waitedMs) {
2640
+ const c = ck
2641
+ if (!c || c.went) return
2642
+ c.gaveUp = true
2643
+ const s = c.stream
2644
+ if (s && c.streamDone) dropGaveUpFile(c)
2645
+ const waited = waitedMs ?? Atomics.load(ctl, CTL_CK_GO_MS) ?? 0
2646
+ ckptFail(new CheckpointError('gave-up', `the guest stopped waiting for the page after ${Math.round((waited || 60_000) / 1000)} s at its checkpoint and went on: the checkpoint was abandoned${s ? `, and its file ${JSON.stringify(s.name)} is removed` : ''}`))
2647
+ }
2648
+ function dropGaveUpFile(c) {
2649
+ if (c.dropped) return
2650
+ c.dropped = true
2651
+ c.stream.store.delete(c.stream.name).catch(() => {}) // the save wrote it after the guest went on (absent: the save failed and removed it)
2652
+ }
2653
+
2628
2654
  async function ckptStreamSave(c) {
2629
2655
  try {
2630
2656
  const names = await netNameList()
@@ -2637,6 +2663,7 @@ async function bootMachine(o) {
2637
2663
  // IOS-2 parent: a diff over that checkpoint, made by the store's Worker from the frozen memory itself
2638
2664
  if (c.stream.parent && c.mem.ram) throw new CheckpointError('malformed', 'a diff checkpoint (save.parent) needs the RAM in memory 0; this machine keeps it in a memory of its own')
2639
2665
  const saved = await c.stream.store.save(c.stream.name, ckpt, c.stream.parent ? { parent: c.stream.parent, memory, index: c.mem.index } : undefined)
2666
+ if (c.gaveUp) return dropGaveUpFile(c)
2640
2667
  if (ck !== c) return
2641
2668
  c.savedResult = { header: ckpt.header, saved, streamed: true }
2642
2669
  c.streamDone = true
@@ -2,7 +2,7 @@
2
2
  // The files of node in the sandboxed frame: the path under a source (the option edge: { sources } of bootWmd), the role the frame gives the file, its
3
3
  // sha256 and its size. The page accepts a file only when it has exactly this sha256 and size. The notice files travel with the rest.
4
4
  // EDGE_PACKAGE is the package that holds these files, for the {name} {version} {file} of a registry source's url (null: none named).
5
- export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.56' }
5
+ export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.57' }
6
6
  export const EDGE_PINS = [
7
7
  { path: 'wmd_browser_bg.wasm', role: 'wasm', sha256: '1e3db7f2c5f4be0ee44e5f2c0205cf8ca11f906d9addd5512915fad4821661c2', size: 6334959 },
8
8
  { path: 'wmd_browser.js', role: 'glue', sha256: 'b389b072096881ba39b22cd705d3a230af02acc5409c61fb4f997d1081c4df6f', size: 75647 },
@@ -16,7 +16,21 @@
16
16
  // every checkpoint when the vCPUs run again. The page writes a request kind into the word at
17
17
  // word_addr (guest memory) and notifies it; the ctl thread hands it to vCPU 0.
18
18
 
19
- import { CTL_CK_ATTACHES, CTL_CK_GO, CTL_CK_HOSTREQ, CTL_CK_POINTS, CTL_CK_STREAM } from './layout.js'
19
+ import { CTL_CK_ATTACHES, CTL_CK_GO, CTL_CK_GO_MS, CTL_CK_HOSTREQ, CTL_CK_POINTS, CTL_CK_STREAM } from './layout.js'
20
+
21
+ /**
22
+ * IOS-6 (a): CTL_CK_GO's value once vCPU 0 stopped waiting for the page (the guest went on, its memory is no longer frozen). Set by one
23
+ * compare-and-swap against the page's go (giveGo), so exactly one of them wins; it stays until the next point.
24
+ */
25
+ export const CK_GO_GAVE_UP = 3
26
+
27
+ /** The page's go to vCPU 0 waiting at its point: true when it was given, false when vCPU 0 had already given up (CK_GO_GAVE_UP). */
28
+ export function giveGo(ctl) {
29
+ const prev = Atomics.compareExchange(ctl, CTL_CK_GO, 0, 1)
30
+ if (prev === CK_GO_GAVE_UP) return false
31
+ Atomics.notify(ctl, CTL_CK_GO, 1)
32
+ return true
33
+ }
20
34
 
21
35
  export const PAGE = 65536
22
36
  /** struct vm_snapshot_hdr (guest/vm/include/vm/snapshot.h), 336 bytes: field offsets read here. */
@@ -188,11 +202,16 @@ export function createCkptImports({ memory, ram = null, touched = () => null, ct
188
202
  return -12
189
203
  }
190
204
  post({ t: 'ckpt-mem', streamed: cap.streamed, index: cap.index, chunks: cap.chunks, pages: cap.pages, scannedPages: cap.scannedPages, skippedPages: cap.skippedPages, ramScannedPages: cap.ram?.scannedPages, ramSkippedPages: cap.ram?.skippedPages, aboveNonzero: cap.aboveNonzero, brkLive: cap.brkLive, endLive: cap.endLive, heapTopRet: cap.heapTopRet, limitBytes: cap.limitBytes, nonzero: cap.nonzero, scanMs: cap.scanMs, copyMs: cap.copyMs, ram: cap.ram ? { index: cap.ram.index, chunks: cap.ram.chunks, pages: cap.ram.pages, nonzero: cap.ram.nonzero, scanMs: cap.ram.scanMs, copyMs: cap.ram.copyMs } : null, doneAt: now() }, [cap.index.buffer, ...cap.chunks, ...(cap.ram ? [cap.ram.index.buffer, ...cap.ram.chunks] : [])])
191
- const r = Atomics.wait(ctl, CTL_CK_GO, 0, goTimeoutMs)
192
- const go = Atomics.load(ctl, CTL_CK_GO)
205
+ Atomics.wait(ctl, CTL_CK_GO, 0, Atomics.load(ctl, CTL_CK_GO_MS) || goTimeoutMs)
206
+ // IOS-6 (a): no answer in time: give up in the cell itself, so a go that comes later is refused (giveGo) and the page knows its
207
+ // save read a memory that was no longer frozen; and say so at once (a save that never ends would otherwise leave the page waiting)
208
+ const go = Atomics.compareExchange(ctl, CTL_CK_GO, 0, CK_GO_GAVE_UP)
209
+ if (go === 0) {
210
+ post({ t: 'ckpt-gaveup', waitedMs: now() - at })
211
+ return -1
212
+ }
193
213
  Atomics.store(ctl, CTL_CK_GO, 0)
194
- if (r === 'timed-out' || go !== 1) return -1
195
- return 0
214
+ return go === 1 ? 0 : -1
196
215
  },
197
216
  }
198
217
  }
@@ -89,6 +89,9 @@ export const CTL_CK_RESTORED = CKPT_BASE + 4 // restore: the page has written th
89
89
  // store saves them (vm.checkpoint({save})), and lets vCPU 0 go after the save. 0: the point copies them, as before
90
90
  export const CTL_CK_STREAM = CKPT_BASE + 5
91
91
 
92
+ // IOS-6 (a): how long vCPU 0 waits at a point for the page's go, ms (0: its default, 60 s); bootWmd({ckptGoTimeoutMs}) sets it
93
+ export const CTL_CK_GO_MS = CKPT_BASE + 7
94
+
92
95
  export const CTL_INTS = CKPT_BASE + 8
93
96
  export const CTL_BYTES = CTL_INTS * 4
94
97
 
package/wmdpack.wasm CHANGED
Binary file