| 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_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 } // namespace test | 54 } // namespace test |
| 55 | 55 |
| 56 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular | 56 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular |
| 57 // handle. This includes most (all?) primitives except for |MojoWait...()|. This | 57 // handle. This includes most (all?) primitives except for |MojoWait...()|. This |
| 58 // object is thread-safe, with its state being protected by a single mutex | 58 // object is thread-safe, with its state being protected by a single mutex |
| 59 // |mutex_|, which is also made available to implementation subclasses (via the | 59 // |mutex_|, which is also made available to implementation subclasses (via the |
| 60 // |mutex()| method). | 60 // |mutex()| method). |
| 61 class Dispatcher : public util::RefCountedThreadSafe<Dispatcher> { | 61 class Dispatcher : public util::RefCountedThreadSafe<Dispatcher> { |
| 62 public: | 62 public: |
| 63 // Types of dispatchers. Note that these are not necessarily a one-to-one with |
| 64 // implementations of |Dispatcher|: multiple implementations may share the |
| 65 // same type. |
| 63 enum class Type { | 66 enum class Type { |
| 64 UNKNOWN = 0, | 67 UNKNOWN = 0, |
| 65 MESSAGE_PIPE, | 68 MESSAGE_PIPE, |
| 66 DATA_PIPE_PRODUCER, | 69 DATA_PIPE_PRODUCER, |
| 67 DATA_PIPE_CONSUMER, | 70 DATA_PIPE_CONSUMER, |
| 68 SHARED_BUFFER, | 71 SHARED_BUFFER, |
| 69 | 72 |
| 70 // "Private" types (not exposed via the public interface): | 73 // "Private" types (not exposed via the public interface): |
| 71 PLATFORM_HANDLE = -1 | 74 PLATFORM_HANDLE = -1 |
| 72 }; | 75 }; |
| 76 |
| 77 // Classes of "entrypoints"/"syscalls": Each dispatcher should support entire |
| 78 // classes of methods (and if they don't support a given class, they should |
| 79 // return |MOJO_RESULT_INVALID_ARGUMENT| for all the methods in that class). |
| 80 // Warning: A method may be called even if |SupportsEntrypointClass()| |
| 81 // indicates that the method's class is not supported (see below). |
| 82 enum class EntrypointClass { |
| 83 // |ReadMessage()|, |WriteMessage()|: |
| 84 MESSAGE_PIPE, |
| 85 |
| 86 // |SetDataPipeProducerOptions()|, |GetDataPipeProducerOptions()|, |
| 87 // |WriteData()|, |BeginWriteData()|, |EndWriteData()|: |
| 88 DATA_PIPE_PRODUCER, |
| 89 |
| 90 // |SetDataPipeConsumerOptions()|, |GetDataPipeConsumerOptions()|, |
| 91 // |ReadData()|, |BeginReadData()|, |EndReadData()|: |
| 92 DATA_PIPE_CONSUMER, |
| 93 |
| 94 // |DuplicateBufferHandle()|, |GetBufferInformation()|, |MapBuffer()|: |
| 95 BUFFER, |
| 96 }; |
| 97 |
| 98 // Gets the type of the dispatcher; see |Type| above. |
| 73 virtual Type GetType() const = 0; | 99 virtual Type GetType() const = 0; |
| 74 | 100 |
| 101 // Gets whether the given entrypoint class is supported; see |EntrypointClass| |
| 102 // above. This is ONLY called when a rights check has failed, to determine |
| 103 // whether |MOJO_RESULT_PERMISSION_DENIED| (if the entrypoint class is |
| 104 // supported) or |MOJO_RESULT_INVALID_ARGUMENT| (if not) should be returned. |
| 105 // In the case that the rights check passes, |Core| will proceed immediately |
| 106 // to call the method (so if the method is not supported, it must still return |
| 107 // |MOJO_RESULT_INVALID_ARGUMENT|). |
| 108 virtual bool SupportsEntrypointClass( |
| 109 EntrypointClass entrypoint_class) const = 0; |
| 110 |
| 75 // These methods implement the various primitives named |Mojo...()|. These | 111 // These methods implement the various primitives named |Mojo...()|. These |
| 76 // take |mutex_| and handle races with |Close()|. Then they call out to | 112 // take |mutex_| and handle races with |Close()|. Then they call out to |
| 77 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which | 113 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which |
| 78 // actually implement the primitives. | 114 // actually implement the primitives. |
| 79 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and | 115 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and |
| 80 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as | 116 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as |
| 81 // possible. If this becomes an issue, we can rethink this. | 117 // possible. If this becomes an issue, we can rethink this. |
| 82 MojoResult Close(); | 118 MojoResult Close(); |
| 83 | 119 |
| 120 // |EntrypointClass::MESSAGE_PIPE|: |
| 84 // |transports| may be non-null if and only if there are handles to be | 121 // |transports| may be non-null if and only if there are handles to be |
| 85 // written; not that |this| must not be in |transports|. On success, all the | 122 // written; not that |this| must not be in |transports|. On success, all the |
| 86 // dispatchers in |transports| must have been moved to a closed state; on | 123 // dispatchers in |transports| must have been moved to a closed state; on |
| 87 // failure, they should remain in their original state. | 124 // failure, they should remain in their original state. |
| 88 MojoResult WriteMessage(UserPointer<const void> bytes, | 125 MojoResult WriteMessage(UserPointer<const void> bytes, |
| 89 uint32_t num_bytes, | 126 uint32_t num_bytes, |
| 90 std::vector<DispatcherTransport>* transports, | 127 std::vector<DispatcherTransport>* transports, |
| 91 MojoWriteMessageFlags flags); | 128 MojoWriteMessageFlags flags); |
| 92 // |dispatchers| must be non-null but empty, if |num_dispatchers| is non-null | 129 // |dispatchers| must be non-null but empty, if |num_dispatchers| is non-null |
| 93 // and nonzero. On success, it will be set to the dispatchers to be received | 130 // and nonzero. On success, it will be set to the dispatchers to be received |
| 94 // (and assigned handles) as part of the message. | 131 // (and assigned handles) as part of the message. |
| 95 MojoResult ReadMessage(UserPointer<void> bytes, | 132 MojoResult ReadMessage(UserPointer<void> bytes, |
| 96 UserPointer<uint32_t> num_bytes, | 133 UserPointer<uint32_t> num_bytes, |
| 97 DispatcherVector* dispatchers, | 134 DispatcherVector* dispatchers, |
| 98 uint32_t* num_dispatchers, | 135 uint32_t* num_dispatchers, |
| 99 MojoReadMessageFlags flags); | 136 MojoReadMessageFlags flags); |
| 100 | 137 |
| 138 // |EntrypointClass::DATA_PIPE_PRODUCER|: |
| 101 MojoResult SetDataPipeProducerOptions( | 139 MojoResult SetDataPipeProducerOptions( |
| 102 UserPointer<const MojoDataPipeProducerOptions> options); | 140 UserPointer<const MojoDataPipeProducerOptions> options); |
| 103 MojoResult GetDataPipeProducerOptions( | 141 MojoResult GetDataPipeProducerOptions( |
| 104 UserPointer<MojoDataPipeProducerOptions> options, | 142 UserPointer<MojoDataPipeProducerOptions> options, |
| 105 uint32_t options_num_bytes); | 143 uint32_t options_num_bytes); |
| 106 MojoResult WriteData(UserPointer<const void> elements, | 144 MojoResult WriteData(UserPointer<const void> elements, |
| 107 UserPointer<uint32_t> elements_num_bytes, | 145 UserPointer<uint32_t> elements_num_bytes, |
| 108 MojoWriteDataFlags flags); | 146 MojoWriteDataFlags flags); |
| 109 MojoResult BeginWriteData(UserPointer<void*> buffer, | 147 MojoResult BeginWriteData(UserPointer<void*> buffer, |
| 110 UserPointer<uint32_t> buffer_num_bytes, | 148 UserPointer<uint32_t> buffer_num_bytes, |
| 111 MojoWriteDataFlags flags); | 149 MojoWriteDataFlags flags); |
| 112 MojoResult EndWriteData(uint32_t num_bytes_written); | 150 MojoResult EndWriteData(uint32_t num_bytes_written); |
| 151 |
| 152 // |EntrypointClass::DATA_PIPE_CONSUMER|: |
| 113 MojoResult SetDataPipeConsumerOptions( | 153 MojoResult SetDataPipeConsumerOptions( |
| 114 UserPointer<const MojoDataPipeConsumerOptions> options); | 154 UserPointer<const MojoDataPipeConsumerOptions> options); |
| 115 MojoResult GetDataPipeConsumerOptions( | 155 MojoResult GetDataPipeConsumerOptions( |
| 116 UserPointer<MojoDataPipeConsumerOptions> options, | 156 UserPointer<MojoDataPipeConsumerOptions> options, |
| 117 uint32_t options_num_bytes); | 157 uint32_t options_num_bytes); |
| 118 MojoResult ReadData(UserPointer<void> elements, | 158 MojoResult ReadData(UserPointer<void> elements, |
| 119 UserPointer<uint32_t> num_bytes, | 159 UserPointer<uint32_t> num_bytes, |
| 120 MojoReadDataFlags flags); | 160 MojoReadDataFlags flags); |
| 121 MojoResult BeginReadData(UserPointer<const void*> buffer, | 161 MojoResult BeginReadData(UserPointer<const void*> buffer, |
| 122 UserPointer<uint32_t> buffer_num_bytes, | 162 UserPointer<uint32_t> buffer_num_bytes, |
| 123 MojoReadDataFlags flags); | 163 MojoReadDataFlags flags); |
| 124 MojoResult EndReadData(uint32_t num_bytes_read); | 164 MojoResult EndReadData(uint32_t num_bytes_read); |
| 125 | 165 |
| 166 // |EntrypointClass::BUFFER|: |
| 126 // |options| may be null. |new_dispatcher| must not be null, but | 167 // |options| may be null. |new_dispatcher| must not be null, but |
| 127 // |*new_dispatcher| should be null (and will contain the dispatcher for the | 168 // |*new_dispatcher| should be null (and will contain the dispatcher for the |
| 128 // new handle on success). | 169 // new handle on success). |
| 129 MojoResult DuplicateBufferHandle( | 170 MojoResult DuplicateBufferHandle( |
| 130 UserPointer<const MojoDuplicateBufferHandleOptions> options, | 171 UserPointer<const MojoDuplicateBufferHandleOptions> options, |
| 131 util::RefPtr<Dispatcher>* new_dispatcher); | 172 util::RefPtr<Dispatcher>* new_dispatcher); |
| 132 MojoResult GetBufferInformation(UserPointer<MojoBufferInformation> info, | 173 MojoResult GetBufferInformation(UserPointer<MojoBufferInformation> info, |
| 133 uint32_t info_num_bytes); | 174 uint32_t info_num_bytes); |
| 134 MojoResult MapBuffer( | 175 MojoResult MapBuffer( |
| 135 uint64_t offset, | 176 uint64_t offset, |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 494 |
| 454 // So logging macros and |DCHECK_EQ()|, etc. work. | 495 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 455 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 496 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
| 456 return out << static_cast<int>(type); | 497 return out << static_cast<int>(type); |
| 457 } | 498 } |
| 458 | 499 |
| 459 } // namespace system | 500 } // namespace system |
| 460 } // namespace mojo | 501 } // namespace mojo |
| 461 | 502 |
| 462 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 503 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |