Loading libs/binder/RpcState.cpp +17 −18 Original line number Diff line number Diff line Loading @@ -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", Loading Loading @@ -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?", Loading @@ -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 Loading libs/binder/RpcState.h +2 −1 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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( Loading libs/binder/RpcTransportRaw.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ namespace android { using namespace android::binder::impl; // RpcTransport with TLS disabled. class RpcTransportRaw : public RpcTransport { public: Loading @@ -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; Loading @@ -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); Loading libs/binder/RpcTransportTipcAndroid.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 { Loading @@ -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 { Loading libs/binder/RpcTransportTls.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ #endif namespace android { using namespace android::binder::impl; namespace { // Implement BIO for socket that ignores SIGPIPE. Loading Loading @@ -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); Loading @@ -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)(); Loading Loading @@ -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(); }; Loading Loading @@ -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; Loading Loading @@ -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 Loading
libs/binder/RpcState.cpp +17 −18 Original line number Diff line number Diff line Loading @@ -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", Loading Loading @@ -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?", Loading @@ -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 Loading
libs/binder/RpcState.h +2 −1 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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( Loading
libs/binder/RpcTransportRaw.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ namespace android { using namespace android::binder::impl; // RpcTransport with TLS disabled. class RpcTransportRaw : public RpcTransport { public: Loading @@ -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; Loading @@ -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); Loading
libs/binder/RpcTransportTipcAndroid.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 { Loading @@ -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 { Loading
libs/binder/RpcTransportTls.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ #endif namespace android { using namespace android::binder::impl; namespace { // Implement BIO for socket that ignores SIGPIPE. Loading Loading @@ -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); Loading @@ -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)(); Loading Loading @@ -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(); }; Loading Loading @@ -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; Loading Loading @@ -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