summaryrefslogtreecommitdiffstats
path: root/mojo/system
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 22:58:21 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 22:58:21 +0000
commita929bad18d128605db55d5e104e2b518854f11b1 (patch)
tree06501f28351cddb7d3b52da16f75df5155076318 /mojo/system
parent3a20a4de02c1500fd3880050a638f49c928b2881 (diff)
downloadchromium_src-a929bad18d128605db55d5e104e2b518854f11b1.zip
chromium_src-a929bad18d128605db55d5e104e2b518854f11b1.tar.gz
chromium_src-a929bad18d128605db55d5e104e2b518854f11b1.tar.bz2
Mojo: Implement RawSharedBuffer for Windows.
R=darin@chromium.org Review URL: https://codereview.chromium.org/208903002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system')
-rw-r--r--mojo/system/raw_shared_buffer_posix.cc1
-rw-r--r--mojo/system/raw_shared_buffer_unittest.cc6
-rw-r--r--mojo/system/raw_shared_buffer_win.cc59
3 files changed, 53 insertions, 13 deletions
diff --git a/mojo/system/raw_shared_buffer_posix.cc b/mojo/system/raw_shared_buffer_posix.cc
index 3fc6191..dc579e6 100644
--- a/mojo/system/raw_shared_buffer_posix.cc
+++ b/mojo/system/raw_shared_buffer_posix.cc
@@ -21,7 +21,6 @@
#include "base/sys_info.h"
#include "base/threading/thread_restrictions.h"
#include "mojo/embedder/platform_handle.h"
-#include "mojo/embedder/scoped_platform_handle.h"
// We assume that |size_t| and |off_t| (type for |ftruncate()|) fits in a
// |uint64_t|.
diff --git a/mojo/system/raw_shared_buffer_unittest.cc b/mojo/system/raw_shared_buffer_unittest.cc
index 06c6c81..6764246 100644
--- a/mojo/system/raw_shared_buffer_unittest.cc
+++ b/mojo/system/raw_shared_buffer_unittest.cc
@@ -5,15 +5,12 @@
#include "mojo/system/raw_shared_buffer.h"
#include "base/memory/scoped_ptr.h"
-#include "build/build_config.h" // TODO(vtl): Remove once enabled on Windows.
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace system {
namespace {
-// TODO(vtl): Implement and enable on Windows.
-#if !defined(OS_WIN)
TEST(RawSharedBufferTest, Basic) {
const size_t kNumInts = 100;
const size_t kNumBytes = kNumInts * sizeof(int);
@@ -113,7 +110,8 @@ TEST(RawSharedBufferTest, InvalidArguments) {
EXPECT_FALSE(buffer->Map(50, 51));
EXPECT_FALSE(buffer->Map(51, 50));
}
-#endif // !defined(OS_WIN)
+
+// TODO(vtl): Check that mappings can outlive the shared buffer.
} // namespace
} // namespace system
diff --git a/mojo/system/raw_shared_buffer_win.cc b/mojo/system/raw_shared_buffer_win.cc
index c18f01f..c148702 100644
--- a/mojo/system/raw_shared_buffer_win.cc
+++ b/mojo/system/raw_shared_buffer_win.cc
@@ -4,7 +4,14 @@
#include "mojo/system/raw_shared_buffer.h"
+#include <windows.h>
+
+#include <limits>
+
#include "base/logging.h"
+#include "base/sys_info.h"
+#include "mojo/embedder/platform_handle.h"
+#include "mojo/embedder/scoped_platform_handle.h"
namespace mojo {
namespace system {
@@ -12,23 +19,59 @@ namespace system {
// RawSharedBuffer::Mapping ----------------------------------------------------
void RawSharedBuffer::Mapping::Unmap() {
- // TODO(vtl)
- NOTIMPLEMENTED();
+ BOOL result = UnmapViewOfFile(real_base_);
+ PLOG_IF(ERROR, !result) << "UnmapViewOfFile";
}
// RawSharedBuffer -------------------------------------------------------------
bool RawSharedBuffer::Init() {
- // TODO(vtl)
- NOTIMPLEMENTED();
- return false;
+ DCHECK(!handle_.is_valid());
+
+ // TODO(vtl): Currently, we only support mapping up to 2^32-1 bytes.
+ if (static_cast<uint64_t>(num_bytes_) >
+ static_cast<uint64_t>(std::numeric_limits<DWORD>::max())) {
+ return false;
+ }
+
+ // IMPORTANT NOTE: Unnamed objects are NOT SECURABLE. Thus if we ever want to
+ // share read-only to other processes, we'll have to name our file mapping
+ // object.
+ // TODO(vtl): Unlike |base::SharedMemory|, we don't round up the size (to a
+ // multiple of 64 KB). This may cause problems with NaCl. Cross this bridge
+ // when we get there. crbug.com/210609
+ handle_.reset(embedder::PlatformHandle(CreateFileMapping(
+ INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
+ static_cast<DWORD>(num_bytes_), NULL)));
+ if (!handle_.is_valid()) {
+ PLOG(ERROR) << "CreateFileMapping";
+ return false;
+ }
+
+ return true;
}
scoped_ptr<RawSharedBuffer::Mapping> RawSharedBuffer::MapImpl(size_t offset,
size_t length) {
- // TODO(vtl)
- NOTIMPLEMENTED();
- return scoped_ptr<Mapping>();
+ size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity();
+ size_t real_offset = offset - offset_rounding;
+ size_t real_length = length + offset_rounding;
+
+ // This should hold (since we checked |num_bytes| versus the maximum value of
+ // |off_t| on creation, but it never hurts to be paranoid.
+ DCHECK_LE(static_cast<uint64_t>(real_offset),
+ static_cast<uint64_t>(std::numeric_limits<DWORD>::max()));
+
+ void* real_base = MapViewOfFile(
+ handle_.get().handle, FILE_MAP_READ | FILE_MAP_WRITE, 0,
+ static_cast<DWORD>(real_offset), real_length);
+ if (!real_base) {
+ PLOG(ERROR) << "MapViewOfFile";
+ return scoped_ptr<Mapping>();
+ }
+
+ void* base = static_cast<char*>(real_base) + offset_rounding;
+ return make_scoped_ptr(new Mapping(base, length, real_base, real_length));
}
} // namespace system