Skip to content

Commit 85667fb

Browse files
uefi: Deprecate allocator::{init,exit_boot_services}
These no longer do anything.
1 parent 5789318 commit 85667fb

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

uefi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ how to integrate the `uefi` crate into them.
1212
take a `BootServices` argument. The global system table is used instead.
1313
- **Breaking:** `GraphicsOutput::modes` no longer takes a `BootServices`
1414
argument. The global system table is used instead.
15+
- `allocator::init` and `allocator::exit_boot_services` have been
16+
deprecated. These functions are now no-ops. The allocator now internally uses
17+
the global system table.
1518

1619

1720
# uefi - 0.31.0 (2024-08-21)

uefi/src/allocator.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
//! If the `global_allocator` feature is enabled, the [`Allocator`] will be used
44
//! as the global Rust allocator.
55
//!
6-
//! # Usage
7-
//!
8-
//! Call the `init` function with a reference to the boot services table.
9-
//! Failure to do so before calling a memory allocating function will panic.
10-
//!
11-
//! Call the `exit_boot_services` function before exiting UEFI boot services.
12-
//! Failure to do so will turn subsequent allocation into undefined behaviour.
6+
//! This allocator can only be used while boot services are active. If boot
7+
//! services are not active, `alloc` will return a null pointer, and `dealloc`
8+
//! will panic.
139
1410
use core::alloc::{GlobalAlloc, Layout};
1511
use core::ptr::{self, NonNull};
@@ -20,18 +16,13 @@ use crate::mem::memory_map::MemoryType;
2016
use crate::proto::loaded_image::LoadedImage;
2117
use crate::table::{Boot, SystemTable};
2218

23-
/// Initializes the allocator.
24-
///
25-
/// # Safety
26-
///
27-
/// This function is unsafe because you _must_ make sure that exit_boot_services
28-
/// will be called when UEFI boot services will be exited.
29-
#[allow(unused_unsafe)]
19+
/// Deprecated; this function is now a no-op.
20+
#[deprecated = "this function is now a no-op"]
21+
#[allow(unused_unsafe, clippy::missing_safety_doc)]
3022
pub unsafe fn init(_: &mut SystemTable<Boot>) {}
3123

32-
/// Notify the allocator library that boot services are not safe to call anymore
33-
///
34-
/// You must arrange for this function to be called on exit from UEFI boot services
24+
/// Deprecated; this function is now a no-op.
25+
#[deprecated = "this function is now a no-op"]
3526
#[allow(clippy::missing_const_for_fn)]
3627
pub fn exit_boot_services() {}
3728

uefi/src/helpers/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,25 @@ pub fn system_table() -> SystemTable<Boot> {
4848
/// Initialize all helpers defined in [`uefi::helpers`] whose Cargo features
4949
/// are activated.
5050
///
51-
/// This must be called as early as possible, before trying to use logging or
52-
/// memory allocation capabilities.
51+
/// This must be called as early as possible, before trying to use logging.
5352
///
5453
/// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
5554
/// epoch. Limited functionality might work after exiting them, such as logging
5655
/// to the debugcon device.
5756
#[allow(clippy::missing_const_for_fn)]
5857
pub fn init() -> Result<()> {
59-
// Setup logging and memory allocation
60-
58+
// Set up logging.
6159
#[cfg(feature = "logger")]
6260
unsafe {
6361
let mut st = table::system_table_boot().expect("boot services are not active");
6462
logger::init(&mut st);
6563
}
6664

67-
#[cfg(feature = "global_allocator")]
68-
unsafe {
69-
let mut st = table::system_table_boot().expect("boot services are not active");
70-
crate::allocator::init(&mut st);
71-
}
72-
7365
Ok(())
7466
}
7567

7668
#[allow(clippy::missing_const_for_fn)]
7769
pub(crate) fn exit() {
7870
#[cfg(feature = "logger")]
7971
logger::disable();
80-
81-
#[cfg(feature = "global_allocator")]
82-
crate::allocator::exit_boot_services();
8372
}

0 commit comments

Comments
 (0)