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

Commit 747e4a40 authored by Frederick Mayle's avatar Frederick Mayle Committed by Automerger Merge Worker
Browse files

Merge "libbinder: Don't alloc for RPC_COMMAND_DEC_STRONG" am: 8f52763d am:...

Merge "libbinder: Don't alloc for RPC_COMMAND_DEC_STRONG" am: 8f52763d am: 7f2538de am: 007b4fa6 am: 14cce22b

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



Change-Id: I789d8c13c66ec83be8e026034ff9fcb8c9abf79b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1b204466 14cce22b
Loading
Loading
Loading
Loading
+10 −14
Original line number Original line Diff line number Diff line
@@ -964,23 +964,19 @@ status_t RpcState::processDecStrong(const sp<RpcSession::RpcConnection>& connect
                                    const sp<RpcSession>& session, const RpcWireHeader& command) {
                                    const sp<RpcSession>& session, const RpcWireHeader& command) {
    LOG_ALWAYS_FATAL_IF(command.command != RPC_COMMAND_DEC_STRONG, "command: %d", command.command);
    LOG_ALWAYS_FATAL_IF(command.command != RPC_COMMAND_DEC_STRONG, "command: %d", command.command);


    CommandData commandData(command.bodySize);
    if (!commandData.valid()) {
        return NO_MEMORY;
    }
    iovec iov{commandData.data(), commandData.size()};
    if (status_t status = rpcRec(connection, session, "dec ref body", &iov, 1); status != OK)
        return status;

    if (command.bodySize != sizeof(RpcDecStrong)) {
    if (command.bodySize != sizeof(RpcDecStrong)) {
        ALOGE("Expecting %zu but got %" PRId32 " bytes for RpcDecStrong. Terminating!",
        ALOGE("Expecting %zu but got %" PRId32 " bytes for RpcDecStrong. Terminating!",
              sizeof(RpcDecStrong), command.bodySize);
              sizeof(RpcDecStrong), command.bodySize);
        (void)session->shutdownAndWait(false);
        (void)session->shutdownAndWait(false);
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
    RpcDecStrong* body = reinterpret_cast<RpcDecStrong*>(commandData.data());


    uint64_t addr = RpcWireAddress::toRaw(body->address);
    RpcDecStrong body;
    iovec iov{&body, sizeof(RpcDecStrong)};
    if (status_t status = rpcRec(connection, session, "dec ref body", &iov, 1); status != OK)
        return status;

    uint64_t addr = RpcWireAddress::toRaw(body.address);
    std::unique_lock<std::mutex> _l(mNodeMutex);
    std::unique_lock<std::mutex> _l(mNodeMutex);
    auto it = mNodeForAddress.find(addr);
    auto it = mNodeForAddress.find(addr);
    if (it == mNodeForAddress.end()) {
    if (it == mNodeForAddress.end()) {
@@ -998,19 +994,19 @@ status_t RpcState::processDecStrong(const sp<RpcSession::RpcConnection>& connect
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


    if (it->second.timesSent < body->amount) {
    if (it->second.timesSent < body.amount) {
        ALOGE("Record of sending binder %zu times, but requested decStrong for %" PRIu64 " of %u",
        ALOGE("Record of sending binder %zu times, but requested decStrong for %" PRIu64 " of %u",
              it->second.timesSent, addr, body->amount);
              it->second.timesSent, addr, body.amount);
        return OK;
        return OK;
    }
    }


    LOG_ALWAYS_FATAL_IF(it->second.sentRef == nullptr, "Inconsistent state, lost ref for %" PRIu64,
    LOG_ALWAYS_FATAL_IF(it->second.sentRef == nullptr, "Inconsistent state, lost ref for %" PRIu64,
                        addr);
                        addr);


    LOG_RPC_DETAIL("Processing dec strong of %" PRIu64 " by %u from %zu", addr, body->amount,
    LOG_RPC_DETAIL("Processing dec strong of %" PRIu64 " by %u from %zu", addr, body.amount,
                   it->second.timesSent);
                   it->second.timesSent);


    it->second.timesSent -= body->amount;
    it->second.timesSent -= body.amount;
    sp<IBinder> tempHold = tryEraseNode(it);
    sp<IBinder> tempHold = tryEraseNode(it);
    _l.unlock();
    _l.unlock();
    tempHold = nullptr; // destructor may make binder calls on this session
    tempHold = nullptr; // destructor may make binder calls on this session
+2 −2
Original line number Original line Diff line number Diff line
@@ -210,8 +210,8 @@ TEST(RpcBinderAllocation, SetupRpcServer) {
        });
        });
        CHECK_EQ(OK, remoteBinder->pingBinder());
        CHECK_EQ(OK, remoteBinder->pingBinder());
    }
    }
    EXPECT_EQ(mallocs, 2);
    EXPECT_EQ(mallocs, 1);
    EXPECT_EQ(totalBytes, 56);
    EXPECT_EQ(totalBytes, 40);
}
}


int main(int argc, char** argv) {
int main(int argc, char** argv) {