@@ -75,12 +75,12 @@ pub struct BootServices {
75
75
proto : * const Guid ,
76
76
key : * mut c_void ,
77
77
buf_sz : & mut usize ,
78
- buf : * mut Handle ,
78
+ buf : * mut MaybeUninit < Handle > ,
79
79
) -> Status ,
80
80
locate_device_path : unsafe extern "efiapi" fn (
81
81
proto : & Guid ,
82
82
device_path : & mut & DevicePath ,
83
- out_handle : * mut Handle ,
83
+ out_handle : & mut MaybeUninit < Handle > ,
84
84
) -> Status ,
85
85
install_configuration_table : usize ,
86
86
@@ -91,7 +91,7 @@ pub struct BootServices {
91
91
device_path : * const DevicePath ,
92
92
source_buffer : * const u8 ,
93
93
source_size : usize ,
94
- * mut Handle ,
94
+ image_handle : & mut MaybeUninit < Handle > ,
95
95
) -> Status ,
96
96
start_image : unsafe extern "efiapi" fn (
97
97
image_handle : Handle ,
@@ -502,11 +502,11 @@ impl BootServices {
502
502
pub fn locate_handle (
503
503
& self ,
504
504
search_ty : SearchType ,
505
- output : Option < & mut [ Handle ] > ,
505
+ output : Option < & mut [ MaybeUninit < Handle > ] > ,
506
506
) -> Result < usize > {
507
507
let handle_size = mem:: size_of :: < Handle > ( ) ;
508
508
509
- const NULL_BUFFER : * mut Handle = ptr:: null_mut ( ) ;
509
+ const NULL_BUFFER : * mut MaybeUninit < Handle > = ptr:: null_mut ( ) ;
510
510
511
511
let ( mut buffer_size, buffer) = match output {
512
512
Some ( buffer) => ( buffer. len ( ) * handle_size, buffer. as_mut_ptr ( ) ) ,
@@ -541,9 +541,10 @@ impl BootServices {
541
541
/// protocol, the `device_path` is advanced to the device path terminator node. If `device_path`
542
542
/// is a multi-instance device path, the function will operate on the first instance.
543
543
pub fn locate_device_path < P : Protocol > ( & self , device_path : & mut & DevicePath ) -> Result < Handle > {
544
+ let mut handle = MaybeUninit :: uninit ( ) ;
544
545
unsafe {
545
- let mut handle = Handle :: uninitialized ( ) ;
546
- ( self . locate_device_path ) ( & P :: GUID , device_path , & mut handle ) . into_with_val ( || handle)
546
+ ( self . locate_device_path ) ( & P :: GUID , device_path , & mut handle)
547
+ . into_with_val ( || handle. assume_init ( ) )
547
548
}
548
549
}
549
550
@@ -553,11 +554,11 @@ impl BootServices {
553
554
parent_image_handle : Handle ,
554
555
source_buffer : & [ u8 ] ,
555
556
) -> Result < Handle > {
557
+ let boot_policy = 0 ;
558
+ let device_path = ptr:: null ( ) ;
559
+ let source_size = source_buffer. len ( ) ;
560
+ let mut image_handle = MaybeUninit :: uninit ( ) ;
556
561
unsafe {
557
- let boot_policy = 0 ;
558
- let device_path = ptr:: null ( ) ;
559
- let source_size = source_buffer. len ( ) ;
560
- let mut image_handle = Handle :: uninitialized ( ) ;
561
562
( self . load_image ) (
562
563
boot_policy,
563
564
parent_image_handle,
@@ -566,7 +567,7 @@ impl BootServices {
566
567
source_size,
567
568
& mut image_handle,
568
569
)
569
- . into_with_val ( || image_handle)
570
+ . into_with_val ( || image_handle. assume_init ( ) )
570
571
}
571
572
}
572
573
@@ -745,7 +746,7 @@ impl BootServices {
745
746
746
747
// Allocate a large enough buffer.
747
748
let mut buffer = Vec :: new ( ) ;
748
- buffer. resize_with ( buffer_size, || unsafe { Handle :: uninitialized ( ) } ) ;
749
+ buffer. resize_with ( buffer_size, MaybeUninit :: uninit ) ;
749
750
750
751
// Perform the search.
751
752
let ( status2, buffer_size) = self . locate_handle ( search_type, Some ( & mut buffer) ) ?. split ( ) ;
@@ -759,9 +760,19 @@ impl BootServices {
759
760
// `Status::BUFFER_TOO_SMALL` and `buffer` will be dropped.
760
761
buffer. truncate ( buffer_size) ;
761
762
763
+ // Convert the buffer from MaybeUninits to Handles.
764
+ // The raw parts roundtrip with a pointer cast is better than just
765
+ // transmuting vectors per mem::transmute docs.
766
+ // Transmuting MaybeUninit<T> to T is also correct, if we are sure that
767
+ // it is initialized, which it is, unless UEFI is broken
768
+ let handles = unsafe {
769
+ let ( ptr, len, cap) = buffer. into_raw_parts ( ) ;
770
+ Vec :: from_raw_parts ( ptr as * mut Handle , len, cap)
771
+ } ;
772
+
762
773
// Emit output, with warnings
763
774
status1
764
- . into_with_val ( || buffer )
775
+ . into_with_val ( || handles )
765
776
. map ( |completion| completion. with_status ( status2) )
766
777
}
767
778
0 commit comments