hyperlight_guest/prim_alloc.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025 The Hyperlight Authors.
3
4#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/prim_alloc.rs")]
5#[cfg_attr(target_arch = "aarch64", path = "arch/aarch64/prim_alloc.rs")]
6mod arch;
7
8/// Allocate n contiguous physical pages and return the physical
9/// addresses of the pages in question.
10/// # Safety
11/// Since this reads and writes specific allocator state addresses, it
12/// is only safe when the allocator has been set up properly. It may
13/// become less safe in the future.
14///
15/// # Panics
16/// This function will panic if memory allocation fails
17///
18/// This is defined in an arch-specific module because it reads and
19/// writes the actual allocator state with inline assembly in order to
20/// access it atomically according to the architecture memory model
21/// rather than the Rust memory model: the stronger constraints of the
22/// latter cannot be perfectly satisfied due to the lack of per-byte
23/// atomic memcpy in the host.
24pub use arch::alloc_phys_pages;