@@ -438,6 +438,16 @@ impl<B> Drop for MmapRegion<B> {
438438 }
439439}
440440
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+
441451/// [`GuestMemoryRegion`](trait.GuestMemoryRegion.html) implementation that mmaps the guest's
442452/// memory region in the current process.
443453///
@@ -480,15 +490,14 @@ impl<B: NewBitmap> GuestRegionMmap<B> {
480490 addr : GuestAddress ,
481491 size : usize ,
482492 file : Option < FileOffset > ,
483- ) -> result:: Result < Self , GuestRegionError > {
493+ ) -> result:: Result < Self , GuestMemoryMmapError > {
484494 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) ?
486496 } else {
487- MmapRegion :: new ( size)
488- }
489- . map_err ( GuestRegionError :: MmapRegion ) ?;
497+ MmapRegion :: new ( size) ?
498+ } ;
490499
491- Self :: new ( region, addr)
500+ Ok ( Self :: new ( region, addr) ? )
492501 }
493502}
494503
@@ -550,15 +559,17 @@ impl<B: NewBitmap> GuestMemoryMmap<B> {
550559 /// Creates a container and allocates anonymous memory for guest memory regions.
551560 ///
552561 /// 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 > {
554565 Self :: from_ranges_with_files ( ranges. iter ( ) . map ( |r| ( r. 0 , r. 1 , None ) ) )
555566 }
556567
557568 /// Creates a container and allocates anonymous memory for guest memory regions.
558569 ///
559570 /// Valid memory regions are specified as a sequence of (Address, Size, [`Option<FileOffset>`])
560571 /// 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 >
562573 where
563574 A : Borrow < ( GuestAddress , usize , Option < FileOffset > ) > ,
564575 T : IntoIterator < Item = A > ,
@@ -571,6 +582,7 @@ impl<B: NewBitmap> GuestMemoryMmap<B> {
571582 } )
572583 . collect :: < result:: Result < Vec < _ > , _ > > ( ) ?,
573584 )
585+ . map_err ( GuestMemoryMmapError :: GuestRegion )
574586 }
575587}
576588
0 commit comments