| 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/embedder/simple_platform_shared_buffer.h" | 5 #include "mojo/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> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 handle_.get().fd, | 134 handle_.get().fd, |
| 135 static_cast<off_t>(real_offset)); | 135 static_cast<off_t>(real_offset)); |
| 136 // |mmap()| should return |MAP_FAILED| (a.k.a. -1) on error. But it shouldn't | 136 // |mmap()| should return |MAP_FAILED| (a.k.a. -1) on error. But it shouldn't |
| 137 // return null either. | 137 // return null either. |
| 138 if (real_base == MAP_FAILED || !real_base) { | 138 if (real_base == MAP_FAILED || !real_base) { |
| 139 PLOG(ERROR) << "mmap"; | 139 PLOG(ERROR) << "mmap"; |
| 140 return scoped_ptr<PlatformSharedBufferMapping>(); | 140 return scoped_ptr<PlatformSharedBufferMapping>(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void* base = static_cast<char*>(real_base) + offset_rounding; | 143 void* base = static_cast<char*>(real_base) + offset_rounding; |
| 144 return scoped_ptr<PlatformSharedBufferMapping>( | 144 return make_scoped_ptr(new SimplePlatformSharedBufferMapping( |
| 145 new SimplePlatformSharedBufferMapping( | 145 base, length, real_base, real_length)); |
| 146 base, length, real_base, real_length)); | |
| 147 } | 146 } |
| 148 | 147 |
| 149 // SimplePlatformSharedBufferMapping ------------------------------------------- | 148 // SimplePlatformSharedBufferMapping ------------------------------------------- |
| 150 | 149 |
| 151 void SimplePlatformSharedBufferMapping::Unmap() { | 150 void SimplePlatformSharedBufferMapping::Unmap() { |
| 152 int result = munmap(real_base_, real_length_); | 151 int result = munmap(real_base_, real_length_); |
| 153 PLOG_IF(ERROR, result != 0) << "munmap"; | 152 PLOG_IF(ERROR, result != 0) << "munmap"; |
| 154 } | 153 } |
| 155 | 154 |
| 156 } // namespace embedder | 155 } // namespace embedder |
| 157 } // namespace mojo | 156 } // namespace mojo |
| OLD | NEW |