Skip to content

Commit 4c60e1d

Browse files
committed
Run bindgen tests
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent b5434c1 commit 4c60e1d

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

hv-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
.allowlist_var("VM.*")
1414
.allowlist_var("IRQ.*")
1515
.derive_default(true)
16-
.layout_tests(false)
16+
.generate_comments(false)
1717
.generate()
1818
.expect("Failed to generate bindings")
1919
.write_to_file(out_path.join("bindings.rs"))

hv-sys/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#![allow(non_upper_case_globals)]
22
#![allow(non_camel_case_types)]
3+
#![allow(improper_ctypes)]
4+
// Comes from unit tests, don't care much
5+
#![allow(deref_nullptr)]
6+
#![allow(unaligned_references)]
37

48
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

hv/examples/as.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Apple Silicon example.
22
// Adapted from https://github.com/zhuowei/FakeHVF/blob/main/simplevm.c
33

4-
use std::ptr;
5-
6-
use hv::arm64::{Reg, VcpuExt};
4+
#![allow(dead_code)]
75

86
static CODE: &[u8] = &[
97
// Compute ((2 + 2) - 1)
@@ -27,10 +25,14 @@ const GUEST_ADDR: usize = 0x69420000;
2725
const RESULT_OFFSET: usize = 0x100;
2826
const GUEST_RESULT_ADDR: usize = GUEST_ADDR + RESULT_OFFSET;
2927

28+
#[cfg(target_arch = "aarch64")]
29+
use hv::arm64::{Reg, VcpuExt};
30+
31+
#[cfg(target_arch = "aarch64")]
3032
fn main() -> Result<(), hv::Error> {
3133
let load_addr = unsafe {
3234
libc::mmap(
33-
ptr::null_mut(),
35+
std::ptr::null_mut(),
3436
MEM_SIZE,
3537
libc::PROT_READ | libc::PROT_WRITE,
3638
libc::MAP_ANONYMOUS | libc::MAP_PRIVATE | libc::MAP_NORESERVE,
@@ -44,11 +46,11 @@ fn main() -> Result<(), hv::Error> {
4446
}
4547

4648
unsafe {
47-
ptr::copy_nonoverlapping(CODE.as_ptr(), load_addr, CODE.len());
49+
std::ptr::copy_nonoverlapping(CODE.as_ptr(), load_addr, CODE.len());
4850
}
4951

5052
// Init VM
51-
hv::Vm::create_vm(ptr::null_mut()).expect("Failed to create VM");
53+
hv::Vm::create_vm(std::ptr::null_mut()).expect("Failed to create VM");
5254

5355
// Initialize guest memory
5456
hv::Vm::map(
@@ -62,7 +64,7 @@ fn main() -> Result<(), hv::Error> {
6264
// Create VCPU
6365
let cpu = hv::Vm::create_cpu().expect("Failed to create CPU");
6466

65-
// Register regs
67+
// Set regs
6668
cpu.set_reg(Reg::PC, GUEST_ADDR as _)
6769
.expect("Failed to set PC reg");
6870

@@ -90,3 +92,6 @@ fn main() -> Result<(), hv::Error> {
9092

9193
Ok(())
9294
}
95+
96+
#[cfg(target_arch = "x86_64")]
97+
fn main() {}

hv/examples/caps.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use hv::x86::{Capability, VmExt, VmOptions};
2-
1+
#[cfg(target_arch = "x86_64")]
32
fn main() -> Result<(), hv::Error> {
3+
use hv::x86::{Capability, VmExt, VmOptions};
4+
45
hv::Vm::create_vm(VmOptions::default())?;
56

67
println!("Max vCPUs: {}", hv::Vm::capability(Capability::VcpuMax)?);
@@ -14,3 +15,6 @@ fn main() -> Result<(), hv::Error> {
1415

1516
Ok(())
1617
}
18+
19+
#[cfg(target_arch = "aarch64")]
20+
fn main() {}

hv/src/arm64/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Apple Silicon extensions support.
22
3-
use std::ptr;
4-
53
use crate::{call, sys, Error, Vcpu};
64

75
mod regs;
86
pub use regs::*;
9-
use std::process::exit;
107

118
/// Injected interrupt type.
129
#[repr(u32)]
@@ -186,7 +183,7 @@ impl VcpuExt for Vcpu {
186183

187184
/// Returns the underlying `hv_vcpu_exit_t` structure.
188185
fn exit_info(&self) -> VcpuExit {
189-
if self.exit == ptr::null() {
186+
if self.exit.is_null() {
190187
VcpuExit::default()
191188
} else {
192189
unsafe { *self.exit }

0 commit comments

Comments
 (0)