Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5ea8f33 authored by Steven Moreland's avatar Steven Moreland Committed by android-build-merger
Browse files

Merge "Allow error/abort for non-oneway calls." am: 4ffbaac8

am: 72c3e195

Change-Id: I9d54c3990bd361a67dfe82a10ec0404185c7e930
parents 84e51e03 72c3e195
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -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>
@@ -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");
@@ -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();
+7 −0
Original line number Original line Diff line number Diff line
@@ -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();
@@ -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.
+2 −0
Original line number Original line Diff line number Diff line
@@ -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
+14 −0
Original line number Original line Diff line number Diff line
@@ -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;
    
    
@@ -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