@threadedstack/wmd-web 0.1.56 → 0.1.58

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/README.md CHANGED
@@ -3039,3 +3039,12 @@ attributes the guest has seen across a cache drop (the page's `ck.dropNames()`),
3039
3039
  An embedder does nothing to get the twin: update the package and call `containerBundle` and `bootWmd` as before, with no line of twin code. `bootWmd` reads the pins (`src/gowasm/pins-data.js`, a JS module that ships in the package, no request), adds the stub mounts to the bundle's spec and sets the service's `gowasm` field from it; the image decides (an image with no Go compile, or a Go release with no pin, runs as before and downloads nothing). The twin's module (41 to 53 MB per Go release) is fetched by the twin's Worker on first use from an ordered list of sources (`GOWASM_SOURCES_DEFAULT` in `src/gowasm/setup.js`: the npm registry, then jsDelivr, then unpkg; `gowasm: false` turns the twin off): the first that gives the pinned sha256 and size wins, a source that fails, stalls, is too big, refuses the file or has a wrong hash is left for the next (jsDelivr refuses files over 50 MB, so for the largest twin the working sources are the registry tarball and unpkg: each release needs only one source that works), and when all fail the guest compiles, with one `gowasm-off` event that names each source. Source kinds: `{ kind: 'tgz', url }` (an npm registry tarball) and `{ kind: 'file', base }` (`<base>/<file>`); only the pins name the package. The module is kept in Cache Storage of the page's origin under a key that holds its hash (checked again at each boot). The twin is on in Chromium, Firefox and WebKit. (D-666 had it off in WebKit: a bundled embedder's machine never came up there with it. The cause was WebKit evaluating the channel service's Worker script a second time when the bundler's edge-go chunk imported it; the channel service now starts from `src/host/chan-service-entry.js`, which imports nothing, #86.) `GOWASM_ENGINES_OFF` in `src/gowasm/boot-setup.js` is the per-engine off switch (empty); `gowasm: { <engine>: true }` turns the twin on in an engine named there. What a consumer may pass to `bootWmd`: `gowasm: false` (off), `gowasm: { sources: [...] }`, `gowasm: { base: 'https://.../gowasm' }` (the override for an app that serves its own copy of the files `compile-<go release>.wasm`), `gowasm: { limits }`. An app with no Content-Security-Policy has nothing to do. An app with a policy that has `connect-src` adds one origin, `https://registry.npmjs.org` (the first source; jsDelivr and unpkg are only fallbacks, so they need not be listed), or names a source of its own that the policy allows with `gowasm: { sources: [...] }`. A source the policy blocks is left for the next one without a request, and when all are blocked the guest compiles and the `gowasm-off` event says what blocked each (the directive and the origin to add; in Playwright's WebKit the page gets no violation event from the twin's Worker, so the reason is the browser's own text with a hint naming `connect-src`); knowing that all three are blocked took 21 to 25 ms in Chromium and 22 to 28 ms in Firefox (counted once, under shared load). Test page words: `gowasm=1`, `gowasm=auto` (only a table the page states by `gowasmtools=<url>` or `<meta name="wmd-gowasm-table" content="<url>">`), `gowasmbase=<url>`. A checkpoint keeps the twin choice it was taken with (a checkpoint taken with the twin always restores: with `gowasm: false` the stub mounts stay, no twin Worker starts, every compile runs in the guest, one `gowasm-off` event, rule `checkpoint-twin`; one taken without it restores without it). Headers, limits, the cache, the checkpoint rule and the images that carry a listed compile: `docs/gowasm-twin.md`.
3040
3040
 
3041
3041
  Off is off: with `gowasm: false` (or no twin source and no table) there is no twin file requested, no twin Worker started, no stub mount in the container (the guest's `/proc/mounts` has none), and no event. What the page does load is four small library modules that main's page does not, because the checkpoint rule needs the twin's spec text even when the twin is off: `src/gowasm/boot-setup.js`, `src/gowasm/setup.js`, `src/gowasm/pins-data.js` and `src/host/gowasm-guard.js`, 4 requests and 39,808 bytes uncompressed (counted once in Chromium against a copy of `origin/main`'s `web/`: 228 requests against 225, 65 distinct paths against 61; `web/test/x6/fix10-count.spec.js`). Nothing else differs in what the page asks for.
3042
+
3043
+ ## IOS-7: mobile WebKit runs vm.wasm in interp (D-686)
3044
+
3045
+ On a real iPhone the Safari tab dies around the guest kernel's `paging_init` with `--mode jit`; `--mode interp` boots. So in mobile
3046
+ WebKit (iPhone, iPad, every iOS browser, iPadOS in desktop mode) `bootWmd` replaces a `--mode jit` in `args` with `--mode interp`
3047
+ with no change in the embedder, on every boot and restore path (`vmModeFor` in `src/boot.js`). `bootWmd({mobileJit: true})` keeps
3048
+ jit; a caller's own `interp` stays; desktop browsers keep jit. The `memory` boot event carries `mode: 'interp', reason: 'mobile-webkit'`
3049
+ when it replaced the mode. The boot key uses the caller's args, so checkpoints and base snapshots restore across the two modes
3050
+ without a refusal. Tests: `test/unit/ios7-mobile-interp.test.js`; `test/e2e/ios7-mobile-interp.spec.js` (WebKit with the iPhone 13 profile).
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": "4973de42b060011074f3156af508e9b3442abb65",
5
5
  "previous": null,
6
6
  "decisions": [
7
7
  "D-388",
@@ -78,7 +78,8 @@
78
78
  "D-659",
79
79
  "D-660",
80
80
  "D-661",
81
- "D-666"
81
+ "D-666",
82
+ "D-686"
82
83
  ],
83
84
  "vmSources": "2a7e60f9e7f01494c5141ec1ac9e38435b7f6ace",
84
85
  "guest": {
@@ -156,7 +157,7 @@
156
157
  }
157
158
  },
158
159
  "files": {
159
- "README.md": "d3df924d7206641a8eeff3b5cd99dbfd26a8ca51013846ad98745f3e4ae57f79",
160
+ "README.md": "62fe86fdab0dd16a79503200ba6410970f52b7f580682201835f158ca05292f4",
160
161
  "edge-site/own/HASHES.txt": "4d83edcb41399bb89eb7b1f89115886d739adac887bdde59a8d33e3a4602683a",
161
162
  "edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
162
163
  "edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
@@ -180,7 +181,7 @@
180
181
  "package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
181
182
  "src/base.js": "c79df2c3d4a6519fb9a6ef5cda39d66a5b9bc1a6dd009d21e7455e141943079f",
182
183
  "src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
183
- "src/boot.js": "d6d45757bbae9949de7ce0dad18c5acd3c50c64bb30cb7b1c9c155a8231ab671",
184
+ "src/boot.js": "671d05752dcd5606115ac8ee27dfa9d4b4cc0b645faefbc2b979670c3f41c34e",
184
185
  "src/build/builder.js": "57a8436acc00147d031a42cccffe508f8deb3735b0ab4f9efcc2aa1cf7c6859c",
185
186
  "src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
186
187
  "src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
@@ -284,7 +285,7 @@
284
285
  "src/host/base-cache.js": "83fd8f28779446eff5dff096856e868416117cd7330d1ce7a8a06c4a10b1a111",
285
286
  "src/host/base-file.js": "edb47c1eeb6b1cec627fa5894512185336b15d3f5db96a7151a8a57b34b4a2e8",
286
287
  "src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
287
- "src/host/boot-events.js": "4af19b460a18b5c4e18c3a30d3cf1e843d4881b823a4f1b052a8cad4cea6cd2b",
288
+ "src/host/boot-events.js": "51991fe83705605ddeb4cc5d2fc3d3ba5ea4a2e9200fd60dd32ac834a506d61a",
288
289
  "src/host/chan-service-entry.js": "18f602f9ad72323e930157cb0820568f3ef83ce49b9672443791b01551f0ffd3",
289
290
  "src/host/chan-service.js": "d61afdcbe1a6929dd93a2f7e842c8b94c8d742db59359004d08ec3997b154288",
290
291
  "src/host/chan-services.js": "e7f52931b6ef76a8b97b793d0a1d86fb35d20dbca3dd333d18cc4ded0806c9f7",
@@ -292,7 +293,7 @@
292
293
  "src/host/ckpt-chain.js": "c208a882da772acafe1373ea1d7e04723e26e870396d4202ef330d4eaf758596",
293
294
  "src/host/ckpt-file.js": "709344bfadf7c8151d51f70787b9e9d4b074ed1f5f80af113f11215851b9c28a",
294
295
  "src/host/ckpt-io.js": "92e437fb3b118c4269ecc4aafec6e17cf99936d3fc0c410e38f48b9146e791fb",
295
- "src/host/ckpt-point.js": "e08441b52d65b18c91f7e14b6ab3ad347572a0ac96a6642cf8072b47dde404eb",
296
+ "src/host/ckpt-point.js": "b0b204f40b7e292c3f1694f7308af570d52af728e574cd2c44bbc8f945b99625",
296
297
  "src/host/ckpt-save.js": "7bb07f536005fb5e7d9db6a09169a5ce1e3865d337ab65ce798a111334c6aa07",
297
298
  "src/host/ckpt.js": "371acb574e31e94201ae1ff32a7cfad85801ae3eae2896cde7d53a96430c502d",
298
299
  "src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
@@ -315,7 +316,7 @@
315
316
  "src/host/jit-hub.js": "cf3fc9f9d4e3fb50c41d6de5e2523f380d3c6c1feaf61c15d90cde89aec2f4c3",
316
317
  "src/host/jit-snap.js": "3932f36047c9edeb7f59282d1c37fef19c8f5a9fe4bd0192fb93aa64030fe51d",
317
318
  "src/host/jit.js": "72ef7334506fde2b3724cee93b52a987fbd6d45473b8de93d914db8a80ae9e17",
318
- "src/host/layout.js": "c878b8da956da3ebc2391cf802869f12b3d74c131ffbcb9879536617728beeac",
319
+ "src/host/layout.js": "287f9f86da57506a7fa706a2ff401a49902dca6ccb9b9dfa78eb6aebfcf4a6cc",
319
320
  "src/host/monitor.js": "ae1741ba35668bcc6192642246494433b175668933921634c699af5a0a69acc0",
320
321
  "src/host/opfs-avail.js": "a98945c0f1792f29bc0147de662173cc9275a43dbeb44ec575ecb8ee44d5f122",
321
322
  "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.58",
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.58",
13
+ "commit": "4973de42b060011074f3156af508e9b3442abb65",
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'
@@ -413,6 +414,22 @@ export function isMobileWebKit(nav = globalThis.navigator) {
413
414
  return /\b(iPhone|iPad|iPod)\b/.test(ua) || (/Macintosh/.test(ua) && (nav?.maxTouchPoints || 0) > 1)
414
415
  }
415
416
 
417
+ /**
418
+ * IOS-7 (D-686): the vm.wasm arguments for this browser. On a real iPhone every wmd version killed the Safari tab around the guest
419
+ * kernel's paging_init with '--mode jit' (vm.wasm's block emitter, even with the JIT imports stubbed); '--mode interp' boots and runs
420
+ * commands. So in mobile WebKit an '--mode jit' in the caller's args (wmn and wmr pass it explicitly) is replaced by 'interp', unless
421
+ * `mobileJit` is true (testing, or once Apple fixes it). A caller's own 'interp' stays. Returns {args, event}: `args` is the same
422
+ * array when nothing changes; `event` is {mode:'interp', reason:'mobile-webkit'} when it was rewritten, else null.
423
+ */
424
+ export function vmModeFor(args, { nav = globalThis.navigator, mobileJit = false } = {}) {
425
+ if (mobileJit || !isMobileWebKit(nav)) return { args, event: null }
426
+ const i = args.indexOf('--mode')
427
+ if (i < 0 || args[i + 1] !== 'jit') return { args, event: null }
428
+ const out = [...args]
429
+ out[i + 1] = 'interp'
430
+ return { args: out, event: { mode: 'interp', reason: 'mobile-webkit' } }
431
+ }
432
+
416
433
  /**
417
434
  * D-516: whether bootWmd asks for W21's heap reserve when the caller does not say. Not in mobile WebKit: there the
418
435
  * reserve (the memory grown to its maximum before boot) costs the whole maximum at once, 2.4 GiB with a 1 GiB guest,
@@ -928,7 +945,8 @@ export function diskArgs(args, disk) {
928
945
  * @param {object} [o.disk] a disk from openDisk (host/disk.js): the guest gets it as virtio-blk
929
946
  * /dev/vda (vm.wasm's --swap MiB sizes the device) with wmd.disk=data on the kernel line, so guest init leaves
930
947
  * it alone. A machine with a disk takes no checkpoints: guest memory and the disk would not match
931
- * @param {boolean} [o.heapReserve] W21 (default true, false in mobile WebKit: heapReserveDefault, D-516): vm.wasm grows its memory to the maximum
948
+ * @param {boolean} [o.mobileJit] IOS-7 (D-686): keep the caller's '--mode jit' in mobile WebKit (default false: it runs interp there, vmModeFor). The 'memory' boot event says mode:'interp', reason:'mobile-webkit' when it was replaced
949
+ * @param {boolean} [o.heapReserve] W21 (default true, false in mobile WebKit: heapReserveDefault, D-516): vm.wasm grows its memory to the maximum
932
950
  * before any thread starts (WMD_HEAP_RESERVE=1), so memory never grows under running
933
951
  * vCPUs. Chromium checks memory.fill/copy against a per-Worker size that lags another
934
952
  * Worker's grow, and trapped (README "W21"). An env entry WMD_HEAP_RESERVE=... wins.
@@ -1006,6 +1024,8 @@ export function diskArgs(args, disk) {
1006
1024
  * checkpoint(): memory 0, the 9P service's files and fids, the JIT slot list and the fd table, taken while the
1007
1025
  * guest is stopped at its checkpoint point. Needs channels with a 9P service, and the same options to restore.
1008
1026
  * @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)
1027
+ * @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
1028
+ * takes longer fails (code 'gave-up'): the guest goes on, the file the save wrote is removed
1009
1029
  * @param {number} [o.checkpointScanLimit] P-B9: bytes of memory 0 a checkpoint reads (default all). Above it pages are taken as zero:
1010
1030
  * only safe with the guest's real heap top (WebKit commits every page a scan reads, W34)
1011
1031
  * @param {object} [o.restore] P-B9: a checkpoint ({header, sections}, from vm.checkpoint() or a store's load())
@@ -1075,7 +1095,12 @@ async function bootMachine(o) {
1075
1095
  if (o.checkpoint || o.restore || o.restoreLazy) throw new TypeError('a machine with a disk takes no checkpoints')
1076
1096
  o = { ...o, args: diskArgs(o.args, o.disk) }
1077
1097
  }
1078
- const argv = ['vm.wasm', ...o.args]
1098
+ // IOS-7: mobile WebKit runs vm.wasm in interp. Every boot and restore (vm.restore(), bootWmd({restore}), a base snapshot) comes through here.
1099
+ // The boot key and the base snapshot's command-line check use the caller's own args (keyArgv), so a snapshot taken with jit restores on
1100
+ // a phone and one taken on a phone restores with jit elsewhere; only the argv vm.wasm runs with changes.
1101
+ const keyArgv = ['vm.wasm', ...o.args]
1102
+ const modeChoice = vmModeFor(o.args, { mobileJit: o.mobileJit })
1103
+ const argv = modeChoice.event ? ['vm.wasm', ...modeChoice.args] : keyArgv
1079
1104
  const env = vmEnv(o.env, o.heapReserve ?? heapReserveDefault())
1080
1105
  // the default Worker is started from a literal new URL(..., import.meta.url) so bundlers (Vite, webpack)
1081
1106
  // see it and bundle worker.js with its imports; a variable URL is copied as a plain asset (2.15)
@@ -1283,7 +1308,7 @@ async function bootMachine(o) {
1283
1308
  const se = baseStorageEvent(lazyIn.info) // IOS-3: no OPFS here (a private window): the snapshot is in memory only
1284
1309
  if (se) be.now('storage', se)
1285
1310
  checkVmKeyFits(h, vmKey)
1286
- checkArgvFits(h, argv) // IOS-2: another command line (a 1024 MiB base under a 256 MiB request) is refused before its body is read
1311
+ checkArgvFits(h, keyArgv) // IOS-2: another command line (a 1024 MiB base under a 256 MiB request) is refused before its body is read
1287
1312
  settleLayout(chooseLayout(o.args, o, h)) // X24 default: the base snapshot's own layout
1288
1313
  // part 4: and its own twin choice. The spec text is first used by the boot key and by the channel service's Worker, both below this point in this same
1289
1314
  // try, so the choice made here is made before either has it; only the layers and ports of the services were used before (their packs download meanwhile)
@@ -1352,7 +1377,7 @@ async function bootMachine(o) {
1352
1377
  } else {
1353
1378
  // the boot key samples each pack (head and tail); packs is the full digest of every layer (a SHA-256 tree over 8 MiB pieces), recorded in
1354
1379
  // every checkpoint this boot takes and checked against a base snapshot's before it is used
1355
- const [k, pk] = await raceAbort(Promise.all([bootKeyOf({ vmKey, argv, env, preopen, files, services: chanSvcs.map((s, i) => ({ ...s, layers: chanLayers[i] })), maxPages: maximum }), packDigestsOf(chanLayers)]))
1380
+ const [k, pk] = await raceAbort(Promise.all([bootKeyOf({ vmKey, argv: keyArgv, env, preopen, files, services: chanSvcs.map((s, i) => ({ ...s, layers: chanLayers[i] })), maxPages: maximum }), packDigestsOf(chanLayers)]))
1356
1381
  bootKey = k.key
1357
1382
  bootDesc = k.desc
1358
1383
  packs = pk
@@ -1421,6 +1446,7 @@ async function bootMachine(o) {
1421
1446
  const memoryInitialBytes = memory.buffer.byteLength
1422
1447
  const ctlSab = createControl()
1423
1448
  const ctl = new Int32Array(ctlSab)
1449
+ if (o.ckptGoTimeoutMs > 0) Atomics.store(ctl, CTL_CK_GO_MS, Math.min(o.ckptGoTimeoutMs, 2 ** 31 - 1) | 0)
1424
1450
  if (restoreIn) {
1425
1451
  // The fd table now; the memory pages when the main thread has made its instance (restoreMemory, from the
1426
1452
  // 'resume-instantiated' message): vm.wasm's start function must see an untouched memory (worker.js).
@@ -1839,7 +1865,7 @@ async function bootMachine(o) {
1839
1865
  }, [...(netPort ? [netPort] : []), ...(gowasmPort ? [gowasmPort] : [])])
1840
1866
  consoleGate = consoleInputGate(chanSab, o.channels.consoleInputBytes ?? CONSOLE_IN_LIMIT)
1841
1867
  }
1842
- be.now('memory', { t: 'boot', stage: 'memory', state: 'done', initialBytes: memoryInitialBytes, maxBytes: maximum * PAGE, ringBytes: stdio.byteLength + (chanSab ? chanSab.byteLength : 0), tookMs: Math.round(memTook) })
1868
+ be.now('memory', { t: 'boot', stage: 'memory', state: 'done', ...(modeChoice.event || {}), initialBytes: memoryInitialBytes, maxBytes: maximum * PAGE, ringBytes: stdio.byteLength + (chanSab ? chanSab.byteLength : 0), tookMs: Math.round(memTook) })
1843
1869
  // W24: each 9P service's writable layer (its upper), from the service's stats (every 250 ms while they change); an
1844
1870
  // event when it is first seen and on each change of 1 MiB or more
1845
1871
  const layerSeen = new Map()
@@ -2178,6 +2204,7 @@ async function bootMachine(o) {
2178
2204
  case 'ckpt-point':
2179
2205
  case 'ckpt-mem':
2180
2206
  case 'ckpt-failed':
2207
+ case 'ckpt-gaveup':
2181
2208
  case 'ckpt-mem-error':
2182
2209
  ckptEvent(m)
2183
2210
  break
@@ -2430,7 +2457,8 @@ async function bootMachine(o) {
2430
2457
  clearTimeout(c.timer)
2431
2458
  clearInterval(c.poll)
2432
2459
  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
2460
+ // 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)
2461
+ Atomics.compareExchange(ctl, CTL_CK_GO, 0, 2)
2434
2462
  Atomics.notify(ctl, CTL_CK_GO)
2435
2463
  }
2436
2464
  c.reject(err)
@@ -2440,6 +2468,7 @@ async function bootMachine(o) {
2440
2468
  const c = ck
2441
2469
  if (!c) return // a point nobody asked for (or one that timed out): nothing to do
2442
2470
  if (m.t === 'ckpt-failed') return ckptFail(new CheckpointError('point', `the guest could not take the checkpoint: ${m.why} (the machine goes on)`))
2471
+ if (m.t === 'ckpt-gaveup') return ckptGaveUp(m.waitedMs)
2443
2472
  if (m.t === 'ckpt-mem-error') return ckptFail(new CheckpointError('memory', `copying the guest's memory failed: ${m.message}`))
2444
2473
  if (m.t === 'ckpt-point') {
2445
2474
  c.atPoint = true
@@ -2511,10 +2540,9 @@ async function bootMachine(o) {
2511
2540
  return
2512
2541
  }
2513
2542
  Atomics.store(ctl, CTL_CK_STREAM, 0)
2543
+ if (!giveGo(ctl)) return ckptGaveUp(null) // vCPU 0 stopped waiting before this go (IOS-6): what was read is not one instant
2514
2544
  c.went = true
2515
2545
  c.goAt = gnow()
2516
- Atomics.store(ctl, CTL_CK_GO, 1)
2517
- Atomics.notify(ctl, CTL_CK_GO, 1)
2518
2546
  // the guest runs again when its ctl thread attaches once more (the end of the pause)
2519
2547
  c.poll = setInterval(() => {
2520
2548
  if (Atomics.load(ctl, CTL_CK_ATTACHES) > c.attachesBefore || gnow() - c.goAt > 15000) {
@@ -2625,6 +2653,26 @@ async function bootMachine(o) {
2625
2653
  * 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
2654
  * then does the guest go on. The page never holds a copy of the guest's memory.
2627
2655
  */
2656
+ /**
2657
+ * 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
2658
+ * 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
2659
+ * it was written, else when its save ends (a save that fails removes its own partial file, ckpt-file.js saveVersioned).
2660
+ */
2661
+ function ckptGaveUp(waitedMs) {
2662
+ const c = ck
2663
+ if (!c || c.went) return
2664
+ c.gaveUp = true
2665
+ const s = c.stream
2666
+ if (s && c.streamDone) dropGaveUpFile(c)
2667
+ const waited = waitedMs ?? Atomics.load(ctl, CTL_CK_GO_MS) ?? 0
2668
+ 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` : ''}`))
2669
+ }
2670
+ function dropGaveUpFile(c) {
2671
+ if (c.dropped) return
2672
+ c.dropped = true
2673
+ c.stream.store.delete(c.stream.name).catch(() => {}) // the save wrote it after the guest went on (absent: the save failed and removed it)
2674
+ }
2675
+
2628
2676
  async function ckptStreamSave(c) {
2629
2677
  try {
2630
2678
  const names = await netNameList()
@@ -2637,6 +2685,7 @@ async function bootMachine(o) {
2637
2685
  // IOS-2 parent: a diff over that checkpoint, made by the store's Worker from the frozen memory itself
2638
2686
  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
2687
  const saved = await c.stream.store.save(c.stream.name, ckpt, c.stream.parent ? { parent: c.stream.parent, memory, index: c.mem.index } : undefined)
2688
+ if (c.gaveUp) return dropGaveUpFile(c)
2640
2689
  if (ck !== c) return
2641
2690
  c.savedResult = { header: ckpt.header, saved, streamed: true }
2642
2691
  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.58' }
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 },
@@ -3,7 +3,7 @@
3
3
  // {t:'boot', stage:'download', state:'progress'|'done', file, bytes, total, cached, atMs, tookMs?} per file
4
4
  // {t:'boot', stage:'download', state:'done', fileBytes, layerBytes, atMs, tookMs} all files in
5
5
  // {t:'boot', stage:'compile', state:'start'|'done', moduleBytes, reused, atMs, tookMs?}
6
- // {t:'boot', stage:'memory', state:'done', initialBytes, maxBytes, ringBytes, atMs, tookMs}
6
+ // {t:'boot', stage:'memory', state:'done', initialBytes, maxBytes, ringBytes, atMs, tookMs, mode?:'interp', reason?:'mobile-webkit'} (mode, reason: IOS-7, only when mobile WebKit replaced the caller's --mode jit)
7
7
  // {t:'boot', stage:'workers', state:'progress'|'done', workers:[{id, role, state, atMs, tid?}], vcpus, jitShared, atMs, tookMs?}
8
8
  // {t:'boot', stage:'kernel', state:'start'|'done', atMs, tookMs?}
9
9
  // {t:'boot', stage:'restore', state:'progress'|'done', bytes, total, source, atMs, tookMs?}
@@ -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