diff options
author | 2022-08-26 21:08:34 +0000 | |
---|---|---|
committer | 2022-08-26 22:20:26 +0000 | |
commit | 3e0061c171182c8b27489ec0d373c92d15d17acc (patch) | |
tree | 5b4d40956a77b6e8e23473940d42ee6ad5ae1843 | |
parent | f546f5b0a1a091ed41ae29a2596cb3048c091ec3 (diff) |
libbinder : Renaming TransportFd to RpcTransportFd
Test: m
Test: m libbinder binderRpcTest
Bug: 218518615
Change-Id: I822bdb751f68c83e1b10c5fd16c9d8439646b771
-rw-r--r-- | libs/binder/FdTrigger.cpp | 2 | ||||
-rw-r--r-- | libs/binder/FdTrigger.h | 3 | ||||
-rw-r--r-- | libs/binder/RpcServer.cpp | 6 | ||||
-rw-r--r-- | libs/binder/RpcSession.cpp | 8 | ||||
-rw-r--r-- | libs/binder/RpcTransportRaw.cpp | 6 | ||||
-rw-r--r-- | libs/binder/RpcTransportTipcAndroid.cpp | 7 | ||||
-rw-r--r-- | libs/binder/RpcTransportTls.cpp | 15 | ||||
-rw-r--r-- | libs/binder/RpcTransportUtils.h | 2 | ||||
-rw-r--r-- | libs/binder/include/binder/RpcServer.h | 6 | ||||
-rw-r--r-- | libs/binder/include/binder/RpcSession.h | 2 | ||||
-rw-r--r-- | libs/binder/include/binder/RpcTransport.h | 16 | ||||
-rw-r--r-- | libs/binder/tests/binderRpcTest.cpp | 6 | ||||
-rw-r--r-- | libs/binder/trusty/RpcServerTrusty.cpp | 2 | ||||
-rw-r--r-- | libs/binder/trusty/RpcTransportTipcTrusty.cpp | 6 |
14 files changed, 45 insertions, 42 deletions
diff --git a/libs/binder/FdTrigger.cpp b/libs/binder/FdTrigger.cpp index 256d587866..8ee6cb0615 100644 --- a/libs/binder/FdTrigger.cpp +++ b/libs/binder/FdTrigger.cpp @@ -54,7 +54,7 @@ bool FdTrigger::isTriggered() { #endif } -status_t FdTrigger::triggerablePoll(const android::TransportFd& transportFd, int16_t event) { +status_t FdTrigger::triggerablePoll(const android::RpcTransportFd& transportFd, int16_t event) { #ifdef BINDER_RPC_SINGLE_THREADED if (mTriggered) { return DEAD_OBJECT; diff --git a/libs/binder/FdTrigger.h b/libs/binder/FdTrigger.h index 14a2749b8a..5fbf2908ad 100644 --- a/libs/binder/FdTrigger.h +++ b/libs/binder/FdTrigger.h @@ -55,7 +55,8 @@ public: * true - time to read! * false - trigger happened */ - [[nodiscard]] status_t triggerablePoll(const android::TransportFd& transportFd, int16_t event); + [[nodiscard]] status_t triggerablePoll(const android::RpcTransportFd& transportFd, + int16_t event); private: #ifdef BINDER_RPC_SINGLE_THREADED diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index f3becbd3f1..0ee5f05030 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -194,7 +194,7 @@ void RpcServer::join() { static_assert(addr.size() >= sizeof(sockaddr_storage), "kRpcAddressSize is too small"); socklen_t addrLen = addr.size(); - TransportFd clientSocket(unique_fd(TEMP_FAILURE_RETRY( + RpcTransportFd clientSocket(unique_fd(TEMP_FAILURE_RETRY( accept4(mServer.fd.get(), reinterpret_cast<sockaddr*>(addr.data()), &addrLen, SOCK_CLOEXEC | SOCK_NONBLOCK)))); @@ -296,7 +296,7 @@ size_t RpcServer::numUninitializedSessions() { } void RpcServer::establishConnection( - sp<RpcServer>&& server, TransportFd clientFd, std::array<uint8_t, kRpcAddressSize> addr, + sp<RpcServer>&& server, RpcTransportFd clientFd, std::array<uint8_t, kRpcAddressSize> addr, size_t addrLen, std::function<void(sp<RpcSession>&&, RpcSession::PreJoinSetupResult&&)>&& joinFn) { // mShutdownTrigger can only be cleared once connection threads have joined. @@ -488,7 +488,7 @@ status_t RpcServer::setupSocketServer(const RpcSocketAddress& addr) { LOG_RPC_DETAIL("Setting up socket server %s", addr.toString().c_str()); LOG_ALWAYS_FATAL_IF(hasServer(), "Each RpcServer can only have one server."); - TransportFd transportFd(unique_fd(TEMP_FAILURE_RETRY( + RpcTransportFd transportFd(unique_fd(TEMP_FAILURE_RETRY( socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)))); if (!transportFd.fd.ok()) { int savedErrno = errno; diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index f109bc6538..bef2ed63c7 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -174,7 +174,7 @@ status_t RpcSession::setupPreconnectedClient(base::unique_fd fd, return res.error().code() == 0 ? UNKNOWN_ERROR : -res.error().code(); } - TransportFd transportFd(std::move(fd)); + RpcTransportFd transportFd(std::move(fd)); status_t status = initAndAddConnection(std::move(transportFd), sessionId, incoming); fd = unique_fd(); // Explicitly reset after move to avoid analyzer warning. return status; @@ -193,7 +193,7 @@ status_t RpcSession::addNullDebuggingClient() { return -savedErrno; } - TransportFd transportFd(std::move(serverFd)); + RpcTransportFd transportFd(std::move(serverFd)); auto server = mCtx->newTransport(std::move(transportFd), mShutdownTrigger.get()); if (server == nullptr) { ALOGE("Unable to set up RpcTransport"); @@ -576,7 +576,7 @@ status_t RpcSession::setupOneSocketConnection(const RpcSocketAddress& addr, return -savedErrno; } - TransportFd transportFd(std::move(serverFd)); + RpcTransportFd transportFd(std::move(serverFd)); if (0 != TEMP_FAILURE_RETRY(connect(transportFd.fd.get(), addr.addr(), addr.addrSize()))) { int connErrno = errno; @@ -624,7 +624,7 @@ status_t RpcSession::setupOneSocketConnection(const RpcSocketAddress& addr, return UNKNOWN_ERROR; } -status_t RpcSession::initAndAddConnection(TransportFd fd, const std::vector<uint8_t>& sessionId, +status_t RpcSession::initAndAddConnection(RpcTransportFd fd, const std::vector<uint8_t>& sessionId, bool incoming) { LOG_ALWAYS_FATAL_IF(mShutdownTrigger == nullptr); auto server = mCtx->newTransport(std::move(fd), mShutdownTrigger.get()); diff --git a/libs/binder/RpcTransportRaw.cpp b/libs/binder/RpcTransportRaw.cpp index 59e6869a1e..65e8fac341 100644 --- a/libs/binder/RpcTransportRaw.cpp +++ b/libs/binder/RpcTransportRaw.cpp @@ -36,7 +36,7 @@ constexpr size_t kMaxFdsPerMsg = 253; // RpcTransport with TLS disabled. class RpcTransportRaw : public RpcTransport { public: - explicit RpcTransportRaw(android::TransportFd socket) : mSocket(std::move(socket)) {} + explicit RpcTransportRaw(android::RpcTransportFd socket) : mSocket(std::move(socket)) {} status_t pollRead(void) override { uint8_t buf; ssize_t ret = TEMP_FAILURE_RETRY( @@ -180,13 +180,13 @@ public: virtual bool isWaiting() { return mSocket.isInPollingState(); } private: - android::TransportFd mSocket; + android::RpcTransportFd mSocket; }; // RpcTransportCtx with TLS disabled. class RpcTransportCtxRaw : public RpcTransportCtx { public: - std::unique_ptr<RpcTransport> newTransport(android::TransportFd socket, FdTrigger*) const { + std::unique_ptr<RpcTransport> newTransport(android::RpcTransportFd socket, FdTrigger*) const { return std::make_unique<RpcTransportRaw>(std::move(socket)); } std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; } diff --git a/libs/binder/RpcTransportTipcAndroid.cpp b/libs/binder/RpcTransportTipcAndroid.cpp index 2e7e931040..453279c0a5 100644 --- a/libs/binder/RpcTransportTipcAndroid.cpp +++ b/libs/binder/RpcTransportTipcAndroid.cpp @@ -36,7 +36,7 @@ namespace { // RpcTransport for writing Trusty IPC clients in Android. class RpcTransportTipcAndroid : public RpcTransport { public: - explicit RpcTransportTipcAndroid(android::TransportFd socket) : mSocket(std::move(socket)) {} + explicit RpcTransportTipcAndroid(android::RpcTransportFd socket) : mSocket(std::move(socket)) {} status_t pollRead() override { if (mReadBufferPos < mReadBufferSize) { @@ -174,7 +174,7 @@ private: } } - TransportFd mSocket; + RpcTransportFd mSocket; // For now, we copy all the input data into a temporary buffer because // we might get multiple interruptableReadFully calls per message, but @@ -193,7 +193,8 @@ private: // RpcTransportCtx for Trusty. class RpcTransportCtxTipcAndroid : public RpcTransportCtx { public: - std::unique_ptr<RpcTransport> newTransport(android::TransportFd fd, FdTrigger*) const override { + std::unique_ptr<RpcTransport> newTransport(android::RpcTransportFd fd, + FdTrigger*) const override { return std::make_unique<RpcTransportTipcAndroid>(std::move(fd)); } std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; } diff --git a/libs/binder/RpcTransportTls.cpp b/libs/binder/RpcTransportTls.cpp index f18519c640..3e98ecca9b 100644 --- a/libs/binder/RpcTransportTls.cpp +++ b/libs/binder/RpcTransportTls.cpp @@ -182,7 +182,7 @@ public: // 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::TransportFd& fd, int sslError, FdTrigger* fdTrigger, + const android::RpcTransportFd& fd, int sslError, FdTrigger* fdTrigger, const char* fnString, int additionalEvent, const std::optional<android::base::function_ref<status_t()>>& altPoll) { switch (sslError) { @@ -198,7 +198,7 @@ public: private: bool mHandled = false; - status_t handlePoll(int event, const android::TransportFd& fd, FdTrigger* fdTrigger, + status_t handlePoll(int event, const android::RpcTransportFd& fd, FdTrigger* fdTrigger, const char* fnString, const std::optional<android::base::function_ref<status_t()>>& altPoll) { status_t ret; @@ -277,7 +277,7 @@ private: class RpcTransportTls : public RpcTransport { public: - RpcTransportTls(TransportFd socket, Ssl ssl) + RpcTransportTls(RpcTransportFd socket, Ssl ssl) : mSocket(std::move(socket)), mSsl(std::move(ssl)) {} status_t pollRead(void) override; status_t interruptableWriteFully( @@ -293,7 +293,7 @@ public: bool isWaiting() { return mSocket.isInPollingState(); }; private: - android::TransportFd mSocket; + android::RpcTransportFd mSocket; Ssl mSsl; }; @@ -411,7 +411,7 @@ status_t RpcTransportTls::interruptableReadFully( } // For |ssl|, set internal FD to |fd|, and do handshake. Handshake is triggerable by |fdTrigger|. -bool setFdAndDoHandshake(Ssl* ssl, const android::TransportFd& socket, FdTrigger* fdTrigger) { +bool setFdAndDoHandshake(Ssl* ssl, const android::RpcTransportFd& socket, FdTrigger* fdTrigger) { bssl::UniquePtr<BIO> bio = newSocketBio(socket.fd); TEST_AND_RETURN(false, bio != nullptr); auto [_, errorQueue] = ssl->call(SSL_set_bio, bio.get(), bio.get()); @@ -444,7 +444,8 @@ public: typename = std::enable_if_t<std::is_base_of_v<RpcTransportCtxTls, Impl>>> static std::unique_ptr<RpcTransportCtxTls> create( std::shared_ptr<RpcCertificateVerifier> verifier, RpcAuth* auth); - std::unique_ptr<RpcTransport> newTransport(TransportFd fd, FdTrigger* fdTrigger) const override; + std::unique_ptr<RpcTransport> newTransport(RpcTransportFd fd, + FdTrigger* fdTrigger) const override; std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override; protected: @@ -514,7 +515,7 @@ std::unique_ptr<RpcTransportCtxTls> RpcTransportCtxTls::create( return ret; } -std::unique_ptr<RpcTransport> RpcTransportCtxTls::newTransport(android::TransportFd socket, +std::unique_ptr<RpcTransport> RpcTransportCtxTls::newTransport(android::RpcTransportFd socket, FdTrigger* fdTrigger) const { bssl::UniquePtr<SSL> ssl(SSL_new(mCtx.get())); TEST_AND_RETURN(nullptr, ssl != nullptr); diff --git a/libs/binder/RpcTransportUtils.h b/libs/binder/RpcTransportUtils.h index d0843c0cc0..32f0db805d 100644 --- a/libs/binder/RpcTransportUtils.h +++ b/libs/binder/RpcTransportUtils.h @@ -25,7 +25,7 @@ namespace android { template <typename SendOrReceive> status_t interruptableReadOrWrite( - const android::TransportFd& socket, FdTrigger* fdTrigger, iovec* iovs, int niovs, + const android::RpcTransportFd& socket, FdTrigger* fdTrigger, iovec* iovs, int niovs, SendOrReceive sendOrReceiveFun, const char* funName, int16_t event, const std::optional<android::base::function_ref<status_t()>>& altPoll) { MAYBE_WAIT_IN_FLAKE_MODE; diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h index 0a4e9d5a49..ca02ab2a78 100644 --- a/libs/binder/include/binder/RpcServer.h +++ b/libs/binder/include/binder/RpcServer.h @@ -199,8 +199,8 @@ private: static constexpr size_t kRpcAddressSize = 128; static void establishConnection( - sp<RpcServer>&& server, TransportFd clientFd, std::array<uint8_t, kRpcAddressSize> addr, - size_t addrLen, + sp<RpcServer>&& server, RpcTransportFd clientFd, + std::array<uint8_t, kRpcAddressSize> addr, size_t addrLen, std::function<void(sp<RpcSession>&&, RpcSession::PreJoinSetupResult&&)>&& joinFn); [[nodiscard]] status_t setupSocketServer(const RpcSocketAddress& address); @@ -210,7 +210,7 @@ private: // A mode is supported if the N'th bit is on, where N is the mode enum's value. std::bitset<8> mSupportedFileDescriptorTransportModes = std::bitset<8>().set( static_cast<size_t>(RpcSession::FileDescriptorTransportMode::NONE)); - TransportFd mServer; // socket we are accepting sessions on + RpcTransportFd mServer; // socket we are accepting sessions on RpcMutex mLock; // for below std::unique_ptr<RpcMaybeThread> mJoinThread; diff --git a/libs/binder/include/binder/RpcSession.h b/libs/binder/include/binder/RpcSession.h index 392b02c7d3..9630e2fafa 100644 --- a/libs/binder/include/binder/RpcSession.h +++ b/libs/binder/include/binder/RpcSession.h @@ -269,7 +269,7 @@ private: [[nodiscard]] status_t setupOneSocketConnection(const RpcSocketAddress& address, const std::vector<uint8_t>& sessionId, bool incoming); - [[nodiscard]] status_t initAndAddConnection(TransportFd fd, + [[nodiscard]] status_t initAndAddConnection(RpcTransportFd fd, const std::vector<uint8_t>& sessionId, bool incoming); [[nodiscard]] status_t addIncomingConnection(std::unique_ptr<RpcTransport> rpcTransport); diff --git a/libs/binder/include/binder/RpcTransport.h b/libs/binder/include/binder/RpcTransport.h index 89f34f8979..fd52a3a1a9 100644 --- a/libs/binder/include/binder/RpcTransport.h +++ b/libs/binder/include/binder/RpcTransport.h @@ -37,7 +37,7 @@ namespace android { class FdTrigger; -struct TransportFd; +struct RpcTransportFd; // Represents a socket connection. // No thread-safety is guaranteed for these APIs. @@ -107,7 +107,7 @@ public: // Implementation details: for TLS, this function may incur I/O. |fdTrigger| may be used // to interrupt I/O. This function blocks until handshake is finished. [[nodiscard]] virtual std::unique_ptr<RpcTransport> newTransport( - android::TransportFd fd, FdTrigger *fdTrigger) const = 0; + android::RpcTransportFd fd, FdTrigger *fdTrigger) const = 0; // Return the preconfigured certificate of this context. // @@ -140,7 +140,7 @@ protected: RpcTransportCtxFactory() = default; }; -struct TransportFd { +struct RpcTransportFd { private: mutable bool isPolling{false}; @@ -149,20 +149,20 @@ private: public: base::unique_fd fd; - TransportFd() = default; - explicit TransportFd(base::unique_fd &&descriptor) + RpcTransportFd() = default; + explicit RpcTransportFd(base::unique_fd &&descriptor) : isPolling(false), fd(std::move(descriptor)) {} - TransportFd(TransportFd &&transportFd) noexcept + RpcTransportFd(RpcTransportFd &&transportFd) noexcept : isPolling(transportFd.isPolling), fd(std::move(transportFd.fd)) {} - TransportFd &operator=(TransportFd &&transportFd) noexcept { + RpcTransportFd &operator=(RpcTransportFd &&transportFd) noexcept { fd = std::move(transportFd.fd); isPolling = transportFd.isPolling; return *this; } - TransportFd &operator=(base::unique_fd &&descriptor) noexcept { + RpcTransportFd &operator=(base::unique_fd &&descriptor) noexcept { fd = std::move(descriptor); isPolling = false; return *this; diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp index cfdfdf8907..21b0354b60 100644 --- a/libs/binder/tests/binderRpcTest.cpp +++ b/libs/binder/tests/binderRpcTest.cpp @@ -1803,7 +1803,7 @@ public: } void handleOne(android::base::unique_fd acceptedFd) { ASSERT_TRUE(acceptedFd.ok()); - TransportFd transportFd(std::move(acceptedFd)); + RpcTransportFd transportFd(std::move(acceptedFd)); auto serverTransport = mCtx->newTransport(std::move(transportFd), mFdTrigger.get()); if (serverTransport == nullptr) return; // handshake failed ASSERT_TRUE(mPostConnect(serverTransport.get(), mFdTrigger.get())); @@ -1823,7 +1823,7 @@ public: std::unique_ptr<std::thread> mThread; ConnectToServer mConnectToServer; std::unique_ptr<FdTrigger> mFdTrigger = FdTrigger::make(); - TransportFd mFd; + RpcTransportFd mFd; std::unique_ptr<RpcTransportCtx> mCtx; std::shared_ptr<RpcCertificateVerifierSimple> mCertVerifier = std::make_shared<RpcCertificateVerifierSimple>(); @@ -1903,7 +1903,7 @@ public: private: ConnectToServer mConnectToServer; - TransportFd mFd; + RpcTransportFd mFd; std::unique_ptr<FdTrigger> mFdTrigger = FdTrigger::make(); std::unique_ptr<RpcTransportCtx> mCtx; std::shared_ptr<RpcCertificateVerifierSimple> mCertVerifier = diff --git a/libs/binder/trusty/RpcServerTrusty.cpp b/libs/binder/trusty/RpcServerTrusty.cpp index 67d7331eee..18ce316d67 100644 --- a/libs/binder/trusty/RpcServerTrusty.cpp +++ b/libs/binder/trusty/RpcServerTrusty.cpp @@ -118,7 +118,7 @@ int RpcServerTrusty::handleConnect(const tipc_port* port, handle_t chan, const u }; base::unique_fd clientFd(chan); - android::TransportFd transportFd(std::move(clientFd)); + android::RpcTransportFd transportFd(std::move(clientFd)); std::array<uint8_t, RpcServer::kRpcAddressSize> addr; constexpr size_t addrLen = sizeof(*peer); diff --git a/libs/binder/trusty/RpcTransportTipcTrusty.cpp b/libs/binder/trusty/RpcTransportTipcTrusty.cpp index ca7f7d3576..0b67b9fb12 100644 --- a/libs/binder/trusty/RpcTransportTipcTrusty.cpp +++ b/libs/binder/trusty/RpcTransportTipcTrusty.cpp @@ -33,7 +33,7 @@ namespace { // RpcTransport for Trusty. class RpcTransportTipcTrusty : public RpcTransport { public: - explicit RpcTransportTipcTrusty(android::TransportFd socket) : mSocket(std::move(socket)) {} + explicit RpcTransportTipcTrusty(android::RpcTransportFd socket) : mSocket(std::move(socket)) {} ~RpcTransportTipcTrusty() { releaseMessage(); } status_t pollRead() override { @@ -212,7 +212,7 @@ private: } } - android::TransportFd mSocket; + android::RpcTransportFd mSocket; bool mHaveMessage = false; ipc_msg_info mMessageInfo; @@ -222,7 +222,7 @@ private: // RpcTransportCtx for Trusty. class RpcTransportCtxTipcTrusty : public RpcTransportCtx { public: - std::unique_ptr<RpcTransport> newTransport(android::TransportFd socket, + std::unique_ptr<RpcTransport> newTransport(android::RpcTransportFd socket, FdTrigger*) const override { return std::make_unique<RpcTransportTipcTrusty>(std::move(socket)); } |