blob: 43b5fe4916862c18d122e6bb6441635e795bbc67 [file] [log] [blame]
Andrew Walbranb12a43e2020-11-10 14:22:42 +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//! Android VirtualizationService
Andrew Walbranb12a43e2020-11-10 14:22:42 +000016
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000017mod aidl;
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000018mod composite;
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000019mod crosvm;
Andrew Walbran3eca16c2021-06-14 11:15:14 +000020mod gpt;
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000021
Andrew Walbranf6bf6862021-05-21 12:41:13 +000022use crate::aidl::{VirtualizationService, BINDER_SERVICE_IDENTIFIER};
23use android_system_virtualizationservice::aidl::android::system::virtualizationservice::IVirtualizationService::BnVirtualizationService;
24use android_system_virtualizationservice::binder::{add_service, BinderFeatures, ProcessState};
Andrew Walbranbf1fb042021-03-15 16:54:09 +000025use log::{info, Level};
Andrew Walbranb12a43e2020-11-10 14:22:42 +000026
Andrew Walbranf6bf6862021-05-21 12:41:13 +000027/// The first CID to assign to a guest VM managed by the VirtualizationService. CIDs lower than this
28/// are reserved for the host or other usage.
Andrew Walbranb12a43e2020-11-10 14:22:42 +000029const FIRST_GUEST_CID: Cid = 10;
30
Andrew Walbranf6bf6862021-05-21 12:41:13 +000031const LOG_TAG: &str = "VirtualizationService";
Andrew Walbranbf1fb042021-03-15 16:54:09 +000032
Andrew Walbranb12a43e2020-11-10 14:22:42 +000033/// The unique ID of a VM used (together with a port number) for vsock communication.
34type Cid = u32;
35
Andrew Walbranb12a43e2020-11-10 14:22:42 +000036fn main() {
Andrew Walbran0909bc52021-03-17 12:11:56 +000037 android_logger::init_once(
38 android_logger::Config::default().with_tag(LOG_TAG).with_min_level(Level::Trace),
39 );
Andrew Walbranbf1fb042021-03-15 16:54:09 +000040
Andrew Walbran17de24f2021-05-27 13:27:30 +000041 let service = VirtualizationService::default();
42 let service = BnVirtualizationService::new_binder(
43 service,
Andrew Walbran02034492021-04-13 15:05:07 +000044 BinderFeatures { set_requesting_sid: true, ..BinderFeatures::default() },
45 );
Andrew Walbran17de24f2021-05-27 13:27:30 +000046 add_service(BINDER_SERVICE_IDENTIFIER, service.as_binder()).unwrap();
Andrew Walbranb12a43e2020-11-10 14:22:42 +000047 info!("Registered Binder service, joining threadpool.");
Andrew Walbrand6dce6f2021-03-05 16:39:08 +000048 ProcessState::join_thread_pool();
Andrew Walbranb12a43e2020-11-10 14:22:42 +000049}