@waffle-os/runtime 0.0.155 → 0.0.157

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.
Files changed (77) hide show
  1. package/browser/filesystem-backend.ts +11 -1
  2. package/browser/preview-protocol.ts +2 -0
  3. package/browser/preview.ts +128 -18
  4. package/browser/runtime-terminals.ts +65 -24
  5. package/browser/shared-fs.ts +141 -14
  6. package/browser/worker.ts +73 -6
  7. package/core/descriptors.ts +19 -2
  8. package/core/devices.ts +237 -2
  9. package/core/fd-reopen.ts +105 -20
  10. package/core/filesystem.ts +79 -0
  11. package/core/index.ts +4 -0
  12. package/core/open-file.ts +212 -18
  13. package/core/wasi.ts +449 -47
  14. package/dist/browser/filesystem-backend.js +4 -2
  15. package/dist/browser/preview.js +120 -17
  16. package/dist/browser/runtime-terminals.js +53 -10
  17. package/dist/browser/shared-fs.js +124 -11
  18. package/dist/browser/worker.js +59 -6
  19. package/dist/core/descriptors.js +9 -1
  20. package/dist/core/devices.js +211 -1
  21. package/dist/core/fd-reopen.js +79 -18
  22. package/dist/core/filesystem.js +14 -0
  23. package/dist/core/open-file.js +166 -13
  24. package/dist/core/wasi.js +402 -29
  25. package/dist/fs/backend.js +51 -3
  26. package/dist/fs/client.js +204 -7
  27. package/dist/fs/cold-read-cache.js +23 -0
  28. package/dist/fs/index.js +21 -1
  29. package/dist/fs/indexeddb.js +30 -2
  30. package/dist/fs/locks.js +1112 -0
  31. package/dist/fs/memory.js +126 -2
  32. package/dist/fs/multitab-backend.js +317 -196
  33. package/dist/fs/multitab-protocol.js +2 -0
  34. package/dist/fs/persistent.js +32 -7
  35. package/dist/fs/protocol.js +9 -3
  36. package/dist/fs/service.js +387 -22
  37. package/dist/fs/shared.js +54 -1
  38. package/dist/fs/storage-geometry.js +2 -0
  39. package/dist/interrupt/rewriter-internal.js +4 -1
  40. package/dist/proc/abi.js +80 -6
  41. package/dist/proc/errors.js +1 -0
  42. package/dist/proc/filesystem-codec.js +40 -9
  43. package/dist/proc/index.js +10 -1
  44. package/dist/proc/pty.js +193 -0
  45. package/dist/proc/worker-client.js +11 -2
  46. package/dist/proc/worker-pipes.js +51 -0
  47. package/dist/runtime.js +11 -2
  48. package/dist/search/engine.js +53 -0
  49. package/dist/tooling/program/program-transformer.json +1 -1
  50. package/fs/backend.ts +54 -2
  51. package/fs/client.ts +230 -6
  52. package/fs/cold-read-cache.ts +38 -0
  53. package/fs/index.ts +22 -1
  54. package/fs/indexeddb.ts +36 -2
  55. package/fs/locks.ts +1406 -0
  56. package/fs/memory.ts +132 -1
  57. package/fs/multitab-backend.ts +563 -304
  58. package/fs/multitab-protocol.ts +2 -0
  59. package/fs/persistent.ts +46 -4
  60. package/fs/protocol.ts +17 -5
  61. package/fs/service.ts +469 -23
  62. package/fs/shared.ts +60 -2
  63. package/fs/storage-geometry.ts +3 -0
  64. package/index.ts +2 -0
  65. package/interrupt/rewriter-internal.ts +4 -1
  66. package/package.json +2 -2
  67. package/proc/abi.ts +79 -6
  68. package/proc/errors.ts +1 -0
  69. package/proc/filesystem-codec.ts +39 -9
  70. package/proc/index.ts +11 -0
  71. package/proc/pty.ts +227 -0
  72. package/proc/worker-client.ts +28 -6
  73. package/proc/worker-pipes.ts +57 -0
  74. package/runtime.ts +12 -2
  75. package/search/engine.ts +49 -0
  76. package/testing/indexeddb-storage-browser.ts +173 -2
  77. package/tooling/program/program-transformer.json +1 -1
@@ -137,6 +137,7 @@ const PURE_STATELESS_READ_OPS = new Set([
137
137
  "lookup",
138
138
  "listFiles",
139
139
  "resolvePath",
140
+ "statPath",
140
141
  "stat",
141
142
  "permissions",
142
143
  "read",
@@ -144,6 +145,7 @@ const PURE_STATELESS_READ_OPS = new Set([
144
145
  "readlink",
145
146
  "resolve",
146
147
  "realpath",
148
+ "probe",
147
149
  "readdirPage"
148
150
  ]);
149
151
  export function isReplayableRead(operation, args) {
@@ -57,8 +57,8 @@ export class PersistentBackend extends MemoryBackend {
57
57
  nonce = crypto.randomUUID();
58
58
  renewing;
59
59
  coldReads = new ColdReadCache;
60
- constructor(storage, fs, reservation, index, intervalMs = 50, checkpointLimits, dirtyLimits = {}, startupRoot, sharedRoot) {
61
- super(fs, reservation, startupRoot, undefined, sharedRoot);
60
+ constructor(storage, fs, reservation, index, intervalMs = 50, checkpointLimits, dirtyLimits = {}, startupRoot, sharedRoot, machineId) {
61
+ super(fs, reservation, startupRoot, undefined, sharedRoot, machineId);
62
62
  this.storage = storage;
63
63
  this.dirtyLimits = dirtyLimits;
64
64
  this.initialWorkspaceId = reservation.workspace;
@@ -139,7 +139,10 @@ export class PersistentBackend extends MemoryBackend {
139
139
  return this.storage.terminalFailureReason?.();
140
140
  }
141
141
  setTerminalFailureListener(listener) {
142
- this.storage.setTerminalFailureListener?.(listener);
142
+ this.storage.setTerminalFailureListener?.((reason) => {
143
+ this.cancelTimer();
144
+ listener(reason);
145
+ });
143
146
  }
144
147
  hasPendingChanges() {
145
148
  if (this.dirty.size > 0 || this.removed.size > 0 || this.shared.publication)
@@ -149,7 +152,11 @@ export class PersistentBackend extends MemoryBackend {
149
152
  startTimer(intervalMs) {
150
153
  if (intervalMs > 0)
151
154
  this.timer = setInterval(() => {
152
- if (!this.stopped && !this.pendingCheckpoints && this.hasPendingChanges())
155
+ if (this.stopped || this.isTerminallyFailed()) {
156
+ this.cancelTimer();
157
+ return;
158
+ }
159
+ if (!this.pendingCheckpoints && this.hasPendingChanges())
153
160
  this.checkpoint().catch(() => {});
154
161
  }, intervalMs);
155
162
  }
@@ -163,11 +170,11 @@ export class PersistentBackend extends MemoryBackend {
163
170
  options.signal?.throwIfAborted();
164
171
  validateReservation(index, reservation);
165
172
  if (!index)
166
- return new PersistentBackend(storage, new MemFS, reservation, undefined, options.intervalMs, options.checkpointLimits, options.dirtyLimits, options.startupRoot, options.sharedRoot);
173
+ return new PersistentBackend(storage, new MemFS, reservation, undefined, options.intervalMs, options.checkpointLimits, options.dirtyLimits, options.startupRoot, options.sharedRoot, options.machineId);
167
174
  const fs = restoreTree(index);
168
175
  const root = fs.root;
169
176
  adoptInodes(root);
170
- const backend = new PersistentBackend(storage, fs, reservation, index, 0, options.checkpointLimits, options.dirtyLimits, options.startupRoot, options.sharedRoot);
177
+ const backend = new PersistentBackend(storage, fs, reservation, index, 0, options.checkpointLimits, options.dirtyLimits, options.startupRoot, options.sharedRoot, options.machineId);
171
178
  try {
172
179
  if (!index.nodes[0]?.identity) {
173
180
  await storage.flush();
@@ -322,17 +329,35 @@ export class PersistentBackend extends MemoryBackend {
322
329
  const cached = this.coldReads.read(key, offset, count);
323
330
  if (cached) {
324
331
  this.storage.checkPayload(key, size);
332
+ this.coldReads.noteRead(key, offset + count);
325
333
  return this.cachedDescriptorRange(cached, cancelled);
326
334
  }
335
+ const window = this.coldReads.readWindow(key, offset, count, size);
327
336
  const backing = this.coldBacking(node, key, undefined, cancelled);
337
+ this.coldReads.noteRead(key, offset + count);
328
338
  const drained = Promise.withResolvers();
329
339
  this.ownWork(drained.promise);
330
- return this.readDescriptorRange(backing, offset, count, cancelled).finally(() => {
340
+ const reply = this.readDescriptorWindow(backing, offset, count, window, cancelled);
341
+ return reply.finally(() => {
331
342
  const release = Promise.resolve().then(() => backing.retention.release());
332
343
  release.then(drained.resolve, drained.reject);
333
344
  return release;
334
345
  });
335
346
  }
347
+ async readDescriptorWindow(backing, offset, count, window, cancelled) {
348
+ if (window.offset === offset && window.length === count)
349
+ return this.readDescriptorRange(backing, offset, count, cancelled);
350
+ try {
351
+ const bytes = await this.readDescriptorRange(backing, window.offset, window.length, cancelled);
352
+ return bytes.slice(offset - window.offset, offset - window.offset + count);
353
+ } catch (error) {
354
+ if (cancelled() || this.stopped)
355
+ throw new FilesystemError(11);
356
+ if (error instanceof FilesystemError && error.errno === 11)
357
+ throw error;
358
+ return this.readDescriptorRange(backing, offset, count, cancelled);
359
+ }
360
+ }
336
361
  async readDescriptorRange(backing, offset, length, cancelled) {
337
362
  if (cancelled() || this.stopped)
338
363
  throw new FilesystemError(11);
@@ -170,23 +170,29 @@ function identityPublication(parent, publication, owner, construction) {
170
170
  }
171
171
  return domain;
172
172
  }
173
- export function createProcessFilesystemIdentity(parent) {
173
+ export function createProcessFilesystemIdentity(parent, posixOwner) {
174
174
  const identity = createFilesystemIdentity(parent);
175
175
  identity.revocations = identity.revocations.slice(0, 1);
176
+ if (posixOwner !== undefined)
177
+ identity.posixOwner = posixOwner;
176
178
  return identity;
177
179
  }
178
180
  export function releaseFilesystemReservation(reservation) {
179
181
  const state = new Int32Array(reservation.state);
180
182
  if (Atomics.exchange(state, 0, 1))
181
- return;
183
+ return false;
182
184
  const target = new Int32ArrayConstructor(reservation.target, 0, CAPABILITY_LENGTH);
183
185
  for (;; ) {
184
186
  const count = Atomics.load(target, reservation.targetKey + 1);
185
187
  if (count <= 0 || Atomics.compareExchange(target, reservation.targetKey + 1, count, count - 1) === count)
186
188
  break;
187
189
  }
188
- if (Atomics.compareExchange(state, 1, 0, 2) === 0)
190
+ if (Atomics.compareExchange(state, 1, 0, 2) === 0) {
191
+ if (reservation.ofd)
192
+ Atomics.sub(new Int32ArrayConstructor(reservation.ofd), 6, 1);
189
193
  Atomics.sub(new Int32ArrayConstructor(reservation.source, 0, CAPABILITY_LENGTH), reservation.sourceKey + 2, 1);
194
+ }
195
+ return true;
190
196
  }
191
197
  export function reserveIdentityCapability(source, handle, target) {
192
198
  const section = new FilesystemSection(source);