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

Side by Side Diff: mojo/edk/embedder/simple_platform_shared_buffer_win.cc

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
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 <windows.h> 7 #include <windows.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 15 matching lines...) Expand all
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(PlatformHandle( 36 handle_.reset(PlatformHandle(CreateFileMapping(INVALID_HANDLE_VALUE,
37 CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, 37 nullptr,
38 static_cast<DWORD>(num_bytes_), nullptr))); 38 PAGE_READWRITE,
39 0,
40 static_cast<DWORD>(num_bytes_),
41 nullptr)));
39 if (!handle_.is_valid()) { 42 if (!handle_.is_valid()) {
40 PLOG(ERROR) << "CreateFileMapping"; 43 PLOG(ERROR) << "CreateFileMapping";
41 return false; 44 return false;
42 } 45 }
43 46
44 return true; 47 return true;
45 } 48 }
46 49
47 bool SimplePlatformSharedBuffer::InitFromPlatformHandle( 50 bool SimplePlatformSharedBuffer::InitFromPlatformHandle(
48 ScopedPlatformHandle platform_handle) { 51 ScopedPlatformHandle platform_handle) {
49 DCHECK(!handle_.is_valid()); 52 DCHECK(!handle_.is_valid());
50 53
51 // TODO(vtl): Implement. 54 // TODO(vtl): Implement.
52 NOTIMPLEMENTED(); 55 NOTIMPLEMENTED();
53 return false; 56 return false;
54 } 57 }
55 58
56 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl( 59 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl(
57 size_t offset, 60 size_t offset,
58 size_t length) { 61 size_t length) {
59 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity(); 62 size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity();
60 size_t real_offset = offset - offset_rounding; 63 size_t real_offset = offset - offset_rounding;
61 size_t real_length = length + offset_rounding; 64 size_t real_length = length + offset_rounding;
62 65
63 // This should hold (since we checked |num_bytes| versus the maximum value of 66 // This should hold (since we checked |num_bytes| versus the maximum value of
64 // |off_t| on creation, but it never hurts to be paranoid. 67 // |off_t| on creation, but it never hurts to be paranoid.
65 DCHECK_LE(static_cast<uint64_t>(real_offset), 68 DCHECK_LE(static_cast<uint64_t>(real_offset),
66 static_cast<uint64_t>(std::numeric_limits<DWORD>::max())); 69 static_cast<uint64_t>(std::numeric_limits<DWORD>::max()));
67 70
68 void* real_base = 71 void* real_base = MapViewOfFile(handle_.get().handle,
69 MapViewOfFile(handle_.get().handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 72 FILE_MAP_READ | FILE_MAP_WRITE,
70 static_cast<DWORD>(real_offset), real_length); 73 0,
74 static_cast<DWORD>(real_offset),
75 real_length);
71 if (!real_base) { 76 if (!real_base) {
72 PLOG(ERROR) << "MapViewOfFile"; 77 PLOG(ERROR) << "MapViewOfFile";
73 return nullptr; 78 return nullptr;
74 } 79 }
75 80
76 void* base = static_cast<char*>(real_base) + offset_rounding; 81 void* base = static_cast<char*>(real_base) + offset_rounding;
77 return make_scoped_ptr(new SimplePlatformSharedBufferMapping( 82 return make_scoped_ptr(new SimplePlatformSharedBufferMapping(
78 base, length, real_base, real_length)); 83 base, length, real_base, real_length));
79 } 84 }
80 85
81 // SimplePlatformSharedBufferMapping ------------------------------------------- 86 // SimplePlatformSharedBufferMapping -------------------------------------------
82 87
83 void SimplePlatformSharedBufferMapping::Unmap() { 88 void SimplePlatformSharedBufferMapping::Unmap() {
84 BOOL result = UnmapViewOfFile(real_base_); 89 BOOL result = UnmapViewOfFile(real_base_);
85 PLOG_IF(ERROR, !result) << "UnmapViewOfFile"; 90 PLOG_IF(ERROR, !result) << "UnmapViewOfFile";
86 } 91 }
87 92
88 } // namespace embedder 93 } // namespace embedder
89 } // namespace mojo 94 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/simple_platform_shared_buffer_posix.cc ('k') | mojo/edk/embedder/test_embedder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698