pub trait InputOutputVirtualAddress
{
#[inline(always)]
fn io_virtual_address(self) -> Result<rte_iova_t, ()>;
#[inline(always)]
fn io_virtual_address_mode() -> rte_iova_mode
{
unsafe { rte_eal_iova_mode() }
}
#[inline(always)]
fn lock_page_to_prevent_swapping(self) -> bool;
#[inline(always)]
fn is_using_physical_addresses() -> bool
{
(unsafe { rte_eal_using_phys_addrs() }) != 0
}
}
impl InputOutputVirtualAddress for *const c_void
{
#[inline(always)]
fn io_virtual_address(self) -> Result<rte_iova_t, ()>
{
const RTE_BAD_IOVA: u64 = 0xFFFF_FFFF_FFFF_FFFF;
let result = unsafe { rte_mem_virt2iova(self) };
if result == RTE_BAD_IOVA
{
Err(())
}
else
{
Ok(result)
}
}
#[inline(always)]
fn lock_page_to_prevent_swapping(self) -> bool
{
match unsafe { rte_mem_lock_page(self) }
{
0 => true,
negative if negative < 0 => false,
illegal @ _ => panic!("Unexpected result '{}' from rte_mem_lock_page()", illegal),
}
}
}
impl InputOutputVirtualAddress for *mut c_void
{
#[inline(always)]
fn io_virtual_address(self) -> Result<rte_iova_t, ()>
{
(self as *const c_void).io_virtual_address()
}
#[inline(always)]
fn lock_page_to_prevent_swapping(self) -> bool
{
(self as *const c_void).lock_page_to_prevent_swapping()
}
}