@@ -17,6 +17,7 @@ limitations under the License.
1717use tracing:: { instrument, Span } ;
1818
1919use super :: { ParameterTuple , SupportedReturnType } ;
20+ use crate :: sandbox:: Callable ;
2021use crate :: { MultiUseSandbox , Result } ;
2122/// A context for calling guest functions.
2223///
@@ -47,6 +48,31 @@ impl MultiUseGuestCallContext {
4748 Self { sbox }
4849 }
4950
51+ /// Close out the context and get back the internally-stored
52+ /// `MultiUseSandbox`. Future contexts opened by the returned sandbox
53+ /// will have guest state restored.
54+ #[ instrument( err( Debug ) , skip( self ) , parent = Span :: current( ) ) ]
55+ pub fn finish ( mut self ) -> Result < MultiUseSandbox > {
56+ self . sbox . restore_state ( ) ?;
57+ Ok ( self . sbox )
58+ }
59+ /// Close out the context and get back the internally-stored
60+ /// `MultiUseSandbox`.
61+ ///
62+ /// Note that this method is pub(crate) and does not reset the state of the
63+ /// sandbox.
64+ ///
65+ /// It is intended to be used when evolving a MultiUseSandbox to a new state
66+ /// and is not intended to be called publicly. It allows the state of the guest to be altered
67+ /// during the evolution of one sandbox state to another, enabling the new state created
68+ /// to be captured and stored in the Sandboxes state stack.
69+ ///
70+ pub ( crate ) fn finish_no_reset ( self ) -> MultiUseSandbox {
71+ self . sbox
72+ }
73+ }
74+
75+ impl Callable for MultiUseGuestCallContext {
5076 /// Call the guest function called `func_name` with the given arguments
5177 /// `args`, and expect the return value have the same type as
5278 /// `func_ret_type`.
@@ -58,7 +84,7 @@ impl MultiUseGuestCallContext {
5884 /// If you want to reset state, call `finish()` on this `MultiUseGuestCallContext`
5985 /// and get a new one from the resulting `MultiUseSandbox`
6086 #[ instrument( err( Debug ) , skip( self , args) , parent = Span :: current( ) ) ]
61- pub fn call < Output : SupportedReturnType > (
87+ fn call < Output : SupportedReturnType > (
6288 & mut self ,
6389 func_name : & str ,
6490 args : impl ParameterTuple ,
@@ -75,29 +101,6 @@ impl MultiUseGuestCallContext {
75101 ) ;
76102 Output :: from_value ( ret?)
77103 }
78-
79- /// Close out the context and get back the internally-stored
80- /// `MultiUseSandbox`. Future contexts opened by the returned sandbox
81- /// will have guest state restored.
82- #[ instrument( err( Debug ) , skip( self ) , parent = Span :: current( ) ) ]
83- pub fn finish ( mut self ) -> Result < MultiUseSandbox > {
84- self . sbox . restore_state ( ) ?;
85- Ok ( self . sbox )
86- }
87- /// Close out the context and get back the internally-stored
88- /// `MultiUseSandbox`.
89- ///
90- /// Note that this method is pub(crate) and does not reset the state of the
91- /// sandbox.
92- ///
93- /// It is intended to be used when evolving a MultiUseSandbox to a new state
94- /// and is not intended to be called publicly. It allows the state of the guest to be altered
95- /// during the evolution of one sandbox state to another, enabling the new state created
96- /// to be captured and stored in the Sandboxes state stack.
97- ///
98- pub ( crate ) fn finish_no_reset ( self ) -> MultiUseSandbox {
99- self . sbox
100- }
101104}
102105
103106#[ cfg( test) ]
@@ -108,6 +111,7 @@ mod tests {
108111 use hyperlight_testing:: simple_guest_as_string;
109112
110113 use super :: MultiUseGuestCallContext ;
114+ use crate :: sandbox:: Callable ;
111115 use crate :: sandbox_state:: sandbox:: EvolvableSandbox ;
112116 use crate :: sandbox_state:: transition:: Noop ;
113117 use crate :: { GuestBinary , HyperlightError , MultiUseSandbox , Result , UninitializedSandbox } ;
0 commit comments