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 #if defined(__GLIBC__)
46 * GC instrumentation is not supported when using nacl-glibc with direct
49 # define NACL_GC_WRAP_SYSCALL(_expr) (_expr)
51 # define NACL_GC_WRAP_SYSCALL(_expr) \
53 __typeof__(_expr) __sysret; \
54 IRT_pre_irtcall_hook(); \
56 IRT_post_irtcall_hook(); \
61 /* ============================================================ */
63 /* ============================================================ */
65 typedef int (*TYPE_nacl_nameservice)(int *desc_in_out);
67 typedef int (*TYPE_nacl_dup)(int oldfd);
69 typedef int (*TYPE_nacl_dup2)(int oldfd, int newfd);
71 typedef int (*TYPE_nacl_read) (int desc, void *buf, size_t count);
73 typedef int (*TYPE_nacl_close) (int desc);
75 typedef int (*TYPE_nacl_fstat) (int fd, struct stat *stbp);
77 typedef int (*TYPE_nacl_write) (int desc, void const *buf, size_t count);
79 typedef int (*TYPE_nacl_open) (char const *pathname, int flags, mode_t mode);
81 typedef int (*TYPE_nacl_lseek) (int desc,
82 off_t *offset, /* 64 bit value */
85 typedef int (*TYPE_nacl_stat) (const char *file, struct stat *st);
87 typedef int (*TYPE_nacl_pread) (int fd, void *buf, size_t count, off_t *offset);
89 typedef int (*TYPE_nacl_pwrite) (int fd,
90 const void *buf, size_t count,
93 typedef int (*TYPE_nacl_isatty) (int fd);
95 /* ============================================================ */
97 /* ============================================================ */
99 typedef int (*TYPE_nacl_imc_recvmsg) (int desc,
100 struct NaClAbiNaClImcMsgHdr *nmhp,
102 typedef int (*TYPE_nacl_imc_sendmsg) (int desc,
103 struct NaClAbiNaClImcMsgHdr const *nmhp,
105 typedef int (*TYPE_nacl_imc_accept) (int d);
107 typedef int (*TYPE_nacl_imc_connect) (int d);
109 typedef int (*TYPE_nacl_imc_makeboundsock) (int *dp);
111 typedef int (*TYPE_nacl_imc_socketpair) (int *d2);
113 typedef int (*TYPE_nacl_imc_mem_obj_create) (size_t nbytes);
115 /* ============================================================ */
117 /* ============================================================ */
119 typedef void *(*TYPE_nacl_mmap) (void *start,
126 typedef int (*TYPE_nacl_munmap) (void *start, size_t length);
128 typedef int (*TYPE_nacl_mprotect) (void *start, size_t length, int prot);
130 typedef int (*TYPE_nacl_list_mappings) (struct NaClMemMappingInfo *region,
133 /* ============================================================ */
135 /* ============================================================ */
137 typedef void (*TYPE_nacl_thread_exit) (int32_t *stack_flag);
138 typedef int (*TYPE_nacl_thread_create) (void *start_user_address,
141 void *second_thread_ptr);
142 typedef int (*TYPE_nacl_thread_nice) (const int nice);
144 /* ============================================================ */
146 /* ============================================================ */
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);
153 /* ============================================================ */
155 /* ============================================================ */
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,
163 const struct timespec *abstime);
165 /* ============================================================ */
167 /* ============================================================ */
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);
173 /* ============================================================ */
175 /* ============================================================ */
177 typedef int (*TYPE_nacl_getdents) (int desc, void *dirp, size_t count);
179 typedef int (*TYPE_nacl_gettimeofday) (struct timeval *tv);
181 typedef int (*TYPE_nacl_sched_yield) (void);
183 typedef int (*TYPE_nacl_sysconf) (int name, int *res);
185 typedef void *(*TYPE_nacl_brk) (void *p);
187 typedef pid_t (*TYPE_nacl_getpid) (void);
189 typedef clock_t (*TYPE_nacl_clock) (void);
191 typedef int (*TYPE_nacl_nanosleep) (const struct timespec *req,
192 struct timespec *rem);
194 typedef int (*TYPE_nacl_clock_getres) (clockid_t clk_id,
195 struct timespec *res);
197 typedef int (*TYPE_nacl_clock_gettime) (clockid_t clk_id,
198 struct timespec *tp);
200 typedef int (*TYPE_nacl_mkdir) (const char *path, int mode);
202 typedef int (*TYPE_nacl_rmdir) (const char *path);
204 typedef int (*TYPE_nacl_chdir) (const char *path);
206 typedef int (*TYPE_nacl_getcwd) (char *path, int len);
208 typedef int (*TYPE_nacl_unlink) (const char *path);
210 typedef int (*TYPE_nacl_truncate) (const char *file, off_t *length);
212 typedef int (*TYPE_nacl_lstat) (const char *file, struct stat *st);
214 typedef int (*TYPE_nacl_link) (const char *oldpath, const char *newpath);
216 typedef int (*TYPE_nacl_rename) (const char *oldpath, const char *newpath);
218 typedef int (*TYPE_nacl_symlink) (const char *oldpath, const char *newpath);
220 typedef int (*TYPE_nacl_chmod) (const char *path, mode_t mode);
222 typedef int (*TYPE_nacl_access) (const char *path, int amode);
224 typedef int (*TYPE_nacl_readlink) (const char *path, char *buf, size_t bufsize);
226 typedef int (*TYPE_nacl_utimes) (const char *path, const struct timeval *times);
229 typedef void (*TYPE_nacl_exit) (int status) __attribute__((noreturn));
231 typedef void (*TYPE_nacl_exit) (int status);
234 typedef void (*TYPE_nacl_null) (void);
236 typedef int (*TYPE_nacl_tls_init) (void *thread_ptr);
238 typedef void *(*TYPE_nacl_tls_get) (void);
240 typedef int (*TYPE_nacl_second_tls_set) (void *new_value);
242 typedef void *(*TYPE_nacl_second_tls_get) (void);
244 typedef int (*TYPE_nacl_dyncode_create) (void *dest, const void *src,
247 typedef int (*TYPE_nacl_dyncode_modify) (void *dest, const void *src,
250 typedef int (*TYPE_nacl_dyncode_delete) (void *dest, size_t size);
252 typedef int (*TYPE_nacl_exception_handler) (
253 void (*handler)(struct NaClExceptionContext *context),
254 void (**old_handler)(struct NaClExceptionContext *context));
256 typedef int (*TYPE_nacl_exception_stack) (void *stack, size_t size);
258 typedef int (*TYPE_nacl_exception_clear_flag) (void);
260 typedef int (*TYPE_nacl_test_infoleak) (void);
262 typedef int (*TYPE_nacl_test_crash) (int crash_type);
264 typedef int (*TYPE_nacl_futex_wait_abs) (volatile int *addr, int value,
265 const struct timespec *abstime);
267 typedef int (*TYPE_nacl_futex_wake) (volatile int *addr, int nwake);
269 typedef int (*TYPE_nacl_get_random_bytes) (void *buf, size_t buf_size);
271 #if defined(__cplusplus)
275 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_NACL_SYSCALL_BINDINGS_TRAMPOLINE_H */