Skip to content

Commit 6d93e1f

Browse files
relicensing: Rewrite PR "allocator: Use appropriate memory types"
The allocator code has already changed a fair amount since that PR landed, so only docstrings needed to be rewritten. This covers these commits: 9dbdfe9 e6803d7
1 parent a228731 commit 6d93e1f

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

uefi/src/allocator.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
//! services are not active, `alloc` will return a null pointer, and `dealloc`
88
//! will panic.
99
10-
use core::alloc::{GlobalAlloc, Layout};
11-
use core::ptr::{self, NonNull};
12-
use core::sync::atomic::{AtomicU32, Ordering};
13-
1410
use crate::boot;
1511
use crate::mem::memory_map::MemoryType;
1612
use crate::proto::loaded_image::LoadedImage;
13+
use core::alloc::{GlobalAlloc, Layout};
14+
use core::ptr::{self, NonNull};
15+
use core::sync::atomic::{AtomicU32, Ordering};
1716

1817
/// Get the memory type to use for allocation.
1918
///
@@ -48,9 +47,11 @@ fn get_memory_type() -> MemoryType {
4847
pub struct Allocator;
4948

5049
unsafe impl GlobalAlloc for Allocator {
51-
/// Allocate memory using [`boot::allocate_pool`]. The allocation is
52-
/// of type [`MemoryType::LOADER_DATA`] for UEFI applications, [`MemoryType::BOOT_SERVICES_DATA`]
53-
/// for UEFI boot drivers and [`MemoryType::RUNTIME_SERVICES_DATA`] for UEFI runtime drivers.
50+
/// Allocate memory using [`boot::allocate_pool`]. The allocation's [memory
51+
/// type] matches the current image's [data type].
52+
///
53+
/// [memory type]: MemoryType
54+
/// [data type]: LoadedImage::data_type
5455
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
5556
if !boot::are_boot_services_active() {
5657
return ptr::null_mut();

uefi/src/proto/loaded_image.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,13 @@ impl LoadedImage {
180180
(self.0.image_base, self.0.image_size)
181181
}
182182

183-
/// Get the memory type of the image's code sections.
184-
///
185-
/// Normally the returned value is one of:
186-
/// - `MemoryType::LOADER_CODE` for UEFI applications
187-
/// - `MemoryType::BOOT_SERVICES_CODE` for UEFI boot drivers
188-
/// - `MemoryType::RUNTIME_SERVICES_CODE` for UEFI runtime drivers
183+
/// Returns the memory type that the image's code sections were loaded as.
189184
#[must_use]
190185
pub const fn code_type(&self) -> MemoryType {
191186
self.0.image_code_type
192187
}
193188

194-
/// Get the memory type of the image's data sections.
195-
///
196-
/// Normally the returned value is one of:
197-
/// - `MemoryType::LOADER_DATA` for UEFI applications
198-
/// - `MemoryType::BOOT_SERVICES_DATA` for UEFI boot drivers
199-
/// - `MemoryType::RUNTIME_SERVICES_DATA` for UEFI runtime drivers
189+
/// Returns the memory type that the image's data sections were loaded as.
200190
#[must_use]
201191
pub const fn data_type(&self) -> MemoryType {
202192
self.0.image_data_type

0 commit comments

Comments
 (0)