| 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 #include "mojo/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "mojo/edk/system/handle_signals_state.h" | 28 #include "mojo/edk/system/handle_signals_state.h" |
| 29 #include "mojo/edk/system/message_for_transit.h" | 29 #include "mojo/edk/system/message_for_transit.h" |
| 30 #include "mojo/edk/system/message_pipe_dispatcher.h" | 30 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 31 #include "mojo/edk/system/platform_handle_dispatcher.h" | 31 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 32 #include "mojo/edk/system/ports/name.h" | 32 #include "mojo/edk/system/ports/name.h" |
| 33 #include "mojo/edk/system/ports/node.h" | 33 #include "mojo/edk/system/ports/node.h" |
| 34 #include "mojo/edk/system/request_context.h" | 34 #include "mojo/edk/system/request_context.h" |
| 35 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 35 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 36 #include "mojo/edk/system/wait_set_dispatcher.h" | 36 #include "mojo/edk/system/wait_set_dispatcher.h" |
| 37 #include "mojo/edk/system/waiter.h" | 37 #include "mojo/edk/system/waiter.h" |
| 38 #include "mojo/edk/system/watcher_dispatcher.h" | |
| 39 | 38 |
| 40 namespace mojo { | 39 namespace mojo { |
| 41 namespace edk { | 40 namespace edk { |
| 42 | 41 |
| 43 namespace { | 42 namespace { |
| 44 | 43 |
| 45 // This is an unnecessarily large limit that is relatively easy to enforce. | 44 // This is an unnecessarily large limit that is relatively easy to enforce. |
| 46 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; | 45 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; |
| 47 | 46 |
| 48 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process | 47 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process |
| 49 // pipes too; for now we just use a constant. This only affects bootstrap pipes. | 48 // pipes too; for now we just use a constant. This only affects bootstrap pipes. |
| 50 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; | 49 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; |
| 51 | 50 |
| 51 void CallWatchCallback(MojoWatchCallback callback, |
| 52 uintptr_t context, |
| 53 MojoResult result, |
| 54 const HandleSignalsState& signals_state, |
| 55 MojoWatchNotificationFlags flags) { |
| 56 callback(context, result, static_cast<MojoHandleSignalsState>(signals_state), |
| 57 flags); |
| 58 } |
| 59 |
| 52 MojoResult MojoPlatformHandleToScopedPlatformHandle( | 60 MojoResult MojoPlatformHandleToScopedPlatformHandle( |
| 53 const MojoPlatformHandle* platform_handle, | 61 const MojoPlatformHandle* platform_handle, |
| 54 ScopedPlatformHandle* out_handle) { | 62 ScopedPlatformHandle* out_handle) { |
| 55 if (platform_handle->struct_size != sizeof(MojoPlatformHandle)) | 63 if (platform_handle->struct_size != sizeof(MojoPlatformHandle)) |
| 56 return MOJO_RESULT_INVALID_ARGUMENT; | 64 return MOJO_RESULT_INVALID_ARGUMENT; |
| 57 | 65 |
| 58 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) { | 66 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) { |
| 59 out_handle->reset(); | 67 out_handle->reset(); |
| 60 return MOJO_RESULT_OK; | 68 return MOJO_RESULT_OK; |
| 61 } | 69 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a | 421 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a |
| 414 // subclass of |MojoHandleSignalsState| that doesn't add any data members. | 422 // subclass of |MojoHandleSignalsState| that doesn't add any data members. |
| 415 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, | 423 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, |
| 416 reinterpret_cast<HandleSignalsState*>(signals_state)); | 424 reinterpret_cast<HandleSignalsState*>(signals_state)); |
| 417 } | 425 } |
| 418 if (index != static_cast<uint32_t>(-1) && result_index) | 426 if (index != static_cast<uint32_t>(-1) && result_index) |
| 419 *result_index = index; | 427 *result_index = index; |
| 420 return rv; | 428 return rv; |
| 421 } | 429 } |
| 422 | 430 |
| 423 MojoResult Core::CreateWatcher(MojoWatcherCallback callback, | 431 MojoResult Core::Watch(MojoHandle handle, |
| 424 MojoHandle* watcher_handle) { | |
| 425 RequestContext request_context; | |
| 426 if (!watcher_handle) | |
| 427 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 428 *watcher_handle = AddDispatcher(new WatcherDispatcher(callback)); | |
| 429 if (*watcher_handle == MOJO_HANDLE_INVALID) | |
| 430 return MOJO_RESULT_RESOURCE_EXHAUSTED; | |
| 431 return MOJO_RESULT_OK; | |
| 432 } | |
| 433 | |
| 434 MojoResult Core::Watch(MojoHandle watcher_handle, | |
| 435 MojoHandle handle, | |
| 436 MojoHandleSignals signals, | 432 MojoHandleSignals signals, |
| 433 MojoWatchCallback callback, |
| 437 uintptr_t context) { | 434 uintptr_t context) { |
| 438 RequestContext request_context; | 435 RequestContext request_context; |
| 439 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); | |
| 440 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) | |
| 441 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 442 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); | 436 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); |
| 443 if (!dispatcher) | 437 if (!dispatcher) |
| 444 return MOJO_RESULT_INVALID_ARGUMENT; | 438 return MOJO_RESULT_INVALID_ARGUMENT; |
| 445 return watcher->WatchDispatcher(dispatcher, signals, context); | 439 return dispatcher->Watch( |
| 440 signals, base::Bind(&CallWatchCallback, callback, context), context); |
| 446 } | 441 } |
| 447 | 442 |
| 448 MojoResult Core::CancelWatch(MojoHandle watcher_handle, uintptr_t context) { | 443 MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) { |
| 449 RequestContext request_context; | 444 RequestContext request_context; |
| 450 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); | 445 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); |
| 451 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) | 446 if (!dispatcher) |
| 452 return MOJO_RESULT_INVALID_ARGUMENT; | 447 return MOJO_RESULT_INVALID_ARGUMENT; |
| 453 return watcher->CancelWatch(context); | 448 return dispatcher->CancelWatch(context); |
| 454 } | |
| 455 | |
| 456 MojoResult Core::ArmWatcher(MojoHandle watcher_handle, | |
| 457 uint32_t* num_ready_contexts, | |
| 458 uintptr_t* ready_contexts, | |
| 459 MojoResult* ready_results, | |
| 460 MojoHandleSignalsState* ready_signals_states) { | |
| 461 RequestContext request_context; | |
| 462 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle); | |
| 463 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER) | |
| 464 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 465 return watcher->Arm(num_ready_contexts, ready_contexts, ready_results, | |
| 466 ready_signals_states); | |
| 467 } | 449 } |
| 468 | 450 |
| 469 MojoResult Core::AllocMessage(uint32_t num_bytes, | 451 MojoResult Core::AllocMessage(uint32_t num_bytes, |
| 470 const MojoHandle* handles, | 452 const MojoHandle* handles, |
| 471 uint32_t num_handles, | 453 uint32_t num_handles, |
| 472 MojoAllocMessageFlags flags, | 454 MojoAllocMessageFlags flags, |
| 473 MojoMessageHandle* message) { | 455 MojoMessageHandle* message) { |
| 474 if (!message) | 456 if (!message) |
| 475 return MOJO_RESULT_INVALID_ARGUMENT; | 457 return MOJO_RESULT_INVALID_ARGUMENT; |
| 476 | 458 |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 std::unique_ptr<NodeController> node_controller) { | 1170 std::unique_ptr<NodeController> node_controller) { |
| 1189 // It's OK to leak this reference. At this point we know the IO loop is still | 1171 // It's OK to leak this reference. At this point we know the IO loop is still |
| 1190 // running, and we know the NodeController will observe its eventual | 1172 // running, and we know the NodeController will observe its eventual |
| 1191 // destruction. This tells the NodeController to delete itself when that | 1173 // destruction. This tells the NodeController to delete itself when that |
| 1192 // happens. | 1174 // happens. |
| 1193 node_controller.release()->DestroyOnIOThreadShutdown(); | 1175 node_controller.release()->DestroyOnIOThreadShutdown(); |
| 1194 } | 1176 } |
| 1195 | 1177 |
| 1196 } // namespace edk | 1178 } // namespace edk |
| 1197 } // namespace mojo | 1179 } // namespace mojo |
| OLD | NEW |