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

Commit 876512d6 authored by Pawan Wagh's avatar Pawan Wagh Committed by Automerger Merge Worker
Browse files

Merge "libbinder : Avoid waiting in binder_rpc_fuzzer" am: 58896655 am:...

Merge "libbinder : Avoid waiting in binder_rpc_fuzzer" am: 58896655 am: 9246c23c am: 5f84dffa am: 1b80b1b1

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2199936



Change-Id: I69d45e71fbdd06dd813c1aad2f9bafbf9d03c06b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d998754b 1b80b1b1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -560,4 +560,14 @@ status_t RpcServer::setupExternalServer(base::unique_fd serverFd) {
    return OK;
}

bool RpcServer::hasActiveRequests() {
    RpcMutexLockGuard _l(mLock);
    for (const auto& [_, session] : mSessions) {
        if (session->hasActiveRequests()) {
            return true;
        }
    }
    return !mServer.isInPollingState();
}

} // namespace android
+20 −0
Original line number Diff line number Diff line
@@ -952,4 +952,24 @@ RpcSession::ExclusiveConnection::~ExclusiveConnection() {
    }
}

bool RpcSession::hasActiveConnection(const std::vector<sp<RpcConnection>>& connections) {
    for (const auto& connection : connections) {
        if (connection->exclusiveTid != std::nullopt && !connection->rpcTransport->isWaiting()) {
            return true;
        }
    }
    return false;
}

bool RpcSession::hasActiveRequests() {
    RpcMutexUniqueLock _l(mMutex);
    if (hasActiveConnection(mConnections.mIncoming)) {
        return true;
    }
    if (hasActiveConnection(mConnections.mOutgoing)) {
        return true;
    }
    return mConnections.mWaitingThreads != 0;
}

} // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -187,6 +187,11 @@ public:
    std::vector<sp<RpcSession>> listSessions();
    size_t numUninitializedSessions();

    /**
     * Whether any requests are currently being processed.
     */
    bool hasActiveRequests();

    ~RpcServer();

private:
+10 −0
Original line number Diff line number Diff line
@@ -189,6 +189,11 @@ public:
     */
    [[nodiscard]] status_t sendDecStrong(const BpBinder* binder);

    /**
     * Whether any requests are currently being processed.
     */
    bool hasActiveRequests();

    ~RpcSession();

    /**
@@ -286,6 +291,11 @@ private:

    [[nodiscard]] status_t initShutdownTrigger();

    /**
     * Checks whether any connection is active (Not polling on fd)
     */
    bool hasActiveConnection(const std::vector<sp<RpcConnection>>& connections);

    enum class ConnectionUse {
        CLIENT,
        CLIENT_ASYNC,
+4 −2
Original line number Diff line number Diff line
@@ -157,8 +157,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
        }
    }

    usleep(10000);

    if (hangupBeforeShutdown) {
        connections.clear();
        while (!server->listSessions().empty() || server->numUninitializedSessions()) {
@@ -167,6 +165,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
        }
    }

    while (server->hasActiveRequests()) {
        usleep(10);
    }

    while (!server->shutdown()) usleep(1);
    serverThread.join();