Bluetooth: add Device events, and cleanup JS API
[chromium-blink-merge.git] / mojo / system / memory.cc
blobdd8b3d2334ada19a88fbf647a0974a260c0383ba
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/system/memory.h"
7 #include <limits>
9 #include "base/logging.h"
11 namespace mojo {
12 namespace system {
14 template <size_t size>
15 bool VerifyUserPointerForSize(const void* pointer, size_t count) {
16 if (count > std::numeric_limits<size_t>::max() / size)
17 return false;
19 // TODO(vtl): If running in kernel mode, do a full verification. For now, just
20 // check that it's non-null if |size| is nonzero. (A faster user mode
21 // implementation is also possible if this check is skipped.)
22 return count == 0 || !!pointer;
25 // Explicitly instantiate the sizes we need. Add instantiations as needed.
26 template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<1>(
27 const void*, size_t);
28 template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<4>(
29 const void*, size_t);
30 template MOJO_SYSTEM_IMPL_EXPORT bool VerifyUserPointerForSize<8>(
31 const void*, size_t);
33 } // namespace system
34 } // namespace mojo