blob: 77e2daacb8cf1e12cb16b0830db46d77af9daafe [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 Stokese0945ad2022-11-24 13:29:57 +000026use binder::unstable_api::AsNative;
Alan Stokes17fd36a2021-09-06 17:22:37 +010027use compos_common::COMPOS_VSOCK_PORT;
Alan Stokesf30982b2022-11-18 11:50:32 +000028use log::{debug, error};
Alan Stokese0945ad2022-11-24 13:29:57 +000029use std::os::raw::c_void;
Alan Stokes7e8c9fc2022-02-02 18:02:41 +000030use std::panic;
Alan Stokese0945ad2022-11-24 13:29:57 +000031use std::ptr;
32use vm_payload_bindgen::{AIBinder, AVmPayload_notifyPayloadReady, AVmPayload_runVsockRpcServer};
Alan Stokes9e2c5d52021-07-21 11:29:10 +010033
Alan Stokese1b6e1c2021-10-01 12:44:49 +010034fn main() {
35 if let Err(e) = try_main() {
36 error!("failed with {:?}", e);
37 std::process::exit(1);
38 }
39}
40
41fn try_main() -> Result<()> {
Alan Stokes454069c2022-02-03 11:21:19 +000042 android_logger::init_once(
43 android_logger::Config::default().with_tag("compsvc").with_min_level(log::Level::Debug),
44 );
45 // Redirect panic messages to logcat.
46 panic::set_hook(Box::new(|panic_info| {
47 error!("{}", panic_info);
48 }));
Alan Stokes9e2c5d52021-07-21 11:29:10 +010049
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070050 debug!("compsvc is starting as a rpc service.");
Alan Stokese0945ad2022-11-24 13:29:57 +000051 let param = ptr::null_mut();
52 let mut service = compsvc::new_binder()?.as_binder();
53 unsafe {
54 // SAFETY: We hold a strong pointer, so the raw pointer remains valid. The bindgen AIBinder
55 // is the same type as sys::AIBinder.
56 let service = service.as_native_mut() as *mut AIBinder;
57 // SAFETY: It is safe for on_ready to be invoked at any time, with any parameter.
58 AVmPayload_runVsockRpcServer(service, COMPOS_VSOCK_PORT, Some(on_ready), param);
59 }
David Brazdil671e6142022-11-16 11:47:27 +000060 Ok(())
Alan Stokes9e2c5d52021-07-21 11:29:10 +010061}
Alan Stokese0945ad2022-11-24 13:29:57 +000062
63extern "C" fn on_ready(_param: *mut c_void) {
64 // SAFETY: Invokes a method from the bindgen library `vm_payload_bindgen` which is safe to
65 // call at any time.
66 unsafe { AVmPayload_notifyPayloadReady() };
67}