@threadedstack/wmd-web 0.1.57 → 0.1.59

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": "b2494d5ce63e0e690a906bee35b2bada872d5c16",
4
+ "commit": "9692d8c2eb46b83435b5de1c56c7cebe573001ab",
5
5
  "previous": null,
6
6
  "decisions": [
7
7
  "D-388",
@@ -78,15 +78,17 @@
78
78
  "D-659",
79
79
  "D-660",
80
80
  "D-661",
81
- "D-666"
81
+ "D-666",
82
+ "D-686",
83
+ "D-687"
82
84
  ],
83
- "vmSources": "2a7e60f9e7f01494c5141ec1ac9e38435b7f6ace",
85
+ "vmSources": "e7ea59770490110be23e658681ad89fd42abad5b",
84
86
  "guest": {
85
87
  "arch": "arm64",
86
88
  "files": {
87
89
  "vm.wasm": {
88
- "sha256": "7d16efadd83097e9b9188410187fb929b4ee5afbcb22cd387deebf1206b52376",
89
- "bytes": 1575966
90
+ "sha256": "185d7226e24fd6bc18c2dfe3ff77be3e7010de5b5d54e064fbe0dbd0eb319abb",
91
+ "bytes": 1579476
90
92
  },
91
93
  "Image": {
92
94
  "sha256": "b7a8843d3469e2f5c32973ce2e6d663f90e07099ed2e9e9aee2ceac0e6a0685b",
@@ -156,7 +158,7 @@
156
158
  }
157
159
  },
158
160
  "files": {
159
- "README.md": "d3df924d7206641a8eeff3b5cd99dbfd26a8ca51013846ad98745f3e4ae57f79",
161
+ "README.md": "62fe86fdab0dd16a79503200ba6410970f52b7f580682201835f158ca05292f4",
160
162
  "edge-site/own/HASHES.txt": "4d83edcb41399bb89eb7b1f89115886d739adac887bdde59a8d33e3a4602683a",
161
163
  "edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
162
164
  "edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
@@ -176,11 +178,11 @@
176
178
  "guest/arm64/Image-4k": "55ab90773d080416f1539ae2caac0a49bb98e2bb34ce9384849725fb8e601551",
177
179
  "guest/arm64/features": "4dc6f2a114c7c87a67eb9f0fe53c52b6b8128bb30830a6be498432a3701587f4",
178
180
  "guest/arm64/initramfs.cpio.gz": "ac7c0fc194b059579943c3d8ceaa0757c3e3e248231c2ad779260e97d5084cd3",
179
- "guest/arm64/vm.wasm": "7d16efadd83097e9b9188410187fb929b4ee5afbcb22cd387deebf1206b52376",
181
+ "guest/arm64/vm.wasm": "185d7226e24fd6bc18c2dfe3ff77be3e7010de5b5d54e064fbe0dbd0eb319abb",
180
182
  "package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
181
183
  "src/base.js": "c79df2c3d4a6519fb9a6ef5cda39d66a5b9bc1a6dd009d21e7455e141943079f",
182
184
  "src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
183
- "src/boot.js": "d9d8f46bb69400cd8b659eace150ebc5fc14190d8eb84a421b1c9f2f3cda9b71",
185
+ "src/boot.js": "671d05752dcd5606115ac8ee27dfa9d4b4cc0b645faefbc2b979670c3f41c34e",
184
186
  "src/build/builder.js": "57a8436acc00147d031a42cccffe508f8deb3735b0ab4f9efcc2aa1cf7c6859c",
185
187
  "src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
186
188
  "src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
@@ -284,7 +286,7 @@
284
286
  "src/host/base-cache.js": "83fd8f28779446eff5dff096856e868416117cd7330d1ce7a8a06c4a10b1a111",
285
287
  "src/host/base-file.js": "edb47c1eeb6b1cec627fa5894512185336b15d3f5db96a7151a8a57b34b4a2e8",
286
288
  "src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
287
- "src/host/boot-events.js": "4af19b460a18b5c4e18c3a30d3cf1e843d4881b823a4f1b052a8cad4cea6cd2b",
289
+ "src/host/boot-events.js": "51991fe83705605ddeb4cc5d2fc3d3ba5ea4a2e9200fd60dd32ac834a506d61a",
288
290
  "src/host/chan-service-entry.js": "18f602f9ad72323e930157cb0820568f3ef83ce49b9672443791b01551f0ffd3",
289
291
  "src/host/chan-service.js": "d61afdcbe1a6929dd93a2f7e842c8b94c8d742db59359004d08ec3997b154288",
290
292
  "src/host/chan-services.js": "e7f52931b6ef76a8b97b793d0a1d86fb35d20dbca3dd333d18cc4ded0806c9f7",
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd-web",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
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.57",
13
- "commit": "b2494d5ce63e0e690a906bee35b2bada872d5c16",
12
+ "tag": "v0.1.59",
13
+ "commit": "9692d8c2eb46b83435b5de1c56c7cebe573001ab",
14
14
  "web": "0.5.1"
15
15
  },
16
16
  "type": "module",
package/src/boot.js CHANGED
@@ -414,6 +414,22 @@ export function isMobileWebKit(nav = globalThis.navigator) {
414
414
  return /\b(iPhone|iPad|iPod)\b/.test(ua) || (/Macintosh/.test(ua) && (nav?.maxTouchPoints || 0) > 1)
415
415
  }
416
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
+
417
433
  /**
418
434
  * D-516: whether bootWmd asks for W21's heap reserve when the caller does not say. Not in mobile WebKit: there the
419
435
  * reserve (the memory grown to its maximum before boot) costs the whole maximum at once, 2.4 GiB with a 1 GiB guest,
@@ -929,7 +945,8 @@ export function diskArgs(args, disk) {
929
945
  * @param {object} [o.disk] a disk from openDisk (host/disk.js): the guest gets it as virtio-blk
930
946
  * /dev/vda (vm.wasm's --swap MiB sizes the device) with wmd.disk=data on the kernel line, so guest init leaves
931
947
  * it alone. A machine with a disk takes no checkpoints: guest memory and the disk would not match
932
- * @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
933
950
  * before any thread starts (WMD_HEAP_RESERVE=1), so memory never grows under running
934
951
  * vCPUs. Chromium checks memory.fill/copy against a per-Worker size that lags another
935
952
  * Worker's grow, and trapped (README "W21"). An env entry WMD_HEAP_RESERVE=... wins.
@@ -1078,7 +1095,12 @@ async function bootMachine(o) {
1078
1095
  if (o.checkpoint || o.restore || o.restoreLazy) throw new TypeError('a machine with a disk takes no checkpoints')
1079
1096
  o = { ...o, args: diskArgs(o.args, o.disk) }
1080
1097
  }
1081
- 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
1082
1104
  const env = vmEnv(o.env, o.heapReserve ?? heapReserveDefault())
1083
1105
  // the default Worker is started from a literal new URL(..., import.meta.url) so bundlers (Vite, webpack)
1084
1106
  // see it and bundle worker.js with its imports; a variable URL is copied as a plain asset (2.15)
@@ -1286,7 +1308,7 @@ async function bootMachine(o) {
1286
1308
  const se = baseStorageEvent(lazyIn.info) // IOS-3: no OPFS here (a private window): the snapshot is in memory only
1287
1309
  if (se) be.now('storage', se)
1288
1310
  checkVmKeyFits(h, vmKey)
1289
- 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
1290
1312
  settleLayout(chooseLayout(o.args, o, h)) // X24 default: the base snapshot's own layout
1291
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
1292
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)
@@ -1355,7 +1377,7 @@ async function bootMachine(o) {
1355
1377
  } else {
1356
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
1357
1379
  // every checkpoint this boot takes and checked against a base snapshot's before it is used
1358
- 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)]))
1359
1381
  bootKey = k.key
1360
1382
  bootDesc = k.desc
1361
1383
  packs = pk
@@ -1843,7 +1865,7 @@ async function bootMachine(o) {
1843
1865
  }, [...(netPort ? [netPort] : []), ...(gowasmPort ? [gowasmPort] : [])])
1844
1866
  consoleGate = consoleInputGate(chanSab, o.channels.consoleInputBytes ?? CONSOLE_IN_LIMIT)
1845
1867
  }
1846
- 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) })
1847
1869
  // W24: each 9P service's writable layer (its upper), from the service's stats (every 250 ms while they change); an
1848
1870
  // event when it is first seen and on each change of 1 MiB or more
1849
1871
  const layerSeen = new Map()
@@ -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.57' }
5
+ export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.59' }
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?}
package/wmdpack.wasm CHANGED
Binary file