Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- \[[#311](https://github.com/rust-vmm/vm-memory/pull/311)\] Allow compiling without the ReadVolatile and WriteVolatile implementations
- \[[#312](https://github.com/rust-vmm/vm-memory/pull/312)\] `GuestRegionContainer`, a generic container of `GuestMemoryRegion`s, generalizing `GuestMemoryMmap` (which
is now a type alias for `GuestRegionContainer<GuestRegionMmap>`).
- \[[#338](https://github.com/rust-vmm/vm-memory/pull/338)\] Make `GuestMemoryAtomic` always implement `Clone`.
- \[[#338](https://github.com/rust-vmm/vm-memory/pull/338)\] Make `GuestAddressSpace` a subtrait of `Clone`.

### Changed

Expand Down
19 changes: 18 additions & 1 deletion src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{GuestAddressSpace, GuestMemory};
/// readers will not be blocked because the copies they retrieved will be collected once
/// no one can access them anymore. Under the assumption that updates to the memory map
/// are rare, this allows a very efficient implementation of the `memory()` method.
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct GuestMemoryAtomic<M: GuestMemory> {
// GuestAddressSpace<M>, which we want to implement, is basically a drop-in
// replacement for &M. Therefore, we need to pass to devices the `GuestMemoryAtomic`
Expand Down Expand Up @@ -75,6 +75,14 @@ impl<M: GuestMemory> GuestMemoryAtomic<M> {
}
}

impl<M: GuestMemory> Clone for GuestMemoryAtomic<M> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}

impl<M: GuestMemory> GuestAddressSpace for GuestMemoryAtomic<M> {
type T = GuestMemoryLoadGuard<M>;
type M = M;
Expand Down Expand Up @@ -196,6 +204,15 @@ mod tests {
assert_eq!(mem3.num_regions(), 2);
assert!(mem3.find_region(GuestAddress(0x1000)).is_some());
assert!(mem3.find_region(GuestAddress(0x10000)).is_none());

let gm2 = gm.clone();
let mem4 = gm2.memory();
for region in mem4.iter() {
assert_eq!(region.len(), region_size as GuestUsize);
}
assert_eq!(mem4.num_regions(), 2);
assert!(mem4.find_region(GuestAddress(0x1000)).is_some());
assert!(mem4.find_region(GuestAddress(0x10000)).is_none());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/guest_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl FileOffset {
/// # }
/// # }
/// ```
pub trait GuestAddressSpace {
pub trait GuestAddressSpace: Clone {
/// The type that will be used to access guest memory.
type M: GuestMemory;

Expand Down