Skip to content

Commit 70a856f

Browse files
authored
Fix some cargo docs (#749)
* Fix cargo doc warnings Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * Update docs for UninitializedSandbox Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * Update docs for MultiUseSandbox Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * Add crate-level docs to lib.rs Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * Test cargo doc on ci Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> --------- Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 652affb commit 70a856f

File tree

9 files changed

+218
-85
lines changed

9 files changed

+218
-85
lines changed

Justfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ like-ci config=default-target hypervisor="kvm":
143143
just bench-ci main {{config}} {{ if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }}
144144

145145
# runs all tests
146-
test target=default-target features="": (test-unit target features) (test-isolated target features) (test-integration "rust" target features) (test-integration "c" target features) (test-seccomp target features)
146+
test target=default-target features="": (test-unit target features) (test-isolated target features) (test-integration "rust" target features) (test-integration "c" target features) (test-seccomp target features) (test-doc target features)
147147

148148
# runs unit tests
149149
test-unit target=default-target features="":
@@ -218,6 +218,8 @@ test-rust-tracing target=default-target features="":
218218
just build-rust-guests {{ target }}
219219
just move-rust-guests {{ target }}
220220

221+
test-doc target=default-target features="":
222+
cargo test --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {''} else { "--features " + features } }} --doc
221223
################
222224
### LINTING ####
223225
################

src/hyperlight_common/src/flatbuffer_wrappers/function_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum ParameterValue {
5151
String(String),
5252
/// bool
5353
Bool(bool),
54-
/// Vec<u8>
54+
/// `Vec<u8>`
5555
VecBytes(Vec<u8>),
5656
}
5757

@@ -75,7 +75,7 @@ pub enum ParameterType {
7575
String,
7676
/// bool
7777
Bool,
78-
/// Vec<u8>
78+
/// `Vec<u8>`
7979
VecBytes,
8080
}
8181

@@ -100,7 +100,7 @@ pub enum ReturnValue {
100100
Bool(bool),
101101
/// ()
102102
Void(()),
103-
/// Vec<u8>
103+
/// `Vec<u8>`
104104
VecBytes(Vec<u8>),
105105
}
106106

@@ -128,7 +128,7 @@ pub enum ReturnType {
128128
Bool,
129129
/// ()
130130
Void,
131-
/// Vec<u8>
131+
/// `Vec<u8>`
132132
VecBytes,
133133
}
134134

src/hyperlight_host/src/func/ret_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ pub trait SupportedReturnType: Sized + Clone + Send + Sync + 'static {
3232
fn from_value(value: ReturnValue) -> Result<Self>;
3333
}
3434

35-
/// A trait to handle either a SupportedReturnType or a Result<impl SupportedReturnType>
35+
/// A trait to handle either a [`SupportedReturnType`] or a [`Result<impl SupportedReturnType>`]
3636
pub trait ResultType {
3737
/// The return type of the supported return value
3838
type ReturnType: SupportedReturnType;
3939

40-
/// Convert the return type into a Result<impl SupportedReturnType>
40+
/// Convert the return type into a `Result<impl SupportedReturnType>`
4141
fn into_result(self) -> Result<Self::ReturnType>;
4242
}
4343

src/hyperlight_host/src/func/utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ limitations under the License.
1818
/// up to 32 parameters. This is useful to implement traits on functions
1919
/// for may parameter tuples.
2020
///
21-
/// Usage:
22-
/// ```rust
23-
/// use hyperlight_host::func::for_each_tuple;
21+
/// This is an internal utility macro used within the func module.
2422
///
23+
/// ```ignore
2524
/// macro_rules! my_macro {
2625
/// ([$count:expr] ($($name:ident: $type:ident),*)) => {
2726
/// // $count is the arity of the tuple
@@ -30,7 +29,7 @@ limitations under the License.
3029
/// };
3130
/// }
3231
///
33-
/// for_each_tuple!(impl_host_function);
32+
/// for_each_tuple!(my_macro);
3433
/// ```
3534
macro_rules! for_each_tuple {
3635
(@

src/hyperlight_host/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,26 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616
#![warn(dead_code, missing_docs, unused_mut)]
17-
//! This crate contains an SDK that is used to execute specially-
18-
// compiled binaries within a very lightweight hypervisor environment.
17+
//! Hyperlight host runtime for executing guest code in lightweight virtual machines.
18+
//!
19+
//! This crate provides the host-side runtime for Hyperlight, enabling safe execution
20+
//! of untrusted guest code within micro virtual machines with minimal overhead.
21+
//! The runtime manages sandbox creation, guest function calls, memory isolation,
22+
//! and host-guest communication.
23+
//!
24+
//! The primary entry points are [`UninitializedSandbox`] for initial setup and
25+
//! [`MultiUseSandbox`] for executing guest functions.
26+
//!
27+
//! ## Guest Requirements
28+
//!
29+
//! Hyperlight requires specially compiled guest binaries and cannot run regular
30+
//! container images or executables. Guests must be built using either the Rust
31+
//! API ([`hyperlight_guest`] with optional use of [`hyperlight_guest_bin`]),
32+
//! or with the C API (`hyperlight_guest_capi`).
33+
//!
34+
//! [`hyperlight_guest`]: https://docs.rs/hyperlight_guest
35+
//! [`hyperlight_guest_bin`]: https://docs.rs/hyperlight_guest_bin
36+
//!
1937
2038
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))]
2139
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))]

src/hyperlight_host/src/mem/shared_mem.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ unsafe impl Send for GuestSharedMemory {}
183183
///
184184
/// Unfortunately, there appears to be no way to do this with defined
185185
/// behaviour in present Rust (see
186-
/// e.g. https://github.com/rust-lang/unsafe-code-guidelines/issues/152).
186+
/// e.g. <https://github.com/rust-lang/unsafe-code-guidelines/issues/152>).
187187
/// Rust does not yet have its own defined memory model, but in the
188188
/// interim, it is widely treated as inheriting the current C/C++
189189
/// memory models. The most immediate problem is that regardless of
190-
/// anything else, under those memory models [1, p. 17-18; 2, p. 88],
190+
/// anything else, under those memory models \[1, p. 17-18; 2, p. 88\],
191191
///
192192
/// > The execution of a program contains a _data race_ if it
193193
/// > contains two [C++23: "potentially concurrent"] conflicting
@@ -205,28 +205,28 @@ unsafe impl Send for GuestSharedMemory {}
205205
/// Despite Rust's de jure inheritance of the C memory model at the
206206
/// present time, the compiler in many cases de facto adheres to LLVM
207207
/// semantics, so it is worthwhile to consider what LLVM does in this
208-
/// case as well. According to the the LangRef [3] memory model,
208+
/// case as well. According to the the LangRef \[3\] memory model,
209209
/// loads which are involved in a race that includes at least one
210210
/// non-atomic access (whether the load or a store) return `undef`,
211211
/// making them roughly equivalent to reading uninitialized
212212
/// memory. While this is much better, it is still bad.
213213
///
214214
/// Considering a different direction, recent C++ papers have seemed
215215
/// to lean towards using `volatile` for similar use cases. For
216-
/// example, in P1152R0 [4], JF Bastien notes that
216+
/// example, in P1152R0 \[4\], JF Bastien notes that
217217
///
218218
/// > We’ve shown that volatile is purposely defined to denote
219219
/// > external modifications. This happens for:
220220
/// > - Shared memory with untrusted code, where volatile is the
221221
/// > right way to avoid time-of-check time-of-use (ToCToU)
222-
/// > races which lead to security bugs such as [PWN2OWN] and
223-
/// > [XENXSA155].
222+
/// > races which lead to security bugs such as \[PWN2OWN\] and
223+
/// > \[XENXSA155\].
224224
///
225225
/// Unfortunately, although this paper was adopted for C++20 (and,
226226
/// sadly, mostly un-adopted for C++23, although that does not concern
227227
/// us), the paper did not actually redefine volatile accesses or data
228228
/// races to prevent volatile accesses from racing with other accesses
229-
/// and causing undefined behaviour. P1382R1 [5] would have amended
229+
/// and causing undefined behaviour. P1382R1 \[5\] would have amended
230230
/// the wording of the data race definition to specifically exclude
231231
/// volatile, but, unfortunately, despite receiving a
232232
/// generally-positive reception at its first WG21 meeting more than
@@ -272,8 +272,8 @@ unsafe impl Send for GuestSharedMemory {}
272272
/// the guest in this case. Unfortunately, while those operations are
273273
/// defined in LLVM, they are not presently exposed to Rust. While
274274
/// atomic fences that are not associated with memory accesses
275-
/// (std::sync::atomic::fence) might at first glance seem to help with
276-
/// this problem, they unfortunately do not [6]:
275+
/// ([`std::sync::atomic::fence`]) might at first glance seem to help with
276+
/// this problem, they unfortunately do not \[6\]:
277277
///
278278
/// > A fence ‘A’ which has (at least) Release ordering semantics,
279279
/// > synchronizes with a fence ‘B’ with (at least) Acquire
@@ -289,12 +289,12 @@ unsafe impl Send for GuestSharedMemory {}
289289
/// fence on a vmenter/vmexit between data being read and written.
290290
/// This is unsafe (not guaranteed in the type system)!
291291
///
292-
/// [1] N3047 C23 Working Draft. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf
293-
/// [2] N4950 C++23 Working Draft. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf
294-
/// [3] LLVM Language Reference Manual, Memory Model for Concurrent Operations. https://llvm.org/docs/LangRef.html#memmodel
295-
/// [4] P1152R0: Deprecating `volatile`. JF Bastien. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1152r0.html
296-
/// [5] P1382R1: `volatile_load<T>` and `volatile_store<T>`. JF Bastien, Paul McKenney, Jeffrey Yasskin, and the indefatigable TBD. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1382r1.pdf
297-
/// [6] Documentation for std::sync::atomic::fence. https://doc.rust-lang.org/std/sync/atomic/fn.fence.html
292+
/// \[1\] N3047 C23 Working Draft. <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf>
293+
/// \[2\] N4950 C++23 Working Draft. <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf>
294+
/// \[3\] LLVM Language Reference Manual, Memory Model for Concurrent Operations. <https://llvm.org/docs/LangRef.html#memmodel>
295+
/// \[4\] P1152R0: Deprecating `volatile`. JF Bastien. <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1152r0.html>
296+
/// \[5\] P1382R1: `volatile_load<T>` and `volatile_store<T>`. JF Bastien, Paul McKenney, Jeffrey Yasskin, and the indefatigable TBD. <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1382r1.pdf>
297+
/// \[6\] Documentation for std::sync::atomic::fence. <https://doc.rust-lang.org/std/sync/atomic/fn.fence.html>
298298
#[derive(Clone, Debug)]
299299
pub struct HostSharedMemory {
300300
region: Arc<HostMapping>,

0 commit comments

Comments
 (0)