Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/arch/src/serial/sys/linux.rs
5394 views
1
// Copyright 2022 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
use std::sync::Arc;
6
7
use base::RawDescriptor;
8
use devices::serial_device::SerialParameters;
9
use devices::BusDevice;
10
use devices::ProxyDevice;
11
use devices::Serial;
12
use minijail::Minijail;
13
use sync::Mutex;
14
15
use crate::DeviceRegistrationError;
16
17
pub fn add_serial_device(
18
com: Serial,
19
_serial_parameters: &SerialParameters,
20
serial_jail: Option<Minijail>,
21
preserved_descriptors: Vec<RawDescriptor>,
22
#[cfg(feature = "swap")] swap_controller: &mut Option<swap::SwapController>,
23
) -> std::result::Result<Arc<Mutex<dyn BusDevice>>, DeviceRegistrationError> {
24
let com: Arc<Mutex<dyn BusDevice>> = if let Some(serial_jail) = serial_jail {
25
Arc::new(Mutex::new(
26
ProxyDevice::new(
27
com,
28
serial_jail,
29
preserved_descriptors,
30
#[cfg(feature = "swap")]
31
swap_controller,
32
)
33
.map_err(DeviceRegistrationError::ProxyDeviceCreation)?,
34
))
35
} else {
36
Arc::new(Mutex::new(com))
37
};
38
Ok(com)
39
}
40
41