#![no_std]
#[macro_use]
extern crate log;
extern crate alloc;
use core::fmt;
use strum::{IntoStaticStr, VariantArray};
const PAGE_SIZE: usize = 0x1000;
mod page;
pub use page::GlobalPage;
#[cfg(feature = "tracking")]
pub mod tracking;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, VariantArray, IntoStaticStr)]
pub enum UsageKind {
RustHeap,
VirtMem,
PageCache,
PageTable,
Dma,
Global,
}
#[derive(Clone, Copy)]
pub struct Usages([usize; UsageKind::VARIANTS.len()]);
impl Usages {
const fn new() -> Self {
Self([0; UsageKind::VARIANTS.len()])
}
fn alloc(&mut self, kind: UsageKind, size: usize) {
self.0[kind as usize] += size;
}
fn dealloc(&mut self, kind: UsageKind, size: usize) {
self.0[kind as usize] -= size;
}
pub fn get(&self, kind: UsageKind) -> usize {
self.0[kind as usize]
}
}
impl fmt::Debug for Usages {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("UsageStats");
for &kind in UsageKind::VARIANTS {
d.field(kind.into(), &self.0[kind as usize]);
}
d.finish()
}
}
#[cfg(feature = "hv")]
mod axvisor_impl;
#[cfg(feature = "hv")]
use axvisor_impl as imp;
#[cfg(not(feature = "hv"))]
mod default_impl;
#[cfg(not(feature = "hv"))]
use default_impl as imp;
pub use imp::{GlobalAllocator, global_add_memory, global_init};
pub use imp::DefaultByteAllocator;
#[cfg(feature = "hv")]
pub use imp::AddrTranslator;
pub fn global_allocator() -> &'static GlobalAllocator {
imp::global_allocator()
}