Skip to main content

hyperlight_guest/
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::{MAIN_STACK_LIMIT_GVA, MAIN_STACK_TOP_GVA};
22pub fn scratch_size_gva() -> *mut u64 {
23    use hyperlight_common::layout::{MAX_GVA, SCRATCH_TOP_SIZE_OFFSET};
24    (MAX_GVA as u64 - SCRATCH_TOP_SIZE_OFFSET + 1) as *mut u64
25}
26pub fn allocator_gva() -> *mut u64 {
27    use hyperlight_common::layout::{MAX_GVA, SCRATCH_TOP_ALLOCATOR_OFFSET};
28    (MAX_GVA as u64 - SCRATCH_TOP_ALLOCATOR_OFFSET + 1) as *mut u64
29}
30pub fn snapshot_pt_gpa_base_gva() -> *mut u64 {
31    use hyperlight_common::layout::{MAX_GVA, SCRATCH_TOP_SNAPSHOT_PT_GPA_BASE_OFFSET};
32    (MAX_GVA as u64 - SCRATCH_TOP_SNAPSHOT_PT_GPA_BASE_OFFSET + 1) as *mut u64
33}
34pub use arch::{scratch_base_gpa, scratch_base_gva};
35
36/// Returns a pointer to the guest counter u64 in scratch memory.
37#[cfg(feature = "nanvix-unstable")]
38pub fn guest_counter_gva() -> *const u64 {
39    use hyperlight_common::layout::{MAX_GVA, SCRATCH_TOP_GUEST_COUNTER_OFFSET};
40    (MAX_GVA as u64 - SCRATCH_TOP_GUEST_COUNTER_OFFSET + 1) as *const u64
41}