1#![no_std]
18use alloc::string::ToString;
20use core::hint::unreachable_unchecked;
21use core::ptr::copy_nonoverlapping;
22
23use buddy_system_allocator::LockedHeap;
24use guest_function_register::GuestFunctionRegister;
25use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
26use hyperlight_common::mem::{HyperlightPEB, RunMode};
27
28use crate::host_function_call::{outb, OutBAction};
29extern crate alloc;
30
31pub mod entrypoint;
33pub mod shared_input_data;
34pub mod shared_output_data;
35
36pub mod guest_error;
37pub mod guest_function_call;
38pub mod guest_function_definition;
39pub mod guest_function_register;
40
41pub mod host_error;
42pub mod host_function_call;
43pub mod host_functions;
44
45pub(crate) mod guest_logger;
46pub mod memory;
47pub mod print;
48pub(crate) mod security_check;
49pub mod setjmp;
50
51pub mod chkstk;
52pub mod error;
53pub mod gdt;
54pub mod idt;
55pub mod idtr;
56pub mod interrupt_entry;
57pub mod interrupt_handlers;
58pub mod logging;
59
60#[no_mangle]
63pub(crate) extern "C" fn __CxxFrameHandler3() {}
64#[no_mangle]
66pub(crate) static _fltused: i32 = 0;
67
68#[cfg_attr(not(test), panic_handler)]
73#[allow(clippy::panic)]
74#[allow(dead_code)]
76fn panic(info: &core::panic::PanicInfo) -> ! {
77 unsafe {
78 let peb_ptr = P_PEB.unwrap();
79 copy_nonoverlapping(
80 info.to_string().as_ptr(),
81 (*peb_ptr).guestPanicContextData.guestPanicContextDataBuffer as *mut u8,
82 (*peb_ptr).guestPanicContextData.guestPanicContextDataSize as usize,
83 );
84 }
85 outb(OutBAction::Abort as u16, ErrorCode::UnknownError as u8);
86 unsafe { unreachable_unchecked() }
87}
88
89#[global_allocator]
91pub(crate) static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::<32>::empty();
92
93#[no_mangle]
95pub(crate) static mut __security_cookie: u64 = 0;
96
97pub(crate) static mut P_PEB: Option<*mut HyperlightPEB> = None;
98pub static mut MIN_STACK_ADDRESS: u64 = 0;
99
100pub static mut OS_PAGE_SIZE: u32 = 0;
101pub(crate) static mut OUTB_PTR: Option<extern "win64" fn(u16, u8)> = None;
102pub(crate) static mut OUTB_PTR_WITH_CONTEXT: Option<
103 extern "win64" fn(*mut core::ffi::c_void, u16, u8),
104> = None;
105pub static mut RUNNING_MODE: RunMode = RunMode::None;
106
107pub(crate) static mut REGISTERED_GUEST_FUNCTIONS: GuestFunctionRegister =
108 GuestFunctionRegister::new();