@agoric/xsnap 0.14.3-other-dev-8f8782b.0 → 0.14.3-other-dev-fbe72e7.0.fbe72e7
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 +6 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +44 -24
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +14 -12
- package/src/build.js +258 -133
- package/src/globals.d.ts +2 -2
- package/src/replay.js +12 -8
- package/src/xsnap.js +131 -115
- package/src/xsrepl.js +8 -9
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1024 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -622
- package/src/defer.js +0 -31
package/src/xsnap.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* eslint-env node */
|
|
2
2
|
/* eslint no-await-in-loop: ["off"] */
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {typeof import('child_process').spawn} Spawn
|
|
6
|
-
* @typedef {import('stream').Writable} Writable
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @template T
|
|
11
|
-
* @typedef {import('./defer').Deferred<T>} Deferred
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
4
|
import { finished } from 'stream/promises';
|
|
15
5
|
import { PassThrough, Readable } from 'stream';
|
|
16
6
|
import { promisify } from 'util';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { Fail, q } from '@endo/errors';
|
|
17
9
|
import { makeNetstringReader, makeNetstringWriter } from '@endo/netstring';
|
|
18
10
|
import { makeNodeReader, makeNodeWriter } from '@endo/stream-node';
|
|
19
11
|
import { makePromiseKit, racePromises } from '@endo/promise-kit';
|
|
20
12
|
import { forever } from '@agoric/internal';
|
|
21
13
|
import { ErrorCode, ErrorSignal, ErrorMessage, METER_TYPE } from '../api.js';
|
|
22
|
-
import { defer } from './defer.js';
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
/** @import {PromiseKit} from '@endo/promise-kit' */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {typeof import('child_process').spawn} Spawn
|
|
19
|
+
* @import {Writable} from 'stream'
|
|
20
|
+
*/
|
|
25
21
|
|
|
26
22
|
// This will need adjustment, but seems to be fine for a start.
|
|
27
23
|
export const DEFAULT_CRANK_METERING_LIMIT = 1e8;
|
|
@@ -55,6 +51,81 @@ function echoCommand(arg) {
|
|
|
55
51
|
const safeHintFromDescription = description =>
|
|
56
52
|
description.replaceAll(/[^a-zA-Z0-9_.-]/g, '-');
|
|
57
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} SnapshotLoader
|
|
56
|
+
* @property {string} snapPath
|
|
57
|
+
* where XS can load the snapshot from, either a filesystem path or a string
|
|
58
|
+
* like `@${fileDescriptorNumber}:${readableDescription}`
|
|
59
|
+
* @property {(destStream?: Writable) => Promise<void>} afterSpawn
|
|
60
|
+
* callback for providing a destination stream to which the data should be
|
|
61
|
+
* piped (only relevant for a stream-based loader)
|
|
62
|
+
* @property {() => Promise<void>} cleanup
|
|
63
|
+
* callback to free resources when the loader is no longer needed
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @callback MakeSnapshotLoader
|
|
68
|
+
* @param {AsyncIterable<Uint8Array>} sourceBytes
|
|
69
|
+
* @param {string} description
|
|
70
|
+
* @param {{fs: Pick<typeof import('fs/promises'), 'open' | 'unlink'>, ptmpName: (opts: import('tmp').TmpNameOptions) => Promise<string>}} ioPowers
|
|
71
|
+
* @returns {Promise<SnapshotLoader>}
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/** @type {MakeSnapshotLoader} */
|
|
75
|
+
const makeSnapshotLoaderWithFS = async (
|
|
76
|
+
sourceBytes,
|
|
77
|
+
description,
|
|
78
|
+
{ fs, ptmpName },
|
|
79
|
+
) => {
|
|
80
|
+
const snapPath = await ptmpName({
|
|
81
|
+
template: `load-snapshot-${safeHintFromDescription(description)}-XXXXXX.xss`,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const afterSpawn = async () => {};
|
|
85
|
+
const cleanup = async () => fs.unlink(snapPath);
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const tmpSnap = await fs.open(snapPath, 'w');
|
|
89
|
+
// @ts-expect-error incorrect typings; writeFile does support AsyncIterable
|
|
90
|
+
await tmpSnap.writeFile(sourceBytes);
|
|
91
|
+
await tmpSnap.close();
|
|
92
|
+
} catch (e) {
|
|
93
|
+
await cleanup();
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return harden({
|
|
98
|
+
snapPath,
|
|
99
|
+
afterSpawn,
|
|
100
|
+
cleanup,
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** @type {MakeSnapshotLoader} */
|
|
105
|
+
const makeSnapshotLoaderWithPipe = async (
|
|
106
|
+
sourceBytes,
|
|
107
|
+
description,
|
|
108
|
+
_ioPowers,
|
|
109
|
+
) => {
|
|
110
|
+
let done = Promise.resolve();
|
|
111
|
+
|
|
112
|
+
const cleanup = async () => done;
|
|
113
|
+
|
|
114
|
+
const afterSpawn = async destStream => {
|
|
115
|
+
const sourceStream = Readable.from(sourceBytes);
|
|
116
|
+
sourceStream.pipe(destStream, { end: false });
|
|
117
|
+
|
|
118
|
+
done = finished(sourceStream);
|
|
119
|
+
void done.catch(noop).then(() => sourceStream.unpipe(destStream));
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return harden({
|
|
123
|
+
snapPath: `@${SNAPSHOT_LOAD_FD}:${safeHintFromDescription(description)}`,
|
|
124
|
+
afterSpawn,
|
|
125
|
+
cleanup,
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
58
129
|
/**
|
|
59
130
|
* @param {XSnapOptions} options
|
|
60
131
|
*
|
|
@@ -70,8 +141,8 @@ const safeHintFromDescription = description =>
|
|
|
70
141
|
* @property {AsyncIterable<Uint8Array>} [snapshotStream]
|
|
71
142
|
* @property {string} [snapshotDescription]
|
|
72
143
|
* @property {boolean} [snapshotUseFs]
|
|
73
|
-
* @property {'ignore' | 'inherit'} [stdout]
|
|
74
|
-
* @property {'ignore' | 'inherit'} [stderr]
|
|
144
|
+
* @property {'ignore' | 'inherit' | 'pipe'} [stdout]
|
|
145
|
+
* @property {'ignore' | 'inherit' | 'pipe'} [stderr]
|
|
75
146
|
* @property {number} [meteringLimit]
|
|
76
147
|
* @property {Record<string, string>} [env]
|
|
77
148
|
*/
|
|
@@ -86,7 +157,7 @@ export async function xsnap(options) {
|
|
|
86
157
|
netstringMaxChunkSize = undefined,
|
|
87
158
|
parserBufferSize = undefined,
|
|
88
159
|
snapshotStream,
|
|
89
|
-
snapshotDescription =
|
|
160
|
+
snapshotDescription = 'unknown',
|
|
90
161
|
snapshotUseFs = false,
|
|
91
162
|
stdout = 'ignore',
|
|
92
163
|
stderr = 'ignore',
|
|
@@ -97,97 +168,39 @@ export async function xsnap(options) {
|
|
|
97
168
|
const platform = {
|
|
98
169
|
Linux: 'lin',
|
|
99
170
|
Darwin: 'mac',
|
|
100
|
-
Windows_NT: 'win',
|
|
171
|
+
// Windows_NT: 'win', // One can dream.
|
|
101
172
|
}[os];
|
|
102
173
|
|
|
103
174
|
if (platform === undefined) {
|
|
104
175
|
throw Error(`xsnap does not support platform ${os}`);
|
|
105
176
|
}
|
|
106
177
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)}-XXXXXX.xss`,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const afterSpawn = async () => {};
|
|
119
|
-
const cleanup = async () => fs.unlink(snapPath);
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
123
|
-
const tmpSnap = await fs.open(snapPath, 'w');
|
|
124
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
125
|
-
await tmpSnap.writeFile(
|
|
126
|
-
// @ts-expect-error incorrect typings, does support AsyncIterable
|
|
127
|
-
snapshotStream,
|
|
128
|
-
);
|
|
129
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
130
|
-
await tmpSnap.close();
|
|
131
|
-
} catch (e) {
|
|
132
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
133
|
-
await cleanup();
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return harden({
|
|
138
|
-
snapPath,
|
|
139
|
-
afterSpawn,
|
|
140
|
-
cleanup,
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const makeLoadSnapshotHandlerWithPipe = async () => {
|
|
145
|
-
let done = Promise.resolve();
|
|
146
|
-
|
|
147
|
-
const cleanup = async () => done;
|
|
148
|
-
|
|
149
|
-
/** @param {Writable} loadSnapshotsStream */
|
|
150
|
-
const afterSpawn = async loadSnapshotsStream => {
|
|
151
|
-
assert(snapshotStream);
|
|
152
|
-
const destStream = loadSnapshotsStream;
|
|
153
|
-
|
|
154
|
-
const sourceStream = Readable.from(snapshotStream);
|
|
155
|
-
sourceStream.pipe(destStream, { end: false });
|
|
156
|
-
|
|
157
|
-
done = finished(sourceStream);
|
|
158
|
-
done.catch(noop).then(() => sourceStream.unpipe(destStream));
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return harden({
|
|
162
|
-
snapPath: `@${SNAPSHOT_LOAD_FD}:${safeHintFromDescription(
|
|
163
|
-
snapshotDescription,
|
|
164
|
-
)}`,
|
|
165
|
-
afterSpawn,
|
|
166
|
-
cleanup,
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
let bin = new URL(
|
|
171
|
-
`../xsnap-native/xsnap/build/bin/${platform}/${
|
|
172
|
-
debug ? 'debug' : 'release'
|
|
173
|
-
}/xsnap-worker`,
|
|
174
|
-
import.meta.url,
|
|
175
|
-
).pathname;
|
|
178
|
+
let bin = fileURLToPath(
|
|
179
|
+
new URL(
|
|
180
|
+
`../xsnap-native/xsnap/build/bin/${platform}/${
|
|
181
|
+
debug ? 'debug' : 'release'
|
|
182
|
+
}/xsnap-worker`,
|
|
183
|
+
import.meta.url,
|
|
184
|
+
),
|
|
185
|
+
);
|
|
176
186
|
|
|
177
|
-
/** @type {
|
|
178
|
-
const vatExit =
|
|
187
|
+
/** @type {PromiseKit<void>} */
|
|
188
|
+
const vatExit = makePromiseKit();
|
|
179
189
|
|
|
180
190
|
assert(!/^-/.test(name), `name '${name}' cannot start with hyphen`);
|
|
181
191
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
/** @type {(opts: import('tmp').TmpNameOptions) => Promise<string>} */
|
|
193
|
+
const ptmpName = fs.tmpName && promisify(fs.tmpName);
|
|
194
|
+
const makeSnapshotLoader = snapshotUseFs
|
|
195
|
+
? makeSnapshotLoaderWithFS
|
|
196
|
+
: makeSnapshotLoaderWithPipe;
|
|
197
|
+
let snapshotLoader = await (snapshotStream &&
|
|
198
|
+
makeSnapshotLoader(snapshotStream, snapshotDescription, { fs, ptmpName }));
|
|
186
199
|
|
|
187
200
|
let args = [name];
|
|
188
201
|
|
|
189
|
-
if (
|
|
190
|
-
args.push('-r',
|
|
202
|
+
if (snapshotLoader) {
|
|
203
|
+
args.push('-r', snapshotLoader.snapPath);
|
|
191
204
|
}
|
|
192
205
|
|
|
193
206
|
if (meteringLimit) {
|
|
@@ -258,13 +271,13 @@ export async function xsnap(options) {
|
|
|
258
271
|
const snapshotSaveStream = xsnapProcessStdio[SNAPSHOT_SAVE_FD];
|
|
259
272
|
const snapshotLoadStream = xsnapProcessStdio[SNAPSHOT_LOAD_FD];
|
|
260
273
|
|
|
261
|
-
await
|
|
274
|
+
await snapshotLoader?.afterSpawn(snapshotLoadStream);
|
|
262
275
|
|
|
263
|
-
if (
|
|
264
|
-
vatExit.promise.catch(noop).then(() => {
|
|
265
|
-
if (
|
|
266
|
-
const { cleanup } =
|
|
267
|
-
|
|
276
|
+
if (snapshotLoader) {
|
|
277
|
+
void vatExit.promise.catch(noop).then(() => {
|
|
278
|
+
if (snapshotLoader) {
|
|
279
|
+
const { cleanup } = snapshotLoader;
|
|
280
|
+
snapshotLoader = undefined;
|
|
268
281
|
return cleanup();
|
|
269
282
|
}
|
|
270
283
|
});
|
|
@@ -277,7 +290,7 @@ export async function xsnap(options) {
|
|
|
277
290
|
* @template T
|
|
278
291
|
* @typedef {object} RunResult
|
|
279
292
|
* @property {T} reply
|
|
280
|
-
* @property {{ meterType: string, allocate: number|null, compute: number|null, timestamps: number[]|null }} meterUsage
|
|
293
|
+
* @property {{ meterType: string, allocate: number|null, compute: number|null, currentHeapCount: number|null, timestamps: number[]|null }} meterUsage
|
|
281
294
|
*/
|
|
282
295
|
|
|
283
296
|
/**
|
|
@@ -286,10 +299,9 @@ export async function xsnap(options) {
|
|
|
286
299
|
async function runToIdle() {
|
|
287
300
|
for await (const _ of forever) {
|
|
288
301
|
const iteration = await messagesFromXsnap.next(undefined);
|
|
289
|
-
if (
|
|
290
|
-
const { cleanup } =
|
|
291
|
-
|
|
292
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
302
|
+
if (snapshotLoader) {
|
|
303
|
+
const { cleanup } = snapshotLoader;
|
|
304
|
+
snapshotLoader = undefined;
|
|
293
305
|
await cleanup();
|
|
294
306
|
}
|
|
295
307
|
if (iteration.done) {
|
|
@@ -303,7 +315,12 @@ export async function xsnap(options) {
|
|
|
303
315
|
xsnapProcess.kill();
|
|
304
316
|
throw Error('xsnap protocol error: received empty message');
|
|
305
317
|
} else if (message[0] === OK) {
|
|
306
|
-
let meterInfo = {
|
|
318
|
+
let meterInfo = {
|
|
319
|
+
compute: null,
|
|
320
|
+
allocate: null,
|
|
321
|
+
currentHeapCount: null,
|
|
322
|
+
timestamps: [],
|
|
323
|
+
};
|
|
307
324
|
const meterSeparator = message.indexOf(OK_SEPARATOR, 1);
|
|
308
325
|
if (meterSeparator >= 0) {
|
|
309
326
|
// The message is `.meterdata\1reply`.
|
|
@@ -328,9 +345,7 @@ export async function xsnap(options) {
|
|
|
328
345
|
)}`,
|
|
329
346
|
);
|
|
330
347
|
} else if (message[0] === QUERY) {
|
|
331
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
332
348
|
const commandResult = await handleCommand(message.subarray(1));
|
|
333
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
334
349
|
await messagesToXsnap.next([QUERY_RESPONSE_BUF, commandResult]);
|
|
335
350
|
} else {
|
|
336
351
|
// unrecognized responses also kill the process
|
|
@@ -429,6 +444,7 @@ export async function xsnap(options) {
|
|
|
429
444
|
let snapshotReadSize = 0;
|
|
430
445
|
/** @type {number | undefined} */
|
|
431
446
|
let snapshotSize;
|
|
447
|
+
await null;
|
|
432
448
|
try {
|
|
433
449
|
/** @type {string} */
|
|
434
450
|
let snapPath;
|
|
@@ -444,7 +460,6 @@ export async function xsnap(options) {
|
|
|
444
460
|
|
|
445
461
|
if (snapshotUseFs) {
|
|
446
462
|
// TODO: Refactor to use tmpFile rather than tmpName.
|
|
447
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
448
463
|
snapPath = await ptmpName({
|
|
449
464
|
template: `make-snapshot-${safeHintFromDescription(
|
|
450
465
|
description,
|
|
@@ -461,14 +476,16 @@ export async function xsnap(options) {
|
|
|
461
476
|
// then wait for the command response to pipe the file stream into the
|
|
462
477
|
// output, causing the file read to begin.
|
|
463
478
|
|
|
464
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
465
479
|
const handle = await fs.open(snapPath, 'w+');
|
|
466
480
|
// @ts-expect-error 'close' event added in Node 15.4
|
|
467
481
|
handle.on('close', () => {
|
|
468
|
-
|
|
482
|
+
// Safe to ignore the result because we are skipping to to clean up the temp directory.
|
|
483
|
+
void fs.unlink(snapPath);
|
|
469
484
|
});
|
|
470
485
|
sourceStream = handle.createReadStream();
|
|
471
|
-
finished(output)
|
|
486
|
+
finished(output)
|
|
487
|
+
.finally(() => sourceStream.destroy())
|
|
488
|
+
.catch(noop);
|
|
472
489
|
} else {
|
|
473
490
|
sourceStream = snapshotSaveStream;
|
|
474
491
|
snapPath = `@${SNAPSHOT_SAVE_FD}`;
|
|
@@ -477,14 +494,13 @@ export async function xsnap(options) {
|
|
|
477
494
|
// ensuring that any previous save stream usage has ended. However we
|
|
478
495
|
// must start the flow before receiving the command's response or the
|
|
479
496
|
// xsnap process would block on a full pipe, causing an IPC deadlock.
|
|
480
|
-
batonKit.promise.then(maybePipe);
|
|
497
|
+
batonKit.promise.then(maybePipe, noop);
|
|
481
498
|
}
|
|
482
499
|
|
|
483
500
|
const cleanup = () => {
|
|
484
501
|
if (cleaned) return;
|
|
485
502
|
cleaned = true;
|
|
486
503
|
sourceStream.unpipe(output);
|
|
487
|
-
// eslint-disable-next-line no-use-before-define
|
|
488
504
|
output.off('data', onData);
|
|
489
505
|
output.end();
|
|
490
506
|
};
|
|
@@ -522,7 +538,6 @@ export async function xsnap(options) {
|
|
|
522
538
|
|
|
523
539
|
yield* output;
|
|
524
540
|
} finally {
|
|
525
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
526
541
|
await done;
|
|
527
542
|
(piped && snapshotReadSize === snapshotSize) ||
|
|
528
543
|
Fail`Snapshot size does not match. saved=${q(snapshotSize)}, read=${q(
|
|
@@ -530,6 +545,7 @@ export async function xsnap(options) {
|
|
|
530
545
|
)}`;
|
|
531
546
|
}
|
|
532
547
|
}
|
|
548
|
+
harden(makeSnapshotInternal);
|
|
533
549
|
|
|
534
550
|
/**
|
|
535
551
|
* @param {string} [description]
|
package/src/xsrepl.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* eslint-env node */
|
|
2
2
|
/* We make exceptions for test code. This is a test utility. */
|
|
3
|
-
/* eslint-disable @jessie.js/no-nested-await */
|
|
4
3
|
/* eslint no-await-in-loop: ["off"] */
|
|
5
4
|
|
|
6
5
|
import '@endo/init';
|
|
7
6
|
|
|
8
|
-
/**
|
|
9
|
-
* @template T
|
|
10
|
-
* @typedef {import('./defer').Deferred<T>} Deferred
|
|
11
|
-
*/
|
|
12
7
|
import * as childProcess from 'child_process';
|
|
13
8
|
import fs from 'fs';
|
|
14
9
|
import { tmpName } from 'tmp';
|
|
15
10
|
import * as os from 'os';
|
|
16
11
|
import * as readline from 'readline';
|
|
12
|
+
import { makePromiseKit } from '@endo/promise-kit';
|
|
17
13
|
import { xsnap } from './xsnap.js';
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
/** @import {PromiseKit} from '@endo/promise-kit' */
|
|
19
16
|
|
|
20
17
|
const decoder = new TextDecoder();
|
|
21
18
|
|
|
@@ -66,7 +63,9 @@ async function main() {
|
|
|
66
63
|
* @returns {Promise<string>}
|
|
67
64
|
*/
|
|
68
65
|
function ask(prompt) {
|
|
69
|
-
const { promise, resolve } = /** @type {
|
|
66
|
+
const { promise, resolve } = /** @type {PromiseKit<string>} */ (
|
|
67
|
+
makePromiseKit()
|
|
68
|
+
);
|
|
70
69
|
rl.question(prompt, resolve);
|
|
71
70
|
return promise;
|
|
72
71
|
}
|
|
@@ -97,4 +96,4 @@ async function main() {
|
|
|
97
96
|
return vat.close();
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
main();
|
|
99
|
+
await main().catch(err => console.log(err));
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
% : %.c
|
|
2
|
+
%.o : %.c
|
|
3
|
+
|
|
4
|
+
GOAL ?= debug
|
|
5
|
+
NAME = xsnap-worker
|
|
6
|
+
ifneq ($(VERBOSE),1)
|
|
7
|
+
MAKEFLAGS += --silent
|
|
8
|
+
endif
|
|
9
|
+
|
|
10
|
+
EXTRA_DEPS =
|
|
11
|
+
|
|
12
|
+
# MODDABLE = $(CURDIR)/../../moddable
|
|
13
|
+
BUILD_DIR = $(CURDIR)/../../build
|
|
14
|
+
TLS_DIR = $(CURDIR)/../../sources
|
|
15
|
+
|
|
16
|
+
# BUILD_DIR = $(MODDABLE)/build
|
|
17
|
+
# TLS_DIR = ../../sources
|
|
18
|
+
|
|
19
|
+
XS_DIR = $(MODDABLE)/xs
|
|
20
|
+
|
|
21
|
+
BIN_DIR = $(BUILD_DIR)/bin/lin/$(GOAL)
|
|
22
|
+
INC_DIR = $(XS_DIR)/includes
|
|
23
|
+
PLT_DIR = $(XS_DIR)/platforms
|
|
24
|
+
SRC_DIR = $(XS_DIR)/sources
|
|
25
|
+
TMP_DIR = $(BUILD_DIR)/tmp/lin/$(GOAL)/$(NAME)
|
|
26
|
+
|
|
27
|
+
C_OPTIONS = \
|
|
28
|
+
-fno-common \
|
|
29
|
+
-DINCLUDE_XSPLATFORM \
|
|
30
|
+
-DXSPLATFORM=\"xsnapPlatform.h\" \
|
|
31
|
+
-DXSNAP_VERSION=\"$(XSNAP_VERSION)\" \
|
|
32
|
+
-DXSNAP_TEST_RECORD=0 \
|
|
33
|
+
-DmxLockdown=1 \
|
|
34
|
+
-DmxMetering=1 \
|
|
35
|
+
-DmxDebug=1 \
|
|
36
|
+
-UmxInstrument \
|
|
37
|
+
-DmxNoConsole=1 \
|
|
38
|
+
-DmxBoundsCheck=1 \
|
|
39
|
+
-DmxParse=1 \
|
|
40
|
+
-DmxRun=1 \
|
|
41
|
+
-DmxSloppy=1 \
|
|
42
|
+
-DmxSnapshot=1 \
|
|
43
|
+
-DmxRegExpUnicodePropertyEscapes=1 \
|
|
44
|
+
-DmxStringNormalize=1 \
|
|
45
|
+
-DmxMinusZero=1 \
|
|
46
|
+
-I$(INC_DIR) \
|
|
47
|
+
-I$(PLT_DIR) \
|
|
48
|
+
-I$(SRC_DIR) \
|
|
49
|
+
-I$(TLS_DIR) \
|
|
50
|
+
-I$(TMP_DIR)
|
|
51
|
+
C_OPTIONS += \
|
|
52
|
+
-Wno-misleading-indentation \
|
|
53
|
+
-Wno-implicit-fallthrough
|
|
54
|
+
ifeq ($(GOAL),debug)
|
|
55
|
+
C_OPTIONS += -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter
|
|
56
|
+
else
|
|
57
|
+
C_OPTIONS += -O3
|
|
58
|
+
endif
|
|
59
|
+
|
|
60
|
+
LIBRARIES = -ldl -lm -lpthread
|
|
61
|
+
|
|
62
|
+
ifeq ($(XSNAP_RANDOM_INIT),1)
|
|
63
|
+
LIBRARIES += -lbsd
|
|
64
|
+
C_OPTIONS += -DmxSnapshotRandomInit
|
|
65
|
+
endif
|
|
66
|
+
|
|
67
|
+
LINK_OPTIONS = -rdynamic
|
|
68
|
+
|
|
69
|
+
OBJECTS = \
|
|
70
|
+
$(TMP_DIR)/xsAll.o \
|
|
71
|
+
$(TMP_DIR)/xsAPI.o \
|
|
72
|
+
$(TMP_DIR)/xsArguments.o \
|
|
73
|
+
$(TMP_DIR)/xsArray.o \
|
|
74
|
+
$(TMP_DIR)/xsAtomics.o \
|
|
75
|
+
$(TMP_DIR)/xsBigInt.o \
|
|
76
|
+
$(TMP_DIR)/xsBoolean.o \
|
|
77
|
+
$(TMP_DIR)/xsCode.o \
|
|
78
|
+
$(TMP_DIR)/xsCommon.o \
|
|
79
|
+
$(TMP_DIR)/xsDataView.o \
|
|
80
|
+
$(TMP_DIR)/xsDate.o \
|
|
81
|
+
$(TMP_DIR)/xsDebug.o \
|
|
82
|
+
$(TMP_DIR)/xsDefaults.o \
|
|
83
|
+
$(TMP_DIR)/xsError.o \
|
|
84
|
+
$(TMP_DIR)/xsFunction.o \
|
|
85
|
+
$(TMP_DIR)/xsGenerator.o \
|
|
86
|
+
$(TMP_DIR)/xsGlobal.o \
|
|
87
|
+
$(TMP_DIR)/xsJSON.o \
|
|
88
|
+
$(TMP_DIR)/xsLexical.o \
|
|
89
|
+
$(TMP_DIR)/xsLockdown.o \
|
|
90
|
+
$(TMP_DIR)/xsMapSet.o \
|
|
91
|
+
$(TMP_DIR)/xsMarshall.o \
|
|
92
|
+
$(TMP_DIR)/xsMath.o \
|
|
93
|
+
$(TMP_DIR)/xsMemory.o \
|
|
94
|
+
$(TMP_DIR)/xsModule.o \
|
|
95
|
+
$(TMP_DIR)/xsNumber.o \
|
|
96
|
+
$(TMP_DIR)/xsObject.o \
|
|
97
|
+
$(TMP_DIR)/xsPlatforms.o \
|
|
98
|
+
$(TMP_DIR)/xsProfile.o \
|
|
99
|
+
$(TMP_DIR)/xsPromise.o \
|
|
100
|
+
$(TMP_DIR)/xsProperty.o \
|
|
101
|
+
$(TMP_DIR)/xsProxy.o \
|
|
102
|
+
$(TMP_DIR)/xsRegExp.o \
|
|
103
|
+
$(TMP_DIR)/xsRun.o \
|
|
104
|
+
$(TMP_DIR)/xsScope.o \
|
|
105
|
+
$(TMP_DIR)/xsScript.o \
|
|
106
|
+
$(TMP_DIR)/xsSnapshot.o \
|
|
107
|
+
$(TMP_DIR)/xsSourceMap.o \
|
|
108
|
+
$(TMP_DIR)/xsString.o \
|
|
109
|
+
$(TMP_DIR)/xsSymbol.o \
|
|
110
|
+
$(TMP_DIR)/xsSyntaxical.o \
|
|
111
|
+
$(TMP_DIR)/xsTree.o \
|
|
112
|
+
$(TMP_DIR)/xsType.o \
|
|
113
|
+
$(TMP_DIR)/xsdtoa.o \
|
|
114
|
+
$(TMP_DIR)/xsre.o \
|
|
115
|
+
$(TMP_DIR)/xsmc.o \
|
|
116
|
+
$(TMP_DIR)/textdecoder.o \
|
|
117
|
+
$(TMP_DIR)/textencoder.o \
|
|
118
|
+
$(TMP_DIR)/modBase64.o \
|
|
119
|
+
$(TMP_DIR)/xsnapPlatform.o \
|
|
120
|
+
$(TMP_DIR)/xsnap-worker.o
|
|
121
|
+
|
|
122
|
+
VPATH += $(SRC_DIR) $(TLS_DIR)
|
|
123
|
+
VPATH += $(MODDABLE)/modules/data/text/decoder
|
|
124
|
+
VPATH += $(MODDABLE)/modules/data/text/encoder
|
|
125
|
+
VPATH += $(MODDABLE)/modules/data/base64
|
|
126
|
+
|
|
127
|
+
build: $(TMP_DIR) $(BIN_DIR) $(BIN_DIR)/$(NAME)
|
|
128
|
+
|
|
129
|
+
$(TMP_DIR):
|
|
130
|
+
mkdir -p $(TMP_DIR)
|
|
131
|
+
|
|
132
|
+
$(BIN_DIR):
|
|
133
|
+
mkdir -p $(BIN_DIR)
|
|
134
|
+
|
|
135
|
+
$(BIN_DIR)/$(NAME): $(OBJECTS)
|
|
136
|
+
@echo "#" $(NAME) $(GOAL) ": cc" $(@F)
|
|
137
|
+
$(CC) $(LINK_OPTIONS) $(OBJECTS) $(LIBRARIES) -o $@
|
|
138
|
+
|
|
139
|
+
$(OBJECTS): $(TLS_DIR)/xsnap.h
|
|
140
|
+
$(OBJECTS): $(TLS_DIR)/xsnapPlatform.h
|
|
141
|
+
$(OBJECTS): $(PLT_DIR)/xsPlatform.h
|
|
142
|
+
$(OBJECTS): $(SRC_DIR)/xsCommon.h
|
|
143
|
+
$(OBJECTS): $(SRC_DIR)/xsAll.h
|
|
144
|
+
$(OBJECTS): $(SRC_DIR)/xsScript.h
|
|
145
|
+
$(OBJECTS): $(SRC_DIR)/xsSnapshot.h
|
|
146
|
+
$(OBJECTS): $(INC_DIR)/xs.h
|
|
147
|
+
$(OBJECTS): $(EXTRA_DEPS)
|
|
148
|
+
$(TMP_DIR)/%.o: %.c
|
|
149
|
+
@echo "#" $(NAME) $(GOAL) ": cc" $(<F)
|
|
150
|
+
$(CC) $< $(C_OPTIONS) -c -o $@
|
|
151
|
+
|
|
152
|
+
clean:
|
|
153
|
+
rm -rf $(BUILD_DIR)/bin/lin/debug/$(NAME)
|
|
154
|
+
rm -rf $(BUILD_DIR)/bin/lin/release/$(NAME)
|
|
155
|
+
rm -rf $(BUILD_DIR)/tmp/lin/debug/$(NAME)
|
|
156
|
+
rm -rf $(BUILD_DIR)/tmp/lin/release/$(NAME)
|