OLD | NEW |
| (Empty) |
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/result.h> | |
6 #include <mojo/system/buffer.h> | |
7 #include <mojo/system/data_pipe.h> | |
8 #include <mojo/system/handle.h> | |
9 #include <mojo/system/message_pipe.h> | |
10 #include <mojo/system/time.h> | |
11 #include <mojo/system/wait.h> | |
12 #include <mojo/system/wait_set.h> | |
13 #include <stdlib.h> | |
14 | |
15 #include "mojo/public/platform/nacl/mojo_irt.h" | |
16 #include "native_client/src/untrusted/irt/irt.h" | |
17 | |
18 bool g_irt_mojo_valid = false; | |
19 struct nacl_irt_mojo g_irt_mojo; | |
20 | |
21 struct nacl_irt_mojo* get_irt_mojo() { | |
22 if (!g_irt_mojo_valid) { | |
23 size_t rc = nacl_interface_query(NACL_IRT_MOJO_v0_1, &g_irt_mojo, | |
24 sizeof(g_irt_mojo)); | |
25 if (rc != sizeof(g_irt_mojo)) | |
26 return NULL; | |
27 else | |
28 g_irt_mojo_valid = true; | |
29 } | |
30 return &g_irt_mojo; | |
31 } | |
32 | |
33 MojoResult _MojoGetInitialHandle(MojoHandle* handle) { | |
34 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
35 if (!irt_mojo) | |
36 abort(); | |
37 return irt_mojo->_MojoGetInitialHandle(handle); | |
38 } | |
39 | |
40 MojoTimeTicks MojoGetTimeTicksNow() { | |
41 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
42 if (!irt_mojo) | |
43 abort(); | |
44 return irt_mojo->MojoGetTimeTicksNow(); | |
45 } | |
46 | |
47 MojoResult MojoClose(MojoHandle handle) { | |
48 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
49 if (!irt_mojo) | |
50 abort(); | |
51 return irt_mojo->MojoClose(handle); | |
52 } | |
53 | |
54 MojoResult MojoGetRights(MojoHandle handle, MojoHandleRights* rights) { | |
55 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
56 if (!irt_mojo) | |
57 abort(); | |
58 return irt_mojo->MojoGetRights(handle, rights); | |
59 } | |
60 | |
61 MojoResult MojoReplaceHandleWithReducedRights(MojoHandle handle, | |
62 MojoHandleRights rights_to_remove, | |
63 MojoHandle* replacement_handle) { | |
64 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
65 if (!irt_mojo) | |
66 abort(); | |
67 return irt_mojo->MojoReplaceHandleWithReducedRights(handle, rights_to_remove, | |
68 replacement_handle); | |
69 } | |
70 | |
71 MojoResult MojoDuplicateHandleWithReducedRights( | |
72 MojoHandle handle, | |
73 MojoHandleRights rights_to_remove, | |
74 MojoHandle* new_handle) { | |
75 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
76 if (!irt_mojo) | |
77 abort(); | |
78 return irt_mojo->MojoDuplicateHandleWithReducedRights( | |
79 handle, rights_to_remove, new_handle); | |
80 } | |
81 | |
82 MojoResult MojoDuplicateHandle(MojoHandle handle, MojoHandle* new_handle) { | |
83 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
84 if (!irt_mojo) | |
85 abort(); | |
86 return irt_mojo->MojoDuplicateHandle(handle, new_handle); | |
87 } | |
88 | |
89 MojoResult MojoWait(MojoHandle handle, | |
90 MojoHandleSignals signals, | |
91 MojoDeadline deadline, | |
92 struct MojoHandleSignalsState* signals_state) { | |
93 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
94 if (!irt_mojo) | |
95 abort(); | |
96 return irt_mojo->MojoWait(handle, signals, deadline, signals_state); | |
97 } | |
98 | |
99 MojoResult MojoWaitMany(const MojoHandle* handles, | |
100 const MojoHandleSignals* signals, | |
101 uint32_t num_handles, | |
102 MojoDeadline deadline, | |
103 uint32_t* result_index, | |
104 struct MojoHandleSignalsState* signals_states) { | |
105 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
106 if (!irt_mojo) | |
107 abort(); | |
108 return irt_mojo->MojoWaitMany(handles, signals, num_handles, deadline, | |
109 result_index, signals_states); | |
110 } | |
111 | |
112 MojoResult MojoCreateMessagePipe( | |
113 const struct MojoCreateMessagePipeOptions* options, | |
114 MojoHandle* message_pipe_handle0, | |
115 MojoHandle* message_pipe_handle1) { | |
116 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
117 if (!irt_mojo) | |
118 abort(); | |
119 return irt_mojo->MojoCreateMessagePipe(options, message_pipe_handle0, | |
120 message_pipe_handle1); | |
121 } | |
122 | |
123 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, | |
124 const void* bytes, | |
125 uint32_t num_bytes, | |
126 const MojoHandle* handles, | |
127 uint32_t num_handles, | |
128 MojoWriteMessageFlags flags) { | |
129 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
130 if (!irt_mojo) | |
131 abort(); | |
132 return irt_mojo->MojoWriteMessage(message_pipe_handle, bytes, num_bytes, | |
133 handles, num_handles, flags); | |
134 } | |
135 | |
136 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | |
137 void* bytes, | |
138 uint32_t* num_bytes, | |
139 MojoHandle* handles, | |
140 uint32_t* num_handles, | |
141 MojoReadMessageFlags flags) { | |
142 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
143 if (!irt_mojo) | |
144 abort(); | |
145 return irt_mojo->MojoReadMessage(message_pipe_handle, bytes, num_bytes, | |
146 handles, num_handles, flags); | |
147 } | |
148 | |
149 MojoResult MojoCreateDataPipe(const struct MojoCreateDataPipeOptions* options, | |
150 MojoHandle* data_pipe_producer_handle, | |
151 MojoHandle* data_pipe_consumer_handle) { | |
152 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
153 if (!irt_mojo) | |
154 abort(); | |
155 return irt_mojo->MojoCreateDataPipe(options, data_pipe_producer_handle, | |
156 data_pipe_consumer_handle); | |
157 } | |
158 | |
159 MojoResult MojoSetDataPipeProducerOptions( | |
160 MojoHandle data_pipe_producer_handle, | |
161 const struct MojoDataPipeProducerOptions* options) { | |
162 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
163 if (!irt_mojo) | |
164 abort(); | |
165 return irt_mojo->MojoSetDataPipeProducerOptions(data_pipe_producer_handle, | |
166 options); | |
167 } | |
168 | |
169 MojoResult MojoGetDataPipeProducerOptions( | |
170 MojoHandle data_pipe_producer_handle, | |
171 struct MojoDataPipeProducerOptions* options, | |
172 uint32_t options_num_bytes) { | |
173 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
174 if (!irt_mojo) | |
175 abort(); | |
176 return irt_mojo->MojoGetDataPipeProducerOptions(data_pipe_producer_handle, | |
177 options, options_num_bytes); | |
178 } | |
179 | |
180 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, | |
181 const void* elements, | |
182 uint32_t* num_bytes, | |
183 MojoWriteDataFlags flags) { | |
184 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
185 if (!irt_mojo) | |
186 abort(); | |
187 return irt_mojo->MojoWriteData(data_pipe_producer_handle, elements, num_bytes, | |
188 flags); | |
189 } | |
190 | |
191 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, | |
192 void** buffer, | |
193 uint32_t* buffer_num_bytes, | |
194 MojoWriteDataFlags flags) { | |
195 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
196 if (!irt_mojo) | |
197 abort(); | |
198 return irt_mojo->MojoBeginWriteData(data_pipe_producer_handle, buffer, | |
199 buffer_num_bytes, flags); | |
200 } | |
201 | |
202 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, | |
203 uint32_t num_bytes_written) { | |
204 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
205 if (!irt_mojo) | |
206 abort(); | |
207 return irt_mojo->MojoEndWriteData(data_pipe_producer_handle, | |
208 num_bytes_written); | |
209 } | |
210 | |
211 MojoResult MojoSetDataPipeConsumerOptions( | |
212 MojoHandle data_pipe_consumer_handle, | |
213 const struct MojoDataPipeConsumerOptions* options) { | |
214 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
215 if (!irt_mojo) | |
216 abort(); | |
217 return irt_mojo->MojoSetDataPipeConsumerOptions(data_pipe_consumer_handle, | |
218 options); | |
219 } | |
220 | |
221 MojoResult MojoGetDataPipeConsumerOptions( | |
222 MojoHandle data_pipe_consumer_handle, | |
223 struct MojoDataPipeConsumerOptions* options, | |
224 uint32_t options_num_bytes) { | |
225 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
226 if (!irt_mojo) | |
227 abort(); | |
228 return irt_mojo->MojoGetDataPipeConsumerOptions(data_pipe_consumer_handle, | |
229 options, options_num_bytes); | |
230 } | |
231 | |
232 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, | |
233 void* elements, | |
234 uint32_t* num_bytes, | |
235 MojoReadDataFlags flags) { | |
236 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
237 if (!irt_mojo) | |
238 abort(); | |
239 return irt_mojo->MojoReadData(data_pipe_consumer_handle, elements, num_bytes, | |
240 flags); | |
241 } | |
242 | |
243 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, | |
244 const void** buffer, | |
245 uint32_t* buffer_num_bytes, | |
246 MojoReadDataFlags flags) { | |
247 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
248 if (!irt_mojo) | |
249 abort(); | |
250 return irt_mojo->MojoBeginReadData(data_pipe_consumer_handle, buffer, | |
251 buffer_num_bytes, flags); | |
252 } | |
253 | |
254 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, | |
255 uint32_t num_bytes_read) { | |
256 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
257 if (!irt_mojo) | |
258 abort(); | |
259 return irt_mojo->MojoEndReadData(data_pipe_consumer_handle, num_bytes_read); | |
260 } | |
261 | |
262 MojoResult MojoCreateSharedBuffer( | |
263 const struct MojoCreateSharedBufferOptions* options, | |
264 uint64_t num_bytes, | |
265 MojoHandle* shared_buffer_handle) { | |
266 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
267 if (!irt_mojo) | |
268 abort(); | |
269 return irt_mojo->MojoCreateSharedBuffer(options, num_bytes, | |
270 shared_buffer_handle); | |
271 } | |
272 | |
273 MojoResult MojoDuplicateBufferHandle( | |
274 MojoHandle buffer_handle, | |
275 const struct MojoDuplicateBufferHandleOptions* options, | |
276 MojoHandle* new_buffer_handle) { | |
277 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
278 if (!irt_mojo) | |
279 abort(); | |
280 return irt_mojo->MojoDuplicateBufferHandle(buffer_handle, options, | |
281 new_buffer_handle); | |
282 } | |
283 | |
284 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, | |
285 struct MojoBufferInformation* info, | |
286 uint32_t info_num_bytes) { | |
287 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
288 if (!irt_mojo) | |
289 abort(); | |
290 return irt_mojo->MojoGetBufferInformation(buffer_handle, info, | |
291 info_num_bytes); | |
292 } | |
293 | |
294 MojoResult MojoMapBuffer(MojoHandle buffer_handle, | |
295 uint64_t offset, | |
296 uint64_t num_bytes, | |
297 void** buffer, | |
298 MojoMapBufferFlags flags) { | |
299 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
300 if (!irt_mojo) | |
301 abort(); | |
302 return irt_mojo->MojoMapBuffer(buffer_handle, offset, num_bytes, buffer, | |
303 flags); | |
304 } | |
305 | |
306 MojoResult MojoUnmapBuffer(void* buffer) { | |
307 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
308 if (!irt_mojo) | |
309 abort(); | |
310 return irt_mojo->MojoUnmapBuffer(buffer); | |
311 } | |
312 | |
313 MojoResult MojoCreateWaitSet(const struct MojoCreateWaitSetOptions* options, | |
314 MojoHandle* handle) { | |
315 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
316 if (!irt_mojo) | |
317 abort(); | |
318 return irt_mojo->MojoCreateWaitSet(options, handle); | |
319 } | |
320 | |
321 MojoResult MojoWaitSetAdd(MojoHandle wait_set_handle, | |
322 MojoHandle handle, | |
323 MojoHandleSignals signals, | |
324 uint64_t cookie, | |
325 const struct MojoWaitSetAddOptions* options) { | |
326 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
327 if (!irt_mojo) | |
328 abort(); | |
329 return irt_mojo->MojoWaitSetAdd(wait_set_handle, handle, signals, cookie, | |
330 options); | |
331 } | |
332 | |
333 MojoResult MojoWaitSetRemove(MojoHandle wait_set_handle, uint64_t cookie) { | |
334 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
335 if (!irt_mojo) | |
336 abort(); | |
337 return irt_mojo->MojoWaitSetRemove(wait_set_handle, cookie); | |
338 } | |
339 | |
340 MojoResult MojoWaitSetWait(MojoHandle wait_set_handle, | |
341 MojoDeadline deadline, | |
342 uint32_t* num_results, | |
343 struct MojoWaitSetResult* results, | |
344 uint32_t* max_results) { | |
345 struct nacl_irt_mojo* irt_mojo = get_irt_mojo(); | |
346 if (!irt_mojo) | |
347 abort(); | |
348 return irt_mojo->MojoWaitSetWait(wait_set_handle, deadline, num_results, | |
349 results, max_results); | |
350 } | |
OLD | NEW |