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

Commit be48640e authored by Devin Moore's avatar Devin Moore Committed by Gerrit Code Review
Browse files

Merge "Rust new_vsock use assigned port feature" into main

parents 1330b03c 398f9f55
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -37,8 +37,12 @@ enum class ARpcSession_FileDescriptorTransportMode {
// Set `cid` to VMADDR_CID_LOCAL to only bind to the local vsock interface.
// Set `cid` to VMADDR_CID_LOCAL to only bind to the local vsock interface.
// Returns an opaque handle to the running server instance, or null if the server
// Returns an opaque handle to the running server instance, or null if the server
// could not be started.
// could not be started.
// Set |port| to VMADDR_PORT_ANY to pick an available ephemeral port.
// |assignedPort| will be set to the assigned port number if it is not null.
// This will be the provided |port|, or the chosen available ephemeral port when
// |port| is VMADDR_PORT_ANY.
[[nodiscard]] ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid,
[[nodiscard]] ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid,
                                              unsigned int port);
                                              unsigned int port, unsigned int* assignedPort);


// Starts a Unix domain RPC server with an open raw socket file descriptor
// Starts a Unix domain RPC server with an open raw socket file descriptor
// and a given root IBinder object.
// and a given root IBinder object.
+3 −2
Original line number Original line Diff line number Diff line
@@ -81,7 +81,8 @@ RpcSession::FileDescriptorTransportMode toTransportMode(
extern "C" {
extern "C" {


#ifndef __TRUSTY__
#ifndef __TRUSTY__
ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid, unsigned int port) {
ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid, unsigned int port,
                                unsigned int* assignedPort) {
    auto server = RpcServer::make();
    auto server = RpcServer::make();


    unsigned int bindCid = VMADDR_CID_ANY; // bind to the remote interface
    unsigned int bindCid = VMADDR_CID_ANY; // bind to the remote interface
@@ -90,7 +91,7 @@ ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid, unsigned in
        cid = VMADDR_CID_ANY;       // no need for a connection filter
        cid = VMADDR_CID_ANY;       // no need for a connection filter
    }
    }


    if (status_t status = server->setupVsockServer(bindCid, port); status != OK) {
    if (status_t status = server->setupVsockServer(bindCid, port, assignedPort); status != OK) {
        ALOGE("Failed to set up vsock server with port %u error: %s", port,
        ALOGE("Failed to set up vsock server with port %u error: %s", port,
              statusToString(status).c_str());
              statusToString(status).c_str());
        return nullptr;
        return nullptr;
+2 −2
Original line number Original line Diff line number Diff line
@@ -104,8 +104,8 @@ struct OnDeleteProviderHolder {
};
};


ABinderRpc_AccessorProvider* ABinderRpc_registerAccessorProvider(
ABinderRpc_AccessorProvider* ABinderRpc_registerAccessorProvider(
        ABinderRpc_AccessorProvider_getAccessorCallback provider, const char** instances,
        ABinderRpc_AccessorProvider_getAccessorCallback provider,
        size_t numInstances, void* data,
        const char* const* const instances, size_t numInstances, void* data,
        ABinderRpc_AccessorProviderUserData_deleteCallback onDelete) {
        ABinderRpc_AccessorProviderUserData_deleteCallback onDelete) {
    if (provider == nullptr) {
    if (provider == nullptr) {
        ALOGE("Null provider passed to ABinderRpc_registerAccessorProvider");
        ALOGE("Null provider passed to ABinderRpc_registerAccessorProvider");
+3 −2
Original line number Original line Diff line number Diff line
@@ -144,8 +144,9 @@ typedef void (*ABinderRpc_AccessorProviderUserData_deleteCallback)(void* _Nullab
 */
 */
ABinderRpc_AccessorProvider* _Nullable ABinderRpc_registerAccessorProvider(
ABinderRpc_AccessorProvider* _Nullable ABinderRpc_registerAccessorProvider(
        ABinderRpc_AccessorProvider_getAccessorCallback _Nonnull provider,
        ABinderRpc_AccessorProvider_getAccessorCallback _Nonnull provider,
        const char* _Nullable* _Nonnull instances, size_t numInstances, void* _Nullable data,
        const char* _Nullable const* const _Nonnull instances, size_t numInstances,
        ABinderRpc_AccessorProviderUserData_deleteCallback _Nullable onDelete) __INTRODUCED_IN(36);
        void* _Nullable data, ABinderRpc_AccessorProviderUserData_deleteCallback _Nullable onDelete)
        __INTRODUCED_IN(36);


/**
/**
 * Remove an ABinderRpc_AccessorProvider from libbinder. This will remove references
 * Remove an ABinderRpc_AccessorProvider from libbinder. This will remove references
+19 −8
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ use crate::session::FileDescriptorTransportMode;
use binder::{unstable_api::AsNative, SpIBinder};
use binder::{unstable_api::AsNative, SpIBinder};
use binder_rpc_unstable_bindgen::ARpcServer;
use binder_rpc_unstable_bindgen::ARpcServer;
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
use std::ffi::CString;
use std::ffi::{c_uint, CString};
use std::io::{Error, ErrorKind};
use std::io::{Error, ErrorKind};
use std::os::unix::io::{IntoRawFd, OwnedFd};
use std::os::unix::io::{IntoRawFd, OwnedFd};


@@ -42,18 +42,29 @@ impl RpcServer {
    /// Creates a binder RPC server, serving the supplied binder service implementation on the given
    /// Creates a binder RPC server, serving the supplied binder service implementation on the given
    /// vsock port. Only connections from the given CID are accepted.
    /// vsock port. Only connections from the given CID are accepted.
    ///
    ///
    // Set `cid` to libc::VMADDR_CID_ANY to accept connections from any client.
    /// Set `cid` to [`libc::VMADDR_CID_ANY`] to accept connections from any client.
    // Set `cid` to libc::VMADDR_CID_LOCAL to only bind to the local vsock interface.
    /// Set `cid` to [`libc::VMADDR_CID_LOCAL`] to only bind to the local vsock interface.
    pub fn new_vsock(mut service: SpIBinder, cid: u32, port: u32) -> Result<RpcServer, Error> {
    /// Set `port` to [`libc::VMADDR_PORT_ANY`] to pick an ephemeral port.
    /// The assigned port is returned with RpcServer.
    pub fn new_vsock(
        mut service: SpIBinder,
        cid: u32,
        port: u32,
    ) -> Result<(RpcServer, u32 /* assigned_port */), Error> {
        let service = service.as_native_mut();
        let service = service.as_native_mut();


        let mut assigned_port: c_uint = 0;
        // SAFETY: Service ownership is transferring to the server and won't be valid afterward.
        // SAFETY: Service ownership is transferring to the server and won't be valid afterward.
        // Plus the binder objects are threadsafe.
        // Plus the binder objects are threadsafe.
        unsafe {
        let server = unsafe {
            Self::checked_from_ptr(binder_rpc_unstable_bindgen::ARpcServer_newVsock(
            Self::checked_from_ptr(binder_rpc_unstable_bindgen::ARpcServer_newVsock(
                service, cid, port,
                service,
            ))
                cid,
        }
                port,
                &mut assigned_port,
            ))?
        };
        Ok((server, assigned_port as _))
    }
    }


    /// Creates a binder RPC server, serving the supplied binder service implementation on the given
    /// Creates a binder RPC server, serving the supplied binder service implementation on the given