@@ -218,7 +218,8 @@ pub unsafe fn free_pages(ptr: NonNull<u8>, count: usize) -> Result {
218218 unsafe { ( bt. free_pages ) ( addr, count) } . to_result ( )
219219}
220220
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.
222223///
223224/// The caller is responsible to free the memory using [`free_pool`].
224225///
@@ -250,15 +251,20 @@ pub unsafe fn free_pages(ptr: NonNull<u8>, count: usize) -> Result {
250251/// * [`Status::OUT_OF_RESOURCES`]: allocation failed.
251252/// * [`Status::INVALID_PARAMETER`]: `mem_ty` is [`MemoryType::PERSISTENT_MEMORY`],
252253/// [`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 ] > > {
254255 let bt = boot_services_raw_panicking ( ) ;
255256 let bt = unsafe { bt. as_ref ( ) } ;
256257
257258 let mut buffer = ptr:: null_mut ( ) ;
258259 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) ?;
260261
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+ }
262268}
263269
264270/// Frees memory allocated by [`allocate_pool`].
0 commit comments