Skip to content

Commit 8654dc9

Browse files
committed
[common/outb,host/outb,guest] moved OutBAction to common lib
OutBAction was duplicated across the host and guest. Signed-off-by: danbugs <[email protected]>
1 parent e680cf4 commit 8654dc9

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

src/hyperlight_common/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ pub mod flatbuffer_wrappers;
3636
mod flatbuffers;
3737
/// cbindgen:ignore
3838
pub mod mem;
39+
40+
/// cbindgen:ignore
41+
pub mod outb;

src/hyperlight_common/src/outb.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub enum OutBAction {
2+
Log = 99,
3+
CallFunction = 101,
4+
Abort = 102,
5+
}
6+
7+
impl TryFrom<u16> for OutBAction {
8+
type Error = anyhow::Error;
9+
fn try_from(val: u16) -> anyhow::Result<Self> {
10+
match val {
11+
99 => Ok(OutBAction::Log),
12+
101 => Ok(OutBAction::CallFunction),
13+
102 => Ok(OutBAction::Abort),
14+
_ => Err(anyhow::anyhow!("Invalid OutBAction value: {}", val)),
15+
}
16+
}
17+
}

src/hyperlight_guest/src/entrypoint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ use core::ffi::{c_char, c_void, CStr};
1919
use core::ptr::copy_nonoverlapping;
2020

2121
use hyperlight_common::mem::{HyperlightPEB, RunMode};
22+
use hyperlight_common::outb::OutBAction;
2223
use log::LevelFilter;
2324
use spin::Once;
2425

2526
use crate::gdt::load_gdt;
2627
use crate::guest_function_call::dispatch_function;
2728
use crate::guest_logger::init_logger;
28-
use crate::host_function_call::{outb, OutBAction};
29+
use crate::host_function_call::outb;
2930
use crate::idtr::load_idt;
3031
use crate::{
3132
__security_cookie, HEAP_ALLOCATOR, MIN_STACK_ADDRESS, OS_PAGE_SIZE, OUTB_PTR,

src/hyperlight_guest/src/guest_error.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use alloc::vec::Vec;
1919
use core::ffi::{c_char, CStr};
2020

2121
use hyperlight_common::flatbuffer_wrappers::guest_error::{ErrorCode, GuestError};
22+
use hyperlight_common::outb::OutBAction;
2223

2324
use crate::entrypoint::halt;
24-
use crate::host_function_call::{outb, OutBAction};
25+
use crate::host_function_call::outb;
2526
use crate::shared_output_data::push_shared_output_data;
2627

2728
pub(crate) fn write_error(error_code: ErrorCode, message: Option<&str>) {

src/hyperlight_guest/src/host_function_call.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,13 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
2626
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
2727
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
2828
use hyperlight_common::mem::RunMode;
29+
use hyperlight_common::outb::OutBAction;
2930

3031
use crate::error::{HyperlightGuestError, Result};
3132
use crate::shared_input_data::try_pop_shared_input_data_into;
3233
use crate::shared_output_data::push_shared_output_data;
3334
use crate::{OUTB_PTR, OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE};
3435

35-
pub enum OutBAction {
36-
Log = 99,
37-
CallFunction = 101,
38-
Abort = 102,
39-
}
40-
4136
/// Get a return value from a host function call.
4237
/// This usually requires a host function to be called first using `call_host_function`.
4338
pub fn get_host_return_value<T: TryFrom<ReturnValue>>() -> Result<T> {

src/hyperlight_guest/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ use buddy_system_allocator::LockedHeap;
2424
use guest_function_register::GuestFunctionRegister;
2525
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
2626
use hyperlight_common::mem::{HyperlightPEB, RunMode};
27+
use hyperlight_common::outb::OutBAction;
2728

28-
use crate::host_function_call::{outb, OutBAction};
29+
use crate::host_function_call::outb;
2930
extern crate alloc;
3031

3132
// Modules

src/hyperlight_guest/src/logging.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use alloc::vec::Vec;
1919

2020
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
2121
use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel;
22+
use hyperlight_common::outb::OutBAction;
2223

23-
use crate::host_function_call::{outb, OutBAction};
24+
use crate::host_function_call::outb;
2425
use crate::shared_output_data::push_shared_output_data;
2526

2627
fn write_log_data(

src/hyperlight_host/src/sandbox/outb.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::sync::{Arc, Mutex};
1919
use hyperlight_common::flatbuffer_wrappers::function_types::ParameterValue;
2020
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
2121
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
22+
use hyperlight_common::outb::OutBAction;
2223
use log::{Level, Record};
2324
use tracing::{instrument, Span};
2425
use tracing_log::format_trace;
@@ -30,25 +31,6 @@ use crate::mem::mgr::SandboxMemoryManager;
3031
use crate::mem::shared_mem::HostSharedMemory;
3132
use crate::{new_error, HyperlightError, Result};
3233

33-
pub(super) enum OutBAction {
34-
Log,
35-
CallFunction,
36-
Abort,
37-
}
38-
39-
impl TryFrom<u16> for OutBAction {
40-
type Error = HyperlightError;
41-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
42-
fn try_from(val: u16) -> Result<Self> {
43-
match val {
44-
99 => Ok(OutBAction::Log),
45-
101 => Ok(OutBAction::CallFunction),
46-
102 => Ok(OutBAction::Abort),
47-
_ => Err(new_error!("Invalid OutB value: {}", val)),
48-
}
49-
}
50-
}
51-
5234
#[instrument(err(Debug), skip_all, parent = Span::current(), level="Trace")]
5335
pub(super) fn outb_log(mgr: &mut SandboxMemoryManager<HostSharedMemory>) -> Result<()> {
5436
// This code will create either a logging record or a tracing record for the GuestLogData depending on if the host has set up a tracing subscriber.

0 commit comments

Comments
 (0)