Debugging: Add code to print backtrace for guest on SIGSEGV
[nativeclient.git] / service_runtime / nacl_syscall_common.h
blob60def91938641393bea999446969c5938f5a3f7f
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl service run-time, non-platform specific system call helper routines.
36 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_NACL_SYSCALL_COMMON_H__
37 #define NATIVE_CLIENT_SERVICE_RUNTIME_NACL_SYSCALL_COMMON_H__ 1
39 #include "native_client/include/portability.h"
41 #include "native_client/include/nacl_base.h"
42 #include "native_client/service_runtime/include/sys/time.h"
44 #if defined(HAVE_SDL)
45 # include "native_client/service_runtime/include/sys/audio_video.h"
46 #endif
48 EXTERN_C_BEGIN
50 struct NaClApp;
51 struct NaClAppThread;
52 struct NaClSocketAddress;
53 struct NaClDesc;
54 struct NaClImcMsgHdr;
55 struct nacl_abi_stat;
57 int32_t NaClSetBreak(struct NaClAppThread *natp,
58 uintptr_t new_break);
61 * Entering kernel mode from user mde. Makes thread unkillable
62 * because while switched to kernel mode, we may be holding kernel
63 * locks and in the middle of mutating protected objects, and killing
64 * the thread will leave the service runtime in an inconsistent state.
65 * Must invoke the correspondng Leave function, except if the thread
66 * is exiting anyway.
68 * Not all syscalls need to invoke the Enter function -- those that we
69 * know definitely does not grab any locks (even implicitly, in libc
70 * routines such as malloc).
72 void NaClSysCommonThreadSyscallEnter(struct NaClAppThread *natp);
75 * Thread is leaving kernel mode and returning to user mode. Checks
76 * if a kill request was made, and if so commit suicide. Must be
77 * invoked if there was a corresponding Enter; not harmful if called
78 * without a corresponding Enter.
80 void NaClSysCommonThreadSyscallLeave(struct NaClAppThread *natp);
82 int NaClHighResolutionTimerEnabled(void);
84 int32_t NaClOpenAclCheck(struct NaClApp *nap,
85 char const *path,
86 int flags,
87 int mode);
89 int32_t NaClStatAclCheck(struct NaClApp *nap,
90 char const *path);
92 int32_t NaClCommonSysExit(struct NaClAppThread *natp,
93 int status);
95 int32_t NaClCommonSysThreadExit(struct NaClAppThread *natp,
96 int32_t *stack_flag);
98 void NaClInsecurelyBypassAllAclChecks(void);
100 int32_t NaClCommonSysOpen(struct NaClAppThread *natp,
101 char *pathname,
102 int flags,
103 int mode);
105 int32_t NaClCommonSysClose(struct NaClAppThread *natp,
106 int d);
108 int32_t NaClCommonSysRead(struct NaClAppThread *natp,
109 int d,
110 void *buf,
111 size_t count);
113 int32_t NaClCommonSysWrite(struct NaClAppThread *natp,
114 int d,
115 void *buf,
116 size_t count);
118 int32_t NaClCommonSysLseek(struct NaClAppThread *natp,
119 int d,
120 off_t offset,
121 int whence);
123 int32_t NaClCommonSysIoctl(struct NaClAppThread *natp,
124 int d,
125 int request,
126 void *arg);
128 int32_t NaClCommonSysFstat(struct NaClAppThread *natp,
129 int d,
130 struct nacl_abi_stat *nasp);
132 int32_t NaClCommonSysStat(struct NaClAppThread *natp,
133 const char *path,
134 struct nacl_abi_stat *nasp);
136 void NaClCommonUtilUpdateAddrMap(struct NaClAppThread *natp,
137 uintptr_t sysaddr,
138 size_t nbytes,
139 int sysprot,
140 struct NaClDesc *backing_desc,
141 size_t backing_bytes,
142 off_t offset_bytes,
143 int delete_mem);
145 /* bool */
146 int NaClSysCommonAddrRangeContainsExecutablePages_mu(struct NaClApp *nap,
147 uintptr_t usraddr,
148 size_t length);
150 int32_t NaClCommonSysMmap(struct NaClAppThread *natp,
151 void *start,
152 size_t length,
153 int prot,
154 int flags,
155 int d,
156 nacl_abi_off_t offset);
157 int32_t NaClSysMmap(struct NaClAppThread *natp,
158 void *start,
159 size_t length,
160 int prot,
161 int flags,
162 int d,
163 nacl_abi_off_t offset);
164 int32_t NaClSysMunmap(struct NaClAppThread *natp,
165 void *start,
166 size_t length);
168 int32_t NaClSysMmap(struct NaClAppThread *natp,
169 void *start,
170 size_t length,
171 int prot,
172 int flags,
173 int d,
174 nacl_abi_off_t offset);
176 int32_t NaClSysMunmap(struct NaClAppThread *natp,
177 void *start,
178 size_t length);
180 int32_t NaClCommonSysGetdents(struct NaClAppThread *natp,
181 int d,
182 void *dirp,
183 size_t count);
185 int32_t NaClCommonSysImc_MakeBoundSock(struct NaClAppThread *natp,
186 int *sap);
188 int32_t NaClCommonSysImc_Accept(struct NaClAppThread *natp,
189 int d);
191 int32_t NaClCommonSysImc_Connect(struct NaClAppThread *natp,
192 int d);
194 int32_t NaClCommonSysImc_Sendmsg(struct NaClAppThread *natp,
195 int d,
196 struct NaClImcMsgHdr *nimhp,
197 int flags);
199 int32_t NaClCommonSysImc_Recvmsg(struct NaClAppThread *natp,
200 int d,
201 struct NaClImcMsgHdr *nimhp,
202 int flags);
204 int32_t NaClCommonSysImc_Mem_Obj_Create(struct NaClAppThread *natp,
205 size_t size);
207 int32_t NaClCommonSysTls_Init(struct NaClAppThread *natp,
208 void *tdb,
209 size_t size);
211 int32_t NaClCommonSysThread_Create(struct NaClAppThread *natp,
212 void *eip,
213 void *esp,
214 void *tdb,
215 size_t tdb_size);
217 #if defined(HAVE_SDL)
219 int32_t NaClCommonSysMultimedia_Init(struct NaClAppThread *natp,
220 int subsys);
222 int32_t NaClCommonSysMultimedia_Shutdown(struct NaClAppThread *natp);
224 int32_t NaClCommonSysVideo_Init(struct NaClAppThread *natp,
225 int width,
226 int height);
228 int32_t NaClCommonSysVideo_Shutdown(struct NaClAppThread *natp);
230 int32_t NaClCommonSysVideo_Update(struct NaClAppThread *natp,
231 const void *data);
233 int32_t NaClCommonSysVideo_Poll_Event(struct NaClAppThread *natp,
234 union NaClMultimediaEvent *event);
236 int32_t NaClCommonSysAudio_Init(struct NaClAppThread *natp,
237 enum NaClAudioFormat format,
238 int desired_samples,
239 int *obtained_samples);
241 int32_t NaClCommonSysAudio_Stream(struct NaClAppThread *natp,
242 const void *data,
243 size_t *size);
245 int32_t NaClCommonSysAudio_Shutdown(struct NaClAppThread *natp);
247 #endif /* HAVE_SDL */
249 /* mutex */
251 int32_t NaClCommonSysMutex_Create(struct NaClAppThread *natp);
253 int32_t NaClCommonSysMutex_Lock(struct NaClAppThread *natp,
254 int32_t mutex_handle);
256 int32_t NaClCommonSysMutex_Unlock(struct NaClAppThread *natp,
257 int32_t mutex_handle);
259 int32_t NaClCommonSysMutex_Trylock(struct NaClAppThread *natp,
260 int32_t mutex_handle);
262 /* condition variable */
264 int32_t NaClCommonSysCond_Create(struct NaClAppThread *natp);
266 int32_t NaClCommonSysCond_Wait(struct NaClAppThread *natp,
267 int32_t cond_handle,
268 int32_t mutex_handle);
270 int32_t NaClCommonSysCond_Signal(struct NaClAppThread *natp,
271 int32_t cond_handle);
273 int32_t NaClCommonSysCond_Broadcast(struct NaClAppThread *natp,
274 int32_t cond_handle);
276 int32_t NaClCommonSysCond_Timed_Wait_Rel(struct NaClAppThread *natp,
277 int32_t cond_handle,
278 int32_t mutex_handle,
279 struct nacl_abi_timespec *ts);
281 int32_t NaClCommonSysCond_Timed_Wait_Abs(struct NaClAppThread *natp,
282 int32_t cond_handle,
283 int32_t mutex_handle,
284 struct nacl_abi_timespec *ts);
286 int32_t NaClCommonDescSocketPair(struct NaClDesc **pair);
288 int32_t NaClCommonSysImc_SocketPair(struct NaClAppThread *natp,
289 int32_t *d_out);
290 /* Semaphores */
291 int32_t NaClCommonSysSem_Create(struct NaClAppThread *natp,
292 int32_t init_value);
294 int32_t NaClCommonSysSem_Wait(struct NaClAppThread *natp,
295 int32_t sem_handle);
297 int32_t NaClCommonSysSem_Post(struct NaClAppThread *natp,
298 int32_t sem_handle);
300 int32_t NaClCommonSysSem_Get_Value(struct NaClAppThread *natp,
301 int32_t sem_handle);
303 EXTERN_C_END
305 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_SYSCALL_COMMON_H__ */