@@ -20,7 +20,7 @@ import { makeSlogger, makeDummySlogger } from './slogger.js';
20
20
import { getKpidsToRetire } from './cleanup.js' ;
21
21
import { processNextGCAction } from './gc-actions.js' ;
22
22
23
- import { makeVatRootObjectSlot , makeVatLoader } from './loadVat.js' ;
23
+ import { makeVatLoader } from './loadVat.js' ;
24
24
import { makeDeviceTranslators } from './deviceTranslator.js' ;
25
25
import { notifyTermination } from './notifyTermination.js' ;
26
26
@@ -43,6 +43,20 @@ function makeError(message, name = 'Error') {
43
43
44
44
const VAT_TERMINATION_ERROR = makeError ( 'vat terminated' ) ;
45
45
46
+ /**
47
+ * Provide the kref of a vat's root object, as if it had been exported.
48
+ *
49
+ * @param {* } kernelKeeper Kernel keeper managing persistent kernel state.
50
+ * @param {string } vatID Vat ID of the vat whose root kref is sought.
51
+ *
52
+ * @returns {string } the kref of the root object of the given vat.
53
+ */
54
+ export function exportRootObject ( kernelKeeper , vatID ) {
55
+ insistVatID ( vatID ) ;
56
+ const vatKeeper = kernelKeeper . provideVatKeeper ( vatID ) ;
57
+ return vatKeeper . mapVatSlotToKernelSlot ( 'o+0' ) ;
58
+ }
59
+
46
60
/*
47
61
* Pretend that a vat just exported an object, and increment the refcount on
48
62
* the resulting kref so nothing tries to delete it for being unreferenced.
@@ -60,8 +74,7 @@ export function doAddExport(kernelKeeper, fromVatID, vref) {
60
74
61
75
/**
62
76
* Enqueue a message to some kernel object, as if the message had been sent
63
- * by some other vat. This requires a kref as a target, so use e.g.
64
- * doAddExport to acquire one and increment its refcount to keep it alive.
77
+ * by some other vat. This requires a kref as a target.
65
78
*
66
79
* @param {* } kernelKeeper Kernel keeper managing persistent kernel state
67
80
* @param {string } kref Target of the message
@@ -236,6 +249,10 @@ export default function buildKernel(
236
249
return vatKeeper . mapKernelSlotToVatSlot ( kernelSlot ) ;
237
250
}
238
251
252
+ function pinObject ( kref ) {
253
+ kernelKeeper . pinObject ( kref ) ;
254
+ }
255
+
239
256
function addExport ( fromVatID , vatSlot ) {
240
257
if ( ! started ) {
241
258
throw new Error ( 'must do kernel.start() before addExport()' ) ;
@@ -576,7 +593,7 @@ export default function buildKernel(
576
593
function makeSuccessResponse ( ) {
577
594
// build success message, giving admin vat access to the new vat's root
578
595
// object
579
- const kernelRootObjSlot = addExport ( vatID , makeVatRootObjectSlot ( ) ) ;
596
+ const kernelRootObjSlot = exportRootObject ( kernelKeeper , vatID ) ;
580
597
return {
581
598
body : JSON . stringify ( [
582
599
vatID ,
@@ -1068,6 +1085,10 @@ export default function buildKernel(
1068
1085
1069
1086
addImport,
1070
1087
addExport,
1088
+ getRootObject ( vatID ) {
1089
+ return exportRootObject ( kernelKeeper , vatID ) ;
1090
+ } ,
1091
+ pinObject,
1071
1092
vatNameToID,
1072
1093
deviceNameToID,
1073
1094
queueToKref,
0 commit comments