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

Side by Side Diff: mojo/edk/embedder/system_impl_private_entrypoints.cc

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some review comments Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "mojo/edk/embedder/embedder_internal.h"
6 #include "mojo/edk/system/core.h"
7 #include "mojo/edk/system/dispatcher.h"
5 #include "mojo/public/c/system/buffer.h" 8 #include "mojo/public/c/system/buffer.h"
6 #include "mojo/public/c/system/data_pipe.h" 9 #include "mojo/public/c/system/data_pipe.h"
7 #include "mojo/public/c/system/functions.h" 10 #include "mojo/public/c/system/functions.h"
8 #include "mojo/public/c/system/message_pipe.h" 11 #include "mojo/public/c/system/message_pipe.h"
9 #include "mojo/public/platform/native/system_impl_private.h" 12 #include "mojo/public/platform/native/system_impl_private.h"
10 #include "third_party/mojo/src/mojo/edk/embedder/embedder_internal.h"
11 #include "third_party/mojo/src/mojo/edk/system/core.h"
12 #include "third_party/mojo/src/mojo/edk/system/dispatcher.h"
13 13
14 using mojo::embedder::internal::g_core; 14 using mojo::edk::internal::g_core;
15 using mojo::system::Core; 15 using mojo::edk::Core;
16 using mojo::system::Dispatcher; 16 using mojo::edk::Dispatcher;
17 using mojo::system::MakeUserPointer; 17
18 //TODO(use_chrome_edk)
19 /*
18 20
19 // Definitions of the system functions, but with an explicit parameter for the 21 // Definitions of the system functions, but with an explicit parameter for the
20 // core object rather than using the default singleton. Also includes functions 22 // core object rather than using the default singleton. Also includes functions
21 // for manipulating core objects. 23 // for manipulating core objects.
22 extern "C" { 24 extern "C" {
23 25
24 MojoSystemImpl MojoSystemImplGetDefaultImpl() { 26 MojoSystemImpl MojoSystemImplGetDefaultImpl() {
25 return static_cast<MojoSystemImpl>(g_core); 27 return static_cast<MojoSystemImpl>(g_core);
26 } 28 }
27 29
(...skipping 29 matching lines...) Expand all
57 if (created_handle == MOJO_HANDLE_INVALID) { 59 if (created_handle == MOJO_HANDLE_INVALID) {
58 // The handle has been lost, unfortunately. There's no guarentee we can put 60 // The handle has been lost, unfortunately. There's no guarentee we can put
59 // it back where it came from, or get the original ID back. Holding locks 61 // it back where it came from, or get the original ID back. Holding locks
60 // for multiple cores risks deadlock, so that isn't a solution. This case 62 // for multiple cores risks deadlock, so that isn't a solution. This case
61 // should not happen for reasonable uses of this API, however. 63 // should not happen for reasonable uses of this API, however.
62 LOG(ERROR) << "Could not transfer handle"; 64 LOG(ERROR) << "Could not transfer handle";
63 d->Close(); 65 d->Close();
64 return MOJO_RESULT_RESOURCE_EXHAUSTED; 66 return MOJO_RESULT_RESOURCE_EXHAUSTED;
65 } 67 }
66 68
67 MakeUserPointer(result_handle).Put(created_handle); 69 *result_handle = created_handle;
68 return MOJO_RESULT_OK; 70 return MOJO_RESULT_OK;
69 } 71 }
70 72
71 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { 73 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) {
72 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 74 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
73 DCHECK(core); 75 DCHECK(core);
74 return core->GetTimeTicksNow(); 76 return core->GetTimeTicksNow();
75 } 77 }
76 78
77 MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) { 79 MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) {
78 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 80 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
79 DCHECK(core); 81 DCHECK(core);
80 return core->Close(handle); 82 return core->Close(handle);
81 } 83 }
82 84
83 MojoResult MojoSystemImplWait(MojoSystemImpl system, 85 MojoResult MojoSystemImplWait(MojoSystemImpl system,
84 MojoHandle handle, 86 MojoHandle handle,
85 MojoHandleSignals signals, 87 MojoHandleSignals signals,
86 MojoDeadline deadline, 88 MojoDeadline deadline,
87 MojoHandleSignalsState* signals_state) { 89 MojoHandleSignalsState* signals_state) {
88 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 90 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
89 DCHECK(core); 91 DCHECK(core);
90 return core->Wait(handle, signals, deadline, MakeUserPointer(signals_state)); 92 return core->Wait(handle, signals, deadline, signals_state);
91 } 93 }
92 94
93 MojoResult MojoSystemImplWaitMany(MojoSystemImpl system, 95 MojoResult MojoSystemImplWaitMany(MojoSystemImpl system,
94 const MojoHandle* handles, 96 const MojoHandle* handles,
95 const MojoHandleSignals* signals, 97 const MojoHandleSignals* signals,
96 uint32_t num_handles, 98 uint32_t num_handles,
97 MojoDeadline deadline, 99 MojoDeadline deadline,
98 uint32_t* result_index, 100 uint32_t* result_index,
99 MojoHandleSignalsState* signals_states) { 101 MojoHandleSignalsState* signals_states) {
100 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 102 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
101 DCHECK(core); 103 DCHECK(core);
102 return core->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 104 return core->WaitMany(handles, signals, num_handles, deadline, result_index,
103 num_handles, deadline, MakeUserPointer(result_index), 105 signals_states);
104 MakeUserPointer(signals_states));
105 } 106 }
106 107
107 MojoResult MojoSystemImplCreateMessagePipe( 108 MojoResult MojoSystemImplCreateMessagePipe(
108 MojoSystemImpl system, 109 MojoSystemImpl system,
109 const MojoCreateMessagePipeOptions* options, 110 const MojoCreateMessagePipeOptions* options,
110 MojoHandle* message_pipe_handle0, 111 MojoHandle* message_pipe_handle0,
111 MojoHandle* message_pipe_handle1) { 112 MojoHandle* message_pipe_handle1) {
112 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 113 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
113 DCHECK(core); 114 DCHECK(core);
114 return core->CreateMessagePipe(MakeUserPointer(options), 115 return core->CreateMessagePipe(options, message_pipe_handle0,
115 MakeUserPointer(message_pipe_handle0), 116 message_pipe_handle1);
116 MakeUserPointer(message_pipe_handle1));
117 } 117 }
118 118
119 MojoResult MojoSystemImplWriteMessage(MojoSystemImpl system, 119 MojoResult MojoSystemImplWriteMessage(MojoSystemImpl system,
120 MojoHandle message_pipe_handle, 120 MojoHandle message_pipe_handle,
121 const void* bytes, 121 const void* bytes,
122 uint32_t num_bytes, 122 uint32_t num_bytes,
123 const MojoHandle* handles, 123 const MojoHandle* handles,
124 uint32_t num_handles, 124 uint32_t num_handles,
125 MojoWriteMessageFlags flags) { 125 MojoWriteMessageFlags flags) {
126 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 126 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
127 DCHECK(core); 127 DCHECK(core);
128 return core->WriteMessage(message_pipe_handle, MakeUserPointer(bytes), 128 return core->WriteMessage(message_pipe_handle, bytes, num_bytes, num_bytes,
129 num_bytes, MakeUserPointer(handles), num_handles, 129 handles, num_handles, flags);
130 flags);
131 } 130 }
132 131
133 MojoResult MojoSystemImplReadMessage(MojoSystemImpl system, 132 MojoResult MojoSystemImplReadMessage(MojoSystemImpl system,
134 MojoHandle message_pipe_handle, 133 MojoHandle message_pipe_handle,
135 void* bytes, 134 void* bytes,
136 uint32_t* num_bytes, 135 uint32_t* num_bytes,
137 MojoHandle* handles, 136 MojoHandle* handles,
138 uint32_t* num_handles, 137 uint32_t* num_handles,
139 MojoReadMessageFlags flags) { 138 MojoReadMessageFlags flags) {
140 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 139 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
141 DCHECK(core); 140 DCHECK(core);
142 return core->ReadMessage(message_pipe_handle, MakeUserPointer(bytes), 141 return core->ReadMessage(message_pipe_handle, bytes, num_bytes, handles,
143 MakeUserPointer(num_bytes), MakeUserPointer(handles), 142 num_handles, flags);
144 MakeUserPointer(num_handles), flags);
145 } 143 }
146 144
147 MojoResult MojoSystemImplCreateDataPipe( 145 MojoResult MojoSystemImplCreateDataPipe(
148 MojoSystemImpl system, 146 MojoSystemImpl system,
149 const MojoCreateDataPipeOptions* options, 147 const MojoCreateDataPipeOptions* options,
150 MojoHandle* data_pipe_producer_handle, 148 MojoHandle* data_pipe_producer_handle,
151 MojoHandle* data_pipe_consumer_handle) { 149 MojoHandle* data_pipe_consumer_handle) {
152 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 150 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
153 DCHECK(core); 151 DCHECK(core);
154 return core->CreateDataPipe(MakeUserPointer(options), 152 return core->CreateDataPipe(options, data_pipe_producer_handle,
155 MakeUserPointer(data_pipe_producer_handle), 153 data_pipe_consumer_handle);
156 MakeUserPointer(data_pipe_consumer_handle));
157 } 154 }
158 155
159 MojoResult MojoSystemImplWriteData(MojoSystemImpl system, 156 MojoResult MojoSystemImplWriteData(MojoSystemImpl system,
160 MojoHandle data_pipe_producer_handle, 157 MojoHandle data_pipe_producer_handle,
161 const void* elements, 158 const void* elements,
162 uint32_t* num_elements, 159 uint32_t* num_elements,
163 MojoWriteDataFlags flags) { 160 MojoWriteDataFlags flags) {
164 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 161 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
165 DCHECK(core); 162 DCHECK(core);
166 return core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements), 163 return core->WriteData(data_pipe_producer_handle, elements, num_elements,
167 MakeUserPointer(num_elements), flags); 164 flags);
168 } 165 }
169 166
170 MojoResult MojoSystemImplBeginWriteData(MojoSystemImpl system, 167 MojoResult MojoSystemImplBeginWriteData(MojoSystemImpl system,
171 MojoHandle data_pipe_producer_handle, 168 MojoHandle data_pipe_producer_handle,
172 void** buffer, 169 void** buffer,
173 uint32_t* buffer_num_elements, 170 uint32_t* buffer_num_elements,
174 MojoWriteDataFlags flags) { 171 MojoWriteDataFlags flags) {
175 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 172 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
176 DCHECK(core); 173 DCHECK(core);
177 return core->BeginWriteData(data_pipe_producer_handle, 174 return core->BeginWriteData(data_pipe_producer_handle, buffer,
178 MakeUserPointer(buffer), 175 buffer_num_elements, flags);
179 MakeUserPointer(buffer_num_elements), flags);
180 } 176 }
181 177
182 MojoResult MojoSystemImplEndWriteData(MojoSystemImpl system, 178 MojoResult MojoSystemImplEndWriteData(MojoSystemImpl system,
183 MojoHandle data_pipe_producer_handle, 179 MojoHandle data_pipe_producer_handle,
184 uint32_t num_elements_written) { 180 uint32_t num_elements_written) {
185 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 181 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
186 DCHECK(core); 182 DCHECK(core);
187 return core->EndWriteData(data_pipe_producer_handle, num_elements_written); 183 return core->EndWriteData(data_pipe_producer_handle, num_elements_written);
188 } 184 }
189 185
190 MojoResult MojoSystemImplReadData(MojoSystemImpl system, 186 MojoResult MojoSystemImplReadData(MojoSystemImpl system,
191 MojoHandle data_pipe_consumer_handle, 187 MojoHandle data_pipe_consumer_handle,
192 void* elements, 188 void* elements,
193 uint32_t* num_elements, 189 uint32_t* num_elements,
194 MojoReadDataFlags flags) { 190 MojoReadDataFlags flags) {
195 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 191 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
196 DCHECK(core); 192 DCHECK(core);
197 return core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements), 193 return core->ReadData(data_pipe_consumer_handle, elements, num_elements,
198 MakeUserPointer(num_elements), flags); 194 flags);
199 } 195 }
200 196
201 MojoResult MojoSystemImplBeginReadData(MojoSystemImpl system, 197 MojoResult MojoSystemImplBeginReadData(MojoSystemImpl system,
202 MojoHandle data_pipe_consumer_handle, 198 MojoHandle data_pipe_consumer_handle,
203 const void** buffer, 199 const void** buffer,
204 uint32_t* buffer_num_elements, 200 uint32_t* buffer_num_elements,
205 MojoReadDataFlags flags) { 201 MojoReadDataFlags flags) {
206 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 202 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
207 DCHECK(core); 203 DCHECK(core);
208 return core->BeginReadData(data_pipe_consumer_handle, MakeUserPointer(buffer), 204 return core->BeginReadData(data_pipe_consumer_handle, buffer,
209 MakeUserPointer(buffer_num_elements), flags); 205 buffer_num_elements, flags);
210 } 206 }
211 207
212 MojoResult MojoSystemImplEndReadData(MojoSystemImpl system, 208 MojoResult MojoSystemImplEndReadData(MojoSystemImpl system,
213 MojoHandle data_pipe_consumer_handle, 209 MojoHandle data_pipe_consumer_handle,
214 uint32_t num_elements_read) { 210 uint32_t num_elements_read) {
215 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 211 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
216 DCHECK(core); 212 DCHECK(core);
217 return core->EndReadData(data_pipe_consumer_handle, num_elements_read); 213 return core->EndReadData(data_pipe_consumer_handle, num_elements_read);
218 } 214 }
219 215
220 MojoResult MojoSystemImplCreateSharedBuffer( 216 MojoResult MojoSystemImplCreateSharedBuffer(
221 MojoSystemImpl system, 217 MojoSystemImpl system,
222 const MojoCreateSharedBufferOptions* options, 218 const MojoCreateSharedBufferOptions* options,
223 uint64_t num_bytes, 219 uint64_t num_bytes,
224 MojoHandle* shared_buffer_handle) { 220 MojoHandle* shared_buffer_handle) {
225 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 221 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
226 DCHECK(core); 222 DCHECK(core);
227 return core->CreateSharedBuffer(MakeUserPointer(options), num_bytes, 223 return core->CreateSharedBuffer(options, num_bytes, shared_buffer_handle);
228 MakeUserPointer(shared_buffer_handle));
229 } 224 }
230 225
231 MojoResult MojoSystemImplDuplicateBufferHandle( 226 MojoResult MojoSystemImplDuplicateBufferHandle(
232 MojoSystemImpl system, 227 MojoSystemImpl system,
233 MojoHandle buffer_handle, 228 MojoHandle buffer_handle,
234 const MojoDuplicateBufferHandleOptions* options, 229 const MojoDuplicateBufferHandleOptions* options,
235 MojoHandle* new_buffer_handle) { 230 MojoHandle* new_buffer_handle) {
236 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 231 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
237 DCHECK(core); 232 DCHECK(core);
238 return core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options), 233 return core->DuplicateBufferHandle(buffer_handle, options, new_buffer_handle);
239 MakeUserPointer(new_buffer_handle));
240 } 234 }
241 235
242 MojoResult MojoSystemImplMapBuffer(MojoSystemImpl system, 236 MojoResult MojoSystemImplMapBuffer(MojoSystemImpl system,
243 MojoHandle buffer_handle, 237 MojoHandle buffer_handle,
244 uint64_t offset, 238 uint64_t offset,
245 uint64_t num_bytes, 239 uint64_t num_bytes,
246 void** buffer, 240 void** buffer,
247 MojoMapBufferFlags flags) { 241 MojoMapBufferFlags flags) {
248 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 242 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
249 DCHECK(core); 243 DCHECK(core);
250 return core->MapBuffer(buffer_handle, offset, num_bytes, 244 return core->MapBuffer(buffer_handle, offset, num_bytes, buffer, flags);
251 MakeUserPointer(buffer), flags);
252 } 245 }
253 246
254 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { 247 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) {
255 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); 248 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system);
256 DCHECK(core); 249 DCHECK(core);
257 return core->UnmapBuffer(MakeUserPointer(buffer)); 250 return core->UnmapBuffer(buffer);
258 } 251 }
259 252
260 } // extern "C" 253 } // extern "C"
254 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698