x86_64/structures/paging/frame_alloc.rs
1//! Traits for abstracting away frame allocation and deallocation.
2
3use crate::structures::paging::{PageSize, PhysFrame};
4
5/// A trait for types that can allocate a frame of memory.
6///
7/// # Safety
8///
9/// The implementer of this trait must guarantee that the `allocate_frame`
10/// method returns only unique unused frames. Otherwise, undefined behavior
11/// may result from two callers modifying or deallocating the same frame.
12pub unsafe trait FrameAllocator<S: PageSize> {
13 /// Allocate a frame of the appropriate size and return it if possible.
14 fn allocate_frame(&mut self) -> Option<PhysFrame<S>>;
15}
16
17/// A trait for types that can deallocate a frame of memory.
18pub trait FrameDeallocator<S: PageSize> {
19 /// Deallocate the given unused frame.
20 ///
21 /// ## Safety
22 ///
23 /// The caller must ensure that the passed frame is unused.
24 unsafe fn deallocate_frame(&mut self, frame: PhysFrame<S>);
25}