@@ -20,8 +20,9 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, Ret
2020
2121use super :: utils:: for_each_tuple;
2222use super :: { ParameterTuple , ResultType , SupportedReturnType } ;
23+ use crate :: sandbox:: host_funcs:: FunctionEntry ;
2324use crate :: sandbox:: { ExtraAllowedSyscall , UninitializedSandbox } ;
24- use crate :: { Result , log_then_return , new_error} ;
25+ use crate :: { Result , new_error} ;
2526
2627/// A sandbox on which (primitive) host functions can be registered
2728///
@@ -52,7 +53,15 @@ impl Registerable for UninitializedSandbox {
5253 . host_funcs
5354 . try_lock ( )
5455 . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?;
55- ( * hfs) . register_host_function ( name. to_string ( ) , hf. into ( ) . into ( ) )
56+
57+ let entry = FunctionEntry {
58+ function : hf. into ( ) . into ( ) ,
59+ extra_allowed_syscalls : None ,
60+ parameter_types : Args :: TYPE ,
61+ return_type : Output :: TYPE ,
62+ } ;
63+
64+ ( * hfs) . register_host_function ( name. to_string ( ) , entry, self . mgr . unwrap_mgr_mut ( ) )
5665 }
5766 #[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
5867 fn register_host_function_with_syscalls < Args : ParameterTuple , Output : SupportedReturnType > (
@@ -65,7 +74,15 @@ impl Registerable for UninitializedSandbox {
6574 . host_funcs
6675 . try_lock ( )
6776 . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?;
68- ( * hfs) . register_host_function_with_syscalls ( name. to_string ( ) , hf. into ( ) . into ( ) , eas)
77+
78+ let entry = FunctionEntry {
79+ function : hf. into ( ) . into ( ) ,
80+ extra_allowed_syscalls : Some ( eas) ,
81+ parameter_types : Args :: TYPE ,
82+ return_type : Output :: TYPE ,
83+ } ;
84+
85+ ( * hfs) . register_host_function ( name. to_string ( ) , entry, self . mgr . unwrap_mgr_mut ( ) )
6986 }
7087}
7188
@@ -182,31 +199,18 @@ pub(crate) fn register_host_function<Args: ParameterTuple, Output: SupportedRetu
182199) -> Result < ( ) > {
183200 let func = func. into ( ) . into ( ) ;
184201
185- if let Some ( _eas) = extra_allowed_syscalls {
186- if cfg ! ( all( feature = "seccomp" , target_os = "linux" ) ) {
187- // Register with extra allowed syscalls
188- #[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
189- {
190- sandbox
191- . host_funcs
192- . try_lock ( )
193- . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?
194- . register_host_function_with_syscalls ( name. to_string ( ) , func, _eas) ?;
195- }
196- } else {
197- // Log and return an error
198- log_then_return ! (
199- "Extra allowed syscalls are only supported on Linux with seccomp enabled"
200- ) ;
201- }
202- } else {
203- // Register without extra allowed syscalls
204- sandbox
205- . host_funcs
206- . try_lock ( )
207- . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?
208- . register_host_function ( name. to_string ( ) , func) ?;
209- }
202+ let entry = FunctionEntry {
203+ function : func,
204+ extra_allowed_syscalls : extra_allowed_syscalls. clone ( ) ,
205+ parameter_types : Args :: TYPE ,
206+ return_type : Output :: TYPE ,
207+ } ;
208+
209+ sandbox
210+ . host_funcs
211+ . try_lock ( )
212+ . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?
213+ . register_host_function ( name. to_string ( ) , entry, sandbox. mgr . unwrap_mgr_mut ( ) ) ?;
210214
211215 Ok ( ( ) )
212216}
0 commit comments