| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 UserPointer<MojoHandleRights> rights) { | 179 UserPointer<MojoHandleRights> rights) { |
| 180 Handle h; | 180 Handle h; |
| 181 MojoResult result = GetHandle(handle, &h); | 181 MojoResult result = GetHandle(handle, &h); |
| 182 if (result != MOJO_RESULT_OK) | 182 if (result != MOJO_RESULT_OK) |
| 183 return result; | 183 return result; |
| 184 | 184 |
| 185 rights.Put(h.rights); | 185 rights.Put(h.rights); |
| 186 return MOJO_RESULT_OK; | 186 return MOJO_RESULT_OK; |
| 187 } | 187 } |
| 188 | 188 |
| 189 MojoResult Core::DuplicateHandleWithReducedRights( |
| 190 MojoHandle handle, |
| 191 MojoHandleRights rights_to_remove, |
| 192 UserPointer<MojoHandle> new_handle) { |
| 193 Handle h; |
| 194 MojoResult result = GetHandle(handle, &h); |
| 195 if (result != MOJO_RESULT_OK) |
| 196 return result; |
| 197 |
| 198 if (!h.has_all_rights(MOJO_HANDLE_RIGHT_DUPLICATE)) |
| 199 return MOJO_RESULT_PERMISSION_DENIED; |
| 200 |
| 201 RefPtr<Dispatcher> new_dispatcher; |
| 202 result = h.dispatcher->DuplicateDispatcher(&new_dispatcher); |
| 203 if (result != MOJO_RESULT_OK) |
| 204 return result; |
| 205 |
| 206 MojoHandle new_handle_value = |
| 207 AddHandle(Handle(new_dispatcher.Clone(), h.rights & ~rights_to_remove)); |
| 208 if (new_handle_value == MOJO_HANDLE_INVALID) { |
| 209 LOG(ERROR) << "Handle table full"; |
| 210 new_dispatcher->Close(); |
| 211 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 212 } |
| 213 |
| 214 new_handle.Put(new_handle_value); |
| 215 return MOJO_RESULT_OK; |
| 216 } |
| 217 |
| 189 MojoResult Core::Wait(MojoHandle handle, | 218 MojoResult Core::Wait(MojoHandle handle, |
| 190 MojoHandleSignals signals, | 219 MojoHandleSignals signals, |
| 191 MojoDeadline deadline, | 220 MojoDeadline deadline, |
| 192 UserPointer<MojoHandleSignalsState> signals_state) { | 221 UserPointer<MojoHandleSignalsState> signals_state) { |
| 193 uint32_t unused = static_cast<uint32_t>(-1); | 222 uint32_t unused = static_cast<uint32_t>(-1); |
| 194 HandleSignalsState hss; | 223 HandleSignalsState hss; |
| 195 MojoResult result = WaitManyInternal(&handle, &signals, 1, deadline, &unused, | 224 MojoResult result = WaitManyInternal(&handle, &signals, 1, deadline, &unused, |
| 196 signals_state.IsNull() ? nullptr : &hss); | 225 signals_state.IsNull() ? nullptr : &hss); |
| 197 if (result != MOJO_RESULT_INVALID_ARGUMENT && !signals_state.IsNull()) | 226 if (result != MOJO_RESULT_INVALID_ARGUMENT && !signals_state.IsNull()) |
| 198 signals_state.Put(hss); | 227 signals_state.Put(hss); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 if (result != MOJO_RESULT_OK) | 620 if (result != MOJO_RESULT_OK) |
| 592 return result; | 621 return result; |
| 593 | 622 |
| 594 auto dispatcher = SharedBufferDispatcher::Create( | 623 auto dispatcher = SharedBufferDispatcher::Create( |
| 595 platform_support_, validated_options, num_bytes, &result); | 624 platform_support_, validated_options, num_bytes, &result); |
| 596 if (result != MOJO_RESULT_OK) { | 625 if (result != MOJO_RESULT_OK) { |
| 597 DCHECK(!dispatcher); | 626 DCHECK(!dispatcher); |
| 598 return result; | 627 return result; |
| 599 } | 628 } |
| 600 | 629 |
| 601 MojoHandle h = AddHandle( | 630 MojoHandle handle = AddHandle( |
| 602 Handle(dispatcher.Clone(), SharedBufferDispatcher::kDefaultHandleRights)); | 631 Handle(dispatcher.Clone(), SharedBufferDispatcher::kDefaultHandleRights)); |
| 603 if (h == MOJO_HANDLE_INVALID) { | 632 if (handle == MOJO_HANDLE_INVALID) { |
| 604 LOG(ERROR) << "Handle table full"; | 633 LOG(ERROR) << "Handle table full"; |
| 605 dispatcher->Close(); | 634 dispatcher->Close(); |
| 606 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 635 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 607 } | 636 } |
| 608 | 637 |
| 609 shared_buffer_handle.Put(h); | 638 shared_buffer_handle.Put(handle); |
| 610 return MOJO_RESULT_OK; | 639 return MOJO_RESULT_OK; |
| 611 } | 640 } |
| 612 | 641 |
| 613 MojoResult Core::DuplicateBufferHandle( | 642 MojoResult Core::DuplicateBufferHandle( |
| 614 MojoHandle buffer_handle, | 643 MojoHandle buffer_handle, |
| 615 UserPointer<const MojoDuplicateBufferHandleOptions> options, | 644 UserPointer<const MojoDuplicateBufferHandleOptions> options, |
| 616 UserPointer<MojoHandle> new_buffer_handle) { | 645 UserPointer<MojoHandle> new_buffer_handle) { |
| 617 // TODO(vtl): This is a big ugly and duplicates some code, but the plan is to | 646 // TODO(vtl): This is a big ugly and duplicates some code, but the plan is to |
| 618 // remove this method anyway. | 647 // remove this method anyway. |
| 619 Handle h; | 648 Handle h; |
| 620 MojoResult result = GetHandle(buffer_handle, &h); | 649 MojoResult result = GetHandle(buffer_handle, &h); |
| 621 if (result != MOJO_RESULT_OK) | 650 if (result != MOJO_RESULT_OK) |
| 622 return result; | 651 return result; |
| 623 | 652 |
| 624 if (!h.has_all_rights(MOJO_HANDLE_RIGHT_DUPLICATE)) { | 653 if (!h.has_all_rights(MOJO_HANDLE_RIGHT_DUPLICATE)) { |
| 625 return h.dispatcher->SupportsEntrypointClass(EntrypointClass::BUFFER) | 654 return h.dispatcher->SupportsEntrypointClass(EntrypointClass::BUFFER) |
| 626 ? MOJO_RESULT_PERMISSION_DENIED | 655 ? MOJO_RESULT_PERMISSION_DENIED |
| 627 : MOJO_RESULT_INVALID_ARGUMENT; | 656 : MOJO_RESULT_INVALID_ARGUMENT; |
| 628 } | 657 } |
| 629 | 658 |
| 630 // Don't verify |options| here; that's the dispatcher's job. | 659 // Don't verify |options| here; that's the dispatcher's job. |
| 631 RefPtr<Dispatcher> new_dispatcher; | 660 RefPtr<Dispatcher> new_dispatcher; |
| 632 result = h.dispatcher->DuplicateBufferHandle(options, &new_dispatcher); | 661 result = h.dispatcher->DuplicateBufferHandle(options, &new_dispatcher); |
| 633 if (result != MOJO_RESULT_OK) | 662 if (result != MOJO_RESULT_OK) |
| 634 return result; | 663 return result; |
| 635 | 664 |
| 636 MojoHandle new_handle = AddHandle(Handle(new_dispatcher.Clone(), h.rights)); | 665 MojoHandle new_handle_value = |
| 637 if (new_handle == MOJO_HANDLE_INVALID) { | 666 AddHandle(Handle(new_dispatcher.Clone(), h.rights)); |
| 667 if (new_handle_value == MOJO_HANDLE_INVALID) { |
| 638 LOG(ERROR) << "Handle table full"; | 668 LOG(ERROR) << "Handle table full"; |
| 639 new_dispatcher->Close(); | 669 new_dispatcher->Close(); |
| 640 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 670 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 641 } | 671 } |
| 642 | 672 |
| 643 new_buffer_handle.Put(new_handle); | 673 new_buffer_handle.Put(new_handle_value); |
| 644 return MOJO_RESULT_OK; | 674 return MOJO_RESULT_OK; |
| 645 } | 675 } |
| 646 | 676 |
| 647 MojoResult Core::GetBufferInformation(MojoHandle buffer_handle, | 677 MojoResult Core::GetBufferInformation(MojoHandle buffer_handle, |
| 648 UserPointer<MojoBufferInformation> info, | 678 UserPointer<MojoBufferInformation> info, |
| 649 uint32_t info_num_bytes) { | 679 uint32_t info_num_bytes) { |
| 650 RefPtr<Dispatcher> dispatcher; | 680 RefPtr<Dispatcher> dispatcher; |
| 651 MojoResult result = | 681 MojoResult result = |
| 652 GetDispatcherAndCheckRights(buffer_handle, MOJO_HANDLE_RIGHT_GET_OPTIONS, | 682 GetDispatcherAndCheckRights(buffer_handle, MOJO_HANDLE_RIGHT_GET_OPTIONS, |
| 653 EntrypointClass::BUFFER, &dispatcher); | 683 EntrypointClass::BUFFER, &dispatcher); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 if (signals_states) { | 791 if (signals_states) { |
| 762 for (; i < num_handles; i++) | 792 for (; i < num_handles; i++) |
| 763 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 793 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
| 764 } | 794 } |
| 765 | 795 |
| 766 return result; | 796 return result; |
| 767 } | 797 } |
| 768 | 798 |
| 769 } // namespace system | 799 } // namespace system |
| 770 } // namespace mojo | 800 } // namespace mojo |
| OLD | NEW |