summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-23 11:51:28 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-10-23 11:51:28 +0000
commit7bcef3add8f53bb32fb73b0af5a5046bfc2bb6ff (patch)
treea9c57c4a44f4a43690bf5e4d4de8841d804e07c2
parent052c702d9f1165cbf31aa31109a82ea419e02970 (diff)
parentbbe31e3a20662310f2c356aea93c613c6fc10240 (diff)
Merge "Unset FDSan tag when converting handle into other types" into main am: bbe31e3a20
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3316994 Change-Id: I03473f90e3ee0897cd4fc605efb68534e4fa48b7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libs/nativewindow/rust/src/handle.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/libs/nativewindow/rust/src/handle.rs b/libs/nativewindow/rust/src/handle.rs
index ee70e3f538..2b08c1bcb9 100644
--- a/libs/nativewindow/rust/src/handle.rs
+++ b/libs/nativewindow/rust/src/handle.rs
@@ -85,6 +85,12 @@ impl NativeHandle {
/// Destroys the `NativeHandle`, taking ownership of the file descriptors it contained.
pub fn into_fds(self) -> Vec<OwnedFd> {
+ // Unset FDSan tag since this `native_handle_t` is no longer the owner of the file
+ // descriptors after this function.
+ // SAFETY: Our wrapped `native_handle_t` pointer is always valid.
+ unsafe {
+ ffi::native_handle_unset_fdsan_tag(self.as_ref());
+ }
let fds = self.data()[..self.fd_count()]
.iter()
.map(|fd| {
@@ -261,6 +267,29 @@ mod test {
}
#[test]
+ fn to_fds() {
+ let file = File::open("/dev/null").unwrap();
+ let original = NativeHandle::new(vec![file.into()], &[42]).unwrap();
+ assert_eq!(original.ints(), &[42]);
+ assert_eq!(original.fds().len(), 1);
+
+ let fds = original.into_fds();
+ assert_eq!(fds.len(), 1);
+ }
+
+ #[test]
+ fn to_aidl() {
+ let file = File::open("/dev/null").unwrap();
+ let original = NativeHandle::new(vec![file.into()], &[42]).unwrap();
+ assert_eq!(original.ints(), &[42]);
+ assert_eq!(original.fds().len(), 1);
+
+ let aidl = AidlNativeHandle::from(original);
+ assert_eq!(&aidl.ints, &[42]);
+ assert_eq!(aidl.fds.len(), 1);
+ }
+
+ #[test]
fn to_from_aidl() {
let file = File::open("/dev/null").unwrap();
let original = NativeHandle::new(vec![file.into()], &[42]).unwrap();