File tree 5 files changed +15
-6
lines changed
uefi-test-runner/src/boot
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) {
121
121
mem:: size_of :: < TestProtocol > ( ) ,
122
122
)
123
123
. unwrap ( )
124
- . cast ( ) ;
124
+ . cast ( )
125
+ . as_ptr ( ) ;
125
126
unsafe { alloc. write ( TestProtocol { data : 123 } ) } ;
126
127
127
128
let _ = unsafe {
@@ -187,7 +188,8 @@ fn test_install_configuration_table(st: &SystemTable<Boot>) {
187
188
let config = st
188
189
. boot_services ( )
189
190
. allocate_pool ( MemoryType :: ACPI_RECLAIM , 1 )
190
- . expect ( "Failed to allocate config table" ) ;
191
+ . expect ( "Failed to allocate config table" )
192
+ . as_ptr ( ) ;
191
193
unsafe { config. write ( 42 ) } ;
192
194
193
195
let count = st. config_table ( ) . len ( ) ;
Original file line number Diff line number Diff line change 15
15
## Changed
16
16
- ` SystemTable::exit_boot_services ` is now ` unsafe ` . See that method's
17
17
documentation for details of obligations for callers.
18
+ - ` BootServices::allocate_pool ` now returns ` NonZero<u8> ` instead of
19
+ ` *mut u8 ` .
18
20
19
21
## Removed
20
22
- 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 {
86
86
// within the allocation.
87
87
let full_alloc_ptr =
88
88
if let Ok ( ptr) = boot_services. allocate_pool ( memory_type, size + align) {
89
- ptr
89
+ ptr. as_ptr ( )
90
90
} else {
91
91
return ptr:: null_mut ( ) ;
92
92
} ;
@@ -116,6 +116,7 @@ unsafe impl GlobalAlloc for Allocator {
116
116
// use `allocate_pool` directly.
117
117
boot_services
118
118
. allocate_pool ( memory_type, size)
119
+ . map ( |ptr| ptr. as_ptr ( ) )
119
120
. unwrap_or ( ptr:: null_mut ( ) )
120
121
}
121
122
}
Original file line number Diff line number Diff line change @@ -271,9 +271,13 @@ impl BootServices {
271
271
///
272
272
/// * [`uefi::Status::OUT_OF_RESOURCES`]
273
273
/// * [`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 > > {
275
275
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" ) )
277
281
}
278
282
279
283
/// Frees memory allocated from a pool.
Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ impl SystemTable<Boot> {
265
265
// Allocate a byte slice to hold the memory map. If the
266
266
// allocation fails treat it as an unrecoverable error.
267
267
let buf: * mut u8 = match boot_services. allocate_pool ( memory_type, buf_size) {
268
- Ok ( buf) => buf,
268
+ Ok ( buf) => buf. as_ptr ( ) ,
269
269
Err ( err) => reset ( err. status ( ) ) ,
270
270
} ;
271
271
You can’t perform that action at this time.
0 commit comments