summaryrefslogtreecommitdiffstats
path: root/modules/gralloc/mapper.cpp
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-07-07 17:53:43 -0700
committerMathias Agopian <mathias@google.com>2009-07-07 17:53:43 -0700
commitbd80b38f2945ac918f66fb336c149b28b9dd030e (patch)
treede39a66516d8503e266ade1b98f3326188c4fb95 /modules/gralloc/mapper.cpp
parent440d4e4741a2641173b44bd9b810c9a4960206c2 (diff)
downloadhardware_libhardware-bd80b38f2945ac918f66fb336c149b28b9dd030e.zip
hardware_libhardware-bd80b38f2945ac918f66fb336c149b28b9dd030e.tar.gz
hardware_libhardware-bd80b38f2945ac918f66fb336c149b28b9dd030e.tar.bz2
more fixes for [1965730]. We now free (unmap) both ashmem and pmem regions.
Diffstat (limited to 'modules/gralloc/mapper.cpp')
-rw-r--r--modules/gralloc/mapper.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/modules/gralloc/mapper.cpp b/modules/gralloc/mapper.cpp
index 75a9bb6..323f5d8 100644
--- a/modules/gralloc/mapper.cpp
+++ b/modules/gralloc/mapper.cpp
@@ -75,7 +75,14 @@ static int gralloc_unmap(gralloc_module_t const* module,
{
private_handle_t* hnd = (private_handle_t*)handle;
if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
- if (munmap((void*)hnd->base, hnd->size) < 0) {
+ void* base = (void*)hnd->base;
+ size_t size = hnd->size;
+#if PMEM_HACK
+ base = (void*)(intptr_t(base) - hnd->offset);
+ size += hnd->offset;
+#endif
+ //LOGD("unmapping from %p, size=%d", base, size);
+ if (munmap(base, size) < 0) {
LOGE("Could not unmap %s", strerror(errno));
}
}
@@ -144,6 +151,33 @@ int gralloc_unregister_buffer(gralloc_module_t const* module,
return 0;
}
+int terminateBuffer(gralloc_module_t const* module,
+ private_handle_t* hnd)
+{
+ /*
+ * If the buffer has been mapped during a lock operation, it's time
+ * to un-map it. It's an error to be here with a locked buffer.
+ */
+
+ LOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK,
+ "handle %p still locked (state=%08x)",
+ hnd, hnd->lockState);
+
+ if (hnd->lockState & private_handle_t::LOCK_STATE_MAPPED) {
+ // this buffer was mapped, unmap it now
+ if ((hnd->flags & private_handle_t::PRIV_FLAGS_USES_PMEM) &&
+ (hnd->pid == getpid())) {
+ // ... unless it's a "master" pmem buffer, that is a buffer
+ // mapped in the process it's been allocated.
+ // (see gralloc_alloc_buffer())
+ } else {
+ gralloc_unmap(module, hnd);
+ }
+ }
+
+ return 0;
+}
+
int gralloc_lock(gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,