diff options
| author | 2019-01-14 14:46:35 -0800 | |
|---|---|---|
| committer | 2019-01-14 14:46:35 -0800 | |
| commit | 77081f8a47ee575880d7a5244a6827a424f3054d (patch) | |
| tree | 711a540279fdc9630c938eeffef7e01d93a2cdb0 | |
| parent | f5ca85113d68da6a18571dcbeab8a346e2049c5f (diff) | |
| parent | d5ea8f33633b1cbaadccc52626adf56e38dbc993 (diff) | |
Merge "Allow error/abort for non-oneway calls." am: 4ffbaac8e8 am: 72c3e1959b
am: d5ea8f3363
Change-Id: Iaada60775896b7e09da684fe304d4332ef940dc1
| -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 8df83f1afe..1d4e234558 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> @@ -661,6 +663,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"); @@ -783,7 +795,8 @@ IPCThreadState::IPCThreadState() mWorkSource(kUnsetWorkSource), mPropagateWorkSource(false), 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 26e8c0b599..a6b0f7e218 100644 --- a/libs/binder/include/binder/IPCThreadState.h +++ b/libs/binder/include/binder/IPCThreadState.h @@ -183,6 +183,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 |