| 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" | 5 #include "mojo/edk/embedder/embedder_internal.h" |
| 6 #include "mojo/edk/system/core.h" | 6 #include "mojo/edk/system/core.h" |
| 7 #include "mojo/edk/system/dispatcher.h" | 7 #include "mojo/edk/system/dispatcher.h" |
| 8 #include "mojo/public/c/system/buffer.h" | 8 #include "mojo/public/c/system/buffer.h" |
| 9 #include "mojo/public/c/system/data_pipe.h" | 9 #include "mojo/public/c/system/data_pipe.h" |
| 10 #include "mojo/public/c/system/functions.h" | 10 #include "mojo/public/c/system/functions.h" |
| 11 #include "mojo/public/c/system/message_pipe.h" | 11 #include "mojo/public/c/system/message_pipe.h" |
| 12 #include "mojo/public/platform/native/system_impl_private.h" | 12 #include "mojo/public/platform/native/system_impl_private.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 using mojo::edk::MakeUserPointer; |
| 18 | 18 |
| 19 // Definitions of the system functions, but with an explicit parameter for the | 19 // Definitions of the system functions, but with an explicit parameter for the |
| 20 // core object rather than using the default singleton. Also includes functions | 20 // core object rather than using the default singleton. Also includes functions |
| 21 // for manipulating core objects. | 21 // for manipulating core objects. |
| 22 extern "C" { | 22 extern "C" { |
| 23 | 23 |
| 24 MojoSystemImpl MojoSystemImplGetDefaultImpl() { | 24 MojoSystemImpl MojoSystemImplGetDefaultImpl() { |
| 25 return static_cast<MojoSystemImpl>(g_core); | 25 return static_cast<MojoSystemImpl>(g_core); |
| 26 } | 26 } |
| 27 | 27 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 LOG(ERROR) << "Could not transfer handle"; | 62 LOG(ERROR) << "Could not transfer handle"; |
| 63 d->Close(); | 63 d->Close(); |
| 64 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 64 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 65 } | 65 } |
| 66 | 66 |
| 67 MakeUserPointer(result_handle).Put(created_handle); | 67 MakeUserPointer(result_handle).Put(created_handle); |
| 68 return MOJO_RESULT_OK; | 68 return MOJO_RESULT_OK; |
| 69 } | 69 } |
| 70 | 70 |
| 71 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { | 71 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { |
| 72 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 72 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 73 DCHECK(core); | 73 DCHECK(core); |
| 74 return core->GetTimeTicksNow(); | 74 return core->GetTimeTicksNow(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) { | 77 MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) { |
| 78 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 78 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 79 DCHECK(core); | 79 DCHECK(core); |
| 80 return core->Close(handle); | 80 return core->Close(handle); |
| 81 } | 81 } |
| 82 | 82 |
| 83 MojoResult MojoSystemImplWait(MojoSystemImpl system, | 83 MojoResult MojoSystemImplWait(MojoSystemImpl system, |
| 84 MojoHandle handle, | 84 MojoHandle handle, |
| 85 MojoHandleSignals signals, | 85 MojoHandleSignals signals, |
| 86 MojoDeadline deadline, | 86 MojoDeadline deadline, |
| 87 MojoHandleSignalsState* signals_state) { | 87 MojoHandleSignalsState* signals_state) { |
| 88 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 88 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 89 DCHECK(core); | 89 DCHECK(core); |
| 90 return core->Wait(handle, signals, deadline, MakeUserPointer(signals_state)); | 90 return core->Wait(handle, signals, deadline, MakeUserPointer(signals_state)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 MojoResult MojoSystemImplWaitMany(MojoSystemImpl system, | 93 MojoResult MojoSystemImplWaitMany(MojoSystemImpl system, |
| 94 const MojoHandle* handles, | 94 const MojoHandle* handles, |
| 95 const MojoHandleSignals* signals, | 95 const MojoHandleSignals* signals, |
| 96 uint32_t num_handles, | 96 uint32_t num_handles, |
| 97 MojoDeadline deadline, | 97 MojoDeadline deadline, |
| 98 uint32_t* result_index, | 98 uint32_t* result_index, |
| 99 MojoHandleSignalsState* signals_states) { | 99 MojoHandleSignalsState* signals_states) { |
| 100 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 100 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 101 DCHECK(core); | 101 DCHECK(core); |
| 102 return core->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), | 102 return core->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), |
| 103 num_handles, deadline, MakeUserPointer(result_index), | 103 num_handles, deadline, MakeUserPointer(result_index), |
| 104 MakeUserPointer(signals_states)); | 104 MakeUserPointer(signals_states)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 MojoResult MojoSystemImplCreateMessagePipe( | 107 MojoResult MojoSystemImplCreateMessagePipe( |
| 108 MojoSystemImpl system, | 108 MojoSystemImpl system, |
| 109 const MojoCreateMessagePipeOptions* options, | 109 const MojoCreateMessagePipeOptions* options, |
| 110 MojoHandle* message_pipe_handle0, | 110 MojoHandle* message_pipe_handle0, |
| 111 MojoHandle* message_pipe_handle1) { | 111 MojoHandle* message_pipe_handle1) { |
| 112 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 112 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 113 DCHECK(core); | 113 DCHECK(core); |
| 114 return core->CreateMessagePipe(MakeUserPointer(options), | 114 return core->CreateMessagePipe(MakeUserPointer(options), |
| 115 MakeUserPointer(message_pipe_handle0), | 115 MakeUserPointer(message_pipe_handle0), |
| 116 MakeUserPointer(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, MakeUserPointer(bytes), |
| 129 num_bytes, MakeUserPointer(handles), num_handles, | 129 num_bytes, MakeUserPointer(handles), num_handles, |
| 130 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, MakeUserPointer(bytes), |
| 143 MakeUserPointer(num_bytes), MakeUserPointer(handles), | 143 MakeUserPointer(num_bytes), MakeUserPointer(handles), |
| 144 MakeUserPointer(num_handles), flags); | 144 MakeUserPointer(num_handles), flags); |
| 145 } | 145 } |
| 146 | 146 |
| 147 MojoResult MojoSystemImplCreateDataPipe( | 147 MojoResult MojoSystemImplCreateDataPipe( |
| 148 MojoSystemImpl system, | 148 MojoSystemImpl system, |
| 149 const MojoCreateDataPipeOptions* options, | 149 const MojoCreateDataPipeOptions* options, |
| 150 MojoHandle* data_pipe_producer_handle, | 150 MojoHandle* data_pipe_producer_handle, |
| 151 MojoHandle* data_pipe_consumer_handle) { | 151 MojoHandle* data_pipe_consumer_handle) { |
| 152 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 152 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 153 DCHECK(core); | 153 DCHECK(core); |
| 154 return core->CreateDataPipe(MakeUserPointer(options), | 154 return core->CreateDataPipe(MakeUserPointer(options), |
| 155 MakeUserPointer(data_pipe_producer_handle), | 155 MakeUserPointer(data_pipe_producer_handle), |
| 156 MakeUserPointer(data_pipe_consumer_handle)); | 156 MakeUserPointer(data_pipe_consumer_handle)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 MojoResult MojoSystemImplWriteData(MojoSystemImpl system, | 159 MojoResult MojoSystemImplWriteData(MojoSystemImpl system, |
| 160 MojoHandle data_pipe_producer_handle, | 160 MojoHandle data_pipe_producer_handle, |
| 161 const void* elements, | 161 const void* elements, |
| 162 uint32_t* num_elements, | 162 uint32_t* num_elements, |
| 163 MojoWriteDataFlags flags) { | 163 MojoWriteDataFlags flags) { |
| 164 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 164 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 165 DCHECK(core); | 165 DCHECK(core); |
| 166 return core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements), | 166 return core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements), |
| 167 MakeUserPointer(num_elements), flags); | 167 MakeUserPointer(num_elements), flags); |
| 168 } | 168 } |
| 169 | 169 |
| 170 MojoResult MojoSystemImplBeginWriteData(MojoSystemImpl system, | 170 MojoResult MojoSystemImplBeginWriteData(MojoSystemImpl system, |
| 171 MojoHandle data_pipe_producer_handle, | 171 MojoHandle data_pipe_producer_handle, |
| 172 void** buffer, | 172 void** buffer, |
| 173 uint32_t* buffer_num_elements, | 173 uint32_t* buffer_num_elements, |
| 174 MojoWriteDataFlags flags) { | 174 MojoWriteDataFlags flags) { |
| 175 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 175 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 176 DCHECK(core); | 176 DCHECK(core); |
| 177 return core->BeginWriteData(data_pipe_producer_handle, | 177 return core->BeginWriteData(data_pipe_producer_handle, |
| 178 MakeUserPointer(buffer), | 178 MakeUserPointer(buffer), |
| 179 MakeUserPointer(buffer_num_elements), flags); | 179 MakeUserPointer(buffer_num_elements), flags); |
| 180 } | 180 } |
| 181 | 181 |
| 182 MojoResult MojoSystemImplEndWriteData(MojoSystemImpl system, | 182 MojoResult MojoSystemImplEndWriteData(MojoSystemImpl system, |
| 183 MojoHandle data_pipe_producer_handle, | 183 MojoHandle data_pipe_producer_handle, |
| 184 uint32_t num_elements_written) { | 184 uint32_t num_elements_written) { |
| 185 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 185 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 186 DCHECK(core); | 186 DCHECK(core); |
| 187 return core->EndWriteData(data_pipe_producer_handle, num_elements_written); | 187 return core->EndWriteData(data_pipe_producer_handle, num_elements_written); |
| 188 } | 188 } |
| 189 | 189 |
| 190 MojoResult MojoSystemImplReadData(MojoSystemImpl system, | 190 MojoResult MojoSystemImplReadData(MojoSystemImpl system, |
| 191 MojoHandle data_pipe_consumer_handle, | 191 MojoHandle data_pipe_consumer_handle, |
| 192 void* elements, | 192 void* elements, |
| 193 uint32_t* num_elements, | 193 uint32_t* num_elements, |
| 194 MojoReadDataFlags flags) { | 194 MojoReadDataFlags flags) { |
| 195 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 195 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 196 DCHECK(core); | 196 DCHECK(core); |
| 197 return core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements), | 197 return core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements), |
| 198 MakeUserPointer(num_elements), flags); | 198 MakeUserPointer(num_elements), flags); |
| 199 } | 199 } |
| 200 | 200 |
| 201 MojoResult MojoSystemImplBeginReadData(MojoSystemImpl system, | 201 MojoResult MojoSystemImplBeginReadData(MojoSystemImpl system, |
| 202 MojoHandle data_pipe_consumer_handle, | 202 MojoHandle data_pipe_consumer_handle, |
| 203 const void** buffer, | 203 const void** buffer, |
| 204 uint32_t* buffer_num_elements, | 204 uint32_t* buffer_num_elements, |
| 205 MojoReadDataFlags flags) { | 205 MojoReadDataFlags flags) { |
| 206 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 206 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 207 DCHECK(core); | 207 DCHECK(core); |
| 208 return core->BeginReadData(data_pipe_consumer_handle, MakeUserPointer(buffer), | 208 return core->BeginReadData(data_pipe_consumer_handle, MakeUserPointer(buffer), |
| 209 MakeUserPointer(buffer_num_elements), flags); | 209 MakeUserPointer(buffer_num_elements), flags); |
| 210 } | 210 } |
| 211 | 211 |
| 212 MojoResult MojoSystemImplEndReadData(MojoSystemImpl system, | 212 MojoResult MojoSystemImplEndReadData(MojoSystemImpl system, |
| 213 MojoHandle data_pipe_consumer_handle, | 213 MojoHandle data_pipe_consumer_handle, |
| 214 uint32_t num_elements_read) { | 214 uint32_t num_elements_read) { |
| 215 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 215 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 216 DCHECK(core); | 216 DCHECK(core); |
| 217 return core->EndReadData(data_pipe_consumer_handle, num_elements_read); | 217 return core->EndReadData(data_pipe_consumer_handle, num_elements_read); |
| 218 } | 218 } |
| 219 | 219 |
| 220 MojoResult MojoSystemImplCreateSharedBuffer( | 220 MojoResult MojoSystemImplCreateSharedBuffer( |
| 221 MojoSystemImpl system, | 221 MojoSystemImpl system, |
| 222 const MojoCreateSharedBufferOptions* options, | 222 const MojoCreateSharedBufferOptions* options, |
| 223 uint64_t num_bytes, | 223 uint64_t num_bytes, |
| 224 MojoHandle* shared_buffer_handle) { | 224 MojoHandle* shared_buffer_handle) { |
| 225 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 225 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 226 DCHECK(core); | 226 DCHECK(core); |
| 227 return core->CreateSharedBuffer(MakeUserPointer(options), num_bytes, | 227 return core->CreateSharedBuffer(MakeUserPointer(options), num_bytes, |
| 228 MakeUserPointer(shared_buffer_handle)); | 228 MakeUserPointer(shared_buffer_handle)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 MojoResult MojoSystemImplDuplicateBufferHandle( | 231 MojoResult MojoSystemImplDuplicateBufferHandle( |
| 232 MojoSystemImpl system, | 232 MojoSystemImpl system, |
| 233 MojoHandle buffer_handle, | 233 MojoHandle buffer_handle, |
| 234 const MojoDuplicateBufferHandleOptions* options, | 234 const MojoDuplicateBufferHandleOptions* options, |
| 235 MojoHandle* new_buffer_handle) { | 235 MojoHandle* new_buffer_handle) { |
| 236 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 236 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 237 DCHECK(core); | 237 DCHECK(core); |
| 238 return core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options), | 238 return core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options), |
| 239 MakeUserPointer(new_buffer_handle)); | 239 MakeUserPointer(new_buffer_handle)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 MojoResult MojoSystemImplMapBuffer(MojoSystemImpl system, | 242 MojoResult MojoSystemImplMapBuffer(MojoSystemImpl system, |
| 243 MojoHandle buffer_handle, | 243 MojoHandle buffer_handle, |
| 244 uint64_t offset, | 244 uint64_t offset, |
| 245 uint64_t num_bytes, | 245 uint64_t num_bytes, |
| 246 void** buffer, | 246 void** buffer, |
| 247 MojoMapBufferFlags flags) { | 247 MojoMapBufferFlags flags) { |
| 248 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 248 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 249 DCHECK(core); | 249 DCHECK(core); |
| 250 return core->MapBuffer(buffer_handle, offset, num_bytes, | 250 return core->MapBuffer(buffer_handle, offset, num_bytes, |
| 251 MakeUserPointer(buffer), flags); | 251 MakeUserPointer(buffer), flags); |
| 252 } | 252 } |
| 253 | 253 |
| 254 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { | 254 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { |
| 255 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 255 mojo::edk::Core* core = static_cast<mojo::edk::Core*>(system); |
| 256 DCHECK(core); | 256 DCHECK(core); |
| 257 return core->UnmapBuffer(MakeUserPointer(buffer)); | 257 return core->UnmapBuffer(MakeUserPointer(buffer)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // extern "C" | 260 } // extern "C" |
| OLD | NEW |