base: simplify SharedMemory::try_clone()

Use the SafeDescriptor try_clone() function rather than reimplementing
it in a roundabout way.

BUG=b:242953353
TEST=tools/dev_container tools/presubmit

Change-Id: Ic75ba06073eb964706b32701f0ed0184a6148bcf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5671239
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2024-07-01 13:07:46 -07:00 committed by crosvm LUCI
parent 458a5603c0
commit 64841ed4dc

View file

@ -57,8 +57,10 @@ impl SharedMemory {
/// Clones the SharedMemory. The new SharedMemory will refer to the same
/// underlying object as the original.
pub fn try_clone(&self) -> Result<SharedMemory> {
let shmem_descriptor = SafeDescriptor::try_from(self as &dyn AsRawDescriptor)?;
SharedMemory::from_safe_descriptor(shmem_descriptor, self.size())
Ok(SharedMemory {
descriptor: self.descriptor.try_clone()?,
size: self.size,
})
}
}