Skip to content

Commit 944472d

Browse files
committed
Remove FunctionsMap
Signed-off-by: Jorge Prendes <[email protected]>
1 parent 43f6ea9 commit 944472d

File tree

2 files changed

+9
-65
lines changed

2 files changed

+9
-65
lines changed

src/hyperlight_host/src/sandbox/host_funcs.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,25 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use std::collections::HashMap;
1718
use std::io::{IsTerminal, Write};
1819

1920
use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnValue};
2021
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
2122
use tracing::{instrument, Span};
2223

23-
use super::{ExtraAllowedSyscall, FunctionsMap};
24+
use super::ExtraAllowedSyscall;
2425
use crate::func::HyperlightFunction;
2526
use crate::HyperlightError::HostFunctionNotFound;
2627
use crate::{new_error, Result};
2728

2829
#[derive(Default, Clone)]
2930
/// A Wrapper around details of functions exposed by the Host
3031
pub struct HostFuncsWrapper {
31-
functions_map: FunctionsMap,
32+
functions_map: HashMap<String, (HyperlightFunction, Option<Vec<ExtraAllowedSyscall>>)>,
3233
}
3334

3435
impl 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")]
123113
fn 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> {

src/hyperlight_host/src/sandbox/mod.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub mod uninitialized;
4545
/// initialized `Sandbox`es.
4646
pub(crate) mod uninitialized_evolve;
4747

48-
use std::collections::HashMap;
49-
5048
/// Re-export for `SandboxConfiguration` type
5149
pub use config::SandboxConfiguration;
5250
/// Re-export for the `MultiUseSandbox` type
@@ -60,7 +58,6 @@ pub use uninitialized::GuestBinary;
6058
pub use uninitialized::UninitializedSandbox;
6159

6260
use self::mem_mgr::MemMgrWrapper;
63-
use crate::func::HyperlightFunction;
6461
use crate::hypervisor::hypervisor_handler::HypervisorHandler;
6562
#[cfg(target_os = "windows")]
6663
use crate::hypervisor::windows_hypervisor_platform;
@@ -86,49 +83,6 @@ pub fn is_supported_platform() -> bool {
8683
/// Alias for the type of extra allowed syscalls.
8784
pub type ExtraAllowedSyscall = i64;
8885

89-
/// A `HashMap` to map function names to `HyperlightFunction`s and their extra allowed syscalls.
90-
///
91-
/// Note: you cannot add extra syscalls on Windows, but the field is still present to avoid a funky
92-
/// conditional compilation setup. This isn't a big deal as this struct isn't public facing.
93-
#[derive(Clone, Default)]
94-
pub(super) struct FunctionsMap(
95-
HashMap<String, (HyperlightFunction, Option<Vec<ExtraAllowedSyscall>>)>,
96-
);
97-
98-
impl FunctionsMap {
99-
/// Insert a new entry into the map
100-
pub(super) fn insert(
101-
&mut self,
102-
key: String,
103-
value: HyperlightFunction,
104-
extra_syscalls: Option<Vec<ExtraAllowedSyscall>>,
105-
) {
106-
self.0.insert(key, (value, extra_syscalls));
107-
}
108-
109-
/// Get the value associated with the given key, if it exists.
110-
pub(super) fn get(
111-
&self,
112-
key: &str,
113-
) -> Option<&(HyperlightFunction, Option<Vec<ExtraAllowedSyscall>>)> {
114-
self.0.get(key)
115-
}
116-
117-
/// Get the length of the map.
118-
fn len(&self) -> usize {
119-
self.0.len()
120-
}
121-
}
122-
123-
impl PartialEq for FunctionsMap {
124-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
125-
fn eq(&self, other: &Self) -> bool {
126-
self.len() == other.len() && self.0.keys().all(|k| other.0.contains_key(k))
127-
}
128-
}
129-
130-
impl Eq for FunctionsMap {}
131-
13286
/// Determine whether a suitable hypervisor is available to run
13387
/// this sandbox.
13488
///

0 commit comments

Comments
 (0)