Make ncval-annotate and ncval-stubout executable
[nativeclient.git] / service_runtime / nacl_syscall_common.h
blob2130ab97cf11fd32f66ddfb3ddeef92643c16e22
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 int32_t NaClCommonSysMmap(struct NaClAppThread *natp,
146 void *start,
147 size_t length,
148 int prot,
149 int flags,
150 int d,
151 nacl_abi_off_t offset);
152 int32_t NaClSysMmap(struct NaClAppThread *natp,
153 void *start,
154 size_t length,
155 int prot,
156 int flags,
157 int d,
158 nacl_abi_off_t offset);
159 int32_t NaClSysMunmap(struct NaClAppThread *natp,
160 void *start,
161 size_t length);
163 int32_t NaClCommonSysGetdents(struct NaClAppThread *natp,
164 int d,
165 void *dirp,
166 size_t count);
168 int32_t NaClCommonSysImc_MakeBoundSock(struct NaClAppThread *natp,
169 int *sap);
171 int32_t NaClCommonSysImc_Accept(struct NaClAppThread *natp,
172 int d);
174 int32_t NaClCommonSysImc_Connect(struct NaClAppThread *natp,
175 int d);
177 int32_t NaClCommonSysImc_Sendmsg(struct NaClAppThread *natp,
178 int d,
179 struct NaClImcMsgHdr *nimhp,
180 int flags);
182 int32_t NaClCommonSysImc_Recvmsg(struct NaClAppThread *natp,
183 int d,
184 struct NaClImcMsgHdr *nimhp,
185 int flags);
187 int32_t NaClCommonSysImc_Mem_Obj_Create(struct NaClAppThread *natp,
188 size_t size);
190 int32_t NaClCommonSysTls_Init(struct NaClAppThread *natp,
191 void *tdb,
192 size_t size);
194 int32_t NaClCommonSysThread_Create(struct NaClAppThread *natp,
195 void *eip,
196 void *esp,
197 void *tdb,
198 size_t tdb_size);
200 #if defined(HAVE_SDL)
202 int32_t NaClCommonSysMultimedia_Init(struct NaClAppThread *natp,
203 int subsys);
205 int32_t NaClCommonSysMultimedia_Shutdown(struct NaClAppThread *natp);
207 int32_t NaClCommonSysVideo_Init(struct NaClAppThread *natp,
208 enum NaClVideoFormat format,
209 int width,
210 int height);
212 int32_t NaClCommonSysVideo_Shutdown(struct NaClAppThread *natp);
214 int32_t NaClCommonSysVideo_Update(struct NaClAppThread *natp,
215 const void *data);
217 int32_t NaClCommonSysVideo_Poll_Event(struct NaClAppThread *natp,
218 union NaClMultimediaEvent *event);
220 int32_t NaClCommonSysAudio_Init(struct NaClAppThread *natp,
221 enum NaClAudioFormat format,
222 int desired_samples,
223 int *obtained_samples);
225 int32_t NaClCommonSysAudio_Stream(struct NaClAppThread *natp,
226 const void *data,
227 size_t *size);
229 int32_t NaClCommonSysAudio_Shutdown(struct NaClAppThread *natp);
231 #endif /* HAVE_SDL */
233 /* mutex */
235 int32_t NaClCommonSysMutex_Create(struct NaClAppThread *natp);
237 int32_t NaClCommonSysMutex_Lock(struct NaClAppThread *natp,
238 int32_t mutex_handle);
240 int32_t NaClCommonSysMutex_Unlock(struct NaClAppThread *natp,
241 int32_t mutex_handle);
243 int32_t NaClCommonSysMutex_Trylock(struct NaClAppThread *natp,
244 int32_t mutex_handle);
246 /* condition variable */
248 int32_t NaClCommonSysCond_Create(struct NaClAppThread *natp);
250 int32_t NaClCommonSysCond_Wait(struct NaClAppThread *natp,
251 int32_t cond_handle,
252 int32_t mutex_handle);
254 int32_t NaClCommonSysCond_Signal(struct NaClAppThread *natp,
255 int32_t cond_handle);
257 int32_t NaClCommonSysCond_Broadcast(struct NaClAppThread *natp,
258 int32_t cond_handle);
260 int32_t NaClCommonSysCond_Timed_Wait_Rel(struct NaClAppThread *natp,
261 int32_t cond_handle,
262 int32_t mutex_handle,
263 struct nacl_abi_timespec *ts);
265 int32_t NaClCommonSysCond_Timed_Wait_Abs(struct NaClAppThread *natp,
266 int32_t cond_handle,
267 int32_t mutex_handle,
268 struct nacl_abi_timespec *ts);
270 int32_t NaClCommonDescSocketPair(struct NaClDesc **pair);
272 int32_t NaClCommonSysImc_SocketPair(struct NaClAppThread *natp,
273 int32_t *d_out);
274 /* Semaphores */
275 int32_t NaClCommonSysSem_Create(struct NaClAppThread *natp,
276 int32_t init_value);
278 int32_t NaClCommonSysSem_Wait(struct NaClAppThread *natp,
279 int32_t sem_handle);
281 int32_t NaClCommonSysSem_Post(struct NaClAppThread *natp,
282 int32_t sem_handle);
284 int32_t NaClCommonSysSem_Get_Value(struct NaClAppThread *natp,
285 int32_t sem_handle);
287 EXTERN_C_END
289 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_SYSCALL_COMMON_H__ */