Loading libs/binder/IPCThreadState.cpp +14 −1 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,9 @@ #include <binder/BpBinder.h> #include <binder/BpBinder.h> #include <binder/TextOutput.h> #include <binder/TextOutput.h> #include <android-base/macros.h> #include <cutils/sched_policy.h> #include <cutils/sched_policy.h> #include <utils/CallStack.h> #include <utils/Log.h> #include <utils/Log.h> #include <utils/SystemClock.h> #include <utils/SystemClock.h> #include <utils/threads.h> #include <utils/threads.h> Loading Loading @@ -617,6 +619,16 @@ status_t IPCThreadState::transact(int32_t handle, } } if ((flags & TF_ONE_WAY) == 0) { 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 0 if (code == 4) { // relayout if (code == 4) { // relayout ALOGI(">>>>>> CALLING transaction 4"); ALOGI(">>>>>> CALLING transaction 4"); Loading Loading @@ -737,7 +749,8 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy) IPCThreadState::IPCThreadState() IPCThreadState::IPCThreadState() : mProcess(ProcessState::self()), : mProcess(ProcessState::self()), mStrictModePolicy(0), mStrictModePolicy(0), mLastTransactionBinderFlags(0) mLastTransactionBinderFlags(0), mCallRestriction(mProcess->mCallRestriction) { { pthread_setspecific(gTLS, this); pthread_setspecific(gTLS, this); clearCaller(); clearCaller(); Loading libs/binder/ProcessState.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -234,6 +234,12 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; 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) ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle) { { const size_t N=mHandleToObject.size(); const size_t N=mHandleToObject.size(); Loading Loading @@ -426,6 +432,7 @@ ProcessState::ProcessState(const char *driver) , mBinderContextUserData(nullptr) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolStarted(false) , mThreadPoolSeq(1) , mThreadPoolSeq(1) , mCallRestriction(CallRestriction::NONE) { { if (mDriverFD >= 0) { if (mDriverFD >= 0) { // mmap the binder, providing a chunk of virtual address space to receive transactions. // mmap the binder, providing a chunk of virtual address space to receive transactions. Loading libs/binder/include/binder/IPCThreadState.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -158,6 +158,8 @@ private: int32_t mStrictModePolicy; int32_t mStrictModePolicy; int32_t mLastTransactionBinderFlags; int32_t mLastTransactionBinderFlags; IPCThreadStateBase *mIPCThreadStateBase; IPCThreadStateBase *mIPCThreadStateBase; ProcessState::CallRestriction mCallRestriction; }; }; }; // namespace android }; // namespace android Loading libs/binder/include/binder/ProcessState.h +14 −0 Original line number Original line Diff line number Diff line Loading @@ -77,6 +77,18 @@ public: ssize_t getKernelReferences(size_t count, uintptr_t* buf); 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: private: friend class IPCThreadState; friend class IPCThreadState; Loading Loading @@ -123,6 +135,8 @@ private: String8 mRootDir; String8 mRootDir; bool mThreadPoolStarted; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; volatile int32_t mThreadPoolSeq; CallRestriction mCallRestriction; }; }; }; // namespace android }; // namespace android Loading Loading
libs/binder/IPCThreadState.cpp +14 −1 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,9 @@ #include <binder/BpBinder.h> #include <binder/BpBinder.h> #include <binder/TextOutput.h> #include <binder/TextOutput.h> #include <android-base/macros.h> #include <cutils/sched_policy.h> #include <cutils/sched_policy.h> #include <utils/CallStack.h> #include <utils/Log.h> #include <utils/Log.h> #include <utils/SystemClock.h> #include <utils/SystemClock.h> #include <utils/threads.h> #include <utils/threads.h> Loading Loading @@ -617,6 +619,16 @@ status_t IPCThreadState::transact(int32_t handle, } } if ((flags & TF_ONE_WAY) == 0) { 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 0 if (code == 4) { // relayout if (code == 4) { // relayout ALOGI(">>>>>> CALLING transaction 4"); ALOGI(">>>>>> CALLING transaction 4"); Loading Loading @@ -737,7 +749,8 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy) IPCThreadState::IPCThreadState() IPCThreadState::IPCThreadState() : mProcess(ProcessState::self()), : mProcess(ProcessState::self()), mStrictModePolicy(0), mStrictModePolicy(0), mLastTransactionBinderFlags(0) mLastTransactionBinderFlags(0), mCallRestriction(mProcess->mCallRestriction) { { pthread_setspecific(gTLS, this); pthread_setspecific(gTLS, this); clearCaller(); clearCaller(); Loading
libs/binder/ProcessState.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -234,6 +234,12 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; 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) ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle) { { const size_t N=mHandleToObject.size(); const size_t N=mHandleToObject.size(); Loading Loading @@ -426,6 +432,7 @@ ProcessState::ProcessState(const char *driver) , mBinderContextUserData(nullptr) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolStarted(false) , mThreadPoolSeq(1) , mThreadPoolSeq(1) , mCallRestriction(CallRestriction::NONE) { { if (mDriverFD >= 0) { if (mDriverFD >= 0) { // mmap the binder, providing a chunk of virtual address space to receive transactions. // mmap the binder, providing a chunk of virtual address space to receive transactions. Loading
libs/binder/include/binder/IPCThreadState.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -158,6 +158,8 @@ private: int32_t mStrictModePolicy; int32_t mStrictModePolicy; int32_t mLastTransactionBinderFlags; int32_t mLastTransactionBinderFlags; IPCThreadStateBase *mIPCThreadStateBase; IPCThreadStateBase *mIPCThreadStateBase; ProcessState::CallRestriction mCallRestriction; }; }; }; // namespace android }; // namespace android Loading
libs/binder/include/binder/ProcessState.h +14 −0 Original line number Original line Diff line number Diff line Loading @@ -77,6 +77,18 @@ public: ssize_t getKernelReferences(size_t count, uintptr_t* buf); 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: private: friend class IPCThreadState; friend class IPCThreadState; Loading Loading @@ -123,6 +135,8 @@ private: String8 mRootDir; String8 mRootDir; bool mThreadPoolStarted; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; volatile int32_t mThreadPoolSeq; CallRestriction mCallRestriction; }; }; }; // namespace android }; // namespace android Loading