| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <ostream> | 12 #include <ostream> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "mojo/edk/platform/scoped_platform_handle.h" | 15 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 16 #include "mojo/edk/system/entrypoint_class.h" |
| 16 #include "mojo/edk/system/handle_signals_state.h" | 17 #include "mojo/edk/system/handle_signals_state.h" |
| 17 #include "mojo/edk/system/memory.h" | 18 #include "mojo/edk/system/memory.h" |
| 18 #include "mojo/edk/util/mutex.h" | 19 #include "mojo/edk/util/mutex.h" |
| 19 #include "mojo/edk/util/ref_counted.h" | 20 #include "mojo/edk/util/ref_counted.h" |
| 20 #include "mojo/edk/util/ref_ptr.h" | 21 #include "mojo/edk/util/ref_ptr.h" |
| 21 #include "mojo/edk/util/thread_annotations.h" | 22 #include "mojo/edk/util/thread_annotations.h" |
| 22 #include "mojo/public/c/system/buffer.h" | 23 #include "mojo/public/c/system/buffer.h" |
| 23 #include "mojo/public/c/system/data_pipe.h" | 24 #include "mojo/public/c/system/data_pipe.h" |
| 24 #include "mojo/public/c/system/handle.h" | 25 #include "mojo/public/c/system/handle.h" |
| 25 #include "mojo/public/c/system/message_pipe.h" | 26 #include "mojo/public/c/system/message_pipe.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 UNKNOWN = 0, | 68 UNKNOWN = 0, |
| 68 MESSAGE_PIPE, | 69 MESSAGE_PIPE, |
| 69 DATA_PIPE_PRODUCER, | 70 DATA_PIPE_PRODUCER, |
| 70 DATA_PIPE_CONSUMER, | 71 DATA_PIPE_CONSUMER, |
| 71 SHARED_BUFFER, | 72 SHARED_BUFFER, |
| 72 | 73 |
| 73 // "Private" types (not exposed via the public interface): | 74 // "Private" types (not exposed via the public interface): |
| 74 PLATFORM_HANDLE = -1 | 75 PLATFORM_HANDLE = -1 |
| 75 }; | 76 }; |
| 76 | 77 |
| 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. | 78 // Gets the type of the dispatcher; see |Type| above. |
| 99 virtual Type GetType() const = 0; | 79 virtual Type GetType() const = 0; |
| 100 | 80 |
| 101 // Gets whether the given entrypoint class is supported; see |EntrypointClass| | 81 // Gets whether the given entrypoint class is supported; see the definition of |
| 102 // above. This is ONLY called when a rights check has failed, to determine | 82 // |EntrypointClass|. This is ONLY called when a rights check has failed, to |
| 103 // whether |MOJO_RESULT_PERMISSION_DENIED| (if the entrypoint class is | 83 // determine whether |MOJO_RESULT_PERMISSION_DENIED| (if the entrypoint class |
| 104 // supported) or |MOJO_RESULT_INVALID_ARGUMENT| (if not) should be returned. | 84 // is supported) or |MOJO_RESULT_INVALID_ARGUMENT| (if not) should be |
| 105 // In the case that the rights check passes, |Core| will proceed immediately | 85 // returned. In the case that the rights check passes, |Core| will proceed |
| 106 // to call the method (so if the method is not supported, it must still return | 86 // immediately to call the method (so if the method is not supported, it must |
| 107 // |MOJO_RESULT_INVALID_ARGUMENT|). | 87 // still return |MOJO_RESULT_INVALID_ARGUMENT|). |
| 108 virtual bool SupportsEntrypointClass( | 88 virtual bool SupportsEntrypointClass( |
| 109 EntrypointClass entrypoint_class) const = 0; | 89 EntrypointClass entrypoint_class) const = 0; |
| 110 | 90 |
| 111 // These methods implement the various primitives named |Mojo...()|. These | 91 // These methods implement the various primitives named |Mojo...()|. These |
| 112 // take |mutex_| and handle races with |Close()|. Then they call out to | 92 // take |mutex_| and handle races with |Close()|. Then they call out to |
| 113 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which | 93 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which |
| 114 // actually implement the primitives. | 94 // actually implement the primitives. |
| 115 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and | 95 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and |
| 116 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as | 96 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as |
| 117 // possible. If this becomes an issue, we can rethink this. | 97 // possible. If this becomes an issue, we can rethink this. |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 474 |
| 495 // So logging macros and |DCHECK_EQ()|, etc. work. | 475 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 496 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 476 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
| 497 return out << static_cast<int>(type); | 477 return out << static_cast<int>(type); |
| 498 } | 478 } |
| 499 | 479 |
| 500 } // namespace system | 480 } // namespace system |
| 501 } // namespace mojo | 481 } // namespace mojo |
| 502 | 482 |
| 503 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 483 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |