libbinder: build option to disable the kernel IPC, part 1/2
Add a new BINDER_WITH_KERNEL_IPC macro to enable all code that
uses IPCThreadState or ProcessState. This macro is defined for
Android libbinder but left out for non-Android builds.
Bug: 224644083
Test: m
Change-Id: I622757fcc0f9885dbf271c0ffa84c54938d50774
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index 01311b5..bde3d90 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -36,7 +36,6 @@
namespace android {
-using base::ScopeGuard;
using base::StringPrintf;
#if RPC_FLAKE_PRONE
@@ -733,6 +732,7 @@
const sp<RpcSession::RpcConnection>& connection, const sp<RpcSession>& session,
const RpcWireHeader& command, CommandType type,
std::vector<std::variant<base::unique_fd, base::borrowed_fd>>&& ancillaryFds) {
+#ifdef BINDER_WITH_KERNEL_IPC
IPCThreadState* kernelBinderState = IPCThreadState::selfOrNull();
IPCThreadState::SpGuard spGuard{
.address = __builtin_frame_address(0),
@@ -742,11 +742,13 @@
if (kernelBinderState != nullptr) {
origGuard = kernelBinderState->pushGetCallingSpGuard(&spGuard);
}
- ScopeGuard guardUnguard = [&]() {
+
+ base::ScopeGuard guardUnguard = [&]() {
if (kernelBinderState != nullptr) {
kernelBinderState->restoreGetCallingSpGuard(origGuard);
}
};
+#endif // BINDER_WITH_KERNEL_IPC
switch (command.command) {
case RPC_COMMAND_TRANSACT: