File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,15 @@ impl Heap {
104104 } )
105105 }
106106
107+ unsafe fn realloc ( & self , ptr : * mut u8 , new_layout : Layout ) -> Option < NonNull < u8 > > {
108+ critical_section:: with ( |cs| {
109+ self . heap
110+ . borrow_ref_mut ( cs)
111+ . tlsf
112+ . reallocate ( NonNull :: new_unchecked ( ptr) , new_layout)
113+ } )
114+ }
115+
107116 /// Get the amount of bytes used by the allocator.
108117 pub fn used ( & self ) -> usize {
109118 critical_section:: with ( |cs| {
@@ -144,6 +153,15 @@ unsafe impl GlobalAlloc for Heap {
144153 unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
145154 self . dealloc ( ptr, layout)
146155 }
156+
157+ unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
158+ // SAFETY: `layout.align()` is a power of two, and the size precondition
159+ // is upheld by the caller.
160+ let new_layout =
161+ unsafe { core:: alloc:: Layout :: from_size_align_unchecked ( new_size, layout. align ( ) ) } ;
162+ self . realloc ( ptr, new_layout)
163+ . map_or ( ptr:: null_mut ( ) , |allocation| allocation. as_ptr ( ) )
164+ }
147165}
148166
149167#[ cfg( feature = "allocator_api" ) ]
You can’t perform that action at this time.
0 commit comments