Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | //! Android Virt Manager |
| 16 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 17 | mod aidl; |
| 18 | mod config; |
| 19 | mod crosvm; |
| 20 | |
| 21 | use crate::aidl::{VirtManager, BINDER_SERVICE_IDENTIFIER}; |
| 22 | use android_system_virtmanager::aidl::android::system::virtmanager::IVirtManager::BnVirtManager; |
| 23 | use android_system_virtmanager::binder::{add_service, ProcessState}; |
Andrew Walbran | bf1fb04 | 2021-03-15 16:54:09 +0000 | [diff] [blame^] | 24 | use log::{info, Level}; |
Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 25 | |
| 26 | /// The first CID to assign to a guest VM managed by the Virt Manager. CIDs lower than this are |
| 27 | /// reserved for the host or other usage. |
| 28 | const FIRST_GUEST_CID: Cid = 10; |
| 29 | |
Andrew Walbran | bf1fb04 | 2021-03-15 16:54:09 +0000 | [diff] [blame^] | 30 | const LOG_TAG: &str = "VirtManager"; |
| 31 | |
Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 32 | /// The unique ID of a VM used (together with a port number) for vsock communication. |
| 33 | type Cid = u32; |
| 34 | |
Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 35 | fn main() { |
Andrew Walbran | bf1fb04 | 2021-03-15 16:54:09 +0000 | [diff] [blame^] | 36 | android_logger::init_once(android_logger::Config::default().with_tag(LOG_TAG).with_min_level( |
| 37 | if env!("TARGET_BUILD_VARIANT") == "user" { Level::Info } else { Level::Trace }, |
| 38 | )); |
| 39 | |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 40 | let virt_manager = VirtManager::default(); |
Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 41 | let virt_manager = BnVirtManager::new_binder(virt_manager); |
| 42 | add_service(BINDER_SERVICE_IDENTIFIER, virt_manager.as_binder()).unwrap(); |
| 43 | info!("Registered Binder service, joining threadpool."); |
Andrew Walbran | d6dce6f | 2021-03-05 16:39:08 +0000 | [diff] [blame] | 44 | ProcessState::join_thread_pool(); |
Andrew Walbran | b12a43e | 2020-11-10 14:22:42 +0000 | [diff] [blame] | 45 | } |