File tree Expand file tree Collapse file tree 5 files changed +15
-6
lines changed
uefi-test-runner/src/boot Expand file tree Collapse file tree 5 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,8 @@ fn test_install_protocol_interface(bt: &BootServices) {
121121 mem:: size_of :: < TestProtocol > ( ) ,
122122 )
123123 . unwrap ( )
124- . cast ( ) ;
124+ . cast ( )
125+ . as_ptr ( ) ;
125126 unsafe { alloc. write ( TestProtocol { data : 123 } ) } ;
126127
127128 let _ = unsafe {
@@ -187,7 +188,8 @@ fn test_install_configuration_table(st: &SystemTable<Boot>) {
187188 let config = st
188189 . boot_services ( )
189190 . allocate_pool ( MemoryType :: ACPI_RECLAIM , 1 )
190- . expect ( "Failed to allocate config table" ) ;
191+ . expect ( "Failed to allocate config table" )
192+ . as_ptr ( ) ;
191193 unsafe { config. write ( 42 ) } ;
192194
193195 let count = st. config_table ( ) . len ( ) ;
Original file line number Diff line number Diff line change 1515## Changed
1616- ` SystemTable::exit_boot_services ` is now ` unsafe ` . See that method's
1717 documentation for details of obligations for callers.
18+ - ` BootServices::allocate_pool ` now returns ` NonZero<u8> ` instead of
19+ ` *mut u8 ` .
1820
1921## Removed
2022- Removed the ` panic-on-logger-errors ` feature of the ` uefi ` crate. Logger
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ unsafe impl GlobalAlloc for Allocator {
8686 // within the allocation.
8787 let full_alloc_ptr =
8888 if let Ok ( ptr) = boot_services. allocate_pool ( memory_type, size + align) {
89- ptr
89+ ptr. as_ptr ( )
9090 } else {
9191 return ptr:: null_mut ( ) ;
9292 } ;
@@ -116,6 +116,7 @@ unsafe impl GlobalAlloc for Allocator {
116116 // use `allocate_pool` directly.
117117 boot_services
118118 . allocate_pool ( memory_type, size)
119+ . map ( |ptr| ptr. as_ptr ( ) )
119120 . unwrap_or ( ptr:: null_mut ( ) )
120121 }
121122 }
Original file line number Diff line number Diff line change @@ -271,9 +271,13 @@ impl BootServices {
271271 ///
272272 /// * [`uefi::Status::OUT_OF_RESOURCES`]
273273 /// * [`uefi::Status::INVALID_PARAMETER`]
274- pub fn allocate_pool ( & self , mem_ty : MemoryType , size : usize ) -> Result < * mut u8 > {
274+ pub fn allocate_pool ( & self , mem_ty : MemoryType , size : usize ) -> Result < NonNull < u8 > > {
275275 let mut buffer = ptr:: null_mut ( ) ;
276- unsafe { ( self . 0 . allocate_pool ) ( mem_ty, size, & mut buffer) } . to_result_with_val ( || buffer)
276+ let ptr = unsafe { ( self . 0 . allocate_pool ) ( mem_ty, size, & mut buffer) }
277+ . to_result_with_val ( || buffer) ?;
278+
279+ Ok ( NonNull :: new ( ptr)
280+ . expect ( "UEFI should return error if an allocation failed but never a null pointer" ) )
277281 }
278282
279283 /// Frees memory allocated from a pool.
Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ impl SystemTable<Boot> {
265265 // Allocate a byte slice to hold the memory map. If the
266266 // allocation fails treat it as an unrecoverable error.
267267 let buf: * mut u8 = match boot_services. allocate_pool ( memory_type, buf_size) {
268- Ok ( buf) => buf,
268+ Ok ( buf) => buf. as_ptr ( ) ,
269269 Err ( err) => reset ( err. status ( ) ) ,
270270 } ;
271271
You can’t perform that action at this time.
0 commit comments