Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: tests/stacked_irt/irt_trace.c

Issue 25027006: Stackable IRT Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/stacked_irt/irt_trace.h ('k') | tests/stacked_irt/nacl.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <string.h>
8
9 #include <stdarg.h>
10 #include <stddef.h>
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <time.h>
14
15 #include "native_client/src/include/nacl_macros.h"
16 #include "native_client/src/include/portability.h"
17 #include "native_client/src/untrusted/irt/irt.h"
18 #include "native_client/src/untrusted/irt/irt_interfaces.h"
19 #include "native_client/src/untrusted/irt/irt_module.h"
20
21 #include "native_client/tests/stacked_irt/irt_trace.h"
22
23 #include "native_client/src/untrusted/nacl/nacl_irt.h"
24
25 static struct nacl_irt_basic __nacl_irt_basic;
26 static struct nacl_irt_fdio __nacl_irt_fdio;
27 static struct nacl_irt_dev_filename __nacl_irt_dev_filename;
28 static struct nacl_irt_memory __nacl_irt_memory;
29 static struct nacl_irt_dyncode __nacl_irt_dyncode;
30 static struct nacl_irt_thread __nacl_irt_thread;
31 static struct nacl_irt_futex __nacl_irt_futex;
32 static struct nacl_irt_mutex __nacl_irt_mutex;
33 static struct nacl_irt_cond __nacl_irt_cond;
34 static struct nacl_irt_sem __nacl_irt_sem;
35 static struct nacl_irt_tls __nacl_irt_tls;
36 static struct nacl_irt_blockhook __nacl_irt_blockhook;
37 #ifdef IRT_PPAPI
38 static struct nacl_irt_ppapihook __nacl_irt_ppapihook;
39 #endif
40 static struct nacl_irt_resource_open __nacl_irt_resource_open;
41 static struct nacl_irt_random __nacl_irt_random;
42 static struct nacl_irt_clock __nacl_irt_clock;
43 static struct nacl_irt_exception_handling __nacl_irt_exception_handling;
44
45 struct irt_trace {
46 int timestamp;
47 };
48
49 static struct irt_trace *irt_trace_get(void) {
50 return (struct irt_trace *) nacl_irt_get_context()->private_data;
51 }
52
53 size_t irt_vdprintf(int d, char const *fmt, va_list ap) {
54 static char buf[1024];
55 int rv;
56 size_t wrote;
57
58 /*
59 * We cannot dynamically allocate the buffer here since malloc
60 * internally uses mmap/munmap/sysbrk which could potentially
61 * lead to an infinite loop.
62 */
63 rv = vsnprintf(buf, sizeof buf, fmt, ap);
64 if (rv >= 0) {
65 __nacl_irt_fdio.write(d, buf, rv, &wrote); /* TODO: check rv */
66 rv = wrote;
67 }
68
69 return rv;
70 }
71
72 size_t irt_dprintf(int d, char const *fmt, ...) {
73 va_list ap;
74 size_t rv;
75
76 va_start(ap, fmt);
77 rv = irt_vdprintf(d, fmt, ap);
78 va_end(ap);
79
80 return rv;
81 }
82
83 char *irt_timestamp_string(char *buf,
84 size_t size) {
85 struct timeval tv;
86 struct tm bdt; /* broken down time */
87
88 if (-1 == __nacl_irt_basic.gettod(&tv)) {
89 snprintf(buf, size, "-NA-");
90 return buf;
91 }
92 (void) localtime_r(&tv.tv_sec, &bdt);
93 /* suseconds_t holds at most 10**6 < 16**6 = (2**4)**6 = 2**24 < 2**32 */
94 snprintf(buf, size, "%02d:%02d:%02d.%06d",
95 bdt.tm_hour, bdt.tm_min, bdt.tm_sec, (int) tv.tv_usec);
96 return buf;
97 }
98
99 static void irt_output_tag(int d) {
100 struct irt_trace *trace = irt_trace_get();
101 char timestamp[128];
102 /*int pid; */
103
104 if (trace->timestamp) {
105 irt_dprintf(d, "[%s] ",
106 irt_timestamp_string(timestamp, sizeof timestamp));
107 }
108 /*if (timestamp_enabled && tag_output) {
109 pid = GETPID();
110 gprintf(s, "[%d,%u:%s] ",
111 pid,
112 NaClThreadId(),
113 NaClTimeStampString(timestamp, sizeof timestamp));
114 tag_output = 0;
115 }*/
116 }
117
118 #if 0
119 #define IRT_TRACE_CALL(name) do { \
120 static const char msg[] = ""name"\n"; \
121 size_t wrote; \
122 __nacl_irt_fdio.write(2, msg, sizeof(msg) - 1, &wrote); \
123 } while (0);
124 #else
125 #define IRT_TRACE_CALL(name) do { \
126 static char msg[100]; \
127 int length; \
128 size_t wrote; \
129 length = snprintf(msg, sizeof(msg), "%s() = 0\n", name); \
130 __nacl_irt_fdio.write(2, msg, length, &wrote); \
131 } while (0);
132 #define IRT_TRACE_CALL1(interface, name) do { \
133 static char msg[100]; \
134 int length; \
135 size_t wrote; \
136 irt_output_tag(2); \
137 length = snprintf(msg, sizeof(msg), "%s.%s()%20s", interface, name, ""); \
138 __nacl_irt_fdio.write(2, msg, length, &wrote); \
139 } while (0);
140 #endif
141
142 static void irt_trace_exit(int status) {
143 IRT_TRACE_CALL1("basic", "exit");
144 __nacl_irt_basic.exit(status);
145 }
146
147 static int irt_trace_gettod(struct timeval *tv) {
148 IRT_TRACE_CALL1("basic", "gettod");
149 return __nacl_irt_basic.gettod(tv);
150 }
151
152 static int irt_trace_clock(clock_t *ticks) {
153 IRT_TRACE_CALL1("basic", "clock");
154 return __nacl_irt_basic.clock(ticks);
155 }
156
157 static int irt_trace_nanosleep(const struct timespec *req, struct timespec *rem) {
158 IRT_TRACE_CALL1("basic", "nanosleep");
159 return __nacl_irt_basic.nanosleep(req, rem);
160 }
161
162 static int irt_trace_sched_yield(void) {
163 IRT_TRACE_CALL1("basic", "sched_yield");
164 return __nacl_irt_basic.sched_yield();
165 }
166
167 static int irt_trace_sysconf(int name, int *value) {
168 int rv;
169 IRT_TRACE_CALL1("basic", "sysconf");
170 rv = __nacl_irt_basic.sysconf(name, value);
171 irt_dprintf(2, " = %d\n", rv);
172 return rv;
173 }
174
175 static struct nacl_irt_basic logged_nacl_irt_basic = {
176 irt_trace_exit,
177 irt_trace_gettod,
178 irt_trace_clock,
179 irt_trace_nanosleep,
180 irt_trace_sched_yield,
181 irt_trace_sysconf,
182 };
183
184 static int irt_trace_close(int fd) {
185 int rv;
186 /*IRT_TRACE_CALL1("fdio", "close");*/
187 irt_dprintf(2, "fdio.close(%d", fd);
188 rv = __nacl_irt_fdio.close(fd);
189 irt_dprintf(2, ")%20s = %d\n", "", rv);
190 return rv;
191 }
192
193 static int irt_trace_read(int fd, void *buf, size_t count, size_t *nread) {
194 IRT_TRACE_CALL1("fdio", "read");
195 return __nacl_irt_fdio.read(fd, buf, count, nread);
196 }
197
198 static int irt_trace_write(int fd, const void *buf, size_t count,
199 size_t *nwrote) {
200 int rv;
201 /*IRT_TRACE_CALL1("fdio", "write");*/
202 irt_dprintf(2, "fdio.write(%d, \"%s\", %zd, %p)", fd, buf, count, nwrote);
203 rv = __nacl_irt_fdio.write(fd, buf, count, nwrote);
204 irt_dprintf(2, " = %d\n", rv);
205 return rv;
206 }
207
208 static int irt_trace_seek(int fd, off_t offset, int whence, off_t *new_offset) {
209 IRT_TRACE_CALL1("fdio", "seek");
210 return __nacl_irt_fdio.seek(fd, offset, whence, new_offset);
211 }
212
213 static int irt_trace_dup(int fd, int *newfd) {
214 IRT_TRACE_CALL1("fdio", "dup");
215 return __nacl_irt_fdio.dup(fd, newfd);
216 }
217
218 static int irt_trace_dup2(int fd, int newfd) {
219 IRT_TRACE_CALL1("fdio", "dup2");
220 return __nacl_irt_fdio.dup2(fd, newfd);
221 }
222
223 static int irt_trace_fstat(int fd, struct stat *st) {
224 int rv;
225 /*IRT_TRACE_CALL1("fdio", "fstat");*/
226 irt_dprintf(2, "fdio.fstat(%d, %x)", fd);
227 rv = __nacl_irt_fdio.fstat(fd, st);
228 irt_dprintf(2, "%20s = %d\n", "", rv);
229 return rv;
230 }
231
232 static int irt_trace_getdents(int fd, struct dirent *buf, size_t count,
233 size_t *nread) {
234 IRT_TRACE_CALL1("fdio", "getdents");
235 return __nacl_irt_fdio.getdents(fd, buf, count, nread);
236 }
237
238 static struct nacl_irt_fdio logged_nacl_irt_fdio = {
239 irt_trace_close,
240 irt_trace_dup,
241 irt_trace_dup2,
242 irt_trace_read,
243 irt_trace_write,
244 irt_trace_seek,
245 irt_trace_fstat,
246 irt_trace_getdents,
247 };
248
249 static int irt_trace_open(const char *pathname, int oflag, mode_t cmode, int *ne wfd) {
250 IRT_TRACE_CALL("open");
251 return __nacl_irt_dev_filename.open(pathname, oflag, cmode, newfd);
252 }
253
254 static int irt_trace_stat(const char *pathname, struct stat *buf) {
255 IRT_TRACE_CALL("stat");
256 return __nacl_irt_dev_filename.stat(pathname, buf);
257 }
258
259 static int irt_trace_mkdir(const char *pathname, mode_t mode) {
260 IRT_TRACE_CALL("mkdir");
261 return __nacl_irt_dev_filename.mkdir(pathname, mode);
262 }
263
264 static int irt_trace_rmdir(const char *pathname) {
265 IRT_TRACE_CALL("rmdir");
266 return __nacl_irt_dev_filename.rmdir(pathname);
267 }
268
269 static int irt_trace_chdir(const char *pathname) {
270 IRT_TRACE_CALL("chdir");
271 return __nacl_irt_dev_filename.chdir(pathname);
272 }
273
274 static int irt_trace_getcwd(char *pathname, size_t len) {
275 IRT_TRACE_CALL("getcwd");
276 return __nacl_irt_dev_filename.getcwd(pathname, len);
277 }
278
279 static int irt_trace_unlink(const char *pathname) {
280 IRT_TRACE_CALL("unlink");
281 return __nacl_irt_dev_filename.unlink(pathname);
282 }
283
284 static struct nacl_irt_dev_filename logged_nacl_irt_dev_filename = {
285 irt_trace_open,
286 irt_trace_stat,
287 irt_trace_mkdir,
288 irt_trace_rmdir,
289 irt_trace_chdir,
290 irt_trace_getcwd,
291 irt_trace_unlink,
292 };
293
294 static int irt_trace_mmap(void **addr, size_t len, int prot, int flags, int fd, off_t off) {
295 IRT_TRACE_CALL("mmap");
296 return __nacl_irt_memory.mmap(addr, len, prot, flags, fd, off);
297 }
298 static int irt_trace_munmap(void *addr, size_t len) {
299 IRT_TRACE_CALL("munmap");
300 return __nacl_irt_memory.munmap(addr, len);
301 }
302 static int irt_trace_mprotect(void *addr, size_t len, int prot) {
303 IRT_TRACE_CALL("mprotect");
304 return __nacl_irt_memory.mprotect(addr, len, prot);
305 }
306
307 static struct nacl_irt_memory logged_nacl_irt_memory = {
308 irt_trace_mmap,
309 irt_trace_munmap,
310 irt_trace_mprotect,
311 };
312
313 static int irt_trace_dyncode_create(void *dest, const void *src, size_t size) {
314 IRT_TRACE_CALL("dyncode_create");
315 return __nacl_irt_dyncode.dyncode_create(dest, src, size);
316 }
317 static int irt_trace_dyncode_modify(void *dest, const void *src, size_t size) {
318 IRT_TRACE_CALL("dyncode_modify");
319 return __nacl_irt_dyncode.dyncode_modify(dest, src, size);
320 }
321 static int irt_trace_dyncode_delete(void *dest, size_t size) {
322 IRT_TRACE_CALL("dyncode_delete");
323 return __nacl_irt_dyncode.dyncode_delete(dest, size);
324 }
325
326 static struct nacl_irt_dyncode logged_nacl_irt_dyncode = {
327 irt_trace_dyncode_create,
328 irt_trace_dyncode_modify,
329 irt_trace_dyncode_delete,
330 };
331
332 static int irt_trace_thread_create(void (*start_func)(void), void *stack, void * thread_ptr) {
333 IRT_TRACE_CALL("thread_create");
334 return __nacl_irt_thread.thread_create(start_func, stack, thread_ptr);
335 }
336 static void irt_trace_thread_exit(int32_t *stack_flag) {
337 IRT_TRACE_CALL("thread_exit");
338 __nacl_irt_thread.thread_exit(stack_flag);
339 }
340 static int irt_trace_thread_nice(const int nice) {
341 IRT_TRACE_CALL("thread_nice");
342 return __nacl_irt_thread.thread_nice(nice);
343 }
344
345 static struct nacl_irt_thread logged_nacl_irt_thread = {
346 irt_trace_thread_create,
347 irt_trace_thread_exit,
348 irt_trace_thread_nice,
349 };
350
351 static int irt_trace_futex_wait_abs(volatile int *addr, int value, const struct timespec *abstime) {
352 IRT_TRACE_CALL("futex_wait_abs");
353 return __nacl_irt_futex.futex_wait_abs(addr, value, abstime);
354 }
355 static int irt_trace_futex_wake(volatile int *addr, int nwake, int *count) {
356 IRT_TRACE_CALL("futex_wake");
357 return __nacl_irt_futex.futex_wake(addr, nwake, count);
358 }
359
360 static struct nacl_irt_futex logged_nacl_irt_futex = {
361 irt_trace_futex_wait_abs,
362 irt_trace_futex_wake,
363 };
364
365 static int irt_trace_mutex_create(int *mutex_handle) {
366 IRT_TRACE_CALL("mutex_create");
367 return __nacl_irt_mutex.mutex_create(mutex_handle);
368 }
369 static int irt_trace_mutex_destroy(int mutex_handle) {
370 IRT_TRACE_CALL("mutex_destroy");
371 return __nacl_irt_mutex.mutex_destroy(mutex_handle);
372 }
373 static int irt_trace_mutex_lock(int mutex_handle) {
374 IRT_TRACE_CALL("mutex_lock");
375 return __nacl_irt_mutex.mutex_lock(mutex_handle);
376 }
377 static int irt_trace_mutex_unlock(int mutex_handle) {
378 IRT_TRACE_CALL("mutex_unlock");
379 return __nacl_irt_mutex.mutex_unlock(mutex_handle);
380 }
381 static int irt_trace_mutex_trylock(int mutex_handle) {
382 IRT_TRACE_CALL("mutex_trylock");
383 return __nacl_irt_mutex.mutex_trylock(mutex_handle);
384 }
385
386 static struct nacl_irt_mutex logged_nacl_irt_mutex = {
387 irt_trace_mutex_create,
388 irt_trace_mutex_destroy,
389 irt_trace_mutex_lock,
390 irt_trace_mutex_unlock,
391 irt_trace_mutex_trylock,
392 };
393
394 static int irt_trace_cond_create(int *cond_handle) {
395 IRT_TRACE_CALL("cond_create");
396 return __nacl_irt_cond.cond_create(cond_handle);
397 }
398 static int irt_trace_cond_destroy(int cond_handle) {
399 IRT_TRACE_CALL("cond_destroy");
400 return __nacl_irt_cond.cond_destroy(cond_handle);
401 }
402 static int irt_trace_cond_signal(int cond_handle) {
403 IRT_TRACE_CALL("cond_signal");
404 return __nacl_irt_cond.cond_signal(cond_handle);
405 }
406 static int irt_trace_cond_broadcast(int cond_handle) {
407 IRT_TRACE_CALL("cond_broadcast");
408 return __nacl_irt_cond.cond_broadcast(cond_handle);
409 }
410 static int irt_trace_cond_wait(int cond_handle, int mutex_handle) {
411 IRT_TRACE_CALL("cond_wait");
412 return __nacl_irt_cond.cond_wait(cond_handle, mutex_handle);
413 }
414 static int irt_trace_cond_timed_wait_abs(int cond_handle, int mutex_handle, cons t struct timespec *abstime) {
415 IRT_TRACE_CALL("cond_timed_wait_abs");
416 return __nacl_irt_cond.cond_timed_wait_abs(cond_handle, mutex_handle, abstime) ;
417 }
418
419 static struct nacl_irt_cond logged_nacl_irt_cond = {
420 irt_trace_cond_create,
421 irt_trace_cond_destroy,
422 irt_trace_cond_signal,
423 irt_trace_cond_broadcast,
424 irt_trace_cond_wait,
425 irt_trace_cond_timed_wait_abs,
426 };
427
428 static int irt_trace_sem_create(int *sem_handle, int32_t value) {
429 IRT_TRACE_CALL("sem_create");
430 return __nacl_irt_sem.sem_create(sem_handle, value);
431 }
432 static int irt_trace_sem_destroy(int sem_handle) {
433 IRT_TRACE_CALL("sem_destroy");
434 return __nacl_irt_sem.sem_destroy(sem_handle);
435 }
436 static int irt_trace_sem_post(int sem_handle) {
437 IRT_TRACE_CALL("sem_post");
438 return __nacl_irt_sem.sem_post(sem_handle);
439 }
440 static int irt_trace_sem_wait(int sem_handle) {
441 IRT_TRACE_CALL("sem_wait");
442 return __nacl_irt_sem.sem_wait(sem_handle);
443 }
444
445 static struct nacl_irt_sem logged_nacl_irt_sem = {
446 irt_trace_sem_create,
447 irt_trace_sem_destroy,
448 irt_trace_sem_post,
449 irt_trace_sem_wait,
450 };
451
452 static int irt_trace_tls_init(void *thread_ptr) {
453 IRT_TRACE_CALL("tls_init");
454 return __nacl_irt_tls.tls_init(thread_ptr);
455 }
456 static void *irt_trace_tls_get(void) {
457 IRT_TRACE_CALL("tls_get");
458 return __nacl_irt_tls.tls_get();
459 }
460
461 static struct nacl_irt_tls logged_nacl_irt_tls = {
462 irt_trace_tls_init,
463 irt_trace_tls_get,
464 };
465
466 static int irt_trace_register_block_hooks(void (*pre)(void), void (*post)(void)) {
467 IRT_TRACE_CALL("register_block_hooks");
468 return __nacl_irt_blockhook.register_block_hooks(pre, post);
469 }
470
471 static struct nacl_irt_blockhook logged_nacl_irt_blockhook = {
472 irt_trace_register_block_hooks,
473 };
474
475 #ifdef IRT_PPAPI
476 static int irt_trace_ppapi_start(const struct PP_StartFunctions *) {
477 IRT_TRACE_CALL("ppapi_start");
478 return __nacl_irt_ppapihook.ppapi_start(funcs);
479 }
480 static void irt_trace_ppapi_register_thread_creator(const struct PP_ThreadFuncti ons *funcs) {
481 IRT_TRACE_CALL("ppapi_register_thread_creator");
482 return __nacl_irt_ppapihook.ppapi_register_thread_creator(funcs);
483 }
484
485 static struct nacl_irt_ppapihook logged_nacl_irt_ppapihook = {
486 irt_trace_ppapi_start,
487 irt_trace_ppapi_register_thread_creator,
488 }
489 #endif
490
491 static int irt_trace_open_resource(const char *file, int *fd) {
492 IRT_TRACE_CALL("open_resource");
493 return __nacl_irt_resource_open.open_resource(file, fd);
494 }
495
496 static struct nacl_irt_resource_open logged_nacl_irt_resource_open = {
497 irt_trace_open_resource,
498 };
499
500 static int irt_trace_get_random_bytes(void *buf, size_t count, size_t *nread) {
501 IRT_TRACE_CALL("get_random_bytes");
502 return __nacl_irt_random.get_random_bytes(buf, count, nread);
503 }
504
505 static struct nacl_irt_random logged_nacl_irt_random = {
506 irt_trace_get_random_bytes,
507 };
508
509 static int irt_trace_clock_getres(clockid_t clk_id, struct timespec *res) {
510 IRT_TRACE_CALL("clock_getres");
511 return __nacl_irt_clock.clock_getres(clk_id, res);
512 }
513 static int irt_trace_clock_gettime(clockid_t clk_id, struct timespec *tp) {
514 IRT_TRACE_CALL("clock_gettime");
515 return __nacl_irt_clock.clock_gettime(clk_id, tp);
516 }
517
518 static struct nacl_irt_clock logged_nacl_irt_clock = {
519 irt_trace_clock_getres,
520 irt_trace_clock_gettime,
521 };
522
523 static int irt_trace_exception_handler(NaClExceptionHandler handler,
524 NaClExceptionHandler *old_handler) {
525 IRT_TRACE_CALL("exception_handler");
526 return __nacl_irt_exception_handling.exception_handler(handler, old_handler);
527 }
528 static int irt_trace_exception_stack(void *stack, size_t size) {
529 IRT_TRACE_CALL("exception_stack");
530 return __nacl_irt_exception_handling.exception_stack(stack, size);
531 }
532 static int irt_trace_exception_clear_flag(void) {
533 IRT_TRACE_CALL("exception_clear_flag");
534 return __nacl_irt_exception_handling.exception_clear_flag();
535 }
536
537 static struct nacl_irt_exception_handling logged_nacl_irt_exception_handling = {
538 irt_trace_exception_handler,
539 irt_trace_exception_stack,
540 irt_trace_exception_clear_flag,
541 };
542
543 static int irt_trace_init(void) {
544 /*struct irt_trace *trace = irt_trace_get();*/
545 fprintf(stderr, "irt_trace_init\n");
546 /*IRT_TRACE_CALL("init");*/
547 /*return __nacl_irt_instance.init(trace->next, );*/
548 /**data = trace;*/
549 return 0;
550 }
551 static void irt_trace_destroy(void) {
552 /*struct irt_trace *trace = irt_trace_get();*/
553 IRT_TRACE_CALL("destroy");
554 }
555
556 static struct nacl_irt_instance logged_nacl_irt_instance = {
557 irt_trace_init,
558 irt_trace_destroy,
559 };
560
561 /*static TYPE_nacl_irt_query nacl_irt_query;*/
562
563 struct nacl_interface_table {
564 const char *name;
565 const void *table;
566 size_t size;
567 };
568
569 static const struct nacl_interface_table irt_trace_interfaces[] = {
570 { NACL_IRT_INSTANCE_v0_1, &logged_nacl_irt_instance, sizeof(logged_nacl_irt_in stance) },
571 { NACL_IRT_BASIC_v0_1, &logged_nacl_irt_basic, sizeof(logged_nacl_irt_basic) } ,
572 { NACL_IRT_FDIO_v0_1, &logged_nacl_irt_fdio, sizeof(logged_nacl_irt_fdio) },
573 { NACL_IRT_DEV_FILENAME_v0_2, &logged_nacl_irt_dev_filename, sizeof(logged_nac l_irt_dev_filename) },
574 { NACL_IRT_MEMORY_v0_3, &logged_nacl_irt_memory, sizeof(logged_nacl_irt_memory ) },
575 { NACL_IRT_DYNCODE_v0_1, &logged_nacl_irt_dyncode, sizeof(logged_nacl_irt_dync ode) },
576 { NACL_IRT_THREAD_v0_1, &logged_nacl_irt_thread, sizeof(logged_nacl_irt_thread ) },
577 { NACL_IRT_FUTEX_v0_1, &logged_nacl_irt_futex, sizeof(logged_nacl_irt_futex) } ,
578 { NACL_IRT_MUTEX_v0_1, &logged_nacl_irt_mutex, sizeof(logged_nacl_irt_mutex) } ,
579 { NACL_IRT_COND_v0_1, &logged_nacl_irt_cond, sizeof(logged_nacl_irt_cond) },
580 { NACL_IRT_SEM_v0_1, &logged_nacl_irt_sem, sizeof(logged_nacl_irt_sem) },
581 { NACL_IRT_TLS_v0_1, &logged_nacl_irt_tls, sizeof(logged_nacl_irt_tls) },
582 { NACL_IRT_BLOCKHOOK_v0_1, &logged_nacl_irt_blockhook, sizeof(logged_nacl_irt_ blockhook) },
583 { NACL_IRT_RESOURCE_OPEN_v0_1, &logged_nacl_irt_resource_open,
584 sizeof(logged_nacl_irt_resource_open) },
585 #ifdef IRT_PPAPI
586 { NACL_IRT_PPAPIHOOK_v0_1, &logged_nacl_irt_ppapihook, sizeof(logged_nacl_irt_ ppapihook) },
587 #endif
588 { NACL_IRT_RANDOM_v0_1, &logged_nacl_irt_random, sizeof(logged_nacl_irt_random ) },
589 { NACL_IRT_CLOCK_v0_1, &logged_nacl_irt_clock, sizeof(logged_nacl_irt_clock) } ,
590 { NACL_IRT_EXCEPTION_HANDLING_v0_1, &logged_nacl_irt_exception_handling,
591 sizeof(logged_nacl_irt_exception_handling) },
592 };
593
594 static size_t irt_trace_interface(const char *interface_ident,
595 void *table, size_t tablesize) {
596 int i;
597 for (i = 0; i < NACL_ARRAY_SIZE(irt_trace_interfaces); ++i) {
598 if (0 == strcmp(interface_ident, irt_trace_interfaces[i].name)) {
599 const size_t size = irt_trace_interfaces[i].size;
600 if (size <= tablesize) {
601 memcpy(table, irt_trace_interfaces[i].table, size);
602 return size;
603 }
604 break;
605 }
606 }
607 return 0;
608 }
609
610 /*
611 TYPE_nacl_irt_query irt_trace_module_query(TYPE_nacl_irt_query nacl_irt_query) {
612 if (nacl_irt_query(NACL_IRT_BASIC_v0_1, &__nacl_irt_basic,
613 sizeof(__nacl_irt_basic)) == sizeof(__nacl_irt_basic)) {
614 }
615 if (nacl_irt_query(NACL_IRT_FDIO_v0_1, &__nacl_irt_fdio,
616 sizeof(__nacl_irt_fdio)) == sizeof(__nacl_irt_fdio)) {
617 }
618 if (nacl_irt_query(NACL_IRT_DEV_FILENAME_v0_2, &__nacl_irt_dev_filename,
619 sizeof(__nacl_irt_dev_filename)) == sizeof(__nacl_irt_dev_f ilename)) {
620 }
621 if (nacl_irt_query(NACL_IRT_MEMORY_v0_3, &__nacl_irt_memory,
622 sizeof(__nacl_irt_memory)) == sizeof(__nacl_irt_memory)) {
623 }
624 if (nacl_irt_query(NACL_IRT_DYNCODE_v0_1, &__nacl_irt_dyncode,
625 sizeof(__nacl_irt_dyncode)) == sizeof(__nacl_irt_basic)) {
626 }
627 if (nacl_irt_query(NACL_IRT_THREAD_v0_1, &__nacl_irt_thread,
628 sizeof(__nacl_irt_thread)) == sizeof(__nacl_irt_basic)) {
629 }
630 if (nacl_irt_query(NACL_IRT_FUTEX_v0_1, &__nacl_irt_futex,
631 sizeof(__nacl_irt_futex)) == sizeof(__nacl_irt_basic)) {
632 }
633 if (nacl_irt_query(NACL_IRT_MUTEX_v0_1, &__nacl_irt_mutex,
634 sizeof(__nacl_irt_mutex)) == sizeof(__nacl_irt_basic)) {
635 }
636 if (nacl_irt_query(NACL_IRT_COND_v0_1, &__nacl_irt_cond,
637 sizeof(__nacl_irt_cond)) == sizeof(__nacl_irt_basic)) {
638 }
639 if (nacl_irt_query(NACL_IRT_SEM_v0_1, &__nacl_irt_sem,
640 sizeof(__nacl_irt_sem)) == sizeof(__nacl_irt_basic)) {
641 }
642 if (nacl_irt_query(NACL_IRT_TLS_v0_1, &__nacl_irt_tls,
643 sizeof(__nacl_irt_tls)) == sizeof(__nacl_irt_basic)) {
644 }
645 if (nacl_irt_query(NACL_IRT_BLOCKHOOK_v0_1, &__nacl_irt_blockhook,
646 sizeof(__nacl_irt_blockhook)) == sizeof(__nacl_irt_blockhoo k)) {
647 }
648 #ifdef IRT_PPAPI
649 if (nacl_irt_query(NACL_IRT_PPAPIHOOK_v0_1, &__nacl_irt_ppapihook,
650 sizeof(__nacl_irt_ppapihook)) == sizeof(__nacl_irt_basic)) {
651 }
652 #endif
653 if (nacl_irt_query(NACL_IRT_RESOURCE_OPEN_v0_1, &__nacl_irt_resource_open,
654 sizeof(__nacl_irt_resource_open)) == sizeof(__nacl_irt_basi c)) {
655 }
656 if (nacl_irt_query(NACL_IRT_RANDOM_v0_1, &__nacl_irt_random,
657 sizeof(__nacl_irt_random)) == sizeof(__nacl_irt_basic)) {
658 }
659 if (nacl_irt_query(NACL_IRT_CLOCK_v0_1, &__nacl_irt_clock,
660 sizeof(__nacl_irt_clock)) == sizeof(__nacl_irt_basic)) {
661 }
662 if (nacl_irt_query(NACL_IRT_EXCEPTION_HANDLING_v0_1, &__nacl_irt_exception_han dling,
663 sizeof(__nacl_irt_exception_handling)) == sizeof(__nacl_irt _basic)) {
664 }
665
666 return irt_trace_interface;
667 }
668 */
669
670 #if 0
671 void irt_logged_module_init(void) {
672 nacl_irt_module_register(irt_logged_module_query);
673 }
674
675 void irt_logged_module_fini(void) {
676 }
677 #endif
678
679 void irt_trace_module_init(void) {
680 if (nacl_irt_interface_set(NACL_IRT_BASIC_v0_1, &logged_nacl_irt_basic,
681 sizeof(logged_nacl_irt_basic), &__nacl_irt_basic) == sizeof (logged_nacl_irt_basic)) {
682 }
683 if (nacl_irt_interface_set(NACL_IRT_FDIO_v0_1, &logged_nacl_irt_fdio,
684 sizeof(logged_nacl_irt_fdio), &__nacl_irt_fdio) == sizeof(l ogged_nacl_irt_fdio)) {
685 }
686 if (nacl_irt_interface_set(NACL_IRT_DEV_FILENAME_v0_2, &logged_nacl_irt_dev_fi lename,
687 sizeof(logged_nacl_irt_dev_filename), &__nacl_irt_dev_filen ame) == sizeof(logged_nacl_irt_dev_filename)) {
688 }
689 if (nacl_irt_interface_set(NACL_IRT_MEMORY_v0_3, &logged_nacl_irt_memory,
690 sizeof(logged_nacl_irt_memory), &__nacl_irt_memory) == size of(logged_nacl_irt_memory)) {
691 }
692 if (nacl_irt_interface_set(NACL_IRT_DYNCODE_v0_1, &logged_nacl_irt_dyncode,
693 sizeof(logged_nacl_irt_dyncode), &__nacl_irt_dyncode) == si zeof(logged_nacl_irt_dyncode)) {
694 }
695 if (nacl_irt_interface_set(NACL_IRT_THREAD_v0_1, &logged_nacl_irt_thread,
696 sizeof(logged_nacl_irt_thread), &__nacl_irt_thread) == size of(logged_nacl_irt_thread)) {
697 }
698 if (nacl_irt_interface_set(NACL_IRT_FUTEX_v0_1, &logged_nacl_irt_futex,
699 sizeof(logged_nacl_irt_futex), &__nacl_irt_futex) == sizeof (logged_nacl_irt_futex)) {
700 }
701 if (nacl_irt_interface_set(NACL_IRT_MUTEX_v0_1, &logged_nacl_irt_mutex,
702 sizeof(logged_nacl_irt_mutex), &__nacl_irt_mutex) == sizeof (logged_nacl_irt_mutex)) {
703 }
704 if (nacl_irt_interface_set(NACL_IRT_COND_v0_1, &logged_nacl_irt_cond,
705 sizeof(logged_nacl_irt_cond), &__nacl_irt_cond) == sizeof(l ogged_nacl_irt_cond)) {
706 }
707 if (nacl_irt_interface_set(NACL_IRT_SEM_v0_1, &logged_nacl_irt_sem,
708 sizeof(logged_nacl_irt_sem), &__nacl_irt_sem) == sizeof(log ged_nacl_irt_sem)) {
709 }
710 if (nacl_irt_interface_set(NACL_IRT_TLS_v0_1, &logged_nacl_irt_tls,
711 sizeof(logged_nacl_irt_tls), &__nacl_irt_tls) == sizeof(log ged_nacl_irt_tls)) {
712 }
713 if (nacl_irt_interface_set(NACL_IRT_BLOCKHOOK_v0_1, &logged_nacl_irt_blockhook ,
714 sizeof(logged_nacl_irt_blockhook), &__nacl_irt_blockhook) = = sizeof(logged_nacl_irt_blockhook)) {
715 }
716 #ifdef IRT_PPAPI
717 if (nacl_irt_interface_set(NACL_IRT_PPAPIHOOK_v0_1, &logged_nacl_irt_ppapihook ,
718 sizeof(logged_nacl_irt_ppapihook), &__nacl_irt_ppapihook) = = sizeof(logged_nacl_irt_ppapihook)) {
719 }
720 #endif
721 if (nacl_irt_interface_set(NACL_IRT_RESOURCE_OPEN_v0_1, &logged_nacl_irt_resou rce_open,
722 sizeof(logged_nacl_irt_resource_open), &__nacl_irt_resource _open) == sizeof(logged_nacl_irt_resource_open)) {
723 }
724 if (nacl_irt_interface_set(NACL_IRT_RANDOM_v0_1, &logged_nacl_irt_random,
725 sizeof(logged_nacl_irt_random), &__nacl_irt_random) == size of(logged_nacl_irt_random)) {
726 }
727 if (nacl_irt_interface_set(NACL_IRT_CLOCK_v0_1, &logged_nacl_irt_clock,
728 sizeof(logged_nacl_irt_clock), &__nacl_irt_clock) == sizeof (logged_nacl_irt_clock)) {
729 }
730 if (nacl_irt_interface_set(NACL_IRT_EXCEPTION_HANDLING_v0_1, &logged_nacl_irt_ exception_handling,
731 sizeof(logged_nacl_irt_exception_handling), &__nacl_irt_exc eption_handling) == sizeof(logged_nacl_irt_exception_handling)) {
732 }
733 }
734
735 /*
736 static const struct nacl_irt_opt irt_trace_opts[] = {
737 IRT_OPT_KEY("-h", 0),
738 IRT_OPT_KEY("--help", 0),
739 { "timestamp", offsetof(struct irt_trace, timestamp), 0 },
740 { NULL, 0, 0 },
741 };
742
743 static void irt_trace_help(void) {
744 printf("-p prefix\n");
745 }
746
747 static int irt_trace_opt_proc(void *data, const char *arg, int key, struct nacl_ irt_args *outargs) {
748 if (NULL == key) {
749 irt_trace_help();
750 return -1;
751 }
752
753 return 1;
754 }
755 */
756
757 #if 0
758 static struct nacl_irt_layer *irt_trace_new(struct nacl_irt_args *args,
759 struct nacl_irt_layer *next[]) {
760 struct nacl_irt_layer *layer;
761 struct irt_trace *trace;
762
763 fprintf(stderr, "initializing\n");
764
765 trace = malloc(sizeof *trace);
766 if (NULL == trace) {
767 fprintf(stderr, "irt-trace: malloc failed\n");
768 return NULL;
769 }
770
771 /*if (-1 == nacl_irt_opt_parse(args, trace, irt_trace_opts, irt_trace_opt_proc )) {
772 goto out_error;
773 }*/
774
775 if (NULL == next[0]) {
776 fprintf(stderr, "irt-trace: at least one layer needed\n");
777 goto out_error;
778 }
779
780 irt_trace_module_init();
781 fprintf(stderr, "trace= %p\n", (void *)(uintptr_t) irt_trace_interface);
782 layer = nacl_irt_layer_new(/*irt_trace_interfaces,
783 sizeof irt_trace_interfaces,*/
784 irt_trace_interface,
785 /*irt_trace_module_query(next[0]->irt_query),*/
786 (void *) trace);
787 if (NULL == layer) {
788 fprintf(stderr, "irt_trace: failed to allocate layer\n");
789 goto out_error;
790 }
791
792 fprintf(stderr, "new layer\n");
793 return layer;
794
795 out_error:
796 free(trace);
797 return NULL;
798 }
799
800 NACL_IRT_REGISTER_MODULE(irt_trace, irt_trace_new)
801 #endif
802
803 static struct nacl_irt_layer *irt_trace_new(int argc, char **args) {
804 struct nacl_irt_layer *layer;
805 struct irt_trace *trace;
806
807 fprintf(stderr, "initializing\n");
808
809 trace = malloc(sizeof *trace);
810 if (NULL == trace) {
811 fprintf(stderr, "irt-trace: malloc failed\n");
812 return NULL;
813 }
814
815 /*if (-1 == nacl_irt_opt_parse(args, trace, irt_trace_opts, irt_trace_opt_proc )) {
816 goto out_error;
817 }*/
818
819 if (NULL == next[0]) {
820 fprintf(stderr, "irt-trace: at least one layer needed\n");
821 goto out_error;
822 }
823
824 irt_trace_module_init();
825 fprintf(stderr, "trace= %p\n", (void *)(uintptr_t) irt_trace_interface);
826 layer = nacl_irt_layer_new(/*irt_trace_interfaces,
827 sizeof irt_trace_interfaces,*/
828 irt_trace_interface,
829 /*irt_trace_module_query(next[0]->irt_query),*/
830 (void *) trace);
831 if (NULL == layer) {
832 fprintf(stderr, "irt_trace: failed to allocate layer\n");
833 goto out_error;
834 }
835
836 fprintf(stderr, "new layer\n");
837 return layer;
838
839 out_error:
840 free(trace);
841 return NULL;
842 }
843
844 NACL_IRT_REGISTER_MODULE(irt_trace, irt_trace_new)
OLDNEW
« no previous file with comments | « tests/stacked_irt/irt_trace.h ('k') | tests/stacked_irt/nacl.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698