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 | |
| 19 | mod common; |
Victor Hsieh | 51789de | 2021-08-06 16:50:49 -0700 | [diff] [blame] | 20 | mod compilation; |
Victor Hsieh | a64194b | 2021-08-06 17:43:36 -0700 | [diff] [blame] | 21 | mod compos_key_service; |
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 | 7ec4e7f | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 24 | mod signer; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 25 | |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame^] | 26 | use crate::common::VSOCK_PORT; |
| 27 | use anyhow::{bail, Result}; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 28 | use binder::unstable_api::AsNative; |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 29 | use log::debug; |
| 30 | |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 31 | fn main() -> Result<()> { |
| 32 | android_logger::init_once( |
| 33 | android_logger::Config::default().with_tag("compsvc").with_min_level(log::Level::Debug), |
| 34 | ); |
| 35 | |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame^] | 36 | let mut service = compsvc::new_binder()?.as_binder(); |
| 37 | debug!("compsvc is starting as a rpc service."); |
| 38 | // SAFETY: Service ownership is transferring to the server and won't be valid afterward. |
| 39 | // Plus the binder objects are threadsafe. |
| 40 | let retval = unsafe { |
| 41 | binder_rpc_unstable_bindgen::RunRpcServer( |
| 42 | service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder, |
| 43 | VSOCK_PORT, |
| 44 | ) |
| 45 | }; |
| 46 | if retval { |
| 47 | debug!("RPC server has shut down gracefully"); |
| 48 | Ok(()) |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 49 | } else { |
Victor Hsieh | 9ebf7ee | 2021-09-03 16:14:14 -0700 | [diff] [blame^] | 50 | bail!("Premature termination of RPC server"); |
Alan Stokes | 9e2c5d5 | 2021-07-21 11:29:10 +0100 | [diff] [blame] | 51 | } |
| 52 | } |