@@ -8,6 +8,7 @@ use super::Revision;
8
8
use crate :: data_types:: PhysicalAddress ;
9
9
use crate :: mem:: memory_map:: * ;
10
10
use crate :: proto:: device_path:: DevicePath ;
11
+ use crate :: proto:: device_path:: FfiDevicePath ;
11
12
use crate :: proto:: loaded_image:: LoadedImage ;
12
13
use crate :: proto:: media:: fs:: SimpleFileSystem ;
13
14
use crate :: proto:: { BootPolicy , Protocol , ProtocolPointer } ;
@@ -841,29 +842,7 @@ impl BootServices {
841
842
parent_image_handle : Handle ,
842
843
source : LoadImageSource ,
843
844
) -> 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 ( ) ;
867
846
868
847
let mut image_handle = ptr:: null_mut ( ) ;
869
848
unsafe {
@@ -1422,6 +1401,44 @@ pub enum LoadImageSource<'a> {
1422
1401
} ,
1423
1402
}
1424
1403
1404
+ impl < ' a > LoadImageSource < ' a > {
1405
+ /// Returns the raw FFI parameters for `load_image`.
1406
+ #[ must_use]
1407
+ pub ( crate ) fn to_ffi_params (
1408
+ & self ,
1409
+ ) -> (
1410
+ BootPolicy ,
1411
+ * const FfiDevicePath ,
1412
+ * const u8 , /* buffer */
1413
+ usize , /* buffer length */
1414
+ ) {
1415
+ let boot_policy;
1416
+ let device_path;
1417
+ let source_buffer;
1418
+ let source_size;
1419
+ match self {
1420
+ LoadImageSource :: FromBuffer { buffer, file_path } => {
1421
+ // Boot policy is ignored when loading from source buffer.
1422
+ boot_policy = BootPolicy :: ExactMatch ;
1423
+
1424
+ device_path = file_path. map ( |p| p. as_ffi_ptr ( ) ) . unwrap_or ( ptr:: null ( ) ) ;
1425
+ source_buffer = buffer. as_ptr ( ) ;
1426
+ source_size = buffer. len ( ) ;
1427
+ }
1428
+ LoadImageSource :: FromDevicePath {
1429
+ device_path : d_path,
1430
+ boot_policy : b_policy,
1431
+ } => {
1432
+ boot_policy = * b_policy;
1433
+ device_path = d_path. as_ffi_ptr ( ) ;
1434
+ source_buffer = ptr:: null ( ) ;
1435
+ source_size = 0 ;
1436
+ }
1437
+ } ;
1438
+ ( boot_policy, device_path, source_buffer, source_size)
1439
+ }
1440
+ }
1441
+
1425
1442
/// RAII guard for task priority level changes
1426
1443
///
1427
1444
/// Will automatically restore the former task priority level when dropped.
0 commit comments