Merge "[test] Test remote attestation for different kernels" into main
diff --git a/Android.bp b/Android.bp
index 03bea5a..717c902 100644
--- a/Android.bp
+++ b/Android.bp
@@ -14,6 +14,7 @@
// limitations under the License.
package {
+ default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/apex/Android.bp b/apex/Android.bp
index ba42c88..7cc0414 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/apex/empty-payload-apk/Android.bp b/apex/empty-payload-apk/Android.bp
index 72ec392..01bf795 100644
--- a/apex/empty-payload-apk/Android.bp
+++ b/apex/empty-payload-apk/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/apex/permissions/Android.bp b/apex/permissions/Android.bp
index 38fd9a1..0c925ce 100644
--- a/apex/permissions/Android.bp
+++ b/apex/permissions/Android.bp
@@ -14,7 +14,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/apkdmverity/Android.bp b/apkdmverity/Android.bp
index 40c5f72..0cb8ca1 100644
--- a/apkdmverity/Android.bp
+++ b/apkdmverity/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/Android.bp b/authfs/Android.bp
index 8dc6d86..8ac600d 100644
--- a/authfs/Android.bp
+++ b/authfs/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/aidl/Android.bp b/authfs/aidl/Android.bp
index 277a964..9504037 100644
--- a/authfs/aidl/Android.bp
+++ b/authfs/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/fd_server/Android.bp b/authfs/fd_server/Android.bp
index 9a16d04..b02c104 100644
--- a/authfs/fd_server/Android.bp
+++ b/authfs/fd_server/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/service/Android.bp b/authfs/service/Android.bp
index b4d3b09..2101a36 100644
--- a/authfs/service/Android.bp
+++ b/authfs/service/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/src/fsverity/metadata/Android.bp b/authfs/src/fsverity/metadata/Android.bp
index c468b7d..c874c2b 100644
--- a/authfs/src/fsverity/metadata/Android.bp
+++ b/authfs/src/fsverity/metadata/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/tests/benchmarks/Android.bp b/authfs/tests/benchmarks/Android.bp
index 5820cb4..93ba41a 100644
--- a/authfs/tests/benchmarks/Android.bp
+++ b/authfs/tests/benchmarks/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/tests/common/Android.bp b/authfs/tests/common/Android.bp
index 60d2df3..bba329e 100644
--- a/authfs/tests/common/Android.bp
+++ b/authfs/tests/common/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/authfs/tests/hosttests/Android.bp b/authfs/tests/hosttests/Android.bp
index 1e95e10..83ef853 100644
--- a/authfs/tests/hosttests/Android.bp
+++ b/authfs/tests/hosttests/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/Android.bp b/compos/Android.bp
index bf57e27..b840506 100644
--- a/compos/Android.bp
+++ b/compos/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/aidl/Android.bp b/compos/aidl/Android.bp
index 1660837..7036511 100644
--- a/compos/aidl/Android.bp
+++ b/compos/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/apex/Android.bp b/compos/apex/Android.bp
index 8b1ba27..55cc446 100644
--- a/compos/apex/Android.bp
+++ b/compos/apex/Android.bp
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/apk/Android.bp b/compos/apk/Android.bp
index a06a5a4..c6192b9 100644
--- a/compos/apk/Android.bp
+++ b/compos/apk/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/benchmark/Android.bp b/compos/benchmark/Android.bp
index 96d35b4..93927a2 100644
--- a/compos/benchmark/Android.bp
+++ b/compos/benchmark/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/common/Android.bp b/compos/common/Android.bp
index 32bdf8a..01ab7c9 100644
--- a/compos/common/Android.bp
+++ b/compos/common/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/compos_key_helper/Android.bp b/compos/compos_key_helper/Android.bp
index 7d27525..4d86780 100644
--- a/compos/compos_key_helper/Android.bp
+++ b/compos/compos_key_helper/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/composd/Android.bp b/compos/composd/Android.bp
index 96d4da7..b0294dd 100644
--- a/compos/composd/Android.bp
+++ b/compos/composd/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/composd/aidl/Android.bp b/compos/composd/aidl/Android.bp
index 20e3679..56b0b60 100644
--- a/compos/composd/aidl/Android.bp
+++ b/compos/composd/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/composd/native/Android.bp b/compos/composd/native/Android.bp
index a0923ef..f35517f 100644
--- a/compos/composd/native/Android.bp
+++ b/compos/composd/native/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/composd_cmd/Android.bp b/compos/composd_cmd/Android.bp
index 8b7a909..4d3ed5f 100644
--- a/compos/composd_cmd/Android.bp
+++ b/compos/composd_cmd/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/service/Android.bp b/compos/service/Android.bp
index 478ea3b..3dcf8be 100644
--- a/compos/service/Android.bp
+++ b/compos/service/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/tests/Android.bp b/compos/tests/Android.bp
index 1213a16..511ecd0 100644
--- a/compos/tests/Android.bp
+++ b/compos/tests/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/verify/Android.bp b/compos/verify/Android.bp
index 6fba1fd..f4d8695 100644
--- a/compos/verify/Android.bp
+++ b/compos/verify/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/compos/verify/native/Android.bp b/compos/verify/native/Android.bp
index ac2fcfb..695d28b 100644
--- a/compos/verify/native/Android.bp
+++ b/compos/verify/native/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/demo/Android.bp b/demo/Android.bp
index 90e302a..a291ee1 100644
--- a/demo/Android.bp
+++ b/demo/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/demo_native/Android.bp b/demo_native/Android.bp
index facb2bb..7ac0e61 100644
--- a/demo_native/Android.bp
+++ b/demo_native/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/encryptedstore/Android.bp b/encryptedstore/Android.bp
index 225eedd..aa46c35 100644
--- a/encryptedstore/Android.bp
+++ b/encryptedstore/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/javalib/Android.bp b/javalib/Android.bp
index 680d59b..e3cb2e3 100644
--- a/javalib/Android.bp
+++ b/javalib/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/javalib/jni/Android.bp b/javalib/jni/Android.bp
index 24dece2..74a1766 100644
--- a/javalib/jni/Android.bp
+++ b/javalib/jni/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/javalib/src/android/system/virtualmachine/VirtualMachineManager.java b/javalib/src/android/system/virtualmachine/VirtualMachineManager.java
index ff0b6e7..1a4b53a 100644
--- a/javalib/src/android/system/virtualmachine/VirtualMachineManager.java
+++ b/javalib/src/android/system/virtualmachine/VirtualMachineManager.java
@@ -225,7 +225,7 @@
*
* @see #getOrCreate
* @throws VirtualMachineException if the virtual machine exists but could not be successfully
- * retrieved.
+ * retrieved. This can be resolved by calling {@link #delete} on the VM.
* @hide
*/
@SystemApi
diff --git a/launcher/Android.bp b/launcher/Android.bp
index 9835fc9..42c18cb 100644
--- a/launcher/Android.bp
+++ b/launcher/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/apexutil/Android.bp b/libs/apexutil/Android.bp
index 410c3cf..beff58d 100644
--- a/libs/apexutil/Android.bp
+++ b/libs/apexutil/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/apkverify/Android.bp b/libs/apkverify/Android.bp
index e39c46d..4c5a622 100644
--- a/libs/apkverify/Android.bp
+++ b/libs/apkverify/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/apkzip/Android.bp b/libs/apkzip/Android.bp
index f3622b1..dc35b5e 100644
--- a/libs/apkzip/Android.bp
+++ b/libs/apkzip/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/avflog/Android.bp b/libs/avflog/Android.bp
index 7e8daef..695a6c6 100644
--- a/libs/avflog/Android.bp
+++ b/libs/avflog/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/bssl/Android.bp b/libs/bssl/Android.bp
index b023e87..2bb5ba5 100644
--- a/libs/bssl/Android.bp
+++ b/libs/bssl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/bssl/error/Android.bp b/libs/bssl/error/Android.bp
index ebdbc0a..000e385 100644
--- a/libs/bssl/error/Android.bp
+++ b/libs/bssl/error/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/capabilities/Android.bp b/libs/capabilities/Android.bp
index 2799926..55112e1 100644
--- a/libs/capabilities/Android.bp
+++ b/libs/capabilities/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/cstr/Android.bp b/libs/cstr/Android.bp
index 88f43a0..4ea87df 100644
--- a/libs/cstr/Android.bp
+++ b/libs/cstr/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/devicemapper/Android.bp b/libs/devicemapper/Android.bp
index 5c74162..5332469 100644
--- a/libs/devicemapper/Android.bp
+++ b/libs/devicemapper/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/dice/open_dice/Android.bp b/libs/dice/open_dice/Android.bp
index 9481f5d..79d0b96 100644
--- a/libs/dice/open_dice/Android.bp
+++ b/libs/dice/open_dice/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_visibility: [":__subpackages__"],
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/dice/sample_inputs/Android.bp b/libs/dice/sample_inputs/Android.bp
index e5d35a7..013038c 100644
--- a/libs/dice/sample_inputs/Android.bp
+++ b/libs/dice/sample_inputs/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/libs/libfdt/Android.bp b/libs/libfdt/Android.bp
index 7231904..b5f7471 100644
--- a/libs/libfdt/Android.bp
+++ b/libs/libfdt/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
@@ -40,6 +39,7 @@
rustlibs: [
"libcstr",
"liblibfdt_bindgen",
+ "libmemoffset_nostd",
"libzerocopy_nostd",
],
whole_static_libs: [
diff --git a/libs/libfdt/src/ctypes.rs b/libs/libfdt/src/ctypes.rs
new file mode 100644
index 0000000..640d447
--- /dev/null
+++ b/libs/libfdt/src/ctypes.rs
@@ -0,0 +1,52 @@
+// Copyright 2024, 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.
+
+//! Safe zero-cost wrappers around integer values used by libfdt.
+
+use crate::{FdtError, Result};
+
+/// Wrapper guaranteed to contain a valid phandle.
+#[repr(transparent)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
+pub struct Phandle(u32);
+
+impl Phandle {
+ /// Minimum valid value for device tree phandles.
+ pub const MIN: Self = Self(1);
+ /// Maximum valid value for device tree phandles.
+ pub const MAX: Self = Self(libfdt_bindgen::FDT_MAX_PHANDLE);
+
+ /// Creates a new Phandle
+ pub const fn new(value: u32) -> Option<Self> {
+ if Self::MIN.0 <= value && value <= Self::MAX.0 {
+ Some(Self(value))
+ } else {
+ None
+ }
+ }
+}
+
+impl From<Phandle> for u32 {
+ fn from(phandle: Phandle) -> u32 {
+ phandle.0
+ }
+}
+
+impl TryFrom<u32> for Phandle {
+ type Error = FdtError;
+
+ fn try_from(value: u32) -> Result<Self> {
+ Self::new(value).ok_or(FdtError::BadPhandle)
+ }
+}
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index 0249d0d..ab3c83f 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -17,10 +17,12 @@
#![no_std]
+mod ctypes;
mod iterators;
mod libfdt;
mod result;
+pub use ctypes::Phandle;
pub use iterators::{
AddressRange, CellIterator, CompatibleIterator, DescendantsIterator, MemRegIterator,
PropertyIterator, RangesIterator, Reg, RegIterator, SubnodeIterator,
@@ -30,6 +32,7 @@
use core::ffi::{c_int, c_void, CStr};
use core::ops::Range;
use cstr::cstr;
+use libfdt::get_slice_at_ptr;
use result::{fdt_err, fdt_err_expect_zero, fdt_err_or_option};
use zerocopy::AsBytes as _;
@@ -92,17 +95,7 @@
impl FdtPropertyStruct {
fn from_offset(fdt: &Fdt, offset: c_int) -> Result<&Self> {
- let mut len = 0;
- let prop =
- // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
- unsafe { libfdt_bindgen::fdt_get_property_by_offset(fdt.as_ptr(), offset, &mut len) };
- if prop.is_null() {
- fdt_err(len)?;
- return Err(FdtError::Internal); // shouldn't happen.
- }
- // SAFETY: prop is only returned when it points to valid libfdt_bindgen.
- let prop = unsafe { &*prop };
- Ok(prop.as_ref())
+ Ok(fdt.get_property_by_offset(offset)?.as_ref())
}
fn name_offset(&self) -> c_int {
@@ -143,11 +136,7 @@
}
fn next_property(&self) -> Result<Option<Self>> {
- let ret =
- // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
- unsafe { libfdt_bindgen::fdt_next_property_offset(self.fdt.as_ptr(), self.offset) };
-
- if let Some(offset) = fdt_err_or_option(ret)? {
+ if let Some(offset) = self.fdt.next_property_offset(self.offset)? {
Ok(Some(Self::new(self.fdt, offset)?))
} else {
Ok(None)
@@ -216,13 +205,7 @@
/// Returns the node name.
pub fn name(&self) -> Result<&'a CStr> {
- let mut len: c_int = 0;
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor). On success, the
- // function returns valid null terminating string and otherwise returned values are dropped.
- let name = unsafe { libfdt_bindgen::fdt_get_name(self.fdt.as_ptr(), self.offset, &mut len) }
- as *const c_void;
- let len = usize::try_from(fdt_err(len)?).unwrap();
- let name = self.fdt.get_from_ptr(name, len + 1)?;
+ let name = self.fdt.get_name(self.offset)?;
CStr::from_bytes_with_nul(name).map_err(|_| FdtError::Internal)
}
@@ -264,44 +247,7 @@
/// Returns the value of a given property.
pub fn getprop(&self, name: &CStr) -> Result<Option<&'a [u8]>> {
- if let Some((prop, len)) = Self::getprop_internal(self.fdt, self.offset, name)? {
- Ok(Some(self.fdt.get_from_ptr(prop, len)?))
- } else {
- Ok(None)
- }
- }
-
- /// Returns the pointer and size of the property named `name`, in a node at offset `offset`, in
- /// a device tree `fdt`. The pointer is guaranteed to be non-null, in which case error returns.
- fn getprop_internal(
- fdt: &'a Fdt,
- offset: c_int,
- name: &CStr,
- ) -> Result<Option<(*const c_void, usize)>> {
- let mut len: i32 = 0;
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) and the
- // function respects the passed number of characters.
- let prop = unsafe {
- libfdt_bindgen::fdt_getprop_namelen(
- fdt.as_ptr(),
- offset,
- name.as_ptr(),
- // *_namelen functions don't include the trailing nul terminator in 'len'.
- name.to_bytes().len().try_into().map_err(|_| FdtError::BadPath)?,
- &mut len as *mut i32,
- )
- } as *const u8;
-
- let Some(len) = fdt_err_or_option(len)? else {
- return Ok(None); // Property was not found.
- };
- let len = usize::try_from(len).unwrap();
-
- if prop.is_null() {
- // We expected an error code in len but still received a valid value?!
- return Err(FdtError::Internal);
- }
- Ok(Some((prop.cast::<c_void>(), len)))
+ self.fdt.getprop_namelen(self.offset, name.to_bytes())
}
/// Returns reference to the containing device tree.
@@ -365,11 +311,7 @@
}
fn first_property(&self) -> Result<Option<FdtProperty<'a>>> {
- let ret =
- // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
- unsafe { libfdt_bindgen::fdt_first_property_offset(self.fdt.as_ptr(), self.offset) };
-
- if let Some(offset) = fdt_err_or_option(ret)? {
+ if let Some(offset) = self.fdt.first_property_offset(self.offset)? {
Ok(Some(FdtProperty::new(self.fdt, offset)?))
} else {
Ok(None)
@@ -410,41 +352,6 @@
}
}
-/// Phandle of a FDT node
-#[repr(transparent)]
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
-pub struct Phandle(u32);
-
-impl Phandle {
- /// Minimum valid value for device tree phandles.
- pub const MIN: Self = Self(1);
- /// Maximum valid value for device tree phandles.
- pub const MAX: Self = Self(libfdt_bindgen::FDT_MAX_PHANDLE);
-
- /// Creates a new Phandle
- pub const fn new(value: u32) -> Option<Self> {
- if Self::MIN.0 <= value && value <= Self::MAX.0 {
- Some(Self(value))
- } else {
- None
- }
- }
-}
-
-impl From<Phandle> for u32 {
- fn from(phandle: Phandle) -> u32 {
- phandle.0
- }
-}
-
-impl TryFrom<u32> for Phandle {
- type Error = FdtError;
-
- fn try_from(value: u32) -> Result<Self> {
- Self::new(value).ok_or(FdtError::BadPhandle)
- }
-}
-
/// Mutable FDT node.
#[derive(Debug)]
pub struct FdtNodeMut<'a> {
@@ -455,54 +362,20 @@
impl<'a> FdtNodeMut<'a> {
/// Appends a property name-value (possibly empty) pair to the given node.
pub fn appendprop<T: AsRef<[u8]>>(&mut self, name: &CStr, value: &T) -> Result<()> {
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
- let ret = unsafe {
- libfdt_bindgen::fdt_appendprop(
- self.fdt.as_mut_ptr(),
- self.offset,
- name.as_ptr(),
- value.as_ref().as_ptr().cast::<c_void>(),
- value.as_ref().len().try_into().map_err(|_| FdtError::BadValue)?,
- )
- };
-
- fdt_err_expect_zero(ret)
+ self.fdt.appendprop(self.offset, name, value.as_ref())
}
/// Appends a (address, size) pair property to the given node.
pub fn appendprop_addrrange(&mut self, name: &CStr, addr: u64, size: u64) -> Result<()> {
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
- let ret = unsafe {
- libfdt_bindgen::fdt_appendprop_addrrange(
- self.fdt.as_mut_ptr(),
- self.parent()?.offset,
- self.offset,
- name.as_ptr(),
- addr,
- size,
- )
- };
-
- fdt_err_expect_zero(ret)
+ let parent = self.parent()?.offset;
+ self.fdt.appendprop_addrrange(parent, self.offset, name, addr, size)
}
/// Sets a property name-value pair to the given node.
///
/// This may create a new prop or replace existing value.
pub fn setprop(&mut self, name: &CStr, value: &[u8]) -> Result<()> {
- // SAFETY: New value size is constrained to the DT totalsize
- // (validated by underlying libfdt).
- let ret = unsafe {
- libfdt_bindgen::fdt_setprop(
- self.fdt.as_mut_ptr(),
- self.offset,
- name.as_ptr(),
- value.as_ptr().cast::<c_void>(),
- value.len().try_into().map_err(|_| FdtError::BadValue)?,
- )
- };
-
- fdt_err_expect_zero(ret)
+ self.fdt.setprop(self.offset, name, value)
}
/// Sets the value of the given property with the given value, and ensure that the given
@@ -510,18 +383,7 @@
///
/// This can only be used to replace existing value.
pub fn setprop_inplace(&mut self, name: &CStr, value: &[u8]) -> Result<()> {
- // SAFETY: fdt size is not altered
- let ret = unsafe {
- libfdt_bindgen::fdt_setprop_inplace(
- self.fdt.as_mut_ptr(),
- self.offset,
- name.as_ptr(),
- value.as_ptr().cast::<c_void>(),
- value.len().try_into().map_err(|_| FdtError::BadValue)?,
- )
- };
-
- fdt_err_expect_zero(ret)
+ self.fdt.setprop_inplace(self.offset, name, value)
}
/// Sets the value of the given (address, size) pair property with the given value, and
@@ -530,63 +392,35 @@
/// This can only be used to replace existing value.
pub fn setprop_addrrange_inplace(&mut self, name: &CStr, addr: u64, size: u64) -> Result<()> {
let pair = [addr.to_be(), size.to_be()];
- self.setprop_inplace(name, pair.as_bytes())
+ self.fdt.setprop_inplace(self.offset, name, pair.as_bytes())
}
/// Sets a flag-like empty property.
///
/// This may create a new prop or replace existing value.
pub fn setprop_empty(&mut self, name: &CStr) -> Result<()> {
- self.setprop(name, &[])
+ self.fdt.setprop(self.offset, name, &[])
}
/// Deletes the given property.
pub fn delprop(&mut self, name: &CStr) -> Result<()> {
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
- // library locates the node's property. Removing the property may shift the offsets of
- // other nodes and properties but the borrow checker should prevent this function from
- // being called when FdtNode instances are in use.
- let ret = unsafe {
- libfdt_bindgen::fdt_delprop(self.fdt.as_mut_ptr(), self.offset, name.as_ptr())
- };
-
- fdt_err_expect_zero(ret)
+ self.fdt.delprop(self.offset, name)
}
/// Deletes the given property effectively from DT, by setting it with FDT_NOP.
pub fn nop_property(&mut self, name: &CStr) -> Result<()> {
- // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
- // library locates the node's property.
- let ret = unsafe {
- libfdt_bindgen::fdt_nop_property(self.fdt.as_mut_ptr(), self.offset, name.as_ptr())
- };
-
- fdt_err_expect_zero(ret)
+ self.fdt.nop_property(self.offset, name)
}
/// Trims the size of the given property to new_size.
pub fn trimprop(&mut self, name: &CStr, new_size: usize) -> Result<()> {
- let (prop, len) =
- FdtNode::getprop_internal(self.fdt, self.offset, name)?.ok_or(FdtError::NotFound)?;
- if len == new_size {
- return Ok(());
- }
- if new_size > len {
- return Err(FdtError::NoSpace);
- }
+ let prop = self.as_node().getprop(name)?.ok_or(FdtError::NotFound)?;
- // SAFETY: new_size is smaller than the old size
- let ret = unsafe {
- libfdt_bindgen::fdt_setprop(
- self.fdt.as_mut_ptr(),
- self.offset,
- name.as_ptr(),
- prop.cast::<c_void>(),
- new_size.try_into().map_err(|_| FdtError::BadValue)?,
- )
- };
-
- fdt_err_expect_zero(ret)
+ match prop.len() {
+ x if x == new_size => Ok(()),
+ x if x < new_size => Err(FdtError::NoSpace),
+ _ => self.fdt.setprop_placeholder(self.offset, name, new_size).map(|_| ()),
+ }
}
/// Returns reference to the containing device tree.
@@ -896,30 +730,21 @@
/// Returns max phandle in the tree.
pub fn max_phandle(&self) -> Result<Phandle> {
- let mut phandle: u32 = 0;
- // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
- let ret = unsafe { libfdt_bindgen::fdt_find_max_phandle(self.as_ptr(), &mut phandle) };
-
- fdt_err_expect_zero(ret)?;
- phandle.try_into()
+ self.find_max_phandle()
}
/// Returns a node with the phandle
pub fn node_with_phandle(&self, phandle: Phandle) -> Result<Option<FdtNode>> {
- let offset = self.node_offset_with_phandle(phandle)?;
+ let offset = self.node_offset_by_phandle(phandle)?;
+
Ok(offset.map(|offset| FdtNode { fdt: self, offset }))
}
/// Returns a mutable node with the phandle
pub fn node_mut_with_phandle(&mut self, phandle: Phandle) -> Result<Option<FdtNodeMut>> {
- let offset = self.node_offset_with_phandle(phandle)?;
- Ok(offset.map(|offset| FdtNodeMut { fdt: self, offset }))
- }
+ let offset = self.node_offset_by_phandle(phandle)?;
- fn node_offset_with_phandle(&self, phandle: Phandle) -> Result<Option<c_int>> {
- // SAFETY: Accesses are constrained to the DT totalsize.
- let ret = unsafe { libfdt_bindgen::fdt_node_offset_by_phandle(self.as_ptr(), phandle.0) };
- fdt_err_or_option(ret)
+ Ok(offset.map(|offset| FdtNodeMut { fdt: self, offset }))
}
/// Returns the mutable root node of the tree.
@@ -952,20 +777,7 @@
}
fn get_from_ptr(&self, ptr: *const c_void, len: usize) -> Result<&[u8]> {
- let ptr = ptr as usize;
- let offset = ptr.checked_sub(self.as_ptr() as usize).ok_or(FdtError::Internal)?;
- self.buffer.get(offset..(offset + len)).ok_or(FdtError::Internal)
- }
-
- fn string(&self, offset: c_int) -> Result<&CStr> {
- // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
- let res = unsafe { libfdt_bindgen::fdt_string(self.as_ptr(), offset) };
- if res.is_null() {
- return Err(FdtError::Internal);
- }
-
- // SAFETY: Non-null return from fdt_string() is valid null-terminating string within FDT.
- Ok(unsafe { CStr::from_ptr(res) })
+ get_slice_at_ptr(self.as_fdt_slice(), ptr.cast(), len).ok_or(FdtError::Internal)
}
/// Returns a shared pointer to the device tree.
diff --git a/libs/libfdt/src/libfdt.rs b/libs/libfdt/src/libfdt.rs
index 7e3b65a..7737718 100644
--- a/libs/libfdt/src/libfdt.rs
+++ b/libs/libfdt/src/libfdt.rs
@@ -19,9 +19,10 @@
//! adapted to their use-cases (e.g. alloc-based userspace or statically allocated no_std).
use core::ffi::{c_int, CStr};
+use core::mem;
use core::ptr;
-use crate::{fdt_err, fdt_err_expect_zero, fdt_err_or_option, FdtError, Result};
+use crate::{fdt_err, fdt_err_expect_zero, fdt_err_or_option, FdtError, Phandle, Result};
// Function names are the C function names without the `fdt_` prefix.
@@ -78,6 +79,16 @@
fdt_err_or_option(ret)
}
+ /// Safe wrapper around `fdt_node_offset_by_phandle()` (C function).
+ fn node_offset_by_phandle(&self, phandle: Phandle) -> Result<Option<c_int>> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ let phandle = phandle.into();
+ // SAFETY: Accesses are constrained to the DT totalsize.
+ let ret = unsafe { libfdt_bindgen::fdt_node_offset_by_phandle(fdt, phandle) };
+
+ fdt_err_or_option(ret)
+ }
+
/// Safe wrapper around `fdt_node_offset_by_compatible()` (C function).
fn node_offset_by_compatible(&self, prev: c_int, compatible: &CStr) -> Result<Option<c_int>> {
let fdt = self.as_fdt_slice().as_ptr().cast();
@@ -175,6 +186,106 @@
Ok(fdt_err(ret)?.try_into().unwrap())
}
+
+ /// Safe wrapper around `fdt_get_name()` (C function).
+ fn get_name(&self, node: c_int) -> Result<&[u8]> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ let mut len = 0;
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor). On success, the
+ // function returns valid null terminating string and otherwise returned values are dropped.
+ let name = unsafe { libfdt_bindgen::fdt_get_name(fdt, node, &mut len) };
+ let len = usize::try_from(fdt_err(len)?).unwrap().checked_add(1).unwrap();
+
+ get_slice_at_ptr(self.as_fdt_slice(), name.cast(), len).ok_or(FdtError::Internal)
+ }
+
+ /// Safe wrapper around `fdt_getprop_namelen()` (C function).
+ fn getprop_namelen(&self, node: c_int, name: &[u8]) -> Result<Option<&[u8]>> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ let namelen = name.len().try_into().map_err(|_| FdtError::BadPath)?;
+ let name = name.as_ptr().cast();
+ let mut len = 0;
+ let prop =
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) and the
+ // function respects the passed number of characters.
+ unsafe { libfdt_bindgen::fdt_getprop_namelen(fdt, node, name, namelen, &mut len) };
+
+ if let Some(len) = fdt_err_or_option(len)? {
+ let len = usize::try_from(len).unwrap();
+ let bytes = get_slice_at_ptr(self.as_fdt_slice(), prop.cast(), len);
+
+ Ok(Some(bytes.ok_or(FdtError::Internal)?))
+ } else {
+ Ok(None)
+ }
+ }
+
+ /// Safe wrapper around `fdt_get_property_by_offset()` (C function).
+ fn get_property_by_offset(&self, offset: c_int) -> Result<&libfdt_bindgen::fdt_property> {
+ let mut len = 0;
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
+ let prop = unsafe { libfdt_bindgen::fdt_get_property_by_offset(fdt, offset, &mut len) };
+
+ let data_len = fdt_err(len)?.try_into().unwrap();
+ // TODO(stable_feature(offset_of)): mem::offset_of!(fdt_property, data).
+ let data_offset = memoffset::offset_of!(libfdt_bindgen::fdt_property, data);
+ let len = data_offset.checked_add(data_len).ok_or(FdtError::Internal)?;
+
+ if !is_aligned(prop) || get_slice_at_ptr(self.as_fdt_slice(), prop.cast(), len).is_none() {
+ return Err(FdtError::Internal);
+ }
+
+ // SAFETY: The pointer is properly aligned, struct is fully contained in the DT slice.
+ let prop = unsafe { &*prop };
+
+ if data_len != u32::from_be(prop.len).try_into().unwrap() {
+ return Err(FdtError::BadLayout);
+ }
+
+ Ok(prop)
+ }
+
+ /// Safe wrapper around `fdt_first_property_offset()` (C function).
+ fn first_property_offset(&self, node: c_int) -> Result<Option<c_int>> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
+ let ret = unsafe { libfdt_bindgen::fdt_first_property_offset(fdt, node) };
+
+ fdt_err_or_option(ret)
+ }
+
+ /// Safe wrapper around `fdt_next_property_offset()` (C function).
+ fn next_property_offset(&self, prev: c_int) -> Result<Option<c_int>> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
+ let ret = unsafe { libfdt_bindgen::fdt_next_property_offset(fdt, prev) };
+
+ fdt_err_or_option(ret)
+ }
+
+ /// Safe wrapper around `fdt_find_max_phandle()` (C function).
+ fn find_max_phandle(&self) -> Result<Phandle> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ let mut phandle = 0;
+ // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
+ let ret = unsafe { libfdt_bindgen::fdt_find_max_phandle(fdt, &mut phandle) };
+
+ fdt_err_expect_zero(ret)?;
+
+ phandle.try_into()
+ }
+
+ /// Safe wrapper around `fdt_string()` (C function).
+ fn string(&self, offset: c_int) -> Result<&CStr> {
+ let fdt = self.as_fdt_slice().as_ptr().cast();
+ // SAFETY: Accesses (read-only) are constrained to the DT totalsize.
+ let ptr = unsafe { libfdt_bindgen::fdt_string(fdt, offset) };
+ let bytes =
+ get_slice_from_ptr(self.as_fdt_slice(), ptr.cast()).ok_or(FdtError::Internal)?;
+
+ CStr::from_bytes_until_nul(bytes).map_err(|_| FdtError::Internal)
+ }
}
/// Wrapper for the read-write libfdt.h functions.
@@ -216,4 +327,129 @@
fdt_err(ret)
}
+
+ /// Safe wrapper around `fdt_setprop()` (C function).
+ fn setprop(&mut self, node: c_int, name: &CStr, value: &[u8]) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ let len = value.len().try_into().map_err(|_| FdtError::BadValue)?;
+ let value = value.as_ptr().cast();
+ // SAFETY: New value size is constrained to the DT totalsize
+ // (validated by underlying libfdt).
+ let ret = unsafe { libfdt_bindgen::fdt_setprop(fdt, node, name, value, len) };
+
+ fdt_err_expect_zero(ret)
+ }
+
+ /// Safe wrapper around `fdt_setprop_placeholder()` (C function).
+ fn setprop_placeholder(&mut self, node: c_int, name: &CStr, size: usize) -> Result<&mut [u8]> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ let len = size.try_into().unwrap();
+ let mut data = ptr::null_mut();
+ let ret =
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
+ unsafe { libfdt_bindgen::fdt_setprop_placeholder(fdt, node, name, len, &mut data) };
+
+ fdt_err_expect_zero(ret)?;
+
+ get_mut_slice_at_ptr(self.as_fdt_slice_mut(), data.cast(), size).ok_or(FdtError::Internal)
+ }
+
+ /// Safe wrapper around `fdt_setprop_inplace()` (C function).
+ fn setprop_inplace(&mut self, node: c_int, name: &CStr, value: &[u8]) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ let len = value.len().try_into().map_err(|_| FdtError::BadValue)?;
+ let value = value.as_ptr().cast();
+ // SAFETY: New value size is constrained to the DT totalsize
+ // (validated by underlying libfdt).
+ let ret = unsafe { libfdt_bindgen::fdt_setprop_inplace(fdt, node, name, value, len) };
+
+ fdt_err_expect_zero(ret)
+ }
+
+ /// Safe wrapper around `fdt_appendprop()` (C function).
+ fn appendprop(&mut self, node: c_int, name: &CStr, value: &[u8]) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ let len = value.len().try_into().map_err(|_| FdtError::BadValue)?;
+ let value = value.as_ptr().cast();
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
+ let ret = unsafe { libfdt_bindgen::fdt_appendprop(fdt, node, name, value, len) };
+
+ fdt_err_expect_zero(ret)
+ }
+
+ /// Safe wrapper around `fdt_appendprop_addrrange()` (C function).
+ fn appendprop_addrrange(
+ &mut self,
+ parent: c_int,
+ node: c_int,
+ name: &CStr,
+ addr: u64,
+ size: u64,
+ ) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor).
+ let ret = unsafe {
+ libfdt_bindgen::fdt_appendprop_addrrange(fdt, parent, node, name, addr, size)
+ };
+
+ fdt_err_expect_zero(ret)
+ }
+
+ /// Safe wrapper around `fdt_delprop()` (C function).
+ fn delprop(&mut self, node: c_int, name: &CStr) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
+ // library locates the node's property. Removing the property may shift the offsets of
+ // other nodes and properties but the borrow checker should prevent this function from
+ // being called when FdtNode instances are in use.
+ let ret = unsafe { libfdt_bindgen::fdt_delprop(fdt, node, name) };
+
+ fdt_err_expect_zero(ret)
+ }
+
+ /// Safe wrapper around `fdt_nop_property()` (C function).
+ fn nop_property(&mut self, node: c_int, name: &CStr) -> Result<()> {
+ let fdt = self.as_fdt_slice_mut().as_mut_ptr().cast();
+ let name = name.as_ptr();
+ // SAFETY: Accesses are constrained to the DT totalsize (validated by ctor) when the
+ // library locates the node's property.
+ let ret = unsafe { libfdt_bindgen::fdt_nop_property(fdt, node, name) };
+
+ fdt_err_expect_zero(ret)
+ }
+}
+
+pub(crate) fn get_slice_at_ptr(s: &[u8], p: *const u8, len: usize) -> Option<&[u8]> {
+ let offset = get_slice_ptr_offset(s, p)?;
+
+ s.get(offset..offset.checked_add(len)?)
+}
+
+fn get_mut_slice_at_ptr(s: &mut [u8], p: *mut u8, len: usize) -> Option<&mut [u8]> {
+ let offset = get_slice_ptr_offset(s, p)?;
+
+ s.get_mut(offset..offset.checked_add(len)?)
+}
+
+fn get_slice_from_ptr(s: &[u8], p: *const u8) -> Option<&[u8]> {
+ s.get(get_slice_ptr_offset(s, p)?..)
+}
+
+fn get_slice_ptr_offset(s: &[u8], p: *const u8) -> Option<usize> {
+ s.as_ptr_range().contains(&p).then(|| {
+ // SAFETY: Both pointers are in bounds, derive from the same object, and size_of::<T>()=1.
+ (unsafe { p.offset_from(s.as_ptr()) }) as usize
+ // TODO(stable_feature(ptr_sub_ptr)): p.sub_ptr()
+ })
+}
+
+// TODO(stable_feature(pointer_is_aligned)): p.is_aligned()
+fn is_aligned<T>(p: *const T) -> bool {
+ (p as usize) % mem::align_of::<T>() == 0
}
diff --git a/libs/vbmeta/Android.bp b/libs/vbmeta/Android.bp
index 48f9e51..4fb6ae4 100644
--- a/libs/vbmeta/Android.bp
+++ b/libs/vbmeta/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/Android.bp b/microdroid/Android.bp
index e2d7af4..233754a 100644
--- a/microdroid/Android.bp
+++ b/microdroid/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/init_debug_policy/Android.bp b/microdroid/init_debug_policy/Android.bp
index 320417d..2a87ac9 100644
--- a/microdroid/init_debug_policy/Android.bp
+++ b/microdroid/init_debug_policy/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/initrd/Android.bp b/microdroid/initrd/Android.bp
index 6f1c9a1..ec971fa 100644
--- a/microdroid/initrd/Android.bp
+++ b/microdroid/initrd/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/kdump/Android.bp b/microdroid/kdump/Android.bp
index 5d129f4..6c85c43 100644
--- a/microdroid/kdump/Android.bp
+++ b/microdroid/kdump/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/kdump/kernel/Android.bp b/microdroid/kdump/kernel/Android.bp
index 9d241b4..0705875 100644
--- a/microdroid/kdump/kernel/Android.bp
+++ b/microdroid/kdump/kernel/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["microdroid_crashdump_kernel_license"],
}
diff --git a/microdroid/kernel/arm64/Android.bp b/microdroid/kernel/arm64/Android.bp
index e014509..0975993 100644
--- a/microdroid/kernel/arm64/Android.bp
+++ b/microdroid/kernel/arm64/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["microdroid_kernel_prebuilts_6.1_arm64_license"],
}
diff --git a/microdroid/kernel/x86_64/Android.bp b/microdroid/kernel/x86_64/Android.bp
index f7161de..b3041cd 100644
--- a/microdroid/kernel/x86_64/Android.bp
+++ b/microdroid/kernel/x86_64/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["microdroid_kernel_prebuilts_6.1_x86_64_license"],
}
diff --git a/microdroid/payload/Android.bp b/microdroid/payload/Android.bp
index e67a6d5..06764a5 100644
--- a/microdroid/payload/Android.bp
+++ b/microdroid/payload/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/payload/config/Android.bp b/microdroid/payload/config/Android.bp
index 7abee15..4c72b97 100644
--- a/microdroid/payload/config/Android.bp
+++ b/microdroid/payload/config/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid/payload/metadata/Android.bp b/microdroid/payload/metadata/Android.bp
index be87fb8..cd182fc 100644
--- a/microdroid/payload/metadata/Android.bp
+++ b/microdroid/payload/metadata/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid_manager/Android.bp b/microdroid_manager/Android.bp
index 0174ce4..81bb409 100644
--- a/microdroid_manager/Android.bp
+++ b/microdroid_manager/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/microdroid_manager/aidl/Android.bp b/microdroid_manager/aidl/Android.bp
index be035df..353e9cc 100644
--- a/microdroid_manager/aidl/Android.bp
+++ b/microdroid_manager/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/pvmfw/Android.bp b/pvmfw/Android.bp
index 110d46a..9a2b3ef 100644
--- a/pvmfw/Android.bp
+++ b/pvmfw/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/pvmfw/avb/Android.bp b/pvmfw/avb/Android.bp
index 3bb8354..6101a0c 100644
--- a/pvmfw/avb/Android.bp
+++ b/pvmfw/avb/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/pvmfw/avb/fuzz/Android.bp b/pvmfw/avb/fuzz/Android.bp
index fe3af0f..e970eed 100644
--- a/pvmfw/avb/fuzz/Android.bp
+++ b/pvmfw/avb/fuzz/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/client_vm_csr/Android.bp b/service_vm/client_vm_csr/Android.bp
index e2ac573..8d738d8 100644
--- a/service_vm/client_vm_csr/Android.bp
+++ b/service_vm/client_vm_csr/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/comm/Android.bp b/service_vm/comm/Android.bp
index 23ff202..bf923a4 100644
--- a/service_vm/comm/Android.bp
+++ b/service_vm/comm/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/demo_apk/Android.bp b/service_vm/demo_apk/Android.bp
index 5644819..3750fe6 100644
--- a/service_vm/demo_apk/Android.bp
+++ b/service_vm/demo_apk/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/fake_chain/Android.bp b/service_vm/fake_chain/Android.bp
index 7735aac..2bc7b4e 100644
--- a/service_vm/fake_chain/Android.bp
+++ b/service_vm/fake_chain/Android.bp
@@ -13,7 +13,6 @@
// limitations under the License.
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/kernel/Android.bp b/service_vm/kernel/Android.bp
index 3817495..79158e6 100644
--- a/service_vm/kernel/Android.bp
+++ b/service_vm/kernel/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/manager/Android.bp b/service_vm/manager/Android.bp
index 6e186a5..6469212 100644
--- a/service_vm/manager/Android.bp
+++ b/service_vm/manager/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/service_vm/requests/Android.bp b/service_vm/requests/Android.bp
index 5a49207..57da012 100644
--- a/service_vm/requests/Android.bp
+++ b/service_vm/requests/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/aidl/Android.bp b/tests/aidl/Android.bp
index 7e22646..ed4e8ff 100644
--- a/tests/aidl/Android.bp
+++ b/tests/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/benchmark/Android.bp b/tests/benchmark/Android.bp
index c31c929..413ffe4 100644
--- a/tests/benchmark/Android.bp
+++ b/tests/benchmark/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/benchmark/src/jni/Android.bp b/tests/benchmark/src/jni/Android.bp
index 06de3e5..bfc3ef3 100644
--- a/tests/benchmark/src/jni/Android.bp
+++ b/tests/benchmark/src/jni/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/benchmark_hostside/Android.bp b/tests/benchmark_hostside/Android.bp
index 8727b05..b613a8a 100644
--- a/tests/benchmark_hostside/Android.bp
+++ b/tests/benchmark_hostside/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/helper/Android.bp b/tests/helper/Android.bp
index 9223391..614c70c 100644
--- a/tests/helper/Android.bp
+++ b/tests/helper/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
index 15e175b..8e11218 100644
--- a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
+++ b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
@@ -150,8 +150,15 @@
public VirtualMachine forceCreateNewVirtualMachine(String name, VirtualMachineConfig config)
throws VirtualMachineException {
final VirtualMachineManager vmm = getVirtualMachineManager();
- VirtualMachine existingVm = vmm.get(name);
- if (existingVm != null) {
+ boolean deleteExisting;
+ try {
+ deleteExisting = vmm.get(name) != null;
+ } catch (VirtualMachineException e) {
+ // VM exists, i.e. there are some files for it, but they could not be successfully
+ // loaded.
+ deleteExisting = true;
+ }
+ if (deleteExisting) {
vmm.delete(name);
}
return vmm.create(name, config);
diff --git a/tests/hostside/Android.bp b/tests/hostside/Android.bp
index 2cfaffa..e3d9cbe 100644
--- a/tests/hostside/Android.bp
+++ b/tests/hostside/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/hostside/helper/Android.bp b/tests/hostside/helper/Android.bp
index 890e14a..75553d0 100644
--- a/tests/hostside/helper/Android.bp
+++ b/tests/hostside/helper/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/no_avf/Android.bp b/tests/no_avf/Android.bp
index cdc9e9f..22d099e 100644
--- a/tests/no_avf/Android.bp
+++ b/tests/no_avf/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/pvmfw/Android.bp b/tests/pvmfw/Android.bp
index 03dcc35..c12f67a 100644
--- a/tests/pvmfw/Android.bp
+++ b/tests/pvmfw/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/pvmfw/helper/Android.bp b/tests/pvmfw/helper/Android.bp
index 7258c68..1b96842 100644
--- a/tests/pvmfw/helper/Android.bp
+++ b/tests/pvmfw/helper/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/pvmfw/tools/Android.bp b/tests/pvmfw/tools/Android.bp
index e4a31d5..7bd3ef5 100644
--- a/tests/pvmfw/tools/Android.bp
+++ b/tests/pvmfw/tools/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index 86172b0..2a04103 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
index 1dd0309..4e340f0 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -477,7 +477,7 @@
.setProtectedVm(mProtectedVm)
.setPayloadBinaryName("binary.so")
.setApkPath("/apk/path")
- .addExtraApk("package.name1:split")
+ .addExtraApk("package.name1")
.addExtraApk("package.name2")
.setDebugLevel(DEBUG_LEVEL_FULL)
.setMemoryBytes(42)
@@ -488,7 +488,7 @@
assertThat(maximal.getApkPath()).isEqualTo("/apk/path");
assertThat(maximal.getExtraApks())
- .containsExactly("package.name1:split", "package.name2")
+ .containsExactly("package.name1", "package.name2")
.inOrder();
assertThat(maximal.getDebugLevel()).isEqualTo(DEBUG_LEVEL_FULL);
assertThat(maximal.getMemoryBytes()).isEqualTo(42);
@@ -1001,8 +1001,7 @@
.setDebugLevel(fromLevel)
.setVmOutputCaptured(false);
VirtualMachineConfig normalConfig = builder.build();
- forceCreateNewVirtualMachine("test_vm", normalConfig);
- assertThat(tryBootVm(TAG, "test_vm").payloadStarted).isTrue();
+ assertThat(tryBootVmWithConfig(normalConfig, "test_vm").payloadStarted).isTrue();
// Try to run the VM again with the previous instance.img
// We need to make sure that no changes on config don't invalidate the identity, to compare
@@ -1203,8 +1202,7 @@
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
- forceCreateNewVirtualMachine(vmName, config);
- assertThat(tryBootVm(TAG, vmName).payloadStarted).isTrue();
+ assertThat(tryBootVmWithConfig(config, vmName).payloadStarted).isTrue();
File instanceImgPath = getVmFile(vmName, "instance.img");
return new RandomAccessFile(instanceImgPath, "rw");
}
@@ -1257,13 +1255,12 @@
@Test
public void bootFailsWhenConfigIsInvalid() throws Exception {
grantPermission(VirtualMachine.USE_CUSTOM_VIRTUAL_MACHINE_PERMISSION);
- VirtualMachineConfig normalConfig =
+ VirtualMachineConfig config =
newVmConfigBuilderWithPayloadConfig("assets/" + os() + "/vm_config_no_task.json")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
- forceCreateNewVirtualMachine("test_vm_invalid_config", normalConfig);
- BootResult bootResult = tryBootVm(TAG, "test_vm_invalid_config");
+ BootResult bootResult = tryBootVmWithConfig(config, "test_vm_invalid_config");
assertThat(bootResult.payloadStarted).isFalse();
assertThat(bootResult.deathReason).isEqualTo(
VirtualMachineCallback.STOP_REASON_MICRODROID_INVALID_PAYLOAD_CONFIG);
@@ -1271,17 +1268,49 @@
@Test
public void bootFailsWhenBinaryNameIsInvalid() throws Exception {
- VirtualMachineConfig.Builder builder =
- newVmConfigBuilderWithPayloadBinary("DoesNotExist.so");
- VirtualMachineConfig normalConfig = builder.setDebugLevel(DEBUG_LEVEL_FULL).build();
- forceCreateNewVirtualMachine("test_vm_invalid_binary_path", normalConfig);
+ VirtualMachineConfig config =
+ newVmConfigBuilderWithPayloadBinary("DoesNotExist.so")
+ .setDebugLevel(DEBUG_LEVEL_FULL)
+ .build();
- BootResult bootResult = tryBootVm(TAG, "test_vm_invalid_binary_path");
+ BootResult bootResult = tryBootVmWithConfig(config, "test_vm_invalid_binary_path");
assertThat(bootResult.payloadStarted).isFalse();
assertThat(bootResult.deathReason)
.isEqualTo(VirtualMachineCallback.STOP_REASON_MICRODROID_UNKNOWN_RUNTIME_ERROR);
}
+ @Test
+ public void bootFailsWhenApkPathIsInvalid() {
+ VirtualMachineConfig config =
+ newVmConfigBuilderWithPayloadBinary("MicrodroidTestNativeLib.so")
+ .setDebugLevel(DEBUG_LEVEL_FULL)
+ .setApkPath("/does/not/exist")
+ .build();
+
+ assertThrowsVmExceptionContaining(
+ () -> tryBootVmWithConfig(config, "test_vm_invalid_apk_path"),
+ "Failed to open APK");
+ }
+
+ @Test
+ public void bootFailsWhenExtraApkPackageIsInvalid() {
+ VirtualMachineConfig config =
+ newVmConfigBuilderWithPayloadBinary("MicrodroidTestNativeLib.so")
+ .setDebugLevel(DEBUG_LEVEL_FULL)
+ .addExtraApk("com.example.nosuch.package")
+ .build();
+ assertThrowsVmExceptionContaining(
+ () -> tryBootVmWithConfig(config, "test_vm_invalid_extra_apk_package"),
+ "Extra APK package not found");
+ }
+
+ private BootResult tryBootVmWithConfig(VirtualMachineConfig config, String vmName)
+ throws Exception {
+ try (VirtualMachine ignored = forceCreateNewVirtualMachine(vmName, config)) {
+ return tryBootVm(TAG, vmName);
+ }
+ }
+
// Checks whether microdroid_launcher started but payload failed. reason must be recorded in the
// console output.
private void assertThatPayloadFailsDueTo(VirtualMachine vm, String reason) throws Exception {
@@ -2190,8 +2219,7 @@
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
- VirtualMachine vm = forceCreateNewVirtualMachine("test_boot_with_unsigned_vendor", config);
- BootResult bootResult = tryBootVm(TAG, "test_boot_with_unsigned_vendor");
+ BootResult bootResult = tryBootVmWithConfig(config, "test_boot_with_unsigned_vendor");
assertThat(bootResult.payloadStarted).isFalse();
assertThat(bootResult.deathReason).isEqualTo(VirtualMachineCallback.STOP_REASON_REBOOT);
}
diff --git a/tests/vendor_images/Android.bp b/tests/vendor_images/Android.bp
index ecf0bb4..26dbc01 100644
--- a/tests/vendor_images/Android.bp
+++ b/tests/vendor_images/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/vmshareapp/Android.bp b/tests/vmshareapp/Android.bp
index d4113bf..5f6dc57 100644
--- a/tests/vmshareapp/Android.bp
+++ b/tests/vmshareapp/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/tests/vmshareapp/aidl/Android.bp b/tests/vmshareapp/aidl/Android.bp
index 09e3405..df4a4b4 100644
--- a/tests/vmshareapp/aidl/Android.bp
+++ b/tests/vmshareapp/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/virtualizationmanager/Android.bp b/virtualizationmanager/Android.bp
index 39d296f..48b5cd1 100644
--- a/virtualizationmanager/Android.bp
+++ b/virtualizationmanager/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/virtualizationmanager/fsfdt/Android.bp b/virtualizationmanager/fsfdt/Android.bp
index 7199485..7a1e5ed 100644
--- a/virtualizationmanager/fsfdt/Android.bp
+++ b/virtualizationmanager/fsfdt/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/virtualizationservice/Android.bp b/virtualizationservice/Android.bp
index 71d9d4b..e0bb97f 100644
--- a/virtualizationservice/Android.bp
+++ b/virtualizationservice/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/virtualizationservice/aidl/Android.bp b/virtualizationservice/aidl/Android.bp
index 7c9c4f7..8ca375a 100644
--- a/virtualizationservice/aidl/Android.bp
+++ b/virtualizationservice/aidl/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/virtualizationservice/vfio_handler/Android.bp b/virtualizationservice/vfio_handler/Android.bp
index b9d495b..66fc2ee 100644
--- a/virtualizationservice/vfio_handler/Android.bp
+++ b/virtualizationservice/vfio_handler/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/vm/Android.bp b/vm/Android.bp
index ff1b788..04aff5e 100644
--- a/vm/Android.bp
+++ b/vm/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}
diff --git a/zipfuse/Android.bp b/zipfuse/Android.bp
index 7ee0ef1..974d66a 100644
--- a/zipfuse/Android.bp
+++ b/zipfuse/Android.bp
@@ -1,5 +1,4 @@
package {
- default_team: "trendy_team_virtualization",
default_applicable_licenses: ["Android-Apache-2.0"],
}