@@ -218,7 +218,8 @@ pub unsafe fn free_pages(ptr: NonNull<u8>, count: usize) -> Result {
218
218
unsafe { ( bt. free_pages ) ( addr, count) } . to_result ( )
219
219
}
220
220
221
- /// Allocates from a memory pool. The pointer will be 8-byte aligned.
221
+ /// Allocates a consecutive region of bytes using the UEFI allocator. The buffer
222
+ /// will be 8-byte aligned.
222
223
///
223
224
/// The caller is responsible to free the memory using [`free_pool`].
224
225
///
@@ -250,15 +251,20 @@ pub unsafe fn free_pages(ptr: NonNull<u8>, count: usize) -> Result {
250
251
/// * [`Status::OUT_OF_RESOURCES`]: allocation failed.
251
252
/// * [`Status::INVALID_PARAMETER`]: `mem_ty` is [`MemoryType::PERSISTENT_MEMORY`],
252
253
/// [`MemoryType::UNACCEPTED`], or in the range [`MemoryType::MAX`]`..=0x6fff_ffff`.
253
- pub fn allocate_pool ( mem_ty : MemoryType , size : usize ) -> Result < NonNull < u8 > > {
254
+ pub fn allocate_pool ( memory_type : MemoryType , size : usize ) -> Result < NonNull < [ u8 ] > > {
254
255
let bt = boot_services_raw_panicking ( ) ;
255
256
let bt = unsafe { bt. as_ref ( ) } ;
256
257
257
258
let mut buffer = ptr:: null_mut ( ) ;
258
259
let ptr =
259
- unsafe { ( bt. allocate_pool ) ( mem_ty , size, & mut buffer) } . to_result_with_val ( || buffer) ?;
260
+ unsafe { ( bt. allocate_pool ) ( memory_type , size, & mut buffer) } . to_result_with_val ( || buffer) ?;
260
261
261
- Ok ( NonNull :: new ( ptr) . expect ( "allocate_pool must not return a null pointer if successful" ) )
262
+ if let Some ( ptr) = NonNull :: new ( ptr) {
263
+ let slice = NonNull :: slice_from_raw_parts ( ptr, size) ;
264
+ Ok ( slice)
265
+ } else {
266
+ Err ( Status :: OUT_OF_RESOURCES . into ( ) )
267
+ }
262
268
}
263
269
264
270
/// Frees memory allocated by [`allocate_pool`].
0 commit comments