use std::cell::RefCell;
use std::os::raw::c_char;
use std::os::raw::c_int;
use base::errno_result;
use base::Error;
use base::FromRawDescriptor;
use base::MappedRegion;
use base::Result;
use base::SafeDescriptor;
use libc::open64;
use libc::EBUSY;
use libc::O_CLOEXEC;
use libc::O_RDWR;
use super::haxm_sys::hax_tunnel;
use super::HaxmVcpu;
use super::HAX_EXIT_PAUSED;
pub(super) fn open_haxm_device(_use_ghaxm: bool) -> Result<SafeDescriptor> {
let ret = unsafe { open64("/dev/HAX\0".as_ptr() as *const c_char, O_RDWR | O_CLOEXEC) };
if ret < 0 {
return errno_result();
}
Ok(unsafe { SafeDescriptor::from_raw_descriptor(ret) })
}
pub(super) fn open_haxm_vm_device(_use_ghaxm: bool, vm_id: u32) -> Result<SafeDescriptor> {
let path = format!("/dev/hax_vm/vm{:02}\0", vm_id);
let ret = unsafe { open64(path.as_ptr() as *const c_char, O_RDWR | O_CLOEXEC) };
if ret < 0 {
return errno_result();
}
Ok(unsafe { SafeDescriptor::from_raw_descriptor(ret) })
}
pub(super) fn open_haxm_vcpu_device(
_use_ghaxm: bool,
vm_id: u32,
vcpu_id: u32,
) -> Result<SafeDescriptor> {
let path = format!("/dev/hax_vm{:02}/vcpu{:02}\0", vm_id, vcpu_id);
let ret = unsafe { open64(path.as_ptr() as *const c_char, O_RDWR | O_CLOEXEC) };
if ret < 0 {
return errno_result();
}
unsafe { SafeDescriptor::from_raw_descriptor(ret) };
}