Skip to content

Rename global_allocator module and change scope of global_allocator feature #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## uefi - [Unreleased]

### Changed

- The `global_allocator` module has been renamed to `allocator`, and is now
available regardless of whether the `global_allocator` feature is enabled. The
`global_allocator` feature now only controls whether `allocator::Allocator` is
set as Rust's global allocator.

## uefi-macros - [Unreleased]

## uefi-services - [Unreleased]
Expand Down
4 changes: 2 additions & 2 deletions uefi-services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result {
init_logger(st);

let boot_services = st.boot_services();
uefi::global_allocator::init(boot_services);
uefi::allocator::init(boot_services);

// Schedule these tools to be disabled on exit from UEFI boot services
boot_services
Expand Down Expand Up @@ -191,7 +191,7 @@ unsafe extern "efiapi" fn exit_boot_services(_e: Event, _ctx: Option<NonNull<c_v
logger.disable();
}

uefi::global_allocator::exit_boot_services();
uefi::allocator::exit_boot_services();
}

#[cfg(feature = "panic_handler")]
Expand Down
5 changes: 3 additions & 2 deletions uefi/src/global_allocator.rs → uefi/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module implements Rust's global allocator interface using UEFI's memory allocation functions.
//!
//! Enabling the `alloc` optional feature in your app will allow you to use Rust's higher-level data structures,
//! like boxes, vectors, hash maps, linked lists and so on.
//! If the `global_allocator` feature is enabled, the [`Allocator`] will be used
//! as the global Rust allocator.
//!
//! # Usage
//!
Expand Down Expand Up @@ -112,5 +112,6 @@ unsafe impl GlobalAlloc for Allocator {
}
}

#[cfg(feature = "global_allocator")]
#[global_allocator]
static ALLOCATOR: Allocator = Allocator;
7 changes: 3 additions & 4 deletions uefi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
//! `Vec` rather than filling a statically-sized array. This requires
//! a global allocator; you can use the `global_allocator` feature or
//! provide your own.
//! - `global_allocator`: Implement a [global allocator] using UEFI
//! functions. This is a simple allocator that relies on the UEFI pool
//! - `global_allocator`: Set [`allocator::Allocator`] as the global Rust
//! allocator. This is a simple allocator that relies on the UEFI pool
//! allocator. You can choose to provide your own allocator instead of
//! using this feature, or no allocator at all if you don't need to
//! dynamically allocate any memory.
Expand Down Expand Up @@ -108,8 +108,7 @@ pub mod proto;

pub mod prelude;

#[cfg(feature = "global_allocator")]
pub mod global_allocator;
pub mod allocator;

#[cfg(feature = "logger")]
pub mod logger;
Expand Down
4 changes: 2 additions & 2 deletions uefi/src/table/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl SystemTable<Boot> {
/// Once boot services are exited, the logger and allocator provided by
/// this crate can no longer be used. The logger should be disabled using
/// the [`Logger::disable`] method, and the allocator should be disabled by
/// calling [`global_allocator::exit_boot_services`]. Note that if the logger and
/// calling [`allocator::exit_boot_services`]. Note that if the logger and
/// allocator were initialized with [`uefi_services::init`], they will be
/// disabled automatically when `exit_boot_services` is called.
///
Expand All @@ -208,7 +208,7 @@ impl SystemTable<Boot> {
/// now in an undefined state. Rather than returning control to the
/// caller, the system will be reset.
///
/// [`global_allocator::exit_boot_services`]: crate::global_allocator::exit_boot_services
/// [`allocator::exit_boot_services`]: crate::allocator::exit_boot_services
/// [`Logger::disable`]: crate::logger::Logger::disable
/// [`uefi_services::init`]: https://docs.rs/uefi-services/latest/uefi_services/fn.init.html
#[must_use]
Expand Down