File tree 1 file changed +21
-2
lines changed
library/std/src/sys/custom
1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 3
3
use crate :: alloc:: { GlobalAlloc , Layout , System } ;
4
4
use crate :: os:: custom:: alloc:: IMPL ;
5
5
use crate :: sync:: Mutex ;
6
+ use core:: ops:: { Deref , DerefMut } ;
6
7
7
8
// Simple implementation of a sequential fit allocator
8
9
//
@@ -39,11 +40,29 @@ use crate::sync::Mutex;
39
40
// note: copy the value of the global "first free slot" variable into the next pointer pair
40
41
// c. update the global "first free slot" variable
41
42
42
- static mut HEAP : [ u8 ; SIZE_BYTES ] = init_heap ( ) ;
43
-
44
43
// maximum: 0xffff
45
44
// more than 0xffff => will cause infinite loops
46
45
const SIZE_BYTES : usize = 4096 * 4 ;
46
+ type HeapArray = [ u8 ; SIZE_BYTES ] ;
47
+
48
+ // align the heap to a page
49
+ #[ repr( align( 4096 ) ) ]
50
+ struct Heap ( HeapArray ) ;
51
+
52
+ impl Deref for Heap {
53
+ type Target = HeapArray ;
54
+ fn deref ( & self ) -> & HeapArray {
55
+ & self . 0
56
+ }
57
+ }
58
+
59
+ impl DerefMut for Heap {
60
+ fn deref_mut ( & mut self ) -> & mut HeapArray {
61
+ & mut self . 0
62
+ }
63
+ }
64
+
65
+ static mut HEAP : Heap = Heap ( init_heap ( ) ) ;
47
66
static FIRST_SLOT : Mutex < usize > = Mutex :: new ( 0 ) ;
48
67
49
68
const fn init_heap ( ) -> [ u8 ; SIZE_BYTES ] {
You can’t perform that action at this time.
0 commit comments