@@ -20,8 +20,9 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, Ret
20
20
21
21
use super :: utils:: for_each_tuple;
22
22
use super :: { ParameterTuple , ResultType , SupportedReturnType } ;
23
+ use crate :: sandbox:: host_funcs:: FunctionEntry ;
23
24
use crate :: sandbox:: { ExtraAllowedSyscall , UninitializedSandbox } ;
24
- use crate :: { Result , log_then_return , new_error} ;
25
+ use crate :: { Result , new_error} ;
25
26
26
27
/// A sandbox on which (primitive) host functions can be registered
27
28
///
@@ -52,7 +53,15 @@ impl Registerable for UninitializedSandbox {
52
53
. host_funcs
53
54
. try_lock ( )
54
55
. 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 ( ) )
56
65
}
57
66
#[ cfg( all( feature = "seccomp" , target_os = "linux" ) ) ]
58
67
fn register_host_function_with_syscalls < Args : ParameterTuple , Output : SupportedReturnType > (
@@ -65,7 +74,15 @@ impl Registerable for UninitializedSandbox {
65
74
. host_funcs
66
75
. try_lock ( )
67
76
. 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 ( ) )
69
86
}
70
87
}
71
88
@@ -182,31 +199,18 @@ pub(crate) fn register_host_function<Args: ParameterTuple, Output: SupportedRetu
182
199
) -> Result < ( ) > {
183
200
let func = func. into ( ) . into ( ) ;
184
201
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 ( ) ) ?;
210
214
211
215
Ok ( ( ) )
212
216
}
0 commit comments