10
10
11
11
#define NACL_ARRAY_SIZE (array ) (sizeof (array) / sizeof ((array)[0 ]))
12
12
13
- struct nacl_irt_basic irt_basic;
14
- struct nacl_irt_fdio irt_fdio;
13
+ static __thread void *tls_thread_ptr;
15
14
16
- int irt_write (int fd, const void *buf, size_t count, size_t *nwrote) {
15
+ static int irt_write (int fd, const void *buf, size_t count, size_t *nwrote) {
17
16
int result = write (fd, buf, count);
18
17
if (result < 0 )
19
18
return -result;
20
19
*nwrote = result;
21
20
return 0 ;
22
21
}
23
22
24
- void irt_exit (int status) {
23
+ static void irt_exit (int status) {
25
24
_exit (status);
26
25
}
27
26
27
+ static int tls_init (void *thread_ptr) {
28
+ tls_thread_ptr = thread_ptr;
29
+ return 0 ;
30
+ }
31
+
32
+ static void *tls_get () {
33
+ return tls_thread_ptr;
34
+ }
35
+
36
+ static void irt_stub_func (const char *name) {
37
+ fprintf (stderr, " Error: Unimplemented IRT function: %s\n " , name);
38
+ abort ();
39
+ }
40
+
41
+ #define DEFINE_STUB (name ) \
42
+ static void irt_stub_##name() { irt_stub_func (#name); }
43
+ #define USE_STUB (s, name ) (typeof(s.name)) irt_stub_##name
44
+
45
+ DEFINE_STUB (gettod)
46
+ DEFINE_STUB(clock)
47
+ DEFINE_STUB(nanosleep)
48
+ DEFINE_STUB(sched_yield)
49
+ DEFINE_STUB(sysconf)
50
+ struct nacl_irt_basic irt_basic = {
51
+ irt_exit,
52
+ USE_STUB (irt_basic, gettod),
53
+ USE_STUB (irt_basic, clock ),
54
+ USE_STUB (irt_basic, nanosleep ),
55
+ USE_STUB (irt_basic, sched_yield),
56
+ USE_STUB (irt_basic, sysconf ),
57
+ };
58
+
59
+ DEFINE_STUB (close)
60
+ DEFINE_STUB(dup)
61
+ DEFINE_STUB(dup2)
62
+ DEFINE_STUB(read)
63
+ DEFINE_STUB(seek)
64
+ DEFINE_STUB(fstat)
65
+ DEFINE_STUB(getdents)
66
+ struct nacl_irt_fdio irt_fdio = {
67
+ USE_STUB (irt_fdio, close ),
68
+ USE_STUB (irt_fdio, dup ),
69
+ USE_STUB (irt_fdio, dup2 ),
70
+ USE_STUB (irt_fdio, read ),
71
+ irt_write,
72
+ USE_STUB (irt_fdio, seek),
73
+ USE_STUB (irt_fdio, fstat),
74
+ USE_STUB (irt_fdio, getdents),
75
+ };
76
+
77
+ DEFINE_STUB (open)
78
+ DEFINE_STUB(stat)
79
+ struct nacl_irt_filename irt_filename = {
80
+ USE_STUB (irt_filename, open ),
81
+ USE_STUB (irt_filename, stat),
82
+ };
83
+
84
+ DEFINE_STUB (sysbrk)
85
+ DEFINE_STUB(mmap)
86
+ DEFINE_STUB(munmap)
87
+ struct nacl_irt_memory irt_memory = {
88
+ USE_STUB (irt_memory, sysbrk),
89
+ USE_STUB (irt_memory, mmap),
90
+ USE_STUB (irt_memory, munmap),
91
+ };
92
+
93
+ DEFINE_STUB (dyncode_create)
94
+ DEFINE_STUB(dyncode_modify)
95
+ DEFINE_STUB(dyncode_delete)
96
+ struct nacl_irt_dyncode irt_dyncode = {
97
+ USE_STUB (irt_dyncode, dyncode_create),
98
+ USE_STUB (irt_dyncode, dyncode_modify),
99
+ USE_STUB (irt_dyncode, dyncode_delete),
100
+ };
101
+
102
+ struct nacl_irt_tls irt_tls = {
103
+ tls_init,
104
+ tls_get,
105
+ };
106
+
107
+ DEFINE_STUB (register_block_hooks)
108
+ struct nacl_irt_blockhook irt_blockhook = {
109
+ USE_STUB (irt_blockhook, register_block_hooks),
110
+ };
111
+
28
112
struct nacl_interface_table {
29
113
const char *name;
30
114
const void *table;
@@ -34,6 +118,11 @@ struct nacl_interface_table {
34
118
static const struct nacl_interface_table irt_interfaces[] = {
35
119
{ NACL_IRT_BASIC_v0_1, &irt_basic, sizeof (irt_basic) },
36
120
{ NACL_IRT_FDIO_v0_1, &irt_fdio, sizeof (irt_fdio) },
121
+ { NACL_IRT_FILENAME_v0_1, &irt_filename, sizeof (irt_filename) },
122
+ { NACL_IRT_MEMORY_v0_1, &irt_memory, sizeof (irt_memory) },
123
+ { NACL_IRT_DYNCODE_v0_1, &irt_dyncode, sizeof (irt_dyncode) },
124
+ { NACL_IRT_TLS_v0_1, &irt_tls, sizeof (irt_tls) },
125
+ { NACL_IRT_BLOCKHOOK_v0_1, &irt_blockhook, sizeof (irt_blockhook) },
37
126
};
38
127
39
128
size_t irt_interface_query (const char *interface_ident,
@@ -49,6 +138,8 @@ size_t irt_interface_query(const char *interface_ident,
49
138
break ;
50
139
}
51
140
}
141
+ fprintf (stderr, " Warning: unavailable IRT interface queried: %s\n " ,
142
+ interface_ident);
52
143
return 0 ;
53
144
}
54
145
@@ -80,9 +171,6 @@ int main(int argc, char **argv) {
80
171
std::map<std::string,uintptr_t > globals;
81
172
translate (module, &globals);
82
173
83
- irt_basic.exit = irt_exit;
84
- irt_fdio.write = irt_write;
85
-
86
174
struct startup_info info;
87
175
info.cleanup_func = NULL ;
88
176
info.envc = 0 ;
0 commit comments