@@ -142,18 +142,9 @@ pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = GuestMemoryError> {
142
142
}
143
143
}
144
144
145
- /// Errors that can occur when dealing with [`GuestRegion `]s, or collections thereof
145
+ /// Errors that can occur when dealing with [`GuestRegionCollection `]s
146
146
#[ derive( Debug , thiserror:: Error ) ]
147
- pub enum GuestRegionError {
148
- /// Adding the guest base address to the length of the underlying mapping resulted
149
- /// in an overflow.
150
- #[ error( "Adding the guest base address to the length of the underlying mapping resulted in an overflow" ) ]
151
- #[ cfg( feature = "backend-mmap" ) ]
152
- InvalidGuestRegion ,
153
- /// Error creating a `MmapRegion` object.
154
- #[ error( "{0}" ) ]
155
- #[ cfg( feature = "backend-mmap" ) ]
156
- MmapRegion ( crate :: mmap:: MmapRegionError ) ,
147
+ pub enum GuestRegionCollectionError {
157
148
/// No memory region found.
158
149
#[ error( "No memory region found" ) ]
159
150
NoMemoryRegion ,
@@ -203,7 +194,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
203
194
/// * `regions` - The vector of regions.
204
195
/// The regions shouldn't overlap, and they should be sorted
205
196
/// by the starting address.
206
- pub fn from_regions ( mut regions : Vec < R > ) -> std:: result:: Result < Self , GuestRegionError > {
197
+ pub fn from_regions ( mut regions : Vec < R > ) -> std:: result:: Result < Self , GuestRegionCollectionError > {
207
198
Self :: from_arc_regions ( regions. drain ( ..) . map ( Arc :: new) . collect ( ) )
208
199
}
209
200
@@ -219,21 +210,21 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
219
210
/// * `regions` - The vector of `Arc` regions.
220
211
/// The regions shouldn't overlap and they should be sorted
221
212
/// by the starting address.
222
- pub fn from_arc_regions ( regions : Vec < Arc < R > > ) -> std:: result:: Result < Self , GuestRegionError > {
213
+ pub fn from_arc_regions ( regions : Vec < Arc < R > > ) -> std:: result:: Result < Self , GuestRegionCollectionError > {
223
214
if regions. is_empty ( ) {
224
- return Err ( GuestRegionError :: NoMemoryRegion ) ;
215
+ return Err ( GuestRegionCollectionError :: NoMemoryRegion ) ;
225
216
}
226
217
227
218
for window in regions. windows ( 2 ) {
228
219
let prev = & window[ 0 ] ;
229
220
let next = & window[ 1 ] ;
230
221
231
222
if prev. start_addr ( ) > next. start_addr ( ) {
232
- return Err ( GuestRegionError :: UnsortedMemoryRegions ) ;
223
+ return Err ( GuestRegionCollectionError :: UnsortedMemoryRegions ) ;
233
224
}
234
225
235
226
if prev. last_addr ( ) >= next. start_addr ( ) {
236
- return Err ( GuestRegionError :: MemoryRegionOverlap ) ;
227
+ return Err ( GuestRegionCollectionError :: MemoryRegionOverlap ) ;
237
228
}
238
229
}
239
230
@@ -247,7 +238,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
247
238
pub fn insert_region (
248
239
& self ,
249
240
region : Arc < R > ,
250
- ) -> std:: result:: Result < GuestRegionCollection < R > , GuestRegionError > {
241
+ ) -> std:: result:: Result < GuestRegionCollection < R > , GuestRegionCollectionError > {
251
242
let mut regions = self . regions . clone ( ) ;
252
243
regions. push ( region) ;
253
244
regions. sort_by_key ( |x| x. start_addr ( ) ) ;
@@ -265,7 +256,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
265
256
& self ,
266
257
base : GuestAddress ,
267
258
size : GuestUsize ,
268
- ) -> std:: result:: Result < ( GuestRegionCollection < R > , Arc < R > ) , GuestRegionError > {
259
+ ) -> std:: result:: Result < ( GuestRegionCollection < R > , Arc < R > ) , GuestRegionCollectionError > {
269
260
if let Ok ( region_index) = self . regions . binary_search_by_key ( & base, |x| x. start_addr ( ) ) {
270
261
if self . regions . get ( region_index) . unwrap ( ) . len ( ) == size {
271
262
let mut regions = self . regions . clone ( ) ;
@@ -274,7 +265,7 @@ impl<R: GuestMemoryRegion> GuestRegionCollection<R> {
274
265
}
275
266
}
276
267
277
- Err ( GuestRegionError :: NoMemoryRegion )
268
+ Err ( GuestRegionCollectionError :: NoMemoryRegion )
278
269
}
279
270
}
280
271
@@ -452,7 +443,7 @@ impl<R: GuestMemoryRegionBytes> Bytes<MemoryRegionAddress> for R {
452
443
453
444
#[ cfg( test) ]
454
445
pub ( crate ) mod tests {
455
- use crate :: region:: { GuestMemoryRegionBytes , GuestRegionError } ;
446
+ use crate :: region:: { GuestMemoryRegionBytes , GuestRegionCollectionError } ;
456
447
use crate :: {
457
448
Address , GuestAddress , GuestMemory , GuestMemoryRegion , GuestRegionCollection , GuestUsize ,
458
449
} ;
@@ -483,7 +474,7 @@ pub(crate) mod tests {
483
474
pub ( crate ) type Collection = GuestRegionCollection < MockRegion > ;
484
475
485
476
fn check_guest_memory_mmap (
486
- maybe_guest_mem : Result < Collection , GuestRegionError > ,
477
+ maybe_guest_mem : Result < Collection , GuestRegionCollectionError > ,
487
478
expected_regions_summary : & [ ( GuestAddress , u64 ) ] ,
488
479
) {
489
480
assert ! ( maybe_guest_mem. is_ok( ) ) ;
@@ -510,7 +501,7 @@ pub(crate) mod tests {
510
501
511
502
pub ( crate ) fn new_guest_memory_collection_from_regions (
512
503
regions_summary : & [ ( GuestAddress , u64 ) ] ,
513
- ) -> Result < Collection , GuestRegionError > {
504
+ ) -> Result < Collection , GuestRegionCollectionError > {
514
505
Collection :: from_regions (
515
506
regions_summary
516
507
. iter ( )
@@ -521,7 +512,7 @@ pub(crate) mod tests {
521
512
522
513
fn new_guest_memory_collection_from_arc_regions (
523
514
regions_summary : & [ ( GuestAddress , u64 ) ] ,
524
- ) -> Result < Collection , GuestRegionError > {
515
+ ) -> Result < Collection , GuestRegionCollectionError > {
525
516
Collection :: from_arc_regions (
526
517
regions_summary
527
518
. iter ( )
@@ -536,11 +527,11 @@ pub(crate) mod tests {
536
527
537
528
assert ! ( matches!(
538
529
new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
539
- GuestRegionError :: NoMemoryRegion
530
+ GuestRegionCollectionError :: NoMemoryRegion
540
531
) ) ;
541
532
assert ! ( matches!(
542
533
new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
543
- GuestRegionError :: NoMemoryRegion
534
+ GuestRegionCollectionError :: NoMemoryRegion
544
535
) ) ;
545
536
}
546
537
@@ -550,11 +541,11 @@ pub(crate) mod tests {
550
541
551
542
assert ! ( matches!(
552
543
new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
553
- GuestRegionError :: MemoryRegionOverlap
544
+ GuestRegionCollectionError :: MemoryRegionOverlap
554
545
) ) ;
555
546
assert ! ( matches!(
556
547
new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
557
- GuestRegionError :: MemoryRegionOverlap
548
+ GuestRegionCollectionError :: MemoryRegionOverlap
558
549
) ) ;
559
550
}
560
551
@@ -564,11 +555,11 @@ pub(crate) mod tests {
564
555
565
556
assert ! ( matches!(
566
557
new_guest_memory_collection_from_regions( & regions_summary) . unwrap_err( ) ,
567
- GuestRegionError :: UnsortedMemoryRegions
558
+ GuestRegionCollectionError :: UnsortedMemoryRegions
568
559
) ) ;
569
560
assert ! ( matches!(
570
561
new_guest_memory_collection_from_arc_regions( & regions_summary) . unwrap_err( ) ,
571
- GuestRegionError :: UnsortedMemoryRegions
562
+ GuestRegionCollectionError :: UnsortedMemoryRegions
572
563
) ) ;
573
564
}
574
565
0 commit comments