diff options
author | 2023-11-02 15:07:45 -0700 | |
---|---|---|
committer | 2023-11-03 09:40:33 -0700 | |
commit | df07f945b946fd1f7039d225ecd3de51a901ace7 (patch) | |
tree | 1f37c190b6cd567549cfd14f3efca5eeb18c19a7 | |
parent | d429f318b42341f27d035072193c2d5da0826e93 (diff) |
Binder: migrate off libbase macros
Test: mma
Bug: 302723053
Change-Id: Ie7c13c324311f600d72bc8ecc4157ad6c46259a0
-rw-r--r-- | libs/binder/FdTrigger.cpp | 5 | ||||
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 11 | ||||
-rw-r--r-- | libs/binder/RpcSession.cpp | 5 | ||||
-rw-r--r-- | libs/binder/RpcState.cpp | 9 | ||||
-rw-r--r-- | libs/binder/ServiceManagerHost.cpp | 3 | ||||
-rw-r--r-- | libs/binder/ServiceManagerHost.h | 1 | ||||
-rw-r--r-- | libs/binder/Utils.h | 11 | ||||
-rw-r--r-- | libs/binder/UtilsHost.h | 4 | ||||
-rw-r--r-- | libs/binder/tests/binderRpcWireProtocolTest.cpp | 1 | ||||
-rw-r--r-- | libs/binder/tests/unit_fuzzers/RecordedTransactionFileFuzz.cpp | 3 | ||||
-rw-r--r-- | libs/binder/tests/unit_fuzzers/RecordedTransactionFuzz.cpp | 3 | ||||
-rw-r--r-- | libs/binder/trusty/include/binder/RpcServerTrusty.h | 4 | ||||
-rw-r--r-- | libs/binder/trusty/logging.cpp | 1 |
13 files changed, 35 insertions, 26 deletions
diff --git a/libs/binder/FdTrigger.cpp b/libs/binder/FdTrigger.cpp index 8ee6cb0615..37c21bb5cd 100644 --- a/libs/binder/FdTrigger.cpp +++ b/libs/binder/FdTrigger.cpp @@ -21,10 +21,11 @@ #include <poll.h> -#include <android-base/macros.h> #include <android-base/scopeguard.h> #include "RpcState.h" +#include "Utils.h" + namespace android { std::unique_ptr<FdTrigger> FdTrigger::make() { @@ -77,7 +78,7 @@ status_t FdTrigger::triggerablePoll(const android::RpcTransportFd& transportFd, auto pollingStateGuard = android::base::make_scope_guard([&]() { transportFd.setPollingState(false); }); - int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); + int ret = TEMP_FAILURE_RETRY(poll(pfd, countof(pfd), -1)); if (ret < 0) { return -errno; } diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index da58251149..9341eff91e 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -22,7 +22,6 @@ #include <binder/BpBinder.h> #include <binder/TextOutput.h> -#include <android-base/macros.h> #include <cutils/sched_policy.h> #include <utils/CallStack.h> #include <utils/Log.h> @@ -395,7 +394,9 @@ void IPCThreadState::restoreGetCallingSpGuard(const SpGuard* guard) { } void IPCThreadState::checkContextIsBinderForUse(const char* use) const { - if (LIKELY(mServingStackPointerGuard == nullptr)) return; + if (mServingStackPointerGuard == nullptr) [[likely]] { + return; + } if (!mServingStackPointer || mServingStackPointerGuard->address < mServingStackPointer) { LOG_ALWAYS_FATAL("In context %s, %s does not make sense (binder sp: %p, guard: %p).", @@ -832,7 +833,7 @@ status_t IPCThreadState::transact(int32_t handle, } if ((flags & TF_ONE_WAY) == 0) { - if (UNLIKELY(mCallRestriction != ProcessState::CallRestriction::NONE)) { + if (mCallRestriction != ProcessState::CallRestriction::NONE) [[unlikely]] { if (mCallRestriction == ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY) { ALOGE("Process making non-oneway call (code: %u) but is restricted.", code); CallStack::logStack("non-oneway call", CallStack::getCurrent(10).get(), @@ -842,13 +843,13 @@ status_t IPCThreadState::transact(int32_t handle, } } - #if 0 +#if 0 if (code == 4) { // relayout ALOGI(">>>>>> CALLING transaction 4"); } else { ALOGI(">>>>>> CALLING transaction %d", code); } - #endif +#endif if (reply) { err = waitForResponse(reply); } else { diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index c8aff63078..7e181941a9 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -26,7 +26,6 @@ #include <string_view> -#include <android-base/macros.h> #include <android-base/scopeguard.h> #include <binder/BpBinder.h> #include <binder/Parcel.h> @@ -411,7 +410,9 @@ public: } private: - DISALLOW_COPY_AND_ASSIGN(JavaThreadAttacher); + JavaThreadAttacher(const JavaThreadAttacher&) = delete; + void operator=(const JavaThreadAttacher&) = delete; + bool mAttached = false; static JavaVM* getJavaVM() { diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index 749c2f81ea..964a5c4ff9 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -18,7 +18,6 @@ #include "RpcState.h" -#include <android-base/macros.h> #include <android-base/scopeguard.h> #include <binder/BpBinder.h> #include <binder/IPCThreadState.h> @@ -601,7 +600,7 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti objectTableSpan.toIovec(), }; if (status_t status = rpcSend( - connection, session, "transaction", iovs, arraysize(iovs), + connection, session, "transaction", iovs, countof(iovs), [&] { if (waitUs > kWaitLogUs) { ALOGE("Cannot send command, trying to process pending refcounts. Waiting " @@ -690,7 +689,7 @@ status_t RpcState::waitForReply(const sp<RpcSession::RpcConnection>& connection, {&rpcReply, rpcReplyWireSize}, {data.data(), data.size()}, }; - if (status_t status = rpcRec(connection, session, "reply body", iovs, arraysize(iovs), nullptr); + if (status_t status = rpcRec(connection, session, "reply body", iovs, countof(iovs), nullptr); status != OK) return status; @@ -760,7 +759,7 @@ status_t RpcState::sendDecStrongToTarget(const sp<RpcSession::RpcConnection>& co .bodySize = sizeof(RpcDecStrong), }; iovec iovs[]{{&cmd, sizeof(cmd)}, {&body, sizeof(body)}}; - return rpcSend(connection, session, "dec ref", iovs, arraysize(iovs), std::nullopt); + return rpcSend(connection, session, "dec ref", iovs, countof(iovs), std::nullopt); } status_t RpcState::getAndExecuteCommand(const sp<RpcSession::RpcConnection>& connection, @@ -1143,7 +1142,7 @@ processTransactInternalTailCall: {const_cast<uint8_t*>(reply.data()), reply.dataSize()}, objectTableSpan.toIovec(), }; - return rpcSend(connection, session, "reply", iovs, arraysize(iovs), std::nullopt, + return rpcSend(connection, session, "reply", iovs, countof(iovs), std::nullopt, rpcFields->mFds.get()); } diff --git a/libs/binder/ServiceManagerHost.cpp b/libs/binder/ServiceManagerHost.cpp index 2b67f030e0..7f43bb64a0 100644 --- a/libs/binder/ServiceManagerHost.cpp +++ b/libs/binder/ServiceManagerHost.cpp @@ -56,7 +56,8 @@ public: [[nodiscard]] const std::optional<unsigned int>& hostPort() const { return mPort; } private: - DISALLOW_COPY_AND_ASSIGN(AdbForwarder); + AdbForwarder(const AdbForwarder&) = delete; + void operator=(const AdbForwarder&) = delete; explicit AdbForwarder(unsigned int port) : mPort(port) {} std::optional<unsigned int> mPort; }; diff --git a/libs/binder/ServiceManagerHost.h b/libs/binder/ServiceManagerHost.h index c5310dac20..941ba3a757 100644 --- a/libs/binder/ServiceManagerHost.h +++ b/libs/binder/ServiceManagerHost.h @@ -16,7 +16,6 @@ #pragma once -#include <android-base/macros.h> #include <android/os/IServiceManager.h> namespace android { diff --git a/libs/binder/Utils.h b/libs/binder/Utils.h index 8942c31c48..68d639208e 100644 --- a/libs/binder/Utils.h +++ b/libs/binder/Utils.h @@ -45,6 +45,17 @@ namespace android { +/** + * Get the size of a statically initialized array. + * + * \param N the array to get the size of. + * \return the size of the array. + */ +template <typename T, size_t N> +constexpr size_t countof(T (&)[N]) { + return N; +} + // avoid optimizations void zeroMemory(uint8_t* data, size_t size); diff --git a/libs/binder/UtilsHost.h b/libs/binder/UtilsHost.h index 98ac4e0c48..14a8dcba57 100644 --- a/libs/binder/UtilsHost.h +++ b/libs/binder/UtilsHost.h @@ -22,7 +22,6 @@ #include <variant> #include <vector> -#include <android-base/macros.h> #include <android-base/result.h> #include <android-base/unique_fd.h> @@ -67,7 +66,8 @@ struct CommandResult { } private: - DISALLOW_COPY_AND_ASSIGN(CommandResult); + CommandResult(const CommandResult&) = delete; + void operator=(const CommandResult&) = delete; }; std::ostream& operator<<(std::ostream& os, const CommandResult& res); diff --git a/libs/binder/tests/binderRpcWireProtocolTest.cpp b/libs/binder/tests/binderRpcWireProtocolTest.cpp index 7ec7c99f06..e59dc82b2b 100644 --- a/libs/binder/tests/binderRpcWireProtocolTest.cpp +++ b/libs/binder/tests/binderRpcWireProtocolTest.cpp @@ -15,7 +15,6 @@ */ #include <android-base/logging.h> -#include <android-base/macros.h> #include <android-base/properties.h> #include <android-base/strings.h> #include <binder/Parcel.h> diff --git a/libs/binder/tests/unit_fuzzers/RecordedTransactionFileFuzz.cpp b/libs/binder/tests/unit_fuzzers/RecordedTransactionFileFuzz.cpp index f3006cdeee..070618294f 100644 --- a/libs/binder/tests/unit_fuzzers/RecordedTransactionFileFuzz.cpp +++ b/libs/binder/tests/unit_fuzzers/RecordedTransactionFileFuzz.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android-base/macros.h> #include <binder/RecordedTransaction.h> #include <filesystem> @@ -36,7 +35,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { intermediateFile = std::tmpfile(); android::base::unique_fd fdForWriting(dup(fileno(intermediateFile))); - auto writeStatus ATTRIBUTE_UNUSED = transaction.value().dumpToFile(fdForWriting); + auto writeStatus [[maybe_unused]] = transaction.value().dumpToFile(fdForWriting); std::fclose(intermediateFile); } diff --git a/libs/binder/tests/unit_fuzzers/RecordedTransactionFuzz.cpp b/libs/binder/tests/unit_fuzzers/RecordedTransactionFuzz.cpp index 33a653eb33..9289f6ac90 100644 --- a/libs/binder/tests/unit_fuzzers/RecordedTransactionFuzz.cpp +++ b/libs/binder/tests/unit_fuzzers/RecordedTransactionFuzz.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android-base/macros.h> #include <binder/RecordedTransaction.h> #include <fuzzbinder/random_parcel.h> #include <filesystem> @@ -55,7 +54,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (transaction.has_value()) { std::FILE* intermediateFile = std::tmpfile(); android::base::unique_fd fdForWriting(dup(fileno(intermediateFile))); - auto writeStatus ATTRIBUTE_UNUSED = transaction.value().dumpToFile(fdForWriting); + auto writeStatus [[maybe_unused]] = transaction.value().dumpToFile(fdForWriting); std::fclose(intermediateFile); } diff --git a/libs/binder/trusty/include/binder/RpcServerTrusty.h b/libs/binder/trusty/include/binder/RpcServerTrusty.h index 8924b3679f..aa476f946a 100644 --- a/libs/binder/trusty/include/binder/RpcServerTrusty.h +++ b/libs/binder/trusty/include/binder/RpcServerTrusty.h @@ -17,7 +17,6 @@ #pragma once #include <android-base/expected.h> -#include <android-base/macros.h> #include <android-base/unique_fd.h> #include <binder/IBinder.h> #include <binder/RpcServer.h> @@ -83,7 +82,8 @@ private: // Both this class and RpcServer have multiple non-copyable fields, // including mPortAcl below which can't be copied because mUuidPtrs // holds pointers into it - DISALLOW_COPY_AND_ASSIGN(RpcServerTrusty); + RpcServerTrusty(const RpcServerTrusty&) = delete; + void operator=(const RpcServerTrusty&) = delete; friend sp<RpcServerTrusty>; explicit RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::string&& portName, diff --git a/libs/binder/trusty/logging.cpp b/libs/binder/trusty/logging.cpp index b4243af891..88a1075f60 100644 --- a/libs/binder/trusty/logging.cpp +++ b/libs/binder/trusty/logging.cpp @@ -22,7 +22,6 @@ #include <iostream> #include <string> -#include <android-base/macros.h> #include <android-base/strings.h> namespace android { |