libbinder: use after fork aborts
This is a separate CL, since the warning is independently useful, even
if this needs to be reverted.
Fixes: 202289725
Test: binderLibTest
Change-Id: Ifb046f01cee047d1908a69c075a66ecb0bc68a78
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index e2ab515..4f21cda 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -93,9 +93,7 @@
[[clang::no_destroy]] static std::mutex gProcessMutex;
static void verifyNotForked(bool forked) {
- if (forked) {
- ALOGE("libbinder does not support being forked");
- }
+ LOG_ALWAYS_FATAL_IF(forked, "libbinder ProcessState can not be used after fork");
}
sp<ProcessState> ProcessState::init(const char *driver, bool requireDefault)
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 639876f..7a2bd81 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -436,6 +436,11 @@
};
};
+TEST_F(BinderLibTest, CannotUseBinderAfterFork) {
+ // EXPECT_DEATH works by forking the process
+ EXPECT_DEATH({ ProcessState::self(); }, "libbinder ProcessState can not be used after fork");
+}
+
TEST_F(BinderLibTest, WasParceled) {
auto binder = sp<BBinder>::make();
EXPECT_FALSE(binder->wasParceled());