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