@@ -21,18 +21,14 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
2121use tracing:: { instrument, Span } ;
2222
2323use super :: { ExtraAllowedSyscall , FunctionsMap } ;
24- use crate :: func:: host_functions:: HostFunctionDefinition ;
2524use crate :: func:: HyperlightFunction ;
2625use crate :: HyperlightError :: HostFunctionNotFound ;
2726use crate :: { new_error, Result } ;
2827
29- type HostFunctionDetails = Option < Vec < HostFunctionDefinition > > ;
30-
3128#[ derive( Default , Clone ) ]
3229/// A Wrapper around details of functions exposed by the Host
3330pub struct HostFuncsWrapper {
3431 functions_map : FunctionsMap ,
35- function_details : HostFunctionDetails ,
3632}
3733
3834impl HostFuncsWrapper {
@@ -44,23 +40,15 @@ impl HostFuncsWrapper {
4440 fn get_host_funcs_mut ( & mut self ) -> & mut FunctionsMap {
4541 & mut self . functions_map
4642 }
47- #[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
48- fn get_host_func_details ( & self ) -> & HostFunctionDetails {
49- & self . function_details
50- }
51- #[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
52- fn get_host_func_details_mut ( & mut self ) -> & mut HostFunctionDetails {
53- & mut self . function_details
54- }
5543
5644 /// Register a host function with the sandbox.
5745 #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level = "Trace" ) ]
5846 pub ( crate ) fn register_host_function (
5947 & mut self ,
60- hfd : & HostFunctionDefinition ,
48+ name : String ,
6149 func : HyperlightFunction ,
6250 ) -> Result < ( ) > {
63- register_host_function_helper ( self , hfd , func, None )
51+ register_host_function_helper ( self , name , func, None )
6452 }
6553
6654 /// Register a host function with the sandbox, with a list of extra syscalls
@@ -69,11 +57,11 @@ impl HostFuncsWrapper {
6957 #[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
7058 pub ( crate ) fn register_host_function_with_syscalls (
7159 & mut self ,
72- hfd : & HostFunctionDefinition ,
60+ name : String ,
7361 func : HyperlightFunction ,
7462 extra_allowed_syscalls : Vec < ExtraAllowedSyscall > ,
7563 ) -> Result < ( ) > {
76- register_host_function_helper ( self , hfd , func, Some ( extra_allowed_syscalls) )
64+ register_host_function_helper ( self , name , func, Some ( extra_allowed_syscalls) )
7765 }
7866
7967 /// Assuming a host function called `"HostPrint"` exists, and takes a
@@ -106,41 +94,27 @@ impl HostFuncsWrapper {
10694 ) -> Result < ReturnValue > {
10795 call_host_func_impl ( self . get_host_funcs ( ) , name, args)
10896 }
109-
110- /// Insert a host function into the list of registered host functions.
111- pub ( super ) fn insert_host_function ( & mut self , host_function : HostFunctionDefinition ) {
112- match & mut self . function_details {
113- Some ( host_functions) => host_functions. push ( host_function) ,
114- None => {
115- let host_functions = Vec :: from ( & [ host_function] ) ;
116- self . function_details = Some ( host_functions) ;
117- }
118- }
119- }
12097}
12198
12299fn register_host_function_helper (
123100 self_ : & mut HostFuncsWrapper ,
124- hfd : & HostFunctionDefinition ,
101+ name : String ,
125102 func : HyperlightFunction ,
126103 extra_allowed_syscalls : Option < Vec < ExtraAllowedSyscall > > ,
127104) -> Result < ( ) > {
128105 if let Some ( _syscalls) = extra_allowed_syscalls {
129106 #[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
130107 self_
131108 . get_host_funcs_mut ( )
132- . insert ( hfd . function_name . to_string ( ) , func, Some ( _syscalls) ) ;
109+ . insert ( name , func, Some ( _syscalls) ) ;
133110
134111 #[ cfg( not( all( feature = "seccomp" , target_os = "linux" ) ) ) ]
135112 return Err ( new_error ! (
136113 "Extra syscalls are only supported on Linux with seccomp"
137114 ) ) ;
138115 } else {
139- self_
140- . get_host_funcs_mut ( )
141- . insert ( hfd. function_name . to_string ( ) , func, None ) ;
116+ self_. get_host_funcs_mut ( ) . insert ( name, func, None ) ;
142117 }
143- self_. insert_host_function ( hfd. clone ( ) ) ;
144118
145119 Ok ( ( ) )
146120}
0 commit comments