1 #ifndef __LITEOS__
2 #ifndef _INTERNAL_SYSCALL_H
3 #define _INTERNAL_SYSCALL_H
4
5 #include <features.h>
6 #include <errno.h>
7 #include <sys/syscall.h>
8 #include "syscall_arch.h"
9
10 #ifndef SYSCALL_RLIM_INFINITY
11 #define SYSCALL_RLIM_INFINITY (~0ULL)
12 #endif
13
14 #ifndef SYSCALL_MMAP2_UNIT
15 #define SYSCALL_MMAP2_UNIT 4096ULL
16 #endif
17
18 #ifndef __SYSCALL_LL_PRW
19 #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x)
20 #endif
21
22 #ifndef __scc
23 #define __scc(X) ((long) (X))
24 typedef long syscall_arg_t;
25 #endif
26
27 hidden long __syscall_ret(unsigned long),
28 __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
29 syscall_arg_t, syscall_arg_t, syscall_arg_t);
30
31 #define __syscall1(n,a) __syscall1(n,__scc(a))
32 #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
33 #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
34 #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
35 #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
36 #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
37 #define __syscall7(n,a,b,c,d,e,f,g) __syscall7(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g))
38
39 #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
40 #define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)
41 #define __SYSCALL_CONCAT_X(a,b) a##b
42 #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b)
43 #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
44
45 #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
46 #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__))
47
48 #define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f))
49 #define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f))
50
51 #define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
52 #define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0)
53 #define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0)
54 #define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0)
55 #define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0)
56 #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0)
57 #define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
58
59 #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
60 #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
61
__alt_socketcall(int sys,int sock,int cp,long a,long b,long c,long d,long e,long f)62 static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f)
63 {
64 long r;
65 if (cp) r = __syscall_cp(sys, a, b, c, d, e, f);
66 else r = __syscall(sys, a, b, c, d, e, f);
67 if (r != -ENOSYS) return r;
68 #ifdef SYS_socketcall
69 if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
70 else r = __syscall(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
71 #endif
72 return r;
73 }
74 #define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \
75 (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
76 #define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \
77 (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
78
79 /* fixup legacy 16-bit junk */
80
81 #ifdef SYS_getuid32
82 #undef SYS_lchown
83 #undef SYS_getuid
84 #undef SYS_getgid
85 #undef SYS_geteuid
86 #undef SYS_getegid
87 #undef SYS_setreuid
88 #undef SYS_setregid
89 #undef SYS_getgroups
90 #undef SYS_setgroups
91 #undef SYS_fchown
92 #undef SYS_setresuid
93 #undef SYS_getresuid
94 #undef SYS_setresgid
95 #undef SYS_getresgid
96 #undef SYS_chown
97 #undef SYS_setuid
98 #undef SYS_setgid
99 #undef SYS_setfsuid
100 #undef SYS_setfsgid
101 #define SYS_lchown SYS_lchown32
102 #define SYS_getuid SYS_getuid32
103 #define SYS_getgid SYS_getgid32
104 #define SYS_geteuid SYS_geteuid32
105 #define SYS_getegid SYS_getegid32
106 #define SYS_setreuid SYS_setreuid32
107 #define SYS_setregid SYS_setregid32
108 #define SYS_getgroups SYS_getgroups32
109 #define SYS_setgroups SYS_setgroups32
110 #define SYS_fchown SYS_fchown32
111 #define SYS_setresuid SYS_setresuid32
112 #define SYS_getresuid SYS_getresuid32
113 #define SYS_setresgid SYS_setresgid32
114 #define SYS_getresgid SYS_getresgid32
115 #define SYS_chown SYS_chown32
116 #define SYS_setuid SYS_setuid32
117 #define SYS_setgid SYS_setgid32
118 #define SYS_setfsuid SYS_setfsuid32
119 #define SYS_setfsgid SYS_setfsgid32
120 #endif
121
122
123 /* fixup legacy 32-bit-vs-lfs64 junk */
124
125 #ifdef SYS_fcntl64
126 #undef SYS_fcntl
127 #define SYS_fcntl SYS_fcntl64
128 #endif
129
130 #ifdef SYS_getdents64
131 #undef SYS_getdents
132 #define SYS_getdents SYS_getdents64
133 #endif
134
135 #ifdef SYS_ftruncate64
136 #undef SYS_ftruncate
137 #undef SYS_truncate
138 #define SYS_ftruncate SYS_ftruncate64
139 #define SYS_truncate SYS_truncate64
140 #endif
141
142 #ifdef SYS_stat64
143 #undef SYS_stat
144 #define SYS_stat SYS_stat64
145 #endif
146
147 #ifdef SYS_fstat64
148 #undef SYS_fstat
149 #define SYS_fstat SYS_fstat64
150 #endif
151
152 #ifdef SYS_lstat64
153 #undef SYS_lstat
154 #define SYS_lstat SYS_lstat64
155 #endif
156
157 #ifdef SYS_statfs64
158 #undef SYS_statfs
159 #define SYS_statfs SYS_statfs64
160 #endif
161
162 #ifdef SYS_fstatfs64
163 #undef SYS_fstatfs
164 #define SYS_fstatfs SYS_fstatfs64
165 #endif
166
167 #if defined(SYS_newfstatat)
168 #undef SYS_fstatat
169 #define SYS_fstatat SYS_newfstatat
170 #elif defined(SYS_fstatat64)
171 #undef SYS_fstatat
172 #define SYS_fstatat SYS_fstatat64
173 #endif
174
175 #ifdef SYS_ugetrlimit
176 #undef SYS_getrlimit
177 #define SYS_getrlimit SYS_ugetrlimit
178 #endif
179
180 #ifdef SYS__newselect
181 #undef SYS_select
182 #define SYS_select SYS__newselect
183 #endif
184
185 #ifdef SYS_pread64
186 #undef SYS_pread
187 #undef SYS_pwrite
188 #define SYS_pread SYS_pread64
189 #define SYS_pwrite SYS_pwrite64
190 #endif
191
192 #ifdef SYS_fadvise64_64
193 #undef SYS_fadvise
194 #define SYS_fadvise SYS_fadvise64_64
195 #elif defined(SYS_fadvise64)
196 #undef SYS_fadvise
197 #define SYS_fadvise SYS_fadvise64
198 #endif
199
200 #ifdef SYS_sendfile64
201 #undef SYS_sendfile
202 #define SYS_sendfile SYS_sendfile64
203 #endif
204
205 #ifndef SYS_timer_settime
206 #define SYS_timer_settime SYS_timer_settime32
207 #endif
208
209 #ifndef SYS_timer_gettime
210 #define SYS_timer_gettime SYS_timer_gettime32
211 #endif
212
213 #ifndef SYS_timerfd_settime
214 #define SYS_timerfd_settime SYS_timerfd_settime32
215 #endif
216
217 #ifndef SYS_timerfd_gettime
218 #define SYS_timerfd_gettime SYS_timerfd_gettime32
219 #endif
220
221 #ifndef SYS_clock_settime
222 #define SYS_clock_settime SYS_clock_settime32
223 #endif
224
225 #ifndef SYS_clock_gettime
226 #define SYS_clock_gettime SYS_clock_gettime32
227 #endif
228
229 #ifndef SYS_clock_getres
230 #define SYS_clock_getres SYS_clock_getres_time32
231 #endif
232
233 #ifndef SYS_clock_nanosleep
234 #define SYS_clock_nanosleep SYS_clock_nanosleep_time32
235 #endif
236
237 #ifndef SYS_gettimeofday
238 #define SYS_gettimeofday SYS_gettimeofday_time32
239 #endif
240
241 #ifndef SYS_settimeofday
242 #define SYS_settimeofday SYS_settimeofday_time32
243 #endif
244
245 /* Ensure that the plain syscall names are defined even for "time64-only"
246 * archs. These facilitate callers passing null time arguments, and make
247 * tests for establishing which to use/fallback-to more consistent when
248 * they do need to be called with time arguments. */
249
250 #ifndef SYS_clock_gettime
251 #define SYS_clock_gettime SYS_clock_gettime64
252 #endif
253
254 #ifndef SYS_clock_settime
255 #define SYS_clock_settime SYS_clock_settime64
256 #endif
257
258 #ifndef SYS_clock_adjtime
259 #define SYS_clock_adjtime SYS_clock_adjtime64
260 #endif
261
262 #ifndef SYS_clock_getres
263 #define SYS_clock_getres SYS_clock_getres_time64
264 #endif
265
266 #ifndef SYS_clock_nanosleep
267 #define SYS_clock_nanosleep SYS_clock_nanosleep_time64
268 #endif
269
270 #ifndef SYS_timer_gettime
271 #define SYS_timer_gettime SYS_timer_gettime64
272 #endif
273
274 #ifndef SYS_timer_settime
275 #define SYS_timer_settime SYS_timer_settime64
276 #endif
277
278 #ifndef SYS_timerfd_gettime
279 #define SYS_timerfd_gettime SYS_timerfd_gettime64
280 #endif
281
282 #ifndef SYS_timerfd_settime
283 #define SYS_timerfd_settime SYS_timerfd_settime64
284 #endif
285
286 #ifndef SYS_utimensat
287 #define SYS_utimensat SYS_utimensat_time64
288 #endif
289
290 #ifndef SYS_pselect6
291 #define SYS_pselect6 SYS_pselect6_time64
292 #endif
293
294 #ifndef SYS_ppoll
295 #define SYS_ppoll SYS_ppoll_time64
296 #endif
297
298 #ifndef SYS_recvmmsg
299 #define SYS_recvmmsg SYS_recvmmsg_time64
300 #endif
301
302 #ifndef SYS_mq_timedsend
303 #define SYS_mq_timedsend SYS_mq_timedsend_time64
304 #endif
305
306 #ifndef SYS_mq_timedreceive
307 #define SYS_mq_timedreceive SYS_mq_timedreceive_time64
308 #endif
309
310 /* SYS_semtimedop omitted because SYS_ipc may provide it */
311
312 #ifndef SYS_rt_sigtimedwait
313 #define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64
314 #endif
315
316 #ifndef SYS_futex
317 #define SYS_futex SYS_futex_time64
318 #endif
319
320 #ifndef SYS_sched_rr_get_interval
321 #define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64
322 #endif
323
324
325
326
327 /* socketcall calls */
328
329 #define __SC_socket 1
330 #define __SC_bind 2
331 #define __SC_connect 3
332 #define __SC_listen 4
333 #define __SC_accept 5
334 #define __SC_getsockname 6
335 #define __SC_getpeername 7
336 #define __SC_socketpair 8
337 #define __SC_send 9
338 #define __SC_recv 10
339 #define __SC_sendto 11
340 #define __SC_recvfrom 12
341 #define __SC_shutdown 13
342 #define __SC_setsockopt 14
343 #define __SC_getsockopt 15
344 #define __SC_sendmsg 16
345 #define __SC_recvmsg 17
346 #define __SC_accept4 18
347 #define __SC_recvmmsg 19
348 #define __SC_sendmmsg 20
349
350 /* This is valid only because all socket syscalls are made via
351 * socketcall, which always fills unused argument slots with zeros. */
352 #ifndef SYS_accept
353 #define SYS_accept SYS_accept4
354 #endif
355
356 #ifndef SO_RCVTIMEO_OLD
357 #define SO_RCVTIMEO_OLD 20
358 #endif
359 #ifndef SO_SNDTIMEO_OLD
360 #define SO_SNDTIMEO_OLD 21
361 #endif
362
363 #define SO_TIMESTAMP_OLD 29
364 #define SO_TIMESTAMPNS_OLD 35
365 #define SO_TIMESTAMPING_OLD 37
366 #define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD
367 #define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD
368 #define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD
369
370 #ifndef SIOCGSTAMP_OLD
371 #define SIOCGSTAMP_OLD 0x8906
372 #endif
373 #ifndef SIOCGSTAMPNS_OLD
374 #define SIOCGSTAMPNS_OLD 0x8907
375 #endif
376
377 #ifdef SYS_open
378 #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE)
379 #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
380 #define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE)
381 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
382 #else
383 #define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
384 #define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
385 #define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
386 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
387 #endif
388
389 #define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)
390 #define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__))
391
392 #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__)
393 #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__))
394
395 hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned);
396
397 hidden void *__vdsosym(const char *, const char *);
398
399 #endif
400 #endif
401