@threadedstack/wmd-web 0.1.61 → 0.1.62

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": "021fe8c375cb3c46735f03ac9695c7caa54636e4",
4
+ "commit": "0f4c8957ac8af45e9d26401f91e1321102907353",
5
5
  "previous": null,
6
6
  "decisions": [
7
7
  "D-388",
@@ -83,15 +83,16 @@
83
83
  "D-687",
84
84
  "D-688",
85
85
  "D-689",
86
- "D-690"
86
+ "D-690",
87
+ "D-691"
87
88
  ],
88
- "vmSources": "e7ea59770490110be23e658681ad89fd42abad5b",
89
+ "vmSources": "eedab6f96cad4777f4e9f945f1c81920df054c6f",
89
90
  "guest": {
90
91
  "arch": "arm64",
91
92
  "files": {
92
93
  "vm.wasm": {
93
- "sha256": "185d7226e24fd6bc18c2dfe3ff77be3e7010de5b5d54e064fbe0dbd0eb319abb",
94
- "bytes": 1579476
94
+ "sha256": "9da8344493105efb6d95af491e457832c8c093a159148b578a75714f8d38c54a",
95
+ "bytes": 1580846
95
96
  },
96
97
  "Image": {
97
98
  "sha256": "b7a8843d3469e2f5c32973ce2e6d663f90e07099ed2e9e9aee2ceac0e6a0685b",
@@ -181,11 +182,11 @@
181
182
  "guest/arm64/Image-4k": "55ab90773d080416f1539ae2caac0a49bb98e2bb34ce9384849725fb8e601551",
182
183
  "guest/arm64/features": "4dc6f2a114c7c87a67eb9f0fe53c52b6b8128bb30830a6be498432a3701587f4",
183
184
  "guest/arm64/initramfs.cpio.gz": "ac7c0fc194b059579943c3d8ceaa0757c3e3e248231c2ad779260e97d5084cd3",
184
- "guest/arm64/vm.wasm": "185d7226e24fd6bc18c2dfe3ff77be3e7010de5b5d54e064fbe0dbd0eb319abb",
185
+ "guest/arm64/vm.wasm": "9da8344493105efb6d95af491e457832c8c093a159148b578a75714f8d38c54a",
185
186
  "package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
186
187
  "src/base.js": "c79df2c3d4a6519fb9a6ef5cda39d66a5b9bc1a6dd009d21e7455e141943079f",
187
188
  "src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
188
- "src/boot.js": "c70c7391e7dc1c877b12183c64cd03daf2879f393c4b069fc9753003c717fe32",
189
+ "src/boot.js": "a6d17aa1a8b254101f0ea76739ac7d0be9e29f28e7fb414a826f17784b3c7ffd",
189
190
  "src/build/builder.js": "57a8436acc00147d031a42cccffe508f8deb3735b0ab4f9efcc2aa1cf7c6859c",
190
191
  "src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
191
192
  "src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
@@ -297,7 +298,7 @@
297
298
  "src/host/ckpt-chain.js": "c208a882da772acafe1373ea1d7e04723e26e870396d4202ef330d4eaf758596",
298
299
  "src/host/ckpt-file.js": "709344bfadf7c8151d51f70787b9e9d4b074ed1f5f80af113f11215851b9c28a",
299
300
  "src/host/ckpt-io.js": "92e437fb3b118c4269ecc4aafec6e17cf99936d3fc0c410e38f48b9146e791fb",
300
- "src/host/ckpt-point.js": "b0b204f40b7e292c3f1694f7308af570d52af728e574cd2c44bbc8f945b99625",
301
+ "src/host/ckpt-point.js": "3d0896281eaf3f49e9b97928dd941a32c20da7ddfc7b239d11712f762e90ec9f",
301
302
  "src/host/ckpt-save.js": "7bb07f536005fb5e7d9db6a09169a5ce1e3865d337ab65ce798a111334c6aa07",
302
303
  "src/host/ckpt.js": "371acb574e31e94201ae1ff32a7cfad85801ae3eae2896cde7d53a96430c502d",
303
304
  "src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
@@ -352,7 +353,7 @@
352
353
  "src/registry/pull.js": "24f2e01a76c9f7f27896af69b989f8c97f0ca31712b3e8110aaa5b5e3148b04b",
353
354
  "src/registry/ref.js": "24038e0fbcb6ac143cb8e8f7b9fac4dd0803d0891961786dc88dba01a4402e7b",
354
355
  "src/registry/wasi-mem.js": "8a8474a090a778db9eabfc2610f8c57f7f66b684ba7b7f8994aabd3ecb07a65a",
355
- "src/worker.js": "c654be359e741d5b1fde1be05f8909968d4e00d1fca61be169e60ea691daa662",
356
+ "src/worker.js": "80904f024ec99119f53b91a38e1b18277215246f45547bb93a097d69c973b832",
356
357
  "src/workers.json": "2dd90729f76d5867a3a2974cdc958b610340383fc81a7a4d651272ba15c7e7dc"
357
358
  },
358
359
  "builder": {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd-web",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
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.61",
13
- "commit": "021fe8c375cb3c46735f03ac9695c7caa54636e4",
12
+ "tag": "v0.1.62",
13
+ "commit": "0f4c8957ac8af45e9d26401f91e1321102907353",
14
14
  "web": "0.5.1"
15
15
  },
16
16
  "type": "module",
package/src/boot.js CHANGED
@@ -2626,6 +2626,7 @@ async function bootMachine(o) {
2626
2626
  nonzeroPages: c.mem.nonzero,
2627
2627
  memPages: c.mem.pages,
2628
2628
  scannedPages: c.mem.scannedPages,
2629
+ zeroRangePages: c.mem.zeroRangePages ?? 0, // IOS-6 (c): pages vm.wasm listed as zero (vm_zero_ranges), not read
2629
2630
  scanLimitBytes: c.mem.limitBytes,
2630
2631
  heapTopPage: c.mem.heapTopRet ? Math.ceil(c.mem.heapTopRet / CKPT_PAGE) : null,
2631
2632
  pagesAtOrAboveHeapTop: c.mem.heapTopRet ? Array.from(c.mem.index).filter(p => p >= Math.ceil(c.mem.heapTopRet / CKPT_PAGE)).length : null, // non-zero pages the checkpoint holds from the heap top up: 0 proves the heap-top bound
@@ -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.61' }
5
+ export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.62' }
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 },
@@ -146,12 +146,34 @@ export function touchedSkips(memory, desc) {
146
146
  }
147
147
  }
148
148
 
149
+ /**
150
+ * IOS-6 (c) (D-691): the pages a checkpoint need not read, from vm.wasm's vm_zero_ranges (guest/vm/include/vm/zero_ranges.h): ranges
151
+ * of memory 0 it knows hold only zero bytes at the point. `desc` is the address of {count, then count (offset, length) u32 pairs}.
152
+ * Returns skip(p): whether page p of memory 0 lies wholly inside one of them (a page a range only partly covers is read).
153
+ */
154
+ export function zeroRangeSkips(memory, desc) {
155
+ const total = memory.buffer.byteLength / PAGE
156
+ const n = Math.min(new Uint32Array(memory.buffer, desc, 1)[0], 64)
157
+ const d = new Uint32Array(memory.buffer, desc, 1 + 2 * n)
158
+ const spans = []
159
+ for (let i = 0; i < n; i++) {
160
+ const off = d[1 + 2 * i]
161
+ const lo = Math.ceil(off / PAGE)
162
+ const hi = Math.min(total, Math.floor((off + d[2 + 2 * i]) / PAGE)) // pages wholly inside, cut to the memory
163
+ if (hi > lo) spans.push([lo, hi])
164
+ }
165
+ return p => {
166
+ for (const [lo, hi] of spans) if (p >= lo && p < hi) return true
167
+ return false
168
+ }
169
+ }
170
+
149
171
  /**
150
172
  * The imports. memory: the machine's shared memory; ctl: the control block's Int32Array; post:
151
173
  * message to the page; goTimeoutMs: how long vCPU 0 waits for the page (a page that is gone
152
174
  * makes the point fail: the guest goes on, as it does for any failed point).
153
175
  */
154
- export function createCkptImports({ memory, ram = null, touched = () => null, ctl, post, scanLimit = null, verifyBound = false, useHeapTop = false, heapTop = () => null, goTimeoutMs = 60_000, now = () => performance.timeOrigin + performance.now() }) {
176
+ export function createCkptImports({ memory, ram = null, touched = () => null, zeroRanges = () => null, ctl, post, scanLimit = null, verifyBound = false, useHeapTop = false, heapTop = () => null, goTimeoutMs = 60_000, now = () => performance.timeOrigin + performance.now() }) {
155
177
  return {
156
178
  ctl_attach(wordAddr) {
157
179
  Atomics.store(ctl, CTL_CK_HOSTREQ, wordAddr >>> 0)
@@ -183,7 +205,14 @@ export function createCkptImports({ memory, ram = null, touched = () => null, ct
183
205
  // RAM in memory 0 starts at a 64 KiB boundary (memory.grow), so a skipped page is all RAM
184
206
  if (skips && (Number(new BigUint64Array(memory.buffer, desc, 6)[2]) % PAGE) !== 0) throw new Error('guest RAM is not page-aligned in memory 0')
185
207
  const copy = Atomics.load(ctl, CTL_CK_STREAM) !== 1
186
- cap = scanMemory(memory, { now, limitBytes: limit, verifyAbove: verifyBound, skip: skips ? skips.mem0 : null, copy })
208
+ // IOS-6 (c): and the ranges vm.wasm says are zero (its JIT tables' tails): not read, left out, zero again on a restore
209
+ const zr = zeroRanges()
210
+ const zskip = zr ? zeroRangeSkips(memory, zr) : null
211
+ let zeroRangePages = 0
212
+ const skip0 = skips ? skips.mem0 : null
213
+ const skip = zskip ? p => (zskip(p) ? (zeroRangePages++, true) : !!skip0 && skip0(p)) : skip0
214
+ cap = scanMemory(memory, { now, limitBytes: limit, verifyAbove: verifyBound, skip, copy })
215
+ cap.zeroRangePages = zeroRangePages
187
216
  cap.streamed = !copy
188
217
  cap.limitBytes = Number.isFinite(limit) ? limit : null
189
218
  // the live g_rsv {brk, end} of vm.wasm 50c6495e / 3aef93fc (linear address 4251160), next to what vm_heap_top() says
@@ -201,7 +230,7 @@ export function createCkptImports({ memory, ram = null, touched = () => null, ct
201
230
  Atomics.store(ctl, CTL_CK_GO, 0)
202
231
  return -12
203
232
  }
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] : [])])
233
+ post({ t: 'ckpt-mem', streamed: cap.streamed, index: cap.index, chunks: cap.chunks, pages: cap.pages, scannedPages: cap.scannedPages, skippedPages: cap.skippedPages, zeroRangePages: cap.zeroRangePages, 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] : [])])
205
234
  Atomics.wait(ctl, CTL_CK_GO, 0, Atomics.load(ctl, CTL_CK_GO_MS) || goTimeoutMs)
206
235
  // 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
236
  // 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)
package/src/worker.js CHANGED
@@ -168,8 +168,9 @@ async function run(m) {
168
168
  const chan = m.chan ? createChanImports({ sab: m.chan, memory, exiting: () => Atomics.load(ctl, CTL_EXIT) !== 0 }) : {}
169
169
  let heapTopFn = null // vm.wasm's vm_heap_top export, once the main thread has instantiated (null: a full scan)
170
170
  let touchedFn = null // vm.wasm's vm_touched_map export: the RAM pages the guest wrote (null: every page is read)
171
+ let zeroFn = null // IOS-6 (c): vm.wasm's vm_zero_ranges export: ranges of memory 0 it knows are zero (null: none)
171
172
  // P-B9: checkpoint support: wmd.ctl_attach and wmd.point (host/ckpt-point.js)
172
- const ckpt = m.ckpt ? createCkptImports({ memory, ram: m.ram || null, ctl, scanLimit: m.ckptScanLimit ?? null, verifyBound: !!m.ckptVerifyBound, useHeapTop: !!m.ckptUseHeapTop, heapTop: () => heapTopFn?.() ?? null, touched: () => touchedFn?.() ?? null, post: (msg, transfer) => self.postMessage(msg, transfer || []) }) : null
173
+ const ckpt = m.ckpt ? createCkptImports({ memory, ram: m.ram || null, ctl, scanLimit: m.ckptScanLimit ?? null, verifyBound: !!m.ckptVerifyBound, useHeapTop: !!m.ckptUseHeapTop, heapTop: () => heapTopFn?.() ?? null, touched: () => touchedFn?.() ?? null, zeroRanges: () => zeroFn?.() ?? null, post: (msg, transfer) => self.postMessage(msg, transfer || []) }) : null
173
174
  // the flat layout: guest RAM is the page's memory64 (host/ram-mem.js)
174
175
  const ramImports = m.ram ? createRamImports({ memory, ram: m.ram }) : null
175
176
  const wmd = createWmdImports({
@@ -254,6 +255,7 @@ async function run(m) {
254
255
  const inst = instantiate()
255
256
  if (typeof inst.exports.vm_heap_top === 'function') heapTopFn = () => Number(inst.exports.vm_heap_top())
256
257
  if (typeof inst.exports.vm_touched_map === 'function') touchedFn = () => inst.exports.vm_touched_map() >>> 0
258
+ if (typeof inst.exports.vm_zero_ranges === 'function') zeroFn = () => inst.exports.vm_zero_ranges() >>> 0
257
259
  self.postMessage({ t: 'ready', role, at: performance.timeOrigin + performance.now() })
258
260
  try {
259
261
  if (m.resume) {
package/wmdpack.wasm CHANGED
Binary file