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

Commit 175ce9ec authored by Priyanka Advani (xWF)'s avatar Priyanka Advani (xWF) Committed by Android (Google) Code Review
Browse files

Merge changes from topic "revert-34231615-LLUPMXXFBH" into main

* changes:
  Revert "Add ifdefs to compile out Parcel::Blob code"
  Revert "Refactors client acceptance logic in RpcServer::join"
parents 7c3d5917 18aeaef1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -735,7 +735,7 @@ cc_library {
}

cc_library {
    name: "libbinder_rpc_no_legacy",
    name: "libbinder_rpc_no_blob",
    vendor_available: true,
    defaults: [
        "libbinder_common_defaults",
+2 −4
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef BINDER_DISABLE_BLOB
#include <sys/mman.h>
#endif // BINDER_DISABLE_BLOB
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>
@@ -3502,7 +3502,6 @@ size_t Parcel::getOpenAshmemSize() const

// --- Parcel::Blob ---

#ifndef BINDER_DISABLE_BLOB
Parcel::Blob::Blob() :
        mFd(-1), mData(nullptr), mSize(0), mMutable(false) {
}
@@ -3533,6 +3532,5 @@ void Parcel::Blob::clear() {
    mSize = 0;
    mMutable = false;
}
#endif // BINDER_DISABLE_BLOB

} // namespace android
+37 −43
Original line number Diff line number Diff line
@@ -273,62 +273,56 @@ void RpcServer::join() {

    status_t status;
    while ((status = mShutdownTrigger->triggerablePoll(mServer, POLLIN)) == OK) {
        status = acceptConnection(RpcSession::join);
        if (status == DEAD_OBJECT) {
            break;
        }
    }
    LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());

    if constexpr (kEnableRpcThreads) {
        RpcMutexLockGuard _l(mLock);
        mJoinThreadRunning = false;
    } else {
        // Multi-threaded builds clear this in shutdown(), but we need it valid
        // so the loop above exits cleanly
        mShutdownTrigger = nullptr;
    }
    mShutdownCv.notify_all();
}

status_t RpcServer::acceptConnection(
        std::function<void(sp<RpcSession>&&, RpcSession::PreJoinSetupResult&&)>&& joinFn) {
    RpcTransportFd clientFd;
        std::array<uint8_t, kRpcAddressSize> addr;
        static_assert(addr.size() >= sizeof(sockaddr_storage), "kRpcAddressSize is too small");
        socklen_t addrLen = addr.size();

    status_t status;
    if ((status = mAcceptFn(*this, &clientFd)) != OK) {
        if (status != DEAD_OBJECT) {
        RpcTransportFd clientSocket;
        if ((status = mAcceptFn(*this, &clientSocket)) != OK) {
            if (status == DEAD_OBJECT) {
                break;
            } else {
                ALOGE("Accept returned error %s", statusToString(status).c_str());
                continue;
            }
        return status;
        }

    LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientFd.fd.get());
        LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientSocket.fd.get());

    if (getpeername(clientFd.fd.get(), reinterpret_cast<sockaddr*>(addr.data()), &addrLen)) {
        if (getpeername(clientSocket.fd.get(), reinterpret_cast<sockaddr*>(addr.data()),
                        &addrLen)) {
            ALOGE("Could not getpeername socket: %s", strerror(errno));
        return EINVAL;
            continue;
        }

        if (mConnectionFilter != nullptr && !mConnectionFilter(addr.data(), addrLen)) {
        ALOGE("Dropped client connection fd %d", clientFd.fd.get());
        return EINVAL;
            ALOGE("Dropped client connection fd %d", clientSocket.fd.get());
            continue;
        }

        {
            RpcMutexLockGuard _l(mLock);
            RpcMaybeThread thread =
                RpcMaybeThread(&RpcServer::establishConnection, sp<RpcServer>::fromExisting(this),
                               std::move(clientFd), addr, addrLen, std::move(joinFn));
                    RpcMaybeThread(&RpcServer::establishConnection,
                                   sp<RpcServer>::fromExisting(this), std::move(clientSocket), addr,
                                   addrLen, RpcSession::join);

            auto& threadRef = mConnectingThreads[thread.get_id()];
            threadRef = std::move(thread);
            rpcJoinIfSingleThreaded(threadRef);
        }
    }
    LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());

    return OK;
    if constexpr (kEnableRpcThreads) {
        RpcMutexLockGuard _l(mLock);
        mJoinThreadRunning = false;
    } else {
        // Multi-threaded builds clear this in shutdown(), but we need it valid
        // so the loop above exits cleanly
        mShutdownTrigger = nullptr;
    }
    mShutdownCv.notify_all();
}

bool RpcServer::shutdown() {
+0 −3
Original line number Diff line number Diff line
@@ -98,9 +98,6 @@
    },
    {
      "name": "binderStatsPusherUnitTest"
    },
    {
      "name": "binderRpcTestNoLegacy"
    }
  ],
  "presubmit-large": [
+4 −8
Original line number Diff line number Diff line
@@ -1399,7 +1399,6 @@ private:

    size_t mReserved;

#ifndef BINDER_DISABLE_BLOB
    class Blob {
    public:
        LIBBINDER_EXPORTED Blob();
@@ -1419,7 +1418,6 @@ private:
        size_t mSize;
        bool mMutable;
    };
#endif // BINDER_DISABLE_BLOB

    #if defined(__clang__)
    #pragma clang diagnostic push
@@ -1471,7 +1469,6 @@ private:
    LIBBINDER_EXPORTED status_t read(FlattenableHelperInterface& val) const;

public:
#ifndef BINDER_DISABLE_BLOB
    class ReadableBlob : public Blob {
        friend class Parcel;
    public:
@@ -1484,7 +1481,6 @@ public:
    public:
        LIBBINDER_EXPORTED inline void* data() { return mData; }
    };
#endif // BINDER_DISABLE_BLOB

    /**
     * Returns the total amount of ashmem memory owned by this object.
Loading