File tree 4 files changed +4
-46
lines changed
4 files changed +4
-46
lines changed Original file line number Diff line number Diff line change 5
5
### Added
6
6
7
7
- \[ [ #311 ] ( https://github.com/rust-vmm/vm-memory/pull/311 ) \] Allow compiling without the ReadVolatile and WriteVolatile implementations
8
+ - \[ [ #319 ] ( https://github.com/rust-vmm/vm-memory/pull/319 ) \] Allow constructing ` MmapRegion ` s
9
+ mapping file descriptors that cannot be seeked, such as ` guest_memfd ` .
8
10
9
11
### Changed
10
12
Original file line number Diff line number Diff line change 13
13
//! This implementation is mmap-ing the memory of the guest into the current process.
14
14
15
15
use std:: borrow:: Borrow ;
16
- #[ cfg( unix) ]
17
- use std:: io:: { Seek , SeekFrom } ;
18
16
use std:: ops:: Deref ;
19
17
use std:: result;
20
18
use std:: sync:: atomic:: Ordering ;
@@ -70,34 +68,6 @@ pub enum Error {
70
68
UnsortedMemoryRegions ,
71
69
}
72
70
73
- // TODO: use this for Windows as well after we redefine the Error type there.
74
- #[ cfg( unix) ]
75
- /// Checks if a mapping of `size` bytes fits at the provided `file_offset`.
76
- ///
77
- /// For a borrowed `FileOffset` and size, this function checks whether the mapping does not
78
- /// extend past EOF, and that adding the size to the file offset does not lead to overflow.
79
- pub fn check_file_offset (
80
- file_offset : & FileOffset ,
81
- size : usize ,
82
- ) -> result:: Result < ( ) , MmapRegionError > {
83
- let mut file = file_offset. file ( ) ;
84
- let start = file_offset. start ( ) ;
85
-
86
- if let Some ( end) = start. checked_add ( size as u64 ) {
87
- let filesize = file
88
- . seek ( SeekFrom :: End ( 0 ) )
89
- . map_err ( MmapRegionError :: SeekEnd ) ?;
90
- file. rewind ( ) . map_err ( MmapRegionError :: SeekStart ) ?;
91
- if filesize < end {
92
- return Err ( MmapRegionError :: MappingPastEof ) ;
93
- }
94
- } else {
95
- return Err ( MmapRegionError :: InvalidOffsetLength ) ;
96
- }
97
-
98
- Ok ( ( ) )
99
- }
100
-
101
71
/// [`GuestMemoryRegion`](trait.GuestMemoryRegion.html) implementation that mmaps the guest's
102
72
/// memory region in the current process.
103
73
///
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ use std::result;
17
17
18
18
use crate :: bitmap:: { Bitmap , BS } ;
19
19
use crate :: guest_memory:: FileOffset ;
20
- use crate :: mmap:: { check_file_offset , NewBitmap } ;
20
+ use crate :: mmap:: NewBitmap ;
21
21
use crate :: volatile_memory:: { self , VolatileMemory , VolatileSlice } ;
22
22
23
23
/// Error conditions that may arise when creating a new `MmapRegion` object.
@@ -41,12 +41,6 @@ pub enum Error {
41
41
/// The `mmap` call returned an error.
42
42
#[ error( "{0}" ) ]
43
43
Mmap ( io:: Error ) ,
44
- /// Seeking the end of the file returned an error.
45
- #[ error( "Error seeking the end of the file: {0}" ) ]
46
- SeekEnd ( io:: Error ) ,
47
- /// Seeking the start of the file returned an error.
48
- #[ error( "Error seeking the start of the file: {0}" ) ]
49
- SeekStart ( io:: Error ) ,
50
44
}
51
45
52
46
pub type Result < T > = result:: Result < T , Error > ;
@@ -137,7 +131,6 @@ impl<B: Bitmap> MmapRegionBuilder<B> {
137
131
}
138
132
139
133
let ( fd, offset) = if let Some ( ref f_off) = self . file_offset {
140
- check_file_offset ( f_off, self . size ) ?;
141
134
( f_off. file ( ) . as_raw_fd ( ) , f_off. start ( ) )
142
135
} else {
143
136
( -1 , 0 )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ use tests::ioctl_with_ref;
26
26
27
27
use crate :: bitmap:: { Bitmap , BS } ;
28
28
use crate :: guest_memory:: { FileOffset , GuestAddress } ;
29
- use crate :: mmap:: { check_file_offset , NewBitmap } ;
29
+ use crate :: mmap:: NewBitmap ;
30
30
use crate :: volatile_memory:: { self , VolatileMemory , VolatileSlice } ;
31
31
32
32
/// Error conditions that may arise when creating a new `MmapRegion` object.
@@ -44,12 +44,6 @@ pub enum Error {
44
44
/// The `mmap` call returned an error.
45
45
#[ error( "{0}" ) ]
46
46
Mmap ( io:: Error ) ,
47
- /// Seeking the end of the file returned an error.
48
- #[ error( "Error seeking the end of the file: {0}" ) ]
49
- SeekEnd ( io:: Error ) ,
50
- /// Seeking the start of the file returned an error.
51
- #[ error( "Error seeking the start of the file: {0}" ) ]
52
- SeekStart ( io:: Error ) ,
53
47
/// Invalid file offset.
54
48
#[ error( "Invalid file offset" ) ]
55
49
InvalidFileOffset ,
@@ -524,7 +518,6 @@ struct MmapXenUnix(MmapUnix);
524
518
impl MmapXenUnix {
525
519
fn new ( range : & MmapRange ) -> Result < Self > {
526
520
let ( fd, offset) = if let Some ( ref f_off) = range. file_offset {
527
- check_file_offset ( f_off, range. size ) ?;
528
521
( f_off. file ( ) . as_raw_fd ( ) , f_off. start ( ) )
529
522
} else {
530
523
( -1 , 0 )
You can’t perform that action at this time.
0 commit comments