hyperlight_common/mem/
mod.rs

1/*
2Copyright 2024 The Hyperlight Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#![allow(non_snake_case)]
18
19pub const PAGE_SHIFT: u64 = 12;
20pub const PAGE_SIZE: u64 = 1 << 12;
21pub const PAGE_SIZE_USIZE: usize = 1 << 12;
22
23use core::ffi::{c_char, c_void};
24
25#[repr(C)]
26pub struct HostFunctionDefinitions {
27    pub fbHostFunctionDetailsSize: u64,
28    pub fbHostFunctionDetails: *mut c_void,
29}
30
31#[repr(C)]
32pub struct HostException {
33    pub hostExceptionSize: u64,
34}
35
36#[repr(C)]
37pub struct GuestErrorData {
38    pub guestErrorSize: u64,
39    pub guestErrorBuffer: *mut c_void,
40}
41
42#[repr(u64)]
43#[derive(Debug, Copy, Clone, PartialEq, Eq)]
44pub enum RunMode {
45    None = 0,
46    Hypervisor = 1,
47    InProcessWindows = 2,
48    InProcessLinux = 3,
49    Invalid = 4,
50}
51
52#[repr(C)]
53pub struct InputData {
54    pub inputDataSize: u64,
55    pub inputDataBuffer: *mut c_void,
56}
57
58#[repr(C)]
59pub struct OutputData {
60    pub outputDataSize: u64,
61    pub outputDataBuffer: *mut c_void,
62}
63
64#[repr(C)]
65pub struct GuestHeapData {
66    pub guestHeapSize: u64,
67    pub guestHeapBuffer: *mut c_void,
68}
69
70#[repr(C)]
71pub struct GuestStackData {
72    /// This is the top of the user stack
73    pub minUserStackAddress: u64,
74    /// This is the user stack pointer
75    pub userStackAddress: u64,
76    /// This is the stack pointer for the kernel mode stack
77    pub kernelStackAddress: u64,
78    /// This is the initial stack pointer when init is called its used before the TSS is set up
79    pub bootStackAddress: u64,
80}
81
82#[repr(C)]
83pub struct GuestPanicContextData {
84    pub guestPanicContextDataSize: u64,
85    pub guestPanicContextDataBuffer: *mut c_void,
86}
87
88#[repr(C)]
89pub struct HyperlightPEB {
90    pub security_cookie_seed: u64,
91    pub guest_function_dispatch_ptr: u64,
92    pub hostFunctionDefinitions: HostFunctionDefinitions,
93    pub hostException: HostException,
94    pub guestErrorData: GuestErrorData,
95    pub pCode: *mut c_char,
96    pub pOutb: *mut c_void,
97    pub pOutbContext: *mut c_void,
98    pub runMode: RunMode,
99    pub inputdata: InputData,
100    pub outputdata: OutputData,
101    pub guestPanicContextData: GuestPanicContextData,
102    pub guestheapData: GuestHeapData,
103    pub gueststackData: GuestStackData,
104}