blob: 5f4b7a763ec89129373df3efc66b2a81eab805ba [file] [log] [blame]
Andrew Walbrand6dce6f2021-03-05 16:39:08 +00001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Andrew Walbranf6bf6862021-05-21 12:41:13 +000015//! Implementation of the AIDL interface of the VirtualizationService.
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000016
Seungjae Yooacf559a2022-08-12 04:44:51 +000017use crate::atom::{write_vm_booted_stats, write_vm_creation_stats};
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000018use crate::composite::make_composite_image;
Andrew Walbranf8d94112021-09-07 11:45:36 +000019use crate::crosvm::{CrosvmConfig, DiskFile, PayloadState, VmInstance, VmState};
Andrew Walbrancc0db522021-07-12 17:03:42 +000020use crate::payload::add_microdroid_images;
Jiyong Parkd50a0242021-09-16 21:00:14 +090021use crate::{Cid, FIRST_GUEST_CID, SYSPROP_LAST_CID};
Jiyong Park029977d2021-11-24 21:56:49 +090022use crate::selinux::{SeContext, getfilecon};
Jiyong Park753553b2021-07-12 21:21:09 +090023use android_os_permissions_aidl::aidl::android::os::IPermissionController;
Jooyung Han21e9b922021-06-26 04:14:16 +090024use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{
Andrew Walbranc92d35f2022-01-12 12:45:19 +000025 DeathReason::DeathReason,
Andrew Walbran6b650662021-09-07 13:13:23 +000026 DiskImage::DiskImage,
Alan Stokes0cc59ee2021-09-24 11:20:34 +010027 IVirtualMachine::{BnVirtualMachine, IVirtualMachine},
Andrew Walbran6b650662021-09-07 13:13:23 +000028 IVirtualMachineCallback::IVirtualMachineCallback,
29 IVirtualizationService::IVirtualizationService,
Jiyong Park029977d2021-11-24 21:56:49 +090030 Partition::Partition,
Andrew Walbran6b650662021-09-07 13:13:23 +000031 PartitionType::PartitionType,
Jooyung Han21e9b922021-06-26 04:14:16 +090032 VirtualMachineAppConfig::VirtualMachineAppConfig,
33 VirtualMachineConfig::VirtualMachineConfig,
Andrew Walbran6b650662021-09-07 13:13:23 +000034 VirtualMachineDebugInfo::VirtualMachineDebugInfo,
Jooyung Han21e9b922021-06-26 04:14:16 +090035 VirtualMachineRawConfig::VirtualMachineRawConfig,
Andrew Walbran6b650662021-09-07 13:13:23 +000036 VirtualMachineState::VirtualMachineState,
Jooyung Han21e9b922021-06-26 04:14:16 +090037};
Alan Stokes0e82b502022-08-08 14:44:48 +010038use binder::{
Andrew Walbran46999c92022-08-04 17:33:46 +000039 self, BinderFeatures, ExceptionCode, Interface, LazyServiceGuard, ParcelFileDescriptor,
40 SpIBinder, Status, StatusCode, Strong, ThreadState,
Andrew Walbrana89fc132021-03-17 17:08:36 +000041};
Alan Stokes0cc59ee2021-09-24 11:20:34 +010042use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::{
43 IVirtualMachineService::{
44 BnVirtualMachineService, IVirtualMachineService, VM_BINDER_SERVICE_PORT,
Shikha Panwar7afc1392022-03-24 08:54:43 +000045 VM_STREAM_SERVICE_PORT, VM_TOMBSTONES_SERVICE_PORT,
Alan Stokes0cc59ee2021-09-24 11:20:34 +010046 },
Inseob Kim1b95f2e2021-08-19 13:17:40 +090047};
Jiyong Parkd50a0242021-09-16 21:00:14 +090048use anyhow::{anyhow, bail, Context, Result};
Andrew Walbran46999c92022-08-04 17:33:46 +000049use binder_common::rpc_server::run_rpc_server_with_factory;
Andrew Walbrandfc953d2021-06-10 13:59:56 +000050use disk::QcowFile;
Alan Stokes0cc59ee2021-09-24 11:20:34 +010051use idsig::{HashAlgorithm, V4Signature};
Seungjae Yoo0a8c84c2022-07-11 08:19:15 +000052use log::{debug, error, info, warn};
Andrew Walbrancc0db522021-07-12 17:03:42 +000053use microdroid_payload_config::VmPayloadConfig;
Jiyong Parkd50a0242021-09-16 21:00:14 +090054use rustutils::system_properties;
Jiyong Parkdcf17412022-02-08 15:07:23 +090055use semver::VersionReq;
Andrew Walbrandff3b942021-06-09 15:20:36 +000056use std::convert::TryInto;
Shikha Panward8e35422021-10-11 13:51:27 +000057use std::ffi::CStr;
Alan Stokes0cc59ee2021-09-24 11:20:34 +010058use std::fs::{create_dir, File, OpenOptions};
Shikha Panwar7afc1392022-03-24 08:54:43 +000059use std::io::{Error, ErrorKind, Write, Read};
Andrew Walbranb15cd6e2021-07-05 16:38:07 +000060use std::num::NonZeroU32;
Andrew Walbrand3a84182021-09-07 14:48:52 +000061use std::os::unix::io::{FromRawFd, IntoRawFd};
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000062use std::path::{Path, PathBuf};
Andrew Walbran320b5602021-03-04 16:11:12 +000063use std::sync::{Arc, Mutex, Weak};
Shikha Panwar7afc1392022-03-24 08:54:43 +000064use tombstoned_client::{TombstonedConnection, DebuggerdDumpType};
Andrew Walbrancc0db522021-07-12 17:03:42 +000065use vmconfig::VmConfig;
Inseob Kim7f61fe72021-08-20 20:50:47 +090066use vsock::{SockAddr, VsockListener, VsockStream};
Jooyung Han35edb8f2021-07-01 16:17:16 +090067use zip::ZipArchive;
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000068
Andrew Walbranf6bf6862021-05-21 12:41:13 +000069pub const BINDER_SERVICE_IDENTIFIER: &str = "android.system.virtualizationservice";
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000070
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000071/// Directory in which to write disk image files used while running VMs.
Andrew Walbran488bd072021-07-14 13:29:51 +000072pub const TEMPORARY_DIRECTORY: &str = "/data/misc/virtualizationservice";
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000073
Jiyong Park8611a6c2021-07-09 18:17:44 +090074/// The CID representing the host VM
75const VMADDR_CID_HOST: u32 = 2;
76
Jooyung Han95884632021-07-06 22:27:54 +090077/// The size of zero.img.
78/// Gaps in composite disk images are filled with a shared zero.img.
79const ZERO_FILLER_SIZE: u64 = 4096;
80
Jiyong Park9dd389e2021-08-23 20:42:59 +090081/// Magic string for the instance image
82const ANDROID_VM_INSTANCE_MAGIC: &str = "Android-VM-instance";
83
84/// Version of the instance image format
85const ANDROID_VM_INSTANCE_VERSION: u16 = 1;
86
Shikha Panwar7afc1392022-03-24 08:54:43 +000087const CHUNK_RECV_MAX_LEN: usize = 1024;
88
Andrew Walbranf6bf6862021-05-21 12:41:13 +000089/// Implementation of `IVirtualizationService`, the entry point of the AIDL service.
Jooyung Han9900f3d2021-07-06 10:27:54 +090090#[derive(Debug, Default)]
Andrew Walbranf6bf6862021-05-21 12:41:13 +000091pub struct VirtualizationService {
Jiyong Park8611a6c2021-07-09 18:17:44 +090092 state: Arc<Mutex<State>>,
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000093}
94
Shikha Panward8e35422021-10-11 13:51:27 +000095impl Interface for VirtualizationService {
96 fn dump(&self, mut file: &File, _args: &[&CStr]) -> Result<(), StatusCode> {
97 check_permission("android.permission.DUMP").or(Err(StatusCode::PERMISSION_DENIED))?;
98 let state = &mut *self.state.lock().unwrap();
99 let vms = state.vms();
100 writeln!(file, "Running {0} VMs:", vms.len()).or(Err(StatusCode::UNKNOWN_ERROR))?;
101 for vm in vms {
102 writeln!(file, "VM CID: {}", vm.cid).or(Err(StatusCode::UNKNOWN_ERROR))?;
103 writeln!(file, "\tState: {:?}", vm.vm_state.lock().unwrap())
104 .or(Err(StatusCode::UNKNOWN_ERROR))?;
105 writeln!(file, "\tPayload state {:?}", vm.payload_state())
106 .or(Err(StatusCode::UNKNOWN_ERROR))?;
107 writeln!(file, "\tProtected: {}", vm.protected).or(Err(StatusCode::UNKNOWN_ERROR))?;
108 writeln!(file, "\ttemporary_directory: {}", vm.temporary_directory.to_string_lossy())
109 .or(Err(StatusCode::UNKNOWN_ERROR))?;
110 writeln!(file, "\trequester_uid: {}", vm.requester_uid)
111 .or(Err(StatusCode::UNKNOWN_ERROR))?;
112 writeln!(file, "\trequester_sid: {}", vm.requester_sid)
113 .or(Err(StatusCode::UNKNOWN_ERROR))?;
114 writeln!(file, "\trequester_debug_pid: {}", vm.requester_debug_pid)
115 .or(Err(StatusCode::UNKNOWN_ERROR))?;
116 }
117 Ok(())
118 }
119}
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000120
Andrew Walbranf6bf6862021-05-21 12:41:13 +0000121impl IVirtualizationService for VirtualizationService {
Andrew Walbranf8d94112021-09-07 11:45:36 +0000122 /// Creates (but does not start) a new VM with the given configuration, assigning it the next
123 /// available CID.
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000124 ///
125 /// Returns a binder `IVirtualMachine` object referring to it, as a handle for the client.
Andrew Walbranf8d94112021-09-07 11:45:36 +0000126 fn createVm(
Andrew Walbrana89fc132021-03-17 17:08:36 +0000127 &self,
Andrew Walbran3a5a9212021-05-04 17:09:08 +0000128 config: &VirtualMachineConfig,
Jiyong Parkb8182bb2021-10-26 22:53:08 +0900129 console_fd: Option<&ParcelFileDescriptor>,
Andrew Walbrana89fc132021-03-17 17:08:36 +0000130 log_fd: Option<&ParcelFileDescriptor>,
131 ) -> binder::Result<Strong<dyn IVirtualMachine>> {
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000132 let mut is_protected = false;
133 let ret = self.create_vm_internal(config, console_fd, log_fd, &mut is_protected);
Seungjae Yoo0a8c84c2022-07-11 08:19:15 +0000134 write_vm_creation_stats(config, is_protected, &ret);
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000135 ret
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000136 }
Andrew Walbran320b5602021-03-04 16:11:12 +0000137
Andrew Walbrandff3b942021-06-09 15:20:36 +0000138 /// Initialise an empty partition image of the given size to be used as a writable partition.
139 fn initializeWritablePartition(
140 &self,
141 image_fd: &ParcelFileDescriptor,
142 size: i64,
Jiyong Park9dd389e2021-08-23 20:42:59 +0900143 partition_type: PartitionType,
Andrew Walbrandff3b942021-06-09 15:20:36 +0000144 ) -> binder::Result<()> {
Jiyong Park753553b2021-07-12 21:21:09 +0900145 check_manage_access()?;
Andrew Walbrandfc953d2021-06-10 13:59:56 +0000146 let size = size.try_into().map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000147 Status::new_exception_str(
Andrew Walbran806f1542021-06-10 14:07:12 +0000148 ExceptionCode::ILLEGAL_ARGUMENT,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000149 Some(format!("Invalid size {}: {}", size, e)),
Andrew Walbran806f1542021-06-10 14:07:12 +0000150 )
Andrew Walbrandff3b942021-06-09 15:20:36 +0000151 })?;
Andrew Walbrandfc953d2021-06-10 13:59:56 +0000152 let image = clone_file(image_fd)?;
Jooyung Han1edd5b92021-10-28 10:58:05 +0900153 // initialize the file. Any data in the file will be erased.
154 image.set_len(0).map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000155 Status::new_service_specific_error_str(
156 -1,
157 Some(format!("Failed to reset a file: {}", e)),
Jooyung Han1edd5b92021-10-28 10:58:05 +0900158 )
159 })?;
Jiyong Park9dd389e2021-08-23 20:42:59 +0900160 let mut part = QcowFile::new(image, size).map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000161 Status::new_service_specific_error_str(
162 -1,
163 Some(format!("Failed to create QCOW2 image: {}", e)),
Andrew Walbran806f1542021-06-10 14:07:12 +0000164 )
Andrew Walbrandfc953d2021-06-10 13:59:56 +0000165 })?;
Andrew Walbrandff3b942021-06-09 15:20:36 +0000166
Jiyong Park9dd389e2021-08-23 20:42:59 +0900167 match partition_type {
168 PartitionType::RAW => Ok(()),
169 PartitionType::ANDROID_VM_INSTANCE => format_as_android_vm_instance(&mut part),
170 _ => Err(Error::new(
171 ErrorKind::Unsupported,
172 format!("Unsupported partition type {:?}", partition_type),
173 )),
174 }
175 .map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000176 Status::new_service_specific_error_str(
177 -1,
178 Some(format!("Failed to initialize partition as {:?}: {}", partition_type, e)),
Jiyong Park9dd389e2021-08-23 20:42:59 +0900179 )
180 })?;
181
Andrew Walbrandff3b942021-06-09 15:20:36 +0000182 Ok(())
183 }
184
Jiyong Park0a248432021-08-20 23:32:39 +0900185 /// Creates or update the idsig file by digesting the input APK file.
186 fn createOrUpdateIdsigFile(
187 &self,
188 input_fd: &ParcelFileDescriptor,
189 idsig_fd: &ParcelFileDescriptor,
190 ) -> binder::Result<()> {
191 // TODO(b/193504400): do this only when (1) idsig_fd is empty or (2) the APK digest in
192 // idsig_fd is different from APK digest in input_fd
193
Jiyong Parkc3ca24f2022-06-28 10:45:15 +0900194 check_manage_access()?;
195
Jiyong Park0a248432021-08-20 23:32:39 +0900196 let mut input = clone_file(input_fd)?;
197 let mut sig = V4Signature::create(&mut input, 4096, &[], HashAlgorithm::SHA256).unwrap();
198
199 let mut output = clone_file(idsig_fd)?;
200 output.set_len(0).unwrap();
201 sig.write_into(&mut output).unwrap();
202 Ok(())
203 }
204
Andrew Walbran320b5602021-03-04 16:11:12 +0000205 /// Get a list of all currently running VMs. This method is only intended for debug purposes,
206 /// and as such is only permitted from the shell user.
207 fn debugListVms(&self) -> binder::Result<Vec<VirtualMachineDebugInfo>> {
Andrew Walbran806f1542021-06-10 14:07:12 +0000208 check_debug_access()?;
Andrew Walbran320b5602021-03-04 16:11:12 +0000209
210 let state = &mut *self.state.lock().unwrap();
211 let vms = state.vms();
Andrew Walbranf6a1eb92021-04-01 11:16:02 +0000212 let cids = vms
213 .into_iter()
214 .map(|vm| VirtualMachineDebugInfo {
215 cid: vm.cid as i32,
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000216 temporaryDirectory: vm.temporary_directory.to_string_lossy().to_string(),
Andrew Walbran1ef19ae2021-04-07 11:31:57 +0000217 requesterUid: vm.requester_uid as i32,
218 requesterSid: vm.requester_sid.clone(),
Andrew Walbran02034492021-04-13 15:05:07 +0000219 requesterPid: vm.requester_debug_pid,
Andrew Walbran6b650662021-09-07 13:13:23 +0000220 state: get_state(&vm),
Andrew Walbranf6a1eb92021-04-01 11:16:02 +0000221 })
222 .collect();
Andrew Walbran320b5602021-03-04 16:11:12 +0000223 Ok(cids)
224 }
David Brazdil3c2ddef2021-03-18 13:09:57 +0000225
Andrew Walbranf6bf6862021-05-21 12:41:13 +0000226 /// Hold a strong reference to a VM in VirtualizationService. This method is only intended for
227 /// debug purposes, and as such is only permitted from the shell user.
Andrei Homescu1415c132021-03-24 02:39:55 +0000228 fn debugHoldVmRef(&self, vmref: &Strong<dyn IVirtualMachine>) -> binder::Result<()> {
Andrew Walbran806f1542021-06-10 14:07:12 +0000229 check_debug_access()?;
David Brazdil3c2ddef2021-03-18 13:09:57 +0000230
David Brazdil3c2ddef2021-03-18 13:09:57 +0000231 let state = &mut *self.state.lock().unwrap();
Andrei Homescu1415c132021-03-24 02:39:55 +0000232 state.debug_hold_vm(vmref.clone());
David Brazdil3c2ddef2021-03-18 13:09:57 +0000233 Ok(())
234 }
235
Andrew Walbranf6bf6862021-05-21 12:41:13 +0000236 /// Drop reference to a VM that is being held by VirtualizationService. Returns the reference if
237 /// the VM was found and None otherwise. This method is only intended for debug purposes, and as
238 /// such is only permitted from the shell user.
David Brazdil3c2ddef2021-03-18 13:09:57 +0000239 fn debugDropVmRef(&self, cid: i32) -> binder::Result<Option<Strong<dyn IVirtualMachine>>> {
Andrew Walbran806f1542021-06-10 14:07:12 +0000240 check_debug_access()?;
David Brazdil3c2ddef2021-03-18 13:09:57 +0000241
242 let state = &mut *self.state.lock().unwrap();
243 Ok(state.debug_drop_vm(cid))
244 }
Andrew Walbran320b5602021-03-04 16:11:12 +0000245}
246
Shikha Panwar7afc1392022-03-24 08:54:43 +0000247fn handle_stream_connection_tombstoned() -> Result<()> {
248 let listener =
249 VsockListener::bind_with_cid_port(VMADDR_CID_HOST, VM_TOMBSTONES_SERVICE_PORT as u32)?;
250 info!("Listening to tombstones from guests ...");
251 for incoming_stream in listener.incoming() {
252 let mut incoming_stream = match incoming_stream {
253 Err(e) => {
254 warn!("invalid incoming connection: {}", e);
255 continue;
256 }
257 Ok(s) => s,
258 };
259 std::thread::spawn(move || {
260 if let Err(e) = handle_tombstone(&mut incoming_stream) {
261 error!("Failed to write tombstone- {:?}", e);
262 }
263 });
264 }
265 Ok(())
266}
267
268fn handle_tombstone(stream: &mut VsockStream) -> Result<()> {
269 if let Ok(SockAddr::Vsock(addr)) = stream.peer_addr() {
270 info!("Vsock Stream connected to cid={} for tombstones", addr.cid());
271 }
272 let tb_connection =
273 TombstonedConnection::connect(std::process::id() as i32, DebuggerdDumpType::Tombstone)
274 .context("Failed to connect to tombstoned")?;
275 let mut text_output = tb_connection
276 .text_output
277 .as_ref()
278 .ok_or_else(|| anyhow!("Could not get file to write the tombstones on"))?;
279 let mut num_bytes_read = 0;
280 loop {
281 let mut chunk_recv = [0; CHUNK_RECV_MAX_LEN];
282 let n = stream
283 .read(&mut chunk_recv)
284 .context("Failed to read tombstone data from Vsock stream")?;
285 if n == 0 {
286 break;
287 }
288 num_bytes_read += n;
289 text_output.write_all(&chunk_recv[0..n]).context("Failed to write guests tombstones")?;
290 }
291 info!("Received {} bytes from guest & wrote to tombstone file", num_bytes_read);
292 tb_connection.notify_completion()?;
293 Ok(())
294}
295
Jiyong Park8611a6c2021-07-09 18:17:44 +0900296impl VirtualizationService {
297 pub fn init() -> VirtualizationService {
298 let service = VirtualizationService::default();
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900299
300 // server for payload output
Jiyong Park8611a6c2021-07-09 18:17:44 +0900301 let state = service.state.clone(); // reference to state (not the state itself) is copied
302 std::thread::spawn(move || {
Inseob Kim7f61fe72021-08-20 20:50:47 +0900303 handle_stream_connection_from_vm(state).unwrap();
Jiyong Park8611a6c2021-07-09 18:17:44 +0900304 });
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900305
Shikha Panwar7afc1392022-03-24 08:54:43 +0000306 std::thread::spawn(|| {
307 if let Err(e) = handle_stream_connection_tombstoned() {
308 warn!("Error receiving tombstone from guest or writing them. Error: {}", e);
309 }
310 });
311
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900312 // binder server for vm
Shikha Panwar7afc1392022-03-24 08:54:43 +0000313 // reference to state (not the state itself) is copied
Andrew Walbran0fd0ff02022-07-29 15:59:17 +0000314 let state = service.state.clone();
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900315 std::thread::spawn(move || {
Andrew Walbran0fd0ff02022-07-29 15:59:17 +0000316 debug!("VirtualMachineService is starting as an RPC service.");
317 if run_rpc_server_with_factory(VM_BINDER_SERVICE_PORT as u32, |cid| {
318 VirtualMachineService::factory(cid, &state)
319 }) {
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900320 debug!("RPC server has shut down gracefully");
321 } else {
Andrew Walbran0fd0ff02022-07-29 15:59:17 +0000322 panic!("Premature termination of RPC server");
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900323 }
Inseob Kim1b95f2e2021-08-19 13:17:40 +0900324 });
Jiyong Park8611a6c2021-07-09 18:17:44 +0900325 service
326 }
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000327
328 fn create_vm_internal(
329 &self,
330 config: &VirtualMachineConfig,
331 console_fd: Option<&ParcelFileDescriptor>,
332 log_fd: Option<&ParcelFileDescriptor>,
333 is_protected: &mut bool,
334 ) -> binder::Result<Strong<dyn IVirtualMachine>> {
335 check_manage_access()?;
Inseob Kim1119d702022-05-02 18:01:58 +0900336
337 if let VirtualMachineConfig::RawConfig(config) = config {
338 if config.protectedVm {
339 check_use_custom_virtual_machine()?;
340 }
341 }
342
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000343 let state = &mut *self.state.lock().unwrap();
344 let console_fd = console_fd.map(clone_file).transpose()?;
345 let log_fd = log_fd.map(clone_file).transpose()?;
346 let requester_uid = ThreadState::get_calling_uid();
347 let requester_sid = get_calling_sid()?;
348 let requester_debug_pid = ThreadState::get_calling_pid();
349 let cid = next_cid().or(Err(ExceptionCode::ILLEGAL_STATE))?;
350
351 // Counter to generate unique IDs for temporary image files.
352 let mut next_temporary_image_id = 0;
353 // Files which are referred to from composite images. These must be mapped to the crosvm
354 // child process, and not closed before it is started.
355 let mut indirect_files = vec![];
356
357 // Make directory for temporary files.
358 let temporary_directory: PathBuf = format!("{}/{}", TEMPORARY_DIRECTORY, cid).into();
359 create_dir(&temporary_directory).map_err(|e| {
360 // At this point, we do not know the protected status of Vm
361 // setting it to false, though this may not be correct.
362 error!(
Alan Stokes70ccf162022-07-08 11:05:03 +0100363 "Failed to create temporary directory {:?} for VM files: {:?}",
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000364 temporary_directory, e
365 );
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000366 Status::new_service_specific_error_str(
367 -1,
368 Some(format!(
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000369 "Failed to create temporary directory {:?} for VM files: {}",
370 temporary_directory, e
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000371 )),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000372 )
373 })?;
374
375 let is_app_config = matches!(config, VirtualMachineConfig::AppConfig(_));
376
377 let config = match config {
378 VirtualMachineConfig::AppConfig(config) => BorrowedOrOwned::Owned(
379 load_app_config(config, &temporary_directory).map_err(|e| {
Alan Stokes70ccf162022-07-08 11:05:03 +0100380 error!("Failed to load app config from {}: {:?}", &config.configPath, e);
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000381 *is_protected = config.protectedVm;
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000382 Status::new_service_specific_error_str(
383 -1,
384 Some(format!(
385 "Failed to load app config from {}: {}",
386 &config.configPath, e
387 )),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000388 )
389 })?,
390 ),
391 VirtualMachineConfig::RawConfig(config) => BorrowedOrOwned::Borrowed(config),
392 };
393 let config = config.as_ref();
394 *is_protected = config.protectedVm;
395
396 // Check if partition images are labeled incorrectly. This is to prevent random images
397 // which are not protected by the Android Verified Boot (e.g. bits downloaded by apps) from
398 // being loaded in a pVM. Specifically, for images in the raw config, nothing is allowed
399 // to be labeled as app_data_file. For images in the app config, nothing but the instance
400 // partition is allowed to be labeled as such.
401 config
402 .disks
403 .iter()
404 .flat_map(|disk| disk.partitions.iter())
405 .filter(|partition| {
406 if is_app_config {
407 partition.label != "vm-instance"
408 } else {
409 true // all partitions are checked
410 }
411 })
412 .try_for_each(check_label_for_partition)
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000413 .map_err(|e| Status::new_service_specific_error_str(-1, Some(e.to_string())))?;
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000414
415 let zero_filler_path = temporary_directory.join("zero.img");
416 write_zero_filler(&zero_filler_path).map_err(|e| {
Alan Stokes70ccf162022-07-08 11:05:03 +0100417 error!("Failed to make composite image: {:?}", e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000418 Status::new_service_specific_error_str(
419 -1,
420 Some(format!("Failed to make composite image: {}", e)),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000421 )
422 })?;
423
424 // Assemble disk images if needed.
425 let disks = config
426 .disks
427 .iter()
428 .map(|disk| {
429 assemble_disk_image(
430 disk,
431 &zero_filler_path,
432 &temporary_directory,
433 &mut next_temporary_image_id,
434 &mut indirect_files,
435 )
436 })
437 .collect::<Result<Vec<DiskFile>, _>>()?;
438
Jiyong Parke558ab12022-07-07 20:18:55 +0900439 // Creating this ramdump file unconditionally is not harmful as ramdump will be created
440 // only when the VM is configured as such. `ramdump_write` is sent to crosvm and will
Jiyong Park4afe2012022-07-08 05:38:49 +0900441 // be the backing store for the /dev/hvc1 where VM will emit ramdump to. `ramdump_read`
Jiyong Parke558ab12022-07-07 20:18:55 +0900442 // will be sent back to the client (i.e. the VM owner) for readout.
443 let ramdump_path = temporary_directory.join("ramdump");
444 let ramdump = prepare_ramdump_file(&ramdump_path).map_err(|e| {
445 error!("Failed to prepare ramdump file: {}", e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000446 Status::new_service_specific_error_str(
447 -1,
448 Some(format!("Failed to prepare ramdump file: {}", e)),
Jiyong Parke558ab12022-07-07 20:18:55 +0900449 )
450 })?;
451
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000452 // Actually start the VM.
453 let crosvm_config = CrosvmConfig {
454 cid,
Seungjae Yoo62085c02022-08-12 04:44:52 +0000455 name: config.name.clone(),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000456 bootloader: maybe_clone_file(&config.bootloader)?,
457 kernel: maybe_clone_file(&config.kernel)?,
458 initrd: maybe_clone_file(&config.initrd)?,
459 disks,
460 params: config.params.to_owned(),
461 protected: *is_protected,
462 memory_mib: config.memoryMib.try_into().ok().and_then(NonZeroU32::new),
463 cpus: config.numCpus.try_into().ok().and_then(NonZeroU32::new),
464 cpu_affinity: config.cpuAffinity.clone(),
Jiyong Parkdfe16d62022-04-20 17:32:12 +0900465 task_profiles: config.taskProfiles.clone(),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000466 console_fd,
467 log_fd,
Jiyong Parke558ab12022-07-07 20:18:55 +0900468 ramdump: Some(ramdump),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000469 indirect_files,
470 platform_version: parse_platform_version_req(&config.platformVersion)?,
Jiyong Parke6ed0f92022-06-22 00:13:00 +0900471 detect_hangup: is_app_config,
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000472 };
473 let instance = Arc::new(
474 VmInstance::new(
475 crosvm_config,
476 temporary_directory,
477 requester_uid,
478 requester_sid,
479 requester_debug_pid,
480 )
481 .map_err(|e| {
Alan Stokes70ccf162022-07-08 11:05:03 +0100482 error!("Failed to create VM with config {:?}: {:?}", config, e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000483 Status::new_service_specific_error_str(
484 -1,
485 Some(format!("Failed to create VM: {}", e)),
Shikha Panwar061aa2c2022-04-05 12:52:56 +0000486 )
487 })?,
488 );
489 state.add_vm(Arc::downgrade(&instance));
490 Ok(VirtualMachine::create(instance))
491 }
Jiyong Park8611a6c2021-07-09 18:17:44 +0900492}
493
Andrew Walbran6b650662021-09-07 13:13:23 +0000494/// Waits for incoming connections from VM. If a new connection is made, stores the stream in the
495/// corresponding `VmInstance`.
Inseob Kim7f61fe72021-08-20 20:50:47 +0900496fn handle_stream_connection_from_vm(state: Arc<Mutex<State>>) -> Result<()> {
Inseob Kimd0587562021-09-01 21:27:32 +0900497 let listener =
498 VsockListener::bind_with_cid_port(VMADDR_CID_HOST, VM_STREAM_SERVICE_PORT as u32)?;
Jiyong Park8611a6c2021-07-09 18:17:44 +0900499 for stream in listener.incoming() {
500 let stream = match stream {
501 Err(e) => {
502 warn!("invalid incoming connection: {}", e);
503 continue;
504 }
505 Ok(s) => s,
506 };
507 if let Ok(SockAddr::Vsock(addr)) = stream.peer_addr() {
508 let cid = addr.cid();
509 let port = addr.port();
Inseob Kim7f61fe72021-08-20 20:50:47 +0900510 info!("payload stream connected from cid={}, port={}", cid, port);
Jiyong Park8611a6c2021-07-09 18:17:44 +0900511 if let Some(vm) = state.lock().unwrap().get_vm(cid) {
Chris Wailes8bbb8932021-09-10 14:14:19 -0700512 *vm.stream.lock().unwrap() = Some(stream);
Inseob Kim7f61fe72021-08-20 20:50:47 +0900513 } else {
514 error!("connection from cid={} is not from a guest VM", cid);
Jiyong Park8611a6c2021-07-09 18:17:44 +0900515 }
516 }
517 }
518 Ok(())
519}
520
Andrew Walbranfbb39d22021-07-28 17:01:25 +0000521fn write_zero_filler(zero_filler_path: &Path) -> Result<()> {
Jooyung Han95884632021-07-06 22:27:54 +0900522 let file = OpenOptions::new()
523 .create_new(true)
524 .read(true)
525 .write(true)
526 .open(zero_filler_path)
527 .with_context(|| "Failed to create zero.img")?;
528 file.set_len(ZERO_FILLER_SIZE)?;
Andrew Walbranfbb39d22021-07-28 17:01:25 +0000529 Ok(())
Jooyung Han95884632021-07-06 22:27:54 +0900530}
531
Jiyong Park9dd389e2021-08-23 20:42:59 +0900532fn format_as_android_vm_instance(part: &mut dyn Write) -> std::io::Result<()> {
533 part.write_all(ANDROID_VM_INSTANCE_MAGIC.as_bytes())?;
534 part.write_all(&ANDROID_VM_INSTANCE_VERSION.to_le_bytes())?;
535 part.flush()
536}
537
Jiyong Parke558ab12022-07-07 20:18:55 +0900538fn prepare_ramdump_file(ramdump_path: &Path) -> Result<File> {
539 File::create(&ramdump_path)
540 .context(format!("Failed to create ramdump file {:?}", &ramdump_path))
541}
542
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000543/// Given the configuration for a disk image, assembles the `DiskFile` to pass to crosvm.
544///
545/// This may involve assembling a composite disk from a set of partition images.
546fn assemble_disk_image(
547 disk: &DiskImage,
Jooyung Han95884632021-07-06 22:27:54 +0900548 zero_filler_path: &Path,
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000549 temporary_directory: &Path,
550 next_temporary_image_id: &mut u64,
551 indirect_files: &mut Vec<File>,
Andrew Walbran806f1542021-06-10 14:07:12 +0000552) -> Result<DiskFile, Status> {
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000553 let image = if !disk.partitions.is_empty() {
554 if disk.image.is_some() {
555 warn!("DiskImage {:?} contains both image and partitions.", disk);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000556 return Err(Status::new_exception_str(
Andrew Walbran806f1542021-06-10 14:07:12 +0000557 ExceptionCode::ILLEGAL_ARGUMENT,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000558 Some("DiskImage contains both image and partitions."),
Andrew Walbran806f1542021-06-10 14:07:12 +0000559 ));
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000560 }
561
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000562 let composite_image_filenames =
563 make_composite_image_filenames(temporary_directory, next_temporary_image_id);
564 let (image, partition_files) = make_composite_image(
565 &disk.partitions,
Jooyung Han95884632021-07-06 22:27:54 +0900566 zero_filler_path,
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000567 &composite_image_filenames.composite,
568 &composite_image_filenames.header,
569 &composite_image_filenames.footer,
570 )
571 .map_err(|e| {
Alan Stokes70ccf162022-07-08 11:05:03 +0100572 error!("Failed to make composite image with config {:?}: {:?}", disk, e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000573 Status::new_service_specific_error_str(
574 -1,
575 Some(format!("Failed to make composite image: {}", e)),
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000576 )
577 })?;
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000578
579 // Pass the file descriptors for the various partition files to crosvm when it
580 // is run.
581 indirect_files.extend(partition_files);
582
583 image
584 } else if let Some(image) = &disk.image {
585 clone_file(image)?
586 } else {
587 warn!("DiskImage {:?} didn't contain image or partitions.", disk);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000588 return Err(Status::new_exception_str(
Andrew Walbran806f1542021-06-10 14:07:12 +0000589 ExceptionCode::ILLEGAL_ARGUMENT,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000590 Some("DiskImage didn't contain image or partitions."),
Andrew Walbran806f1542021-06-10 14:07:12 +0000591 ));
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000592 };
593
594 Ok(DiskFile { image, writable: disk.writable })
595}
596
Jooyung Han21e9b922021-06-26 04:14:16 +0900597fn load_app_config(
598 config: &VirtualMachineAppConfig,
599 temporary_directory: &Path,
Jooyung Hanadfb76c2021-06-28 17:29:30 +0900600) -> Result<VirtualMachineRawConfig> {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000601 let apk_file = clone_file(config.apk.as_ref().unwrap())?;
602 let idsig_file = clone_file(config.idsig.as_ref().unwrap())?;
Jiyong Park8d081812021-07-23 17:45:04 +0900603 let instance_file = clone_file(config.instanceImage.as_ref().unwrap())?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900604 let config_path = &config.configPath;
605
Andrew Walbrancc0db522021-07-12 17:03:42 +0000606 let mut apk_zip = ZipArchive::new(&apk_file)?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900607 let config_file = apk_zip.by_name(config_path)?;
608 let vm_payload_config: VmPayloadConfig = serde_json::from_reader(config_file)?;
609
610 let os_name = &vm_payload_config.os.name;
Andrew Walbrancc0db522021-07-12 17:03:42 +0000611
Jooyung Han35edb8f2021-07-01 16:17:16 +0900612 // For now, the only supported "os" value is "microdroid"
613 if os_name != "microdroid" {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000614 bail!("Unknown OS \"{}\"", os_name);
Jooyung Han35edb8f2021-07-01 16:17:16 +0900615 }
Andrew Walbrancc0db522021-07-12 17:03:42 +0000616
617 // It is safe to construct a filename based on the os_name because we've already checked that it
618 // is one of the allowed values.
Jooyung Han21e9b922021-06-26 04:14:16 +0900619 let vm_config_path = PathBuf::from(format!("/apex/com.android.virt/etc/{}.json", os_name));
620 let vm_config_file = File::open(vm_config_path)?;
Andrew Walbrancc0db522021-07-12 17:03:42 +0000621 let mut vm_config = VmConfig::load(&vm_config_file)?.to_parcelable()?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900622
Andrew Walbrancc045902021-07-27 16:06:17 +0000623 if config.memoryMib > 0 {
624 vm_config.memoryMib = config.memoryMib;
Andrew Walbran45bcb0c2021-07-14 15:02:06 +0000625 }
626
Seungjae Yoo62085c02022-08-12 04:44:52 +0000627 vm_config.name = config.name.clone();
Andrew Walbran3994f002022-01-27 17:33:45 +0000628 vm_config.protectedVm = config.protectedVm;
Jiyong Park032615f2022-01-10 13:55:34 +0900629 vm_config.numCpus = config.numCpus;
630 vm_config.cpuAffinity = config.cpuAffinity.clone();
Jiyong Parkdfe16d62022-04-20 17:32:12 +0900631 vm_config.taskProfiles = config.taskProfiles.clone();
Jiyong Park032615f2022-01-10 13:55:34 +0900632
Andrew Walbrancc0db522021-07-12 17:03:42 +0000633 // Microdroid requires an additional payload disk image and the bootconfig partition.
Jooyung Hanadfb76c2021-06-28 17:29:30 +0900634 if os_name == "microdroid" {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000635 add_microdroid_images(
636 config,
Jooyung Hanadfb76c2021-06-28 17:29:30 +0900637 temporary_directory,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000638 apk_file,
639 idsig_file,
Jiyong Park8d081812021-07-23 17:45:04 +0900640 instance_file,
Jooyung Han5dc42172021-10-05 16:43:47 +0900641 &vm_payload_config,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000642 &mut vm_config,
643 )?;
Jooyung Hanadfb76c2021-06-28 17:29:30 +0900644 }
Jooyung Han21e9b922021-06-26 04:14:16 +0900645
Andrew Walbrancc0db522021-07-12 17:03:42 +0000646 Ok(vm_config)
Jooyung Han21e9b922021-06-26 04:14:16 +0900647}
648
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000649/// Generates a unique filename to use for a composite disk image.
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000650fn make_composite_image_filenames(
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000651 temporary_directory: &Path,
652 next_temporary_image_id: &mut u64,
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000653) -> CompositeImageFilenames {
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000654 let id = *next_temporary_image_id;
655 *next_temporary_image_id += 1;
Andrew Walbran3eca16c2021-06-14 11:15:14 +0000656 CompositeImageFilenames {
657 composite: temporary_directory.join(format!("composite-{}.img", id)),
658 header: temporary_directory.join(format!("composite-{}-header.img", id)),
659 footer: temporary_directory.join(format!("composite-{}-footer.img", id)),
660 }
661}
662
663/// Filenames for a composite disk image, including header and footer partitions.
664#[derive(Clone, Debug, Eq, PartialEq)]
665struct CompositeImageFilenames {
666 /// The composite disk image itself.
667 composite: PathBuf,
668 /// The header partition image.
669 header: PathBuf,
670 /// The footer partition image.
671 footer: PathBuf,
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000672}
673
674/// Gets the calling SID of the current Binder thread.
Andrew Walbran806f1542021-06-10 14:07:12 +0000675fn get_calling_sid() -> Result<String, Status> {
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000676 ThreadState::with_calling_sid(|sid| {
677 if let Some(sid) = sid {
678 match sid.to_str() {
679 Ok(sid) => Ok(sid.to_owned()),
680 Err(e) => {
Andrew Walbran806f1542021-06-10 14:07:12 +0000681 error!("SID was not valid UTF-8: {}", e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000682 Err(Status::new_exception_str(
Andrew Walbran806f1542021-06-10 14:07:12 +0000683 ExceptionCode::ILLEGAL_ARGUMENT,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000684 Some(format!("SID was not valid UTF-8: {}", e)),
Andrew Walbran806f1542021-06-10 14:07:12 +0000685 ))
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000686 }
687 }
688 } else {
Andrew Walbranf8d94112021-09-07 11:45:36 +0000689 error!("Missing SID on createVm");
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000690 Err(Status::new_exception_str(ExceptionCode::SECURITY, Some("Missing SID on createVm")))
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000691 }
692 })
693}
694
Jiyong Park753553b2021-07-12 21:21:09 +0900695/// Checks whether the caller has a specific permission
696fn check_permission(perm: &str) -> binder::Result<()> {
697 let calling_pid = ThreadState::get_calling_pid();
698 let calling_uid = ThreadState::get_calling_uid();
699 // Root can do anything
700 if calling_uid == 0 {
701 return Ok(());
702 }
703 let perm_svc: Strong<dyn IPermissionController::IPermissionController> =
704 binder::get_interface("permission")?;
705 if perm_svc.checkPermission(perm, calling_pid, calling_uid as i32)? {
Andrew Walbran806f1542021-06-10 14:07:12 +0000706 Ok(())
707 } else {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000708 Err(Status::new_exception_str(
Jiyong Park753553b2021-07-12 21:21:09 +0900709 ExceptionCode::SECURITY,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000710 Some(format!("does not have the {} permission", perm)),
Jiyong Park753553b2021-07-12 21:21:09 +0900711 ))
Andrew Walbran806f1542021-06-10 14:07:12 +0000712 }
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000713}
714
Jiyong Park753553b2021-07-12 21:21:09 +0900715/// Check whether the caller of the current Binder method is allowed to call debug methods.
716fn check_debug_access() -> binder::Result<()> {
717 check_permission("android.permission.DEBUG_VIRTUAL_MACHINE")
718}
719
720/// Check whether the caller of the current Binder method is allowed to manage VMs
721fn check_manage_access() -> binder::Result<()> {
722 check_permission("android.permission.MANAGE_VIRTUAL_MACHINE")
723}
724
Inseob Kim1119d702022-05-02 18:01:58 +0900725/// Check whether the caller of the current Binder method is allowed to create custom VMs
726fn check_use_custom_virtual_machine() -> binder::Result<()> {
727 check_permission("android.permission.USE_CUSTOM_VIRTUAL_MACHINE")
728}
729
Jiyong Park029977d2021-11-24 21:56:49 +0900730/// Check if a partition has selinux labels that are not allowed
731fn check_label_for_partition(partition: &Partition) -> Result<()> {
732 let ctx = getfilecon(partition.image.as_ref().unwrap().as_ref())?;
733 if ctx == SeContext::new("u:object_r:app_data_file:s0").unwrap() {
734 Err(anyhow!("Partition {} shouldn't be labeled as {}", &partition.label, ctx))
735 } else {
736 Ok(())
737 }
738}
739
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000740/// Implementation of the AIDL `IVirtualMachine` interface. Used as a handle to a VM.
741#[derive(Debug)]
742struct VirtualMachine {
743 instance: Arc<VmInstance>,
Alan Stokes0cc59ee2021-09-24 11:20:34 +0100744 /// Keeps our service process running as long as this VM instance exists.
Chris Wailes641fc4a2021-12-01 15:03:21 -0800745 #[allow(dead_code)]
Alan Stokes0cc59ee2021-09-24 11:20:34 +0100746 lazy_service_guard: LazyServiceGuard,
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000747}
748
749impl VirtualMachine {
750 fn create(instance: Arc<VmInstance>) -> Strong<dyn IVirtualMachine> {
Alan Stokes0cc59ee2021-09-24 11:20:34 +0100751 let binder = VirtualMachine { instance, lazy_service_guard: Default::default() };
Andrew Walbran4de28782021-04-13 14:51:43 +0000752 BnVirtualMachine::new_binder(binder, BinderFeatures::default())
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000753 }
754}
755
756impl Interface for VirtualMachine {}
757
758impl IVirtualMachine for VirtualMachine {
759 fn getCid(&self) -> binder::Result<i32> {
Jiyong Park753553b2021-07-12 21:21:09 +0900760 // Don't check permission. The owner of the VM might have passed this binder object to
761 // others.
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000762 Ok(self.instance.cid as i32)
763 }
Andrew Walbrandae07162021-03-12 17:05:20 +0000764
Andrew Walbran6b650662021-09-07 13:13:23 +0000765 fn getState(&self) -> binder::Result<VirtualMachineState> {
Jiyong Park753553b2021-07-12 21:21:09 +0900766 // Don't check permission. The owner of the VM might have passed this binder object to
767 // others.
Andrew Walbran6b650662021-09-07 13:13:23 +0000768 Ok(get_state(&self.instance))
Andrew Walbrandae07162021-03-12 17:05:20 +0000769 }
770
771 fn registerCallback(
772 &self,
773 callback: &Strong<dyn IVirtualMachineCallback>,
774 ) -> binder::Result<()> {
Jiyong Park753553b2021-07-12 21:21:09 +0900775 // Don't check permission. The owner of the VM might have passed this binder object to
776 // others.
777 //
Andrew Walbrandae07162021-03-12 17:05:20 +0000778 // TODO: Should this give an error if the VM is already dead?
779 self.instance.callbacks.add(callback.clone());
780 Ok(())
781 }
Andrew Walbrancbe8b082021-08-06 15:42:11 +0000782
Andrew Walbranf8d94112021-09-07 11:45:36 +0000783 fn start(&self) -> binder::Result<()> {
784 self.instance.start().map_err(|e| {
785 error!("Error starting VM with CID {}: {:?}", self.instance.cid, e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000786 Status::new_service_specific_error_str(-1, Some(e.to_string()))
Andrew Walbranf8d94112021-09-07 11:45:36 +0000787 })
788 }
789
Inseob Kima446f802022-07-11 19:46:37 +0900790 fn stop(&self) -> binder::Result<()> {
791 self.instance.kill().map_err(|e| {
792 error!("Error stopping VM with CID {}: {:?}", self.instance.cid, e);
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000793 Status::new_service_specific_error_str(-1, Some(e.to_string()))
Inseob Kima446f802022-07-11 19:46:37 +0900794 })
795 }
796
Andrew Walbrancbe8b082021-08-06 15:42:11 +0000797 fn connectVsock(&self, port: i32) -> binder::Result<ParcelFileDescriptor> {
Andrew Walbranf8d94112021-09-07 11:45:36 +0000798 if !matches!(&*self.instance.vm_state.lock().unwrap(), VmState::Running { .. }) {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000799 return Err(Status::new_service_specific_error_str(-1, Some("VM is not running")));
Andrew Walbrancbe8b082021-08-06 15:42:11 +0000800 }
801 let stream =
802 VsockStream::connect_with_cid_port(self.instance.cid, port as u32).map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000803 Status::new_service_specific_error_str(
804 -1,
805 Some(format!("Failed to connect: {}", e)),
Andrew Walbrancbe8b082021-08-06 15:42:11 +0000806 )
807 })?;
808 Ok(vsock_stream_to_pfd(stream))
809 }
Andrew Walbrandae07162021-03-12 17:05:20 +0000810}
811
812impl Drop for VirtualMachine {
813 fn drop(&mut self) {
814 debug!("Dropping {:?}", self);
Inseob Kima446f802022-07-11 19:46:37 +0900815 if let Err(e) = self.instance.kill() {
816 debug!("Error stopping dropped VM with CID {}: {:?}", self.instance.cid, e);
817 }
Andrew Walbrandae07162021-03-12 17:05:20 +0000818 }
819}
820
821/// A set of Binders to be called back in response to various events on the VM, such as when it
822/// dies.
823#[derive(Debug, Default)]
824pub struct VirtualMachineCallbacks(Mutex<Vec<Strong<dyn IVirtualMachineCallback>>>);
825
826impl VirtualMachineCallbacks {
Jiyong Park8611a6c2021-07-09 18:17:44 +0900827 /// Call all registered callbacks to notify that the payload has started.
Inseob Kim7f61fe72021-08-20 20:50:47 +0900828 pub fn notify_payload_started(&self, cid: Cid, stream: Option<VsockStream>) {
Jiyong Park8611a6c2021-07-09 18:17:44 +0900829 let callbacks = &*self.0.lock().unwrap();
Inseob Kim7f61fe72021-08-20 20:50:47 +0900830 let pfd = stream.map(vsock_stream_to_pfd);
Jiyong Park8611a6c2021-07-09 18:17:44 +0900831 for callback in callbacks {
Inseob Kim7f61fe72021-08-20 20:50:47 +0900832 if let Err(e) = callback.onPayloadStarted(cid as i32, pfd.as_ref()) {
Alan Stokes70ccf162022-07-08 11:05:03 +0100833 error!("Error notifying payload start event from VM CID {}: {:?}", cid, e);
Jiyong Park8611a6c2021-07-09 18:17:44 +0900834 }
835 }
836 }
837
Inseob Kim14cb8692021-08-31 21:50:39 +0900838 /// Call all registered callbacks to notify that the payload is ready to serve.
839 pub fn notify_payload_ready(&self, cid: Cid) {
840 let callbacks = &*self.0.lock().unwrap();
841 for callback in callbacks {
842 if let Err(e) = callback.onPayloadReady(cid as i32) {
Alan Stokes70ccf162022-07-08 11:05:03 +0100843 error!("Error notifying payload ready event from VM CID {}: {:?}", cid, e);
Inseob Kim14cb8692021-08-31 21:50:39 +0900844 }
845 }
846 }
847
Inseob Kim2444af92021-08-31 01:22:50 +0900848 /// Call all registered callbacks to notify that the payload has finished.
849 pub fn notify_payload_finished(&self, cid: Cid, exit_code: i32) {
850 let callbacks = &*self.0.lock().unwrap();
851 for callback in callbacks {
852 if let Err(e) = callback.onPayloadFinished(cid as i32, exit_code) {
Alan Stokes70ccf162022-07-08 11:05:03 +0100853 error!("Error notifying payload finish event from VM CID {}: {:?}", cid, e);
Inseob Kim2444af92021-08-31 01:22:50 +0900854 }
855 }
856 }
857
Jooyung Handd0a1732021-11-23 15:26:20 +0900858 /// Call all registered callbacks to say that the VM encountered an error.
859 pub fn notify_error(&self, cid: Cid, error_code: i32, message: &str) {
860 let callbacks = &*self.0.lock().unwrap();
861 for callback in callbacks {
862 if let Err(e) = callback.onError(cid as i32, error_code, message) {
Alan Stokes70ccf162022-07-08 11:05:03 +0100863 error!("Error notifying error event from VM CID {}: {:?}", cid, e);
Jooyung Handd0a1732021-11-23 15:26:20 +0900864 }
865 }
866 }
867
Andrew Walbrandae07162021-03-12 17:05:20 +0000868 /// Call all registered callbacks to say that the VM has died.
Andrew Walbranc92d35f2022-01-12 12:45:19 +0000869 pub fn callback_on_died(&self, cid: Cid, reason: DeathReason) {
Andrew Walbrandae07162021-03-12 17:05:20 +0000870 let callbacks = &*self.0.lock().unwrap();
871 for callback in callbacks {
Andrew Walbranc92d35f2022-01-12 12:45:19 +0000872 if let Err(e) = callback.onDied(cid as i32, reason) {
Alan Stokes70ccf162022-07-08 11:05:03 +0100873 error!("Error notifying exit of VM CID {}: {:?}", cid, e);
Andrew Walbrandae07162021-03-12 17:05:20 +0000874 }
875 }
876 }
877
Jiyong Parke558ab12022-07-07 20:18:55 +0900878 /// Call all registered callbacks to say that there was a ramdump to download.
879 pub fn callback_on_ramdump(&self, cid: Cid, ramdump: File) {
880 let callbacks = &*self.0.lock().unwrap();
881 let pfd = ParcelFileDescriptor::new(ramdump);
882 for callback in callbacks {
883 if let Err(e) = callback.onRamdump(cid as i32, &pfd) {
884 error!("Error notifying ramdump of VM CID {}: {}", cid, e);
885 }
886 }
887 }
888
Andrew Walbrandae07162021-03-12 17:05:20 +0000889 /// Add a new callback to the set.
890 fn add(&self, callback: Strong<dyn IVirtualMachineCallback>) {
891 self.0.lock().unwrap().push(callback);
892 }
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000893}
894
Andrew Walbranf6bf6862021-05-21 12:41:13 +0000895/// The mutable state of the VirtualizationService. There should only be one instance of this
896/// struct.
Chris Wailes641fc4a2021-12-01 15:03:21 -0800897#[derive(Debug, Default)]
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000898struct State {
Andrew Walbran320b5602021-03-04 16:11:12 +0000899 /// The VMs which have been started. When VMs are started a weak reference is added to this list
900 /// while a strong reference is returned to the caller over Binder. Once all copies of the
901 /// Binder client are dropped the weak reference here will become invalid, and will be removed
902 /// from the list opportunistically the next time `add_vm` is called.
903 vms: Vec<Weak<VmInstance>>,
David Brazdil3c2ddef2021-03-18 13:09:57 +0000904
905 /// Vector of strong VM references held on behalf of users that cannot hold them themselves.
906 /// This is only used for debugging purposes.
907 debug_held_vms: Vec<Strong<dyn IVirtualMachine>>,
Andrew Walbran320b5602021-03-04 16:11:12 +0000908}
909
910impl State {
Andrew Walbrandae07162021-03-12 17:05:20 +0000911 /// Get a list of VMs which still have Binder references to them.
Andrew Walbran320b5602021-03-04 16:11:12 +0000912 fn vms(&self) -> Vec<Arc<VmInstance>> {
913 // Attempt to upgrade the weak pointers to strong pointers.
914 self.vms.iter().filter_map(Weak::upgrade).collect()
915 }
916
917 /// Add a new VM to the list.
918 fn add_vm(&mut self, vm: Weak<VmInstance>) {
919 // Garbage collect any entries from the stored list which no longer exist.
920 self.vms.retain(|vm| vm.strong_count() > 0);
921
922 // Actually add the new VM.
923 self.vms.push(vm);
924 }
David Brazdil3c2ddef2021-03-18 13:09:57 +0000925
Jiyong Park8611a6c2021-07-09 18:17:44 +0900926 /// Get a VM that corresponds to the given cid
927 fn get_vm(&self, cid: Cid) -> Option<Arc<VmInstance>> {
928 self.vms().into_iter().find(|vm| vm.cid == cid)
929 }
930
David Brazdil3c2ddef2021-03-18 13:09:57 +0000931 /// Store a strong VM reference.
932 fn debug_hold_vm(&mut self, vm: Strong<dyn IVirtualMachine>) {
933 self.debug_held_vms.push(vm);
934 }
935
936 /// Retrieve and remove a strong VM reference.
937 fn debug_drop_vm(&mut self, cid: i32) -> Option<Strong<dyn IVirtualMachine>> {
938 let pos = self.debug_held_vms.iter().position(|vm| vm.getCid() == Ok(cid))?;
Alan Stokes7e54e292021-09-09 11:37:56 +0100939 let vm = self.debug_held_vms.swap_remove(pos);
Alan Stokes7e54e292021-09-09 11:37:56 +0100940 Some(vm)
David Brazdil3c2ddef2021-03-18 13:09:57 +0000941 }
Andrew Walbrand6dce6f2021-03-05 16:39:08 +0000942}
943
Jiyong Parkd50a0242021-09-16 21:00:14 +0900944/// Get the next available CID, or an error if we have run out. The last CID used is stored in
945/// a system property so that restart of virtualizationservice doesn't reuse CID while the host
946/// Android is up.
947fn next_cid() -> Result<Cid> {
Andrew Walbran014efb52022-02-03 17:43:11 +0000948 let next = if let Some(val) = system_properties::read(SYSPROP_LAST_CID)? {
Jiyong Parkd50a0242021-09-16 21:00:14 +0900949 if let Ok(num) = val.parse::<u32>() {
950 num.checked_add(1).ok_or_else(|| anyhow!("run out of CID"))?
951 } else {
952 error!("Invalid last CID {}. Using {}", &val, FIRST_GUEST_CID);
953 FIRST_GUEST_CID
954 }
955 } else {
956 // First VM since the boot
957 FIRST_GUEST_CID
958 };
959 // Persist the last value for next use
960 let str_val = format!("{}", next);
961 system_properties::write(SYSPROP_LAST_CID, &str_val)?;
962 Ok(next)
963}
964
Andrew Walbran6b650662021-09-07 13:13:23 +0000965/// Gets the `VirtualMachineState` of the given `VmInstance`.
966fn get_state(instance: &VmInstance) -> VirtualMachineState {
Andrew Walbranf8d94112021-09-07 11:45:36 +0000967 match &*instance.vm_state.lock().unwrap() {
968 VmState::NotStarted { .. } => VirtualMachineState::NOT_STARTED,
969 VmState::Running { .. } => match instance.payload_state() {
Andrew Walbran6b650662021-09-07 13:13:23 +0000970 PayloadState::Starting => VirtualMachineState::STARTING,
971 PayloadState::Started => VirtualMachineState::STARTED,
972 PayloadState::Ready => VirtualMachineState::READY,
973 PayloadState::Finished => VirtualMachineState::FINISHED,
Jiyong Parka4eebde2022-07-12 18:01:12 +0900974 PayloadState::Hangup => VirtualMachineState::DEAD,
Andrew Walbranf8d94112021-09-07 11:45:36 +0000975 },
976 VmState::Dead => VirtualMachineState::DEAD,
977 VmState::Failed => VirtualMachineState::DEAD,
Andrew Walbran6b650662021-09-07 13:13:23 +0000978 }
979}
980
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +0000981/// Converts a `&ParcelFileDescriptor` to a `File` by cloning the file.
Seungjae Yoo0a8c84c2022-07-11 08:19:15 +0000982pub fn clone_file(file: &ParcelFileDescriptor) -> Result<File, Status> {
Andrew Walbran806f1542021-06-10 14:07:12 +0000983 file.as_ref().try_clone().map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000984 Status::new_exception_str(
Andrew Walbran806f1542021-06-10 14:07:12 +0000985 ExceptionCode::BAD_PARCELABLE,
Andrew Walbrandcf9d582022-08-03 11:25:24 +0000986 Some(format!("Failed to clone File from ParcelFileDescriptor: {}", e)),
Andrew Walbran806f1542021-06-10 14:07:12 +0000987 )
988 })
989}
990
Andrew Walbrand3a84182021-09-07 14:48:52 +0000991/// Converts an `&Option<ParcelFileDescriptor>` to an `Option<File>` by cloning the file.
992fn maybe_clone_file(file: &Option<ParcelFileDescriptor>) -> Result<Option<File>, Status> {
993 file.as_ref().map(clone_file).transpose()
994}
995
Andrew Walbrancbe8b082021-08-06 15:42:11 +0000996/// Converts a `VsockStream` to a `ParcelFileDescriptor`.
997fn vsock_stream_to_pfd(stream: VsockStream) -> ParcelFileDescriptor {
998 // SAFETY: ownership is transferred from stream to f
999 let f = unsafe { File::from_raw_fd(stream.into_raw_fd()) };
1000 ParcelFileDescriptor::new(f)
1001}
1002
Jiyong Parkdcf17412022-02-08 15:07:23 +09001003/// Parses the platform version requirement string.
1004fn parse_platform_version_req(s: &str) -> Result<VersionReq, Status> {
1005 VersionReq::parse(s).map_err(|e| {
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001006 Status::new_exception_str(
Jiyong Parkdcf17412022-02-08 15:07:23 +09001007 ExceptionCode::BAD_PARCELABLE,
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001008 Some(format!("Invalid platform version requirement {}: {}", s, e)),
Jiyong Parkdcf17412022-02-08 15:07:23 +09001009 )
1010 })
1011}
1012
Jooyung Han35edb8f2021-07-01 16:17:16 +09001013/// Simple utility for referencing Borrowed or Owned. Similar to std::borrow::Cow, but
1014/// it doesn't require that T implements Clone.
1015enum BorrowedOrOwned<'a, T> {
1016 Borrowed(&'a T),
1017 Owned(T),
1018}
1019
1020impl<'a, T> AsRef<T> for BorrowedOrOwned<'a, T> {
1021 fn as_ref(&self) -> &T {
1022 match self {
1023 Self::Borrowed(b) => b,
Chris Wailes68c39f82021-07-27 16:03:44 -07001024 Self::Owned(o) => o,
Jooyung Han35edb8f2021-07-01 16:17:16 +09001025 }
1026 }
1027}
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001028
1029/// Implementation of `IVirtualMachineService`, the entry point of the AIDL service.
1030#[derive(Debug, Default)]
1031struct VirtualMachineService {
1032 state: Arc<Mutex<State>>,
Inseob Kimc7d28c72021-10-25 14:28:10 +00001033 cid: Cid,
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001034}
1035
1036impl Interface for VirtualMachineService {}
1037
1038impl IVirtualMachineService for VirtualMachineService {
Inseob Kimc7d28c72021-10-25 14:28:10 +00001039 fn notifyPayloadStarted(&self) -> binder::Result<()> {
1040 let cid = self.cid;
Inseob Kim7f61fe72021-08-20 20:50:47 +09001041 if let Some(vm) = self.state.lock().unwrap().get_vm(cid) {
1042 info!("VM having CID {} started payload", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001043 vm.update_payload_state(PayloadState::Started).map_err(|e| {
1044 Status::new_exception_str(ExceptionCode::ILLEGAL_STATE, Some(e.to_string()))
1045 })?;
Inseob Kim7f61fe72021-08-20 20:50:47 +09001046 let stream = vm.stream.lock().unwrap().take();
1047 vm.callbacks.notify_payload_started(cid, stream);
Seungjae Yoo62085c02022-08-12 04:44:52 +00001048
1049 write_vm_booted_stats(vm.requester_uid as i32, &vm.name);
Inseob Kim7f61fe72021-08-20 20:50:47 +09001050 Ok(())
1051 } else {
Jooyung Handd0a1732021-11-23 15:26:20 +09001052 error!("notifyPayloadStarted is called from an unknown CID {}", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001053 Err(Status::new_service_specific_error_str(
1054 -1,
1055 Some(format!("cannot find a VM with CID {}", cid)),
Inseob Kim7f61fe72021-08-20 20:50:47 +09001056 ))
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001057 }
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001058 }
Inseob Kim2444af92021-08-31 01:22:50 +09001059
Inseob Kimc7d28c72021-10-25 14:28:10 +00001060 fn notifyPayloadReady(&self) -> binder::Result<()> {
1061 let cid = self.cid;
Inseob Kim14cb8692021-08-31 21:50:39 +09001062 if let Some(vm) = self.state.lock().unwrap().get_vm(cid) {
1063 info!("VM having CID {} payload is ready", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001064 vm.update_payload_state(PayloadState::Ready).map_err(|e| {
1065 Status::new_exception_str(ExceptionCode::ILLEGAL_STATE, Some(e.to_string()))
1066 })?;
Inseob Kim14cb8692021-08-31 21:50:39 +09001067 vm.callbacks.notify_payload_ready(cid);
1068 Ok(())
1069 } else {
Jooyung Handd0a1732021-11-23 15:26:20 +09001070 error!("notifyPayloadReady is called from an unknown CID {}", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001071 Err(Status::new_service_specific_error_str(
1072 -1,
1073 Some(format!("cannot find a VM with CID {}", cid)),
Inseob Kim14cb8692021-08-31 21:50:39 +09001074 ))
1075 }
1076 }
1077
Inseob Kimc7d28c72021-10-25 14:28:10 +00001078 fn notifyPayloadFinished(&self, exit_code: i32) -> binder::Result<()> {
1079 let cid = self.cid;
Inseob Kim2444af92021-08-31 01:22:50 +09001080 if let Some(vm) = self.state.lock().unwrap().get_vm(cid) {
1081 info!("VM having CID {} finished payload", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001082 vm.update_payload_state(PayloadState::Finished).map_err(|e| {
1083 Status::new_exception_str(ExceptionCode::ILLEGAL_STATE, Some(e.to_string()))
1084 })?;
Inseob Kim2444af92021-08-31 01:22:50 +09001085 vm.callbacks.notify_payload_finished(cid, exit_code);
1086 Ok(())
1087 } else {
Jooyung Handd0a1732021-11-23 15:26:20 +09001088 error!("notifyPayloadFinished is called from an unknown CID {}", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001089 Err(Status::new_service_specific_error_str(
1090 -1,
1091 Some(format!("cannot find a VM with CID {}", cid)),
Jooyung Handd0a1732021-11-23 15:26:20 +09001092 ))
1093 }
1094 }
1095
1096 fn notifyError(&self, error_code: i32, message: &str) -> binder::Result<()> {
1097 let cid = self.cid;
1098 if let Some(vm) = self.state.lock().unwrap().get_vm(cid) {
1099 info!("VM having CID {} encountered an error", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001100 vm.update_payload_state(PayloadState::Finished).map_err(|e| {
1101 Status::new_exception_str(ExceptionCode::ILLEGAL_STATE, Some(e.to_string()))
1102 })?;
Jooyung Handd0a1732021-11-23 15:26:20 +09001103 vm.callbacks.notify_error(cid, error_code, message);
1104 Ok(())
1105 } else {
Seungjae Yooec8c1602022-06-20 05:28:00 +00001106 error!("notifyError is called from an unknown CID {}", cid);
Andrew Walbrandcf9d582022-08-03 11:25:24 +00001107 Err(Status::new_service_specific_error_str(
1108 -1,
1109 Some(format!("cannot find a VM with CID {}", cid)),
Inseob Kim2444af92021-08-31 01:22:50 +09001110 ))
1111 }
1112 }
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001113}
1114
1115impl VirtualMachineService {
Andrew Walbran0fd0ff02022-07-29 15:59:17 +00001116 fn factory(cid: Cid, state: &Arc<Mutex<State>>) -> Option<SpIBinder> {
Inseob Kimc7d28c72021-10-25 14:28:10 +00001117 if let Some(vm) = state.lock().unwrap().get_vm(cid) {
1118 let mut vm_service = vm.vm_service.lock().unwrap();
1119 let service = vm_service.get_or_insert_with(|| Self::new_binder(state.clone(), cid));
Andrew Walbran0fd0ff02022-07-29 15:59:17 +00001120 Some(service.as_binder())
Inseob Kimc7d28c72021-10-25 14:28:10 +00001121 } else {
1122 error!("connection from cid={} is not from a guest VM", cid);
Andrew Walbran0fd0ff02022-07-29 15:59:17 +00001123 None
Inseob Kimc7d28c72021-10-25 14:28:10 +00001124 }
1125 }
1126
1127 fn new_binder(state: Arc<Mutex<State>>, cid: Cid) -> Strong<dyn IVirtualMachineService> {
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001128 BnVirtualMachineService::new_binder(
Inseob Kimc7d28c72021-10-25 14:28:10 +00001129 VirtualMachineService { state, cid },
Inseob Kim1b95f2e2021-08-19 13:17:40 +09001130 BinderFeatures::default(),
1131 )
1132 }
1133}