| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "mojo/edk/embedder/embedder_internal.h" | 6 #include "mojo/edk/embedder/embedder_internal.h" |
| 7 #include "mojo/edk/system/core.h" | 7 #include "mojo/edk/system/core.h" |
| 8 #include "mojo/edk/system/dispatcher.h" | 8 #include "mojo/edk/system/dispatcher.h" |
| 9 #include "mojo/edk/system/handle.h" |
| 9 #include "mojo/edk/util/ref_ptr.h" | 10 #include "mojo/edk/util/ref_ptr.h" |
| 10 #include "mojo/public/c/system/buffer.h" | 11 #include "mojo/public/c/system/buffer.h" |
| 11 #include "mojo/public/c/system/data_pipe.h" | 12 #include "mojo/public/c/system/data_pipe.h" |
| 12 #include "mojo/public/c/system/handle.h" | 13 #include "mojo/public/c/system/handle.h" |
| 13 #include "mojo/public/c/system/message_pipe.h" | 14 #include "mojo/public/c/system/message_pipe.h" |
| 14 #include "mojo/public/c/system/result.h" | 15 #include "mojo/public/c/system/result.h" |
| 15 #include "mojo/public/c/system/time.h" | 16 #include "mojo/public/c/system/time.h" |
| 16 #include "mojo/public/c/system/wait.h" | 17 #include "mojo/public/c/system/wait.h" |
| 17 #include "mojo/public/platform/native/system_impl_private.h" | 18 #include "mojo/public/platform/native/system_impl_private.h" |
| 18 | 19 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 return MOJO_RESULT_INVALID_ARGUMENT; | 53 return MOJO_RESULT_INVALID_ARGUMENT; |
| 53 | 54 |
| 54 if (result_handle == nullptr) | 55 if (result_handle == nullptr) |
| 55 return MOJO_RESULT_INVALID_ARGUMENT; | 56 return MOJO_RESULT_INVALID_ARGUMENT; |
| 56 | 57 |
| 57 RefPtr<Dispatcher> d; | 58 RefPtr<Dispatcher> d; |
| 58 MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); | 59 MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); |
| 59 if (result != MOJO_RESULT_OK) | 60 if (result != MOJO_RESULT_OK) |
| 60 return result; | 61 return result; |
| 61 | 62 |
| 62 MojoHandle created_handle = to_core->AddDispatcher(d.get()); | 63 // TODO(vtl): The rights should come from the original handle (to be dealt |
| 64 // with when I fix/replace |Core::GetAndRemoveDispatcher()|. |
| 65 MojoHandle created_handle = to_core->AddHandle(mojo::system::Handle( |
| 66 d.Clone(), MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ | |
| 67 MOJO_HANDLE_RIGHT_WRITE)); |
| 63 if (created_handle == MOJO_HANDLE_INVALID) { | 68 if (created_handle == MOJO_HANDLE_INVALID) { |
| 64 // The handle has been lost, unfortunately. There's no guarentee we can put | 69 // The handle has been lost, unfortunately. There's no guarentee we can put |
| 65 // it back where it came from, or get the original ID back. Holding locks | 70 // it back where it came from, or get the original ID back. Holding locks |
| 66 // for multiple cores risks deadlock, so that isn't a solution. This case | 71 // for multiple cores risks deadlock, so that isn't a solution. This case |
| 67 // should not happen for reasonable uses of this API, however. | 72 // should not happen for reasonable uses of this API, however. |
| 68 LOG(ERROR) << "Could not transfer handle"; | 73 LOG(ERROR) << "Could not transfer handle"; |
| 69 d->Close(); | 74 d->Close(); |
| 70 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 75 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 71 } | 76 } |
| 72 | 77 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 MakeUserPointer(buffer), flags); | 314 MakeUserPointer(buffer), flags); |
| 310 } | 315 } |
| 311 | 316 |
| 312 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { | 317 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { |
| 313 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 318 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); |
| 314 DCHECK(core); | 319 DCHECK(core); |
| 315 return core->UnmapBuffer(MakeUserPointer(buffer)); | 320 return core->UnmapBuffer(MakeUserPointer(buffer)); |
| 316 } | 321 } |
| 317 | 322 |
| 318 } // extern "C" | 323 } // extern "C" |
| OLD | NEW |