Allow error/abort for non-oneway calls.
Low-level processes like init might not want to make blocking calls.
This provides the mechanism to programmatically enforce that.
Test: enable ERROR_BLOCKING on process and look at callstacks
Bug: 36424585
Change-Id: I6dad33271108768f8bfc4723bf3eeddbf9720395
(cherry picked from commit b7412b0d15e5e5625c63cc2aacba72a692594837)
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index f052bcb..22f6f54 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -23,7 +23,9 @@
#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>
#include <utils/SystemClock.h>
#include <utils/threads.h>
@@ -617,6 +619,16 @@
}
if ((flags & TF_ONE_WAY) == 0) {
+ if (UNLIKELY(mCallRestriction != ProcessState::CallRestriction::NONE)) {
+ if (mCallRestriction == ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY) {
+ ALOGE("Process making non-oneway call but is restricted.");
+ CallStack::logStack("non-oneway call", CallStack::getCurrent(10).get(),
+ ANDROID_LOG_ERROR);
+ } else /* FATAL_IF_NOT_ONEWAY */ {
+ LOG_ALWAYS_FATAL("Process may not make oneway calls.");
+ }
+ }
+
#if 0
if (code == 4) { // relayout
ALOGI(">>>>>> CALLING transaction 4");
@@ -737,7 +749,8 @@
IPCThreadState::IPCThreadState()
: mProcess(ProcessState::self()),
mStrictModePolicy(0),
- mLastTransactionBinderFlags(0)
+ mLastTransactionBinderFlags(0),
+ mCallRestriction(mProcess->mCallRestriction)
{
pthread_setspecific(gTLS, this);
clearCaller();