@@ -8,6 +8,7 @@ use super::Revision;
88use crate :: data_types:: PhysicalAddress ;
99use crate :: mem:: memory_map:: * ;
1010use crate :: proto:: device_path:: DevicePath ;
11+ use crate :: proto:: device_path:: FfiDevicePath ;
1112use crate :: proto:: loaded_image:: LoadedImage ;
1213use crate :: proto:: media:: fs:: SimpleFileSystem ;
1314use crate :: proto:: { BootPolicy , Protocol , ProtocolPointer } ;
@@ -841,29 +842,7 @@ impl BootServices {
841842 parent_image_handle : Handle ,
842843 source : LoadImageSource ,
843844 ) -> uefi:: Result < Handle > {
844- let boot_policy;
845- let device_path;
846- let source_buffer;
847- let source_size;
848- match source {
849- LoadImageSource :: FromBuffer { buffer, file_path } => {
850- // Boot policy is ignored when loading from source buffer.
851- boot_policy = BootPolicy :: ExactMatch ;
852-
853- device_path = file_path. map ( |p| p. as_ffi_ptr ( ) ) . unwrap_or ( ptr:: null ( ) ) ;
854- source_buffer = buffer. as_ptr ( ) ;
855- source_size = buffer. len ( ) ;
856- }
857- LoadImageSource :: FromDevicePath {
858- device_path : file_path,
859- boot_policy : new_boot_policy,
860- } => {
861- boot_policy = new_boot_policy;
862- device_path = file_path. as_ffi_ptr ( ) ;
863- source_buffer = ptr:: null ( ) ;
864- source_size = 0 ;
865- }
866- } ;
845+ let ( boot_policy, device_path, source_buffer, source_size) = source. to_ffi_params ( ) ;
867846
868847 let mut image_handle = ptr:: null_mut ( ) ;
869848 unsafe {
@@ -1424,6 +1403,44 @@ pub enum LoadImageSource<'a> {
14241403 } ,
14251404}
14261405
1406+ impl < ' a > LoadImageSource < ' a > {
1407+ /// Returns the raw FFI parameters for `load_image`.
1408+ #[ must_use]
1409+ pub ( crate ) fn to_ffi_params (
1410+ & self ,
1411+ ) -> (
1412+ BootPolicy ,
1413+ * const FfiDevicePath ,
1414+ * const u8 , /* buffer */
1415+ usize , /* buffer length */
1416+ ) {
1417+ let boot_policy;
1418+ let device_path;
1419+ let source_buffer;
1420+ let source_size;
1421+ match self {
1422+ LoadImageSource :: FromBuffer { buffer, file_path } => {
1423+ // Boot policy is ignored when loading from source buffer.
1424+ boot_policy = BootPolicy :: ExactMatch ;
1425+
1426+ device_path = file_path. map ( |p| p. as_ffi_ptr ( ) ) . unwrap_or ( ptr:: null ( ) ) ;
1427+ source_buffer = buffer. as_ptr ( ) ;
1428+ source_size = buffer. len ( ) ;
1429+ }
1430+ LoadImageSource :: FromDevicePath {
1431+ device_path : d_path,
1432+ boot_policy : b_policy,
1433+ } => {
1434+ boot_policy = * b_policy;
1435+ device_path = d_path. as_ffi_ptr ( ) ;
1436+ source_buffer = ptr:: null ( ) ;
1437+ source_size = 0 ;
1438+ }
1439+ } ;
1440+ ( boot_policy, device_path, source_buffer, source_size)
1441+ }
1442+ }
1443+
14271444/// RAII guard for task priority level changes
14281445///
14291446/// Will automatically restore the former task priority level when dropped.
0 commit comments