hyperlight_common/
mem.rs

1/*
2Copyright 2025  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
17pub const PAGE_SHIFT: u64 = 12;
18pub const PAGE_SIZE: u64 = 1 << 12;
19pub const PAGE_SIZE_USIZE: usize = 1 << 12;
20
21/// A memory region in the guest address space
22#[derive(Debug, Clone, Copy)]
23#[repr(C)]
24pub struct GuestMemoryRegion {
25    /// The size of the memory region
26    pub size: u64,
27    /// The address of the memory region
28    pub ptr: u64,
29}
30
31/// A memory region in the guest address space that is used for the stack
32#[derive(Debug, Clone, Copy)]
33#[repr(C)]
34pub struct GuestStack {
35    /// The top of the user stack
36    pub min_user_stack_address: u64,
37    /// The user stack pointer
38    pub user_stack_address: u64,
39}
40
41#[derive(Debug, Clone, Copy)]
42#[repr(C)]
43pub struct HyperlightPEB {
44    pub security_cookie_seed: u64,
45    pub guest_function_dispatch_ptr: u64,
46    pub code_ptr: u64,
47    pub input_stack: GuestMemoryRegion,
48    pub output_stack: GuestMemoryRegion,
49    pub init_data: GuestMemoryRegion,
50    pub guest_heap: GuestMemoryRegion,
51    pub guest_stack: GuestStack,
52    pub host_function_definitions: GuestMemoryRegion,
53}