mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
Move os independent files under a new crate sys_util_core
sys_util_core won't have OS specific features so that sys_util and win_sys_util can depend on it. Test: Presubmit Bug: b:213149154 Upstream-Crate: common/win_sys_util Cq-Depend: chromium:3433709 Change-Id: I863f7a6bc7549944b4d114cca6d7be04c3093fc3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3426380 Reviewed-by: Dennis Kempin <denniskempin@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
9503e86ff4
commit
323006cf82
16 changed files with 63 additions and 17 deletions
|
@ -71,6 +71,7 @@ exclude = [
|
|||
"common/assertions",
|
||||
"common/audio_streams",
|
||||
"common/base",
|
||||
"common/sys_util_core",
|
||||
"common/cros-fuzz",
|
||||
"common/cros_async",
|
||||
"common/cros_asyncv2",
|
||||
|
@ -172,6 +173,7 @@ base = "*"
|
|||
assertions = { path = "common/assertions" }
|
||||
audio_streams = { path = "common/audio_streams" }
|
||||
base = { path = "common/base" }
|
||||
sys_util_core = { path = "common/sys_util_core" }
|
||||
cros_async = { path = "common/cros_async" }
|
||||
cros_fuzz = { path = "common/cros-fuzz" } # ignored by ebuild
|
||||
data_model = { path = "common/data_model" }
|
||||
|
|
|
@ -6,9 +6,10 @@ edition = "2018"
|
|||
include = ["src/**/*", "Cargo.toml"]
|
||||
|
||||
[dependencies]
|
||||
sys_util_core = { path = "../sys_util_core" } # provided by ebuild
|
||||
data_model = { path = "../data_model" } # provided by ebuild
|
||||
libc = "*"
|
||||
poll_token_derive = { version = "*", path = "poll_token_derive" }
|
||||
poll_token_derive = { path = "../sys_util_core/poll_token_derive" } # provided by ebuild
|
||||
remain = "0.2"
|
||||
thiserror = "*"
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
//! Small system utility modules for usage by other modules.
|
||||
|
||||
mod alloc;
|
||||
#[cfg(target_os = "android")]
|
||||
mod android;
|
||||
#[cfg(target_os = "android")]
|
||||
|
@ -26,7 +25,6 @@ mod descriptor;
|
|||
mod descriptor_reflection;
|
||||
mod errno;
|
||||
mod eventfd;
|
||||
mod external_mapping;
|
||||
mod file_flags;
|
||||
pub mod file_traits;
|
||||
mod fork;
|
||||
|
@ -53,13 +51,11 @@ pub mod vsock;
|
|||
mod write_zeroes;
|
||||
|
||||
pub use crate::acpi_event::*;
|
||||
pub use crate::alloc::LayoutAllocation;
|
||||
pub use crate::capabilities::drop_capabilities;
|
||||
pub use crate::clock::{Clock, FakeClock};
|
||||
pub use crate::descriptor::*;
|
||||
pub use crate::errno::{errno_result, Error, Result};
|
||||
pub use crate::eventfd::*;
|
||||
pub use crate::external_mapping::*;
|
||||
pub use crate::file_flags::*;
|
||||
pub use crate::fork::*;
|
||||
pub use crate::get_filesystem_type::*;
|
||||
|
@ -82,9 +78,8 @@ pub use descriptor_reflection::{
|
|||
SerializeDescriptors,
|
||||
};
|
||||
pub use poll_token_derive::*;
|
||||
pub use sys_util_core::*;
|
||||
|
||||
pub use crate::external_mapping::Error as ExternalMappingError;
|
||||
pub use crate::external_mapping::Result as ExternalMappingResult;
|
||||
pub use crate::file_traits::{
|
||||
AsRawFds, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen,
|
||||
FileSync,
|
||||
|
|
|
@ -13,6 +13,7 @@ use std::ptr::{copy_nonoverlapping, null_mut, read_unaligned, write_unaligned};
|
|||
|
||||
use libc::{self, c_int, c_void, read, write};
|
||||
use remain::sorted;
|
||||
use sys_util_core::ExternalMapping;
|
||||
|
||||
use data_model::volatile_memory::*;
|
||||
use data_model::DataInit;
|
||||
|
@ -170,6 +171,17 @@ impl dyn MappedRegion {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl MappedRegion for ExternalMapping {
|
||||
fn as_ptr(&self) -> *mut u8 {
|
||||
self.as_ptr()
|
||||
}
|
||||
|
||||
/// Returns the size of the memory region in bytes.
|
||||
fn size(&self) -> usize {
|
||||
self.size()
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps an anonymous shared memory mapping in the current process. Provides
|
||||
/// RAII semantics including munmap when no longer needed.
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -9,7 +9,9 @@ use std::os::unix::io::AsRawFd;
|
|||
use data_model::DataInit;
|
||||
use libc::EINVAL;
|
||||
|
||||
use crate::{errno_result, Error, FromRawDescriptor, LayoutAllocation, Result, SafeDescriptor};
|
||||
use sys_util_core::LayoutAllocation;
|
||||
|
||||
use crate::{errno_result, Error, FromRawDescriptor, Result, SafeDescriptor};
|
||||
|
||||
// Custom nlmsghdr struct that can be declared DataInit.
|
||||
#[repr(C)]
|
||||
|
|
0
common/sys_util_core/.windows_build_test_skip
Normal file
0
common/sys_util_core/.windows_build_test_skip
Normal file
13
common/sys_util_core/Cargo.toml
Normal file
13
common/sys_util_core/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "sys_util_core"
|
||||
version = "0.1.0"
|
||||
authors = ["The Chromium OS Authors"]
|
||||
edition = "2018"
|
||||
include = ["src/**/*", "Cargo.toml"]
|
||||
|
||||
[dependencies]
|
||||
libc = "*"
|
||||
remain = "0.2"
|
||||
thiserror = "*"
|
||||
|
||||
[workspace]
|
|
@ -13,3 +13,5 @@ path = "poll_token_derive.rs"
|
|||
proc-macro2 = "^1"
|
||||
quote = "^1"
|
||||
syn = "^1"
|
||||
|
||||
[workspace]
|
|
@ -2,8 +2,6 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::MappedRegion;
|
||||
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -70,16 +68,14 @@ impl ExternalMapping {
|
|||
unmap,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl MappedRegion for ExternalMapping {
|
||||
/// used for passing this region to ioctls for setting guest memory.
|
||||
fn as_ptr(&self) -> *mut u8 {
|
||||
pub fn as_ptr(&self) -> *mut u8 {
|
||||
self.ptr as *mut u8
|
||||
}
|
||||
|
||||
/// Returns the size of the memory region in bytes.
|
||||
fn size(&self) -> usize {
|
||||
pub fn size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
22
common/sys_util_core/src/lib.rs
Normal file
22
common/sys_util_core/src/lib.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2022 The Chromium OS Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
//! Small system utility modules for usage by other higher level system
|
||||
//! utility modules like sys_util(on unix/linux) and win_sys_util(on windows).
|
||||
//!
|
||||
//! Crates other than sys_util and win_sys_util should not depend directly on
|
||||
//! sys_util_core.
|
||||
//!
|
||||
//! sys_util_core contains system utilities that are strictly platform/os
|
||||
//! independent. Platform dependent, conditionally compiled, code should
|
||||
//! not be added to sys_util_core.
|
||||
//!
|
||||
|
||||
mod alloc;
|
||||
mod external_mapping;
|
||||
|
||||
pub use crate::alloc::LayoutAllocation;
|
||||
pub use crate::external_mapping::Error as ExternalMappingError;
|
||||
pub use crate::external_mapping::Result as ExternalMappingResult;
|
||||
pub use crate::external_mapping::*;
|
|
@ -32,6 +32,7 @@ class TestOption(enum.Enum):
|
|||
# Please add a bug number when restricting a tests.
|
||||
CRATE_OPTIONS: dict[str, list[TestOption]] = {
|
||||
"aarch64": [TestOption.BUILD_ARM_ONLY, TestOption.DO_NOT_BUILD_ARMHF], #b/210015864
|
||||
"sys_util_core": [TestOption.SINGLE_THREADED],
|
||||
"crosvm_plugin": [TestOption.BUILD_X86_ONLY],
|
||||
"devices": [TestOption.SINGLE_THREADED, TestOption.DO_NOT_BUILD_ARMHF],
|
||||
"disk": [TestOption.RUN_X86_ONLY], # b/202294155
|
||||
|
@ -49,9 +50,9 @@ CRATE_OPTIONS: dict[str, list[TestOption]] = {
|
|||
"x86_64": [TestOption.BUILD_X86_ONLY],
|
||||
"sys_util": [TestOption.SINGLE_THREADED],
|
||||
"rutabaga_gfx_ffi": [TestOption.DO_NOT_BUILD], # b/206689789
|
||||
"rutabaga_gfx": [TestOption.DO_NOT_BUILD_ARMHF], #b/210015864
|
||||
"vm_control": [TestOption.DO_NOT_BUILD_ARMHF], #b/210015864
|
||||
"libcrosvm_control": [TestOption.DO_NOT_BUILD_ARMHF], #b/210015864
|
||||
"rutabaga_gfx": [TestOption.DO_NOT_BUILD_ARMHF], # b/210015864
|
||||
"vm_control": [TestOption.DO_NOT_BUILD_ARMHF], # b/210015864
|
||||
"libcrosvm_control": [TestOption.DO_NOT_BUILD_ARMHF], # b/210015864
|
||||
}
|
||||
|
||||
BUILD_FEATURES: dict[str, str] = {
|
||||
|
|
Loading…
Reference in a new issue