File tree 3 files changed +27
-3
lines changed
3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change
1
+ use core:: alloc:: GlobalAlloc ;
2
+ extern crate alloc;
3
+
4
+ type MainAllocator = RootAllocator ;
5
+
6
+ #[ global_allocator]
7
+ static GLOBAL_ALLOC : MainAllocator = MainAllocator :: new ( ) ;
8
+
9
+ struct RootAllocator { }
10
+
11
+ impl RootAllocator {
12
+ const fn new ( ) -> Self {
13
+ Self { }
14
+ }
15
+ }
16
+
17
+ unsafe impl GlobalAlloc for RootAllocator {
18
+ unsafe fn alloc ( & self , layout : core:: alloc:: Layout ) -> * mut u8 {
19
+ super :: staticalloc:: GLOBAL_STATIC_ALLOCATOR . alloc ( layout)
20
+ }
21
+ unsafe fn dealloc ( & self , ptr : * mut u8 , layout : core:: alloc:: Layout ) {
22
+ super :: staticalloc:: GLOBAL_STATIC_ALLOCATOR . dealloc ( ptr, layout) ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change 4
4
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
*/
6
6
7
+ pub mod mall;
7
8
pub mod map;
8
9
pub mod staticalloc;
Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ extern crate alloc;
4
4
5
5
const MAX : usize = crate :: config:: STATIC_ALLOCATOR_SIZE_BYTES ;
6
6
7
- #[ global_allocator]
8
- static GLOBAL_STATIC_ALLOCATOR : StaticAllocator < MAX > = StaticAllocator :: new ( ) ;
7
+ pub static GLOBAL_STATIC_ALLOCATOR : StaticAllocator < MAX > = StaticAllocator :: new ( ) ;
9
8
10
- struct StaticAllocator < const SIZE : usize > {
9
+ pub struct StaticAllocator < const SIZE : usize > {
11
10
buffer : [ u8 ; SIZE ] ,
12
11
bump_addr : spin:: Mutex < usize > ,
13
12
refcount : spin:: Mutex < usize > ,
You can’t perform that action at this time.
0 commit comments