Extract a library for common CompOS things
A small refactoring as a preliminary step to creating composd.
Create a Rust library for useful things shared by various
CompOS-related binaries. This initially includes the code to start the
VM and connect to CompOS, as well as various useful constants.
As part of extracting the start VM code I migrated to using logging
directly rather than writing to stdout/stderr for greater reusability,
as suggested by Victor.
Bug: 186126194
Test: Get odsign to run compos_verify_key, still works
Change-Id: I57b7ebcdd1a6cb604b5d739b8a8e028fd59e7b90
diff --git a/compos/src/common.rs b/compos/src/common.rs
deleted file mode 100644
index ca831bb..0000000
--- a/compos/src/common.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/// Port to listen. This should be out of future port range (if happens) that microdroid may
-/// reserve for system components.
-pub const VSOCK_PORT: u32 = 6432;
diff --git a/compos/src/compsvc_main.rs b/compos/src/compsvc_main.rs
index 46c8f8c..9855b53 100644
--- a/compos/src/compsvc_main.rs
+++ b/compos/src/compsvc_main.rs
@@ -16,16 +16,15 @@
//! A tool to start a standalone compsvc server that serves over RPC binder.
-mod common;
mod compilation;
mod compos_key_service;
mod compsvc;
mod fsverity;
mod signer;
-use crate::common::VSOCK_PORT;
use anyhow::{bail, Result};
use binder::unstable_api::AsNative;
+use compos_common::COMPOS_VSOCK_PORT;
use log::debug;
fn main() -> Result<()> {
@@ -40,7 +39,7 @@
let retval = unsafe {
binder_rpc_unstable_bindgen::RunRpcServer(
service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder,
- VSOCK_PORT,
+ COMPOS_VSOCK_PORT,
)
};
if retval {
diff --git a/compos/src/pvm_exec.rs b/compos/src/pvm_exec.rs
index 6938370..b6fc729 100644
--- a/compos/src/pvm_exec.rs
+++ b/compos/src/pvm_exec.rs
@@ -41,9 +41,7 @@
FdAnnotation::FdAnnotation, ICompOsService::ICompOsService,
};
use compos_aidl_interface::binder::Strong;
-
-mod common;
-use common::VSOCK_PORT;
+use compos_common::COMPOS_VSOCK_PORT;
const FD_SERVER_BIN: &str = "/apex/com.android.virt/bin/fd_server";
@@ -51,7 +49,9 @@
// SAFETY: AIBinder returned by RpcClient has correct reference count, and the ownership can be
// safely taken by new_spibinder.
let ibinder = unsafe {
- new_spibinder(binder_rpc_unstable_bindgen::RpcClient(cid, VSOCK_PORT) as *mut AIBinder)
+ new_spibinder(
+ binder_rpc_unstable_bindgen::RpcClient(cid, COMPOS_VSOCK_PORT) as *mut AIBinder
+ )
};
if let Some(ibinder) = ibinder {
<dyn ICompOsService>::try_from(ibinder).context("Cannot connect to RPC service")