@@ -438,6 +438,16 @@ impl<B> Drop for MmapRegion<B> {
438
438
}
439
439
}
440
440
441
+ #[ derive( Debug , thiserror:: Error ) ]
442
+ pub enum GuestMemoryMmapError {
443
+ /// Error creating a `MmapRegion` object.
444
+ #[ error( "{0}" ) ]
445
+ MmapRegion ( #[ from] Error ) ,
446
+ /// Error when calling [`GuestRegionCollection`] APIs
447
+ #[ error( "{0}" ) ]
448
+ GuestRegion ( #[ from] GuestRegionError ) ,
449
+ }
450
+
441
451
/// [`GuestMemoryRegion`](trait.GuestMemoryRegion.html) implementation that mmaps the guest's
442
452
/// memory region in the current process.
443
453
///
@@ -480,15 +490,14 @@ impl<B: NewBitmap> GuestRegionMmap<B> {
480
490
addr : GuestAddress ,
481
491
size : usize ,
482
492
file : Option < FileOffset > ,
483
- ) -> result:: Result < Self , GuestRegionError > {
493
+ ) -> result:: Result < Self , GuestMemoryMmapError > {
484
494
let region = if let Some ( ref f_off) = file {
485
- MmapRegion :: from_file ( f_off. clone ( ) , size)
495
+ MmapRegion :: from_file ( f_off. clone ( ) , size) ?
486
496
} else {
487
- MmapRegion :: new ( size)
488
- }
489
- . map_err ( GuestRegionError :: MmapRegion ) ?;
497
+ MmapRegion :: new ( size) ?
498
+ } ;
490
499
491
- Self :: new ( region, addr)
500
+ Ok ( Self :: new ( region, addr) ? )
492
501
}
493
502
}
494
503
@@ -550,15 +559,17 @@ impl<B: NewBitmap> GuestMemoryMmap<B> {
550
559
/// Creates a container and allocates anonymous memory for guest memory regions.
551
560
///
552
561
/// Valid memory regions are specified as a slice of (Address, Size) tuples sorted by Address.
553
- pub fn from_ranges ( ranges : & [ ( GuestAddress , usize ) ] ) -> result:: Result < Self , GuestRegionError > {
562
+ pub fn from_ranges (
563
+ ranges : & [ ( GuestAddress , usize ) ] ,
564
+ ) -> result:: Result < Self , GuestMemoryMmapError > {
554
565
Self :: from_ranges_with_files ( ranges. iter ( ) . map ( |r| ( r. 0 , r. 1 , None ) ) )
555
566
}
556
567
557
568
/// Creates a container and allocates anonymous memory for guest memory regions.
558
569
///
559
570
/// Valid memory regions are specified as a sequence of (Address, Size, [`Option<FileOffset>`])
560
571
/// tuples sorted by Address.
561
- pub fn from_ranges_with_files < A , T > ( ranges : T ) -> result:: Result < Self , GuestRegionError >
572
+ pub fn from_ranges_with_files < A , T > ( ranges : T ) -> result:: Result < Self , GuestMemoryMmapError >
562
573
where
563
574
A : Borrow < ( GuestAddress , usize , Option < FileOffset > ) > ,
564
575
T : IntoIterator < Item = A > ,
@@ -571,6 +582,7 @@ impl<B: NewBitmap> GuestMemoryMmap<B> {
571
582
} )
572
583
. collect :: < result:: Result < Vec < _ > , _ > > ( ) ?,
573
584
)
585
+ . map_err ( GuestMemoryMmapError :: GuestRegion )
574
586
}
575
587
}
576
588
0 commit comments