@@ -63,32 +63,52 @@ const fn order_from_size(size: u64) -> usize {
63
63
unreachable ! ( )
64
64
}
65
65
66
- pub struct LockedFrameAllocator ( Once < Mutex < GlobalFrameAllocator > > ) ;
66
+ pub struct LockedFrameAllocator ( Mutex < GlobalFrameAllocator > ) ;
67
67
68
68
impl LockedFrameAllocator {
69
69
/// Constructs a new uninitialized and locked version of the global frame
70
70
/// allocator.
71
71
pub ( super ) const fn new_uninit ( ) -> Self {
72
- Self ( Once :: new ( ) )
72
+ let bstrap_ref = BootAllocRef {
73
+ inner : core:: ptr:: null ( ) ,
74
+ } ;
75
+
76
+ Self ( Mutex :: new ( GlobalFrameAllocator {
77
+ buddies : [
78
+ Bitmap :: empty ( bstrap_ref) ,
79
+ Bitmap :: empty ( bstrap_ref) ,
80
+ Bitmap :: empty ( bstrap_ref) ,
81
+ Bitmap :: empty ( bstrap_ref) ,
82
+ Bitmap :: empty ( bstrap_ref) ,
83
+ Bitmap :: empty ( bstrap_ref) ,
84
+ Bitmap :: empty ( bstrap_ref) ,
85
+ Bitmap :: empty ( bstrap_ref) ,
86
+ Bitmap :: empty ( bstrap_ref) ,
87
+ Bitmap :: empty ( bstrap_ref) ,
88
+ ] ,
89
+ free : [ 0 ; 10 ] ,
90
+
91
+ base : PhysAddr :: zero ( ) ,
92
+ end : PhysAddr :: zero ( ) ,
93
+ } ) )
73
94
}
74
95
75
96
/// Initializes the inner locked global frame allocator.
76
97
pub ( super ) fn init ( & self , memory_map : & mut limine:: response:: MemoryMapResponse ) {
77
- self . 0
78
- . call_once ( || Mutex :: new ( GlobalFrameAllocator :: new ( memory_map) ) ) ;
98
+ * self . 0 . lock_irq ( ) = GlobalFrameAllocator :: new ( memory_map) ;
79
99
}
80
100
81
101
pub fn dealloc ( & self , addr : PhysAddr , size_bytes : usize ) {
82
102
let order = order_from_size ( size_bytes as u64 ) ;
83
103
84
- let mut allocator = self . 0 . get ( ) . unwrap ( ) . lock_irq ( ) ;
104
+ let mut allocator = self . 0 . lock_irq ( ) ;
85
105
allocator. deallocate_frame_inner ( addr, order) ;
86
106
}
87
107
88
108
pub fn alloc ( & self , size_bytes : usize ) -> Option < PhysAddr > {
89
109
let order = order_from_size ( size_bytes as u64 ) ;
90
110
91
- let mut allocator = self . 0 . get ( ) ? . lock_irq ( ) ;
111
+ let mut allocator = self . 0 . lock_irq ( ) ;
92
112
allocator. allocate_frame_inner ( order)
93
113
}
94
114
@@ -108,12 +128,8 @@ unsafe impl FrameAllocator<Size4KiB> for LockedFrameAllocator {
108
128
109
129
fn deallocate_frame ( & self , frame : PhysFrame < Size4KiB > ) {
110
130
self . 0
111
- . get ( )
112
- . map ( |m| {
113
- m. lock_irq ( )
114
- . deallocate_frame_inner ( frame. start_address ( ) , order_from_size ( Size4KiB :: SIZE ) )
115
- } )
116
- . unwrap ( )
131
+ . lock_irq ( )
132
+ . deallocate_frame_inner ( frame. start_address ( ) , order_from_size ( Size4KiB :: SIZE ) )
117
133
}
118
134
}
119
135
@@ -125,12 +141,8 @@ unsafe impl FrameAllocator<Size2MiB> for LockedFrameAllocator {
125
141
126
142
fn deallocate_frame ( & self , frame : PhysFrame < Size2MiB > ) {
127
143
self . 0
128
- . get ( )
129
- . map ( |m| {
130
- m. lock_irq ( )
131
- . deallocate_frame_inner ( frame. start_address ( ) , order_from_size ( Size2MiB :: SIZE ) )
132
- } )
133
- . unwrap ( )
144
+ . lock_irq ( )
145
+ . deallocate_frame_inner ( frame. start_address ( ) , order_from_size ( Size2MiB :: SIZE ) )
134
146
}
135
147
}
136
148
@@ -188,7 +200,7 @@ pub fn pmm_alloc(order: BuddyOrdering) -> PhysAddr {
188
200
debug_assert ! ( order <= BUDDY_SIZE . len( ) ) ;
189
201
190
202
super :: FRAME_ALLOCATOR
191
- . alloc_zeroed ( BUDDY_SIZE [ order] as _ )
203
+ . alloc ( BUDDY_SIZE [ order] as _ )
192
204
. unwrap ( )
193
205
}
194
206
@@ -232,13 +244,13 @@ impl BootAlloc {
232
244
}
233
245
}
234
246
235
- #[ derive( Debug , Clone ) ]
247
+ #[ derive( Debug , Clone , Copy ) ]
236
248
struct BootAllocRef {
237
249
inner : * const BootAlloc ,
238
250
}
239
251
240
252
impl BootAllocRef {
241
- fn new ( inner : & BootAlloc ) -> Self {
253
+ const fn new ( inner : & BootAlloc ) -> Self {
242
254
Self {
243
255
inner : inner as * const _ ,
244
256
}
@@ -357,16 +369,16 @@ impl GlobalFrameAllocator {
357
369
end,
358
370
359
371
buddies : [
360
- Bitmap :: empty ( bref. clone ( ) ) ,
361
- Bitmap :: empty ( bref. clone ( ) ) ,
362
- Bitmap :: empty ( bref. clone ( ) ) ,
363
- Bitmap :: empty ( bref. clone ( ) ) ,
364
- Bitmap :: empty ( bref. clone ( ) ) ,
365
- Bitmap :: empty ( bref. clone ( ) ) ,
366
- Bitmap :: empty ( bref. clone ( ) ) ,
367
- Bitmap :: empty ( bref. clone ( ) ) ,
368
- Bitmap :: empty ( bref. clone ( ) ) ,
369
- Bitmap :: empty ( bref. clone ( ) ) ,
372
+ Bitmap :: empty ( bref) ,
373
+ Bitmap :: empty ( bref) ,
374
+ Bitmap :: empty ( bref) ,
375
+ Bitmap :: empty ( bref) ,
376
+ Bitmap :: empty ( bref) ,
377
+ Bitmap :: empty ( bref) ,
378
+ Bitmap :: empty ( bref) ,
379
+ Bitmap :: empty ( bref) ,
380
+ Bitmap :: empty ( bref) ,
381
+ Bitmap :: empty ( bref) ,
370
382
] ,
371
383
free : [ 0 ; 10 ] ,
372
384
} ;
@@ -376,7 +388,7 @@ impl GlobalFrameAllocator {
376
388
// Allocate the buddies using prealloc:
377
389
for ( i, bsize) in BUDDY_SIZE . iter ( ) . enumerate ( ) {
378
390
let chunk = size / bsize;
379
- this. buddies [ i] = Bitmap :: new_in ( bref. clone ( ) , chunk as usize ) ;
391
+ this. buddies [ i] = Bitmap :: new_in ( bref, chunk as usize ) ;
380
392
}
381
393
382
394
for region in bref. get_inner ( ) . memory_ranges . lock ( ) . iter ( ) {
@@ -545,12 +557,7 @@ impl GlobalFrameAllocator {
545
557
546
558
pub fn init_vm_frames ( ) {
547
559
VM_FRAMES . call_once ( || {
548
- let frame_count = super :: FRAME_ALLOCATOR
549
- . 0
550
- . get ( )
551
- . unwrap ( )
552
- . lock_irq ( )
553
- . frame_count ( ) ;
560
+ let frame_count = super :: FRAME_ALLOCATOR . 0 . lock_irq ( ) . frame_count ( ) ;
554
561
555
562
let mut frames = Vec :: < VmFrame > :: new ( ) ;
556
563
frames. resize_with ( frame_count, VmFrame :: new) ;
0 commit comments