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

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

Issue 418033005: Mojo: Change how we handle invalid pointer arguments (at the system layer). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 6 years, 4 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
« no previous file with comments | « no previous file | mojo/system/core.cc » ('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 #ifndef MOJO_SYSTEM_CORE_H_ 5 #ifndef MOJO_SYSTEM_CORE_H_
6 #define MOJO_SYSTEM_CORE_H_ 6 #define MOJO_SYSTEM_CORE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "mojo/public/c/system/buffer.h" 12 #include "mojo/public/c/system/buffer.h"
13 #include "mojo/public/c/system/data_pipe.h" 13 #include "mojo/public/c/system/data_pipe.h"
14 #include "mojo/public/c/system/message_pipe.h" 14 #include "mojo/public/c/system/message_pipe.h"
15 #include "mojo/public/c/system/types.h" 15 #include "mojo/public/c/system/types.h"
16 #include "mojo/system/handle_table.h" 16 #include "mojo/system/handle_table.h"
17 #include "mojo/system/mapping_table.h" 17 #include "mojo/system/mapping_table.h"
18 #include "mojo/system/memory.h"
18 #include "mojo/system/system_impl_export.h" 19 #include "mojo/system/system_impl_export.h"
19 20
20 namespace mojo { 21 namespace mojo {
21 namespace system { 22 namespace system {
22 23
23 class Dispatcher; 24 class Dispatcher;
24 25
25 // |Core| is an object that implements the Mojo system calls. All public methods 26 // |Core| is an object that implements the Mojo system calls. All public methods
26 // are thread-safe. 27 // are thread-safe.
27 class MOJO_SYSTEM_IMPL_EXPORT Core { 28 class MOJO_SYSTEM_IMPL_EXPORT Core {
28 public: 29 public:
29 // These methods are only to be used by via the embedder API (and internally). 30 // These methods are only to be used by via the embedder API (and internally).
30 Core(); 31 Core();
31 virtual ~Core(); 32 virtual ~Core();
32 33
33 // Adds |dispatcher| to the handle table, returning the handle for it. Returns 34 // Adds |dispatcher| to the handle table, returning the handle for it. Returns
34 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. 35 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full.
35 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); 36 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher);
36 37
37 // Looks up the dispatcher for the given handle. Returns null if the handle is 38 // Looks up the dispatcher for the given handle. Returns null if the handle is
38 // invalid. 39 // invalid.
39 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); 40 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
40 41
41 // System calls implementation. 42 // System calls implementation.
42 MojoTimeTicks GetTimeTicksNow(); 43 MojoTimeTicks GetTimeTicksNow();
43 MojoResult Close(MojoHandle handle); 44 MojoResult Close(MojoHandle handle);
44 MojoResult Wait(MojoHandle handle, 45 MojoResult Wait(MojoHandle handle,
45 MojoHandleSignals signals, 46 MojoHandleSignals signals,
46 MojoDeadline deadline); 47 MojoDeadline deadline);
47 MojoResult WaitMany(const MojoHandle* handles, 48 MojoResult WaitMany(UserPointer<const MojoHandle> handles,
48 const MojoHandleSignals* signals, 49 UserPointer<const MojoHandleSignals> signals,
49 uint32_t num_handles, 50 uint32_t num_handles,
50 MojoDeadline deadline); 51 MojoDeadline deadline);
51 MojoResult CreateMessagePipe(const MojoCreateMessagePipeOptions* options, 52 MojoResult CreateMessagePipe(
52 MojoHandle* message_pipe_handle0, 53 UserPointer<const MojoCreateMessagePipeOptions> options,
53 MojoHandle* message_pipe_handle1); 54 UserPointer<MojoHandle> message_pipe_handle0,
55 UserPointer<MojoHandle> message_pipe_handle1);
54 MojoResult WriteMessage(MojoHandle message_pipe_handle, 56 MojoResult WriteMessage(MojoHandle message_pipe_handle,
55 const void* bytes, 57 UserPointer<const void> bytes,
56 uint32_t num_bytes, 58 uint32_t num_bytes,
57 const MojoHandle* handles, 59 UserPointer<const MojoHandle> handles,
58 uint32_t num_handles, 60 uint32_t num_handles,
59 MojoWriteMessageFlags flags); 61 MojoWriteMessageFlags flags);
60 MojoResult ReadMessage(MojoHandle message_pipe_handle, 62 MojoResult ReadMessage(MojoHandle message_pipe_handle,
61 void* bytes, 63 UserPointer<void> bytes,
62 uint32_t* num_bytes, 64 UserPointer<uint32_t> num_bytes,
63 MojoHandle* handles, 65 UserPointer<MojoHandle> handles,
64 uint32_t* num_handles, 66 UserPointer<uint32_t> num_handles,
65 MojoReadMessageFlags flags); 67 MojoReadMessageFlags flags);
66 MojoResult CreateDataPipe(const MojoCreateDataPipeOptions* options, 68 MojoResult CreateDataPipe(
67 MojoHandle* data_pipe_producer_handle, 69 UserPointer<const MojoCreateDataPipeOptions> options,
68 MojoHandle* data_pipe_consumer_handle); 70 UserPointer<MojoHandle> data_pipe_producer_handle,
71 UserPointer<MojoHandle> data_pipe_consumer_handle);
69 MojoResult WriteData(MojoHandle data_pipe_producer_handle, 72 MojoResult WriteData(MojoHandle data_pipe_producer_handle,
70 const void* elements, 73 UserPointer<const void> elements,
71 uint32_t* num_bytes, 74 UserPointer<uint32_t> num_bytes,
72 MojoWriteDataFlags flags); 75 MojoWriteDataFlags flags);
73 MojoResult BeginWriteData(MojoHandle data_pipe_producer_handle, 76 MojoResult BeginWriteData(MojoHandle data_pipe_producer_handle,
74 void** buffer, 77 UserPointer<void*> buffer,
75 uint32_t* buffer_num_bytes, 78 UserPointer<uint32_t> buffer_num_bytes,
76 MojoWriteDataFlags flags); 79 MojoWriteDataFlags flags);
77 MojoResult EndWriteData(MojoHandle data_pipe_producer_handle, 80 MojoResult EndWriteData(MojoHandle data_pipe_producer_handle,
78 uint32_t num_bytes_written); 81 uint32_t num_bytes_written);
79 MojoResult ReadData(MojoHandle data_pipe_consumer_handle, 82 MojoResult ReadData(MojoHandle data_pipe_consumer_handle,
80 void* elements, 83 UserPointer<void> elements,
81 uint32_t* num_bytes, 84 UserPointer<uint32_t> num_bytes,
82 MojoReadDataFlags flags); 85 MojoReadDataFlags flags);
83 MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, 86 MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle,
84 const void** buffer, 87 UserPointer<const void*> buffer,
85 uint32_t* buffer_num_bytes, 88 UserPointer<uint32_t> buffer_num_bytes,
86 MojoReadDataFlags flags); 89 MojoReadDataFlags flags);
87 MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, 90 MojoResult EndReadData(MojoHandle data_pipe_consumer_handle,
88 uint32_t num_bytes_read); 91 uint32_t num_bytes_read);
89 MojoResult CreateSharedBuffer(const MojoCreateSharedBufferOptions* options, 92 MojoResult CreateSharedBuffer(
90 uint64_t num_bytes, 93 UserPointer<const MojoCreateSharedBufferOptions> options,
91 MojoHandle* shared_buffer_handle); 94 uint64_t num_bytes,
95 UserPointer<MojoHandle> shared_buffer_handle);
92 MojoResult DuplicateBufferHandle( 96 MojoResult DuplicateBufferHandle(
93 MojoHandle buffer_handle, 97 MojoHandle buffer_handle,
94 const MojoDuplicateBufferHandleOptions* options, 98 UserPointer<const MojoDuplicateBufferHandleOptions> options,
95 MojoHandle* new_buffer_handle); 99 UserPointer<MojoHandle> new_buffer_handle);
96 MojoResult MapBuffer(MojoHandle buffer_handle, 100 MojoResult MapBuffer(MojoHandle buffer_handle,
97 uint64_t offset, 101 uint64_t offset,
98 uint64_t num_bytes, 102 uint64_t num_bytes,
99 void** buffer, 103 UserPointer<void*> buffer,
100 MojoMapBufferFlags flags); 104 MojoMapBufferFlags flags);
101 MojoResult UnmapBuffer(void* buffer); 105 MojoResult UnmapBuffer(UserPointerValue<void> buffer);
102 106
103 private: 107 private:
104 friend bool internal::ShutdownCheckNoLeaks(Core*); 108 friend bool internal::ShutdownCheckNoLeaks(Core*);
105 109
106 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic 110 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic
107 // validation of arguments. 111 // validation of arguments.
108 MojoResult WaitManyInternal(const MojoHandle* handles, 112 MojoResult WaitManyInternal(const MojoHandle* handles,
109 const MojoHandleSignals* signals, 113 const MojoHandleSignals* signals,
110 uint32_t num_handles, 114 uint32_t num_handles,
111 MojoDeadline deadline); 115 MojoDeadline deadline);
(...skipping 10 matching lines...) Expand all
122 126
123 // --------------------------------------------------------------------------- 127 // ---------------------------------------------------------------------------
124 128
125 DISALLOW_COPY_AND_ASSIGN(Core); 129 DISALLOW_COPY_AND_ASSIGN(Core);
126 }; 130 };
127 131
128 } // namespace system 132 } // namespace system
129 } // namespace mojo 133 } // namespace mojo
130 134
131 #endif // MOJO_SYSTEM_CORE_H_ 135 #endif // MOJO_SYSTEM_CORE_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/system/core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698