Skip to content

Commit

Permalink
alloc: update to new allocator and bump up r-efi version to 4
Browse files Browse the repository at this point in the history
Needed since rust-lang/wg-allocators#76

Signed-off-by: Mizuho MORI <morimolymoly@gmail.com>
(drop Cargo.lock-changes from commit)
Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
  • Loading branch information
morimolymoly authored and dvdhrm committed May 5, 2022
1 parent 3bcc031 commit c9029a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -38,4 +38,4 @@ name = "hello-world"
required-features = ["examples"]

[dependencies]
r-efi = "2.2.0"
r-efi = "4.0.0"
12 changes: 6 additions & 6 deletions src/alloc.rs
Expand Up @@ -4,11 +4,11 @@
//! exports an `Allocator` type that wraps a System-Table together with a UEFI memory type and
//! forwards memory requests to the UEFI pool allocator.
//!
//! The allocator implements the `core::alloc::AllocRef` API defined by the rust standard library.
//! The allocator implements the `core::alloc::Allocator` API defined by the rust standard library.
//! Apart from the constructors, no private extensions are defined. For documentation on the
//! allocation-API, see the rust standard library.
//!
//! Note that `core::alloc::AllocRef` is marked unstable as of time of this crate-release. That
//! Note that `core::alloc::Allocator` is marked unstable as of time of this crate-release. That
//! is, future versions of this trait definition might be incompatible to the current version.
//! Make sure you use a crate-version that matches your standard-library.

Expand Down Expand Up @@ -92,7 +92,7 @@ unsafe fn unalign_block(ptr: *mut u8, align: usize) -> *mut u8 {
/// allocator. It takes a System-Table as input, as well as the memory type to use as backing, and
/// then forwards all memory allocation requests to the `AllocatePool()` UEFI system.
///
/// The `core::alloc::AllocRef` trait is implemented for this allocator. Hence, this allocator can
/// The `core::alloc::Allocator` trait is implemented for this allocator. Hence, this allocator can
/// also be used to back the global memory-allocator of `liballoc` (or `libstd`). See the `Global`
/// type for an implementation of the global allocator.
pub struct Allocator {
Expand Down Expand Up @@ -124,8 +124,8 @@ impl Allocator {
}
}

unsafe impl core::alloc::AllocRef for Allocator {
fn alloc(
unsafe impl core::alloc::Allocator for Allocator {
fn allocate(
&self,
layout: core::alloc::Layout,
) -> Result<core::ptr::NonNull<[u8]>, core::alloc::AllocError> {
Expand Down Expand Up @@ -165,7 +165,7 @@ unsafe impl core::alloc::AllocRef for Allocator {
).unwrap())
}

unsafe fn dealloc(&self, ptr: core::ptr::NonNull<u8>, layout: core::alloc::Layout) {
unsafe fn deallocate(&self, ptr: core::ptr::NonNull<u8>, layout: core::alloc::Layout) {
if layout.size() != 0 {
// The spec allows returning errors from `FreePool()`. However, it
// must serve any valid requests. Only `INVALID_PARAMETER` is
Expand Down
4 changes: 2 additions & 2 deletions src/global.rs
Expand Up @@ -131,7 +131,7 @@ unsafe impl core::alloc::GlobalAlloc for Bridge {
return core::ptr::null_mut();
}

core::alloc::AllocRef::alloc(&mut *allocator, layout)
core::alloc::Allocator::allocate(&mut *allocator, layout)
.map(|mut mem| mem.as_mut().as_mut_ptr())
.unwrap_or(core::ptr::null_mut())
}
Expand All @@ -141,7 +141,7 @@ unsafe impl core::alloc::GlobalAlloc for Bridge {

assert!(!allocator.is_null());

core::alloc::AllocRef::dealloc(
core::alloc::Allocator::deallocate(
&mut *allocator,
core::ptr::NonNull::new_unchecked(ptr),
layout,
Expand Down

0 comments on commit c9029a5

Please sign in to comment.