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

Side by Side Diff: mojo/edk/system/memory.cc

Issue 1776033002: Implement MojoGetBufferInformation(), part 1. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/dispatcher_unittest.cc ('k') | mojo/edk/system/shared_buffer_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "mojo/edk/system/memory.h" 5 #include "mojo/edk/system/memory.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace system { 12 namespace system {
13 namespace internal { 13 namespace internal {
14 14
15 template <size_t alignment> 15 template <size_t alignment>
16 bool IsAligned(const void* pointer) { 16 bool IsAligned(const void* pointer) {
17 return reinterpret_cast<uintptr_t>(pointer) % alignment == 0; 17 return reinterpret_cast<uintptr_t>(pointer) % alignment == 0;
18 } 18 }
19 19
20 template <size_t size, size_t alignment> 20 template <size_t size, size_t alignment>
21 void CheckUserPointer(const void* pointer) { 21 void CheckUserPointer(const void* pointer) {
22 CHECK(pointer && IsAligned<alignment>(pointer)); 22 CHECK(pointer && IsAligned<alignment>(pointer));
23 } 23 }
24 24
25 // Explicitly instantiate the sizes we need. Add instantiations as needed. 25 // Explicitly instantiate the sizes we need. Add instantiations as needed.
26 template void CheckUserPointer<1, 1>(const void*); 26 template void CheckUserPointer<1, 1>(const void*);
27 template void CheckUserPointer<4, 4>(const void*); 27 template void CheckUserPointer<4, 4>(const void*);
28 template void CheckUserPointer<8, 4>(const void*); 28 template void CheckUserPointer<8, 4>(const void*);
29 template void CheckUserPointer<8, 8>(const void*); 29 template void CheckUserPointer<8, 8>(const void*);
30 template void CheckUserPointer<16, 8>(const void*);
30 31
31 template <size_t size, size_t alignment> 32 template <size_t size, size_t alignment>
32 void CheckUserPointerWithCount(const void* pointer, size_t count) { 33 void CheckUserPointerWithCount(const void* pointer, size_t count) {
33 CHECK_LE(count, std::numeric_limits<size_t>::max() / size); 34 CHECK_LE(count, std::numeric_limits<size_t>::max() / size);
34 CHECK(count == 0 || (pointer && IsAligned<alignment>(pointer))); 35 CHECK(count == 0 || (pointer && IsAligned<alignment>(pointer)));
35 } 36 }
36 37
37 // Explicitly instantiate the sizes we need. Add instantiations as needed. 38 // Explicitly instantiate the sizes we need. Add instantiations as needed.
38 template void CheckUserPointerWithCount<1, 1>(const void*, size_t); 39 template void CheckUserPointerWithCount<1, 1>(const void*, size_t);
39 template void CheckUserPointerWithCount<4, 4>(const void*, size_t); 40 template void CheckUserPointerWithCount<4, 4>(const void*, size_t);
40 template void CheckUserPointerWithCount<8, 4>(const void*, size_t); 41 template void CheckUserPointerWithCount<8, 4>(const void*, size_t);
41 template void CheckUserPointerWithCount<8, 8>(const void*, size_t); 42 template void CheckUserPointerWithCount<8, 8>(const void*, size_t);
42 43
43 template <size_t alignment> 44 template <size_t alignment>
44 void CheckUserPointerWithSize(const void* pointer, size_t size) { 45 void CheckUserPointerWithSize(const void* pointer, size_t size) {
45 // TODO(vtl): If running in kernel mode, do a full verification. For now, just 46 // TODO(vtl): If running in kernel mode, do a full verification. For now, just
46 // check that it's non-null and aligned. (A faster user mode implementation is 47 // check that it's non-null and aligned. (A faster user mode implementation is
47 // also possible if this check is skipped.) 48 // also possible if this check is skipped.)
48 CHECK(size == 0 || (!!pointer && internal::IsAligned<alignment>(pointer))); 49 CHECK(size == 0 || (!!pointer && internal::IsAligned<alignment>(pointer)));
49 } 50 }
50 51
51 // Explicitly instantiate the sizes we need. Add instantiations as needed. 52 // Explicitly instantiate the sizes we need. Add instantiations as needed.
52 template void CheckUserPointerWithSize<1>(const void*, size_t); 53 template void CheckUserPointerWithSize<1>(const void*, size_t);
53 template void CheckUserPointerWithSize<4>(const void*, size_t); 54 template void CheckUserPointerWithSize<4>(const void*, size_t);
54 template void CheckUserPointerWithSize<8>(const void*, size_t); 55 template void CheckUserPointerWithSize<8>(const void*, size_t);
55 56
56 } // namespace internal 57 } // namespace internal
57 } // namespace system 58 } // namespace system
58 } // namespace mojo 59 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher_unittest.cc ('k') | mojo/edk/system/shared_buffer_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698