@@ -5,7 +5,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
5
5
use crate :: ptr;
6
6
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
7
7
8
- // symbols defined in the target linkerscript
8
+ // Symbols for heap section boundaries defined in the target's linkerscript
9
9
unsafe extern "C" {
10
10
static mut __heap_start: u8 ;
11
11
static mut __heap_end: u8 ;
@@ -21,10 +21,12 @@ unsafe impl dlmalloc::Allocator for Vexos {
21
21
static INIT : AtomicBool = AtomicBool :: new ( false ) ;
22
22
23
23
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.
24
26
unsafe {
25
27
(
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 ) ,
28
30
0 ,
29
31
)
30
32
}
@@ -63,31 +65,31 @@ unsafe impl GlobalAlloc for System {
63
65
#[ inline]
64
66
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
65
67
// 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.
67
69
// Calling malloc() is safe because preconditions on this function match the trait method preconditions.
68
70
unsafe { DLMALLOC . malloc ( layout. size ( ) , layout. align ( ) ) }
69
71
}
70
72
71
73
#[ inline]
72
74
unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
73
75
// 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.
75
77
// Calling calloc() is safe because preconditions on this function match the trait method preconditions.
76
78
unsafe { DLMALLOC . calloc ( layout. size ( ) , layout. align ( ) ) }
77
79
}
78
80
79
81
#[ inline]
80
82
unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
81
83
// 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.
83
85
// Calling free() is safe because preconditions on this function match the trait method preconditions.
84
86
unsafe { DLMALLOC . free ( ptr, layout. size ( ) , layout. align ( ) ) }
85
87
}
86
88
87
89
#[ inline]
88
90
unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
89
91
// 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.
91
93
// Calling realloc() is safe because preconditions on this function match the trait method preconditions.
92
94
unsafe { DLMALLOC . realloc ( ptr, layout. size ( ) , layout. align ( ) , new_size) }
93
95
}
0 commit comments