Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 416b71f0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "libbinder_rs: Build on Trusty" into main

parents 9c6c6436 4b21b9fb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ use std::fmt;
use std::io::Write;
use std::marker::PhantomData;
use std::ops::Deref;
use std::os::fd::AsRawFd;
use std::os::raw::c_char;
use std::os::unix::io::AsRawFd;
use std::ptr;

/// Binder action to perform.
+2 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ mod error;
mod native;
mod parcel;
mod proxy;
#[cfg(not(target_os = "trusty"))]
mod state;

use binder_ndk_sys as sys;
@@ -116,6 +117,7 @@ pub use proxy::{
    get_declared_instances, get_interface, get_service, is_declared, wait_for_interface,
    wait_for_service, DeathRecipient, SpIBinder, WpIBinder,
};
#[cfg(not(target_os = "trusty"))]
pub use state::{ProcessState, ThreadState};

/// Binder result containing a [`Status`] on error.
+17 −5
Original line number Diff line number Diff line
@@ -24,13 +24,10 @@ use crate::sys;

use std::convert::TryFrom;
use std::ffi::{c_void, CStr, CString};
use std::fs::File;
use std::io::Write;
use std::mem::ManuallyDrop;
use std::ops::Deref;
use std::os::raw::c_char;
use std::os::unix::io::FromRawFd;
use std::slice;
use std::sync::Mutex;

/// Rust wrapper around Binder remotable objects.
@@ -331,6 +328,7 @@ impl<T: Remotable> InterfaceClassMethods for Binder<T> {
    /// contains a `T` pointer in its user data. fd should be a non-owned file
    /// descriptor, and args must be an array of null-terminated string
    /// pointers with length num_args.
    #[cfg(not(target_os = "trusty"))]
    unsafe extern "C" fn on_dump(
        binder: *mut sys::AIBinder,
        fd: i32,
@@ -340,9 +338,10 @@ impl<T: Remotable> InterfaceClassMethods for Binder<T> {
        if fd < 0 {
            return StatusCode::UNEXPECTED_NULL as status_t;
        }
        use std::os::fd::FromRawFd;
        // Safety: Our caller promised that fd is a file descriptor. We don't
        // own this file descriptor, so we need to be careful not to drop it.
        let mut file = unsafe { ManuallyDrop::new(File::from_raw_fd(fd)) };
        let mut file = unsafe { ManuallyDrop::new(std::fs::File::from_raw_fd(fd)) };

        if args.is_null() && num_args != 0 {
            return StatusCode::UNEXPECTED_NULL as status_t;
@@ -354,7 +353,7 @@ impl<T: Remotable> InterfaceClassMethods for Binder<T> {
            // Safety: Our caller promised that `args` is an array of
            // null-terminated string pointers with length `num_args`.
            unsafe {
                slice::from_raw_parts(args, num_args as usize)
                std::slice::from_raw_parts(args, num_args as usize)
                    .iter()
                    .map(|s| CStr::from_ptr(*s))
                    .collect()
@@ -374,6 +373,19 @@ impl<T: Remotable> InterfaceClassMethods for Binder<T> {
            Err(e) => e as status_t,
        }
    }

    /// Called to handle the `dump` transaction.
    #[cfg(target_os = "trusty")]
    unsafe extern "C" fn on_dump(
        _binder: *mut sys::AIBinder,
        _fd: i32,
        _args: *mut *const c_char,
        _num_args: u32,
    ) -> status_t {
        // This operation is not supported on Trusty right now
        // because we do not have a uniform way of writing to handles
        StatusCode::INVALID_OPERATION as status_t
    }
}

impl<T: Remotable> Drop for Binder<T> {
+1 −1
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ use std::convert::TryInto;
use std::ffi::{c_void, CStr, CString};
use std::fmt;
use std::mem;
use std::os::fd::AsRawFd;
use std::os::raw::c_char;
use std::os::unix::io::AsRawFd;
use std::ptr;
use std::sync::Arc;

+37 −0
Original line number Diff line number Diff line
# Copyright (C) 2023 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.
#

LOCAL_DIR := $(GET_LOCAL_DIR)
LIBBINDER_DIR := $(LOCAL_DIR)/../..

MODULE := $(LOCAL_DIR)

MODULE_SRCS := $(LIBBINDER_DIR)/rust/src/lib.rs

MODULE_CRATE_NAME := binder

MODULE_LIBRARY_DEPS += \
	$(LIBBINDER_DIR)/trusty \
	$(LIBBINDER_DIR)/trusty/ndk \
	$(LIBBINDER_DIR)/trusty/rust/binder_ndk_sys \
	external/rust/crates/downcast-rs \
	trusty/user/base/lib/trusty-sys \

# Trusty does not have `ProcessState`, so there are a few
# doc links in `IBinder` that are still broken.
MODULE_RUSTFLAGS += \
	--allow rustdoc::broken-intra-doc-links \

include make/library.mk