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 // WARNING this file was generated by generate_monacl_bindings.py | |
6 // Do not edit by hand. | |
7 | |
8 #include "mojo/monacl/mojo_syscall.h" | |
9 | |
10 #include <stdio.h> | |
11 | |
12 #include "mojo/public/c/system/core.h" | |
13 #include "native_client/src/public/nacl_app.h" | |
14 #include "native_client/src/shared/platform/nacl_log.h" | |
15 #include "native_client/src/trusted/desc/nacl_desc_custom.h" | |
16 #include "native_client/src/trusted/service_runtime/nacl_copy.h" | |
17 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | |
18 | |
19 static INLINE uintptr_t NaClUserToSysAddrArray( | |
20 struct NaClApp *nap, | |
21 uintptr_t uaddr, | |
22 size_t count, | |
23 size_t size) { | |
24 // TODO overflow checking | |
25 size_t range = count * size; | |
26 return NaClUserToSysAddrRange(nap, uaddr, range); | |
27 } | |
28 | |
29 void MojoDescDestroy(void *handle) { | |
30 UNREFERENCED_PARAMETER(handle); | |
31 NaClLog(LOG_ERROR, "Called destroy...\n"); | |
32 } | |
33 | |
34 ssize_t MojoDescSendMsg(void *handle, | |
35 const struct NaClImcTypedMsgHdr *msg, | |
36 int flags) { | |
37 UNREFERENCED_PARAMETER(flags); | |
38 | |
39 struct NaClApp *nap = static_cast<struct NaClApp*>(handle); | |
40 | |
41 if (msg->iov_length != 1 || msg->iov[0].length < 8 || msg->ndesc_length != 0) { | |
42 NaClLog(LOG_ERROR, "Malformed message.\n"); | |
43 return -1; | |
44 } | |
45 | |
46 uint32_t *params = static_cast<uint32_t*>(msg->iov[0].base); | |
47 uint32_t numParams = msg->iov[0].length / sizeof(*params); | |
48 | |
49 uint32_t msgType = params[0]; | |
50 //printf("Message: %d.\n", msgType); | |
51 switch (msgType) { | |
52 case 0: | |
53 { | |
54 if (numParams != 5) { | |
55 return -1; | |
56 } | |
57 NaClCopyTakeLock(nap); | |
58 const struct MojoCreateSharedBufferOptions* options; | |
59 if (params[1] == 0) { | |
60 options = NULL; | |
61 } else { | |
62 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(*options) ); | |
Mark Seaborn
2014/07/21 16:31:39
You should use NaClCopyInFromUser() and NaClCopyOu
Nick Bray (chromium)
2014/07/21 22:38:36
Except that the logic is more complicated than NaC
Mark Seaborn
2014/07/21 23:25:44
You could make a wrapper around CopyIn/Out to hand
Mark Seaborn
2014/09/09 19:13:10
Can you add a TODO for passing the parameters in a
Nick Bray (chromium)
2014/09/09 23:12:32
This transcends the scope of a TODO. The issue tr
| |
63 if (temp == kNaClBadAddress) { | |
64 return -1; | |
65 } | |
66 options = reinterpret_cast<const struct MojoCreateSharedBufferOptions*>( temp); | |
67 } | |
68 uint64_t num_bytes; | |
69 if (params[2] == 0) { | |
70 return -1; | |
71 } else { | |
72 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(num_bytes )); | |
73 if (temp == kNaClBadAddress) { | |
74 return -1; | |
75 } | |
76 num_bytes = *reinterpret_cast<uint64_t volatile*>(temp); | |
77 } | |
78 MojoHandle* shared_buffer_handle_ptr; | |
79 MojoHandle shared_buffer_handle; | |
80 if (params[3] == 0) { | |
81 return -1; | |
82 } else { | |
83 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(shared_bu ffer_handle)); | |
84 if (temp == kNaClBadAddress) { | |
85 return -1; | |
86 } | |
87 shared_buffer_handle_ptr = reinterpret_cast<MojoHandle*>(temp); | |
88 } | |
89 MojoResult* result_ptr; | |
90 MojoResult result; | |
91 if (params[4] == 0) { | |
92 return -1; | |
93 } else { | |
94 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(result)); | |
95 if (temp == kNaClBadAddress) { | |
96 return -1; | |
97 } | |
98 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
99 } | |
100 NaClCopyDropLock(nap); | |
101 | |
102 result = MojoCreateSharedBuffer(options, num_bytes, &shared_buffer_handle) ; | |
103 | |
104 NaClCopyTakeLock(nap); | |
105 *shared_buffer_handle_ptr = shared_buffer_handle; | |
106 *result_ptr = result; | |
107 NaClCopyDropLock(nap); | |
108 | |
109 return 0; | |
110 } | |
111 case 1: | |
112 { | |
113 if (numParams != 5) { | |
114 return -1; | |
115 } | |
116 NaClCopyTakeLock(nap); | |
117 MojoHandle buffer_handle; | |
118 if (params[1] == 0) { | |
119 return -1; | |
120 } else { | |
121 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(buffer_ha ndle)); | |
122 if (temp == kNaClBadAddress) { | |
123 return -1; | |
124 } | |
125 buffer_handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
126 } | |
127 const struct MojoDuplicateBufferHandleOptions* options; | |
128 if (params[2] == 0) { | |
129 options = NULL; | |
130 } else { | |
131 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(*options) ); | |
132 if (temp == kNaClBadAddress) { | |
133 return -1; | |
134 } | |
135 options = reinterpret_cast<const struct MojoDuplicateBufferHandleOptions *>(temp); | |
136 } | |
137 MojoHandle* new_buffer_handle_ptr; | |
138 MojoHandle new_buffer_handle; | |
139 if (params[3] == 0) { | |
140 return -1; | |
141 } else { | |
142 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(new_buffe r_handle)); | |
143 if (temp == kNaClBadAddress) { | |
144 return -1; | |
145 } | |
146 new_buffer_handle_ptr = reinterpret_cast<MojoHandle*>(temp); | |
147 } | |
148 MojoResult* result_ptr; | |
149 MojoResult result; | |
150 if (params[4] == 0) { | |
151 return -1; | |
152 } else { | |
153 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(result)); | |
154 if (temp == kNaClBadAddress) { | |
155 return -1; | |
156 } | |
157 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
158 } | |
159 NaClCopyDropLock(nap); | |
160 | |
161 result = MojoDuplicateBufferHandle(buffer_handle, options, &new_buffer_han dle); | |
162 | |
163 NaClCopyTakeLock(nap); | |
164 *new_buffer_handle_ptr = new_buffer_handle; | |
165 *result_ptr = result; | |
166 NaClCopyDropLock(nap); | |
167 | |
168 return 0; | |
169 } | |
170 case 2: | |
171 { | |
172 if (numParams != 7) { | |
173 return -1; | |
174 } | |
175 NaClCopyTakeLock(nap); | |
176 MojoHandle buffer_handle; | |
177 if (params[1] == 0) { | |
178 return -1; | |
179 } else { | |
180 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(buffer_ha ndle)); | |
181 if (temp == kNaClBadAddress) { | |
182 return -1; | |
183 } | |
184 buffer_handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
185 } | |
186 uint64_t offset; | |
187 if (params[2] == 0) { | |
188 return -1; | |
189 } else { | |
190 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(offset)); | |
191 if (temp == kNaClBadAddress) { | |
192 return -1; | |
193 } | |
194 offset = *reinterpret_cast<uint64_t volatile*>(temp); | |
195 } | |
196 uint64_t num_bytes; | |
197 if (params[3] == 0) { | |
198 return -1; | |
199 } else { | |
200 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_bytes )); | |
201 if (temp == kNaClBadAddress) { | |
202 return -1; | |
203 } | |
204 num_bytes = *reinterpret_cast<uint64_t volatile*>(temp); | |
205 } | |
206 void** buffer_ptr; | |
207 void* buffer; | |
208 if (params[4] == 0) { | |
209 return -1; | |
210 } else { | |
211 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(buffer)); | |
212 if (temp == kNaClBadAddress) { | |
213 return -1; | |
214 } | |
215 buffer_ptr = reinterpret_cast<void**>(temp); | |
216 } | |
217 MojoMapBufferFlags flags; | |
218 if (params[5] == 0) { | |
219 return -1; | |
220 } else { | |
221 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(flags)); | |
222 if (temp == kNaClBadAddress) { | |
223 return -1; | |
224 } | |
225 flags = *reinterpret_cast<MojoMapBufferFlags volatile*>(temp); | |
226 } | |
227 MojoResult* result_ptr; | |
228 MojoResult result; | |
229 if (params[6] == 0) { | |
230 return -1; | |
231 } else { | |
232 uintptr_t temp = NaClUserToSysAddrRange(nap, params[6], sizeof(result)); | |
233 if (temp == kNaClBadAddress) { | |
234 return -1; | |
235 } | |
236 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
237 } | |
238 NaClCopyDropLock(nap); | |
239 | |
240 result = MojoMapBuffer(buffer_handle, offset, num_bytes, &buffer, flags); | |
241 | |
242 NaClCopyTakeLock(nap); | |
243 *buffer_ptr = buffer; | |
244 *result_ptr = result; | |
245 NaClCopyDropLock(nap); | |
246 | |
247 return 0; | |
248 } | |
249 case 3: | |
250 { | |
251 if (numParams != 3) { | |
252 return -1; | |
253 } | |
254 NaClCopyTakeLock(nap); | |
255 void* buffer; | |
256 if (params[1] == 0) { | |
257 return -1; | |
258 } else { | |
259 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(buffer)); | |
260 if (temp == kNaClBadAddress) { | |
261 return -1; | |
262 } | |
263 buffer = *reinterpret_cast<void* volatile*>(temp); | |
264 } | |
265 MojoResult* result_ptr; | |
266 MojoResult result; | |
267 if (params[2] == 0) { | |
268 return -1; | |
269 } else { | |
270 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(result)); | |
271 if (temp == kNaClBadAddress) { | |
272 return -1; | |
273 } | |
274 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
275 } | |
276 NaClCopyDropLock(nap); | |
277 | |
278 result = MojoUnmapBuffer(buffer); | |
279 | |
280 NaClCopyTakeLock(nap); | |
281 *result_ptr = result; | |
282 NaClCopyDropLock(nap); | |
283 | |
284 return 0; | |
285 } | |
286 case 4: | |
287 { | |
288 if (numParams != 5) { | |
289 return -1; | |
290 } | |
291 NaClCopyTakeLock(nap); | |
292 const struct MojoCreateDataPipeOptions* options; | |
293 if (params[1] == 0) { | |
294 options = NULL; | |
295 } else { | |
296 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(*options) ); | |
297 if (temp == kNaClBadAddress) { | |
298 return -1; | |
299 } | |
300 options = reinterpret_cast<const struct MojoCreateDataPipeOptions*>(temp ); | |
301 } | |
302 MojoHandle* data_pipe_producer_handle_ptr; | |
303 MojoHandle data_pipe_producer_handle; | |
304 if (params[2] == 0) { | |
305 return -1; | |
306 } else { | |
307 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(data_pipe _producer_handle)); | |
308 if (temp == kNaClBadAddress) { | |
309 return -1; | |
310 } | |
311 data_pipe_producer_handle_ptr = reinterpret_cast<MojoHandle*>(temp); | |
312 } | |
313 MojoHandle* data_pipe_consumer_handle_ptr; | |
314 MojoHandle data_pipe_consumer_handle; | |
315 if (params[3] == 0) { | |
316 return -1; | |
317 } else { | |
318 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(data_pipe _consumer_handle)); | |
319 if (temp == kNaClBadAddress) { | |
320 return -1; | |
321 } | |
322 data_pipe_consumer_handle_ptr = reinterpret_cast<MojoHandle*>(temp); | |
323 } | |
324 MojoResult* result_ptr; | |
325 MojoResult result; | |
326 if (params[4] == 0) { | |
327 return -1; | |
328 } else { | |
329 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(result)); | |
330 if (temp == kNaClBadAddress) { | |
331 return -1; | |
332 } | |
333 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
334 } | |
335 NaClCopyDropLock(nap); | |
336 | |
337 result = MojoCreateDataPipe(options, &data_pipe_producer_handle, &data_pip e_consumer_handle); | |
338 | |
339 NaClCopyTakeLock(nap); | |
340 *data_pipe_producer_handle_ptr = data_pipe_producer_handle; | |
341 *data_pipe_consumer_handle_ptr = data_pipe_consumer_handle; | |
342 *result_ptr = result; | |
343 NaClCopyDropLock(nap); | |
344 | |
345 return 0; | |
346 } | |
347 case 5: | |
348 { | |
349 if (numParams != 6) { | |
350 return -1; | |
351 } | |
352 NaClCopyTakeLock(nap); | |
353 MojoHandle data_pipe_producer_handle; | |
354 if (params[1] == 0) { | |
355 return -1; | |
356 } else { | |
357 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _producer_handle)); | |
358 if (temp == kNaClBadAddress) { | |
359 return -1; | |
360 } | |
361 data_pipe_producer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
362 } | |
363 uint32_t* num_bytes_ptr; | |
364 uint32_t num_bytes; | |
365 if (params[3] == 0) { | |
366 return -1; | |
367 } else { | |
368 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_bytes )); | |
369 if (temp == kNaClBadAddress) { | |
370 return -1; | |
371 } | |
372 num_bytes_ptr = reinterpret_cast<uint32_t*>(temp); | |
373 // In/Out | |
374 num_bytes = *num_bytes_ptr; | |
375 } | |
376 MojoWriteDataFlags flags; | |
377 if (params[4] == 0) { | |
378 return -1; | |
379 } else { | |
380 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(flags)); | |
381 if (temp == kNaClBadAddress) { | |
382 return -1; | |
383 } | |
384 flags = *reinterpret_cast<MojoWriteDataFlags volatile*>(temp); | |
385 } | |
386 const void* elements; | |
387 if (params[2] == 0) { | |
388 return -1; | |
389 } else { | |
390 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], num_bytes); | |
391 if (temp == kNaClBadAddress) { | |
392 return -1; | |
393 } | |
394 elements = reinterpret_cast<const void*>(temp); | |
395 } | |
396 MojoResult* result_ptr; | |
397 MojoResult result; | |
398 if (params[5] == 0) { | |
399 return -1; | |
400 } else { | |
401 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(result)); | |
402 if (temp == kNaClBadAddress) { | |
403 return -1; | |
404 } | |
405 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
406 } | |
407 NaClCopyDropLock(nap); | |
408 | |
409 result = MojoWriteData(data_pipe_producer_handle, elements, &num_bytes, fl ags); | |
410 | |
411 NaClCopyTakeLock(nap); | |
412 *num_bytes_ptr = num_bytes; | |
413 *result_ptr = result; | |
414 NaClCopyDropLock(nap); | |
415 | |
416 return 0; | |
417 } | |
418 case 6: | |
419 { | |
420 if (numParams != 6) { | |
421 return -1; | |
422 } | |
423 NaClCopyTakeLock(nap); | |
424 MojoHandle data_pipe_producer_handle; | |
425 if (params[1] == 0) { | |
426 return -1; | |
427 } else { | |
428 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _producer_handle)); | |
429 if (temp == kNaClBadAddress) { | |
430 return -1; | |
431 } | |
432 data_pipe_producer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
433 } | |
434 void** buffer_ptr; | |
435 void* buffer; | |
436 if (params[2] == 0) { | |
437 return -1; | |
438 } else { | |
439 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(buffer)); | |
440 if (temp == kNaClBadAddress) { | |
441 return -1; | |
442 } | |
443 buffer_ptr = reinterpret_cast<void**>(temp); | |
444 } | |
445 uint32_t* buffer_num_bytes_ptr; | |
446 uint32_t buffer_num_bytes; | |
447 if (params[3] == 0) { | |
448 return -1; | |
449 } else { | |
450 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(buffer_nu m_bytes)); | |
451 if (temp == kNaClBadAddress) { | |
452 return -1; | |
453 } | |
454 buffer_num_bytes_ptr = reinterpret_cast<uint32_t*>(temp); | |
455 // In/Out | |
456 buffer_num_bytes = *buffer_num_bytes_ptr; | |
457 } | |
458 MojoWriteDataFlags flags; | |
459 if (params[4] == 0) { | |
460 return -1; | |
461 } else { | |
462 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(flags)); | |
463 if (temp == kNaClBadAddress) { | |
464 return -1; | |
465 } | |
466 flags = *reinterpret_cast<MojoWriteDataFlags volatile*>(temp); | |
467 } | |
468 MojoResult* result_ptr; | |
469 MojoResult result; | |
470 if (params[5] == 0) { | |
471 return -1; | |
472 } else { | |
473 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(result)); | |
474 if (temp == kNaClBadAddress) { | |
475 return -1; | |
476 } | |
477 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
478 } | |
479 NaClCopyDropLock(nap); | |
480 | |
481 result = MojoBeginWriteData(data_pipe_producer_handle, &buffer, &buffer_nu m_bytes, flags); | |
482 | |
483 NaClCopyTakeLock(nap); | |
484 *buffer_ptr = buffer; | |
485 *buffer_num_bytes_ptr = buffer_num_bytes; | |
486 *result_ptr = result; | |
487 NaClCopyDropLock(nap); | |
488 | |
489 return 0; | |
490 } | |
491 case 7: | |
492 { | |
493 if (numParams != 4) { | |
494 return -1; | |
495 } | |
496 NaClCopyTakeLock(nap); | |
497 MojoHandle data_pipe_producer_handle; | |
498 if (params[1] == 0) { | |
499 return -1; | |
500 } else { | |
501 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _producer_handle)); | |
502 if (temp == kNaClBadAddress) { | |
503 return -1; | |
504 } | |
505 data_pipe_producer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
506 } | |
507 uint32_t num_bytes_written; | |
508 if (params[2] == 0) { | |
509 return -1; | |
510 } else { | |
511 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(num_bytes _written)); | |
512 if (temp == kNaClBadAddress) { | |
513 return -1; | |
514 } | |
515 num_bytes_written = *reinterpret_cast<uint32_t volatile*>(temp); | |
516 } | |
517 MojoResult* result_ptr; | |
518 MojoResult result; | |
519 if (params[3] == 0) { | |
520 return -1; | |
521 } else { | |
522 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(result)); | |
523 if (temp == kNaClBadAddress) { | |
524 return -1; | |
525 } | |
526 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
527 } | |
528 NaClCopyDropLock(nap); | |
529 | |
530 result = MojoEndWriteData(data_pipe_producer_handle, num_bytes_written); | |
531 | |
532 NaClCopyTakeLock(nap); | |
533 *result_ptr = result; | |
534 NaClCopyDropLock(nap); | |
535 | |
536 return 0; | |
537 } | |
538 case 8: | |
539 { | |
540 if (numParams != 6) { | |
541 return -1; | |
542 } | |
543 NaClCopyTakeLock(nap); | |
544 MojoHandle data_pipe_consumer_handle; | |
545 if (params[1] == 0) { | |
546 return -1; | |
547 } else { | |
548 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _consumer_handle)); | |
549 if (temp == kNaClBadAddress) { | |
550 return -1; | |
551 } | |
552 data_pipe_consumer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
553 } | |
554 uint32_t* num_bytes_ptr; | |
555 uint32_t num_bytes; | |
556 if (params[3] == 0) { | |
557 return -1; | |
558 } else { | |
559 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_bytes )); | |
560 if (temp == kNaClBadAddress) { | |
561 return -1; | |
562 } | |
563 num_bytes_ptr = reinterpret_cast<uint32_t*>(temp); | |
564 // In/Out | |
565 num_bytes = *num_bytes_ptr; | |
566 } | |
567 MojoReadDataFlags flags; | |
568 if (params[4] == 0) { | |
569 return -1; | |
570 } else { | |
571 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(flags)); | |
572 if (temp == kNaClBadAddress) { | |
573 return -1; | |
574 } | |
575 flags = *reinterpret_cast<MojoReadDataFlags volatile*>(temp); | |
576 } | |
577 void* elements; | |
578 if (params[2] == 0) { | |
579 return -1; | |
580 } else { | |
581 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], num_bytes); | |
582 if (temp == kNaClBadAddress) { | |
583 return -1; | |
584 } | |
585 elements = reinterpret_cast<void*>(temp); | |
586 } | |
587 MojoResult* result_ptr; | |
588 MojoResult result; | |
589 if (params[5] == 0) { | |
590 return -1; | |
591 } else { | |
592 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(result)); | |
593 if (temp == kNaClBadAddress) { | |
594 return -1; | |
595 } | |
596 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
597 } | |
598 NaClCopyDropLock(nap); | |
599 | |
600 result = MojoReadData(data_pipe_consumer_handle, elements, &num_bytes, fla gs); | |
601 | |
602 NaClCopyTakeLock(nap); | |
603 *num_bytes_ptr = num_bytes; | |
604 *result_ptr = result; | |
605 NaClCopyDropLock(nap); | |
606 | |
607 return 0; | |
608 } | |
609 case 9: | |
610 { | |
611 if (numParams != 6) { | |
612 return -1; | |
613 } | |
614 NaClCopyTakeLock(nap); | |
615 MojoHandle data_pipe_consumer_handle; | |
616 if (params[1] == 0) { | |
617 return -1; | |
618 } else { | |
619 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _consumer_handle)); | |
620 if (temp == kNaClBadAddress) { | |
621 return -1; | |
622 } | |
623 data_pipe_consumer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
624 } | |
625 const void** buffer_ptr; | |
626 const void* buffer; | |
627 if (params[2] == 0) { | |
628 return -1; | |
629 } else { | |
630 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(buffer)); | |
631 if (temp == kNaClBadAddress) { | |
632 return -1; | |
633 } | |
634 buffer_ptr = reinterpret_cast<const void**>(temp); | |
635 } | |
636 uint32_t* buffer_num_bytes_ptr; | |
637 uint32_t buffer_num_bytes; | |
638 if (params[3] == 0) { | |
639 return -1; | |
640 } else { | |
641 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(buffer_nu m_bytes)); | |
642 if (temp == kNaClBadAddress) { | |
643 return -1; | |
644 } | |
645 buffer_num_bytes_ptr = reinterpret_cast<uint32_t*>(temp); | |
646 // In/Out | |
647 buffer_num_bytes = *buffer_num_bytes_ptr; | |
648 } | |
649 MojoReadDataFlags flags; | |
650 if (params[4] == 0) { | |
651 return -1; | |
652 } else { | |
653 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(flags)); | |
654 if (temp == kNaClBadAddress) { | |
655 return -1; | |
656 } | |
657 flags = *reinterpret_cast<MojoReadDataFlags volatile*>(temp); | |
658 } | |
659 MojoResult* result_ptr; | |
660 MojoResult result; | |
661 if (params[5] == 0) { | |
662 return -1; | |
663 } else { | |
664 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(result)); | |
665 if (temp == kNaClBadAddress) { | |
666 return -1; | |
667 } | |
668 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
669 } | |
670 NaClCopyDropLock(nap); | |
671 | |
672 result = MojoBeginReadData(data_pipe_consumer_handle, &buffer, &buffer_num _bytes, flags); | |
673 | |
674 NaClCopyTakeLock(nap); | |
675 *buffer_ptr = buffer; | |
676 *buffer_num_bytes_ptr = buffer_num_bytes; | |
677 *result_ptr = result; | |
678 NaClCopyDropLock(nap); | |
679 | |
680 return 0; | |
681 } | |
682 case 10: | |
683 { | |
684 if (numParams != 4) { | |
685 return -1; | |
686 } | |
687 NaClCopyTakeLock(nap); | |
688 MojoHandle data_pipe_consumer_handle; | |
689 if (params[1] == 0) { | |
690 return -1; | |
691 } else { | |
692 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(data_pipe _consumer_handle)); | |
693 if (temp == kNaClBadAddress) { | |
694 return -1; | |
695 } | |
696 data_pipe_consumer_handle = *reinterpret_cast<MojoHandle volatile*>(temp ); | |
697 } | |
698 uint32_t num_bytes_read; | |
699 if (params[2] == 0) { | |
700 return -1; | |
701 } else { | |
702 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(num_bytes _read)); | |
703 if (temp == kNaClBadAddress) { | |
704 return -1; | |
705 } | |
706 num_bytes_read = *reinterpret_cast<uint32_t volatile*>(temp); | |
707 } | |
708 MojoResult* result_ptr; | |
709 MojoResult result; | |
710 if (params[3] == 0) { | |
711 return -1; | |
712 } else { | |
713 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(result)); | |
714 if (temp == kNaClBadAddress) { | |
715 return -1; | |
716 } | |
717 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
718 } | |
719 NaClCopyDropLock(nap); | |
720 | |
721 result = MojoEndReadData(data_pipe_consumer_handle, num_bytes_read); | |
722 | |
723 NaClCopyTakeLock(nap); | |
724 *result_ptr = result; | |
725 NaClCopyDropLock(nap); | |
726 | |
727 return 0; | |
728 } | |
729 case 11: | |
730 { | |
731 if (numParams != 2) { | |
732 return -1; | |
733 } | |
734 NaClCopyTakeLock(nap); | |
735 MojoTimeTicks* result_ptr; | |
736 MojoTimeTicks result; | |
737 if (params[1] == 0) { | |
738 return -1; | |
739 } else { | |
740 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(result)); | |
741 if (temp == kNaClBadAddress) { | |
742 return -1; | |
743 } | |
744 result_ptr = reinterpret_cast<MojoTimeTicks*>(temp); | |
745 } | |
746 NaClCopyDropLock(nap); | |
747 | |
748 result = MojoGetTimeTicksNow(); | |
749 | |
750 NaClCopyTakeLock(nap); | |
751 *result_ptr = result; | |
752 NaClCopyDropLock(nap); | |
753 | |
754 return 0; | |
755 } | |
756 case 12: | |
757 { | |
758 if (numParams != 3) { | |
759 return -1; | |
760 } | |
761 NaClCopyTakeLock(nap); | |
762 MojoHandle handle; | |
763 if (params[1] == 0) { | |
764 return -1; | |
765 } else { | |
766 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(handle)); | |
767 if (temp == kNaClBadAddress) { | |
768 return -1; | |
769 } | |
770 handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
771 } | |
772 MojoResult* result_ptr; | |
773 MojoResult result; | |
774 if (params[2] == 0) { | |
775 return -1; | |
776 } else { | |
777 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(result)); | |
778 if (temp == kNaClBadAddress) { | |
779 return -1; | |
780 } | |
781 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
782 } | |
783 NaClCopyDropLock(nap); | |
784 | |
785 result = MojoClose(handle); | |
786 | |
787 NaClCopyTakeLock(nap); | |
788 *result_ptr = result; | |
789 NaClCopyDropLock(nap); | |
790 | |
791 return 0; | |
792 } | |
793 case 13: | |
794 { | |
795 if (numParams != 5) { | |
796 return -1; | |
797 } | |
798 NaClCopyTakeLock(nap); | |
799 MojoHandle handle; | |
800 if (params[1] == 0) { | |
801 return -1; | |
802 } else { | |
803 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(handle)); | |
804 if (temp == kNaClBadAddress) { | |
805 return -1; | |
806 } | |
807 handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
808 } | |
809 MojoHandleSignals signals; | |
810 if (params[2] == 0) { | |
811 return -1; | |
812 } else { | |
813 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(signals)) ; | |
814 if (temp == kNaClBadAddress) { | |
815 return -1; | |
816 } | |
817 signals = *reinterpret_cast<MojoHandleSignals volatile*>(temp); | |
818 } | |
819 MojoDeadline deadline; | |
820 if (params[3] == 0) { | |
821 return -1; | |
822 } else { | |
823 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(deadline) ); | |
824 if (temp == kNaClBadAddress) { | |
825 return -1; | |
826 } | |
827 deadline = *reinterpret_cast<MojoDeadline volatile*>(temp); | |
828 } | |
829 MojoResult* result_ptr; | |
830 MojoResult result; | |
831 if (params[4] == 0) { | |
832 return -1; | |
833 } else { | |
834 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(result)); | |
835 if (temp == kNaClBadAddress) { | |
836 return -1; | |
837 } | |
838 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
839 } | |
840 NaClCopyDropLock(nap); | |
841 | |
842 result = MojoWait(handle, signals, deadline); | |
843 | |
844 NaClCopyTakeLock(nap); | |
845 *result_ptr = result; | |
846 NaClCopyDropLock(nap); | |
847 | |
848 return 0; | |
849 } | |
850 case 14: | |
851 { | |
852 if (numParams != 6) { | |
853 return -1; | |
854 } | |
855 NaClCopyTakeLock(nap); | |
856 uint32_t num_handles; | |
857 if (params[3] == 0) { | |
858 return -1; | |
859 } else { | |
860 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_handl es)); | |
861 if (temp == kNaClBadAddress) { | |
862 return -1; | |
863 } | |
864 num_handles = *reinterpret_cast<uint32_t volatile*>(temp); | |
865 } | |
866 MojoDeadline deadline; | |
867 if (params[4] == 0) { | |
868 return -1; | |
869 } else { | |
870 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(deadline) ); | |
871 if (temp == kNaClBadAddress) { | |
872 return -1; | |
873 } | |
874 deadline = *reinterpret_cast<MojoDeadline volatile*>(temp); | |
875 } | |
876 const MojoHandle* handles; | |
877 if (params[1] == 0) { | |
878 return -1; | |
879 } else { | |
880 uintptr_t temp = NaClUserToSysAddrArray(nap, params[1], num_handles, siz eof(*handles)); | |
881 if (temp == kNaClBadAddress) { | |
882 return -1; | |
883 } | |
884 handles = reinterpret_cast<const MojoHandle*>(temp); | |
885 } | |
886 const MojoHandleSignals* signals; | |
887 if (params[2] == 0) { | |
888 return -1; | |
889 } else { | |
890 uintptr_t temp = NaClUserToSysAddrArray(nap, params[2], num_handles, siz eof(*signals)); | |
891 if (temp == kNaClBadAddress) { | |
892 return -1; | |
893 } | |
894 signals = reinterpret_cast<const MojoHandleSignals*>(temp); | |
895 } | |
896 MojoResult* result_ptr; | |
897 MojoResult result; | |
898 if (params[5] == 0) { | |
899 return -1; | |
900 } else { | |
901 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(result)); | |
902 if (temp == kNaClBadAddress) { | |
903 return -1; | |
904 } | |
905 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
906 } | |
907 NaClCopyDropLock(nap); | |
908 | |
909 result = MojoWaitMany(handles, signals, num_handles, deadline); | |
910 | |
911 NaClCopyTakeLock(nap); | |
912 *result_ptr = result; | |
913 NaClCopyDropLock(nap); | |
914 | |
915 return 0; | |
916 } | |
917 case 15: | |
918 { | |
919 if (numParams != 5) { | |
920 return -1; | |
921 } | |
922 NaClCopyTakeLock(nap); | |
923 const struct MojoCreateMessagePipeOptions* options; | |
924 if (params[1] == 0) { | |
925 options = NULL; | |
926 } else { | |
927 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(*options) ); | |
928 if (temp == kNaClBadAddress) { | |
929 return -1; | |
930 } | |
931 options = reinterpret_cast<const struct MojoCreateMessagePipeOptions*>(t emp); | |
932 } | |
933 MojoHandle* message_pipe_handle0_ptr; | |
934 MojoHandle message_pipe_handle0; | |
935 if (params[2] == 0) { | |
936 return -1; | |
937 } else { | |
938 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], sizeof(message_p ipe_handle0)); | |
939 if (temp == kNaClBadAddress) { | |
940 return -1; | |
941 } | |
942 message_pipe_handle0_ptr = reinterpret_cast<MojoHandle*>(temp); | |
943 } | |
944 MojoHandle* message_pipe_handle1_ptr; | |
945 MojoHandle message_pipe_handle1; | |
946 if (params[3] == 0) { | |
947 return -1; | |
948 } else { | |
949 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(message_p ipe_handle1)); | |
950 if (temp == kNaClBadAddress) { | |
951 return -1; | |
952 } | |
953 message_pipe_handle1_ptr = reinterpret_cast<MojoHandle*>(temp); | |
954 } | |
955 MojoResult* result_ptr; | |
956 MojoResult result; | |
957 if (params[4] == 0) { | |
958 return -1; | |
959 } else { | |
960 uintptr_t temp = NaClUserToSysAddrRange(nap, params[4], sizeof(result)); | |
961 if (temp == kNaClBadAddress) { | |
962 return -1; | |
963 } | |
964 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
965 } | |
966 NaClCopyDropLock(nap); | |
967 | |
968 result = MojoCreateMessagePipe(options, &message_pipe_handle0, &message_pi pe_handle1); | |
969 | |
970 NaClCopyTakeLock(nap); | |
971 *message_pipe_handle0_ptr = message_pipe_handle0; | |
972 *message_pipe_handle1_ptr = message_pipe_handle1; | |
973 *result_ptr = result; | |
974 NaClCopyDropLock(nap); | |
975 | |
976 return 0; | |
977 } | |
978 case 16: | |
979 { | |
980 if (numParams != 8) { | |
981 return -1; | |
982 } | |
983 NaClCopyTakeLock(nap); | |
984 MojoHandle message_pipe_handle; | |
985 if (params[1] == 0) { | |
986 return -1; | |
987 } else { | |
988 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(message_p ipe_handle)); | |
989 if (temp == kNaClBadAddress) { | |
990 return -1; | |
991 } | |
992 message_pipe_handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
993 } | |
994 uint32_t num_bytes; | |
995 if (params[3] == 0) { | |
996 return -1; | |
997 } else { | |
998 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_bytes )); | |
999 if (temp == kNaClBadAddress) { | |
1000 return -1; | |
1001 } | |
1002 num_bytes = *reinterpret_cast<uint32_t volatile*>(temp); | |
1003 } | |
1004 uint32_t num_handles; | |
1005 if (params[5] == 0) { | |
1006 return -1; | |
1007 } else { | |
1008 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(num_handl es)); | |
1009 if (temp == kNaClBadAddress) { | |
1010 return -1; | |
1011 } | |
1012 num_handles = *reinterpret_cast<uint32_t volatile*>(temp); | |
1013 } | |
1014 MojoWriteMessageFlags flags; | |
1015 if (params[6] == 0) { | |
1016 return -1; | |
1017 } else { | |
1018 uintptr_t temp = NaClUserToSysAddrRange(nap, params[6], sizeof(flags)); | |
1019 if (temp == kNaClBadAddress) { | |
1020 return -1; | |
1021 } | |
1022 flags = *reinterpret_cast<MojoWriteMessageFlags volatile*>(temp); | |
1023 } | |
1024 const void* bytes; | |
1025 if (params[2] == 0) { | |
1026 bytes = NULL; | |
1027 } else { | |
1028 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], num_bytes); | |
1029 if (temp == kNaClBadAddress) { | |
1030 return -1; | |
1031 } | |
1032 bytes = reinterpret_cast<const void*>(temp); | |
1033 } | |
1034 const MojoHandle* handles; | |
1035 if (params[4] == 0) { | |
1036 handles = NULL; | |
1037 } else { | |
1038 uintptr_t temp = NaClUserToSysAddrArray(nap, params[4], num_handles, siz eof(*handles)); | |
1039 if (temp == kNaClBadAddress) { | |
1040 return -1; | |
1041 } | |
1042 handles = reinterpret_cast<const MojoHandle*>(temp); | |
1043 } | |
1044 MojoResult* result_ptr; | |
1045 MojoResult result; | |
1046 if (params[7] == 0) { | |
1047 return -1; | |
1048 } else { | |
1049 uintptr_t temp = NaClUserToSysAddrRange(nap, params[7], sizeof(result)); | |
1050 if (temp == kNaClBadAddress) { | |
1051 return -1; | |
1052 } | |
1053 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
1054 } | |
1055 NaClCopyDropLock(nap); | |
1056 | |
1057 result = MojoWriteMessage(message_pipe_handle, bytes, num_bytes, handles, num_handles, flags); | |
1058 | |
1059 NaClCopyTakeLock(nap); | |
1060 *result_ptr = result; | |
1061 NaClCopyDropLock(nap); | |
1062 | |
1063 return 0; | |
1064 } | |
1065 case 17: | |
1066 { | |
1067 if (numParams != 8) { | |
1068 return -1; | |
1069 } | |
1070 NaClCopyTakeLock(nap); | |
1071 MojoHandle message_pipe_handle; | |
1072 if (params[1] == 0) { | |
1073 return -1; | |
1074 } else { | |
1075 uintptr_t temp = NaClUserToSysAddrRange(nap, params[1], sizeof(message_p ipe_handle)); | |
1076 if (temp == kNaClBadAddress) { | |
1077 return -1; | |
1078 } | |
1079 message_pipe_handle = *reinterpret_cast<MojoHandle volatile*>(temp); | |
1080 } | |
1081 uint32_t* num_bytes_ptr; | |
1082 uint32_t num_bytes; | |
1083 if (params[3] == 0) { | |
1084 num_bytes_ptr = NULL; | |
1085 num_bytes = 0; | |
1086 } else { | |
1087 uintptr_t temp = NaClUserToSysAddrRange(nap, params[3], sizeof(num_bytes )); | |
1088 if (temp == kNaClBadAddress) { | |
1089 return -1; | |
1090 } | |
1091 num_bytes_ptr = reinterpret_cast<uint32_t*>(temp); | |
1092 // In/Out | |
1093 num_bytes = *num_bytes_ptr; | |
1094 } | |
1095 uint32_t* num_handles_ptr; | |
1096 uint32_t num_handles; | |
1097 if (params[5] == 0) { | |
1098 num_handles_ptr = NULL; | |
1099 num_handles = 0; | |
1100 } else { | |
1101 uintptr_t temp = NaClUserToSysAddrRange(nap, params[5], sizeof(num_handl es)); | |
1102 if (temp == kNaClBadAddress) { | |
1103 return -1; | |
1104 } | |
1105 num_handles_ptr = reinterpret_cast<uint32_t*>(temp); | |
1106 // In/Out | |
1107 num_handles = *num_handles_ptr; | |
1108 } | |
1109 MojoReadMessageFlags flags; | |
1110 if (params[6] == 0) { | |
1111 return -1; | |
1112 } else { | |
1113 uintptr_t temp = NaClUserToSysAddrRange(nap, params[6], sizeof(flags)); | |
1114 if (temp == kNaClBadAddress) { | |
1115 return -1; | |
1116 } | |
1117 flags = *reinterpret_cast<MojoReadMessageFlags volatile*>(temp); | |
1118 } | |
1119 void* bytes; | |
1120 if (params[2] == 0) { | |
1121 bytes = NULL; | |
1122 } else { | |
1123 uintptr_t temp = NaClUserToSysAddrRange(nap, params[2], num_bytes); | |
1124 if (temp == kNaClBadAddress) { | |
1125 return -1; | |
1126 } | |
1127 bytes = reinterpret_cast<void*>(temp); | |
1128 } | |
1129 MojoHandle* handles; | |
1130 if (params[4] == 0) { | |
1131 handles = NULL; | |
1132 } else { | |
1133 uintptr_t temp = NaClUserToSysAddrArray(nap, params[4], num_handles, siz eof(*handles)); | |
1134 if (temp == kNaClBadAddress) { | |
1135 return -1; | |
1136 } | |
1137 handles = reinterpret_cast<MojoHandle*>(temp); | |
1138 } | |
1139 MojoResult* result_ptr; | |
1140 MojoResult result; | |
1141 if (params[7] == 0) { | |
1142 return -1; | |
1143 } else { | |
1144 uintptr_t temp = NaClUserToSysAddrRange(nap, params[7], sizeof(result)); | |
1145 if (temp == kNaClBadAddress) { | |
1146 return -1; | |
1147 } | |
1148 result_ptr = reinterpret_cast<MojoResult*>(temp); | |
1149 } | |
1150 NaClCopyDropLock(nap); | |
1151 | |
1152 result = MojoReadMessage(message_pipe_handle, bytes, num_bytes_ptr ? &num_ bytes : NULL, handles, num_handles_ptr ? &num_handles : NULL, flags); | |
1153 | |
1154 NaClCopyTakeLock(nap); | |
1155 if (num_bytes_ptr != NULL) { | |
1156 *num_bytes_ptr = num_bytes; | |
1157 } | |
1158 if (num_handles_ptr != NULL) { | |
1159 *num_handles_ptr = num_handles; | |
1160 } | |
1161 *result_ptr = result; | |
1162 NaClCopyDropLock(nap); | |
1163 | |
1164 return 0; | |
1165 } | |
1166 | |
1167 default: | |
1168 return -1; | |
1169 } | |
1170 | |
1171 return -1; | |
1172 } | |
1173 | |
1174 ssize_t MojoDescRecvMsg(void *handle, | |
1175 struct NaClImcTypedMsgHdr *msg, | |
1176 int flags) { | |
1177 UNREFERENCED_PARAMETER(handle); | |
1178 UNREFERENCED_PARAMETER(msg); | |
1179 UNREFERENCED_PARAMETER(flags); | |
1180 | |
1181 NaClLog(LOG_FATAL, "MojoDescRecvMsg: Not implemented\n"); | |
1182 return 0; | |
1183 } | |
1184 | |
1185 struct NaClDesc *MakeMojoDesc(struct NaClApp *nap) { | |
1186 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; | |
1187 funcs.Destroy = MojoDescDestroy; | |
1188 funcs.SendMsg = MojoDescSendMsg; | |
1189 funcs.RecvMsg = MojoDescRecvMsg; | |
1190 return NaClDescMakeCustomDesc(nap, &funcs); | |
1191 } | |
1192 | |
1193 #define NACL_MOJO_DESC 5 | |
1194 | |
1195 void InjectMojo(struct NaClApp *nap) { | |
1196 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); | |
1197 } | |
OLD | NEW |