| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_EDK_SYSTEM_MEMORY_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MEMORY_H_ |
| 6 #define MOJO_EDK_SYSTEM_MEMORY_H_ | 6 #define MOJO_EDK_SYSTEM_MEMORY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> // For |memcpy()|. | 10 #include <string.h> // For |memcpy()|. |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <type_traits> | 13 #include <type_traits> |
| 14 | 14 |
| 15 #include "mojo/edk/system/system_impl_export.h" | |
| 16 #include "mojo/public/c/system/macros.h" | 15 #include "mojo/public/c/system/macros.h" |
| 17 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
| 18 | 17 |
| 19 namespace mojo { | 18 namespace mojo { |
| 20 namespace system { | 19 namespace system { |
| 21 | 20 |
| 22 namespace internal { | 21 namespace internal { |
| 23 | 22 |
| 24 // Yields |(const) char| if |T| is |(const) void|, else |T|: | 23 // Yields |(const) char| if |T| is |(const) void|, else |T|: |
| 25 template <typename T> | 24 template <typename T> |
| 26 struct VoidToChar { | 25 struct VoidToChar { |
| 27 using type = T; | 26 using type = T; |
| 28 }; | 27 }; |
| 29 template <> | 28 template <> |
| 30 struct VoidToChar<void> { | 29 struct VoidToChar<void> { |
| 31 using type = char; | 30 using type = char; |
| 32 }; | 31 }; |
| 33 template <> | 32 template <> |
| 34 struct VoidToChar<const void> { | 33 struct VoidToChar<const void> { |
| 35 using type = const char; | 34 using type = const char; |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to | 37 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to |
| 39 // a buffer of the given size and alignment (both in bytes). | 38 // a buffer of the given size and alignment (both in bytes). |
| 40 template <size_t size, size_t alignment> | 39 template <size_t size, size_t alignment> |
| 41 void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer(const void* pointer); | 40 void CheckUserPointer(const void* pointer); |
| 42 | 41 |
| 43 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to | 42 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to |
| 44 // a buffer of |count| elements of the given size and alignment (both in bytes). | 43 // a buffer of |count| elements of the given size and alignment (both in bytes). |
| 45 template <size_t size, size_t alignment> | 44 template <size_t size, size_t alignment> |
| 46 void MOJO_SYSTEM_IMPL_EXPORT | 45 void CheckUserPointerWithCount(const void* pointer, size_t count); |
| 47 CheckUserPointerWithCount(const void* pointer, size_t count); | |
| 48 | 46 |
| 49 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to | 47 // Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to |
| 50 // a buffer of the given size and alignment (both in bytes). | 48 // a buffer of the given size and alignment (both in bytes). |
| 51 template <size_t alignment> | 49 template <size_t alignment> |
| 52 void MOJO_SYSTEM_IMPL_EXPORT | 50 void CheckUserPointerWithSize(const void* pointer, size_t size); |
| 53 CheckUserPointerWithSize(const void* pointer, size_t size); | |
| 54 | 51 |
| 55 } // namespace internal | 52 } // namespace internal |
| 56 | 53 |
| 57 // Forward declarations so that they can be friended. | 54 // Forward declarations so that they can be friended. |
| 58 template <typename Type> | 55 template <typename Type> |
| 59 class UserPointerReader; | 56 class UserPointerReader; |
| 60 template <typename Type> | 57 template <typename Type> |
| 61 class UserPointerWriter; | 58 class UserPointerWriter; |
| 62 template <typename Type> | 59 template <typename Type> |
| 63 class UserPointerReaderWriter; | 60 class UserPointerReaderWriter; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 size_t count_; | 356 size_t count_; |
| 360 std::unique_ptr<Type[]> buffer_; | 357 std::unique_ptr<Type[]> buffer_; |
| 361 | 358 |
| 362 MOJO_DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); | 359 MOJO_DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); |
| 363 }; | 360 }; |
| 364 | 361 |
| 365 } // namespace system | 362 } // namespace system |
| 366 } // namespace mojo | 363 } // namespace mojo |
| 367 | 364 |
| 368 #endif // MOJO_EDK_SYSTEM_MEMORY_H_ | 365 #endif // MOJO_EDK_SYSTEM_MEMORY_H_ |
| OLD | NEW |