This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 167
Hostcall macros and Vmctx rework #157
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
bf6a8dd
[packaging] use the new cargo-deb feature to rename the packages
acfoltzer 3c12474
[lucet-wasi] use /dev/null by default for stdio handles
acfoltzer a77f2a1
[lucetc] add exact reserved size setting
acfoltzer 608ca14
[lucet-wasi-sdk] refine API and be more verbose with commands
acfoltzer 6627fd4
Merge branch 'master' into acf/terrarium-integration
acfoltzer 577a541
[lucet-runtime] add macros for hostcalls and instance termination
acfoltzer 2ae55a1
[lucet-runtime] RefCell-based `Vmctx` interface
acfoltzer ec39d3c
Merge remote-tracking branch 'origin/master' into acf/terrarium-integ…
acfoltzer 153fe21
[lucet-runtime] silence panic output when terminating instances
acfoltzer d1ef54a
[lucet-wasi] expose `inherit_stdio` C API
acfoltzer 64f8964
[lucet-benchmarks] add benchmarks for hostcall wrapper
acfoltzer 7561b98
make `/host` ignore more specific, and check in missing test
acfoltzer 0eb7b00
[lucet-benchmarks] hostcall overhead benches now take more arguments
acfoltzer c207a24
[lucet-runtime] always inline hostcall implementation; use `move`
acfoltzer a02912d
Merge remote-tracking branch 'origin/master' into acf/terrarium-integ…
acfoltzer e56975c
[lucet-runtime] tweak the terrarium-only vmctx testing interface
acfoltzer 394494c
[lucet-runtime] remove obsolete testing functions
acfoltzer d65d75a
[lucet-runtime] 🐛 fix soundness of vmctx heap methods
acfoltzer 031089e
[lucet-runtime] document the assumptions around the Vmctx heap view
acfoltzer 476b4e2
Add another explicit page zeroing when MADV_DONTNEED is not enough
jedisct1 c20ca5b
Zero the heap only until the accessible size
jedisct1 0ffcccb
Update faerie to version 0.10 + support for extended ELF section
jedisct1 5ee3981
[lucet-runtime] make sigaltstack restore on a per-thread basis
acfoltzer 1f25930
[lucet-runtime] improve clarity of Vmctx heap/globals views
acfoltzer ab496fb
Merge remote-tracking branch 'origin/master' into acf/terrarium-integ…
acfoltzer 9f0eec1
Merge remote-tracking branch 'origin/master' into acf/terrarium-integ…
acfoltzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| target/ | ||
| *.rs.bk | ||
| *.pyc | ||
| host | ||
|
|
||
| # devenv-installed directory | ||
| /host | ||
|
|
||
| core.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
lucet-runtime/lucet-runtime-internals/src/hostcall_macros.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /// The macro that surrounds definitions of Lucet hostcalls in Rust. | ||
| /// | ||
| /// It is important to use this macro for hostcalls, rather than exporting them directly, as it | ||
| /// installs unwind protection that prevents panics from unwinding into the guest stack. | ||
| /// | ||
| /// Since this is not yet a proc macro, the syntax is unfortunately fairly brittle. The functions it | ||
| /// encloses must be of the form: | ||
| /// | ||
| /// ```ignore | ||
| /// #[$attr1] | ||
| /// #[$attr2] | ||
| /// ... // any number of attributes are supported; in most cases you will want `#[no_mangle]` | ||
| /// pub unsafe extern "C" fn $name( // must be `pub unsafe extern "C"` | ||
| /// &mut $vmctx, | ||
| /// $arg1: $arg1_ty, | ||
| /// $arg2: $arg2_ty, | ||
| /// ... , // trailing comma must always be present | ||
| /// ) -> $ret_ty { // return type must always be present even if it is `()` | ||
| /// // body | ||
| /// } | ||
| /// ``` | ||
| #[macro_export] | ||
| macro_rules! lucet_hostcalls { | ||
| { | ||
| $( | ||
| $(#[$attr:meta])* | ||
| pub unsafe extern "C" fn $name:ident( | ||
| &mut $vmctx:ident | ||
| $(, $arg:ident : $arg_ty:ty )*, | ||
| ) -> $ret_ty:ty { | ||
| $($body:tt)* | ||
| } | ||
| )* | ||
| } => { | ||
| $( | ||
| $(#[$attr])* | ||
| pub unsafe extern "C" fn $name( | ||
| vmctx_raw: *mut $crate::vmctx::lucet_vmctx, | ||
| $( $arg: $arg_ty ),* | ||
| ) -> $ret_ty { | ||
| #[inline(always)] | ||
| unsafe fn hostcall_impl( | ||
| $vmctx: &mut $crate::vmctx::Vmctx, | ||
| $( $arg : $arg_ty ),* | ||
| ) -> $ret_ty { | ||
| $($body)* | ||
| } | ||
| let res = std::panic::catch_unwind(move || { | ||
| hostcall_impl(&mut $crate::vmctx::Vmctx::from_raw(vmctx_raw), $( $arg ),*) | ||
| }); | ||
| match res { | ||
| Ok(res) => res, | ||
| Err(e) => { | ||
| if let Some(details) = e.downcast_ref::<$crate::instance::TerminationDetails>() { | ||
| let mut vmctx = $crate::vmctx::Vmctx::from_raw(vmctx_raw); | ||
| vmctx.terminate_no_unwind(details.clone()); | ||
| } else { | ||
| std::panic::resume_unwind(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )* | ||
| } | ||
| } | ||
|
|
||
| /// Terminate an instance from within a hostcall, returning an optional value as an error. | ||
| /// | ||
| /// Use this instead of `panic!` when you want the instance to terminate, but not the entire host | ||
| /// program. Like `panic!`, you can pass a format string with arguments, a value that implements | ||
| /// `Any`, or nothing to return a default message. | ||
| /// | ||
| /// Upon termination, the call to `Instance::run()` will return with an | ||
| /// `Err(Error::RuntimeTerminated)` value containing the value you pass to this macro. | ||
| /// | ||
| /// This macro safely unwinds the hostcall stack out to the entrypoint of the hostcall, so any | ||
| /// resources that may have been acquired will be properly dropped. | ||
| #[macro_export] | ||
| macro_rules! lucet_hostcall_terminate { | ||
| () => { | ||
| lucet_hostcall_terminate!("lucet_hostcall_terminate") | ||
| }; | ||
| ( $payload:expr ) => { | ||
| panic!($crate::instance::TerminationDetails::provide($payload)) | ||
| }; | ||
| ( $payload:expr, ) => { | ||
| lucet_hostcall_terminate!($payload) | ||
| }; | ||
| ( $fmt:expr, $($arg:tt)+ ) => { | ||
| lucet_hostcall_terminate!(format!($fmt, $($arg),+)) | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be a case where would not want
#[no_mangle]?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's useful when we're defining hostcalls for a
MockModuleBuilder, so hostcalls for different tests don't interfere with each other.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, these aren't technically hostcalls, but are the fake guest functions that go into the module