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

Commit 8355a71a authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 22066 into eclair

* changes:
  Add offset handling in MemoryHeapBase class
parents 2f142745 d4851d74
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -42,7 +42,7 @@ public:
     * maps the memory referenced by fd. but DOESN'T take ownership
     * maps the memory referenced by fd. but DOESN'T take ownership
     * of the filedescriptor (it makes a copy with dup()
     * of the filedescriptor (it makes a copy with dup()
     */
     */
    MemoryHeapBase(int fd, size_t size, uint32_t flags = 0);
    MemoryHeapBase(int fd, size_t size, uint32_t flags = 0, uint32_t offset = 0);
    
    
    /*
    /*
     * maps memory from the given device
     * maps memory from the given device
@@ -82,7 +82,7 @@ protected:
            int flags = 0, const char* device = NULL);    
            int flags = 0, const char* device = NULL);    


private:
private:
    status_t mapfd(int fd, size_t size);
    status_t mapfd(int fd, size_t size, uint32_t offset = 0);


    int         mFD;
    int         mFD;
    size_t      mSize;
    size_t      mSize;
+4 −4
Original line number Original line Diff line number Diff line
@@ -78,13 +78,13 @@ MemoryHeapBase::MemoryHeapBase(const char* device, size_t size, uint32_t flags)
    }
    }
}
}


MemoryHeapBase::MemoryHeapBase(int fd, size_t size, uint32_t flags)
MemoryHeapBase::MemoryHeapBase(int fd, size_t size, uint32_t flags, uint32_t offset)
    : mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags),
    : mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags),
      mDevice(0), mNeedUnmap(false)
      mDevice(0), mNeedUnmap(false)
{
{
    const size_t pagesize = getpagesize();
    const size_t pagesize = getpagesize();
    size = ((size + pagesize-1) & ~(pagesize-1));
    size = ((size + pagesize-1) & ~(pagesize-1));
    mapfd(dup(fd), size);
    mapfd(dup(fd), size, offset);
}
}


status_t MemoryHeapBase::init(int fd, void *base, int size, int flags, const char* device)
status_t MemoryHeapBase::init(int fd, void *base, int size, int flags, const char* device)
@@ -100,7 +100,7 @@ status_t MemoryHeapBase::init(int fd, void *base, int size, int flags, const cha
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t MemoryHeapBase::mapfd(int fd, size_t size)
status_t MemoryHeapBase::mapfd(int fd, size_t size, uint32_t offset)
{
{
    if (size == 0) {
    if (size == 0) {
        // try to figure out the size automatically
        // try to figure out the size automatically
@@ -121,7 +121,7 @@ status_t MemoryHeapBase::mapfd(int fd, size_t size)


    if ((mFlags & DONT_MAP_LOCALLY) == 0) {
    if ((mFlags & DONT_MAP_LOCALLY) == 0) {
        void* base = (uint8_t*)mmap(0, size,
        void* base = (uint8_t*)mmap(0, size,
                PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
                PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset);
        if (base == MAP_FAILED) {
        if (base == MAP_FAILED) {
            LOGE("mmap(fd=%d, size=%u) failed (%s)",
            LOGE("mmap(fd=%d, size=%u) failed (%s)",
                    fd, uint32_t(size), strerror(errno));
                    fd, uint32_t(size), strerror(errno));