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

Side by Side Diff: mojo/system/memory.h

Issue 25895002: Simple shell that loads a dll and calls an entrypoint function passing in a handle to a pipe create… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: exports to template instantiations Created 7 years, 2 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 | Annotate | Revision Log
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 #ifndef MOJO_SYSTEM_MEMORY_H_ 5 #ifndef MOJO_SYSTEM_MEMORY_H_
6 #define MOJO_SYSTEM_MEMORY_H_ 6 #define MOJO_SYSTEM_MEMORY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "mojo/public/system/system_export.h"
11
10 namespace mojo { 12 namespace mojo {
11 namespace system { 13 namespace system {
12 14
13 // This is just forward-declared, with the definition and explicit 15 // This is just forward-declared, with the definition and explicit
14 // instantiations in the .cc file. This is used by |VerifyUserPointer<T>()| 16 // instantiations in the .cc file. This is used by |VerifyUserPointer<T>()|
15 // below, and you should use that instead. 17 // below, and you should use that instead.
16 template <size_t size> 18 template <size_t size>
17 bool VerifyUserPointerForSize(const void* pointer, size_t count); 19 bool MOJO_SYSTEM_EXPORT VerifyUserPointerForSize(const void* pointer,
20 size_t count);
18 21
19 // Verify that |count * sizeof(T)| bytes can be read from the user |pointer| 22 // Verify that |count * sizeof(T)| bytes can be read from the user |pointer|
20 // insofar as possible/necessary (note: this is done carefully since |count * 23 // insofar as possible/necessary (note: this is done carefully since |count *
21 // sizeof(T)| may overflow a |size_t|. |count| may be zero. If |T| is |void|, 24 // sizeof(T)| may overflow a |size_t|. |count| may be zero. If |T| is |void|,
22 // then the size of each element is taken to be a single byte. 25 // then the size of each element is taken to be a single byte.
23 // 26 //
24 // For example, if running in kernel mode, this should be a full verification 27 // For example, if running in kernel mode, this should be a full verification
25 // that the given memory is owned and readable by the user process. In user 28 // that the given memory is owned and readable by the user process. In user
26 // mode, if crashes are acceptable, this may do nothing at all (and always 29 // mode, if crashes are acceptable, this may do nothing at all (and always
27 // return true). 30 // return true).
28 template <typename T> 31 template <typename T>
29 bool VerifyUserPointer(const T* pointer, size_t count) { 32 bool VerifyUserPointer(const T* pointer, size_t count) {
30 return VerifyUserPointerForSize<sizeof(T)>(pointer, count); 33 return VerifyUserPointerForSize<sizeof(T)>(pointer, count);
31 } 34 }
32 35
33 // Special-case |T| equals |void| so that the size is in bytes, as indicated 36 // Special-case |T| equals |void| so that the size is in bytes, as indicated
34 // above. 37 // above.
35 template <> 38 template <>
36 inline bool VerifyUserPointer<void>(const void* pointer, size_t count) { 39 inline bool VerifyUserPointer<void>(const void* pointer, size_t count) {
37 return VerifyUserPointerForSize<1>(pointer, count); 40 return VerifyUserPointerForSize<1>(pointer, count);
38 } 41 }
39 42
40 } // namespace system 43 } // namespace system
41 } // namespace mojo 44 } // namespace mojo
42 45
43 #endif // MOJO_SYSTEM_MEMORY_H_ 46 #endif // MOJO_SYSTEM_MEMORY_H_
OLDNEW
« build/all.gyp ('K') | « mojo/system/dispatcher.h ('k') | mojo/system/memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698