From 0aacc50fd25d61ae1274d6054550f45acaa50897 Mon Sep 17 00:00:00 2001 From: Steven Richman Date: Mon, 11 May 2020 13:27:03 -0700 Subject: hypervisor: add KvmVm new and try_clone Vms and Vcpus will be try_cloneable and Send, so we can configure on vcpu threads and so IrqChips can reference all Vcpus. To support cloning, collection fields in Vm have been moved into arc mutexes, and Vm and Vcpu are now Sized. Because this breaks object safety, all usage of the traits will be via static binding. Add impl AsRawFd for SafeDescriptor, to get the sys_util ioctl functions working with SafeDescriptor; eventually the functions will change to take SafeDescriptors. Copy set_user_memory_region helper from kvm crate. BUG=chromium:1077058 TEST=cargo test -p hypervisor Change-Id: I23de47c4472a77632006d0d45de9754394b400c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197337 Reviewed-by: Udam Saini Reviewed-by: Zach Reizner Tested-by: kokoro Commit-Queue: Steven Richman --- sys_util/src/descriptor.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sys_util') diff --git a/sys_util/src/descriptor.rs b/sys_util/src/descriptor.rs index 1af72fc..9082394 100644 --- a/sys_util/src/descriptor.rs +++ b/sys_util/src/descriptor.rs @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use std::os::unix::io::RawFd; - -use crate::{errno_result, Result}; use std::mem; use std::ops::Drop; +use std::os::unix::io::{AsRawFd, RawFd}; + +use crate::{errno_result, Result}; pub type RawDescriptor = RawFd; @@ -60,6 +60,12 @@ impl FromRawDescriptor for SafeDescriptor { } } +impl AsRawFd for SafeDescriptor { + fn as_raw_fd(&self) -> RawFd { + self.as_raw_descriptor() + } +} + impl SafeDescriptor { /// Clones this descriptor, internally creating a new descriptor. The new SafeDescriptor will /// share the same underlying count within the kernel. -- cgit 1.4.1