@@ -18,21 +18,13 @@ use alloc::format;
1818use alloc:: string:: ToString ;
1919use alloc:: vec:: Vec ;
2020
21- use flatbuffers:: FlatBufferBuilder ;
22- use hyperlight_common:: flatbuffer_wrappers:: function_call:: { FunctionCall , FunctionCallType } ;
23- use hyperlight_common:: flatbuffer_wrappers:: function_types:: {
24- FunctionCallResult , ParameterValue , ReturnType , ReturnValue ,
25- } ;
2621use hyperlight_common:: flatbuffer_wrappers:: guest_error:: ErrorCode ;
2722use hyperlight_common:: flatbuffer_wrappers:: guest_log_data:: GuestLogData ;
2823use hyperlight_common:: flatbuffer_wrappers:: guest_log_level:: LogLevel ;
29- use hyperlight_common:: flatbuffer_wrappers:: util:: estimate_flatbuffer_capacity;
30- use hyperlight_common:: outb:: OutBAction ;
3124use tracing:: instrument;
3225
3326use super :: handle:: GuestHandle ;
3427use crate :: error:: { HyperlightGuestError , Result } ;
35- use crate :: exit:: out32;
3628
3729impl GuestHandle {
3830 /// Get user memory region as bytes.
@@ -59,99 +51,6 @@ impl GuestHandle {
5951 }
6052 }
6153
62- /// Get a return value from a host function call.
63- /// This usually requires a host function to be called first using
64- /// `call_host_function_internal`.
65- ///
66- /// When calling `call_host_function<T>`, this function is called
67- /// internally to get the return value.
68- #[ instrument( skip_all, level = "Trace" ) ]
69- pub fn get_host_return_value < T : TryFrom < ReturnValue > > ( & self ) -> Result < T > {
70- let inner = self
71- . try_pop_shared_input_data_into :: < FunctionCallResult > ( )
72- . expect ( "Unable to deserialize a return value from host" )
73- . into_inner ( ) ;
74-
75- match inner {
76- Ok ( ret) => T :: try_from ( ret) . map_err ( |_| {
77- let expected = core:: any:: type_name :: < T > ( ) ;
78- HyperlightGuestError :: new (
79- ErrorCode :: UnsupportedParameterType ,
80- format ! ( "Host return value could not be converted to expected {expected}" , ) ,
81- )
82- } ) ,
83- Err ( e) => Err ( HyperlightGuestError {
84- kind : e. code ,
85- message : e. message ,
86- } ) ,
87- }
88- }
89-
90- pub fn get_host_return_raw ( & self ) -> Result < ReturnValue > {
91- let inner = self
92- . try_pop_shared_input_data_into :: < FunctionCallResult > ( )
93- . expect ( "Unable to deserialize a return value from host" )
94- . into_inner ( ) ;
95-
96- match inner {
97- Ok ( ret) => Ok ( ret) ,
98- Err ( e) => Err ( HyperlightGuestError {
99- kind : e. code ,
100- message : e. message ,
101- } ) ,
102- }
103- }
104-
105- /// Call a host function without reading its return value from shared mem.
106- /// This is used by both the Rust and C APIs to reduce code duplication.
107- ///
108- /// Note: The function return value must be obtained by calling
109- /// `get_host_return_value`.
110- #[ instrument( skip_all, level = "Trace" ) ]
111- pub fn call_host_function_without_returning_result (
112- & self ,
113- function_name : & str ,
114- parameters : Option < Vec < ParameterValue > > ,
115- return_type : ReturnType ,
116- ) -> Result < ( ) > {
117- let estimated_capacity =
118- estimate_flatbuffer_capacity ( function_name, parameters. as_deref ( ) . unwrap_or ( & [ ] ) ) ;
119-
120- let host_function_call = FunctionCall :: new (
121- function_name. to_string ( ) ,
122- parameters,
123- FunctionCallType :: Host ,
124- return_type,
125- ) ;
126-
127- let mut builder = FlatBufferBuilder :: with_capacity ( estimated_capacity) ;
128-
129- let host_function_call_buffer = host_function_call. encode ( & mut builder) ;
130- self . push_shared_output_data ( host_function_call_buffer) ?;
131-
132- unsafe {
133- out32 ( OutBAction :: CallFunction as u16 , 0 ) ;
134- }
135-
136- Ok ( ( ) )
137- }
138-
139- /// Call a host function with the given parameters and return type.
140- /// This function serializes the function call and its parameters,
141- /// sends it to the host, and then retrieves the return value.
142- ///
143- /// The return value is deserialized into the specified type `T`.
144- #[ instrument( skip_all, level = "Info" ) ]
145- pub fn call_host_function < T : TryFrom < ReturnValue > > (
146- & self ,
147- function_name : & str ,
148- parameters : Option < Vec < ParameterValue > > ,
149- return_type : ReturnType ,
150- ) -> Result < T > {
151- self . call_host_function_without_returning_result ( function_name, parameters, return_type) ?;
152- self . get_host_return_value :: < T > ( )
153- }
154-
15554 /// Log a message with the specified log level, source, caller, source file, and line number.
15655 pub fn log_message (
15756 & self ,
0 commit comments