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.
7 * TODO(bradchen): figure out where to move this include file and then
11 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H
12 #define NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H
14 #if defined(__cplusplus)
18 #include <sys/types.h>
21 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h"
22 #include "native_client/src/trusted/service_runtime/nacl_config.h"
24 struct NaClExceptionContext;
25 struct NaClAbiNaClImcMsgHdr;
26 struct NaClMemMappingInfo;
31 #define NACL_SYSCALL(s) ((TYPE_nacl_ ## s) NACL_SYSCALL_ADDR(NACL_sys_ ## s))
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).
41 extern void IRT_pre_irtcall_hook(void);
42 extern void IRT_post_irtcall_hook(void);
44 #define NACL_GC_WRAP_SYSCALL(_expr) \
46 __typeof__(_expr) __sysret; \
47 IRT_pre_irtcall_hook(); \
49 IRT_post_irtcall_hook(); \
53 /* ============================================================ */
55 /* ============================================================ */
57 typedef int (*TYPE_nacl_nameservice)(int *desc_in_out);
59 typedef int (*TYPE_nacl_dup)(int oldfd);
61 typedef int (*TYPE_nacl_dup2)(int oldfd, int newfd);
63 typedef int (*TYPE_nacl_read) (int desc, void *buf, size_t count);
65 typedef int (*TYPE_nacl_close) (int desc);
67 typedef int (*TYPE_nacl_fstat) (int fd, struct stat *stbp);
69 typedef int (*TYPE_nacl_write) (int desc, void const *buf, size_t count);
71 typedef int (*TYPE_nacl_open) (char const *pathname, int flags, mode_t mode);
73 typedef int (*TYPE_nacl_lseek) (int desc,
74 off_t *offset, /* 64 bit value */
77 typedef int (*TYPE_nacl_stat) (const char *file, struct stat *st);
79 typedef int (*TYPE_nacl_pread) (int fd, void *buf, size_t count, off_t *offset);
81 typedef int (*TYPE_nacl_pwrite) (int fd,
82 const void *buf, size_t count,
85 typedef int (*TYPE_nacl_isatty) (int fd);
87 /* ============================================================ */
89 /* ============================================================ */
91 typedef int (*TYPE_nacl_imc_recvmsg) (int desc,
92 struct NaClAbiNaClImcMsgHdr *nmhp,
94 typedef int (*TYPE_nacl_imc_sendmsg) (int desc,
95 struct NaClAbiNaClImcMsgHdr const *nmhp,
97 typedef int (*TYPE_nacl_imc_accept) (int d);
99 typedef int (*TYPE_nacl_imc_connect) (int d);
101 typedef int (*TYPE_nacl_imc_makeboundsock) (int *dp);
103 typedef int (*TYPE_nacl_imc_socketpair) (int *d2);
105 typedef int (*TYPE_nacl_imc_mem_obj_create) (size_t nbytes);
107 /* ============================================================ */
109 /* ============================================================ */
111 typedef void *(*TYPE_nacl_mmap) (void *start,
118 typedef int (*TYPE_nacl_munmap) (void *start, size_t length);
120 typedef int (*TYPE_nacl_mprotect) (void *start, size_t length, int prot);
122 typedef int (*TYPE_nacl_list_mappings) (struct NaClMemMappingInfo *region,
125 /* ============================================================ */
127 /* ============================================================ */
129 typedef void (*TYPE_nacl_thread_exit) (int32_t *stack_flag);
130 typedef int (*TYPE_nacl_thread_create) (void *start_user_address,
133 void *second_thread_ptr);
134 typedef int (*TYPE_nacl_thread_nice) (const int nice);
136 /* ============================================================ */
138 /* ============================================================ */
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);
145 /* ============================================================ */
147 /* ============================================================ */
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,
155 const struct timespec *abstime);
157 /* ============================================================ */
159 /* ============================================================ */
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);
165 /* ============================================================ */
167 /* ============================================================ */
169 typedef int (*TYPE_nacl_getdents) (int desc, void *dirp, size_t count);
171 typedef int (*TYPE_nacl_gettimeofday) (struct timeval *tv, void *tz);
173 typedef int (*TYPE_nacl_sched_yield) (void);
175 typedef int (*TYPE_nacl_sysconf) (int name, int *res);
177 typedef void *(*TYPE_nacl_brk) (void *p);
179 typedef pid_t (*TYPE_nacl_getpid) (void);
181 typedef clock_t (*TYPE_nacl_clock) (void);
183 typedef int (*TYPE_nacl_nanosleep) (const struct timespec *req,
184 struct timespec *rem);
186 typedef int (*TYPE_nacl_clock_getres) (clockid_t clk_id,
187 struct timespec *res);
189 typedef int (*TYPE_nacl_clock_gettime) (clockid_t clk_id,
190 struct timespec *tp);
192 typedef int (*TYPE_nacl_mkdir) (const char *path, int mode);
194 typedef int (*TYPE_nacl_rmdir) (const char *path);
196 typedef int (*TYPE_nacl_chdir) (const char *path);
198 typedef int (*TYPE_nacl_getcwd) (char *path, int len);
200 typedef int (*TYPE_nacl_unlink) (const char *path);
202 typedef int (*TYPE_nacl_truncate) (const char *file, off_t *length);
204 typedef int (*TYPE_nacl_lstat) (const char *file, struct stat *st);
206 typedef int (*TYPE_nacl_link) (const char *oldpath, const char *newpath);
208 typedef int (*TYPE_nacl_rename) (const char *oldpath, const char *newpath);
210 typedef int (*TYPE_nacl_symlink) (const char *oldpath, const char *newpath);
212 typedef int (*TYPE_nacl_chmod) (const char *path, mode_t mode);
214 typedef int (*TYPE_nacl_access) (const char *path, int amode);
216 typedef int (*TYPE_nacl_readlink) (const char *path, char *buf, size_t bufsize);
218 typedef int (*TYPE_nacl_utimes) (const char *path, const struct timeval *times);
221 typedef void (*TYPE_nacl_exit) (int status) __attribute__((noreturn));
223 typedef void (*TYPE_nacl_exit) (int status);
226 typedef void (*TYPE_nacl_null) (void);
228 typedef int (*TYPE_nacl_tls_init) (void *thread_ptr);
230 typedef void *(*TYPE_nacl_tls_get) (void);
232 typedef int (*TYPE_nacl_second_tls_set) (void *new_value);
234 typedef void *(*TYPE_nacl_second_tls_get) (void);
236 typedef int (*TYPE_nacl_dyncode_create) (void *dest, const void *src,
239 typedef int (*TYPE_nacl_dyncode_modify) (void *dest, const void *src,
242 typedef int (*TYPE_nacl_dyncode_delete) (void *dest, size_t size);
244 typedef int (*TYPE_nacl_exception_handler) (
245 void (*handler)(struct NaClExceptionContext *context),
246 void (**old_handler)(struct NaClExceptionContext *context));
248 typedef int (*TYPE_nacl_exception_stack) (void *stack, size_t size);
250 typedef int (*TYPE_nacl_exception_clear_flag) (void);
252 typedef int (*TYPE_nacl_test_infoleak) (void);
254 typedef int (*TYPE_nacl_test_crash) (int crash_type);
256 typedef int (*TYPE_nacl_futex_wait_abs) (volatile int *addr, int value,
257 const struct timespec *abstime);
259 typedef int (*TYPE_nacl_futex_wake) (volatile int *addr, int nwake);
261 #if defined(__cplusplus)
265 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H */