Skip to content

Commit 43f6ea9

Browse files
committed
remove unused FunctionDefinition
Signed-off-by: Jorge Prendes <[email protected]>
1 parent cfc394c commit 43f6ea9

File tree

2 files changed

+10
-74
lines changed

2 files changed

+10
-74
lines changed

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,14 @@ limitations under the License.
1717
#![allow(non_snake_case)]
1818
use std::sync::{Arc, Mutex};
1919

20-
use hyperlight_common::flatbuffer_wrappers::function_types::{
21-
ParameterType, ParameterValue, ReturnType,
22-
};
20+
use hyperlight_common::flatbuffer_wrappers::function_types::ParameterValue;
2321
use tracing::{instrument, Span};
2422

2523
use super::{HyperlightFunction, SupportedParameterType, SupportedReturnType};
2624
use crate::sandbox::{ExtraAllowedSyscall, UninitializedSandbox};
2725
use crate::HyperlightError::UnexpectedNoOfArguments;
2826
use crate::{log_then_return, new_error, Result};
2927

30-
/// The definition of a function exposed from the host to the guest
31-
#[derive(Debug, Default, Clone, PartialEq, Eq)]
32-
pub struct HostFunctionDefinition {
33-
/// The function name
34-
pub function_name: String,
35-
/// The type of the parameter values for the host function call.
36-
pub parameter_types: Option<Vec<ParameterType>>,
37-
/// The type of the return value from the host function call
38-
pub return_type: ReturnType,
39-
}
40-
41-
impl HostFunctionDefinition {
42-
/// Create a new `HostFunctionDefinition`.
43-
pub fn new(
44-
function_name: String,
45-
parameter_types: Option<Vec<ParameterType>>,
46-
return_type: ReturnType,
47-
) -> Self {
48-
Self {
49-
function_name,
50-
parameter_types,
51-
return_type,
52-
}
53-
}
54-
}
55-
5628
/// Trait for registering a host function
5729
pub trait HostFunction<R, Args> {
5830
/// Register the host function with the given name in the sandbox.
@@ -181,8 +153,6 @@ macro_rules! impl_host_function {
181153
Ok(result.into_value())
182154
});
183155

184-
let parameter_types = Some(vec![$($P::TYPE),*]);
185-
186156
if let Some(_eas) = extra_allowed_syscalls {
187157
if cfg!(all(feature = "seccomp", target_os = "linux")) {
188158
// Register with extra allowed syscalls
@@ -193,11 +163,7 @@ macro_rules! impl_host_function {
193163
.try_lock()
194164
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
195165
.register_host_function_with_syscalls(
196-
&HostFunctionDefinition::new(
197-
name.to_string(),
198-
parameter_types,
199-
R::TYPE,
200-
),
166+
name.to_string(),
201167
HyperlightFunction::new(func),
202168
_eas,
203169
)?;
@@ -213,11 +179,7 @@ macro_rules! impl_host_function {
213179
.try_lock()
214180
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
215181
.register_host_function(
216-
&HostFunctionDefinition::new(
217-
name.to_string(),
218-
parameter_types,
219-
R::TYPE,
220-
),
182+
name.to_string(),
221183
HyperlightFunction::new(func),
222184
)?;
223185
}

src/hyperlight_host/src/sandbox/host_funcs.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
2121
use tracing::{instrument, Span};
2222

2323
use super::{ExtraAllowedSyscall, FunctionsMap};
24-
use crate::func::host_functions::HostFunctionDefinition;
2524
use crate::func::HyperlightFunction;
2625
use crate::HyperlightError::HostFunctionNotFound;
2726
use 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
3330
pub struct HostFuncsWrapper {
3431
functions_map: FunctionsMap,
35-
function_details: HostFunctionDetails,
3632
}
3733

3834
impl 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

12299
fn 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

Comments
 (0)