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 #ifndef MOJO_SYSTEM_MEMORY_H_
6 #define MOJO_SYSTEM_MEMORY_H_
10 #include "mojo/public/c/system/macros.h"
11 #include "mojo/system/system_impl_export.h"
18 template <size_t size
, size_t alignment
>
19 bool MOJO_SYSTEM_IMPL_EXPORT
VerifyUserPointerHelper(const void* pointer
);
21 // Note: This is also used by options_validation.h.
22 template <size_t size
, size_t alignment
>
23 bool MOJO_SYSTEM_IMPL_EXPORT
VerifyUserPointerWithCountHelper(
27 } // namespace internal
29 // Verify (insofar as possible/necessary) that a |T| can be read from the user
32 bool VerifyUserPointer(const T
* pointer
) {
33 return internal::VerifyUserPointerHelper
<sizeof(T
), MOJO_ALIGNOF(T
)>(pointer
);
36 // Verify (insofar as possible/necessary) that |count| |T|s can be read from the
37 // user |pointer|; |count| may be zero. (This is done carefully since |count *
38 // sizeof(T)| may overflow a |size_t|.)
40 bool VerifyUserPointerWithCount(const T
* pointer
, size_t count
) {
41 return internal::VerifyUserPointerWithCountHelper
<sizeof(T
),
42 MOJO_ALIGNOF(T
)>(pointer
,
46 // Verify that |size| bytes (which may be zero) can be read from the user
47 // |pointer|, and that |pointer| has the specified |alignment| (if |size| is
49 template <size_t alignment
>
50 bool MOJO_SYSTEM_IMPL_EXPORT
VerifyUserPointerWithSize(const void* pointer
,
56 #endif // MOJO_SYSTEM_MEMORY_H_