Skip to content

Commit b164763

Browse files
committed
Save an unconditional clone of guest parameters
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 8c991d1 commit b164763

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/hyperlight_guest_bin/src/guest_function/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use tracing::{Span, instrument};
2727

2828
use crate::{GUEST_HANDLE, REGISTERED_GUEST_FUNCTIONS};
2929

30-
type GuestFunc = fn(&FunctionCall) -> Result<Vec<u8>>;
30+
type GuestFunc = fn(FunctionCall) -> Result<Vec<u8>>;
3131

3232
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
3333
pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>> {
@@ -64,7 +64,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
6464
core::mem::transmute::<usize, GuestFunc>(function_pointer)
6565
};
6666

67-
p_function(&function_call)
67+
p_function(function_call)
6868
} else {
6969
// The given function is not registered. The guest should implement a function called guest_dispatch_function to handle this.
7070

src/hyperlight_guest_bin/src/guest_function/definition.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct GuestFunctionDefinition {
4141
pub function_pointer: usize,
4242
}
4343

44-
/// Trait for functions that can be converted to a `fn(&FunctionCall) -> Result<Vec<u8>>`
44+
/// Trait for functions that can be converted to a `fn(FunctionCall) -> Result<Vec<u8>>`
4545
#[doc(hidden)]
4646
pub trait IntoGuestFunction<Output, Args>
4747
where
@@ -53,8 +53,8 @@ where
5353
#[doc(hidden)]
5454
const ASSERT_ZERO_SIZED: ();
5555

56-
/// Convert the function into a `fn(&FunctionCall) -> Result<Vec<u8>>`
57-
fn into_guest_function(self) -> fn(&FunctionCall) -> Result<Vec<u8>>;
56+
/// Convert the function into a `fn(FunctionCall) -> Result<Vec<u8>>`
57+
fn into_guest_function(self) -> fn(FunctionCall) -> Result<Vec<u8>>;
5858
}
5959

6060
/// Trait for functions that can be converted to a `GuestFunctionDefinition`
@@ -124,14 +124,14 @@ macro_rules! impl_host_function {
124124
assert!(core::mem::size_of::<Self>() == 0)
125125
};
126126

127-
fn into_guest_function(self) -> fn(&FunctionCall) -> Result<Vec<u8>> {
128-
|fc: &FunctionCall| {
127+
fn into_guest_function(self) -> fn(FunctionCall) -> Result<Vec<u8>> {
128+
|fc: FunctionCall| {
129129
// SAFETY: This is safe because:
130130
// 1. F is zero-sized (enforced by the ASSERT_ZERO_SIZED const).
131131
// 2. F has no Drop impl (enforced by the Copy bound).
132132
// Therefore, creating an instance of F is safe.
133133
let this = unsafe { core::mem::zeroed::<F>() };
134-
let params = fc.parameters.clone().unwrap_or_default();
134+
let params = fc.parameters.unwrap_or_default();
135135
let params = <($($P,)*) as ParameterTuple>::from_value(params)?;
136136
let result = Function::<R::ReturnType, ($($P,)*), HyperlightGuestError>::call(&this, params)?;
137137
Ok(into_flatbuffer_result(result.into_value()))

0 commit comments

Comments
 (0)