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

Unified Diff: mojo/system/memory.cc

Issue 103533008: Mojo: More data pipe implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indentation Created 7 years 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
« no previous file with comments | « mojo/system/memory.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/memory.cc
diff --git a/mojo/system/memory.cc b/mojo/system/memory.cc
index 633b2bef4adb28f34e4c2129fe5d82835fce6e20..a10b021cedc035e3f669d9eea0d25c91a698b4c5 100644
--- a/mojo/system/memory.cc
+++ b/mojo/system/memory.cc
@@ -11,6 +11,8 @@
namespace mojo {
namespace system {
+// TODO(vtl): Can I make this use the non-templatized function without a
+// performance hit?
template <size_t size>
bool VerifyUserPointerForSize(const void* pointer, size_t count) {
if (count > std::numeric_limits<size_t>::max() / size)
@@ -22,11 +24,25 @@ bool VerifyUserPointerForSize(const void* pointer, size_t count) {
return count == 0 || !!pointer;
}
+bool MOJO_SYSTEM_IMPL_EXPORT VerifyUserPointerForSize(const void* pointer,
+ size_t size,
+ size_t count) {
+ if (count > std::numeric_limits<size_t>::max() / size)
+ 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;
+}
+
// Explicitly instantiate the sizes we need. Add instantiations as needed.
template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<1>(
const void*, size_t);
template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<4>(
const void*, size_t);
+template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<8>(
+ const void*, size_t);
} // namespace system
} // namespace mojo
« no previous file with comments | « 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