Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / nacl / syscall_bindings_trampoline.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  * TODO(bradchen): figure out where to move this include file and then
8  * move it.
9  */
10
11 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H
12 #define NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H
13
14 #if defined(__cplusplus)
15 extern "C" {
16 #endif
17
18 #include <sys/types.h>
19 #include <time.h>
20
21 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h"
22 #include "native_client/src/trusted/service_runtime/nacl_config.h"
23
24 struct NaClExceptionContext;
25 struct NaClAbiNaClImcMsgHdr;
26 struct NaClMemMappingInfo;
27 struct stat;
28 struct timespec;
29 struct timeval;
30
31 #define NACL_SYSCALL(s) ((TYPE_nacl_ ## s) NACL_SYSCALL_ADDR(NACL_sys_ ## s))
32
33 /*
34  * These hook functions and the GC_WRAP macro are for wrapping a subset of
35  * syscalls that are likely to take a long time, which will interfere with
36  * thread parking for garbage collection. In particular, we don't want to
37  * wrap all of the syscalls because some of them are used within the thread
38  * parking instrumentation (tls related calls).
39  */
40
41 extern void IRT_pre_irtcall_hook(void);
42 extern void IRT_post_irtcall_hook(void);
43
44 #if defined(__GLIBC__)
45 /*
46  * GC instrumentation is not supported when using nacl-glibc with direct
47  * NaCl syscalls.
48  */
49 # define NACL_GC_WRAP_SYSCALL(_expr) (_expr)
50 #else
51 # define NACL_GC_WRAP_SYSCALL(_expr) \
52   ({                                \
53     __typeof__(_expr) __sysret;     \
54     IRT_pre_irtcall_hook();        \
55     __sysret = _expr;               \
56     IRT_post_irtcall_hook();       \
57     __sysret;                       \
58   })
59 #endif
60
61 /* ============================================================ */
62 /* files */
63 /* ============================================================ */
64
65 typedef int (*TYPE_nacl_nameservice)(int *desc_in_out);
66
67 typedef int (*TYPE_nacl_dup)(int oldfd);
68
69 typedef int (*TYPE_nacl_dup2)(int oldfd, int newfd);
70
71 typedef int (*TYPE_nacl_read) (int desc, void *buf, size_t count);
72
73 typedef int (*TYPE_nacl_close) (int desc);
74
75 typedef int (*TYPE_nacl_fstat) (int fd, struct stat *stbp);
76
77 typedef int (*TYPE_nacl_write) (int desc, void const *buf, size_t count);
78
79 typedef int (*TYPE_nacl_open) (char const *pathname, int flags, mode_t mode);
80
81 typedef int (*TYPE_nacl_lseek) (int desc,
82                                 off_t *offset, /* 64 bit value */
83                                 int whence);
84
85 typedef int (*TYPE_nacl_stat) (const char *file, struct stat *st);
86
87 typedef int (*TYPE_nacl_pread) (int fd, void *buf, size_t count, off_t *offset);
88
89 typedef int (*TYPE_nacl_pwrite) (int fd,
90                                  const void *buf, size_t count,
91                                  off_t *offset);
92
93 typedef int (*TYPE_nacl_isatty) (int fd);
94
95 /* ============================================================ */
96 /* imc */
97 /* ============================================================ */
98
99 typedef int (*TYPE_nacl_imc_recvmsg) (int desc,
100                                       struct NaClAbiNaClImcMsgHdr *nmhp,
101                                       int flags);
102 typedef int (*TYPE_nacl_imc_sendmsg) (int desc,
103                                       struct NaClAbiNaClImcMsgHdr const *nmhp,
104                                       int flags);
105 typedef int (*TYPE_nacl_imc_accept) (int d);
106
107 typedef int (*TYPE_nacl_imc_connect) (int d);
108
109 typedef int (*TYPE_nacl_imc_makeboundsock) (int *dp);
110
111 typedef int (*TYPE_nacl_imc_socketpair) (int *d2);
112
113 typedef int (*TYPE_nacl_imc_mem_obj_create) (size_t nbytes);
114
115 /* ============================================================ */
116 /* mmap */
117 /* ============================================================ */
118
119 typedef void *(*TYPE_nacl_mmap) (void *start,
120                                   size_t length,
121                                   int prot,
122                                   int flags,
123                                   int desc,
124                                   off_t *offset);
125
126 typedef int (*TYPE_nacl_munmap) (void *start, size_t length);
127
128 typedef int (*TYPE_nacl_mprotect) (void *start, size_t length, int prot);
129
130 typedef int (*TYPE_nacl_list_mappings) (struct NaClMemMappingInfo *region,
131                                         size_t count);
132
133 /* ============================================================ */
134 /* threads */
135 /* ============================================================ */
136
137 typedef void (*TYPE_nacl_thread_exit) (int32_t *stack_flag);
138 typedef int (*TYPE_nacl_thread_create) (void *start_user_address,
139                                         void *stack,
140                                         void *thread_ptr,
141                                         void *second_thread_ptr);
142 typedef int (*TYPE_nacl_thread_nice) (const int nice);
143
144 /* ============================================================ */
145 /* mutex */
146 /* ============================================================ */
147
148 typedef int (*TYPE_nacl_mutex_create) (void);
149 typedef int (*TYPE_nacl_mutex_lock) (int mutex);
150 typedef int (*TYPE_nacl_mutex_unlock) (int mutex);
151 typedef int (*TYPE_nacl_mutex_trylock) (int mutex);
152
153 /* ============================================================ */
154 /* condvar */
155 /* ============================================================ */
156
157 typedef int (*TYPE_nacl_cond_create) (void);
158 typedef int (*TYPE_nacl_cond_wait) (int cv, int mutex);
159 typedef int (*TYPE_nacl_cond_signal) (int cv);
160 typedef int (*TYPE_nacl_cond_broadcast) (int cv);
161 typedef int (*TYPE_nacl_cond_timed_wait_abs) (int condvar,
162                                               int mutex,
163                                               const struct timespec *abstime);
164
165 /* ============================================================ */
166 /* semaphore */
167 /* ============================================================ */
168
169 typedef int (*TYPE_nacl_sem_create) (int32_t value);
170 typedef int (*TYPE_nacl_sem_wait) (int sem);
171 typedef int (*TYPE_nacl_sem_post) (int sem);
172
173 /* ============================================================ */
174 /* misc */
175 /* ============================================================ */
176
177 typedef int (*TYPE_nacl_getdents) (int desc, void *dirp, size_t count);
178
179 typedef int (*TYPE_nacl_gettimeofday) (struct timeval *tv);
180
181 typedef int (*TYPE_nacl_sched_yield) (void);
182
183 typedef int (*TYPE_nacl_sysconf) (int name, int *res);
184
185 typedef void *(*TYPE_nacl_brk) (void *p);
186
187 typedef pid_t (*TYPE_nacl_getpid) (void);
188
189 typedef clock_t (*TYPE_nacl_clock) (void);
190
191 typedef int (*TYPE_nacl_nanosleep) (const struct timespec *req,
192                                     struct timespec *rem);
193
194 typedef int (*TYPE_nacl_clock_getres) (clockid_t clk_id,
195                                        struct timespec *res);
196
197 typedef int (*TYPE_nacl_clock_gettime) (clockid_t clk_id,
198                                         struct timespec *tp);
199
200 typedef int (*TYPE_nacl_mkdir) (const char *path, int mode);
201
202 typedef int (*TYPE_nacl_rmdir) (const char *path);
203
204 typedef int (*TYPE_nacl_chdir) (const char *path);
205
206 typedef int (*TYPE_nacl_getcwd) (char *path, int len);
207
208 typedef int (*TYPE_nacl_unlink) (const char *path);
209
210 typedef int (*TYPE_nacl_truncate) (const char *file, off_t *length);
211
212 typedef int (*TYPE_nacl_lstat) (const char *file, struct stat *st);
213
214 typedef int (*TYPE_nacl_link) (const char *oldpath, const char *newpath);
215
216 typedef int (*TYPE_nacl_rename) (const char *oldpath, const char *newpath);
217
218 typedef int (*TYPE_nacl_symlink) (const char *oldpath, const char *newpath);
219
220 typedef int (*TYPE_nacl_chmod) (const char *path, mode_t mode);
221
222 typedef int (*TYPE_nacl_access) (const char *path, int amode);
223
224 typedef int (*TYPE_nacl_readlink) (const char *path, char *buf, size_t bufsize);
225
226 typedef int (*TYPE_nacl_utimes) (const char *path, const struct timeval *times);
227
228 #ifdef __GNUC__
229 typedef void (*TYPE_nacl_exit) (int status) __attribute__((noreturn));
230 #else
231 typedef void (*TYPE_nacl_exit) (int status);
232 #endif
233
234 typedef void (*TYPE_nacl_null) (void);
235
236 typedef int (*TYPE_nacl_tls_init) (void *thread_ptr);
237
238 typedef void *(*TYPE_nacl_tls_get) (void);
239
240 typedef int (*TYPE_nacl_second_tls_set) (void *new_value);
241
242 typedef void *(*TYPE_nacl_second_tls_get) (void);
243
244 typedef int (*TYPE_nacl_dyncode_create) (void *dest, const void *src,
245                                        size_t size);
246
247 typedef int (*TYPE_nacl_dyncode_modify) (void *dest, const void *src,
248                                        size_t size);
249
250 typedef int (*TYPE_nacl_dyncode_delete) (void *dest, size_t size);
251
252 typedef int (*TYPE_nacl_exception_handler) (
253     void (*handler)(struct NaClExceptionContext *context),
254     void (**old_handler)(struct NaClExceptionContext *context));
255
256 typedef int (*TYPE_nacl_exception_stack) (void *stack, size_t size);
257
258 typedef int (*TYPE_nacl_exception_clear_flag) (void);
259
260 typedef int (*TYPE_nacl_test_infoleak) (void);
261
262 typedef int (*TYPE_nacl_test_crash) (int crash_type);
263
264 typedef int (*TYPE_nacl_futex_wait_abs) (volatile int *addr, int value,
265                                          const struct timespec *abstime);
266
267 typedef int (*TYPE_nacl_futex_wake) (volatile int *addr, int nwake);
268
269 typedef int (*TYPE_nacl_get_random_bytes) (void *buf, size_t buf_size);
270
271 #if defined(__cplusplus)
272 }
273 #endif
274
275 #endif  /*  NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H */