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

Commit 23e0a8e4 authored by Devin Moore's avatar Devin Moore
Browse files

Remove libnix dependency on libbinder_rs

Use the libc types directly.

Test: atest vm_accessor_test
Bug: na
Change-Id: I85876faa047bc929211695f5d3ff6f4ddb7438f2
parent 9fe5f80e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ rust_library {
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
    host_supported: true,
    vendor_available: true,
@@ -200,7 +199,6 @@ rust_test {
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
}

+14 −7
Original line number Diff line number Diff line
@@ -22,10 +22,9 @@ use crate::sys;
use std::ffi::{c_void, CStr, CString};
use std::os::raw::c_char;

use libc::sockaddr;
use nix::sys::socket::{SockaddrLike, UnixAddr, VsockAddr};
use libc::{sockaddr, sockaddr_un, sockaddr_vm, socklen_t};
use std::sync::Arc;
use std::{fmt, ptr};
use std::{fmt, mem, ptr};

/// Rust wrapper around ABinderRpc_Accessor objects for RPC binder service management.
///
@@ -44,9 +43,9 @@ impl fmt::Debug for Accessor {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionInfo {
    /// For vsock connection
    Vsock(VsockAddr),
    Vsock(sockaddr_vm),
    /// For unix domain socket connection
    Unix(UnixAddr),
    Unix(sockaddr_un),
}

/// Safety: A `Accessor` is a wrapper around `ABinderRpc_Accessor` which is
@@ -148,13 +147,21 @@ impl Accessor {
        match connection {
            ConnectionInfo::Vsock(addr) => {
                // Safety: The sockaddr is being copied in the NDK API
                unsafe { sys::ABinderRpc_ConnectionInfo_new(addr.as_ptr(), addr.len()) }
                unsafe {
                    sys::ABinderRpc_ConnectionInfo_new(
                        &addr as *const sockaddr_vm as *const sockaddr,
                        mem::size_of::<sockaddr_vm>() as socklen_t,
                    )
                }
            }
            ConnectionInfo::Unix(addr) => {
                // Safety: The sockaddr is being copied in the NDK API
                // The cast is from sockaddr_un* to sockaddr*.
                unsafe {
                    sys::ABinderRpc_ConnectionInfo_new(addr.as_ptr() as *const sockaddr, addr.len())
                    sys::ABinderRpc_ConnectionInfo_new(
                        &addr as *const sockaddr_un as *const sockaddr,
                        mem::size_of::<sockaddr_un>() as socklen_t,
                    )
                }
            }
        }