1414
1515use core:: ffi:: c_void;
1616
17+ use atomic_refcell:: AtomicRefCell ;
1718use r_efi:: {
1819 efi:: {
1920 self , AllocateType , Boolean , CapsuleHeader , Char16 , Event , EventNotify , Guid , Handle ,
@@ -25,7 +26,6 @@ use r_efi::{
2526 device_path:: Protocol as DevicePathProtocol , loaded_image:: Protocol as LoadedImageProtocol ,
2627 } ,
2728} ;
28- use spin:: Mutex ;
2929
3030mod alloc;
3131mod block;
@@ -48,7 +48,7 @@ struct HandleWrapper {
4848 handle_type : HandleType ,
4949}
5050
51- pub static ALLOCATOR : Mutex < Allocator > = Mutex :: new ( Allocator :: new ( ) ) ;
51+ pub static ALLOCATOR : AtomicRefCell < Allocator > = AtomicRefCell :: new ( Allocator :: new ( ) ) ;
5252
5353static mut BLOCK_WRAPPERS : block:: BlockWrappers = block:: BlockWrappers {
5454 wrappers : [ core:: ptr:: null_mut ( ) ; 16 ] ,
@@ -87,7 +87,7 @@ pub extern "win64" fn set_virtual_address_map(
8787 core:: slice:: from_raw_parts_mut ( descriptors as * mut alloc:: MemoryDescriptor , count)
8888 } ;
8989
90- ALLOCATOR . lock ( ) . update_virtual_addresses ( descriptors)
90+ ALLOCATOR . borrow_mut ( ) . update_virtual_addresses ( descriptors)
9191}
9292
9393pub extern "win64" fn convert_pointer ( _: usize , _: * mut * mut c_void ) -> Status {
@@ -175,7 +175,7 @@ pub extern "win64" fn allocate_pages(
175175) -> Status {
176176 let ( status, new_address) =
177177 ALLOCATOR
178- . lock ( )
178+ . borrow_mut ( )
179179 . allocate_pages (
180180 allocate_type,
181181 memory_type,
@@ -191,7 +191,7 @@ pub extern "win64" fn allocate_pages(
191191}
192192
193193pub extern "win64" fn free_pages ( address : PhysicalAddress , _: usize ) -> Status {
194- ALLOCATOR . lock ( ) . free_pages ( address)
194+ ALLOCATOR . borrow_mut ( ) . free_pages ( address)
195195}
196196
197197pub extern "win64" fn get_memory_map (
@@ -201,7 +201,7 @@ pub extern "win64" fn get_memory_map(
201201 descriptor_size : * mut usize ,
202202 descriptor_version : * mut u32 ,
203203) -> Status {
204- let count = ALLOCATOR . lock ( ) . get_descriptor_count ( ) ;
204+ let count = ALLOCATOR . borrow ( ) . get_descriptor_count ( ) ;
205205 let map_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) * count;
206206 if unsafe { * memory_map_size } < map_size {
207207 unsafe {
@@ -212,13 +212,13 @@ pub extern "win64" fn get_memory_map(
212212
213213 let out =
214214 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) ;
216216 let map_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) * count;
217217 unsafe {
218218 * memory_map_size = map_size;
219219 * descriptor_version = efi:: MEMORY_DESCRIPTOR_VERSION ;
220220 * descriptor_size = core:: mem:: size_of :: < MemoryDescriptor > ( ) ;
221- * key = ALLOCATOR . lock ( ) . get_map_key ( ) ;
221+ * key = ALLOCATOR . borrow ( ) . get_map_key ( ) ;
222222 }
223223
224224 Status :: SUCCESS
@@ -229,7 +229,7 @@ pub extern "win64" fn allocate_pool(
229229 size : usize ,
230230 address : * mut * mut c_void ,
231231) -> Status {
232- let ( status, new_address) = ALLOCATOR . lock ( ) . allocate_pages (
232+ let ( status, new_address) = ALLOCATOR . borrow_mut ( ) . allocate_pages (
233233 AllocateType :: AllocateAnyPages ,
234234 memory_type,
235235 ( ( size + PAGE_SIZE as usize - 1 ) / PAGE_SIZE as usize ) as u64 ,
@@ -246,7 +246,7 @@ pub extern "win64" fn allocate_pool(
246246}
247247
248248pub 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 )
250250}
251251
252252pub extern "win64" fn create_event (
@@ -597,7 +597,7 @@ fn populate_allocator(image_address: u64, image_size: u64) {
597597
598598 for entry in e820_table {
599599 if entry. entry_type == E820_RAM {
600- ALLOCATOR . lock ( ) . add_initial_allocation (
600+ ALLOCATOR . borrow_mut ( ) . add_initial_allocation (
601601 MemoryType :: ConventionalMemory ,
602602 entry. size / PAGE_SIZE ,
603603 entry. addr ,
@@ -607,15 +607,15 @@ fn populate_allocator(image_address: u64, image_size: u64) {
607607 }
608608
609609 // Add ourselves
610- ALLOCATOR . lock ( ) . allocate_pages (
610+ ALLOCATOR . borrow_mut ( ) . allocate_pages (
611611 AllocateType :: AllocateAddress ,
612612 MemoryType :: RuntimeServicesCode ,
613613 1024 * 1024 / PAGE_SIZE ,
614614 1024 * 1024 ,
615615 ) ;
616616
617617 // Add the loaded binary
618- ALLOCATOR . lock ( ) . allocate_pages (
618+ ALLOCATOR . borrow_mut ( ) . allocate_pages (
619619 AllocateType :: AllocateAddress ,
620620 MemoryType :: LoaderCode ,
621621 image_size / PAGE_SIZE ,
0 commit comments