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

Unified Diff: mojo/system/memory.cc

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: mojo/system/memory.cc
diff --git a/mojo/system/memory.cc b/mojo/system/memory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df658ae5ee3d405aff88f8f244259583f22f81b3
--- /dev/null
+++ b/mojo/system/memory.cc
@@ -0,0 +1,26 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/system/memory.h"
+
+#include <limits>
+
+#include "base/logging.h"
+
+namespace mojo {
+namespace system {
+
+bool VerifyUserPointer(const void* pointer, size_t count, size_t size_each) {
+ DCHECK_GT(size_each, 0u);
+ if (count > std::numeric_limits<size_t>::max() / size_each)
+ return false;
+
+ // TODO(vtl): If running in kernel mode, do a full verification. For now, just
+ // check that it's non-null if |size| is nonzero. (A faster user mode
+ // implementation is also possible if this check is skipped.)
+ return count == 0 || !!pointer;
+}
+
+} // namespace system
+} // namespace mojo
« mojo/mojo.gyp ('K') | « mojo/system/memory.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698