AxVisor HyperCall Definitions
English | 中文
axhvc provides AxVisor hypercall definitions for guest-hypervisor communication. It is a lightweight #![no_std] crate intended for bare-metal guests, hypervisors, and low-level virtualization components across x86_64, RISC-V, and AArch64 platforms.
This library exports three core public types:
HyperCallCode- Enumerates all supported AxVisor hypercall operationsInvalidHyperCallCode- Represents conversion errors for invalid numeric hypercall valuesHyperCallResult- Alias ofAxResult<usize>used by hypercall handlers
HyperCallCode supports TryFrom<u32> conversion and includes variants for hypervisor control and IVC channel management.
- Rust nightly toolchain
- Rust components: rust-src, clippy, rustfmt
# Install rustup (if not installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install nightly toolchain and components
rustup install nightly
rustup component add rust-src clippy rustfmt --toolchain nightly# 1. Enter the repository
cd axhvc
# 2. Code check
./scripts/check.sh
# 3. Run tests
./scripts/test.shAdd to your Cargo.toml:
[dependencies]
axhvc = "0.2.0"use axerrno::ax_err;
use axhvc::{HyperCallCode, HyperCallResult, InvalidHyperCallCode};
fn handle_hypercall(code: u32) -> Result<HyperCallResult, InvalidHyperCallCode> {
let code = HyperCallCode::try_from(code)?;
let result = match code {
HyperCallCode::HypervisorDisable => Ok(0),
HyperCallCode::HyperVisorPrepareDisable => Ok(0),
HyperCallCode::HIVCPublishChannel => Ok(0x1000),
_ => ax_err!(Unsupported),
};
Ok(result)
}
fn main() {
let code = HyperCallCode::try_from(3u32).unwrap();
assert_eq!(code as u32, 3);
let result = handle_hypercall(code as u32).unwrap().unwrap();
assert_eq!(result, 0x1000);
let invalid = HyperCallCode::try_from(7u32);
assert!(invalid.is_err());
}Generate and view API documentation:
cargo doc --no-deps --openOnline documentation: docs.rs/axhvc
- Fork the repository and create a branch
- Run local check:
./scripts/check.sh - Run local tests:
./scripts/test.sh - Submit PR and pass CI checks
Licensed under the Apache License, Version 2.0. See LICENSE for details.