Skip to main content

hyperlight_guest/
prim_alloc.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/prim_alloc.rs")]
18#[cfg_attr(target_arch = "x86", path = "arch/i686/prim_alloc.rs")]
19mod arch;
20
21/// Allocate n contiguous physical pages and return the physical
22/// addresses of the pages in question.
23/// # Safety
24/// Since this reads and writes specific allocator state addresses, it
25/// is only safe when the allocator has been set up properly. It may
26/// become less safe in the future.
27///
28/// # Panics
29/// This function will panic if memory allocation fails
30///
31/// This is defined in an arch-specific module because it reads and
32/// writes the actual allocator state with inline assembly in order to
33/// access it atomically according to the architecture memory model
34/// rather than the Rust memory model: the stronger constraints of the
35/// latter cannot be perfectly satisfied due to the lack of per-byte
36/// atomic memcpy in the host.
37pub use arch::alloc_phys_pages;