blob: 206dd4b400005c8fe9317033c070d06e1308664e [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
David Brazdil671e6142022-11-16 11:47:27 +000025use anyhow::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};
David Brazdil671e6142022-11-16 11:47:27 +000028use rpcbinder::RpcServer;
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
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070048 debug!("compsvc is starting as a rpc service.");
David Brazdil671e6142022-11-16 11:47:27 +000049 let service = compsvc::new_binder()?.as_binder();
50 let server = RpcServer::new_vsock(service, COMPOS_VSOCK_PORT)?;
Alice Wangbd569a02022-10-06 15:23:24 +000051 // SAFETY: Invokes a method from the bindgen library `vm_payload_bindgen`.
David Brazdil671e6142022-11-16 11:47:27 +000052 unsafe { AVmPayload_notifyPayloadReady() };
53 server.join();
54 Ok(())
Alan Stokes9e2c5d52021-07-21 11:29:10 +010055}