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

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

Merge "Support initializing ProcessState with custom binder window size."

am: 77a4fa6b

Change-Id: Id1a237475d3bb44740a3c3f64f7da3dd6e60e9ce
parents 8fac56f5 77a4fa6b
Loading
Loading
Loading
Loading
+25 −8
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>


#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
#define DEFAULT_BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
#define DEFAULT_MAX_BINDER_THREADS 15
#define DEFAULT_MAX_BINDER_THREADS 15


#ifdef __ANDROID_VNDK__
#ifdef __ANDROID_VNDK__
@@ -77,7 +77,13 @@ sp<ProcessState> ProcessState::self()
    if (gProcess != nullptr) {
    if (gProcess != nullptr) {
        return gProcess;
        return gProcess;
    }
    }
    gProcess = new ProcessState(kDefaultDriver);
    gProcess = new ProcessState(kDefaultDriver, DEFAULT_BINDER_VM_SIZE);
    return gProcess;
}

sp<ProcessState> ProcessState::selfOrNull()
{
    Mutex::Autolock _l(gProcessMutex);
    return gProcess;
    return gProcess;
}
}


@@ -98,13 +104,19 @@ sp<ProcessState> ProcessState::initWithDriver(const char* driver)
        driver = "/dev/binder";
        driver = "/dev/binder";
    }
    }


    gProcess = new ProcessState(driver);
    gProcess = new ProcessState(driver, DEFAULT_BINDER_VM_SIZE);
    return gProcess;
    return gProcess;
}
}


sp<ProcessState> ProcessState::selfOrNull()
sp<ProcessState> ProcessState::initWithMmapSize(size_t mmap_size) {
{
    Mutex::Autolock _l(gProcessMutex);
    Mutex::Autolock _l(gProcessMutex);
    if (gProcess != nullptr) {
        LOG_ALWAYS_FATAL_IF(mmap_size != gProcess->getMmapSize(),
                "ProcessState already initialized with a different mmap size.");
        return gProcess;
    }

    gProcess = new ProcessState(kDefaultDriver, mmap_size);
    return gProcess;
    return gProcess;
}
}


@@ -237,6 +249,10 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
    return count;
    return count;
}
}


size_t ProcessState::getMmapSize() {
    return mMmapSize;
}

void ProcessState::setCallRestriction(CallRestriction restriction) {
void ProcessState::setCallRestriction(CallRestriction restriction) {
    LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");
    LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");


@@ -421,7 +437,7 @@ static int open_driver(const char *driver)
    return fd;
    return fd;
}
}


ProcessState::ProcessState(const char *driver)
ProcessState::ProcessState(const char *driver, size_t mmap_size)
    : mDriverName(String8(driver))
    : mDriverName(String8(driver))
    , mDriverFD(open_driver(driver))
    , mDriverFD(open_driver(driver))
    , mVMStart(MAP_FAILED)
    , mVMStart(MAP_FAILED)
@@ -435,11 +451,12 @@ ProcessState::ProcessState(const char *driver)
    , mBinderContextUserData(nullptr)
    , mBinderContextUserData(nullptr)
    , mThreadPoolStarted(false)
    , mThreadPoolStarted(false)
    , mThreadPoolSeq(1)
    , mThreadPoolSeq(1)
    , mMmapSize(mmap_size)
    , mCallRestriction(CallRestriction::NONE)
    , 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.
        mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
        mVMStart = mmap(nullptr, mMmapSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
        if (mVMStart == MAP_FAILED) {
        if (mVMStart == MAP_FAILED) {
            // *sigh*
            // *sigh*
            ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
            ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
@@ -456,7 +473,7 @@ ProcessState::~ProcessState()
{
{
    if (mDriverFD >= 0) {
    if (mDriverFD >= 0) {
        if (mVMStart != MAP_FAILED) {
        if (mVMStart != MAP_FAILED) {
            munmap(mVMStart, BINDER_VM_SIZE);
            munmap(mVMStart, mMmapSize);
        }
        }
        close(mDriverFD);
        close(mDriverFD);
    }
    }
+5 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@ class ProcessState : public virtual RefBase
public:
public:
    static  sp<ProcessState>    self();
    static  sp<ProcessState>    self();
    static  sp<ProcessState>    selfOrNull();
    static  sp<ProcessState>    selfOrNull();
    // Note: don't call self() or selfOrNull() before initWithMmapSize()
    static  sp<ProcessState>    initWithMmapSize(size_t mmapSize); // size in bytes


    /* initWithDriver() can be used to configure libbinder to use
    /* initWithDriver() can be used to configure libbinder to use
     * a different binder driver dev node. It must be called *before*
     * a different binder driver dev node. It must be called *before*
@@ -76,6 +78,7 @@ public:
            String8             getDriverName();
            String8             getDriverName();


            ssize_t             getKernelReferences(size_t count, uintptr_t* buf);
            ssize_t             getKernelReferences(size_t count, uintptr_t* buf);
            size_t              getMmapSize();


            enum class CallRestriction {
            enum class CallRestriction {
                // all calls okay
                // all calls okay
@@ -92,7 +95,7 @@ public:
private:
private:
    friend class IPCThreadState;
    friend class IPCThreadState;
    
    
            explicit            ProcessState(const char* driver);
            explicit            ProcessState(const char* driver, size_t mmap_size);
                                ~ProcessState();
                                ~ProcessState();


                                ProcessState(const ProcessState& o);
                                ProcessState(const ProcessState& o);
@@ -135,6 +138,7 @@ private:
            String8             mRootDir;
            String8             mRootDir;
            bool                mThreadPoolStarted;
            bool                mThreadPoolStarted;
    volatile int32_t            mThreadPoolSeq;
    volatile int32_t            mThreadPoolSeq;
            size_t              mMmapSize;


            CallRestriction     mCallRestriction;
            CallRestriction     mCallRestriction;
};
};