Commit b53dfa47 authored by Fritz Koenig's avatar Fritz Koenig Committed by Commit Bot

Multiplane dmabuf import mmap offset computation

mmap fails on some platforms when trying to map
a dmabuf with a non-zero offset.

Instead of passing in the offset to map to, get the
base address and add the offset afterwards.

BUG: none
TEST=./ozone_gl_unittests --gtest_filter=GLImageNativePixmap/GLImageBindTest/5.BindTexImage --gtest_also_run_disabled_tests

Change-Id: Ie20e460e4099f937452a96a6e64b39ec56f1cc3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1979096
Auto-Submit: Fritz Koenig <frkoenig@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Commit-Queue: Fritz Koenig <frkoenig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731605}
parent b8e35886
......@@ -83,7 +83,7 @@ ClientNativePixmapDmaBuf::PlaneInfo::PlaneInfo(PlaneInfo&& info)
ClientNativePixmapDmaBuf::PlaneInfo::~PlaneInfo() {
if (data) {
int ret = munmap(data, size);
int ret = munmap(data, offset + size);
DCHECK(!ret);
}
}
......@@ -183,7 +183,6 @@ ClientNativePixmapDmaBuf::ImportFromDmabuf(gfx::NativePixmapHandle handle,
return nullptr;
}
const size_t page_size = base::GetPageSize();
for (size_t i = 0; i < handle.planes.size(); ++i) {
// Verify that the plane buffer has appropriate size.
size_t min_stride = 0;
......@@ -201,22 +200,19 @@ ClientNativePixmapDmaBuf::ImportFromDmabuf(gfx::NativePixmapHandle handle,
if (!min_size.IsValid() || handle.planes[i].size < min_size.ValueOrDie())
return nullptr;
// mmap() fails if the offset argument is not page-aligned.
// Since handle.planes[i].offset is possibly not page-aligned, we
// have to map with an additional offset to be aligned to the page.
const size_t extra_offset = handle.planes[i].offset % page_size;
size_t map_size =
base::checked_cast<size_t>(handle.planes[i].size + extra_offset);
plane_info[i].offset = extra_offset;
const size_t map_size = base::checked_cast<size_t>(handle.planes[i].size);
plane_info[i].offset = handle.planes[i].offset;
plane_info[i].size = map_size;
void* data =
mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
handle.planes[i].fd.get(), handle.planes[i].offset - extra_offset);
void* data = mmap(nullptr, map_size + handle.planes[i].offset,
(PROT_READ | PROT_WRITE), MAP_SHARED,
handle.planes[i].fd.get(), 0);
if (data == MAP_FAILED) {
logging::SystemErrorCode mmap_error = logging::GetLastSystemErrorCode();
if (mmap_error == ENOMEM)
base::TerminateBecauseOutOfMemory(map_size);
base::TerminateBecauseOutOfMemory(map_size +
handle.planes[i].offset);
LOG(ERROR) << "Failed to mmap dmabuf: "
<< logging::SystemErrorCodeToString(mmap_error);
return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment