Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xsnap): Add xsnap #2168

Merged
merged 7 commits into from
Jan 11, 2021
Merged

feat(xsnap): Add xsnap #2168

merged 7 commits into from
Jan 11, 2021

Conversation

kriskowal
Copy link
Member

@kriskowal kriskowal commented Jan 8, 2021

This change brings the XS binary xsnap into a new package of Agoric SDK. The xsnap binary can start a virtual machine from scratch or from a snapshot, and opens file descriptors 3 and 4 from the parent process to send and receive instructions, including “syscalls”, using a netstring envelope protocol. Within the netstrings, we use a single character prefix control code to evaluate, import modules, execute scripts, take snapshots, and send and receive binary messages synchronously (“syscalls”).

Co-authored-by: Dan Connolly dckc@madmode.com
Co-authored-by: Michael Kellner mkellner@moddable.tech
Co-authored-by: Moddable Open Source 32498429+Moddable-OpenSource@users.noreply

packages/xsnap/makefiles/lin/xsnap.mk Show resolved Hide resolved
packages/xsnap/makefiles/mac/xsnap.mk Show resolved Hide resolved
packages/xsnap/src/xsnap.c Outdated Show resolved Hide resolved
Comment on lines 1240 to 1243
* @param dest: where to store address of newly allocated buffer,
* which is null-terminated for compatibility with C strings
* @returns count of bytes read or -1 for error;
* caller takes ownership of *dest unless an error occurs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to update this. I changed the protocol to something more C idiomatic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine. I wonder why the "resolve conversation" button isn't showing up for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's punt on the function comment.

The norm in XS code is no comments. This is static (not exported) and the implementation is entirely straightforward. And we don't comment fxWriteNetString

packages/xsnap/src/xsnap.c Outdated Show resolved Hide resolved
char command = *nsbuf;
// fprintf(stderr, "command: len %d %c arg: %s\n", nslen, command, nsbuf + 1);
switch(command) {
case '?':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For symmetry with outbound syscalls, I changed the 'd' code to '?'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the symmetry. I wonder about > for "send". But I don't feel strongly.

packages/xsnap/src/xsnap.c Outdated Show resolved Hide resolved
@dckc
Copy link
Member

dckc commented Jan 8, 2021

I don't see any automated tests; it seems odd to approve a feature without automated tests.

I suppose it doesn't matter much since a follow-on PR will have tests, but still... I'd like to hear more about norms in this area before I approve.

@kriskowal kriskowal changed the title feat(xsnap): Add xsnap C feat(xsnap): Add xsnap Jan 8, 2021
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all my critical comments are addressed

Copy link
Member

@warner warner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

packages/xsnap/doc/XSNAP - CLI.md Outdated Show resolved Hide resolved
packages/xsnap/example/modules/after.js Outdated Show resolved Hide resolved
packages/xsnap/makefiles/lin/xsnap.mk Show resolved Hide resolved
-fno-common \
-DINCLUDE_XSPLATFORM \
-DXSPLATFORM=\"xsnap.h\" \
-DmxDebug=1 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if mxDebug is the flag that either makes normal startup impossible (because intentional exceptions wait for an xsbug that isn't running) or makes debugging impossible (because exceptions have no stack traces), maybe we should paint an arrow/comment on it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #define causes some additional functions to be incorporated in the binary, but the DEBUG environment variable is also necessary and links in additional static libraries and reduces the optimization latitude given to gcc. I’m not sure why mxDebug is always set, but I assume for good reason.

$(MACOS_VERSION_MIN) \
-DINCLUDE_XSPLATFORM \
-DXSPLATFORM=\"xsnap.h\" \
-DmxDebug=1 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH painting an arrow on it in multiple files would be a drag


const bin = debug ? xsnapDebugBin : xsnapBin;

const xsnapProcess = spawn(bin, args, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we get an actionable error message if the binary wasn't compiled first? or is that not even a thing, since it will always get compiled in the process of installing this file? I'm not sure how install-time scripts will work in the monorepo symlinking step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

I got ENOENT aka file not found once before I fixed a typo in the lin makefiles.

Copy link
Member Author

@kriskowal kriskowal Jan 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it fails but not mysteriously. The npm postinstall script should ensure that nobody sees this error. We should keep an eye open to be sure that any wrappers for yarn install are triggering the postinstall script.

packages/xsnap/src/xsnap.c Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants