Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / nacl / nacl_irt.h
1 /*
2  * Copyright (c) 2012 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 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_NACL_IRT_H_
8 #define NATIVE_CLIENT_SRC_UNTRUSTED_NACL_IRT_H_
9
10 #include <errno.h>
11
12 #include "native_client/src/include/elf32.h"
13 #include "native_client/src/untrusted/irt/irt.h"
14 #include "native_client/src/untrusted/irt/irt_dev.h"
15
16 extern TYPE_nacl_irt_query __nacl_irt_query;
17
18 extern struct nacl_irt_basic __libnacl_irt_basic;
19 extern struct nacl_irt_fdio __libnacl_irt_fdio;
20 extern struct nacl_irt_dev_fdio __libnacl_irt_dev_fdio;
21 extern struct nacl_irt_dev_filename __libnacl_irt_dev_filename;
22 extern struct nacl_irt_memory __libnacl_irt_memory;
23 extern struct nacl_irt_tls __libnacl_irt_tls;
24 extern struct nacl_irt_clock __libnacl_irt_clock;
25 extern struct nacl_irt_dev_getpid __libnacl_irt_dev_getpid;
26
27 extern int __libnacl_irt_query(const char *interface,
28                                void *table, size_t table_size);
29 extern void __libnacl_mandatory_irt_query(const char *interface_ident,
30                                           void *table, size_t table_size);
31 extern void __libnacl_irt_init(Elf32_auxv_t *auxv);
32
33 extern void __libnacl_irt_clock_init(void);
34 extern void __libnacl_irt_dev_fdio_init(void);
35 extern void __libnacl_irt_dev_filename_init(void);
36
37 /*
38  * __libnacl_irt_init_fn() is used for initializing an IRT interface
39  * struct on demand.  Example usage:
40  *
41  *   int foo_func(int arg) {
42  *     if (!__libnacl_irt_init_fn(&__libnacl_irt_foo.foo_func,
43  *                                __libnacl_irt_foo_init)) {
44  *       return -1;
45  *     }
46  *     int error = __libnacl_irt_foo.foo_func(arg);
47  *     if (error) {
48  *       errno = error;
49  *       return -1;
50  *     }
51  *     return 0;
52  *   }
53  *
54  * This pattern assumes that the IRT's query function writes each
55  * function pointer to the interface struct atomically, so that this
56  * is thread-safe if foo_func() is called in multiple threads.
57  *
58  * A limitation of this approach is that, if the IRT does not provide
59  * the "foo" interface, each call to foo_func() will call the IRT's
60  * query function.
61  */
62 extern int __libnacl_irt_init_fn(void *interface_field, void (*init)(void));
63
64 #endif  /* NATIVE_CLIENT_SRC_UNTRUSTED_NACL_IRT_H_ */