Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ValidatePullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- name: Spell Check Repo
uses: crate-ci/[email protected].2
uses: crate-ci/[email protected].3

license-headers:
name: check license headers
Expand Down
81 changes: 40 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/hyperlight_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Hyperlight's components common to host and guest.
workspace = true

[dependencies]
flatbuffers = { version = "25.2.10", default-features = false }
flatbuffers = { version = "25.9.23", default-features = false }
anyhow = { version = "1.0.100", default-features = false }
log = "0.4.28"
tracing = { version = "0.1.41", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ anyhow = { version = "1.0.100", default-features = false }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
hyperlight-common = { workspace = true }
hyperlight-guest-tracing = { workspace = true, default-features = false }
flatbuffers = { version= "25.2.10", default-features = false }
flatbuffers = { version= "25.9.23", default-features = false }

[features]
default = []
Expand Down
35 changes: 34 additions & 1 deletion src/hyperlight_guest_capi/src/flatbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ limitations under the License.
*/

use alloc::boxed::Box;
use alloc::ffi::CString;
use alloc::string::String;
use alloc::vec::Vec;
use core::ffi::{CStr, c_char};

use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
Expand Down Expand Up @@ -115,4 +118,34 @@ pub extern "C" fn hl_get_host_return_value_as_ULong() -> u64 {
get_host_return_value().expect("Unable to get host return value as ulong")
}

// TODO add bool, float, double, string, vecbytes
#[unsafe(no_mangle)]
pub extern "C" fn hl_get_host_return_value_as_Bool() -> bool {
get_host_return_value().expect("Unable to get host return value as bool")
}

#[unsafe(no_mangle)]
pub extern "C" fn hl_get_host_return_value_as_float() -> f32 {
get_host_return_value().expect("Unable to get host return value as f32")
}

#[unsafe(no_mangle)]
pub extern "C" fn hl_get_host_return_value_as_double() -> f64 {
get_host_return_value().expect("Unable to get host return value as f32")
}

#[unsafe(no_mangle)]
pub extern "C" fn hl_get_host_return_value_as_String() -> *const c_char {
let string_value: String =
get_host_return_value().expect("Unable to get host return value as string");

let c_string = CString::new(string_value).expect("Failed to create CString");
c_string.into_raw()
}

#[unsafe(no_mangle)]
pub extern "C" fn hl_get_host_return_value_as_VecBytes() -> Box<FfiVec> {
let vec_value: Vec<u8> =
get_host_return_value().expect("Unable to get host return value as vec bytes");

Box::new(unsafe { FfiVec::from_vec(vec_value) })
}
8 changes: 4 additions & 4 deletions src/hyperlight_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ gdbstub_arch = { version = "0.3.2", optional = true }
goblin = { version = "0.10", default-features = false, features = ["std", "elf32", "elf64", "endian_fd"] }
rand = { version = "0.9" }
cfg-if = { version = "1.0.3" }
libc = { version = "0.2.175" }
flatbuffers = "25.2.10"
libc = { version = "0.2.176" }
flatbuffers = "25.9.23"
framehop = { version = "0.15.0", optional = true }
fallible-iterator = { version = "0.3.0", optional = true }
blake3 = "1.8.2"
Expand Down Expand Up @@ -87,7 +87,7 @@ signal-hook-registry = "1.4.6"
envy = { version = "0.4.2" }
serde = "1.0"
proptest = "1.8.0"
tempfile = "3.22.0"
tempfile = "3.23.0"
crossbeam-queue = "0.3.12"
tracing-serde = "0.2.0"
hyperlight-testing = { workspace = true }
Expand All @@ -98,7 +98,7 @@ tracing-subscriber = {version = "0.3.20", features = ["std", "env-filter"]}
tracing-opentelemetry = "0.31.0"
opentelemetry = "0.30.0"
opentelemetry-otlp = { version = "0.30.0", default-features = false, features = ["http-proto", "reqwest-blocking-client"] }
opentelemetry-semantic-conventions = "0.30"
opentelemetry-semantic-conventions = "0.31"
opentelemetry_sdk = { version = "0.30.0", features = ["rt-tokio"] }
tokio = { version = "1.47.1", features = ["full"] }
criterion = "0.7.0"
Expand Down
11 changes: 11 additions & 0 deletions src/hyperlight_host/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,14 @@ fn log_test_messages(levelfilter: Option<log::LevelFilter>) {
.unwrap();
}
}

// cargo test --test integration_test log_message -- --ignored
#[test]
fn test_if_guest_is_able_to_get_return_values_from_host() {
let mut sbox1 = new_uninit().unwrap().evolve().unwrap();


let res = sbox1.call::<()>("HostReturnsBoolValue", iterations).unwrap_err();
println!("{:?}", res);
assert!(matches!(res, HyperlightError::StackOverflow()));
}
22 changes: 22 additions & 0 deletions src/tests/c_guests/c_simpleguest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ int guest_function(const char *from_host) {
return 0;
}


bool host_returns_bool_value(const char *from_host) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not taking a string as parameter might make this simpler to test

char guest_message[256] = "Hello from host_returns_bool_value, ";
int len = strlen(from_host);
strncat(guest_message, from_host, len);

hl_Parameter params = {.tag = hl_ParameterType_Bool,
.value = {.Bool = true}};
const hl_FunctionCall host_call = {.function_name = "HostMethod1",
.parameters = &params,
.parameters_len = 1,
.return_type = hl_ReturnType_Bool
};
hl_call_host_function(&host_call);
return hl_get_host_return_value_as_Bool();
}

HYPERLIGHT_WRAP_FUNCTION(host_returns_bool_value, Bool, 1, String)
HYPERLIGHT_WRAP_FUNCTION(echo, String, 1, String)
// HYPERLIGHT_WRAP_FUNCTION(set_byte_array_to_zero, 1, VecBytes) is not valid for functions that return VecBytes
HYPERLIGHT_WRAP_FUNCTION(guest_function, Int, 1, String)
Expand Down Expand Up @@ -289,6 +307,7 @@ HYPERLIGHT_WRAP_FUNCTION(log_message, Int, 2, String, Long)

void hyperlight_main(void)
{
HYPERLIGHT_REGISTER_FUNCTION("HostReturnsBoolValue", host_returns_bool_value);
HYPERLIGHT_REGISTER_FUNCTION("Echo", echo);
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes,
// so we use hl_register_function_definition directly
Expand Down Expand Up @@ -325,6 +344,9 @@ void hyperlight_main(void)
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes,
// so we use hl_register_function_definition directly
hl_register_function_definition("24K_in_8K_out", twenty_four_k_in_eight_k_out, 1, (hl_ParameterType[]){hl_ParameterType_VecBytes}, hl_ReturnType_VecBytes);
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes,
// so we use hl_register_function_definition directly
hl_register_function_definition("24K_in_8K_out", twenty_four_k_in_eight_k_out, 1, (hl_ParameterType[]){hl_ParameterType_VecBytes}, hl_ReturnType_VecBytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a copy paste of the function above?

}

// This dispatch function is only used when the host dispatches a guest function
Expand Down
Loading
Loading