From 64841ed4dcdddc8d7eb482b3a98925493db23583 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 1 Jul 2024 13:07:46 -0700 Subject: [PATCH] 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 Commit-Queue: Daniel Verkamp --- base/src/shm.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/src/shm.rs b/base/src/shm.rs index 96284f37c5..92d7775e3a 100644 --- a/base/src/shm.rs +++ b/base/src/shm.rs @@ -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 { - 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, + }) } }