Skip to content

Creates hyperlight-guest-bin crate #545

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

Merged
merged 9 commits into from
Jun 2, 2025

Conversation

danbugs
Copy link
Contributor

@danbugs danbugs commented Jun 2, 2025

This PR splits the hyperlight_guest crate into two:
(1) The core hyperlight_guest crate: It provides only the essential building blocks for interacting with the host environment, including the VM exit mechanism (outb), abstractions for calling host functions and receiving return values, and the input/output stacks used for guest-host communication. This is the kind of crate that custom guests (e.g., Nanvix) can use to avoid duplicating code.
(2) NEW The hyperlight_guest_bin crate: This crate contains the opinionated bits of the guest library, such as the panic handler, the entry point, the guest logger, the exception handling logic, and third_party code used by our C-API.

Below is a diagram to help illustrate how guests can rely on functionalities of each crate.
image

It might help to review this PR commit-by-commit.

@danbugs danbugs added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Jun 2, 2025
@danbugs
Copy link
Contributor Author

danbugs commented Jun 2, 2025

@jprendes ~ for this PR, we'll have to reserve hyperlight-guest-bin on crates.io.

@danbugs danbugs force-pushed the split-hl-guest-lib branch from 8e14ab3 to 2a75b5e Compare June 2, 2025 01:27
@simongdavies simongdavies mentioned this pull request Jun 2, 2025
@danbugs danbugs force-pushed the split-hl-guest-lib branch from 2a75b5e to 9e6739f Compare June 2, 2025 17:51
simongdavies
simongdavies previously approved these changes Jun 2, 2025
Copy link
Contributor

@simongdavies simongdavies left a comment

Choose a reason for hiding this comment

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

Just minor comments LGTM , lets get one other person to look at it before we merge it?

ludfjig
ludfjig previously approved these changes Jun 2, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

lgtm

@danbugs danbugs dismissed stale reviews from ludfjig and simongdavies via a47e6a7 June 2, 2025 20:53
@danbugs danbugs force-pushed the split-hl-guest-lib branch 2 times, most recently from a47e6a7 to adaa29f Compare June 2, 2025 21:00
danbugs added 9 commits June 2, 2025 21:36
It's currently hard to use the guest library. For instance, it defines a panic handler, which will
cause compilation errors if a user of the library already has one defined. This commit creates a new crate to
house the opinionated bits of the guest library to make its base functionality (i.e., causing
VM exits, calling host functions) easier to consume without sacrificing functionality that currently exists in
guest lib that makes writing guest apps easier.

Aside from creating the crate, this commit also fixes up some doc references that referenced the guest lib
alone.

Signed-off-by: danbugs <[email protected]>
…gger + exceptions + guest function logic + guest_err

- moved entrypoint to guest_bin library. W/ this, I also moved a lot of things that were only used via the entrypoint:
-- IDT/GDT setup for exceptions.
-- guest_logger.

- w/ the entrypoint fxn from the guest lib having moved, I re-named that module to 'exit' as it still contains stuff for
aborting guest execution. I also moved OUT functions there like 'outb' and 'out32'.

- a lot of our public functions in the guest lib, like, for example, push_shared_output_data relied on a pub(crate) global
(i.e., P_PEB) being set. W/ that only ever being set in the entrypoint and w/ it not being appropriate as pub, I created a
GuestHandle struct. This struct houses a *mut HyperlightPEB that operations like push_shared_output_data can leverage.
bin-like crates can then create their own GuestHandle globals and use its functionality like self.push_shared_output_data(...).

- moved all out guest function defintion, registration and so on to the guest_bin crate.

Signed-off-by: danbugs <[email protected]>
This module defines C-wrappers for our global allocator, specific to the needs of our C-API and custom guests,
so it makes sense to move it.

Signed-off-by: danbugs <[email protected]>
guest lib should only contain basic functions to interact with the host. Whatever we decide to bring in as
third_party deps belong in the guest_bin crate.

Signed-off-by: danbugs <[email protected]>
@danbugs danbugs force-pushed the split-hl-guest-lib branch from adaa29f to a68ff5e Compare June 2, 2025 21:36
@danbugs danbugs merged commit a68ff5e into hyperlight-dev:main Jun 2, 2025
24 checks passed
@danbugs danbugs deleted the split-hl-guest-lib branch June 2, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor For PRs that restructure or remove code without adding new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants