hyperlight_common/layout.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
17#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/layout.rs")]
18#[cfg_attr(target_arch = "x86", path = "arch/i686/layout.rs")]
19mod arch;
20
21pub use arch::{MAX_GPA, MAX_GVA, SNAPSHOT_PT_GVA_MAX, SNAPSHOT_PT_GVA_MIN};
22
23// offsets down from the top of scratch memory for various things
24pub const SCRATCH_TOP_SIZE_OFFSET: u64 = 0x08;
25pub const SCRATCH_TOP_ALLOCATOR_OFFSET: u64 = 0x10;
26pub const SCRATCH_TOP_SNAPSHOT_PT_GPA_BASE_OFFSET: u64 = 0x18;
27pub const SCRATCH_TOP_EXN_STACK_OFFSET: u64 = 0x20;
28
29pub fn scratch_base_gpa(size: usize) -> u64 {
30 (MAX_GPA - size + 1) as u64
31}
32pub fn scratch_base_gva(size: usize) -> u64 {
33 (MAX_GVA - size + 1) as u64
34}
35
36/// Compute the minimum scratch region size needed for a sandbox.
37pub use arch::min_scratch_size;