@@ -29,7 +29,13 @@ use crate::{new_error, Result};
29
29
#[ derive( Default , Clone ) ]
30
30
/// A Wrapper around details of functions exposed by the Host
31
31
pub struct HostFuncsWrapper {
32
- functions_map : HashMap < String , ( HyperlightFunction , Option < Vec < ExtraAllowedSyscall > > ) > ,
32
+ functions_map : HashMap < String , FunctionEntry > ,
33
+ }
34
+
35
+ #[ derive( Clone ) ]
36
+ pub struct FunctionEntry {
37
+ pub function : HyperlightFunction ,
38
+ pub extra_allowed_syscalls : Option < Vec < ExtraAllowedSyscall > > ,
33
39
}
34
40
35
41
impl HostFuncsWrapper {
@@ -86,7 +92,7 @@ impl HostFuncsWrapper {
86
92
fn register_host_function_helper (
87
93
& mut self ,
88
94
name : String ,
89
- func : HyperlightFunction ,
95
+ function : HyperlightFunction ,
90
96
extra_allowed_syscalls : Option < Vec < ExtraAllowedSyscall > > ,
91
97
) -> Result < ( ) > {
92
98
#[ cfg( not( all( feature = "seccomp" , target_os = "linux" ) ) ) ]
@@ -95,16 +101,24 @@ impl HostFuncsWrapper {
95
101
"Extra syscalls are only supported on Linux with seccomp"
96
102
) ) ;
97
103
}
98
- self . functions_map
99
- . insert ( name, ( func, extra_allowed_syscalls) ) ;
104
+ self . functions_map . insert (
105
+ name,
106
+ FunctionEntry {
107
+ function,
108
+ extra_allowed_syscalls,
109
+ } ,
110
+ ) ;
100
111
Ok ( ( ) )
101
112
}
102
113
103
114
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level = "Trace" ) ]
104
115
fn call_host_func_impl ( & self , name : & str , args : Vec < ParameterValue > ) -> Result < ReturnValue > {
105
116
// Inner function containing the common logic
106
117
let do_call = || {
107
- let ( func, syscalls) = self
118
+ let FunctionEntry {
119
+ function,
120
+ extra_allowed_syscalls,
121
+ } = self
108
122
. functions_map
109
123
. get ( name)
110
124
. ok_or_else ( || HostFunctionNotFound ( name. to_string ( ) ) ) ?;
@@ -113,12 +127,12 @@ impl HostFuncsWrapper {
113
127
{
114
128
let seccomp_filter =
115
129
crate :: seccomp:: guest:: get_seccomp_filter_for_host_function_worker_thread (
116
- syscalls . clone ( ) ,
130
+ extra_allowed_syscalls . clone ( ) ,
117
131
) ?;
118
132
seccompiler:: apply_filter ( & seccomp_filter) ?;
119
133
}
120
134
121
- crate :: metrics:: maybe_time_and_emit_host_call ( name, || func . call ( args) )
135
+ crate :: metrics:: maybe_time_and_emit_host_call ( name, || function . call ( args) )
122
136
} ;
123
137
124
138
// Create a new thread when seccomp is enabled on Linux
0 commit comments