forked from rust-osdev/uefi-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
43 lines (33 loc) · 1008 Bytes
/
mod.rs
File metadata and controls
43 lines (33 loc) · 1008 Bytes
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
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Types, functions, traits, and other helpers to work with memory in UEFI
//! libraries and applications.
use crate::boot;
use core::ptr::NonNull;
pub mod memory_map;
#[cfg(feature = "alloc")]
pub(crate) mod util;
#[cfg(feature = "alloc")]
pub(crate) use util::*;
#[cfg(feature = "alloc")]
mod aligned_buffer;
#[cfg(feature = "alloc")]
pub use aligned_buffer::{AlignedBuffer, AlignmentError};
/// Wrapper for memory allocated with UEFI's pool allocator. The memory is freed
/// on drop.
#[derive(Debug)]
pub(crate) struct PoolAllocation(NonNull<u8>);
impl PoolAllocation {
pub(crate) const fn new(ptr: NonNull<u8>) -> Self {
Self(ptr)
}
pub(crate) const fn as_ptr(&self) -> NonNull<u8> {
self.0
}
}
impl Drop for PoolAllocation {
fn drop(&mut self) {
// Ignore errors returned by `free_pool` since we can't propagate them
// from `drop`.
let _ = unsafe { boot::free_pool(self.0) };
}
}