@waffle-os/runtime 0.0.150 → 0.0.152

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.
@@ -211,6 +211,8 @@ export function isPeerMessage(value) {
211
211
  return typeof value.reqId === "number" && typeof value.op === "string" && Array.isArray(value.args);
212
212
  case "chunk-put":
213
213
  return typeof value.reqId === "number" && typeof value.uploadId === "string" && typeof value.offset === "number" && typeof value.totalBytes === "number" && value.chunk instanceof Uint8Array;
214
+ case "chunk-abort":
215
+ return typeof value.uploadId === "string";
214
216
  case "chunk-get":
215
217
  return typeof value.reqId === "number" && typeof value.downloadId === "string" && typeof value.offset === "number" && typeof value.length === "number";
216
218
  case "res":
@@ -973,14 +973,36 @@ export class FilesystemService {
973
973
  return;
974
974
  }
975
975
  if (operation === "flush" || operation === "sync") {
976
- const flushing = this.backend.flush?.(operation === "sync" ? a : typeof a === "string" ? a : undefined);
977
- return this.trackRequestWork(session, Promise.resolve(flushing)).then(() => this.finishResult(session, id, operation, operation === "sync" ? 0 : undefined));
976
+ const target = operation === "sync" ? a : typeof a === "string" ? a : undefined;
977
+ if (operation === "sync")
978
+ this.backend.retain(a);
979
+ let flushing;
980
+ try {
981
+ flushing = this.backend.flush?.(target);
982
+ } catch (error) {
983
+ if (operation === "sync")
984
+ this.backend.release(a);
985
+ throw error;
986
+ }
987
+ return this.trackRequestWork(session, Promise.resolve(flushing)).then(() => {
988
+ if (operation === "sync")
989
+ this.backend.release(a);
990
+ return this.finishResult(session, id, operation, operation === "sync" ? 0 : undefined);
991
+ }, (error) => {
992
+ if (operation === "sync")
993
+ this.backend.release(a);
994
+ throw error;
995
+ });
978
996
  }
979
997
  if (operation === "resolve" && session.socketScope && this.backend instanceof MemoryBackend) {
980
998
  const result = this.backend.fs.resolveSocket(a, b, c === true);
981
999
  return this.finishResult(session, id, operation, result, args);
982
1000
  }
983
- const result = this.backend.execute(operation, args, data);
1001
+ const isCancelled = () => {
1002
+ const pending = session.pending.get(id);
1003
+ return !pending || sessionRevoked(session) || !this.sessions.has(session) || requestCancelled(pending);
1004
+ };
1005
+ const result = this.backend.execute(operation, args, data, isCancelled);
984
1006
  if (result instanceof Promise)
985
1007
  return this.trackRequestWork(session, result).then((value) => this.finishResult(session, id, operation, value, args));
986
1008
  return this.finishResult(session, id, operation, result, args);
@@ -1,4 +1,4 @@
1
- export const INTERRUPT_REWRITER_REVISION = 7;
1
+ export const INTERRUPT_REWRITER_REVISION = 8;
2
2
  const encoder = new TextEncoder;
3
3
  const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
4
4
  const HEADER = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0]);
@@ -27,6 +27,7 @@ const runtimeProcSignatures = new Map([
27
27
  ["wait_job", { params: [127, 127, 127], results: [127] }],
28
28
  ["kill", { params: [127, 127], results: [127] }],
29
29
  ["kill_job", { params: [127, 127], results: [127] }],
30
+ ["probe_process", { params: [127], results: [127] }],
30
31
  ["start_status", { params: [127], results: [127] }],
31
32
  ["poll", { params: [127, 127, 127, 127], results: [127] }],
32
33
  ["interrupted", { params: [], results: [127] }],
package/dist/proc/abi.js CHANGED
@@ -53,6 +53,7 @@ import {
53
53
  ProcessError,
54
54
  Signal,
55
55
  checkedJobLifetime,
56
+ checkedKillSignal,
56
57
  checkedProcessCwd,
57
58
  checkedProcessKind,
58
59
  snapshotLogicalProcessIdentity
@@ -146,17 +147,30 @@ export class ProcessABI {
146
147
  wait: (pid, ptr) => this.result(() => this.wait(pid, ptr)),
147
148
  wait_job: (job, flags, ptr) => this.result(() => this.waitJob(job, flags, ptr)),
148
149
  kill: (pid, signal) => this.result(() => {
149
- if (options.service.canSignal?.(options.pid, pid) === false)
150
- return -63;
151
- options.service.kill(pid, signal);
150
+ const sig = checkedKillSignal(signal);
151
+ const allowed = sig === 0 && options.service.canProbe ? options.service.canProbe(options.pid, pid) : options.service.canSignal?.(options.pid, pid);
152
+ if (allowed === false)
153
+ return -ProcessErrno.PERM;
154
+ if (sig === 0 && allowed === true)
155
+ return 0;
156
+ options.service.kill(pid, sig);
152
157
  return 0;
153
158
  }),
154
159
  kill_job: (job, signal) => this.result(() => {
155
- if (options.service.canSignalJob?.(options.pid, job) === false)
156
- return -63;
157
- options.service.killJob(job, signal);
160
+ const sig = checkedKillSignal(signal);
161
+ const allowed = sig === 0 && options.service.canProbeJob ? options.service.canProbeJob(options.pid, job) : options.service.canSignalJob?.(options.pid, job);
162
+ if (allowed === false)
163
+ return -ProcessErrno.PERM;
164
+ if (sig === 0 && allowed === true)
165
+ return 0;
166
+ options.service.killJob(job, sig);
158
167
  return 0;
159
168
  }),
169
+ probe_process: (pid) => this.result(() => {
170
+ if (!options.service.canSignalProcess)
171
+ return -NOSYS;
172
+ return options.service.canSignalProcess(options.pid, pid) ? 0 : -ProcessErrno.PERM;
173
+ }),
160
174
  start_status: (pid) => this.result(() => options.service.startStatus(options.pid, pid)),
161
175
  poll: (ptr, count, timeout, out) => this.result(() => this.poll(ptr, count, timeout, out)),
162
176
  interrupted: () => this.interrupted(),
@@ -290,6 +290,117 @@ export function* directoryGroups(directory) {
290
290
  }
291
291
  }
292
292
  }
293
+ export function peekDirectoryProcess(directory, pid) {
294
+ const capacity = directoryCapacity(directory);
295
+ const processes = new BigInt64ArrayConstructor(directory, HEADER_BYTES, capacity * PROCESS_WORDS);
296
+ for (let slot = 0;slot < capacity; slot++) {
297
+ const token = atomicsLoad(processes, slot * PROCESS_WORDS);
298
+ if ((token & 0xffffffffn) !== 1n || Number(token >> 32n) !== pid)
299
+ continue;
300
+ try {
301
+ const state = directoryState({ directory, slot, pid });
302
+ if (controlLoad(state.jobPending, 0) >= 0)
303
+ return state;
304
+ } catch (error) {
305
+ if (!isCollectedProcess(error))
306
+ throw error;
307
+ }
308
+ }
309
+ return;
310
+ }
311
+ export function peekDirectoryProcessesByLogicalPid(directory, processId, callerSlot, callerPid) {
312
+ const matches = [];
313
+ if (!Number.isInteger(processId) || processId <= 0 || processId > 2147483647)
314
+ return matches;
315
+ const capacity = directoryCapacity(directory);
316
+ const processes = new BigInt64ArrayConstructor(directory, HEADER_BYTES, capacity * PROCESS_WORDS);
317
+ for (let slot = 0;slot < capacity; slot++) {
318
+ const base = slot * PROCESS_WORDS;
319
+ const token = atomicsLoad(processes, base);
320
+ if ((token & 0xffffffffn) !== 1n)
321
+ continue;
322
+ const pid = Number(token >> 32n);
323
+ if (callerSlot !== undefined && slot === callerSlot && pid !== callerPid)
324
+ continue;
325
+ if (atomicsLoad(processes, base + PROCESS_ID) !== packedControl(pid, processId))
326
+ continue;
327
+ try {
328
+ const state = directoryState({ directory, slot, pid });
329
+ if (controlLoad(state.jobPending, 0) >= 0)
330
+ arrayAppend(matches, state);
331
+ } catch (error) {
332
+ if (!isCollectedProcess(error))
333
+ throw error;
334
+ }
335
+ }
336
+ return matches;
337
+ }
338
+ export function probeDirectoryProcess(directory, callerPid, pid) {
339
+ const target = peekDirectoryProcess(directory, pid);
340
+ if (!target)
341
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
342
+ try {
343
+ return directoryControls(directory, () => {
344
+ controlLoad(target.controlParent);
345
+ return target.pid;
346
+ }, callerPid);
347
+ } catch (error) {
348
+ if (isCollectedProcess(error))
349
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
350
+ throw error;
351
+ }
352
+ }
353
+ export function probeDirectoryLogicalPid(directory, callerPid, processId, callerSlot) {
354
+ const matches = peekDirectoryProcessesByLogicalPid(directory, processId, callerSlot, callerPid);
355
+ let found = false;
356
+ for (let index = 0;index < matches.length; index++) {
357
+ const target = matches[index];
358
+ try {
359
+ const controlled = directoryControls(directory, () => {
360
+ controlLoad(target.controlParent);
361
+ return target.pid;
362
+ }, callerPid);
363
+ found = true;
364
+ if (controlled)
365
+ return true;
366
+ } catch (error) {
367
+ if (!isCollectedProcess(error))
368
+ throw error;
369
+ }
370
+ }
371
+ if (!found)
372
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${processId}`);
373
+ return false;
374
+ }
375
+ export function probeDirectoryJob(directory, callerPid, job) {
376
+ const group = peekDirectoryJob(directory, job);
377
+ if (!group)
378
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
379
+ try {
380
+ return directoryControls(directory, () => controlLoad(group.controlParent), callerPid, true);
381
+ } catch (error) {
382
+ if (isCollectedProcess(error))
383
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
384
+ throw error;
385
+ }
386
+ }
387
+ export function peekDirectoryJob(directory, id) {
388
+ for (let slot = 0;slot < directoryCapacity(directory); slot++) {
389
+ const raw = row(directory, slot, true);
390
+ const token = atomicsLoad(raw, 0);
391
+ if ((token & 0xffffffffn) !== 1n || Number(token >> 32n) !== id)
392
+ continue;
393
+ try {
394
+ if (controlLoad(cells(raw, id, 4)) < 0)
395
+ return;
396
+ return directoryJob(directory, slot, id);
397
+ } catch (error) {
398
+ if (!isCollectedProcess(error))
399
+ throw error;
400
+ }
401
+ }
402
+ return;
403
+ }
293
404
  export function findDirectoryJob(directory, id) {
294
405
  for (let slot = 0;slot < directoryCapacity(directory); slot++) {
295
406
  const raw = row(directory, slot, true), token = atomicsLoad(raw, 0), current = Number(token >> 32n);
@@ -16,5 +16,6 @@ export const ProcessErrno = objectFreeze({
16
16
  INVAL: 28,
17
17
  NOMEM: 48,
18
18
  NOTSUP: 58,
19
+ PERM: 63,
19
20
  SRCH: 71
20
21
  });
@@ -1,5 +1,13 @@
1
1
  import { admitProcessObservation, captureNativeReturn } from "./observation.js";
2
- import { directoryState, directoryHasProcessSibling } from "./directory.js";
2
+ import {
3
+ directoryState,
4
+ directoryHasProcessSibling,
5
+ peekDirectoryJob,
6
+ peekDirectoryProcess,
7
+ probeDirectoryJob,
8
+ probeDirectoryLogicalPid,
9
+ probeDirectoryProcess
10
+ } from "./directory.js";
3
11
  import { allocateSharedControl } from "../memory/control.js";
4
12
  import {
5
13
  isInstance,
@@ -51,7 +59,7 @@ import {
51
59
  ProcessErrno,
52
60
  ProcessError,
53
61
  Signal,
54
- checkedSignal,
62
+ checkedKillSignal,
55
63
  checkedJobLifetime,
56
64
  checkedProcessCwd,
57
65
  snapshotSpawnWorker,
@@ -281,9 +289,23 @@ export class ProcessSupervisor {
281
289
  this.access(pid, id).owner.requests.delete(id);
282
290
  return 0;
283
291
  }
284
- canSignal(callerPid, pid) {
285
- this.table.require(callerPid);
286
- this.table.require(pid);
292
+ requireLiveCaller(callerPid) {
293
+ const caller = this.table.require(callerPid);
294
+ if (this.disposed || caller.result !== null || readOutcome(caller.outcome))
295
+ throw new ProcessError(ProcessErrno.SRCH, "process has exited");
296
+ return caller;
297
+ }
298
+ callerDirectory(caller) {
299
+ return isInstance(caller.outcome, OutcomeCell) ? caller.outcome.validity.buffer : undefined;
300
+ }
301
+ isLiveDirectoryRecord(record) {
302
+ return !isInstance(record.outcome, OutcomeCell) || peekDirectoryProcess(record.outcome.validity.buffer, record.pid) !== undefined;
303
+ }
304
+ isLiveDirectoryJob(jobId) {
305
+ const directory = this.table.jobDirectory(jobId);
306
+ return !directory || peekDirectoryJob(directory, jobId) !== undefined;
307
+ }
308
+ controls(callerPid, pid) {
287
309
  let target = pid;
288
310
  while (target !== undefined && target !== 0) {
289
311
  if (target === callerPid)
@@ -292,13 +314,84 @@ export class ProcessSupervisor {
292
314
  }
293
315
  return false;
294
316
  }
317
+ canSignal(callerPid, pid) {
318
+ const caller = this.requireLiveCaller(callerPid);
319
+ const target = this.table.require(pid);
320
+ if (caller.rootPid === undefined || target.rootPid !== caller.rootPid)
321
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
322
+ return this.controls(callerPid, pid);
323
+ }
324
+ canProbe(callerPid, pid) {
325
+ const caller = this.requireLiveCaller(callerPid);
326
+ const target = this.table.get(pid);
327
+ if (target) {
328
+ if (caller.rootPid === undefined || target.rootPid !== caller.rootPid)
329
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
330
+ if (isInstance(target.outcome, OutcomeCell)) {
331
+ if (!peekDirectoryProcess(target.outcome.validity.buffer, pid))
332
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
333
+ return this.controls(callerPid, pid) || probeDirectoryProcess(target.outcome.validity.buffer, callerPid, pid);
334
+ }
335
+ return this.controls(callerPid, pid);
336
+ }
337
+ const directory = this.callerDirectory(caller);
338
+ if (directory)
339
+ return probeDirectoryProcess(directory, callerPid, pid);
340
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
341
+ }
342
+ canSignalProcess(callerPid, processId) {
343
+ const caller = this.requireLiveCaller(callerPid);
344
+ if (caller.rootPid === undefined || !Number.isInteger(processId) || processId <= 0 || processId > 2147483647)
345
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${processId}`);
346
+ let found = false;
347
+ for (const record of this.table.values()) {
348
+ if (record.rootPid !== caller.rootPid || record.processIdentity.pid !== processId || !this.isLiveDirectoryRecord(record))
349
+ continue;
350
+ found = true;
351
+ if (this.controls(callerPid, record.pid))
352
+ return true;
353
+ }
354
+ const directory = this.callerDirectory(caller);
355
+ if (directory) {
356
+ try {
357
+ if (probeDirectoryLogicalPid(directory, callerPid, processId))
358
+ return true;
359
+ found = true;
360
+ } catch (error) {
361
+ if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.SRCH)
362
+ throw error;
363
+ }
364
+ }
365
+ if (!found)
366
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${processId}`);
367
+ return false;
368
+ }
295
369
  canSignalJob(callerPid, jobId) {
296
- this.table.require(callerPid);
370
+ const caller = this.requireLiveCaller(callerPid);
297
371
  const job = this.table.job(jobId);
298
- if (!job)
372
+ if (!job || caller.rootPid === undefined || job.rootPid !== caller.rootPid)
299
373
  throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
300
374
  return job.controlParent === callerPid;
301
375
  }
376
+ canProbeJob(callerPid, jobId) {
377
+ const caller = this.requireLiveCaller(callerPid);
378
+ const job = this.table.job(jobId);
379
+ if (job) {
380
+ if (caller.rootPid === undefined || job.rootPid !== caller.rootPid)
381
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
382
+ const directory = this.table.jobDirectory(jobId);
383
+ if (directory) {
384
+ if (!peekDirectoryJob(directory, jobId))
385
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
386
+ return job.controlParent === callerPid || probeDirectoryJob(directory, callerPid, jobId);
387
+ }
388
+ return job.controlParent === callerPid;
389
+ }
390
+ const directory = this.callerDirectory(caller);
391
+ if (directory)
392
+ return probeDirectoryJob(directory, callerPid, jobId);
393
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
394
+ }
302
395
  canWaitJob(callerPid, jobId) {
303
396
  if (this.table.parentOf(callerPid) === undefined)
304
397
  throw new ProcessError(ProcessErrno.SRCH, `unknown process ${callerPid}`);
@@ -387,10 +480,11 @@ export class ProcessSupervisor {
387
480
  const observation = admitProcessObservation(pid, outcome, options.observation);
388
481
  const job = options.job !== undefined && this.table.job(options.job) ? this.table.job(options.job) : this.table.createJob(pid, options.foreground ?? true, options.job, isInstance(options.outcome, OutcomeCell) ? {
389
482
  ownerPid: pid,
483
+ rootPid: pid,
390
484
  leaderPid: pid,
391
485
  outcome: options.outcome,
392
486
  foreground: options.foreground ?? true
393
- } : undefined);
487
+ } : undefined, "independent", pid);
394
488
  this.table.insert({
395
489
  pid,
396
490
  parentPid: 0,
@@ -454,20 +548,7 @@ export class ProcessSupervisor {
454
548
  const processIdentity = this.spawnIdentity(pid, processKind, parent, capturedIdentity);
455
549
  this.table.checkPid(pid, admitted ? reservation.outcome : undefined);
456
550
  const observation = admitProcessObservation(pid, outcome, reservation.observation);
457
- let job = reservation.job ?? (selector > 0 ? selector : undefined);
458
- let createdJob = false;
459
- if (job !== undefined && !this.table.job(job)) {
460
- if (reservation.job === undefined)
461
- throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
462
- this.table.createJob(jobIdentity?.ownerPid ?? parentPid, jobIdentity?.foreground ?? selector === 0, job, jobIdentity, jobLifetime);
463
- createdJob = true;
464
- }
465
- if (job === undefined) {
466
- const group = this.table.createJob(parentPid, selector === 0, undefined, undefined, jobLifetime);
467
- group.controlParent = reservation.controlParent ?? parentPid;
468
- job = group.id;
469
- createdJob = true;
470
- }
551
+ const { job, createdJob } = this.resolveSpawnJob(parentPid, parent, selector, jobLifetime, reservation, jobIdentity);
471
552
  if (jobIdentity)
472
553
  this.table.adoptJobIdentity(job, jobIdentity);
473
554
  this.checkJobAdmission(job, admitted);
@@ -532,6 +613,21 @@ export class ProcessSupervisor {
532
613
  }
533
614
  return pid;
534
615
  }
616
+ resolveSpawnJob(parentPid, parent, selector, jobLifetime, reservation, jobIdentity) {
617
+ const rootPid = reservation.rootPid ?? parent?.rootPid;
618
+ const job = reservation.job ?? (selector > 0 ? selector : undefined);
619
+ if (job === undefined) {
620
+ const group = this.table.createJob(parentPid, selector === 0, undefined, undefined, jobLifetime, rootPid);
621
+ group.controlParent = reservation.controlParent ?? parentPid;
622
+ return { job: group.id, createdJob: true };
623
+ }
624
+ if (this.table.job(job))
625
+ return { job, createdJob: false };
626
+ if (reservation.job === undefined)
627
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
628
+ this.table.createJob(jobIdentity?.ownerPid ?? parentPid, jobIdentity?.foreground ?? selector === 0, job, jobIdentity, jobLifetime, rootPid);
629
+ return { job, createdJob: true };
630
+ }
535
631
  checkSpawnParent(parentPid, parent, kind, admitted, retained) {
536
632
  if (!parent && (!admitted || !retained))
537
633
  throw new ProcessError(ProcessErrno.SRCH, `unknown process ${parentPid}`);
@@ -939,7 +1035,12 @@ export class ProcessSupervisor {
939
1035
  this.finish(pid, { kind: "exited", code });
940
1036
  }
941
1037
  kill(pid, signal) {
942
- const sig = checkedSignal(signal), record = this.table.require(pid);
1038
+ const sig = checkedKillSignal(signal), record = this.table.require(pid);
1039
+ if (sig === 0) {
1040
+ if (!this.isLiveDirectoryRecord(record))
1041
+ throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
1042
+ return;
1043
+ }
943
1044
  if (record.result)
944
1045
  return;
945
1046
  this.recordSignal(record, sig);
@@ -993,10 +1094,15 @@ export class ProcessSupervisor {
993
1094
  this.finish(pid, winner);
994
1095
  }
995
1096
  killJob(jobId, signal) {
996
- const sig = checkedSignal(signal);
1097
+ const sig = checkedKillSignal(signal);
997
1098
  const job = this.table.job(jobId);
998
1099
  if (!job)
999
1100
  throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
1101
+ if (sig === 0) {
1102
+ if (!this.isLiveDirectoryJob(jobId))
1103
+ throw new ProcessError(ProcessErrno.SRCH, `unknown job ${jobId}`);
1104
+ return;
1105
+ }
1000
1106
  const targets = Array.from(job.members, (pid) => this.table.require(pid));
1001
1107
  for (const record of targets) {
1002
1108
  try {
@@ -62,6 +62,13 @@ export class ProcessTable {
62
62
  const outcome = this.jobs.get(id)?.leaderOutcome;
63
63
  return isInstance(outcome, OutcomeCell) && !outcome.valid();
64
64
  }
65
+ jobDirectory(id) {
66
+ const job = this.jobs.get(id);
67
+ if (!job)
68
+ return;
69
+ const outcome = job.leaderOutcome ?? (job.leaderPid === undefined ? undefined : this.records.get(job.leaderPid)?.outcome);
70
+ return isInstance(outcome, OutcomeCell) ? outcome.validity.buffer : undefined;
71
+ }
65
72
  values() {
66
73
  return this.records.values();
67
74
  }
@@ -74,7 +81,7 @@ export class ProcessTable {
74
81
  throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
75
82
  return record;
76
83
  }
77
- createJob(ownerPid, foreground, id = this.identities.job(), identity, jobLifetime = "independent") {
84
+ createJob(ownerPid, foreground, id = this.identities.job(), identity, jobLifetime = "independent", rootPid) {
78
85
  if (isInstance(identity?.outcome, OutcomeCell))
79
86
  identity.outcome.check();
80
87
  const captured = isInstance(identity?.outcome, OutcomeCell);
@@ -84,6 +91,7 @@ export class ProcessTable {
84
91
  const job = {
85
92
  id,
86
93
  ownerPid,
94
+ rootPid: rootPid ?? identity?.rootPid ?? this.records.get(ownerPid)?.rootPid ?? ownerPid,
87
95
  controlParent: identity?.controlParent ?? ownerPid,
88
96
  foreground,
89
97
  jobLifetime: identity?.jobLifetime ?? jobLifetime,
@@ -75,3 +75,8 @@ export function checkedSignal(signal) {
75
75
  }
76
76
  return signal;
77
77
  }
78
+ export function checkedKillSignal(signal) {
79
+ if (signal === 0)
80
+ return 0;
81
+ return checkedSignal(signal);
82
+ }
@@ -39,6 +39,8 @@ import {
39
39
  directorySlots,
40
40
  directoryJob,
41
41
  findDirectoryJob,
42
+ probeDirectoryJob,
43
+ probeDirectoryLogicalPid,
42
44
  directoryControls,
43
45
  isCollectedProcess,
44
46
  reserveDirectoryProcess,
@@ -68,6 +70,7 @@ import {
68
70
  ProcessErrno,
69
71
  ProcessError,
70
72
  checkedSignal,
73
+ checkedKillSignal,
71
74
  checkedJobLifetime,
72
75
  checkedProcessCwd,
73
76
  snapshotSpawnWorker,
@@ -290,6 +293,10 @@ export class WorkerProcessClient {
290
293
  if (commandTransferFailed(this.options.transport.commandTransfer))
291
294
  throw new ProcessError(ProcessErrno.SRCH, "command transfer cleanup failed");
292
295
  }
296
+ checkAlive() {
297
+ if (readOutcome(this.signals.outcome))
298
+ throw new ProcessError(ProcessErrno.SRCH, "process has exited");
299
+ }
293
300
  admit() {
294
301
  if (readOutcome(this.signals.outcome)) {
295
302
  this.retireAccesses();
@@ -659,6 +666,7 @@ export class WorkerProcessClient {
659
666
  canSignal(callerPid, pid) {
660
667
  if (callerPid !== this.pid)
661
668
  return false;
669
+ this.checkAlive();
662
670
  const target = this.find(pid);
663
671
  return directoryControls(this.options.transport.directory, () => {
664
672
  controlLoad(target.controlParent);
@@ -672,19 +680,40 @@ export class WorkerProcessClient {
672
680
  const group = this.requireJob(callerPid, job);
673
681
  return directoryControls(this.options.transport.directory, () => controlLoad(group.controlParent), this.pid, true);
674
682
  } catch (error) {
675
- if (error instanceof ProcessError && error.errno === 63)
683
+ if (error instanceof ProcessError && error.errno === ProcessErrno.PERM)
676
684
  return false;
677
685
  throw error;
678
686
  }
679
687
  }
688
+ canProbeJob(callerPid, job) {
689
+ if (callerPid !== this.pid)
690
+ return false;
691
+ this.checkAlive();
692
+ return probeDirectoryJob(this.options.transport.directory, this.pid, job);
693
+ }
694
+ canSignalProcess(callerPid, processId) {
695
+ if (callerPid !== this.pid)
696
+ return false;
697
+ this.checkAlive();
698
+ return probeDirectoryLogicalPid(this.options.transport.directory, callerPid, processId, this.options.transport.slot);
699
+ }
680
700
  kill(pid, signal) {
701
+ const sig = checkedKillSignal(signal);
681
702
  if (!this.canSignal(this.pid, pid))
682
- throw new ProcessError(63, "process is outside the caller's ancestry");
683
- this.deliver([this.find(pid)], checkedSignal(signal));
703
+ throw new ProcessError(ProcessErrno.PERM, "process is outside the caller's ancestry");
704
+ if (sig === 0)
705
+ return;
706
+ this.deliver([this.find(pid)], sig);
684
707
  }
685
708
  killJob(job, signal) {
709
+ const sig = checkedKillSignal(signal);
710
+ if (sig === 0) {
711
+ if (!this.canProbeJob(this.pid, job))
712
+ throw new ProcessError(ProcessErrno.PERM, "job is not owned by the caller");
713
+ return;
714
+ }
686
715
  if (!this.canSignalJob(this.pid, job))
687
- throw new ProcessError(63, "job is not owned by the caller");
716
+ throw new ProcessError(ProcessErrno.PERM, "job is not owned by the caller");
688
717
  const directory = this.options.transport.directory;
689
718
  const slots = directorySlots(directory);
690
719
  const targets = [];
@@ -699,7 +728,7 @@ export class WorkerProcessClient {
699
728
  throw error;
700
729
  }
701
730
  }
702
- this.deliver(targets, checkedSignal(signal), true);
731
+ this.deliver(targets, sig, true);
703
732
  }
704
733
  deliver(targets, signal, collective = false) {
705
734
  this.admit();
package/dist/runtime.js CHANGED
@@ -84,7 +84,10 @@ const supervisorCapabilities = {
84
84
  jobOf: "method",
85
85
  cwd: "method",
86
86
  canSignal: "method",
87
+ canProbe: "method",
87
88
  canSignalJob: "method",
89
+ canProbeJob: "method",
90
+ canSignalProcess: "method",
88
91
  canWaitJob: "method",
89
92
  accessStart: "method",
90
93
  accessTake: "method",
@@ -1 +1 @@
1
- {"commit":"f2b1143915c41d86a9ef930b7f9d50e5228b1a05","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
1
+ {"commit":"72849910ef1260a1e27ec37e6b3a8e0371f71de3","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
package/fs/backend.ts CHANGED
@@ -23,7 +23,12 @@ import { SharedFilesystemState, type SharedSegment } from "./shared.js";
23
23
 
24
24
  /** Storage boundary. 3b can add asynchronous loading/commit without changing guest transport. */
25
25
  export interface FilesystemBackend {
26
- execute(operation: string, args: any[], data: Uint8Array): unknown | Promise<unknown>;
26
+ execute(
27
+ operation: string,
28
+ args: any[],
29
+ data: Uint8Array,
30
+ cancelled?: () => boolean,
31
+ ): unknown | Promise<unknown>;
27
32
  retain(handle: FileHandle): void;
28
33
  release(handle: FileHandle): void;
29
34
  resources?(): Record<string, number>;