Revert "gralloc: Return an error if the buffer was not mapped"

This reverts commit 3261eb2236.

Bug: 28526999
Change-Id: I755627af7567c49e7500e92de1124587b1086b38
This commit is contained in:
Steve Pfetsch 2016-06-13 13:30:13 -07:00
parent c571e04757
commit f026d04dde
1 changed files with 29 additions and 34 deletions

View File

@ -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)
{
@ -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) &&
@ -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,
@ -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,