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/system/handle.h" |
10 #include "mojo/edk/util/ref_ptr.h" | 10 #include "mojo/edk/util/ref_ptr.h" |
11 #include "mojo/public/c/system/buffer.h" | 11 #include "mojo/public/c/system/buffer.h" |
12 #include "mojo/public/c/system/data_pipe.h" | 12 #include "mojo/public/c/system/data_pipe.h" |
13 #include "mojo/public/c/system/handle.h" | 13 #include "mojo/public/c/system/handle.h" |
14 #include "mojo/public/c/system/message_pipe.h" | 14 #include "mojo/public/c/system/message_pipe.h" |
15 #include "mojo/public/c/system/result.h" | 15 #include "mojo/public/c/system/result.h" |
16 #include "mojo/public/c/system/time.h" | 16 #include "mojo/public/c/system/time.h" |
17 #include "mojo/public/c/system/wait.h" | 17 #include "mojo/public/c/system/wait.h" |
18 #include "mojo/public/platform/native/system_impl_private.h" | 18 #include "mojo/public/platform/native/system_impl_private.h" |
19 | 19 |
20 using mojo::embedder::internal::g_core; | 20 using mojo::embedder::internal::g_core; |
21 using mojo::system::Core; | 21 using mojo::system::Core; |
22 using mojo::system::Dispatcher; | 22 using mojo::system::Dispatcher; |
| 23 using mojo::system::Handle; |
23 using mojo::system::MakeUserPointer; | 24 using mojo::system::MakeUserPointer; |
24 using mojo::util::RefPtr; | 25 using mojo::util::RefPtr; |
25 | 26 |
26 // Definitions of the system functions, but with an explicit parameter for the | 27 // Definitions of the system functions, but with an explicit parameter for the |
27 // core object rather than using the default singleton. Also includes functions | 28 // core object rather than using the default singleton. Also includes functions |
28 // for manipulating core objects. | 29 // for manipulating core objects. |
29 extern "C" { | 30 extern "C" { |
30 | 31 |
31 MojoSystemImpl MojoSystemImplGetDefaultImpl() { | 32 MojoSystemImpl MojoSystemImplGetDefaultImpl() { |
32 return static_cast<MojoSystemImpl>(g_core); | 33 return static_cast<MojoSystemImpl>(g_core); |
(...skipping 15 matching lines...) Expand all Loading... |
48 if (handle == MOJO_HANDLE_INVALID) | 49 if (handle == MOJO_HANDLE_INVALID) |
49 return MOJO_RESULT_INVALID_ARGUMENT; | 50 return MOJO_RESULT_INVALID_ARGUMENT; |
50 | 51 |
51 Core* to_core = static_cast<Core*>(to_system); | 52 Core* to_core = static_cast<Core*>(to_system); |
52 if (to_core == nullptr) | 53 if (to_core == nullptr) |
53 return MOJO_RESULT_INVALID_ARGUMENT; | 54 return MOJO_RESULT_INVALID_ARGUMENT; |
54 | 55 |
55 if (result_handle == nullptr) | 56 if (result_handle == nullptr) |
56 return MOJO_RESULT_INVALID_ARGUMENT; | 57 return MOJO_RESULT_INVALID_ARGUMENT; |
57 | 58 |
58 RefPtr<Dispatcher> d; | 59 Handle h; |
59 MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); | 60 MojoResult result = from_core->GetAndRemoveHandle(handle, &h); |
60 if (result != MOJO_RESULT_OK) | 61 if (result != MOJO_RESULT_OK) |
61 return result; | 62 return result; |
62 | 63 |
63 // TODO(vtl): The rights should come from the original handle (to be dealt | 64 MojoHandle created_handle = |
64 // with when I fix/replace |Core::GetAndRemoveDispatcher()|. | 65 to_core->AddHandle(Handle(h.dispatcher.Clone(), h.rights)); |
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)); | |
68 if (created_handle == MOJO_HANDLE_INVALID) { | 66 if (created_handle == MOJO_HANDLE_INVALID) { |
69 // The handle has been lost, unfortunately. There's no guarentee we can put | 67 // The handle has been lost, unfortunately. There's no guarentee we can put |
70 // it back where it came from, or get the original ID back. Holding locks | 68 // it back where it came from, or get the original ID back. Holding locks |
71 // for multiple cores risks deadlock, so that isn't a solution. This case | 69 // for multiple cores risks deadlock, so that isn't a solution. This case |
72 // should not happen for reasonable uses of this API, however. | 70 // should not happen for reasonable uses of this API, however. |
| 71 // TODO(vtl): This behaviour is pretty crappy. This can be fixed by marking |
| 72 // the original handle as busy and only removing it on success, though |
| 73 // that'd require some work. |
73 LOG(ERROR) << "Could not transfer handle"; | 74 LOG(ERROR) << "Could not transfer handle"; |
74 d->Close(); | 75 h.dispatcher->Close(); |
75 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 76 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
76 } | 77 } |
77 | 78 |
78 MakeUserPointer(result_handle).Put(created_handle); | 79 MakeUserPointer(result_handle).Put(created_handle); |
79 return MOJO_RESULT_OK; | 80 return MOJO_RESULT_OK; |
80 } | 81 } |
81 | 82 |
82 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { | 83 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { |
83 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 84 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); |
84 DCHECK(core); | 85 DCHECK(core); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 MakeUserPointer(buffer), flags); | 315 MakeUserPointer(buffer), flags); |
315 } | 316 } |
316 | 317 |
317 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { | 318 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { |
318 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 319 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); |
319 DCHECK(core); | 320 DCHECK(core); |
320 return core->UnmapBuffer(MakeUserPointer(buffer)); | 321 return core->UnmapBuffer(MakeUserPointer(buffer)); |
321 } | 322 } |
322 | 323 |
323 } // extern "C" | 324 } // extern "C" |
OLD | NEW |