OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/entrypoints.h" | 5 #include "mojo/edk/embedder/embedder_internal.h" |
6 | |
7 #include "base/logging.h" | |
8 #include "mojo/edk/system/core.h" | 6 #include "mojo/edk/system/core.h" |
9 #include "mojo/public/c/system/buffer.h" | 7 #include "mojo/public/c/system/buffer.h" |
10 #include "mojo/public/c/system/data_pipe.h" | 8 #include "mojo/public/c/system/data_pipe.h" |
11 #include "mojo/public/c/system/functions.h" | 9 #include "mojo/public/c/system/functions.h" |
12 #include "mojo/public/c/system/message_pipe.h" | 10 #include "mojo/public/c/system/message_pipe.h" |
13 | 11 |
14 static mojo::system::Core* g_core = nullptr; | 12 using mojo::embedder::internal::g_core; |
15 | |
16 using mojo::system::MakeUserPointer; | 13 using mojo::system::MakeUserPointer; |
17 | 14 |
18 namespace mojo { | |
19 namespace system { | |
20 namespace entrypoints { | |
21 | |
22 void SetCore(Core* core) { | |
23 g_core = core; | |
24 } | |
25 | |
26 Core* GetCore() { | |
27 return g_core; | |
28 } | |
29 | |
30 } // namespace entrypoints | |
31 } // namepace system | |
32 } // namespace mojo | |
33 | |
34 // Definitions of the system functions. | 15 // Definitions of the system functions. |
35 extern "C" { | 16 extern "C" { |
36 MojoTimeTicks MojoGetTimeTicksNow() { | 17 MojoTimeTicks MojoGetTimeTicksNow() { |
37 return g_core->GetTimeTicksNow(); | 18 return g_core->GetTimeTicksNow(); |
38 } | 19 } |
39 | 20 |
40 MojoResult MojoClose(MojoHandle handle) { | 21 MojoResult MojoClose(MojoHandle handle) { |
41 return g_core->Close(handle); | 22 return g_core->Close(handle); |
42 } | 23 } |
43 | 24 |
44 MojoResult MojoWait(MojoHandle handle, | 25 MojoResult MojoWait(MojoHandle handle, |
45 MojoHandleSignals signals, | 26 MojoHandleSignals signals, |
46 MojoDeadline deadline) { | 27 MojoDeadline deadline) { |
47 return g_core->Wait( | 28 return g_core->Wait(handle, signals, deadline, |
48 handle, signals, deadline, mojo::system::NullUserPointer()); | 29 mojo::system::NullUserPointer()); |
49 } | 30 } |
50 | 31 |
51 MojoResult MojoWaitMany(const MojoHandle* handles, | 32 MojoResult MojoWaitMany(const MojoHandle* handles, |
52 const MojoHandleSignals* signals, | 33 const MojoHandleSignals* signals, |
53 uint32_t num_handles, | 34 uint32_t num_handles, |
54 MojoDeadline deadline) { | 35 MojoDeadline deadline) { |
55 uint32_t result_index = static_cast<uint32_t>(-1); | 36 uint32_t result_index = static_cast<uint32_t>(-1); |
56 MojoResult result = g_core->WaitMany(MakeUserPointer(handles), | 37 MojoResult result = g_core->WaitMany( |
57 MakeUserPointer(signals), | 38 MakeUserPointer(handles), MakeUserPointer(signals), num_handles, deadline, |
58 num_handles, | 39 MakeUserPointer(&result_index), mojo::system::NullUserPointer()); |
59 deadline, | |
60 MakeUserPointer(&result_index), | |
61 mojo::system::NullUserPointer()); | |
62 return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index) | 40 return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index) |
63 : result; | 41 : result; |
64 } | 42 } |
65 | 43 |
66 MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options, | 44 MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options, |
67 MojoHandle* message_pipe_handle0, | 45 MojoHandle* message_pipe_handle0, |
68 MojoHandle* message_pipe_handle1) { | 46 MojoHandle* message_pipe_handle1) { |
69 return g_core->CreateMessagePipe(MakeUserPointer(options), | 47 return g_core->CreateMessagePipe(MakeUserPointer(options), |
70 MakeUserPointer(message_pipe_handle0), | 48 MakeUserPointer(message_pipe_handle0), |
71 MakeUserPointer(message_pipe_handle1)); | 49 MakeUserPointer(message_pipe_handle1)); |
72 } | 50 } |
73 | 51 |
74 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, | 52 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, |
75 const void* bytes, | 53 const void* bytes, |
76 uint32_t num_bytes, | 54 uint32_t num_bytes, |
77 const MojoHandle* handles, | 55 const MojoHandle* handles, |
78 uint32_t num_handles, | 56 uint32_t num_handles, |
79 MojoWriteMessageFlags flags) { | 57 MojoWriteMessageFlags flags) { |
80 return g_core->WriteMessage(message_pipe_handle, | 58 return g_core->WriteMessage(message_pipe_handle, MakeUserPointer(bytes), |
81 MakeUserPointer(bytes), | 59 num_bytes, MakeUserPointer(handles), num_handles, |
82 num_bytes, | |
83 MakeUserPointer(handles), | |
84 num_handles, | |
85 flags); | 60 flags); |
86 } | 61 } |
87 | 62 |
88 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | 63 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, |
89 void* bytes, | 64 void* bytes, |
90 uint32_t* num_bytes, | 65 uint32_t* num_bytes, |
91 MojoHandle* handles, | 66 MojoHandle* handles, |
92 uint32_t* num_handles, | 67 uint32_t* num_handles, |
93 MojoReadMessageFlags flags) { | 68 MojoReadMessageFlags flags) { |
94 return g_core->ReadMessage(message_pipe_handle, | 69 return g_core->ReadMessage( |
95 MakeUserPointer(bytes), | 70 message_pipe_handle, MakeUserPointer(bytes), MakeUserPointer(num_bytes), |
96 MakeUserPointer(num_bytes), | 71 MakeUserPointer(handles), MakeUserPointer(num_handles), flags); |
97 MakeUserPointer(handles), | |
98 MakeUserPointer(num_handles), | |
99 flags); | |
100 } | 72 } |
101 | 73 |
102 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options, | 74 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options, |
103 MojoHandle* data_pipe_producer_handle, | 75 MojoHandle* data_pipe_producer_handle, |
104 MojoHandle* data_pipe_consumer_handle) { | 76 MojoHandle* data_pipe_consumer_handle) { |
105 return g_core->CreateDataPipe(MakeUserPointer(options), | 77 return g_core->CreateDataPipe(MakeUserPointer(options), |
106 MakeUserPointer(data_pipe_producer_handle), | 78 MakeUserPointer(data_pipe_producer_handle), |
107 MakeUserPointer(data_pipe_consumer_handle)); | 79 MakeUserPointer(data_pipe_consumer_handle)); |
108 } | 80 } |
109 | 81 |
110 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, | 82 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, |
111 const void* elements, | 83 const void* elements, |
112 uint32_t* num_elements, | 84 uint32_t* num_elements, |
113 MojoWriteDataFlags flags) { | 85 MojoWriteDataFlags flags) { |
114 return g_core->WriteData(data_pipe_producer_handle, | 86 return g_core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements), |
115 MakeUserPointer(elements), | 87 MakeUserPointer(num_elements), flags); |
116 MakeUserPointer(num_elements), | |
117 flags); | |
118 } | 88 } |
119 | 89 |
120 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, | 90 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, |
121 void** buffer, | 91 void** buffer, |
122 uint32_t* buffer_num_elements, | 92 uint32_t* buffer_num_elements, |
123 MojoWriteDataFlags flags) { | 93 MojoWriteDataFlags flags) { |
124 return g_core->BeginWriteData(data_pipe_producer_handle, | 94 return g_core->BeginWriteData(data_pipe_producer_handle, |
125 MakeUserPointer(buffer), | 95 MakeUserPointer(buffer), |
126 MakeUserPointer(buffer_num_elements), | 96 MakeUserPointer(buffer_num_elements), flags); |
127 flags); | |
128 } | 97 } |
129 | 98 |
130 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, | 99 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, |
131 uint32_t num_elements_written) { | 100 uint32_t num_elements_written) { |
132 return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written); | 101 return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written); |
133 } | 102 } |
134 | 103 |
135 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, | 104 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, |
136 void* elements, | 105 void* elements, |
137 uint32_t* num_elements, | 106 uint32_t* num_elements, |
138 MojoReadDataFlags flags) { | 107 MojoReadDataFlags flags) { |
139 return g_core->ReadData(data_pipe_consumer_handle, | 108 return g_core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements), |
140 MakeUserPointer(elements), | 109 MakeUserPointer(num_elements), flags); |
141 MakeUserPointer(num_elements), | |
142 flags); | |
143 } | 110 } |
144 | 111 |
145 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, | 112 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, |
146 const void** buffer, | 113 const void** buffer, |
147 uint32_t* buffer_num_elements, | 114 uint32_t* buffer_num_elements, |
148 MojoReadDataFlags flags) { | 115 MojoReadDataFlags flags) { |
149 return g_core->BeginReadData(data_pipe_consumer_handle, | 116 return g_core->BeginReadData(data_pipe_consumer_handle, |
150 MakeUserPointer(buffer), | 117 MakeUserPointer(buffer), |
151 MakeUserPointer(buffer_num_elements), | 118 MakeUserPointer(buffer_num_elements), flags); |
152 flags); | |
153 } | 119 } |
154 | 120 |
155 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, | 121 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, |
156 uint32_t num_elements_read) { | 122 uint32_t num_elements_read) { |
157 return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read); | 123 return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read); |
158 } | 124 } |
159 | 125 |
160 MojoResult MojoCreateSharedBuffer( | 126 MojoResult MojoCreateSharedBuffer( |
161 const struct MojoCreateSharedBufferOptions* options, | 127 const struct MojoCreateSharedBufferOptions* options, |
162 uint64_t num_bytes, | 128 uint64_t num_bytes, |
163 MojoHandle* shared_buffer_handle) { | 129 MojoHandle* shared_buffer_handle) { |
164 return g_core->CreateSharedBuffer(MakeUserPointer(options), | 130 return g_core->CreateSharedBuffer(MakeUserPointer(options), num_bytes, |
165 num_bytes, | |
166 MakeUserPointer(shared_buffer_handle)); | 131 MakeUserPointer(shared_buffer_handle)); |
167 } | 132 } |
168 | 133 |
169 MojoResult MojoDuplicateBufferHandle( | 134 MojoResult MojoDuplicateBufferHandle( |
170 MojoHandle buffer_handle, | 135 MojoHandle buffer_handle, |
171 const struct MojoDuplicateBufferHandleOptions* options, | 136 const struct MojoDuplicateBufferHandleOptions* options, |
172 MojoHandle* new_buffer_handle) { | 137 MojoHandle* new_buffer_handle) { |
173 return g_core->DuplicateBufferHandle(buffer_handle, | 138 return g_core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options), |
174 MakeUserPointer(options), | |
175 MakeUserPointer(new_buffer_handle)); | 139 MakeUserPointer(new_buffer_handle)); |
176 } | 140 } |
177 | 141 |
178 MojoResult MojoMapBuffer(MojoHandle buffer_handle, | 142 MojoResult MojoMapBuffer(MojoHandle buffer_handle, |
179 uint64_t offset, | 143 uint64_t offset, |
180 uint64_t num_bytes, | 144 uint64_t num_bytes, |
181 void** buffer, | 145 void** buffer, |
182 MojoMapBufferFlags flags) { | 146 MojoMapBufferFlags flags) { |
183 return g_core->MapBuffer( | 147 return g_core->MapBuffer(buffer_handle, offset, num_bytes, |
184 buffer_handle, offset, num_bytes, MakeUserPointer(buffer), flags); | 148 MakeUserPointer(buffer), flags); |
185 } | 149 } |
186 | 150 |
187 MojoResult MojoUnmapBuffer(void* buffer) { | 151 MojoResult MojoUnmapBuffer(void* buffer) { |
188 return g_core->UnmapBuffer(MakeUserPointer(buffer)); | 152 return g_core->UnmapBuffer(MakeUserPointer(buffer)); |
189 } | 153 } |
190 | 154 |
191 } // extern "C" | 155 } // extern "C" |
OLD | NEW |