File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
library/std/src/sys/custom Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 33use crate :: alloc:: { GlobalAlloc , Layout , System } ;
44use crate :: os:: custom:: alloc:: IMPL ;
55use crate :: sync:: Mutex ;
6+ use core:: ops:: { Deref , DerefMut } ;
67
78// Simple implementation of a sequential fit allocator
89//
@@ -39,11 +40,29 @@ use crate::sync::Mutex;
3940// note: copy the value of the global "first free slot" variable into the next pointer pair
4041// c. update the global "first free slot" variable
4142
42- static mut HEAP : [ u8 ; SIZE_BYTES ] = init_heap ( ) ;
43-
4443// maximum: 0xffff
4544// more than 0xffff => will cause infinite loops
4645const 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 ( ) ) ;
4766static FIRST_SLOT : Mutex < usize > = Mutex :: new ( 0 ) ;
4867
4968const fn init_heap ( ) -> [ u8 ; SIZE_BYTES ] {
You can’t perform that action at this time.
0 commit comments