2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
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"
45 # include "native_client/service_runtime/include/sys/audio_video.h"
52 struct NaClSocketAddress
;
57 int32_t NaClSetBreak(struct NaClAppThread
*natp
,
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
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
,
89 int32_t NaClStatAclCheck(struct NaClApp
*nap
,
92 int32_t NaClCommonSysExit(struct NaClAppThread
*natp
,
95 int32_t NaClCommonSysThreadExit(struct NaClAppThread
*natp
,
98 void NaClInsecurelyBypassAllAclChecks(void);
100 int32_t NaClCommonSysOpen(struct NaClAppThread
*natp
,
105 int32_t NaClCommonSysClose(struct NaClAppThread
*natp
,
108 int32_t NaClCommonSysRead(struct NaClAppThread
*natp
,
113 int32_t NaClCommonSysWrite(struct NaClAppThread
*natp
,
118 int32_t NaClCommonSysLseek(struct NaClAppThread
*natp
,
123 int32_t NaClCommonSysIoctl(struct NaClAppThread
*natp
,
128 int32_t NaClCommonSysFstat(struct NaClAppThread
*natp
,
130 struct nacl_abi_stat
*nasp
);
132 int32_t NaClCommonSysStat(struct NaClAppThread
*natp
,
134 struct nacl_abi_stat
*nasp
);
136 void NaClCommonUtilUpdateAddrMap(struct NaClAppThread
*natp
,
140 struct NaClDesc
*backing_desc
,
141 size_t backing_bytes
,
146 int NaClSysCommonAddrRangeContainsExecutablePages_mu(struct NaClApp
*nap
,
150 int32_t NaClCommonSysMmap(struct NaClAppThread
*natp
,
156 nacl_abi_off_t offset
);
157 int32_t NaClSysMmap(struct NaClAppThread
*natp
,
163 nacl_abi_off_t offset
);
164 int32_t NaClSysMunmap(struct NaClAppThread
*natp
,
168 int32_t NaClSysMmap(struct NaClAppThread
*natp
,
174 nacl_abi_off_t offset
);
176 int32_t NaClSysMunmap(struct NaClAppThread
*natp
,
180 int32_t NaClCommonSysGetdents(struct NaClAppThread
*natp
,
185 int32_t NaClCommonSysImc_MakeBoundSock(struct NaClAppThread
*natp
,
188 int32_t NaClCommonSysImc_Accept(struct NaClAppThread
*natp
,
191 int32_t NaClCommonSysImc_Connect(struct NaClAppThread
*natp
,
194 int32_t NaClCommonSysImc_Sendmsg(struct NaClAppThread
*natp
,
196 struct NaClImcMsgHdr
*nimhp
,
199 int32_t NaClCommonSysImc_Recvmsg(struct NaClAppThread
*natp
,
201 struct NaClImcMsgHdr
*nimhp
,
204 int32_t NaClCommonSysImc_Mem_Obj_Create(struct NaClAppThread
*natp
,
207 int32_t NaClCommonSysTls_Init(struct NaClAppThread
*natp
,
211 int32_t NaClCommonSysThread_Create(struct NaClAppThread
*natp
,
217 #if defined(HAVE_SDL)
219 int32_t NaClCommonSysMultimedia_Init(struct NaClAppThread
*natp
,
222 int32_t NaClCommonSysMultimedia_Shutdown(struct NaClAppThread
*natp
);
224 int32_t NaClCommonSysVideo_Init(struct NaClAppThread
*natp
,
228 int32_t NaClCommonSysVideo_Shutdown(struct NaClAppThread
*natp
);
230 int32_t NaClCommonSysVideo_Update(struct NaClAppThread
*natp
,
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
,
239 int *obtained_samples
);
241 int32_t NaClCommonSysAudio_Stream(struct NaClAppThread
*natp
,
245 int32_t NaClCommonSysAudio_Shutdown(struct NaClAppThread
*natp
);
247 #endif /* HAVE_SDL */
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
,
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
,
278 int32_t mutex_handle
,
279 struct nacl_abi_timespec
*ts
);
281 int32_t NaClCommonSysCond_Timed_Wait_Abs(struct NaClAppThread
*natp
,
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
,
291 int32_t NaClCommonSysSem_Create(struct NaClAppThread
*natp
,
294 int32_t NaClCommonSysSem_Wait(struct NaClAppThread
*natp
,
297 int32_t NaClCommonSysSem_Post(struct NaClAppThread
*natp
,
300 int32_t NaClCommonSysSem_Get_Value(struct NaClAppThread
*natp
,
305 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_SYSCALL_COMMON_H__ */