Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc

Issue 2302053003: ozone: Validate the memory buffer used. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" 5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <xf86drm.h> 10 #include <xf86drm.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 // static 57 // static
58 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( 58 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf(
59 int dmabuf_fd, 59 int dmabuf_fd,
60 const gfx::Size& size, 60 const gfx::Size& size,
61 int stride) { 61 int stride) {
62 DCHECK_GE(dmabuf_fd, 0); 62 DCHECK_GE(dmabuf_fd, 0);
63 return base::WrapUnique( 63 base::CheckedNumeric<size_t> map_size = stride;
64 new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); 64 map_size *= size.height();
65 if (!map_size.IsValid())
66 return nullptr;
67 return base::WrapUnique(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride,
68 map_size.ValueOrDie()));
65 } 69 }
66 70
67 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, 71 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd,
68 const gfx::Size& size, 72 const gfx::Size& size,
69 int stride) 73 int stride,
70 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { 74 size_t map_size)
75 : dmabuf_fd_(dmabuf_fd), map_size_(map_size), size_(size), stride_(stride) {
71 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); 76 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf");
72 size_t map_size = stride_ * size_.height(); 77 data_ = mmap(nullptr, map_size_, (PROT_READ | PROT_WRITE), MAP_SHARED,
73 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
74 dmabuf_fd, 0); 78 dmabuf_fd, 0);
75 if (data_ == MAP_FAILED) { 79 if (data_ == MAP_FAILED) {
76 PLOG(ERROR) << "Failed mmap()."; 80 PLOG(ERROR) << "Failed mmap().";
77 base::TerminateBecauseOutOfMemory(map_size); 81 base::TerminateBecauseOutOfMemory(map_size_);
78 } 82 }
79 } 83 }
80 84
81 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { 85 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() {
82 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); 86 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf");
83 size_t size = stride_ * size_.height(); 87 int ret = munmap(data_, map_size_);
84 int ret = munmap(data_, size);
85 DCHECK(!ret); 88 DCHECK(!ret);
86 } 89 }
87 90
88 void* ClientNativePixmapDmaBuf::Map() { 91 void* ClientNativePixmapDmaBuf::Map() {
89 TRACE_EVENT0("drm", "DmaBuf:Map"); 92 TRACE_EVENT0("drm", "DmaBuf:Map");
90 PrimeSyncStart(dmabuf_fd_.get()); 93 PrimeSyncStart(dmabuf_fd_.get());
91 return data_; 94 return data_;
92 } 95 }
93 96
94 void ClientNativePixmapDmaBuf::Unmap() { 97 void ClientNativePixmapDmaBuf::Unmap() {
95 TRACE_EVENT0("drm", "DmaBuf:Unmap"); 98 TRACE_EVENT0("drm", "DmaBuf:Unmap");
96 PrimeSyncEnd(dmabuf_fd_.get()); 99 PrimeSyncEnd(dmabuf_fd_.get());
97 } 100 }
98 101
99 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { 102 void ClientNativePixmapDmaBuf::GetStride(int* stride) const {
100 *stride = stride_; 103 *stride = stride_;
101 } 104 }
102 105
103 } // namespace ui 106 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698