@@ -14,33 +14,25 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ use std:: collections:: HashMap ;
1718use std:: io:: { IsTerminal , Write } ;
1819
1920use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterValue , ReturnValue } ;
2021use termcolor:: { Color , ColorChoice , ColorSpec , StandardStream , WriteColor } ;
2122use tracing:: { instrument, Span } ;
2223
23- use super :: { ExtraAllowedSyscall , FunctionsMap } ;
24+ use super :: ExtraAllowedSyscall ;
2425use crate :: func:: HyperlightFunction ;
2526use crate :: HyperlightError :: HostFunctionNotFound ;
2627use crate :: { new_error, Result } ;
2728
2829#[ derive( Default , Clone ) ]
2930/// A Wrapper around details of functions exposed by the Host
3031pub struct HostFuncsWrapper {
31- functions_map : FunctionsMap ,
32+ functions_map : HashMap < String , ( HyperlightFunction , Option < Vec < ExtraAllowedSyscall > > ) > ,
3233}
3334
3435impl HostFuncsWrapper {
35- #[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
36- fn get_host_funcs ( & self ) -> & FunctionsMap {
37- & self . functions_map
38- }
39- #[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
40- fn get_host_funcs_mut ( & mut self ) -> & mut FunctionsMap {
41- & mut self . functions_map
42- }
43-
4436 /// Register a host function with the sandbox.
4537 #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level = "Trace" ) ]
4638 pub ( crate ) fn register_host_function (
@@ -72,7 +64,7 @@ impl HostFuncsWrapper {
7264 #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level = "Trace" ) ]
7365 pub ( super ) fn host_print ( & mut self , msg : String ) -> Result < i32 > {
7466 let res = call_host_func_impl (
75- self . get_host_funcs ( ) ,
67+ & self . functions_map ,
7668 "HostPrint" ,
7769 vec ! [ ParameterValue :: String ( msg) ] ,
7870 ) ?;
@@ -92,7 +84,7 @@ impl HostFuncsWrapper {
9284 name : & str ,
9385 args : Vec < ParameterValue > ,
9486 ) -> Result < ReturnValue > {
95- call_host_func_impl ( self . get_host_funcs ( ) , name, args)
87+ call_host_func_impl ( & self . functions_map , name, args)
9688 }
9789}
9890
@@ -104,30 +96,28 @@ fn register_host_function_helper(
10496) -> Result < ( ) > {
10597 if let Some ( _syscalls) = extra_allowed_syscalls {
10698 #[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
107- self_
108- . get_host_funcs_mut ( )
109- . insert ( name, func, Some ( _syscalls) ) ;
99+ self_. functions_map . insert ( name, ( func, Some ( _syscalls) ) ) ;
110100
111101 #[ cfg( not( all( feature = "seccomp" , target_os = "linux" ) ) ) ]
112102 return Err ( new_error ! (
113103 "Extra syscalls are only supported on Linux with seccomp"
114104 ) ) ;
115105 } else {
116- self_. get_host_funcs_mut ( ) . insert ( name, func, None ) ;
106+ self_. functions_map . insert ( name, ( func, None ) ) ;
117107 }
118108
119109 Ok ( ( ) )
120110}
121111
122112#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level = "Trace" ) ]
123113fn call_host_func_impl (
124- host_funcs : & FunctionsMap ,
114+ host_funcs : & HashMap < String , ( HyperlightFunction , Option < Vec < ExtraAllowedSyscall > > ) > ,
125115 name : & str ,
126116 args : Vec < ParameterValue > ,
127117) -> Result < ReturnValue > {
128118 // Inner function containing the common logic
129119 fn call_func (
130- host_funcs : & FunctionsMap ,
120+ host_funcs : & HashMap < String , ( HyperlightFunction , Option < Vec < ExtraAllowedSyscall > > ) > ,
131121 name : & str ,
132122 args : Vec < ParameterValue > ,
133123 ) -> Result < ReturnValue > {
0 commit comments