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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
13 #include "mojo/embedder/platform_handle.h" | 13 #include "mojo/embedder/platform_handle.h" |
14 #include "mojo/embedder/scoped_platform_handle.h" | 14 #include "mojo/embedder/scoped_platform_handle.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 namespace system { | 17 namespace system { |
18 | 18 |
19 // RawSharedBuffer ------------------------------------------------------------- | 19 // RawSharedBuffer ------------------------------------------------------------- |
20 | 20 |
21 bool RawSharedBuffer::InitNoLock() { | 21 bool RawSharedBuffer::Init() { |
22 DCHECK(!handle_.is_valid()); | 22 DCHECK(!handle_.is_valid()); |
23 | 23 |
24 // TODO(vtl): Currently, we only support mapping up to 2^32-1 bytes. | 24 // TODO(vtl): Currently, we only support mapping up to 2^32-1 bytes. |
25 if (static_cast<uint64_t>(num_bytes_) > | 25 if (static_cast<uint64_t>(num_bytes_) > |
26 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())) { | 26 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())) { |
27 return false; | 27 return false; |
28 } | 28 } |
29 | 29 |
30 // IMPORTANT NOTE: Unnamed objects are NOT SECURABLE. Thus if we ever want to | 30 // IMPORTANT NOTE: Unnamed objects are NOT SECURABLE. Thus if we ever want to |
31 // share read-only to other processes, we'll have to name our file mapping | 31 // share read-only to other processes, we'll have to name our file mapping |
32 // object. | 32 // object. |
33 // TODO(vtl): Unlike |base::SharedMemory|, we don't round up the size (to a | 33 // TODO(vtl): Unlike |base::SharedMemory|, we don't round up the size (to a |
34 // multiple of 64 KB). This may cause problems with NaCl. Cross this bridge | 34 // multiple of 64 KB). This may cause problems with NaCl. Cross this bridge |
35 // when we get there. crbug.com/210609 | 35 // when we get there. crbug.com/210609 |
36 handle_.reset(embedder::PlatformHandle(CreateFileMapping( | 36 handle_.reset(embedder::PlatformHandle(CreateFileMapping( |
37 INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, | 37 INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, |
38 static_cast<DWORD>(num_bytes_), NULL))); | 38 static_cast<DWORD>(num_bytes_), NULL))); |
39 if (!handle_.is_valid()) { | 39 if (!handle_.is_valid()) { |
40 PLOG(ERROR) << "CreateFileMapping"; | 40 PLOG(ERROR) << "CreateFileMapping"; |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 return true; | 44 return true; |
45 } | 45 } |
46 | 46 |
47 scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapImplNoLock( | 47 bool RawSharedBuffer::InitFromPlatformHandle( |
48 size_t offset, | 48 embedder::ScopedPlatformHandle platform_handle) { |
49 size_t length) { | 49 DCHECK(!handle_.is_valid()); |
50 lock_.AssertAcquired(); | |
51 | 50 |
| 51 // TODO(vtl): Implement. |
| 52 NOTIMPLEMENTED(); |
| 53 return false; |
| 54 } |
| 55 |
| 56 scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapImpl(size_t offset, |
| 57 size_t length) { |
52 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); | 58 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); |
53 size_t real_offset = offset - offset_rounding; | 59 size_t real_offset = offset - offset_rounding; |
54 size_t real_length = length + offset_rounding; | 60 size_t real_length = length + offset_rounding; |
55 | 61 |
56 // This should hold (since we checked |num_bytes| versus the maximum value of | 62 // This should hold (since we checked |num_bytes| versus the maximum value of |
57 // |off_t| on creation, but it never hurts to be paranoid. | 63 // |off_t| on creation, but it never hurts to be paranoid. |
58 DCHECK_LE(static_cast<uint64_t>(real_offset), | 64 DCHECK_LE(static_cast<uint64_t>(real_offset), |
59 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())); | 65 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())); |
60 | 66 |
61 void* real_base = MapViewOfFile( | 67 void* real_base = MapViewOfFile( |
(...skipping 11 matching lines...) Expand all Loading... |
73 | 79 |
74 // RawSharedBufferMapping ------------------------------------------------------ | 80 // RawSharedBufferMapping ------------------------------------------------------ |
75 | 81 |
76 void RawSharedBufferMapping::Unmap() { | 82 void RawSharedBufferMapping::Unmap() { |
77 BOOL result = UnmapViewOfFile(real_base_); | 83 BOOL result = UnmapViewOfFile(real_base_); |
78 PLOG_IF(ERROR, !result) << "UnmapViewOfFile"; | 84 PLOG_IF(ERROR, !result) << "UnmapViewOfFile"; |
79 } | 85 } |
80 | 86 |
81 } // namespace system | 87 } // namespace system |
82 } // namespace mojo | 88 } // namespace mojo |
OLD | NEW |