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

Commit 99157624 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: hide BpBinder::create(*) functions

There is no need to have these around, and having them exposed
potentially means they could be stuck in the ABI.

They are created (instead of absorbed into the private constructors)
because of the additional UID tracking logic there.

Bug: 167966510
Test: binderRpcTest
Change-Id: I673d7a4c591a1b004f3214e8a17b48e54e91171d
parent 728587b2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder) {
                    return INVALID_OPERATION;
                }
            }
            const int32_t handle = proxy ? proxy->getPrivateAccessorForId().binderHandle() : 0;
            const int32_t handle = proxy ? proxy->getPrivateAccessor().binderHandle() : 0;
            obj.hdr.type = BINDER_TYPE_HANDLE;
            obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
            obj.handle = handle;
@@ -572,7 +572,7 @@ void Parcel::markForBinder(const sp<IBinder>& binder) {
    LOG_ALWAYS_FATAL_IF(mData != nullptr, "format must be set before data is written");

    if (binder && binder->remoteBinder() && binder->remoteBinder()->isRpcBinder()) {
        markForRpc(binder->remoteBinder()->getPrivateAccessorForId().rpcSession());
        markForRpc(binder->remoteBinder()->getPrivateAccessor().rpcSession());
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ ssize_t ProcessState::getStrongRefCountForNode(const sp<BpBinder>& binder) {
    binder_node_info_for_ref info;
    memset(&info, 0, sizeof(binder_node_info_for_ref));

    info.handle = binder->getPrivateAccessorForId().binderHandle();
    info.handle = binder->getPrivateAccessor().binderHandle();

    status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info);

@@ -301,7 +301,7 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
                   return nullptr;
            }

            sp<BpBinder> b = BpBinder::create(handle);
            sp<BpBinder> b = BpBinder::PrivateAccessor::create(handle);
            e->binder = b.get();
            if (b) e->refs = b->getWeakRefs();
            result = b;
+3 −4
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ status_t RpcState::onBinderLeaving(const sp<RpcSession>& session, const sp<IBind
    bool isRemote = binder->remoteBinder();
    bool isRpc = isRemote && binder->remoteBinder()->isRpcBinder();

    if (isRpc && binder->remoteBinder()->getPrivateAccessorForId().rpcSession() != session) {
    if (isRpc && binder->remoteBinder()->getPrivateAccessor().rpcSession() != session) {
        // We need to be able to send instructions over the socket for how to
        // connect to a different server, and we also need to let the host
        // process know that this is happening.
@@ -85,8 +85,7 @@ status_t RpcState::onBinderLeaving(const sp<RpcSession>& session, const sp<IBind
        if (binder == node.binder) {
            if (isRpc) {
                // check integrity of data structure
                uint64_t actualAddr =
                        binder->remoteBinder()->getPrivateAccessorForId().rpcAddress();
                uint64_t actualAddr = binder->remoteBinder()->getPrivateAccessor().rpcAddress();
                LOG_ALWAYS_FATAL_IF(addr != actualAddr, "Address mismatch %" PRIu64 " vs %" PRIu64,
                                    addr, actualAddr);
            }
@@ -185,7 +184,7 @@ status_t RpcState::onBinderEntering(const sp<RpcSession>& session, uint64_t addr

    // Currently, all binders are assumed to be part of the same session (no
    // device global binders in the RPC world).
    it->second.binder = *out = BpBinder::create(session, it->first);
    it->second.binder = *out = BpBinder::PrivateAccessor::create(session, it->first);
    it->second.timesRecd = 1;
    return OK;
}
+12 −9
Original line number Diff line number Diff line
@@ -39,9 +39,6 @@ using binder_proxy_limit_callback = void(*)(int);
class BpBinder : public IBinder
{
public:
    static sp<BpBinder> create(int32_t handle);
    static sp<BpBinder> create(const sp<RpcSession>& session, uint64_t address);

    /**
     * Return value:
     * true - this is associated with a socket RpcSession
@@ -116,13 +113,18 @@ public:
        KeyedVector<const void*, entry_t> mObjects;
    };

    class PrivateAccessorForId {
    class PrivateAccessor {
    private:
        friend class BpBinder;
        friend class ::android::Parcel;
        friend class ::android::ProcessState;
        friend class ::android::RpcState;
        explicit PrivateAccessorForId(const BpBinder* binder) : mBinder(binder) {}
        explicit PrivateAccessor(const BpBinder* binder) : mBinder(binder) {}

        static sp<BpBinder> create(int32_t handle) { return BpBinder::create(handle); }
        static sp<BpBinder> create(const sp<RpcSession>& session, uint64_t address) {
            return BpBinder::create(session, address);
        }

        // valid if !isRpcBinder
        int32_t binderHandle() const { return mBinder->binderHandle(); }
@@ -133,14 +135,15 @@ public:

        const BpBinder* mBinder;
    };
    const PrivateAccessorForId getPrivateAccessorForId() const {
        return PrivateAccessorForId(this);
    }
    const PrivateAccessor getPrivateAccessor() const { return PrivateAccessor(this); }

private:
    friend PrivateAccessorForId;
    friend PrivateAccessor;
    friend class sp<BpBinder>;

    static sp<BpBinder> create(int32_t handle);
    static sp<BpBinder> create(const sp<RpcSession>& session, uint64_t address);

    struct BinderHandle {
        int32_t handle;
    };