1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! # Bare-metal memory allocator for kernel development.
#![deny(missing_docs)]
#![no_std]
#![feature(associated_type_defaults)]
#![feature(allocator_api)]
#![feature(dropck_eyepatch)]
#![feature(try_reserve)]
#![feature(const_fn_trait_bound)]

#[cfg(test)]
#[macro_use]
extern crate std;

extern crate alloc;

mod rawlist;

pub mod buddy;
pub mod cached;
pub mod guard;
pub mod list;
pub mod vecque;
pub mod wrapper;

pub use cached::Allocator;
pub use typenum::consts;

use core::{alloc::Layout, cmp::max};

#[inline]
fn to_order(pgsize: usize, layout: &Layout) -> usize {
    debug_assert!(pgsize.is_power_of_two());
    debug_assert!(layout.align().is_power_of_two());
    let npage = (max(layout.size().next_power_of_two(), layout.align()) + pgsize - 1) / pgsize;
    npage.trailing_zeros() as usize
}