Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 1 | /* |
| 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 Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame] | 17 | //! A tool to start a standalone compsvc server that serves over RPC binder. |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 18 | |
Alan Stokes | 183d7d3 | 2021-12-08 16:10:45 +0000 | [diff] [blame] | 19 | mod artifact_signer; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 20 | mod compilation; |
Alan Stokes | 16fb855 | 2022-02-10 15:07:27 +0000 | [diff] [blame] | 21 | mod compos_key; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 22 | mod compsvc; |
Victor Hsieh | 9ed2718 | 2021-08-25 15:52:42 -0700 | [diff] [blame] | 23 | mod fsverity; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 24 | |
Alice Wang | bd569a0 | 2022-10-06 15:23:24 +0000 | [diff] [blame] | 25 | use anyhow::{bail, Result}; |
Alan Stokes | 17fd36a | 2021-09-06 17:22:37 +0100 | [diff] [blame] | 26 | use compos_common::COMPOS_VSOCK_PORT; |
Alan Stokes | f30982b | 2022-11-18 11:50:32 +0000 | [diff] [blame] | 27 | use log::{debug, error}; |
Alice Wang | 86c88cc | 2022-10-17 08:10:49 +0000 | [diff] [blame] | 28 | use rpcbinder::run_vsock_rpc_server; |
Alan Stokes | 7e8c9fc | 2022-02-02 18:02:41 +0000 | [diff] [blame] | 29 | use std::panic; |
Alan Stokes | f30982b | 2022-11-18 11:50:32 +0000 | [diff] [blame] | 30 | use vm_payload_bindgen::AVmPayload_notifyPayloadReady; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 31 | |
Alan Stokes | e1b6e1c | 2021-10-01 12:44:49 +0100 | [diff] [blame] | 32 | fn main() { |
| 33 | if let Err(e) = try_main() { |
| 34 | error!("failed with {:?}", e); |
| 35 | std::process::exit(1); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | fn try_main() -> Result<()> { |
Alan Stokes | 454069c | 2022-02-03 11:21:19 +0000 | [diff] [blame] | 40 | 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 Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 47 | |
Alan Stokes | cd359bb | 2021-10-08 18:22:42 +0100 | [diff] [blame] | 48 | let service = compsvc::new_binder()?.as_binder(); |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame] | 49 | debug!("compsvc is starting as a rpc service."); |
Alice Wang | bd569a0 | 2022-10-06 15:23:24 +0000 | [diff] [blame] | 50 | // SAFETY: Invokes a method from the bindgen library `vm_payload_bindgen`. |
Alice Wang | 86c88cc | 2022-10-17 08:10:49 +0000 | [diff] [blame] | 51 | let retval = run_vsock_rpc_server(service, COMPOS_VSOCK_PORT, || unsafe { |
Andrew Scull | 655e98e | 2022-10-10 22:24:58 +0000 | [diff] [blame] | 52 | AVmPayload_notifyPayloadReady(); |
Alan Stokes | cd359bb | 2021-10-08 18:22:42 +0100 | [diff] [blame] | 53 | }); |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame] | 54 | if retval { |
| 55 | debug!("RPC server has shut down gracefully"); |
| 56 | Ok(()) |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 57 | } else { |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame] | 58 | bail!("Premature termination of RPC server"); |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 59 | } |
| 60 | } |