From 268589d00b1adc69a5bc4b484e8251da84a5a50d Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Mon, 11 Jan 2021 16:54:53 -0600 Subject: [PATCH] AllocErr -> AllocError Port https://github.com/rust-lang/rust/pull/77315 --- liblumen_alloc/src/blocks/block_bit_set.rs | 16 +++++----- liblumen_alloc/src/blocks/free_block.rs | 10 +++---- liblumen_alloc/src/carriers/slab.rs | 6 ++-- liblumen_alloc/src/erts/exception/alloc.rs | 6 ++-- liblumen_alloc/src/erts/process/alloc.rs | 6 ++-- .../erts/process/alloc/process_heap_alloc.rs | 6 ++-- liblumen_alloc/src/segmented_alloc.rs | 26 ++++++++-------- liblumen_alloc/src/size_class_alloc.rs | 18 +++++------ liblumen_alloc/src/stats_alloc.rs | 6 ++-- liblumen_alloc/src/std_alloc.rs | 16 +++++----- liblumen_core/src/alloc.rs | 2 +- liblumen_core/src/alloc/mmap.rs | 12 ++++---- liblumen_core/src/alloc/sys_alloc.rs | 8 ++--- liblumen_core/src/sys/unix/alloc.rs | 26 ++++++++-------- liblumen_core/src/sys/unix/mmap.rs | 30 +++++++++---------- liblumen_core/src/sys/wasm32/unknown/alloc.rs | 20 ++++++------- liblumen_core/src/sys/wasm32/wasi/alloc.rs | 18 +++++------ liblumen_core/src/sys/windows/alloc.rs | 18 +++++------ liblumen_core/src/sys/windows/mmap.rs | 12 ++++---- 19 files changed, 131 insertions(+), 131 deletions(-) diff --git a/liblumen_alloc/src/blocks/block_bit_set.rs b/liblumen_alloc/src/blocks/block_bit_set.rs index 771ca4284..b98fb4bb0 100644 --- a/liblumen_alloc/src/blocks/block_bit_set.rs +++ b/liblumen_alloc/src/blocks/block_bit_set.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; use core::mem; use core::sync::atomic::{AtomicUsize, Ordering}; -use liblumen_core::alloc::AllocErr; +use liblumen_core::alloc::AllocError; use crate::mem::bit_size_of; @@ -15,7 +15,7 @@ pub trait BlockBitSubset: Default { /// and when you tried to allocate it, or a neighboring bit in the subset was flipped. You may /// retry, or try searching for another block, or simply fail the allocation request. It is up /// to the allocator. - fn alloc_block(&self, bit_len: usize) -> Result; + fn alloc_block(&self, bit_len: usize) -> Result; /// Return a count of the allocated blocks managed by this subset fn count_allocated(&self) -> usize; @@ -29,7 +29,7 @@ pub trait BlockBitSubset: Default { pub struct ThreadSafeBlockBitSubset(AtomicUsize); impl BlockBitSubset for ThreadSafeBlockBitSubset { - fn alloc_block(&self, bit_len: usize) -> Result { + fn alloc_block(&self, bit_len: usize) -> Result { assert!(bit_len <= bit_size_of::()); // On x86 this could use `bsf*` (Bit Scan Forward) instructions @@ -51,7 +51,7 @@ impl BlockBitSubset for ThreadSafeBlockBitSubset { } } - Err(AllocErr) + Err(AllocError) } fn count_allocated(&self) -> usize { @@ -187,11 +187,11 @@ impl BlockBitSet { /// Try to allocate block. /// /// NOTE: This operation can fail, primarily in multi-threaded scenarios - /// with atomics in play. If `Err(AllocErr)` is returned, it means that either all blocks were + /// with atomics in play. If `Err(AllocError)` is returned, it means that either all blocks were /// already allocated or a neighboring bit that was in the same subset /// represented by `S` was flipped. You may retry or simply fail the allocation request. It is /// up to the allocator. - pub fn alloc_block(&self) -> Result { + pub fn alloc_block(&self) -> Result { for subset_index in 0..self.subset_len() { let subset = unsafe { self.subset(subset_index) }; let subset_bit_len = self.subset_bit_len(subset_index); @@ -202,11 +202,11 @@ impl BlockBitSet { return Ok(set_bit); } - Err(AllocErr) => continue, + Err(AllocError) => continue, } } - Err(AllocErr) + Err(AllocError) } /// Free the block represented by the given bit index diff --git a/liblumen_alloc/src/blocks/free_block.rs b/liblumen_alloc/src/blocks/free_block.rs index 05a2a372c..5b32c8d53 100644 --- a/liblumen_alloc/src/blocks/free_block.rs +++ b/liblumen_alloc/src/blocks/free_block.rs @@ -9,7 +9,7 @@ use intrusive_collections::container_of; use intrusive_collections::RBTreeLink; use liblumen_core::alloc::utils as alloc_utils; -use liblumen_core::alloc::{AllocErr, Layout}; +use liblumen_core::alloc::{AllocError, Layout}; use crate::sorted::{SortKey, SortOrder, Sortable}; @@ -169,14 +169,14 @@ impl FreeBlock { /// NOTE: If the allocator changes such that blocks can be accessed by more /// than one thread, the `Block` internals will need to be refactored to handle /// that, it is _only_ designed to be accessed by one thread at a time. - pub fn try_alloc(&mut self, layout: &Layout) -> Result, AllocErr> { + pub fn try_alloc(&mut self, layout: &Layout) -> Result, AllocError> { // This is here as a safety against trying to use a FreeBlock twice if unlikely!(!self.header.is_free()) { debug_assert!( !self.header.is_free(), "tried to allocate a free block twice" ); - return Err(AllocErr); + return Err(AllocError); } let mut ptr = unsafe { self.header.data() as *mut u8 }; @@ -194,14 +194,14 @@ impl FreeBlock { let padding = (aligned_ptr as usize) - (ptr as usize); if self.usable_size() < size + padding { // No good - return Err(AllocErr); + return Err(AllocError); } ptr = aligned_ptr } else { // Alignment is good, check size if self.usable_size() < size { // No good - return Err(AllocErr); + return Err(AllocError); } } diff --git a/liblumen_alloc/src/carriers/slab.rs b/liblumen_alloc/src/carriers/slab.rs index 289590e0e..133ee2b33 100644 --- a/liblumen_alloc/src/carriers/slab.rs +++ b/liblumen_alloc/src/carriers/slab.rs @@ -2,7 +2,7 @@ use core::mem; use core::ptr::{self, NonNull}; use liblumen_core::alloc::size_classes::SizeClass; -use liblumen_core::alloc::AllocErr; +use liblumen_core::alloc::AllocError; use crate::blocks::{BlockBitSet, BlockBitSubset}; use crate::sorted::Link; @@ -80,7 +80,7 @@ where } /// Allocates a block within this carrier, if one is available - pub unsafe fn alloc_block(&self) -> Result, AllocErr> { + pub unsafe fn alloc_block(&self) -> Result, AllocError> { match self.block_bit_set().alloc_block() { Ok(index) => { // We were able to mark this block allocated @@ -95,7 +95,7 @@ where Ok(NonNull::new_unchecked(block)) } // No space available - Err(AllocErr) => Err(AllocErr), + Err(AllocError) => Err(AllocError), } } diff --git a/liblumen_alloc/src/erts/exception/alloc.rs b/liblumen_alloc/src/erts/exception/alloc.rs index 379442eec..f99a6bc50 100644 --- a/liblumen_alloc/src/erts/exception/alloc.rs +++ b/liblumen_alloc/src/erts/exception/alloc.rs @@ -1,5 +1,5 @@ use alloc::sync::Arc; -use core::alloc::AllocErr; +use core::alloc::AllocError; use thiserror::Error; @@ -33,9 +33,9 @@ impl PartialEq for Alloc { } } -impl From for Alloc { +impl From for Alloc { #[inline(always)] - fn from(_: AllocErr) -> Self { + fn from(_: AllocError) -> Self { Self::new() } } diff --git a/liblumen_alloc/src/erts/process/alloc.rs b/liblumen_alloc/src/erts/process/alloc.rs index 2cab835d3..ba78b54f7 100644 --- a/liblumen_alloc/src/erts/process/alloc.rs +++ b/liblumen_alloc/src/erts/process/alloc.rs @@ -18,7 +18,7 @@ pub use self::term_alloc::TermAlloc; pub use self::virtual_alloc::{VirtualAlloc, VirtualAllocator, VirtualHeap}; pub use self::virtual_binary_heap::VirtualBinaryHeap; -use core::alloc::{AllocErr, Layout}; +use core::alloc::{AllocError, Layout}; use core::ffi::c_void; use core::mem::transmute; use core::ptr; @@ -165,13 +165,13 @@ pub fn stack(num_pages: usize) -> AllocResult { /// Reallocate a process heap, in place /// /// If reallocating and trying to grow the heap, if the allocation cannot be done -/// in place, then `Err(AllocErr)` will be returned +/// in place, then `Err(AllocError)` will be returned #[inline] pub unsafe fn realloc( heap: *mut Term, size: usize, new_size: usize, -) -> Result<*mut Term, AllocErr> { +) -> Result<*mut Term, AllocError> { PROC_ALLOC.realloc_in_place(heap, size, new_size) } diff --git a/liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs b/liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs index ca1811cac..aef9dca38 100644 --- a/liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs +++ b/liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs @@ -105,7 +105,7 @@ impl ProcessHeapAlloc { heap: *mut Term, size: usize, new_size: usize, - ) -> Result<*mut Term, AllocErr> { + ) -> Result<*mut Term, AllocError> { // Nothing to do if the size didn't change if size == new_size { return Ok(heap); @@ -121,7 +121,7 @@ impl ProcessHeapAlloc { if new_size < size { return Ok(heap); } - return Err(AllocErr); + return Err(AllocError); } let layout = self.heap_layout(size); @@ -149,7 +149,7 @@ impl ProcessHeapAlloc { } } - Err(AllocErr) + Err(AllocError) } /// Deallocate a process heap, releasing the memory back to the operating system diff --git a/liblumen_alloc/src/segmented_alloc.rs b/liblumen_alloc/src/segmented_alloc.rs index 9758577be..697fc6e95 100644 --- a/liblumen_alloc/src/segmented_alloc.rs +++ b/liblumen_alloc/src/segmented_alloc.rs @@ -72,7 +72,7 @@ impl SegmentedAlloc { /// allocator, or it will not be used, and will not be freed unsafe fn create_carrier( size_class: SizeClass, - ) -> Result<*mut SlabCarrier, AllocErr> { + ) -> Result<*mut SlabCarrier, AllocError> { let size = SUPERALIGNED_CARRIER_SIZE; assert!(size_class.to_bytes() < size); let carrier_layout = Layout::from_size_align_unchecked(size, size); @@ -87,7 +87,7 @@ impl SegmentedAlloc { unsafe impl AllocRef for SegmentedAlloc { #[inline] - fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { if layout.size() >= self.sbc_threshold { return unsafe { self.alloc_large(layout, init) }; } @@ -102,7 +102,7 @@ unsafe impl AllocRef for SegmentedAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { if layout.size() >= self.sbc_threshold { // This was a single-block carrier // @@ -122,7 +122,7 @@ unsafe impl AllocRef for SegmentedAlloc { layout: Layout, new_size: usize, placement: ReallocPlacement, - ) -> Result { + ) -> Result { if layout.size() >= self.sbc_threshold { // This was a single-block carrier // @@ -152,7 +152,7 @@ impl SegmentedAlloc { &mut self, layout: Layout, init: AllocInit, - ) -> Result { + ) -> Result { // Ensure allocated region has enough space for carrier header and aligned block let data_layout = layout.clone(); let data_layout_size = data_layout.size(); @@ -198,9 +198,9 @@ impl SegmentedAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } // Allocate new carrier @@ -263,7 +263,7 @@ impl SegmentedAlloc { /// allocator, or it will not be used, and will not be freed unsafe fn create_slab_carrier( size_class: SizeClass, - ) -> Result<*mut SlabCarrier, AllocErr> { + ) -> Result<*mut SlabCarrier, AllocError> { let size = SUPERALIGNED_CARRIER_SIZE; assert!(size_class.to_bytes() < size); let carrier_layout = Layout::from_size_align_unchecked(size, size); @@ -280,11 +280,11 @@ impl SegmentedAlloc { &mut self, layout: Layout, init: AllocInit, - ) -> Result { + ) -> Result { // Ensure allocated region has enough space for carrier header and aligned block let size = layout.size(); if unlikely(size > Self::MAX_SIZE_CLASS.to_bytes()) { - return Err(AllocErr); + return Err(AllocError); } let size_class = self.size_class_for_unchecked(size); let index = self.index_for(size_class); @@ -327,9 +327,9 @@ impl SegmentedAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { if unlikely(new_size > Self::MAX_SIZE_CLASS.to_bytes()) { - return Err(AllocErr); + return Err(AllocError); } let size = layout.size(); let size_class = self.size_class_for_unchecked(size); @@ -344,7 +344,7 @@ impl SegmentedAlloc { // Otherwise we have to allocate in the new size class, // copy to that new block, and deallocate the original block if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } let align = layout.align(); let new_layout = Layout::from_size_align_unchecked(new_size, align); diff --git a/liblumen_alloc/src/size_class_alloc.rs b/liblumen_alloc/src/size_class_alloc.rs index 669df13f9..84ac3703e 100644 --- a/liblumen_alloc/src/size_class_alloc.rs +++ b/liblumen_alloc/src/size_class_alloc.rs @@ -93,11 +93,11 @@ impl SizeClassAlloc { &self, layout: Layout, init: AllocInit, - ) -> Result { + ) -> Result { // Ensure allocated region has enough space for carrier header and aligned block let size = layout.size(); if unlikely(size > self.max_size_class.to_bytes()) { - return Err(AllocErr); + return Err(AllocError); } let (index, size_class) = binary_search_next_largest(&self.size_classes, |sc| sc.to_bytes().cmp(&size)).unwrap(); @@ -139,9 +139,9 @@ impl SizeClassAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { if unlikely(new_size > self.max_size_class.to_bytes()) { - return Err(AllocErr); + return Err(AllocError); } let size = layout.size(); let size_class = self.size_class_for_unchecked(size); @@ -156,7 +156,7 @@ impl SizeClassAlloc { // Otherwise we have to allocate in the new size class, // copy to that new block, and deallocate the original block if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } let align = layout.align(); let new_layout = Layout::from_size_align_unchecked(new_size, align); @@ -191,7 +191,7 @@ impl SizeClassAlloc { /// allocator, or it will not be used, and will not be freed unsafe fn create_carrier( size_class: SizeClass, - ) -> Result<*mut SlabCarrier, AllocErr> { + ) -> Result<*mut SlabCarrier, AllocError> { let size = SUPERALIGNED_CARRIER_SIZE; assert!(size_class.to_bytes() < size); let carrier_layout = Layout::from_size_align_unchecked(size, size); @@ -206,7 +206,7 @@ impl SizeClassAlloc { unsafe impl AllocRef for SizeClassAlloc { #[inline] - fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { unsafe { self.allocate(layout, init) } } @@ -218,7 +218,7 @@ unsafe impl AllocRef for SizeClassAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { self.reallocate(ptr, layout, new_size, placement, init) } @@ -229,7 +229,7 @@ unsafe impl AllocRef for SizeClassAlloc { layout: Layout, new_size: usize, placement: ReallocPlacement, - ) -> Result { + ) -> Result { self.reallocate(ptr, layout, new_size, placement, AllocInit::Uninitialized) } diff --git a/liblumen_alloc/src/stats_alloc.rs b/liblumen_alloc/src/stats_alloc.rs index ace216630..732134705 100644 --- a/liblumen_alloc/src/stats_alloc.rs +++ b/liblumen_alloc/src/stats_alloc.rs @@ -116,7 +116,7 @@ impl fmt::Display for Statistics { unsafe impl AllocRef for StatsAlloc { #[inline] - fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { let size = layout.size(); let align = layout.align(); match self.allocator.alloc(layout, init) { @@ -144,7 +144,7 @@ unsafe impl AllocRef for StatsAlloc new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { let old_ptr = ptr.as_ptr(); let old_size = layout.size(); let align = layout.align(); @@ -187,7 +187,7 @@ unsafe impl AllocRef for StatsAlloc layout: Layout, new_size: usize, placement: ReallocPlacement, - ) -> Result { + ) -> Result { let old_ptr = ptr.as_ptr(); let old_size = layout.size(); let align = layout.align(); diff --git a/liblumen_alloc/src/std_alloc.rs b/liblumen_alloc/src/std_alloc.rs index e7d0a6202..a4439de3f 100644 --- a/liblumen_alloc/src/std_alloc.rs +++ b/liblumen_alloc/src/std_alloc.rs @@ -323,7 +323,7 @@ impl StandardAlloc { AllocInit::init(init, block); Ok(block) } - Err(AllocErr) => Err(alloc!()), + Err(AllocError) => Err(alloc!()), } } @@ -389,8 +389,8 @@ impl StandardAlloc { } unsafe impl AllocRef for StandardAlloc { #[inline] - fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { - unsafe { self.allocate(layout, init).map_err(|_| AllocErr) } + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { + unsafe { self.allocate(layout, init).map_err(|_| AllocError) } } #[inline] @@ -401,9 +401,9 @@ unsafe impl AllocRef for StandardAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { self.reallocate(ptr, layout, new_size, placement, init) - .map_err(|_| AllocErr) + .map_err(|_| AllocError) } #[inline] @@ -413,9 +413,9 @@ unsafe impl AllocRef for StandardAlloc { layout: Layout, new_size: usize, placement: ReallocPlacement, - ) -> Result { + ) -> Result { self.reallocate(ptr, layout, new_size, placement, AllocInit::Uninitialized) - .map_err(|_| AllocErr) + .map_err(|_| AllocError) } #[inline] @@ -491,7 +491,7 @@ unsafe fn create_multi_block_carrier() -> AllocResult Err(alloc!()), + Err(AllocError) => Err(alloc!()), } } diff --git a/liblumen_core/src/alloc.rs b/liblumen_core/src/alloc.rs index 1e0be6bad..c481a082b 100755 --- a/liblumen_core/src/alloc.rs +++ b/liblumen_core/src/alloc.rs @@ -10,7 +10,7 @@ pub use self::sys_alloc::*; // Re-export core alloc types pub mod prelude { pub use core::alloc::{ - AllocErr, AllocInit, AllocRef, GlobalAlloc, Layout, LayoutErr, MemoryBlock, + AllocError, AllocInit, AllocRef, GlobalAlloc, Layout, LayoutErr, MemoryBlock, ReallocPlacement, }; pub use core_alloc::alloc::{handle_alloc_error, Global}; diff --git a/liblumen_core/src/alloc/mmap.rs b/liblumen_core/src/alloc/mmap.rs index b14e55225..d135e4db1 100644 --- a/liblumen_core/src/alloc/mmap.rs +++ b/liblumen_core/src/alloc/mmap.rs @@ -14,21 +14,21 @@ use crate::sys::mmap; /// Creates a memory mapping for the given `Layout` #[cfg(has_mmap)] #[inline] -pub unsafe fn map(layout: Layout) -> Result, AllocErr> { +pub unsafe fn map(layout: Layout) -> Result, AllocError> { mmap::map(layout).map(|(ptr, _)| ptr) } /// Creates a memory mapping for the given `Layout` #[cfg(not(has_mmap))] #[inline] -pub unsafe fn map(layout: Layout) -> Result, AllocErr> { +pub unsafe fn map(layout: Layout) -> Result, AllocError> { sys_alloc::alloc(layout).map(|memory_block| memory_block.ptr) } /// Creates a memory mapping specifically set up to behave like a stack #[cfg(has_mmap)] #[inline] -pub unsafe fn map_stack(pages: usize) -> Result, AllocErr> { +pub unsafe fn map_stack(pages: usize) -> Result, AllocError> { mmap::map_stack(pages) } @@ -38,7 +38,7 @@ pub unsafe fn map_stack(pages: usize) -> Result, AllocErr> { /// and it is implemented the same as `map` #[cfg(not(has_mmap))] #[inline] -pub unsafe fn map_stack(pages: usize) -> Result, AllocErr> { +pub unsafe fn map_stack(pages: usize) -> Result, AllocError> { let page_size = crate::sys::sysconf::pagesize(); let (layout, _offset) = Layout::from_size_align(page_size, page_size) .unwrap() @@ -55,7 +55,7 @@ pub unsafe fn remap( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result, AllocErr> { +) -> Result, AllocError> { mmap::remap(ptr, layout, new_size).map(|(ptr, _)| ptr) } @@ -66,7 +66,7 @@ pub unsafe fn remap( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result, AllocErr> { +) -> Result, AllocError> { sys_alloc::realloc(ptr, layout, new_size, ReallocPlacement::MayMove) .map(|memory_block| memory_block.ptr) } diff --git a/liblumen_core/src/alloc/sys_alloc.rs b/liblumen_core/src/alloc/sys_alloc.rs index 6be3ce08f..e402446d2 100644 --- a/liblumen_core/src/alloc/sys_alloc.rs +++ b/liblumen_core/src/alloc/sys_alloc.rs @@ -28,7 +28,7 @@ impl SysAlloc { unsafe impl AllocRef for SysAlloc { #[inline] - fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { match init { AllocInit::Uninitialized => sys_alloc::alloc(layout), AllocInit::Zeroed => sys_alloc::alloc_zeroed(layout), @@ -48,7 +48,7 @@ unsafe impl AllocRef for SysAlloc { new_size: usize, placement: ReallocPlacement, init: AllocInit, - ) -> Result { + ) -> Result { sys_alloc::grow(ptr.as_ptr(), layout, new_size, placement, init) } @@ -59,7 +59,7 @@ unsafe impl AllocRef for SysAlloc { layout: Layout, new_size: usize, placement: ReallocPlacement, - ) -> Result { + ) -> Result { sys_alloc::shrink(ptr.as_ptr(), layout, new_size, placement) } } @@ -111,7 +111,7 @@ pub unsafe fn realloc_fallback( ptr: *mut u8, old_layout: Layout, new_size: usize, -) -> Result { +) -> Result { use core::intrinsics::unlikely; let old_size = old_layout.size(); diff --git a/liblumen_core/src/sys/unix/alloc.rs b/liblumen_core/src/sys/unix/alloc.rs index cde79d0af..a62a50cfd 100755 --- a/liblumen_core/src/sys/unix/alloc.rs +++ b/liblumen_core/src/sys/unix/alloc.rs @@ -4,11 +4,11 @@ use crate::alloc::{prelude::*, realloc_fallback}; use crate::sys::sysconf::MIN_ALIGN; #[inline] -pub fn alloc(layout: Layout) -> Result { +pub fn alloc(layout: Layout) -> Result { let layout_size = layout.size(); if layout.align() <= MIN_ALIGN && layout.align() <= layout_size { NonNull::new(unsafe { libc::malloc(layout_size) as *mut u8 }) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: layout_size, @@ -17,7 +17,7 @@ pub fn alloc(layout: Layout) -> Result { #[cfg(target_os = "macos")] { if layout.align() > (1 << 31) { - return Err(AllocErr); + return Err(AllocError); } } unsafe { aligned_alloc(&layout) } @@ -25,11 +25,11 @@ pub fn alloc(layout: Layout) -> Result { } #[inline] -pub fn alloc_zeroed(layout: Layout) -> Result { +pub fn alloc_zeroed(layout: Layout) -> Result { let layout_size = layout.size(); if layout.align() <= MIN_ALIGN && layout.align() <= layout_size { NonNull::new(unsafe { libc::calloc(layout_size, 1) as *mut u8 }) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: layout_size, @@ -49,14 +49,14 @@ pub unsafe fn grow( new_size: usize, placement: ReallocPlacement, _init: AllocInit, -) -> Result { +) -> Result { if placement != ReallocPlacement::MayMove { // We can't guarantee the allocation won't move - return Err(AllocErr); + return Err(AllocError); } if layout.align() <= MIN_ALIGN && layout.align() <= new_size { NonNull::new(libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: new_size, @@ -72,14 +72,14 @@ pub unsafe fn shrink( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { if placement != ReallocPlacement::MayMove { // We can't guarantee the allocation won't move - return Err(AllocErr); + return Err(AllocError); } if layout.align() <= MIN_ALIGN && layout.align() <= new_size { NonNull::new(libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: new_size, @@ -95,12 +95,12 @@ pub unsafe fn free(ptr: *mut u8, _layout: Layout) { } #[inline] -unsafe fn aligned_alloc(layout: &Layout) -> Result { +unsafe fn aligned_alloc(layout: &Layout) -> Result { let mut ptr = ptr::null_mut(); let layout_size = layout.size(); let result = libc::posix_memalign(&mut ptr, layout.align(), layout_size); if result != 0 { - return Err(AllocErr); + return Err(AllocError); } Ok(MemoryBlock { ptr: NonNull::new_unchecked(ptr as *mut u8), diff --git a/liblumen_core/src/sys/unix/mmap.rs b/liblumen_core/src/sys/unix/mmap.rs index efe7b7bbf..d66b08318 100755 --- a/liblumen_core/src/sys/unix/mmap.rs +++ b/liblumen_core/src/sys/unix/mmap.rs @@ -1,4 +1,4 @@ -use core::alloc::{AllocErr, Layout}; +use core::alloc::{AllocError, Layout}; #[cfg(all( not(target_os = "linux"), not(target_os = "emscripten"), @@ -64,7 +64,7 @@ const STACK_FLAGS: libc::c_int = MMAP_FLAGS; /// If `hint_ptr` is not a null pointer, it will be used to hint to the OS /// where we would like the region mapped. #[inline] -pub unsafe fn map(layout: Layout) -> Result<(NonNull, usize), AllocErr> { +pub unsafe fn map(layout: Layout) -> Result<(NonNull, usize), AllocError> { let page_size = sysconf::pagesize(); let size = alloc_utils::round_up_to_multiple_of(layout.size(), page_size); let align = layout.align(); @@ -104,7 +104,7 @@ pub unsafe fn map(layout: Layout) -> Result<(NonNull, usize), AllocErr> { } #[inline] -pub unsafe fn map_stack(pages: usize) -> Result, AllocErr> { +pub unsafe fn map_stack(pages: usize) -> Result, AllocError> { // Stacks must be at least 1 page + 1 guard page let page_size = sysconf::pagesize(); let stack_size = page_size * (pages + 1); @@ -120,19 +120,19 @@ pub unsafe fn map_stack(pages: usize) -> Result, AllocErr> { ); if res == MAP_FAILED { - return Err(AllocErr); + return Err(AllocError); } // Set up guard page if 0 == libc::mprotect(res as *mut libc::c_void, page_size, GUARD_PROT) { Ok(NonNull::new_unchecked(res as *mut u8)) } else { - Err(AllocErr) + Err(AllocError) } } #[inline(always)] -unsafe fn map_internal(hint_ptr: *mut u8, size: usize) -> Result<(NonNull, usize), AllocErr> { +unsafe fn map_internal(hint_ptr: *mut u8, size: usize) -> Result<(NonNull, usize), AllocError> { let res = libc::mmap( hint_ptr as *mut libc::c_void, size, @@ -142,7 +142,7 @@ unsafe fn map_internal(hint_ptr: *mut u8, size: usize) -> Result<(NonNull, u 0, ); if res == MAP_FAILED { - return Err(AllocErr); + return Err(AllocError); } Ok((NonNull::new_unchecked(res as *mut u8), size)) @@ -179,7 +179,7 @@ pub unsafe fn remap( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { let old_size = layout.size(); let align = layout.align(); let new_size = alloc_utils::round_up_to_multiple_of(new_size, align); @@ -198,10 +198,10 @@ unsafe fn remap_internal( old_size: usize, _align: usize, new_size: usize, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { let new_seg = libc::mremap(ptr as *mut _, old_size, new_size, libc::MREMAP_MAYMOVE); if new_seg == MAP_FAILED { - return Err(AllocErr); + return Err(AllocError); } Ok((NonNull::new_unchecked(new_seg as *mut _), new_size)) } @@ -216,10 +216,10 @@ unsafe fn remap_internal( old_size: usize, _align: usize, new_size: usize, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { let new_seg = libc::mremap(ptr as *mut _, old_size, 0, new_size, 0 as libc::c_int); if new_seg == MAP_FAILED { - return Err(AllocErr); + return Err(AllocError); } Ok((NonNull::new_unchecked(new_seg as *mut _), new_size)) } @@ -240,7 +240,7 @@ unsafe fn remap_internal( old_size: usize, align: usize, new_size: usize, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { // Try and map the extra space at the end of the old mapping let hint_ptr = ((ptr as usize) + old_size) as *mut libc::c_void; let extend_size = new_size - old_size; @@ -255,7 +255,7 @@ unsafe fn remap_internal( // Unable to map any new memory if ret == MAP_FAILED { - return Err(AllocErr); + return Err(AllocError); } // We have the memory, but not where we wanted it @@ -283,7 +283,7 @@ unsafe fn remap_fallback( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { // Allocate new mapping let new_layout = Layout::from_size_align(new_size, layout.align()).expect("invalid layout"); let (new_ptr, new_ptr_size) = map(new_layout)?; diff --git a/liblumen_core/src/sys/wasm32/unknown/alloc.rs b/liblumen_core/src/sys/wasm32/unknown/alloc.rs index a430ae9bd..e54368cbd 100644 --- a/liblumen_core/src/sys/wasm32/unknown/alloc.rs +++ b/liblumen_core/src/sys/wasm32/unknown/alloc.rs @@ -1,4 +1,4 @@ -use core::alloc::{AllocErr, AllocInit, Layout, MemoryBlock, ReallocPlacement}; +use core::alloc::{AllocError, AllocInit, Layout, MemoryBlock, ReallocPlacement}; use core::ptr::NonNull; @@ -7,22 +7,22 @@ use crate::locks::SpinLock; static SYS_ALLOC_LOCK: SpinLock = SpinLock::new(dlmalloc::DLMALLOC_INIT); #[inline] -pub fn alloc(layout: Layout) -> Result { +pub fn alloc(layout: Layout) -> Result { let mut allocator = SYS_ALLOC_LOCK.lock(); let layout_size = layout.size(); let ptr = unsafe { (*allocator).malloc(layout_size, layout.align()) }; - NonNull::new(ptr).ok_or(AllocErr).map(|ptr| MemoryBlock { + NonNull::new(ptr).ok_or(AllocError).map(|ptr| MemoryBlock { ptr, size: layout_size, }) } #[inline] -pub fn alloc_zeroed(layout: Layout) -> Result { +pub fn alloc_zeroed(layout: Layout) -> Result { let mut allocator = SYS_ALLOC_LOCK.lock(); let layout_size = layout.size(); let ptr = unsafe { (*allocator).calloc(layout_size, layout.align()) }; - NonNull::new(ptr).ok_or(AllocErr).map(|ptr| MemoryBlock { + NonNull::new(ptr).ok_or(AllocError).map(|ptr| MemoryBlock { ptr, size: layout_size, }) @@ -35,7 +35,7 @@ pub unsafe fn grow( new_size: usize, placement: ReallocPlacement, init: AllocInit, -) -> Result { +) -> Result { let old_size = layout.size(); let block = self::realloc(ptr, layout, new_size, placement)?; AllocInit::init_offset(init, block, old_size); @@ -48,7 +48,7 @@ pub unsafe fn shrink( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { self::realloc(ptr, layout, new_size, placement) } @@ -58,16 +58,16 @@ pub unsafe fn realloc( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } let mut allocator = SYS_ALLOC_LOCK.lock(); let layout_size = layout.size(); let new_ptr = (*allocator).realloc(ptr, layout_size, layout.align(), new_size); NonNull::new(new_ptr) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: layout_size, diff --git a/liblumen_core/src/sys/wasm32/wasi/alloc.rs b/liblumen_core/src/sys/wasm32/wasi/alloc.rs index 70e3cc0fb..e49fe93ff 100644 --- a/liblumen_core/src/sys/wasm32/wasi/alloc.rs +++ b/liblumen_core/src/sys/wasm32/wasi/alloc.rs @@ -5,7 +5,7 @@ use crate::alloc::realloc_fallback; use crate::sys::sysconf::MIN_ALIGN; #[inline] -pub fn alloc(layout: Layout) -> Result { +pub fn alloc(layout: Layout) -> Result { let layout_size = layout.size(); let ptr = if layout.align() <= MIN_ALIGN && layout.align() <= layout_size { libc::malloc(layout_size) as *mut u8 @@ -13,14 +13,14 @@ pub fn alloc(layout: Layout) -> Result { libc::aligned_alloc(layout_size, layout.align()) as *mut u8 }; - NonNull::new(ptr).ok_or(AllocErr).map(|ptr| MemoryBlock { + NonNull::new(ptr).ok_or(AllocError).map(|ptr| MemoryBlock { ptr, size: layout_size, }) } #[inline] -pub fn alloc_zeroed(layout: Layout) -> Result { +pub fn alloc_zeroed(layout: Layout) -> Result { let layout_size = layout.size(); let ptr = if layout.align() <= MIN_ALIGN && layout.align() <= layout_size { libc::calloc(layout.size(), 1) as *mut u8 @@ -32,7 +32,7 @@ pub fn alloc_zeroed(layout: Layout) -> Result { ptr }; - NonNull::new(ptr).ok_or(AllocErr).map(|ptr| MemoryBlock { + NonNull::new(ptr).ok_or(AllocError).map(|ptr| MemoryBlock { ptr, size: layout_size, }) @@ -45,7 +45,7 @@ pub unsafe fn grow( new_size: usize, placement: ReallocPlacement, init: AllocInit, -) -> Result { +) -> Result { let old_size = layout.size(); let block = self::realloc(ptr, layout, new_size, placement)?; AllocInit::init_offset(init, block, old_size); @@ -58,7 +58,7 @@ pub unsafe fn shrink( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { self::realloc(ptr, layout, new_size, placement) } @@ -68,14 +68,14 @@ unsafe fn realloc( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } if layout.align() <= MIN_ALIGN && layout.align() <= new_size { NonNull::new(libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: new_size, diff --git a/liblumen_core/src/sys/windows/alloc.rs b/liblumen_core/src/sys/windows/alloc.rs index 423c87732..47eb6c55f 100755 --- a/liblumen_core/src/sys/windows/alloc.rs +++ b/liblumen_core/src/sys/windows/alloc.rs @@ -13,10 +13,10 @@ use crate::sys::sysconf::MIN_ALIGN; struct Header(*mut u8); #[inline] -pub fn alloc(layout: Layout) -> Result { +pub fn alloc(layout: Layout) -> Result { let layout_size = layout.size(); NonNull::new(alloc_with_flags(layout, 0)) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: layout_size, @@ -24,9 +24,9 @@ pub fn alloc(layout: Layout) -> Result { } #[inline] -pub fn alloc_zeroed(layout: Layout) -> Result { +pub fn alloc_zeroed(layout: Layout) -> Result { NonNull::new(alloc_with_flags(layout, HEAP_ZERO_MEMORY)) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: layout_size, @@ -40,7 +40,7 @@ pub unsafe fn grow( new_size: usize, placement: ReallocPlacement, init: AllocInit, -) -> Result { +) -> Result { let old_size = layout.size(); let block = self::realloc(ptr, layout, new_size, placement)?; AllocInit::init_offset(init, block, old_size); @@ -53,7 +53,7 @@ pub unsafe fn shrink( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result { +) -> Result { self::realloc(ptr, layout, new_size, placement) } @@ -63,14 +63,14 @@ unsafe fn realloc( layout: Layout, new_size: usize, placement: ReallocPlacement, -) -> Result<(NonNull, usize), AllocErr> { +) -> Result<(NonNull, usize), AllocError> { if placement != ReallocPlacement::MayMove { - return Err(AllocErr); + return Err(AllocError); } if layout.align() <= MIN_ALIGN { NonNull::new(HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, new_size) as *mut u8) - .ok_or(AllocErr) + .ok_or(AllocError) .map(|ptr| MemoryBlock { ptr, size: new_size, diff --git a/liblumen_core/src/sys/windows/mmap.rs b/liblumen_core/src/sys/windows/mmap.rs index 9d9006324..ca35482b0 100755 --- a/liblumen_core/src/sys/windows/mmap.rs +++ b/liblumen_core/src/sys/windows/mmap.rs @@ -1,4 +1,4 @@ -use core::alloc::{AllocErr, Layout}; +use core::alloc::{AllocError, Layout}; use core::mem; use core::ptr::{self, NonNull}; @@ -26,7 +26,7 @@ use crate::sys::sysconf; // e.g., result in VirtualAlloc being called with invalid arguments). This isn't ideal, but // during debugging, error codes can be printed here, so it's not the end of the world. #[inline] -pub unsafe fn map(layout: Layout) -> Result, AllocErr> { +pub unsafe fn map(layout: Layout) -> Result, AllocError> { let page_size = sysconf::pagesize(); let align = layout.align(); @@ -40,7 +40,7 @@ pub unsafe fn map(layout: Layout) -> Result, AllocErr> { MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE, ); - return NonNull::new(ptr as *mut u8).ok_or(AllocErr); + return NonNull::new(ptr as *mut u8).ok_or(AllocError); } // We have to handle alignment ourselves, so we reserve a larger region @@ -54,7 +54,7 @@ pub unsafe fn map(layout: Layout) -> Result, AllocErr> { let ptr = VirtualAlloc(ptr::null_mut(), padded, MEM_RESERVE, PAGE_NOACCESS); if ptr.is_null() { - return Err(AllocErr); + return Err(AllocError); } // Calculate aligned address @@ -153,7 +153,7 @@ pub unsafe fn remap( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result, AllocErr> { +) -> Result, AllocError> { let old_size = layout.size(); let page_size = sysconf::pagesize(); @@ -193,7 +193,7 @@ unsafe fn remap_fallback( ptr: *mut u8, layout: Layout, new_size: usize, -) -> Result, AllocErr> { +) -> Result, AllocError> { use core::cmp; // Create new mapping