Skip to content

Commit

Permalink
Revert \"gralloc: Return an error if the buffer was not mapped\"
Browse files Browse the repository at this point in the history
am: f026d04

Change-Id: I6e14ceadf3bd57bfa1b608336ed2369383562977
  • Loading branch information
spfetsch authored and android-build-merger committed Jun 14, 2016
2 parents 50c46b7 + f026d04 commit 4e17f54
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions msm8994/libgralloc/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,6 @@ static IMemAlloc* getAllocator(int flags)
return memalloc;
}

static int gralloc_map_metadata(buffer_handle_t handle) {
private_handle_t* hnd = (private_handle_t*)handle;
hnd->base_metadata = 0;
IMemAlloc* memalloc = getAllocator(hnd->flags) ;
void *mappedAddress = MAP_FAILED;
unsigned int size = 0;
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
mappedAddress = MAP_FAILED;
size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
int ret = memalloc->map_buffer(&mappedAddress, size,
hnd->offset_metadata, hnd->fd_metadata);
if(ret || mappedAddress == MAP_FAILED) {
ALOGE("Could not mmap metadata for handle %p, fd=%d (%s)",
hnd, hnd->fd_metadata, strerror(errno));
return -errno;
}
hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
}
return 0;
}

static int gralloc_map(gralloc_module_t const* module,
buffer_handle_t handle)
{
Expand All @@ -89,6 +68,7 @@ static int gralloc_map(gralloc_module_t const* module,
IMemAlloc* memalloc = getAllocator(hnd->flags) ;
void *mappedAddress = MAP_FAILED;
hnd->base = 0;
hnd->base_metadata = 0;

// Dont map framebuffer and secure buffers
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
Expand All @@ -103,18 +83,23 @@ static int gralloc_map(gralloc_module_t const* module,
}

hnd->base = uint64_t(mappedAddress) + hnd->offset;
} else {
// Cannot map secure buffers or framebuffers, but still need to map
// metadata for secure buffers.
// If mapping a secure buffers fails, the framework needs to get
// an error code.
err = -EINVAL;
}

//Allow mapping of metadata for all buffers including secure ones, but not
//of framebuffer
err = gralloc_map_metadata(handle);
return err;
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
mappedAddress = MAP_FAILED;
size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
err = memalloc->map_buffer(&mappedAddress, size,
hnd->offset_metadata, hnd->fd_metadata);
if(err || mappedAddress == MAP_FAILED) {
ALOGE("Could not mmap handle %p, fd=%d (%s)",
handle, hnd->fd_metadata, strerror(errno));
return -errno;
}
hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
}
return 0;
}

static int gralloc_unmap(gralloc_module_t const* module,
Expand Down Expand Up @@ -167,11 +152,21 @@ int gralloc_register_buffer(gralloc_module_t const* module,
ATRACE_CALL();
if (!module || private_handle_t::validate(handle) < 0)
return -EINVAL;
// The base address received via IPC is invalid in this process
// Reset it to 0 here since it will be mapped in lock()
private_handle_t* hnd = (private_handle_t*)handle;
hnd->base = 0;
return gralloc_map_metadata(handle);

/* NOTE: we need to initialize the buffer as not mapped/not locked
* because it shouldn't when this function is called the first time
* in a new process. Ideally these flags shouldn't be part of the
* handle, but instead maintained in the kernel or at least
* out-of-line
*/

int err = gralloc_map(module, handle);
if (err) {
ALOGE("%s: gralloc_map failed", __FUNCTION__);
return err;
}

return 0;
}

int gralloc_unregister_buffer(gralloc_module_t const* module,
Expand Down

0 comments on commit 4e17f54

Please sign in to comment.