Upstream version 7.36.149.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 #define NACL_GC_WRAP_SYSCALL(_expr) \
45   ({                                \
46     __typeof__(_expr) __sysret;     \
47     IRT_pre_irtcall_hook();        \
48     __sysret = _expr;               \
49     IRT_post_irtcall_hook();       \
50     __sysret;                       \
51   })
52
53 /* ============================================================ */
54 /* files */
55 /* ============================================================ */
56
57 typedef int (*TYPE_nacl_nameservice)(int *desc_in_out);
58
59 typedef int (*TYPE_nacl_dup)(int oldfd);
60
61 typedef int (*TYPE_nacl_dup2)(int oldfd, int newfd);
62
63 typedef int (*TYPE_nacl_read) (int desc, void *buf, size_t count);
64
65 typedef int (*TYPE_nacl_close) (int desc);
66
67 typedef int (*TYPE_nacl_fstat) (int fd, struct stat *stbp);
68
69 typedef int (*TYPE_nacl_write) (int desc, void const *buf, size_t count);
70
71 typedef int (*TYPE_nacl_open) (char const *pathname, int flags, mode_t mode);
72
73 typedef int (*TYPE_nacl_lseek) (int desc,
74                                 off_t *offset, /* 64 bit value */
75                                 int whence);
76
77 typedef int (*TYPE_nacl_stat) (const char *file, struct stat *st);
78
79 typedef int (*TYPE_nacl_pread) (int fd, void *buf, size_t count, off_t *offset);
80
81 typedef int (*TYPE_nacl_pwrite) (int fd,
82                                  const void *buf, size_t count,
83                                  off_t *offset);
84
85 typedef int (*TYPE_nacl_isatty) (int fd);
86
87 /* ============================================================ */
88 /* imc */
89 /* ============================================================ */
90
91 typedef int (*TYPE_nacl_imc_recvmsg) (int desc,
92                                       struct NaClAbiNaClImcMsgHdr *nmhp,
93                                       int flags);
94 typedef int (*TYPE_nacl_imc_sendmsg) (int desc,
95                                       struct NaClAbiNaClImcMsgHdr const *nmhp,
96                                       int flags);
97 typedef int (*TYPE_nacl_imc_accept) (int d);
98
99 typedef int (*TYPE_nacl_imc_connect) (int d);
100
101 typedef int (*TYPE_nacl_imc_makeboundsock) (int *dp);
102
103 typedef int (*TYPE_nacl_imc_socketpair) (int *d2);
104
105 typedef int (*TYPE_nacl_imc_mem_obj_create) (size_t nbytes);
106
107 /* ============================================================ */
108 /* mmap */
109 /* ============================================================ */
110
111 typedef void *(*TYPE_nacl_mmap) (void *start,
112                                   size_t length,
113                                   int prot,
114                                   int flags,
115                                   int desc,
116                                   off_t *offset);
117
118 typedef int (*TYPE_nacl_munmap) (void *start, size_t length);
119
120 typedef int (*TYPE_nacl_mprotect) (void *start, size_t length, int prot);
121
122 typedef int (*TYPE_nacl_list_mappings) (struct NaClMemMappingInfo *region,
123                                         size_t count);
124
125 /* ============================================================ */
126 /* threads */
127 /* ============================================================ */
128
129 typedef void (*TYPE_nacl_thread_exit) (int32_t *stack_flag);
130 typedef int (*TYPE_nacl_thread_create) (void *start_user_address,
131                                         void *stack,
132                                         void *thread_ptr,
133                                         void *second_thread_ptr);
134 typedef int (*TYPE_nacl_thread_nice) (const int nice);
135
136 /* ============================================================ */
137 /* mutex */
138 /* ============================================================ */
139
140 typedef int (*TYPE_nacl_mutex_create) (void);
141 typedef int (*TYPE_nacl_mutex_lock) (int mutex);
142 typedef int (*TYPE_nacl_mutex_unlock) (int mutex);
143 typedef int (*TYPE_nacl_mutex_trylock) (int mutex);
144
145 /* ============================================================ */
146 /* condvar */
147 /* ============================================================ */
148
149 typedef int (*TYPE_nacl_cond_create) (void);
150 typedef int (*TYPE_nacl_cond_wait) (int cv, int mutex);
151 typedef int (*TYPE_nacl_cond_signal) (int cv);
152 typedef int (*TYPE_nacl_cond_broadcast) (int cv);
153 typedef int (*TYPE_nacl_cond_timed_wait_abs) (int condvar,
154                                               int mutex,
155                                               const struct timespec *abstime);
156
157 /* ============================================================ */
158 /* semaphore */
159 /* ============================================================ */
160
161 typedef int (*TYPE_nacl_sem_create) (int32_t value);
162 typedef int (*TYPE_nacl_sem_wait) (int sem);
163 typedef int (*TYPE_nacl_sem_post) (int sem);
164
165 /* ============================================================ */
166 /* misc */
167 /* ============================================================ */
168
169 typedef int (*TYPE_nacl_getdents) (int desc, void *dirp, size_t count);
170
171 typedef int (*TYPE_nacl_gettimeofday) (struct timeval *tv, void *tz);
172
173 typedef int (*TYPE_nacl_sched_yield) (void);
174
175 typedef int (*TYPE_nacl_sysconf) (int name, int *res);
176
177 typedef void *(*TYPE_nacl_brk) (void *p);
178
179 typedef pid_t (*TYPE_nacl_getpid) (void);
180
181 typedef clock_t (*TYPE_nacl_clock) (void);
182
183 typedef int (*TYPE_nacl_nanosleep) (const struct timespec *req,
184                                     struct timespec *rem);
185
186 typedef int (*TYPE_nacl_clock_getres) (clockid_t clk_id,
187                                        struct timespec *res);
188
189 typedef int (*TYPE_nacl_clock_gettime) (clockid_t clk_id,
190                                         struct timespec *tp);
191
192 typedef int (*TYPE_nacl_mkdir) (const char *path, int mode);
193
194 typedef int (*TYPE_nacl_rmdir) (const char *path);
195
196 typedef int (*TYPE_nacl_chdir) (const char *path);
197
198 typedef int (*TYPE_nacl_getcwd) (char *path, int len);
199
200 typedef int (*TYPE_nacl_unlink) (const char *path);
201
202 typedef int (*TYPE_nacl_truncate) (const char *file, off_t *length);
203
204 typedef int (*TYPE_nacl_lstat) (const char *file, struct stat *st);
205
206 typedef int (*TYPE_nacl_link) (const char *oldpath, const char *newpath);
207
208 typedef int (*TYPE_nacl_rename) (const char *oldpath, const char *newpath);
209
210 typedef int (*TYPE_nacl_symlink) (const char *oldpath, const char *newpath);
211
212 typedef int (*TYPE_nacl_chmod) (const char *path, mode_t mode);
213
214 typedef int (*TYPE_nacl_access) (const char *path, int amode);
215
216 typedef int (*TYPE_nacl_readlink) (const char *path, char *buf, size_t bufsize);
217
218 typedef int (*TYPE_nacl_utimes) (const char *path, const struct timeval *times);
219
220 #ifdef __GNUC__
221 typedef void (*TYPE_nacl_exit) (int status) __attribute__((noreturn));
222 #else
223 typedef void (*TYPE_nacl_exit) (int status);
224 #endif
225
226 typedef void (*TYPE_nacl_null) (void);
227
228 typedef int (*TYPE_nacl_tls_init) (void *thread_ptr);
229
230 typedef void *(*TYPE_nacl_tls_get) (void);
231
232 typedef int (*TYPE_nacl_second_tls_set) (void *new_value);
233
234 typedef void *(*TYPE_nacl_second_tls_get) (void);
235
236 typedef int (*TYPE_nacl_dyncode_create) (void *dest, const void *src,
237                                        size_t size);
238
239 typedef int (*TYPE_nacl_dyncode_modify) (void *dest, const void *src,
240                                        size_t size);
241
242 typedef int (*TYPE_nacl_dyncode_delete) (void *dest, size_t size);
243
244 typedef int (*TYPE_nacl_exception_handler) (
245     void (*handler)(struct NaClExceptionContext *context),
246     void (**old_handler)(struct NaClExceptionContext *context));
247
248 typedef int (*TYPE_nacl_exception_stack) (void *stack, size_t size);
249
250 typedef int (*TYPE_nacl_exception_clear_flag) (void);
251
252 typedef int (*TYPE_nacl_test_infoleak) (void);
253
254 typedef int (*TYPE_nacl_test_crash) (int crash_type);
255
256 typedef int (*TYPE_nacl_futex_wait_abs) (volatile int *addr, int value,
257                                          const struct timespec *abstime);
258
259 typedef int (*TYPE_nacl_futex_wake) (volatile int *addr, int nwake);
260
261 #if defined(__cplusplus)
262 }
263 #endif
264
265 #endif  /*  NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H */