• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "mojo/edk/embedder/entrypoints.h"
6 
7 #include <stdint.h>
8 
9 #include "mojo/edk/embedder/embedder_internal.h"
10 #include "mojo/edk/system/core.h"
11 #include "mojo/public/c/system/buffer.h"
12 #include "mojo/public/c/system/data_pipe.h"
13 #include "mojo/public/c/system/functions.h"
14 #include "mojo/public/c/system/message_pipe.h"
15 #include "mojo/public/c/system/platform_handle.h"
16 #include "mojo/public/c/system/wait_set.h"
17 
18 using mojo::edk::internal::g_core;
19 
20 // Definitions of the system functions.
21 extern "C" {
22 
MojoGetTimeTicksNowImpl()23 MojoTimeTicks MojoGetTimeTicksNowImpl() {
24   return g_core->GetTimeTicksNow();
25 }
26 
MojoCloseImpl(MojoHandle handle)27 MojoResult MojoCloseImpl(MojoHandle handle) {
28   return g_core->Close(handle);
29 }
30 
MojoWaitImpl(MojoHandle handle,MojoHandleSignals signals,MojoDeadline deadline,MojoHandleSignalsState * signals_state)31 MojoResult MojoWaitImpl(MojoHandle handle,
32                         MojoHandleSignals signals,
33                         MojoDeadline deadline,
34                         MojoHandleSignalsState* signals_state) {
35   return g_core->Wait(handle, signals, deadline, signals_state);
36 }
37 
MojoWaitManyImpl(const MojoHandle * handles,const MojoHandleSignals * signals,uint32_t num_handles,MojoDeadline deadline,uint32_t * result_index,MojoHandleSignalsState * signals_states)38 MojoResult MojoWaitManyImpl(const MojoHandle* handles,
39                             const MojoHandleSignals* signals,
40                             uint32_t num_handles,
41                             MojoDeadline deadline,
42                             uint32_t* result_index,
43                             MojoHandleSignalsState* signals_states) {
44   return g_core->WaitMany(handles, signals, num_handles, deadline, result_index,
45                           signals_states);
46 }
47 
MojoWatchImpl(MojoHandle handle,MojoHandleSignals signals,MojoWatchCallback callback,uintptr_t context)48 MojoResult MojoWatchImpl(MojoHandle handle,
49                          MojoHandleSignals signals,
50                          MojoWatchCallback callback,
51                          uintptr_t context) {
52   return g_core->Watch(handle, signals, callback, context);
53 }
54 
MojoCancelWatchImpl(MojoHandle handle,uintptr_t context)55 MojoResult MojoCancelWatchImpl(MojoHandle handle, uintptr_t context) {
56   return g_core->CancelWatch(handle, context);
57 }
58 
MojoAllocMessageImpl(uint32_t num_bytes,const MojoHandle * handles,uint32_t num_handles,MojoAllocMessageFlags flags,MojoMessageHandle * message)59 MojoResult MojoAllocMessageImpl(uint32_t num_bytes,
60                                 const MojoHandle* handles,
61                                 uint32_t num_handles,
62                                 MojoAllocMessageFlags flags,
63                                 MojoMessageHandle* message) {
64   return g_core->AllocMessage(num_bytes, handles, num_handles, flags, message);
65 }
66 
MojoFreeMessageImpl(MojoMessageHandle message)67 MojoResult MojoFreeMessageImpl(MojoMessageHandle message) {
68   return g_core->FreeMessage(message);
69 }
70 
MojoGetMessageBufferImpl(MojoMessageHandle message,void ** buffer)71 MojoResult MojoGetMessageBufferImpl(MojoMessageHandle message, void** buffer) {
72   return g_core->GetMessageBuffer(message, buffer);
73 }
74 
MojoCreateWaitSetImpl(MojoHandle * wait_set_handle)75 MojoResult MojoCreateWaitSetImpl(MojoHandle* wait_set_handle) {
76   return g_core->CreateWaitSet(wait_set_handle);
77 }
78 
MojoAddHandleImpl(MojoHandle wait_set_handle,MojoHandle handle,MojoHandleSignals signals)79 MojoResult MojoAddHandleImpl(MojoHandle wait_set_handle,
80                              MojoHandle handle,
81                              MojoHandleSignals signals) {
82   return g_core->AddHandle(wait_set_handle, handle, signals);
83 }
84 
MojoRemoveHandleImpl(MojoHandle wait_set_handle,MojoHandle handle)85 MojoResult MojoRemoveHandleImpl(MojoHandle wait_set_handle, MojoHandle handle) {
86   return g_core->RemoveHandle(wait_set_handle, handle);
87 }
88 
MojoGetReadyHandlesImpl(MojoHandle wait_set_handle,uint32_t * count,MojoHandle * handles,MojoResult * results,struct MojoHandleSignalsState * signals_states)89 MojoResult MojoGetReadyHandlesImpl(
90     MojoHandle wait_set_handle,
91     uint32_t* count,
92     MojoHandle* handles,
93     MojoResult* results,
94     struct MojoHandleSignalsState* signals_states) {
95   return g_core->GetReadyHandles(wait_set_handle, count, handles, results,
96                                  signals_states);
97 }
98 
MojoCreateMessagePipeImpl(const MojoCreateMessagePipeOptions * options,MojoHandle * message_pipe_handle0,MojoHandle * message_pipe_handle1)99 MojoResult MojoCreateMessagePipeImpl(
100     const MojoCreateMessagePipeOptions* options,
101     MojoHandle* message_pipe_handle0,
102     MojoHandle* message_pipe_handle1) {
103   return g_core->CreateMessagePipe(options, message_pipe_handle0,
104                                    message_pipe_handle1);
105 }
106 
MojoWriteMessageImpl(MojoHandle message_pipe_handle,const void * bytes,uint32_t num_bytes,const MojoHandle * handles,uint32_t num_handles,MojoWriteMessageFlags flags)107 MojoResult MojoWriteMessageImpl(MojoHandle message_pipe_handle,
108                                 const void* bytes,
109                                 uint32_t num_bytes,
110                                 const MojoHandle* handles,
111                                 uint32_t num_handles,
112                                 MojoWriteMessageFlags flags) {
113   return g_core->WriteMessage(message_pipe_handle, bytes, num_bytes, handles,
114                               num_handles, flags);
115 }
116 
MojoWriteMessageNewImpl(MojoHandle message_pipe_handle,MojoMessageHandle message,MojoWriteMessageFlags flags)117 MojoResult MojoWriteMessageNewImpl(MojoHandle message_pipe_handle,
118                                    MojoMessageHandle message,
119                                    MojoWriteMessageFlags flags) {
120   return g_core->WriteMessageNew(message_pipe_handle, message, flags);
121 }
122 
MojoReadMessageImpl(MojoHandle message_pipe_handle,void * bytes,uint32_t * num_bytes,MojoHandle * handles,uint32_t * num_handles,MojoReadMessageFlags flags)123 MojoResult MojoReadMessageImpl(MojoHandle message_pipe_handle,
124                                void* bytes,
125                                uint32_t* num_bytes,
126                                MojoHandle* handles,
127                                uint32_t* num_handles,
128                                MojoReadMessageFlags flags) {
129   return g_core->ReadMessage(
130       message_pipe_handle, bytes, num_bytes, handles, num_handles, flags);
131 }
132 
MojoReadMessageNewImpl(MojoHandle message_pipe_handle,MojoMessageHandle * message,uint32_t * num_bytes,MojoHandle * handles,uint32_t * num_handles,MojoReadMessageFlags flags)133 MojoResult MojoReadMessageNewImpl(MojoHandle message_pipe_handle,
134                                   MojoMessageHandle* message,
135                                   uint32_t* num_bytes,
136                                   MojoHandle* handles,
137                                   uint32_t* num_handles,
138                                   MojoReadMessageFlags flags) {
139   return g_core->ReadMessageNew(
140       message_pipe_handle, message, num_bytes, handles, num_handles, flags);
141 }
142 
MojoFuseMessagePipesImpl(MojoHandle handle0,MojoHandle handle1)143 MojoResult MojoFuseMessagePipesImpl(MojoHandle handle0, MojoHandle handle1) {
144   return g_core->FuseMessagePipes(handle0, handle1);
145 }
146 
MojoCreateDataPipeImpl(const MojoCreateDataPipeOptions * options,MojoHandle * data_pipe_producer_handle,MojoHandle * data_pipe_consumer_handle)147 MojoResult MojoCreateDataPipeImpl(const MojoCreateDataPipeOptions* options,
148                                   MojoHandle* data_pipe_producer_handle,
149                                   MojoHandle* data_pipe_consumer_handle) {
150   return g_core->CreateDataPipe(options, data_pipe_producer_handle,
151                                 data_pipe_consumer_handle);
152 }
153 
MojoWriteDataImpl(MojoHandle data_pipe_producer_handle,const void * elements,uint32_t * num_elements,MojoWriteDataFlags flags)154 MojoResult MojoWriteDataImpl(MojoHandle data_pipe_producer_handle,
155                              const void* elements,
156                              uint32_t* num_elements,
157                              MojoWriteDataFlags flags) {
158   return g_core->WriteData(data_pipe_producer_handle, elements, num_elements,
159                            flags);
160 }
161 
MojoBeginWriteDataImpl(MojoHandle data_pipe_producer_handle,void ** buffer,uint32_t * buffer_num_elements,MojoWriteDataFlags flags)162 MojoResult MojoBeginWriteDataImpl(MojoHandle data_pipe_producer_handle,
163                                   void** buffer,
164                                   uint32_t* buffer_num_elements,
165                                   MojoWriteDataFlags flags) {
166   return g_core->BeginWriteData(data_pipe_producer_handle, buffer,
167                                 buffer_num_elements, flags);
168 }
169 
MojoEndWriteDataImpl(MojoHandle data_pipe_producer_handle,uint32_t num_elements_written)170 MojoResult MojoEndWriteDataImpl(MojoHandle data_pipe_producer_handle,
171                                 uint32_t num_elements_written) {
172   return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written);
173 }
174 
MojoReadDataImpl(MojoHandle data_pipe_consumer_handle,void * elements,uint32_t * num_elements,MojoReadDataFlags flags)175 MojoResult MojoReadDataImpl(MojoHandle data_pipe_consumer_handle,
176                             void* elements,
177                             uint32_t* num_elements,
178                             MojoReadDataFlags flags) {
179   return g_core->ReadData(data_pipe_consumer_handle, elements, num_elements,
180                           flags);
181 }
182 
MojoBeginReadDataImpl(MojoHandle data_pipe_consumer_handle,const void ** buffer,uint32_t * buffer_num_elements,MojoReadDataFlags flags)183 MojoResult MojoBeginReadDataImpl(MojoHandle data_pipe_consumer_handle,
184                                  const void** buffer,
185                                  uint32_t* buffer_num_elements,
186                                  MojoReadDataFlags flags) {
187   return g_core->BeginReadData(data_pipe_consumer_handle, buffer,
188                                buffer_num_elements, flags);
189 }
190 
MojoEndReadDataImpl(MojoHandle data_pipe_consumer_handle,uint32_t num_elements_read)191 MojoResult MojoEndReadDataImpl(MojoHandle data_pipe_consumer_handle,
192                                uint32_t num_elements_read) {
193   return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read);
194 }
195 
MojoCreateSharedBufferImpl(const struct MojoCreateSharedBufferOptions * options,uint64_t num_bytes,MojoHandle * shared_buffer_handle)196 MojoResult MojoCreateSharedBufferImpl(
197     const struct MojoCreateSharedBufferOptions* options,
198     uint64_t num_bytes,
199     MojoHandle* shared_buffer_handle) {
200   return g_core->CreateSharedBuffer(options, num_bytes, shared_buffer_handle);
201 }
202 
MojoDuplicateBufferHandleImpl(MojoHandle buffer_handle,const struct MojoDuplicateBufferHandleOptions * options,MojoHandle * new_buffer_handle)203 MojoResult MojoDuplicateBufferHandleImpl(
204     MojoHandle buffer_handle,
205     const struct MojoDuplicateBufferHandleOptions* options,
206     MojoHandle* new_buffer_handle) {
207   return g_core->DuplicateBufferHandle(buffer_handle, options,
208                                        new_buffer_handle);
209 }
210 
MojoMapBufferImpl(MojoHandle buffer_handle,uint64_t offset,uint64_t num_bytes,void ** buffer,MojoMapBufferFlags flags)211 MojoResult MojoMapBufferImpl(MojoHandle buffer_handle,
212                              uint64_t offset,
213                              uint64_t num_bytes,
214                              void** buffer,
215                              MojoMapBufferFlags flags) {
216   return g_core->MapBuffer(buffer_handle, offset, num_bytes, buffer, flags);
217 }
218 
MojoUnmapBufferImpl(void * buffer)219 MojoResult MojoUnmapBufferImpl(void* buffer) {
220   return g_core->UnmapBuffer(buffer);
221 }
222 
MojoWrapPlatformHandleImpl(const MojoPlatformHandle * platform_handle,MojoHandle * mojo_handle)223 MojoResult MojoWrapPlatformHandleImpl(const MojoPlatformHandle* platform_handle,
224                                       MojoHandle* mojo_handle) {
225   return g_core->WrapPlatformHandle(platform_handle, mojo_handle);
226 }
227 
MojoUnwrapPlatformHandleImpl(MojoHandle mojo_handle,MojoPlatformHandle * platform_handle)228 MojoResult MojoUnwrapPlatformHandleImpl(MojoHandle mojo_handle,
229                                         MojoPlatformHandle* platform_handle) {
230   return g_core->UnwrapPlatformHandle(mojo_handle, platform_handle);
231 }
232 
MojoWrapPlatformSharedBufferHandleImpl(const MojoPlatformHandle * platform_handle,size_t num_bytes,MojoPlatformSharedBufferHandleFlags flags,MojoHandle * mojo_handle)233 MojoResult MojoWrapPlatformSharedBufferHandleImpl(
234     const MojoPlatformHandle* platform_handle,
235     size_t num_bytes,
236     MojoPlatformSharedBufferHandleFlags flags,
237     MojoHandle* mojo_handle) {
238   return g_core->WrapPlatformSharedBufferHandle(platform_handle, num_bytes,
239                                                 flags, mojo_handle);
240 }
241 
MojoUnwrapPlatformSharedBufferHandleImpl(MojoHandle mojo_handle,MojoPlatformHandle * platform_handle,size_t * num_bytes,MojoPlatformSharedBufferHandleFlags * flags)242 MojoResult MojoUnwrapPlatformSharedBufferHandleImpl(
243     MojoHandle mojo_handle,
244     MojoPlatformHandle* platform_handle,
245     size_t* num_bytes,
246     MojoPlatformSharedBufferHandleFlags* flags) {
247   return g_core->UnwrapPlatformSharedBufferHandle(mojo_handle, platform_handle,
248                                                   num_bytes, flags);
249 }
250 
MojoNotifyBadMessageImpl(MojoMessageHandle message,const char * error,size_t error_num_bytes)251 MojoResult MojoNotifyBadMessageImpl(MojoMessageHandle message,
252                                     const char* error,
253                                     size_t error_num_bytes) {
254   return g_core->NotifyBadMessage(message, error, error_num_bytes);
255 }
256 
MojoGetPropertyImpl(MojoPropertyType type,void * value)257 MojoResult MojoGetPropertyImpl(MojoPropertyType type, void* value) {
258   return g_core->GetProperty(type, value);
259 }
260 
261 }  // extern "C"
262 
263 namespace mojo {
264 namespace edk {
265 
MakeSystemThunks()266 MojoSystemThunks MakeSystemThunks() {
267   MojoSystemThunks system_thunks = {sizeof(MojoSystemThunks),
268                                     MojoGetTimeTicksNowImpl,
269                                     MojoCloseImpl,
270                                     MojoWaitImpl,
271                                     MojoWaitManyImpl,
272                                     MojoCreateMessagePipeImpl,
273                                     MojoWriteMessageImpl,
274                                     MojoReadMessageImpl,
275                                     MojoCreateDataPipeImpl,
276                                     MojoWriteDataImpl,
277                                     MojoBeginWriteDataImpl,
278                                     MojoEndWriteDataImpl,
279                                     MojoReadDataImpl,
280                                     MojoBeginReadDataImpl,
281                                     MojoEndReadDataImpl,
282                                     MojoCreateSharedBufferImpl,
283                                     MojoDuplicateBufferHandleImpl,
284                                     MojoMapBufferImpl,
285                                     MojoUnmapBufferImpl,
286                                     MojoCreateWaitSetImpl,
287                                     MojoAddHandleImpl,
288                                     MojoRemoveHandleImpl,
289                                     MojoGetReadyHandlesImpl,
290                                     MojoWatchImpl,
291                                     MojoCancelWatchImpl,
292                                     MojoFuseMessagePipesImpl,
293                                     MojoWriteMessageNewImpl,
294                                     MojoReadMessageNewImpl,
295                                     MojoAllocMessageImpl,
296                                     MojoFreeMessageImpl,
297                                     MojoGetMessageBufferImpl,
298                                     MojoWrapPlatformHandleImpl,
299                                     MojoUnwrapPlatformHandleImpl,
300                                     MojoWrapPlatformSharedBufferHandleImpl,
301                                     MojoUnwrapPlatformSharedBufferHandleImpl,
302                                     MojoNotifyBadMessageImpl,
303                                     MojoGetPropertyImpl};
304   return system_thunks;
305 }
306 
307 }  // namespace edk
308 }  // namespace mojo
309