| 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/dispatcher.h" | 5 #include "mojo/edk/system/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/configuration.h" | 8 #include "mojo/edk/system/configuration.h" |
| 9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
| 10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return nullptr; | 84 return nullptr; |
| 85 case Type::MESSAGE_PIPE: | 85 case Type::MESSAGE_PIPE: |
| 86 return MessagePipeDispatcher::Deserialize(channel, source, size); | 86 return MessagePipeDispatcher::Deserialize(channel, source, size); |
| 87 case Type::DATA_PIPE_PRODUCER: | 87 case Type::DATA_PIPE_PRODUCER: |
| 88 return DataPipeProducerDispatcher::Deserialize(channel, source, size); | 88 return DataPipeProducerDispatcher::Deserialize(channel, source, size); |
| 89 case Type::DATA_PIPE_CONSUMER: | 89 case Type::DATA_PIPE_CONSUMER: |
| 90 return DataPipeConsumerDispatcher::Deserialize(channel, source, size); | 90 return DataPipeConsumerDispatcher::Deserialize(channel, source, size); |
| 91 case Type::SHARED_BUFFER: | 91 case Type::SHARED_BUFFER: |
| 92 return SharedBufferDispatcher::Deserialize(channel, source, size, | 92 return SharedBufferDispatcher::Deserialize(channel, source, size, |
| 93 platform_handles); | 93 platform_handles); |
| 94 case Type::WAIT_SET: |
| 95 // Wait sets aren't transferrable. |
| 96 LOG(WARNING) << "Received wait set handle"; |
| 97 return nullptr; |
| 94 case Type::PLATFORM_HANDLE: | 98 case Type::PLATFORM_HANDLE: |
| 95 return PlatformHandleDispatcher::Deserialize(channel, source, size, | 99 return PlatformHandleDispatcher::Deserialize(channel, source, size, |
| 96 platform_handles); | 100 platform_handles); |
| 97 } | 101 } |
| 98 LOG(WARNING) << "Unknown dispatcher type " << type; | 102 LOG(WARNING) << "Unknown dispatcher type " << type; |
| 99 return nullptr; | 103 return nullptr; |
| 100 } | 104 } |
| 101 | 105 |
| 102 MojoResult Dispatcher::Close() { | 106 MojoResult Dispatcher::Close() { |
| 103 MutexLocker locker(&mutex_); | 107 MutexLocker locker(&mutex_); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 uint64_t num_bytes, | 269 uint64_t num_bytes, |
| 266 MojoMapBufferFlags flags, | 270 MojoMapBufferFlags flags, |
| 267 std::unique_ptr<PlatformSharedBufferMapping>* mapping) { | 271 std::unique_ptr<PlatformSharedBufferMapping>* mapping) { |
| 268 MutexLocker locker(&mutex_); | 272 MutexLocker locker(&mutex_); |
| 269 if (is_closed_) | 273 if (is_closed_) |
| 270 return MOJO_RESULT_INVALID_ARGUMENT; | 274 return MOJO_RESULT_INVALID_ARGUMENT; |
| 271 | 275 |
| 272 return MapBufferImplNoLock(offset, num_bytes, flags, mapping); | 276 return MapBufferImplNoLock(offset, num_bytes, flags, mapping); |
| 273 } | 277 } |
| 274 | 278 |
| 279 MojoResult Dispatcher::WaitSetAdd( |
| 280 UserPointer<const MojoWaitSetAddOptions> options, |
| 281 Handle&& handle, |
| 282 MojoHandleSignals signals, |
| 283 uint64_t cookie) { |
| 284 MutexLocker locker(&mutex_); |
| 285 if (is_closed_) |
| 286 return MOJO_RESULT_INVALID_ARGUMENT; |
| 287 |
| 288 return WaitSetAddImplNoLock(options, std::move(handle), signals, cookie); |
| 289 } |
| 290 |
| 291 MojoResult Dispatcher::WaitSetRemove(uint64_t cookie) { |
| 292 MutexLocker locker(&mutex_); |
| 293 if (is_closed_) |
| 294 return MOJO_RESULT_INVALID_ARGUMENT; |
| 295 |
| 296 return WaitSetRemoveImplNoLock(cookie); |
| 297 } |
| 298 |
| 299 MojoResult Dispatcher::WaitSetWait(MojoDeadline deadline, |
| 300 UserPointer<uint32_t> num_results, |
| 301 UserPointer<MojoWaitSetResult> results, |
| 302 UserPointer<uint32_t> max_results) { |
| 303 // Note: This doesn't lock |mutex_|, and leaves everything for |
| 304 // |WaitSetWaitImpl()| to do. (We could just make this method virtual, but we |
| 305 // prefer to have a separate "impl" method for consistency.) |
| 306 return WaitSetWaitImpl(deadline, num_results, results, max_results); |
| 307 } |
| 308 |
| 275 HandleSignalsState Dispatcher::GetHandleSignalsState() const { | 309 HandleSignalsState Dispatcher::GetHandleSignalsState() const { |
| 276 MutexLocker locker(&mutex_); | 310 MutexLocker locker(&mutex_); |
| 277 if (is_closed_) | 311 if (is_closed_) |
| 278 return HandleSignalsState(); | 312 return HandleSignalsState(); |
| 279 | 313 |
| 280 return GetHandleSignalsStateImplNoLock(); | 314 return GetHandleSignalsStateImplNoLock(); |
| 281 } | 315 } |
| 282 | 316 |
| 283 MojoResult Dispatcher::AddAwakable(Awakable* awakable, | 317 MojoResult Dispatcher::AddAwakable(Awakable* awakable, |
| 284 MojoHandleSignals signals, | 318 MojoHandleSignals signals, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 mutex_.AssertHeld(); | 392 mutex_.AssertHeld(); |
| 359 DCHECK(!is_closed_); | 393 DCHECK(!is_closed_); |
| 360 // By default, not supported. Only needed for message pipe dispatchers. | 394 // By default, not supported. Only needed for message pipe dispatchers. |
| 361 return MOJO_RESULT_INVALID_ARGUMENT; | 395 return MOJO_RESULT_INVALID_ARGUMENT; |
| 362 } | 396 } |
| 363 | 397 |
| 364 MojoResult Dispatcher::SetDataPipeProducerOptionsImplNoLock( | 398 MojoResult Dispatcher::SetDataPipeProducerOptionsImplNoLock( |
| 365 UserPointer<const MojoDataPipeProducerOptions> /*options*/) { | 399 UserPointer<const MojoDataPipeProducerOptions> /*options*/) { |
| 366 mutex_.AssertHeld(); | 400 mutex_.AssertHeld(); |
| 367 DCHECK(!is_closed_); | 401 DCHECK(!is_closed_); |
| 402 // By default, not supported. Only needed for data pipe producer dispatchers. |
| 368 return MOJO_RESULT_INVALID_ARGUMENT; | 403 return MOJO_RESULT_INVALID_ARGUMENT; |
| 369 } | 404 } |
| 370 | 405 |
| 371 MojoResult Dispatcher::GetDataPipeProducerOptionsImplNoLock( | 406 MojoResult Dispatcher::GetDataPipeProducerOptionsImplNoLock( |
| 372 UserPointer<MojoDataPipeProducerOptions> /*options*/, | 407 UserPointer<MojoDataPipeProducerOptions> /*options*/, |
| 373 uint32_t /*options_num_bytes*/) { | 408 uint32_t /*options_num_bytes*/) { |
| 374 mutex_.AssertHeld(); | 409 mutex_.AssertHeld(); |
| 375 DCHECK(!is_closed_); | 410 DCHECK(!is_closed_); |
| 411 // By default, not supported. Only needed for data pipe producer dispatchers. |
| 376 return MOJO_RESULT_INVALID_ARGUMENT; | 412 return MOJO_RESULT_INVALID_ARGUMENT; |
| 377 } | 413 } |
| 378 | 414 |
| 379 MojoResult Dispatcher::WriteDataImplNoLock(UserPointer<const void> /*elements*/, | 415 MojoResult Dispatcher::WriteDataImplNoLock(UserPointer<const void> /*elements*/, |
| 380 UserPointer<uint32_t> /*num_bytes*/, | 416 UserPointer<uint32_t> /*num_bytes*/, |
| 381 MojoWriteDataFlags /*flags*/) { | 417 MojoWriteDataFlags /*flags*/) { |
| 382 mutex_.AssertHeld(); | 418 mutex_.AssertHeld(); |
| 383 DCHECK(!is_closed_); | 419 DCHECK(!is_closed_); |
| 384 // By default, not supported. Only needed for data pipe dispatchers. | 420 // By default, not supported. Only needed for data pipe producer dispatchers. |
| 385 return MOJO_RESULT_INVALID_ARGUMENT; | 421 return MOJO_RESULT_INVALID_ARGUMENT; |
| 386 } | 422 } |
| 387 | 423 |
| 388 MojoResult Dispatcher::BeginWriteDataImplNoLock( | 424 MojoResult Dispatcher::BeginWriteDataImplNoLock( |
| 389 UserPointer<void*> /*buffer*/, | 425 UserPointer<void*> /*buffer*/, |
| 390 UserPointer<uint32_t> /*buffer_num_bytes*/, | 426 UserPointer<uint32_t> /*buffer_num_bytes*/, |
| 391 MojoWriteDataFlags /*flags*/) { | 427 MojoWriteDataFlags /*flags*/) { |
| 392 mutex_.AssertHeld(); | 428 mutex_.AssertHeld(); |
| 393 DCHECK(!is_closed_); | 429 DCHECK(!is_closed_); |
| 394 // By default, not supported. Only needed for data pipe dispatchers. | 430 // By default, not supported. Only needed for data pipe producer dispatchers. |
| 395 return MOJO_RESULT_INVALID_ARGUMENT; | 431 return MOJO_RESULT_INVALID_ARGUMENT; |
| 396 } | 432 } |
| 397 | 433 |
| 398 MojoResult Dispatcher::EndWriteDataImplNoLock(uint32_t /*num_bytes_written*/) { | 434 MojoResult Dispatcher::EndWriteDataImplNoLock(uint32_t /*num_bytes_written*/) { |
| 399 mutex_.AssertHeld(); | 435 mutex_.AssertHeld(); |
| 400 DCHECK(!is_closed_); | 436 DCHECK(!is_closed_); |
| 401 // By default, not supported. Only needed for data pipe dispatchers. | 437 // By default, not supported. Only needed for data pipe producer dispatchers. |
| 402 return MOJO_RESULT_INVALID_ARGUMENT; | 438 return MOJO_RESULT_INVALID_ARGUMENT; |
| 403 } | 439 } |
| 404 | 440 |
| 405 MojoResult Dispatcher::ReadDataImplNoLock(UserPointer<void> /*elements*/, | |
| 406 UserPointer<uint32_t> /*num_bytes*/, | |
| 407 MojoReadDataFlags /*flags*/) { | |
| 408 mutex_.AssertHeld(); | |
| 409 DCHECK(!is_closed_); | |
| 410 // By default, not supported. Only needed for data pipe dispatchers. | |
| 411 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 412 } | |
| 413 | |
| 414 MojoResult Dispatcher::SetDataPipeConsumerOptionsImplNoLock( | 441 MojoResult Dispatcher::SetDataPipeConsumerOptionsImplNoLock( |
| 415 UserPointer<const MojoDataPipeConsumerOptions> /*options*/) { | 442 UserPointer<const MojoDataPipeConsumerOptions> /*options*/) { |
| 416 mutex_.AssertHeld(); | 443 mutex_.AssertHeld(); |
| 417 DCHECK(!is_closed_); | 444 DCHECK(!is_closed_); |
| 445 // By default, not supported. Only needed for data pipe consumer dispatchers. |
| 418 return MOJO_RESULT_INVALID_ARGUMENT; | 446 return MOJO_RESULT_INVALID_ARGUMENT; |
| 419 } | 447 } |
| 420 | 448 |
| 421 MojoResult Dispatcher::GetDataPipeConsumerOptionsImplNoLock( | 449 MojoResult Dispatcher::GetDataPipeConsumerOptionsImplNoLock( |
| 422 UserPointer<MojoDataPipeConsumerOptions> /*options*/, | 450 UserPointer<MojoDataPipeConsumerOptions> /*options*/, |
| 423 uint32_t /*options_num_bytes*/) { | 451 uint32_t /*options_num_bytes*/) { |
| 424 mutex_.AssertHeld(); | 452 mutex_.AssertHeld(); |
| 425 DCHECK(!is_closed_); | 453 DCHECK(!is_closed_); |
| 454 // By default, not supported. Only needed for data pipe consumer dispatchers. |
| 426 return MOJO_RESULT_INVALID_ARGUMENT; | 455 return MOJO_RESULT_INVALID_ARGUMENT; |
| 427 } | 456 } |
| 428 | 457 |
| 458 MojoResult Dispatcher::ReadDataImplNoLock(UserPointer<void> /*elements*/, |
| 459 UserPointer<uint32_t> /*num_bytes*/, |
| 460 MojoReadDataFlags /*flags*/) { |
| 461 mutex_.AssertHeld(); |
| 462 DCHECK(!is_closed_); |
| 463 // By default, not supported. Only needed for data pipe consumer dispatchers. |
| 464 return MOJO_RESULT_INVALID_ARGUMENT; |
| 465 } |
| 466 |
| 429 MojoResult Dispatcher::BeginReadDataImplNoLock( | 467 MojoResult Dispatcher::BeginReadDataImplNoLock( |
| 430 UserPointer<const void*> /*buffer*/, | 468 UserPointer<const void*> /*buffer*/, |
| 431 UserPointer<uint32_t> /*buffer_num_bytes*/, | 469 UserPointer<uint32_t> /*buffer_num_bytes*/, |
| 432 MojoReadDataFlags /*flags*/) { | 470 MojoReadDataFlags /*flags*/) { |
| 433 mutex_.AssertHeld(); | 471 mutex_.AssertHeld(); |
| 434 DCHECK(!is_closed_); | 472 DCHECK(!is_closed_); |
| 435 // By default, not supported. Only needed for data pipe dispatchers. | 473 // By default, not supported. Only needed for data pipe consumer dispatchers. |
| 436 return MOJO_RESULT_INVALID_ARGUMENT; | 474 return MOJO_RESULT_INVALID_ARGUMENT; |
| 437 } | 475 } |
| 438 | 476 |
| 439 MojoResult Dispatcher::EndReadDataImplNoLock(uint32_t /*num_bytes_read*/) { | 477 MojoResult Dispatcher::EndReadDataImplNoLock(uint32_t /*num_bytes_read*/) { |
| 440 mutex_.AssertHeld(); | 478 mutex_.AssertHeld(); |
| 441 DCHECK(!is_closed_); | 479 DCHECK(!is_closed_); |
| 442 // By default, not supported. Only needed for data pipe dispatchers. | 480 // By default, not supported. Only needed for data pipe consumer dispatchers. |
| 443 return MOJO_RESULT_INVALID_ARGUMENT; | 481 return MOJO_RESULT_INVALID_ARGUMENT; |
| 444 } | 482 } |
| 445 | 483 |
| 446 MojoResult Dispatcher::DuplicateBufferHandleImplNoLock( | 484 MojoResult Dispatcher::DuplicateBufferHandleImplNoLock( |
| 447 UserPointer<const MojoDuplicateBufferHandleOptions> /*options*/, | 485 UserPointer<const MojoDuplicateBufferHandleOptions> /*options*/, |
| 448 RefPtr<Dispatcher>* /*new_dispatcher*/) { | 486 RefPtr<Dispatcher>* /*new_dispatcher*/) { |
| 449 mutex_.AssertHeld(); | 487 mutex_.AssertHeld(); |
| 450 DCHECK(!is_closed_); | 488 DCHECK(!is_closed_); |
| 451 // By default, not supported. Only needed for buffer dispatchers. | 489 // By default, not supported. Only needed for buffer dispatchers. |
| 452 return MOJO_RESULT_INVALID_ARGUMENT; | 490 return MOJO_RESULT_INVALID_ARGUMENT; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 465 uint64_t /*offset*/, | 503 uint64_t /*offset*/, |
| 466 uint64_t /*num_bytes*/, | 504 uint64_t /*num_bytes*/, |
| 467 MojoMapBufferFlags /*flags*/, | 505 MojoMapBufferFlags /*flags*/, |
| 468 std::unique_ptr<PlatformSharedBufferMapping>* /*mapping*/) { | 506 std::unique_ptr<PlatformSharedBufferMapping>* /*mapping*/) { |
| 469 mutex_.AssertHeld(); | 507 mutex_.AssertHeld(); |
| 470 DCHECK(!is_closed_); | 508 DCHECK(!is_closed_); |
| 471 // By default, not supported. Only needed for buffer dispatchers. | 509 // By default, not supported. Only needed for buffer dispatchers. |
| 472 return MOJO_RESULT_INVALID_ARGUMENT; | 510 return MOJO_RESULT_INVALID_ARGUMENT; |
| 473 } | 511 } |
| 474 | 512 |
| 513 MojoResult Dispatcher::WaitSetAddImplNoLock( |
| 514 UserPointer<const MojoWaitSetAddOptions> /*options*/, |
| 515 Handle&& /*handle*/, |
| 516 MojoHandleSignals /*signals*/, |
| 517 uint64_t /*cookie*/) { |
| 518 mutex_.AssertHeld(); |
| 519 DCHECK(!is_closed_); |
| 520 // By default, not supported. Only needed for wait set dispatchers. |
| 521 return MOJO_RESULT_INVALID_ARGUMENT; |
| 522 } |
| 523 |
| 524 MojoResult Dispatcher::WaitSetRemoveImplNoLock(uint64_t /*cookie*/) { |
| 525 mutex_.AssertHeld(); |
| 526 DCHECK(!is_closed_); |
| 527 // By default, not supported. Only needed for wait set dispatchers. |
| 528 return MOJO_RESULT_INVALID_ARGUMENT; |
| 529 } |
| 530 |
| 531 MojoResult Dispatcher::WaitSetWaitImpl( |
| 532 MojoDeadline /*deadline*/, |
| 533 UserPointer<uint32_t> /*num_results*/, |
| 534 UserPointer<MojoWaitSetResult> /*results*/, |
| 535 UserPointer<uint32_t> /*max_results*/) { |
| 536 // Note that this is *not* called under |mutex_| and |is_closed_| hasn't been |
| 537 // checked. But since we'll return |MOJO_RESULT_INVALID_ARGUMENT| in either |
| 538 // case (by default, this is not supported: it's only needed for wait set |
| 539 // dispatchers), we don't need to lock |mutex_| and check |is_closed_|. |
| 540 return MOJO_RESULT_INVALID_ARGUMENT; |
| 541 } |
| 542 |
| 475 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { | 543 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { |
| 476 mutex_.AssertHeld(); | 544 mutex_.AssertHeld(); |
| 477 DCHECK(!is_closed_); | 545 DCHECK(!is_closed_); |
| 478 // By default, waiting isn't supported. Only dispatchers that can be waited on | 546 // By default, waiting isn't supported. Only dispatchers that can be waited on |
| 479 // will do something nontrivial. | 547 // will do something nontrivial. |
| 480 return HandleSignalsState(); | 548 return HandleSignalsState(); |
| 481 } | 549 } |
| 482 | 550 |
| 483 MojoResult Dispatcher::AddAwakableImplNoLock( | 551 MojoResult Dispatcher::AddAwakableImplNoLock( |
| 484 Awakable* /*awakable*/, | 552 Awakable* /*awakable*/, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // want to remove or weaken). | 644 // want to remove or weaken). |
| 577 MutexLocker locker(&mutex_); | 645 MutexLocker locker(&mutex_); |
| 578 #endif | 646 #endif |
| 579 | 647 |
| 580 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, | 648 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, |
| 581 platform_handles); | 649 platform_handles); |
| 582 } | 650 } |
| 583 | 651 |
| 584 } // namespace system | 652 } // namespace system |
| 585 } // namespace mojo | 653 } // namespace mojo |
| OLD | NEW |