Skip to content

Commit 8ff4b46

Browse files
committed
Workaround bindgen
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 3b0660e commit 8ff4b46

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

hv/src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ macro_rules! call {
2020
($f:expr) => {{
2121
let code = unsafe { $f };
2222
match code {
23-
::hv_sys::HV_SUCCESS => Ok(()),
23+
0 => Ok(()),
2424
_ => Err(Error::from(code)),
2525
}
2626
}};
@@ -58,13 +58,17 @@ impl fmt::Display for Error {
5858

5959
impl From<sys::hv_return_t> for Error {
6060
fn from(value: sys::hv_return_t) -> Self {
61-
match value {
62-
sys::HV_ERROR => Error::Unsuccessful,
63-
sys::HV_BUSY => Error::Busy,
64-
sys::HV_BAD_ARGUMENT => Error::BadArgument,
65-
sys::HV_NO_RESOURCES => Error::NoResources,
66-
sys::HV_NO_DEVICE => Error::NoDevice,
67-
sys::HV_UNSUPPORTED => Error::Unsupported,
61+
// Looks like bindgen gets confused sometimes and produces different code for these
62+
// constants (`sys::HV_ERROR` vs `hv_return_t_HV_ERROR`) on different machines making things
63+
// to fail. It's probably easier to just hardcode them.
64+
let v = value as i64;
65+
match v {
66+
0xfae94001 => Error::Unsuccessful,
67+
0xfae94002 => Error::Busy,
68+
0xfae94003 => Error::BadArgument,
69+
0xfae94005 => Error::NoResources,
70+
0xfae94006 => Error::NoDevice,
71+
0xfae9400f => Error::Unsupported,
6872
_ => Error::Unknown(value),
6973
}
7074
}

hv/src/x86/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub const VM_SPACE_DEFAULT: Space = sys::HV_VM_SPACE_DEFAULT;
2222
#[repr(u32)]
2323
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2424
pub enum Capability {
25-
VcpuMax = sys::HV_CAP_VCPUMAX,
26-
AddrSpaceMax = sys::HV_CAP_ADDRSPACEMAX,
25+
VcpuMax = 0,
26+
AddrSpaceMax = 1,
2727
}
2828

2929
bitflags::bitflags! {

0 commit comments

Comments
 (0)