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/system/raw_shared_buffer.h" | 5 #include "mojo/system/raw_shared_buffer.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 bool RawSharedBuffer::InitFromPlatformHandle( | 51 bool RawSharedBuffer::InitFromPlatformHandle( |
52 embedder::ScopedPlatformHandle platform_handle) { | 52 embedder::ScopedPlatformHandle platform_handle) { |
53 DCHECK(!handle_.is_valid()); | 53 DCHECK(!handle_.is_valid()); |
54 | 54 |
55 // TODO(vtl): Implement. | 55 // TODO(vtl): Implement. |
56 NOTIMPLEMENTED(); | 56 NOTIMPLEMENTED(); |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapImpl(size_t offset, | 60 scoped_ptr<embedder::PlatformSharedBufferMapping> RawSharedBuffer::MapImpl( |
61 size_t length) { | 61 size_t offset, |
| 62 size_t length) { |
62 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); | 63 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); |
63 size_t real_offset = offset - offset_rounding; | 64 size_t real_offset = offset - offset_rounding; |
64 size_t real_length = length + offset_rounding; | 65 size_t real_length = length + offset_rounding; |
65 | 66 |
66 // This should hold (since we checked |num_bytes| versus the maximum value of | 67 // This should hold (since we checked |num_bytes| versus the maximum value of |
67 // |off_t| on creation, but it never hurts to be paranoid. | 68 // |off_t| on creation, but it never hurts to be paranoid. |
68 DCHECK_LE(static_cast<uint64_t>(real_offset), | 69 DCHECK_LE(static_cast<uint64_t>(real_offset), |
69 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())); | 70 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())); |
70 | 71 |
71 void* real_base = MapViewOfFile(handle_.get().handle, | 72 void* real_base = MapViewOfFile(handle_.get().handle, |
72 FILE_MAP_READ | FILE_MAP_WRITE, | 73 FILE_MAP_READ | FILE_MAP_WRITE, |
73 0, | 74 0, |
74 static_cast<DWORD>(real_offset), | 75 static_cast<DWORD>(real_offset), |
75 real_length); | 76 real_length); |
76 if (!real_base) { | 77 if (!real_base) { |
77 PLOG(ERROR) << "MapViewOfFile"; | 78 PLOG(ERROR) << "MapViewOfFile"; |
78 return scoped_ptr<RawSharedBufferMapping>(); | 79 return scoped_ptr<embedder::PlatformSharedBufferMapping>(); |
79 } | 80 } |
80 | 81 |
81 void* base = static_cast<char*>(real_base) + offset_rounding; | 82 void* base = static_cast<char*>(real_base) + offset_rounding; |
82 return make_scoped_ptr( | 83 return scoped_ptr<embedder::PlatformSharedBufferMapping>( |
83 new RawSharedBufferMapping(base, length, real_base, real_length)); | 84 new RawSharedBufferMapping(base, length, real_base, real_length)); |
84 } | 85 } |
85 | 86 |
86 // RawSharedBufferMapping ------------------------------------------------------ | 87 // RawSharedBufferMapping ------------------------------------------------------ |
87 | 88 |
88 void RawSharedBufferMapping::Unmap() { | 89 void RawSharedBufferMapping::Unmap() { |
89 BOOL result = UnmapViewOfFile(real_base_); | 90 BOOL result = UnmapViewOfFile(real_base_); |
90 PLOG_IF(ERROR, !result) << "UnmapViewOfFile"; | 91 PLOG_IF(ERROR, !result) << "UnmapViewOfFile"; |
91 } | 92 } |
92 | 93 |
93 } // namespace system | 94 } // namespace system |
94 } // namespace mojo | 95 } // namespace mojo |
OLD | NEW |