OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/embedder/simple_platform_shared_buffer.h" | 5 #include "mojo/edk/embedder/simple_platform_shared_buffer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdio.h> // For |fileno()|. | 8 #include <stdio.h> // For |fileno()|. |
9 #include <sys/mman.h> // For |mmap()|/|munmap()|. | 9 #include <sys/mman.h> // For |mmap()|/|munmap()|. |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <sys/types.h> // For |off_t|. | 11 #include <sys/types.h> // For |off_t|. |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | |
14 #include <limits> | 13 #include <limits> |
| 14 #include <utility> |
15 | 15 |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
18 #include "base/files/scoped_file.h" | 18 #include "base/files/scoped_file.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
23 #include "mojo/edk/embedder/platform_handle.h" | 23 #include "mojo/edk/embedder/platform_handle.h" |
24 | 24 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 if (sb.st_size != static_cast<off_t>(num_bytes_)) { | 110 if (sb.st_size != static_cast<off_t>(num_bytes_)) { |
111 LOG(ERROR) << "Shared memory file has the wrong size"; | 111 LOG(ERROR) << "Shared memory file has the wrong size"; |
112 return false; | 112 return false; |
113 } | 113 } |
114 | 114 |
115 // TODO(vtl): More checks? | 115 // TODO(vtl): More checks? |
116 | 116 |
117 handle_ = platform_handle.Pass(); | 117 handle_ = std::move(platform_handle); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 #endif // !defined(OS_ANDROID) | 121 #endif // !defined(OS_ANDROID) |
122 | 122 |
123 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl( | 123 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl( |
124 size_t offset, | 124 size_t offset, |
125 size_t length) { | 125 size_t length) { |
126 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); | 126 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); |
127 size_t real_offset = offset - offset_rounding; | 127 size_t real_offset = offset - offset_rounding; |
(...skipping 21 matching lines...) Expand all Loading... |
149 | 149 |
150 // SimplePlatformSharedBufferMapping ------------------------------------------- | 150 // SimplePlatformSharedBufferMapping ------------------------------------------- |
151 | 151 |
152 void SimplePlatformSharedBufferMapping::Unmap() { | 152 void SimplePlatformSharedBufferMapping::Unmap() { |
153 int result = munmap(real_base_, real_length_); | 153 int result = munmap(real_base_, real_length_); |
154 PLOG_IF(ERROR, result != 0) << "munmap"; | 154 PLOG_IF(ERROR, result != 0) << "munmap"; |
155 } | 155 } |
156 | 156 |
157 } // namespace edk | 157 } // namespace edk |
158 } // namespace mojo | 158 } // namespace mojo |
OLD | NEW |