14
14
15
15
use core:: ffi:: c_void;
16
16
17
+ use atomic_refcell:: AtomicRefCell ;
17
18
use r_efi:: {
18
19
efi:: {
19
20
self , AllocateType , Boolean , CapsuleHeader , Char16 , Event , EventNotify , Guid , Handle ,
@@ -25,7 +26,6 @@ use r_efi::{
25
26
device_path:: Protocol as DevicePathProtocol , loaded_image:: Protocol as LoadedImageProtocol ,
26
27
} ,
27
28
} ;
28
- use spin:: Mutex ;
29
29
30
30
mod alloc;
31
31
mod block;
@@ -48,7 +48,7 @@ struct HandleWrapper {
48
48
handle_type : HandleType ,
49
49
}
50
50
51
- pub static ALLOCATOR : Mutex < Allocator > = Mutex :: new ( Allocator :: new ( ) ) ;
51
+ pub static ALLOCATOR : AtomicRefCell < Allocator > = AtomicRefCell :: new ( Allocator :: new ( ) ) ;
52
52
53
53
static mut BLOCK_WRAPPERS : block:: BlockWrappers = block:: BlockWrappers {
54
54
wrappers : [ core:: ptr:: null_mut ( ) ; 16 ] ,
@@ -87,7 +87,7 @@ pub extern "win64" fn set_virtual_address_map(
87
87
core:: slice:: from_raw_parts_mut ( descriptors as * mut alloc:: MemoryDescriptor , count)
88
88
} ;
89
89
90
- ALLOCATOR . lock ( ) . update_virtual_addresses ( descriptors)
90
+ ALLOCATOR . borrow_mut ( ) . update_virtual_addresses ( descriptors)
91
91
}
92
92
93
93
pub extern "win64" fn convert_pointer ( _: usize , _: * mut * mut c_void ) -> Status {
@@ -175,7 +175,7 @@ pub extern "win64" fn allocate_pages(
175
175
) -> Status {
176
176
let ( status, new_address) =
177
177
ALLOCATOR
178
- . lock ( )
178
+ . borrow_mut ( )
179
179
. allocate_pages (
180
180
allocate_type,
181
181
memory_type,
@@ -191,7 +191,7 @@ pub extern "win64" fn allocate_pages(
191
191
}
192
192
193
193
pub extern "win64" fn free_pages ( address : PhysicalAddress , _: usize ) -> Status {
194
- ALLOCATOR . lock ( ) . free_pages ( address)
194
+ ALLOCATOR . borrow_mut ( ) . free_pages ( address)
195
195
}
196
196
197
197
pub extern "win64" fn get_memory_map (
@@ -201,7 +201,7 @@ pub extern "win64" fn get_memory_map(
201
201
descriptor_size : * mut usize ,
202
202
descriptor_version : * mut u32 ,
203
203
) -> Status {
204
- let count = ALLOCATOR . lock ( ) . get_descriptor_count ( ) ;
204
+ let count = ALLOCATOR . borrow ( ) . get_descriptor_count ( ) ;
205
205
let map_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) * count;
206
206
if unsafe { * memory_map_size } < map_size {
207
207
unsafe {
@@ -212,13 +212,13 @@ pub extern "win64" fn get_memory_map(
212
212
213
213
let out =
214
214
unsafe { core:: slice:: from_raw_parts_mut ( out as * mut alloc:: MemoryDescriptor , count) } ;
215
- let count = ALLOCATOR . lock ( ) . get_descriptors ( out) ;
215
+ let count = ALLOCATOR . borrow ( ) . get_descriptors ( out) ;
216
216
let map_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) * count;
217
217
unsafe {
218
218
* memory_map_size = map_size;
219
219
* descriptor_version = efi:: MEMORY_DESCRIPTOR_VERSION ;
220
220
* descriptor_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) ;
221
- * key = ALLOCATOR . lock ( ) . get_map_key ( ) ;
221
+ * key = ALLOCATOR . borrow ( ) . get_map_key ( ) ;
222
222
}
223
223
224
224
Status :: SUCCESS
@@ -229,7 +229,7 @@ pub extern "win64" fn allocate_pool(
229
229
size : usize ,
230
230
address : * mut * mut c_void ,
231
231
) -> Status {
232
- let ( status, new_address) = ALLOCATOR . lock ( ) . allocate_pages (
232
+ let ( status, new_address) = ALLOCATOR . borrow_mut ( ) . allocate_pages (
233
233
AllocateType :: AllocateAnyPages ,
234
234
memory_type,
235
235
( ( size + PAGE_SIZE as usize - 1 ) / PAGE_SIZE as usize ) as u64 ,
@@ -246,7 +246,7 @@ pub extern "win64" fn allocate_pool(
246
246
}
247
247
248
248
pub extern "win64" fn free_pool ( ptr : * mut c_void ) -> Status {
249
- ALLOCATOR . lock ( ) . free_pages ( ptr as u64 )
249
+ ALLOCATOR . borrow_mut ( ) . free_pages ( ptr as u64 )
250
250
}
251
251
252
252
pub extern "win64" fn create_event (
@@ -597,7 +597,7 @@ fn populate_allocator(image_address: u64, image_size: u64) {
597
597
598
598
for entry in e820_table {
599
599
if entry. entry_type == E820_RAM {
600
- ALLOCATOR . lock ( ) . add_initial_allocation (
600
+ ALLOCATOR . borrow_mut ( ) . add_initial_allocation (
601
601
MemoryType :: ConventionalMemory ,
602
602
entry. size / PAGE_SIZE ,
603
603
entry. addr ,
@@ -607,15 +607,15 @@ fn populate_allocator(image_address: u64, image_size: u64) {
607
607
}
608
608
609
609
// Add ourselves
610
- ALLOCATOR . lock ( ) . allocate_pages (
610
+ ALLOCATOR . borrow_mut ( ) . allocate_pages (
611
611
AllocateType :: AllocateAddress ,
612
612
MemoryType :: RuntimeServicesCode ,
613
613
1024 * 1024 / PAGE_SIZE ,
614
614
1024 * 1024 ,
615
615
) ;
616
616
617
617
// Add the loaded binary
618
- ALLOCATOR . lock ( ) . allocate_pages (
618
+ ALLOCATOR . borrow_mut ( ) . allocate_pages (
619
619
AllocateType :: AllocateAddress ,
620
620
MemoryType :: LoaderCode ,
621
621
image_size / PAGE_SIZE ,
0 commit comments