@@ -5,7 +5,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
55use crate :: ptr;
66use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
77
8- // symbols defined in the target linkerscript
8+ // Symbols for heap section boundaries defined in the target's linkerscript
99unsafe extern "C" {
1010 static mut __heap_start: u8 ;
1111 static mut __heap_end: u8 ;
@@ -21,10 +21,12 @@ unsafe impl dlmalloc::Allocator for Vexos {
2121 static INIT : AtomicBool = AtomicBool :: new ( false ) ;
2222
2323 if !INIT . swap ( true , Ordering :: Relaxed ) {
24+ // This target has no growable heap, as user memory has a fixed
25+ // size/location and VEXos does not manage allocation for us.
2426 unsafe {
2527 (
26- ( & raw mut __heap_start) . cast ( ) ,
27- ( & raw const __heap_end) . byte_offset_from ( ptr :: addr_of! ( __heap_start ) ) as _ ,
28+ ( & raw mut __heap_start) . cast :: < u8 > ( ) ,
29+ ( & raw const __heap_end) . offset_from_unsigned ( & raw const __heap_start ) ,
2830 0 ,
2931 )
3032 }
@@ -63,31 +65,31 @@ unsafe impl GlobalAlloc for System {
6365 #[ inline]
6466 unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
6567 // SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
66- // guarantees unique and non-reentrant access to the allocator.
68+ // guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
6769 // Calling malloc() is safe because preconditions on this function match the trait method preconditions.
6870 unsafe { DLMALLOC . malloc ( layout. size ( ) , layout. align ( ) ) }
6971 }
7072
7173 #[ inline]
7274 unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
7375 // SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
74- // guarantees unique and non-reentrant access to the allocator.
76+ // guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
7577 // Calling calloc() is safe because preconditions on this function match the trait method preconditions.
7678 unsafe { DLMALLOC . calloc ( layout. size ( ) , layout. align ( ) ) }
7779 }
7880
7981 #[ inline]
8082 unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
8183 // SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
82- // guarantees unique and non-reentrant access to the allocator.
84+ // guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
8385 // Calling free() is safe because preconditions on this function match the trait method preconditions.
8486 unsafe { DLMALLOC . free ( ptr, layout. size ( ) , layout. align ( ) ) }
8587 }
8688
8789 #[ inline]
8890 unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
8991 // SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
90- // guarantees unique and non-reentrant access to the allocator.
92+ // guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
9193 // Calling realloc() is safe because preconditions on this function match the trait method preconditions.
9294 unsafe { DLMALLOC . realloc ( ptr, layout. size ( ) , layout. align ( ) , new_size) }
9395 }
0 commit comments