Skip to content

Commit 5fdaf9d

Browse files
authoredJan 14, 2021
Merge pull request #2194 from dckc/xs-vat-lockdown
bootstrap SES shim on xsnap
2 parents 437814c + 1affb63 commit 5fdaf9d

20 files changed

+96
-520
lines changed
 

‎.github/workflows/test-all-packages.yml

-6
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,6 @@ jobs:
313313
if: steps.built.outputs.cache-hit != 'true'
314314
# END-RESTORE-BOILERPLATE
315315

316-
- name: install XS dependencies
317-
working-directory: ./packages/xs-vat-worker
318-
run: yarn install:xs-lin
319-
- name: yarn build XS worker
320-
working-directory: ./packages/xs-vat-worker
321-
run: yarn build:xs-lin
322316
- name: yarn test (SwingSet)
323317
run: cd packages/SwingSet && yarn test
324318
env:

‎packages/xs-vat-worker/Makefile

-61
This file was deleted.

‎packages/xs-vat-worker/manifest.json

-40
This file was deleted.

‎packages/xs-vat-worker/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
"main": "src/locate.js",
99
"module": "src/locate.js",
1010
"scripts": {
11-
"install:xs-lin": "make install-deps",
12-
"build:xs-lin": "make",
1311
"test": "ava",
14-
"build": "exit 0",
12+
"build": "rollup --config rollup.config.js",
1513
"lint-fix": "eslint --fix '**/*.{js,jsx}'",
1614
"lint-check": "eslint '**/*.{js,jsx}'",
1715
"lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.{js,jsx}'",
@@ -27,6 +25,8 @@
2725
"timeout": "2m"
2826
},
2927
"devDependencies": {
28+
"@rollup/plugin-commonjs": "^11.0.2",
29+
"@rollup/plugin-node-resolve": "^7.1.1",
3030
"ava": "^3.12.1",
3131
"detective-es6": "^2.2.0",
3232
"eslint": "^6.8.0",
@@ -38,7 +38,8 @@
3838
"eslint-plugin-prettier": "^3.1.2",
3939
"filing-cabinet": "^2.5.1",
4040
"nyc": "^15.1.0",
41-
"prettier": "^1.18.2"
41+
"prettier": "^1.18.2",
42+
"rollup": "^1.23.1"
4243
},
4344
"dependencies": {
4445
"@agoric/assert": "^0.2.0",
@@ -49,8 +50,10 @@
4950
"@agoric/marshal": "^0.3.0",
5051
"@agoric/promise-kit": "^0.2.0",
5152
"@agoric/swingset-vat": "^0.11.0",
53+
"@agoric/xsnap": "^0.1.0",
5254
"anylogger": "^0.21.0",
53-
"esm": "^3.2.5"
55+
"esm": "^3.2.5",
56+
"ses": "^0.11.0"
5457
},
5558
"keywords": [],
5659
"files": [
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import resolve from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
4+
export default [
5+
{
6+
input: 'src/bootstrap.js',
7+
output: {
8+
file: `dist/bootstrap.umd.js`,
9+
format: 'umd',
10+
name: 'Bootstrap',
11+
},
12+
plugins: [resolve(), commonjs()],
13+
},
14+
];

‎packages/xs-vat-worker/src-native/fdchan.c

-74
This file was deleted.

‎packages/xs-vat-worker/src-native/fdchan.js

-9
This file was deleted.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './console-shim';
2+
import './text-shim';
3+
import './lockdown-shim';
4+
5+
harden(console);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const noop = _ => undefined;
2+
3+
globalThis.console = {
4+
debug: noop,
5+
log: noop,
6+
info: noop,
7+
warn: noop,
8+
error: noop,
9+
};

‎packages/xs-vat-worker/src/console.js

-22
This file was deleted.

‎packages/xs-vat-worker/src/endo-load.js

-59
This file was deleted.

‎packages/xs-vat-worker/src/harden.js

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* global lockdown */
2+
3+
import 'ses/lockdown';
4+
5+
lockdown();
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable class-methods-use-this */
2+
3+
// Save this XS extension before SES shim deletes it.
4+
const { fromString } = ArrayBuffer;
5+
6+
class TextEncoder {
7+
encode(s) {
8+
return new Uint8Array(fromString(s));
9+
}
10+
}
11+
12+
globalThis.TextEncoder = TextEncoder;

‎packages/xs-vat-worker/start-xs.js

-45
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import test from 'ava';
2+
import * as childProcess from 'child_process';
3+
import * as os from 'os';
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
import { xsnap } from '@agoric/xsnap';
7+
8+
const dist = async name =>
9+
fs.promises.readFile(path.join(__filename, '..', '..', 'dist', name));
10+
11+
const decoder = new TextDecoder();
12+
13+
const xsnapOptions = {
14+
spawn: childProcess.spawn,
15+
os: os.type(),
16+
};
17+
18+
test('bootstrap to SES lockdown', async t => {
19+
const bootScript = await dist('bootstrap.umd.js');
20+
const messages = [];
21+
async function handleCommand(message) {
22+
messages.push(decoder.decode(message));
23+
return new Uint8Array();
24+
}
25+
const name = 'SES lockdown worker';
26+
const vat = xsnap({ ...xsnapOptions, handleCommand, name });
27+
await vat.evaluate(bootScript);
28+
t.deepEqual([], messages);
29+
30+
await vat.evaluate(`
31+
const encoder = new TextEncoder();
32+
globalThis.send = msg => issueCommand(encoder.encode(JSON.stringify(msg)).buffer);
33+
`);
34+
await vat.evaluate(`
35+
send([ typeof harden, typeof Compartment ]);
36+
`);
37+
await vat.close();
38+
t.deepEqual(['["function","function"]'], messages);
39+
});

‎packages/xs-vat-worker/test/test-locate.js

-11
This file was deleted.

‎packages/xs-vat-worker/tools/findmods.js

-176
This file was deleted.

‎packages/xsnap/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agoric/xsnap",
3-
"version": "0.0.0+1-dev",
3+
"version": "0.1.0",
44
"description": "Description forthcoming.",
55
"author": "Agoric",
66
"license": "Apache-2.0",

‎packages/xsnap/src/xsnap.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,18 @@ int main(int argc, char* argv[])
322322
xsBeginHost(machine);
323323
{
324324
xsVars(3);
325-
xsVar(1) = xsArrayBuffer(nsbuf + 1, nslen - 1);
326325
xsTry {
327326
if (command == '?') {
327+
xsVar(1) = xsArrayBuffer(nsbuf + 1, nslen - 1);
328328
xsVar(2) = xsCall1(xsGlobal, xsID("handleCommand"), xsVar(1));
329329
if (xsTypeOf(xsVar(2)) != xsUndefinedType) {
330330
responseLength = fxGetArrayBufferLength(machine, &xsVar(2));
331331
response = malloc(responseLength);
332332
fxGetArrayBufferData(machine, &xsVar(2), 0, response, responseLength);
333333
}
334334
} else {
335-
xsVar(0) = xsGet(xsGlobal, xsID("String"));
336-
xsVar(2) = xsCall1(xsVar(0), xsID("fromArrayBuffer"), xsVar(1));
337-
xsCall1(xsGlobal, xsID("eval"), xsVar(2));
335+
xsVar(1) = xsStringBuffer(nsbuf + 1, nslen - 1);
336+
xsCall1_noResult(xsGlobal, xsID("eval"), xsVar(1));
338337
}
339338
}
340339
xsCatch {

0 commit comments

Comments
 (0)
Please sign in to comment.