Stop passing file size from pvm_exec
File size is no longer used by authfs, so remove the reference in
pvm_exec and compsvc.
Bug: 198824883
Test: atest ComposHostTestCases
Change-Id: Iabaae7c4e2a67780c6819b6d20b3cc410264ae29
diff --git a/compos/aidl/com/android/compos/InputFdAnnotation.aidl b/compos/aidl/com/android/compos/FdAnnotation.aidl
similarity index 61%
rename from compos/aidl/com/android/compos/InputFdAnnotation.aidl
rename to compos/aidl/com/android/compos/FdAnnotation.aidl
index 44a5591..b910391 100644
--- a/compos/aidl/com/android/compos/InputFdAnnotation.aidl
+++ b/compos/aidl/com/android/compos/FdAnnotation.aidl
@@ -17,13 +17,16 @@
package com.android.compos;
/** {@hide} */
-parcelable InputFdAnnotation {
+parcelable FdAnnotation {
/**
- * File descriptor number to be passed to the program. This is also the same file descriptor
- * number used in the backend server.
+ * Input file descriptor numbers to be passed to the program. This is currently assumed to be
+ * same as the file descriptor number used in the backend server.
*/
- int fd;
+ int[] input_fds;
- /** The actual file size in bytes of the backing file to be read. */
- long file_size;
+ /**
+ * Output file descriptor numbers to be passed to the program. This is currently assumed to be
+ * same as the file descriptor number used in the backend server.
+ */
+ int[] output_fds;
}
diff --git a/compos/aidl/com/android/compos/ICompOsService.aidl b/compos/aidl/com/android/compos/ICompOsService.aidl
index 3a74940..7904130 100644
--- a/compos/aidl/com/android/compos/ICompOsService.aidl
+++ b/compos/aidl/com/android/compos/ICompOsService.aidl
@@ -18,7 +18,7 @@
import com.android.compos.CompOsKeyData;
import com.android.compos.CompilationResult;
-import com.android.compos.Metadata;
+import com.android.compos.FdAnnotation;
/** {@hide} */
interface ICompOsService {
@@ -33,17 +33,17 @@
void initializeSigningKey(in byte[] keyBlob);
/**
- * Run dex2oat command with provided args, in a context that may be specified in the Metadata,
+ * Run dex2oat command with provided args, in a context that may be specified in FdAnnotation,
* e.g. with file descriptors pre-opened. The service is responsible to decide what executables
* it may run.
*
* @param args The command line arguments to run. The 0-th args is normally the program name,
* which may not be used by the service. The service may be configured to always use
* a fixed executable, or possibly use the 0-th args are the executable lookup hint.
- * @param metadata Additional information of the execution
+ * @param fd_annotation Additional file descriptor information of the execution
* @return a CompilationResult
*/
- CompilationResult compile(in String[] args, in Metadata metadata);
+ CompilationResult compile(in String[] args, in FdAnnotation fd_annotation);
/**
* Generate a new public/private key pair suitable for signing CompOs output files.
diff --git a/compos/aidl/com/android/compos/Metadata.aidl b/compos/aidl/com/android/compos/Metadata.aidl
deleted file mode 100644
index a15214d..0000000
--- a/compos/aidl/com/android/compos/Metadata.aidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.compos;
-
-import com.android.compos.InputFdAnnotation;
-import com.android.compos.OutputFdAnnotation;
-
-/** {@hide} */
-parcelable Metadata {
- InputFdAnnotation[] input_fd_annotations;
- OutputFdAnnotation[] output_fd_annotations;
-}
diff --git a/compos/aidl/com/android/compos/OutputFdAnnotation.aidl b/compos/aidl/com/android/compos/OutputFdAnnotation.aidl
deleted file mode 100644
index 95ce425..0000000
--- a/compos/aidl/com/android/compos/OutputFdAnnotation.aidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.compos;
-
-/** {@hide} */
-parcelable OutputFdAnnotation {
- /**
- * File descriptor number to be passed to the program. This is currently assumed to be same as
- * the file descriptor number used in the backend server.
- */
- int fd;
-}
diff --git a/compos/src/compilation.rs b/compos/src/compilation.rs
index 0199eb5..fec82a6 100644
--- a/compos/src/compilation.rs
+++ b/compos/src/compilation.rs
@@ -27,7 +27,7 @@
InputFdAnnotation::InputFdAnnotation, OutputFdAnnotation::OutputFdAnnotation,
};
use authfs_aidl_interface::binder::{ParcelFileDescriptor, Strong};
-use compos_aidl_interface::aidl::com::android::compos::Metadata::Metadata;
+use compos_aidl_interface::aidl::com::android::compos::FdAnnotation::FdAnnotation;
/// The number that represents the file descriptor number expecting by the task. The number may be
/// meaningless in the current process.
@@ -50,17 +50,17 @@
image: ParcelFileDescriptor,
}
-/// Runs the compiler with given flags with file descriptors described in `metadata` retrieved via
-/// `authfs_service`. Returns exit code of the compiler process.
+/// Runs the compiler with given flags with file descriptors described in `fd_annotation` retrieved
+/// via `authfs_service`. Returns exit code of the compiler process.
pub fn compile(
compiler_path: &Path,
compiler_args: &[String],
authfs_service: Strong<dyn IAuthFsService>,
- metadata: &Metadata,
+ fd_annotation: &FdAnnotation,
) -> Result<CompilerOutput> {
// Mount authfs (via authfs_service). The authfs instance unmounts once the `authfs` variable
// is out of scope.
- let authfs_config = build_authfs_config(metadata);
+ let authfs_config = build_authfs_config(fd_annotation);
let authfs = authfs_service.mount(&authfs_config)?;
// The task expects to receive FD numbers that match its flags (e.g. --zip-fd=42) prepared
@@ -135,18 +135,18 @@
})
}
-fn build_authfs_config(metadata: &Metadata) -> AuthFsConfig {
+fn build_authfs_config(fd_annotation: &FdAnnotation) -> AuthFsConfig {
AuthFsConfig {
port: 3264, // TODO: support dynamic port
- inputFdAnnotations: metadata
- .input_fd_annotations
+ inputFdAnnotations: fd_annotation
+ .input_fds
.iter()
- .map(|x| InputFdAnnotation { fd: x.fd, fileSize: x.file_size })
+ .map(|fd| InputFdAnnotation { fd: *fd })
.collect(),
- outputFdAnnotations: metadata
- .output_fd_annotations
+ outputFdAnnotations: fd_annotation
+ .output_fds
.iter()
- .map(|x| OutputFdAnnotation { fd: x.fd })
+ .map(|fd| OutputFdAnnotation { fd: *fd })
.collect(),
}
}
diff --git a/compos/src/compsvc.rs b/compos/src/compsvc.rs
index 4a19030..ed5534e 100644
--- a/compos/src/compsvc.rs
+++ b/compos/src/compsvc.rs
@@ -32,8 +32,8 @@
use compos_aidl_interface::aidl::com::android::compos::{
CompOsKeyData::CompOsKeyData,
CompilationResult::CompilationResult,
+ FdAnnotation::FdAnnotation,
ICompOsService::{BnCompOsService, ICompOsService},
- Metadata::Metadata,
};
use compos_aidl_interface::binder::{
BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status, Strong,
@@ -85,14 +85,19 @@
}
}
- fn compile(&self, args: &[String], metadata: &Metadata) -> BinderResult<CompilationResult> {
+ fn compile(
+ &self,
+ args: &[String],
+ fd_annotation: &FdAnnotation,
+ ) -> BinderResult<CompilationResult> {
let authfs_service = get_authfs_service()?;
- let output = compile(&self.dex2oat_path, args, authfs_service, metadata).map_err(|e| {
- new_binder_exception(
- ExceptionCode::SERVICE_SPECIFIC,
- format!("Compilation failed: {}", e),
- )
- })?;
+ let output =
+ compile(&self.dex2oat_path, args, authfs_service, fd_annotation).map_err(|e| {
+ new_binder_exception(
+ ExceptionCode::SERVICE_SPECIFIC,
+ format!("Compilation failed: {}", e),
+ )
+ })?;
match output {
CompilerOutput::Digests { oat, vdex, image } => {
let key = &*self.key_blob.read().unwrap();
diff --git a/compos/src/pvm_exec.rs b/compos/src/pvm_exec.rs
index 99eddfc..27802e3 100644
--- a/compos/src/pvm_exec.rs
+++ b/compos/src/pvm_exec.rs
@@ -32,14 +32,12 @@
use log::{debug, error, warn};
use minijail::Minijail;
use nix::fcntl::{fcntl, FcntlArg::F_GETFD};
-use nix::sys::stat::fstat;
use std::os::unix::io::RawFd;
use std::path::Path;
use std::process::exit;
use compos_aidl_interface::aidl::com::android::compos::{
- ICompOsService::ICompOsService, InputFdAnnotation::InputFdAnnotation, Metadata::Metadata,
- OutputFdAnnotation::OutputFdAnnotation,
+ FdAnnotation::FdAnnotation, ICompOsService::ICompOsService,
};
use compos_aidl_interface::binder::Strong;
@@ -65,7 +63,7 @@
}
}
-fn spawn_fd_server(metadata: &Metadata, debuggable: bool) -> Result<Minijail> {
+fn spawn_fd_server(fd_annotation: &FdAnnotation, debuggable: bool) -> Result<Minijail> {
let mut inheritable_fds = if debuggable {
vec![1, 2] // inherit/redirect stdout/stderr for debugging
} else {
@@ -73,15 +71,15 @@
};
let mut args = vec![FD_SERVER_BIN.to_string(), "--rpc-binder".to_string()];
- for metadata in &metadata.input_fd_annotations {
+ for fd in &fd_annotation.input_fds {
args.push("--ro-fds".to_string());
- args.push(metadata.fd.to_string());
- inheritable_fds.push(metadata.fd);
+ args.push(fd.to_string());
+ inheritable_fds.push(*fd);
}
- for metadata in &metadata.output_fd_annotations {
+ for fd in &fd_annotation.output_fds {
args.push("--rw-fds".to_string());
- args.push(metadata.fd.to_string());
- inheritable_fds.push(metadata.fd);
+ args.push(fd.to_string());
+ inheritable_fds.push(*fd);
}
let jail = Minijail::new()?;
@@ -104,7 +102,7 @@
struct Config {
args: Vec<String>,
- metadata: Metadata,
+ fd_annotation: FdAnnotation,
cid: Option<u32>,
debuggable: bool,
}
@@ -133,38 +131,20 @@
.multiple(true))
.get_matches();
- let results: Result<Vec<_>> = matches
- .values_of("in-fd")
- .unwrap_or_default()
- .map(|arg| {
- let fd = parse_arg_fd(arg)?;
- let file_size = fstat(fd)?.st_size;
- Ok(InputFdAnnotation { fd, file_size })
- })
- .collect();
- let input_fd_annotations = results?;
+ let results: Result<Vec<_>> =
+ matches.values_of("in-fd").unwrap_or_default().map(parse_arg_fd).collect();
+ let input_fds = results?;
- let results: Result<Vec<_>> = matches
- .values_of("out-fd")
- .unwrap_or_default()
- .map(|arg| {
- let fd = parse_arg_fd(arg)?;
- Ok(OutputFdAnnotation { fd })
- })
- .collect();
- let output_fd_annotations = results?;
+ let results: Result<Vec<_>> =
+ matches.values_of("out-fd").unwrap_or_default().map(parse_arg_fd).collect();
+ let output_fds = results?;
let args: Vec<_> = matches.values_of("args").unwrap().map(|s| s.to_string()).collect();
let cid =
if let Some(arg) = matches.value_of("cid") { Some(arg.parse::<u32>()?) } else { None };
let debuggable = matches.is_present("debug");
- Ok(Config {
- args,
- metadata: Metadata { input_fd_annotations, output_fd_annotations },
- cid,
- debuggable,
- })
+ Ok(Config { args, fd_annotation: FdAnnotation { input_fds, output_fds }, cid, debuggable })
}
fn main() -> Result<()> {
@@ -175,10 +155,10 @@
);
// 1. Parse the command line arguments for collect execution data.
- let Config { args, metadata, cid, debuggable } = parse_args()?;
+ let Config { args, fd_annotation, cid, debuggable } = parse_args()?;
// 2. Spawn and configure a fd_server to serve remote read/write requests.
- let fd_server_jail = spawn_fd_server(&metadata, debuggable)?;
+ let fd_server_jail = spawn_fd_server(&fd_annotation, debuggable)?;
let fd_server_lifetime = scopeguard::guard(fd_server_jail, |fd_server_jail| {
if let Err(e) = fd_server_jail.kill() {
if !matches!(e, minijail::Error::Killed(_)) {
@@ -189,7 +169,7 @@
// 3. Send the command line args to the remote to execute.
let service = if let Some(cid) = cid { get_rpc_binder(cid) } else { get_local_service() }?;
- let result = service.compile(&args, &metadata).context("Binder call failed")?;
+ let result = service.compile(&args, &fd_annotation).context("Binder call failed")?;
// TODO: store/use the signature
debug!(