1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
mojo / core / dispatcher.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/core/dispatcher.h"
#include "base/logging.h"
#include "mojo/core/configuration.h"
#include "mojo/core/data_pipe_consumer_dispatcher.h"
#include "mojo/core/data_pipe_producer_dispatcher.h"
#include "mojo/core/message_pipe_dispatcher.h"
#include "mojo/core/platform_handle_dispatcher.h"
#include "mojo/core/ports/event.h"
#include "mojo/core/shared_buffer_dispatcher.h"
namespace mojo {
namespace core {
namespace {
constinit thread_local bool is_extracting_handles_from_message = false;
} // namespace
Dispatcher::DispatcherInTransit::DispatcherInTransit() = default;
Dispatcher::DispatcherInTransit::DispatcherInTransit(
const DispatcherInTransit& other) = default;
Dispatcher::DispatcherInTransit::~DispatcherInTransit() = default;
// static
void Dispatcher::SetExtractingHandlesFromMessage(bool extracting) {
is_extracting_handles_from_message = extracting;
}
// static
void Dispatcher::AssertNotExtractingHandlesFromMessage() {
DCHECK(!is_extracting_handles_from_message);
}
MojoResult Dispatcher::WatchDispatcher(scoped_refptr<Dispatcher> dispatcher,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::CancelWatch(uintptr_t context) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::Arm(uint32_t* num_blocking_events,
MojoTrapEvent* blocking_events) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::WriteMessage(
std::unique_ptr<ports::UserMessageEvent> message) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::ReadMessage(
std::unique_ptr<ports::UserMessageEvent>* message) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::DuplicateBufferHandle(
const MojoDuplicateBufferHandleOptions* options,
scoped_refptr<Dispatcher>* new_dispatcher) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::MapBuffer(
uint64_t offset,
uint64_t num_bytes,
std::unique_ptr<PlatformSharedMemoryMapping>* mapping) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::GetBufferInfo(MojoSharedBufferInfo* info) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::ReadData(const MojoReadDataOptions& options,
void* elements,
uint32_t* num_bytes) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::BeginReadData(const void** buffer,
uint32_t* buffer_num_bytes) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::EndReadData(uint32_t num_bytes_read) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::WriteData(const void* elements,
uint32_t* num_bytes,
const MojoWriteDataOptions& options) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::BeginWriteData(void** buffer,
uint32_t* buffer_num_bytes,
MojoBeginWriteDataFlags flags) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::EndWriteData(uint32_t num_bytes_written) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::AttachMessagePipe(std::string_view name,
ports::PortRef remote_peer_port) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::ExtractMessagePipe(std::string_view name,
MojoHandle* message_pipe_handle) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::SetQuota(MojoQuotaType type, uint64_t limit) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::QueryQuota(MojoQuotaType type,
uint64_t* limit,
uint64_t* usage) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
HandleSignalsState Dispatcher::GetHandleSignalsState() const {
return HandleSignalsState();
}
MojoResult Dispatcher::AddWatcherRef(
const scoped_refptr<WatcherDispatcher>& watcher,
uintptr_t context) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
MojoResult Dispatcher::RemoveWatcherRef(WatcherDispatcher* watcher,
uintptr_t context) {
return MOJO_RESULT_INVALID_ARGUMENT;
}
void Dispatcher::StartSerialize(uint32_t* num_bytes,
uint32_t* num_ports,
uint32_t* num_platform_handles) {
*num_bytes = 0;
*num_ports = 0;
*num_platform_handles = 0;
}
bool Dispatcher::EndSerialize(void* destination,
ports::PortName* ports,
PlatformHandle* handles) {
LOG(ERROR) << "Attempting to serialize a non-transferrable dispatcher.";
return true;
}
bool Dispatcher::BeginTransit() {
return true;
}
void Dispatcher::CompleteTransitAndClose() {}
void Dispatcher::CancelTransit() {}
// static
scoped_refptr<Dispatcher> Dispatcher::Deserialize(
Type type,
const void* bytes,
size_t num_bytes,
const ports::PortName* ports,
size_t num_ports,
PlatformHandle* platform_handles,
size_t num_platform_handles) {
switch (type) {
case Type::MESSAGE_PIPE:
return MessagePipeDispatcher::Deserialize(bytes, num_bytes, ports,
num_ports, platform_handles,
num_platform_handles);
case Type::SHARED_BUFFER:
return SharedBufferDispatcher::Deserialize(bytes, num_bytes, ports,
num_ports, platform_handles,
num_platform_handles);
case Type::DATA_PIPE_CONSUMER:
return DataPipeConsumerDispatcher::Deserialize(
bytes, num_bytes, ports, num_ports, platform_handles,
num_platform_handles);
case Type::DATA_PIPE_PRODUCER:
return DataPipeProducerDispatcher::Deserialize(
bytes, num_bytes, ports, num_ports, platform_handles,
num_platform_handles);
case Type::PLATFORM_HANDLE:
return PlatformHandleDispatcher::Deserialize(bytes, num_bytes, ports,
num_ports, platform_handles,
num_platform_handles);
default:
LOG(ERROR) << "Deserializing invalid dispatcher type.";
return nullptr;
}
}
Dispatcher::Dispatcher() = default;
Dispatcher::~Dispatcher() = default;
} // namespace core
} // namespace mojo