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

Commit 8a154aee authored by Nick Kralevich's avatar Nick Kralevich Committed by Android Git Automerger
Browse files

am 42d38127: Merge "Allow pixelflinger to work when NX (No Execute) is enabled." into kraken

parents cb6d5c1e 42d38127
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#include <cutils/log.h>
#include <cutils/atomic.h>
@@ -39,15 +41,14 @@ namespace android {
Assembly::Assembly(size_t size)
    : mCount(1), mSize(0)
{
    mBase = (uint32_t*)malloc(size);
    if (mBase) {
    mBase = (uint32_t*)mspace_malloc(getMspace(), size);
    mSize = size;
    }
    ensureMbaseExecutable();
}

Assembly::~Assembly()
{
    free(mBase);
    mspace_free(getMspace(), mBase);
}

void Assembly::incStrong(const void*) const
@@ -75,11 +76,32 @@ uint32_t* Assembly::base() const

ssize_t Assembly::resize(size_t newSize)
{
    mBase = (uint32_t*)realloc(mBase, newSize);
    mBase = (uint32_t*)mspace_realloc(getMspace(), mBase, newSize);
    mSize = newSize;
    ensureMbaseExecutable();
    return size();
}

mspace Assembly::getMspace()
{
    static mspace msp = create_contiguous_mspace(2 * 1024, 1024 * 1024, /*locked=*/ false);
    return msp;
}

void Assembly::ensureMbaseExecutable()
{
    long pagesize = sysconf(_SC_PAGESIZE);
    long pagemask = ~(pagesize - 1);  // assumes pagesize is a power of 2

    uint32_t* pageStart = (uint32_t*) (((uintptr_t) mBase) & pagemask);
    size_t adjustedLength = mBase - pageStart + mSize;

    if (mBase && mprotect(pageStart, adjustedLength, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
        mspace_free(getMspace(), mBase);
        mBase = NULL;
    }
}

// ----------------------------------------------------------------------------

CodeCache::CodeCache(size_t size)
+5 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <stdint.h>
#include <pthread.h>
#include <sys/types.h>
#include <cutils/mspace.h>

#include "tinyutils/KeyedVector.h"
#include "tinyutils/smartpointer.h"
@@ -67,9 +68,12 @@ public:
    typedef void    weakref_type;

private:
    static  mspace  getMspace();
            void    ensureMbaseExecutable();

    mutable int32_t     mCount;
            uint32_t*   mBase;
            ssize_t     mSize;
            size_t      mSize;
};

// ----------------------------------------------------------------------------