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

Commit 35804862 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Revert^2 "Use std::function instead of base::function_ref"

84b7cff1

Test: m
Bug: 302723053
Change-Id: If25bdb65254a4a8ad5afeda7e6ce1eedf422d896
parent 1de48a25
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -358,7 +358,7 @@ RpcState::CommandData::CommandData(size_t size) : mSize(size) {
status_t RpcState::rpcSend(
        const sp<RpcSession::RpcConnection>& connection, const sp<RpcSession>& session,
        const char* what, iovec* iovs, int niovs,
        const std::optional<android::base::function_ref<status_t()>>& altPoll,
        const std::optional<SmallFunction<status_t()>>& altPoll,
        const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) {
    for (int i = 0; i < niovs; i++) {
        LOG_RPC_DETAIL("Sending %s (part %d of %d) on RpcTransport %p: %s",
@@ -601,9 +601,7 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti
            {const_cast<uint8_t*>(data.data()), data.dataSize()},
            objectTableSpan.toIovec(),
    };
    if (status_t status = rpcSend(
                connection, session, "transaction", iovs, countof(iovs),
                [&] {
    auto altPoll = [&] {
        if (waitUs > kWaitLogUs) {
            ALOGE("Cannot send command, trying to process pending refcounts. Waiting "
                  "%zuus. Too many oneway calls?",
@@ -618,8 +616,9 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti
        }

        return drainCommands(connection, session, CommandType::CONTROL_ONLY);
                },
                rpcFields->mFds.get());
    };
    if (status_t status = rpcSend(connection, session, "transaction", iovs, countof(iovs),
                                  std::ref(altPoll), rpcFields->mFds.get());
        status != OK) {
        // rpcSend calls shutdownAndWait, so all refcounts should be reset. If we ever tolerate
        // errors here, then we may need to undo the binder-sent counts for the transaction as
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#pragma once

#include <android-base/unique_fd.h>
#include <binder/Functional.h>
#include <binder/IBinder.h>
#include <binder/Parcel.h>
#include <binder/RpcSession.h>
@@ -190,7 +191,7 @@ private:
    [[nodiscard]] status_t rpcSend(
            const sp<RpcSession::RpcConnection>& connection, const sp<RpcSession>& session,
            const char* what, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<binder::impl::SmallFunction<status_t()>>& altPoll,
            const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds =
                    nullptr);
    [[nodiscard]] status_t rpcRec(
+4 −2
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@

namespace android {

using namespace android::binder::impl;

// RpcTransport with TLS disabled.
class RpcTransportRaw : public RpcTransport {
public:
@@ -54,7 +56,7 @@ public:

    status_t interruptableWriteFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds)
            override {
        bool sentFds = false;
@@ -70,7 +72,7 @@ public:

    status_t interruptableReadFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) override {
        auto recv = [&](iovec* iovs, int niovs) -> ssize_t {
            return binder::os::receiveMessageFromSocket(mSocket, iovs, niovs, ancillaryFds);
+4 −2
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
#include "RpcState.h"
#include "RpcTransportUtils.h"

using namespace android::binder::impl;

namespace android {

// RpcTransport for writing Trusty IPC clients in Android.
@@ -72,7 +74,7 @@ public:

    status_t interruptableWriteFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds)
            override {
        auto writeFn = [&](iovec* iovs, size_t niovs) -> ssize_t {
@@ -90,7 +92,7 @@ public:

    status_t interruptableReadFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* /*ancillaryFds*/)
            override {
        auto readFn = [&](iovec* iovs, size_t niovs) -> ssize_t {
+11 −9
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@
#endif

namespace android {

using namespace android::binder::impl;

namespace {

// Implement BIO for socket that ignores SIGPIPE.
@@ -183,10 +186,9 @@ public:
    // |sslError| should be from Ssl::getError().
    // If |sslError| is WANT_READ / WANT_WRITE, poll for POLLIN / POLLOUT respectively. Otherwise
    // return error. Also return error if |fdTrigger| is triggered before or during poll().
    status_t pollForSslError(
            const android::RpcTransportFd& fd, int sslError, FdTrigger* fdTrigger,
    status_t pollForSslError(const android::RpcTransportFd& fd, int sslError, FdTrigger* fdTrigger,
                             const char* fnString, int additionalEvent,
            const std::optional<android::base::function_ref<status_t()>>& altPoll) {
                             const std::optional<SmallFunction<status_t()>>& altPoll) {
        switch (sslError) {
            case SSL_ERROR_WANT_READ:
                return handlePoll(POLLIN | additionalEvent, fd, fdTrigger, fnString, altPoll);
@@ -202,7 +204,7 @@ private:

    status_t handlePoll(int event, const android::RpcTransportFd& fd, FdTrigger* fdTrigger,
                        const char* fnString,
                        const std::optional<android::base::function_ref<status_t()>>& altPoll) {
                        const std::optional<SmallFunction<status_t()>>& altPoll) {
        status_t ret;
        if (altPoll) {
            ret = (*altPoll)();
@@ -286,12 +288,12 @@ public:
    status_t pollRead(void) override;
    status_t interruptableWriteFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds)
            override;
    status_t interruptableReadFully(
            FdTrigger* fdTrigger, iovec* iovs, int niovs,
            const std::optional<android::base::function_ref<status_t()>>& altPoll,
            const std::optional<SmallFunction<status_t()>>& altPoll,
            std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) override;

    bool isWaiting() override { return mSocket.isInPollingState(); };
@@ -322,7 +324,7 @@ status_t RpcTransportTls::pollRead(void) {

status_t RpcTransportTls::interruptableWriteFully(
        FdTrigger* fdTrigger, iovec* iovs, int niovs,
        const std::optional<android::base::function_ref<status_t()>>& altPoll,
        const std::optional<SmallFunction<status_t()>>& altPoll,
        const std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) {
    (void)ancillaryFds;

@@ -368,7 +370,7 @@ status_t RpcTransportTls::interruptableWriteFully(

status_t RpcTransportTls::interruptableReadFully(
        FdTrigger* fdTrigger, iovec* iovs, int niovs,
        const std::optional<android::base::function_ref<status_t()>>& altPoll,
        const std::optional<SmallFunction<status_t()>>& altPoll,
        std::vector<std::variant<base::unique_fd, base::borrowed_fd>>* ancillaryFds) {
    (void)ancillaryFds;

Loading