blob: a4e3903fdf54e7b30432d21293bcaa67b3ee872b [file] [log] [blame]
Alan Stokes9e2c5d52021-07-21 11:29:10 +01001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070017//! A tool to start a standalone compsvc server that serves over RPC binder.
Alan Stokes9e2c5d52021-07-21 11:29:10 +010018
Alan Stokes183d7d32021-12-08 16:10:45 +000019mod artifact_signer;
Victor Hsieh51789de2021-08-06 16:50:49 -070020mod compilation;
Alan Stokes16fb8552022-02-10 15:07:27 +000021mod compos_key;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010022mod compsvc;
Victor Hsieh9ed27182021-08-25 15:52:42 -070023mod fsverity;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010024
Alice Wangbd569a02022-10-06 15:23:24 +000025use anyhow::{bail, Result};
Alan Stokes17fd36a2021-09-06 17:22:37 +010026use compos_common::COMPOS_VSOCK_PORT;
Alan Stokesf30982b2022-11-18 11:50:32 +000027use log::{debug, error};
Alice Wang86c88cc2022-10-17 08:10:49 +000028use rpcbinder::run_vsock_rpc_server;
Alan Stokes7e8c9fc2022-02-02 18:02:41 +000029use std::panic;
Alan Stokesf30982b2022-11-18 11:50:32 +000030use vm_payload_bindgen::AVmPayload_notifyPayloadReady;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010031
Alan Stokese1b6e1c2021-10-01 12:44:49 +010032fn main() {
33 if let Err(e) = try_main() {
34 error!("failed with {:?}", e);
35 std::process::exit(1);
36 }
37}
38
39fn try_main() -> Result<()> {
Alan Stokes454069c2022-02-03 11:21:19 +000040 android_logger::init_once(
41 android_logger::Config::default().with_tag("compsvc").with_min_level(log::Level::Debug),
42 );
43 // Redirect panic messages to logcat.
44 panic::set_hook(Box::new(|panic_info| {
45 error!("{}", panic_info);
46 }));
Alan Stokes9e2c5d52021-07-21 11:29:10 +010047
Alan Stokescd359bb2021-10-08 18:22:42 +010048 let service = compsvc::new_binder()?.as_binder();
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070049 debug!("compsvc is starting as a rpc service.");
Alice Wangbd569a02022-10-06 15:23:24 +000050 // SAFETY: Invokes a method from the bindgen library `vm_payload_bindgen`.
Alice Wang86c88cc2022-10-17 08:10:49 +000051 let retval = run_vsock_rpc_server(service, COMPOS_VSOCK_PORT, || unsafe {
Andrew Scull655e98e2022-10-10 22:24:58 +000052 AVmPayload_notifyPayloadReady();
Alan Stokescd359bb2021-10-08 18:22:42 +010053 });
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070054 if retval {
55 debug!("RPC server has shut down gracefully");
56 Ok(())
Alan Stokes9e2c5d52021-07-21 11:29:10 +010057 } else {
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070058 bail!("Premature termination of RPC server");
Alan Stokes9e2c5d52021-07-21 11:29:10 +010059 }
60}