@@ -20,6 +20,7 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
2020use tracing:: { instrument, Span } ;
2121
2222use super :: guest_dispatch:: call_function_on_guest;
23+ use crate :: sandbox:: Callable ;
2324use crate :: { MultiUseSandbox , Result } ;
2425/// A context for calling guest functions.
2526///
@@ -50,6 +51,31 @@ impl MultiUseGuestCallContext {
5051 Self { sbox }
5152 }
5253
54+ /// Close out the context and get back the internally-stored
55+ /// `MultiUseSandbox`. Future contexts opened by the returned sandbox
56+ /// will have guest state restored.
57+ #[ instrument( err( Debug ) , skip( self ) , parent = Span :: current( ) ) ]
58+ pub fn finish ( mut self ) -> Result < MultiUseSandbox > {
59+ self . sbox . restore_state ( ) ?;
60+ Ok ( self . sbox )
61+ }
62+ /// Close out the context and get back the internally-stored
63+ /// `MultiUseSandbox`.
64+ ///
65+ /// Note that this method is pub(crate) and does not reset the state of the
66+ /// sandbox.
67+ ///
68+ /// It is intended to be used when evolving a MultiUseSandbox to a new state
69+ /// and is not intended to be called publicly. It allows the state of the guest to be altered
70+ /// during the evolution of one sandbox state to another, enabling the new state created
71+ /// to be captured and stored in the Sandboxes state stack.
72+ ///
73+ pub ( crate ) fn finish_no_reset ( self ) -> MultiUseSandbox {
74+ self . sbox
75+ }
76+ }
77+
78+ impl Callable for MultiUseGuestCallContext {
5379 /// Call the guest function called `func_name` with the given arguments
5480 /// `args`, and expect the return value have the same type as
5581 /// `func_ret_type`.
@@ -61,7 +87,7 @@ impl MultiUseGuestCallContext {
6187 /// If you want to reset state, call `finish()` on this `MultiUseGuestCallContext`
6288 /// and get a new one from the resulting `MultiUseSandbox`
6389 #[ instrument( err( Debug ) , skip( self , args) , parent = Span :: current( ) ) ]
64- pub fn call (
90+ fn call (
6591 & mut self ,
6692 func_name : & str ,
6793 func_ret_type : ReturnType ,
@@ -74,29 +100,6 @@ impl MultiUseGuestCallContext {
74100
75101 call_function_on_guest ( & mut self . sbox , func_name, func_ret_type, args)
76102 }
77-
78- /// Close out the context and get back the internally-stored
79- /// `MultiUseSandbox`. Future contexts opened by the returned sandbox
80- /// will have guest state restored.
81- #[ instrument( err( Debug ) , skip( self ) , parent = Span :: current( ) ) ]
82- pub fn finish ( mut self ) -> Result < MultiUseSandbox > {
83- self . sbox . restore_state ( ) ?;
84- Ok ( self . sbox )
85- }
86- /// Close out the context and get back the internally-stored
87- /// `MultiUseSandbox`.
88- ///
89- /// Note that this method is pub(crate) and does not reset the state of the
90- /// sandbox.
91- ///
92- /// It is intended to be used when evolving a MultiUseSandbox to a new state
93- /// and is not intended to be called publicly. It allows the state of the guest to be altered
94- /// during the evolution of one sandbox state to another, enabling the new state created
95- /// to be captured and stored in the Sandboxes state stack.
96- ///
97- pub ( crate ) fn finish_no_reset ( self ) -> MultiUseSandbox {
98- self . sbox
99- }
100103}
101104
102105#[ cfg( test) ]
@@ -109,6 +112,7 @@ mod tests {
109112 } ;
110113 use hyperlight_testing:: simple_guest_as_string;
111114
115+ use crate :: sandbox:: Callable ;
112116 use crate :: sandbox_state:: sandbox:: EvolvableSandbox ;
113117 use crate :: sandbox_state:: transition:: Noop ;
114118 use crate :: { GuestBinary , HyperlightError , MultiUseSandbox , Result , UninitializedSandbox } ;
0 commit comments