diff options
| -rw-r--r-- | libs/binder/IPCThreadState.cpp | 15 | ||||
| -rw-r--r-- | libs/binder/ProcessState.cpp | 7 | ||||
| -rw-r--r-- | libs/binder/include/binder/IPCThreadState.h | 2 | ||||
| -rw-r--r-- | libs/binder/include/binder/ProcessState.h | 14 |
4 files changed, 37 insertions, 1 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index f052bcb982..22f6f54e28 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 @@ status_t IPCThreadState::transact(int32_t handle, } 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 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy) IPCThreadState::IPCThreadState() : mProcess(ProcessState::self()), mStrictModePolicy(0), - mLastTransactionBinderFlags(0) + mLastTransactionBinderFlags(0), + mCallRestriction(mProcess->mCallRestriction) { pthread_setspecific(gTLS, this); clearCaller(); diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 53f8dddfe1..3798b61ab9 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -234,6 +234,12 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; } +void ProcessState::setCallRestriction(CallRestriction restriction) { + LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started."); + + mCallRestriction = restriction; +} + ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle) { const size_t N=mHandleToObject.size(); @@ -426,6 +432,7 @@ ProcessState::ProcessState(const char *driver) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolSeq(1) + , mCallRestriction(CallRestriction::NONE) { if (mDriverFD >= 0) { // mmap the binder, providing a chunk of virtual address space to receive transactions. diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h index 40b51adb06..745f6182f6 100644 --- a/libs/binder/include/binder/IPCThreadState.h +++ b/libs/binder/include/binder/IPCThreadState.h @@ -158,6 +158,8 @@ private: int32_t mStrictModePolicy; int32_t mLastTransactionBinderFlags; IPCThreadStateBase *mIPCThreadStateBase; + + ProcessState::CallRestriction mCallRestriction; }; }; // namespace android diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index 3712c84a58..224cb36807 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -77,6 +77,18 @@ public: ssize_t getKernelReferences(size_t count, uintptr_t* buf); + enum class CallRestriction { + // all calls okay + NONE, + // log when calls are blocking + ERROR_IF_NOT_ONEWAY, + // abort process on blocking calls + FATAL_IF_NOT_ONEWAY, + }; + // Sets calling restrictions for all transactions in this process. This must be called + // before any threads are spawned. + void setCallRestriction(CallRestriction restriction); + private: friend class IPCThreadState; @@ -123,6 +135,8 @@ private: String8 mRootDir; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; + + CallRestriction mCallRestriction; }; }; // namespace android |