1 #ifndef _INTERNAL_SYSCALL_H
2 #define _INTERNAL_SYSCALL_H
6 #include <sys/syscall.h>
7 #include "syscall_arch.h"
9 #ifndef SYSCALL_RLIM_INFINITY
10 #define SYSCALL_RLIM_INFINITY (~0ULL)
13 #ifndef SYSCALL_MMAP2_UNIT
14 #define SYSCALL_MMAP2_UNIT 4096ULL
17 #ifndef __SYSCALL_LL_PRW
18 #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x)
22 #define __scc(X) ((long) (X))
23 typedef long syscall_arg_t
;
26 hidden
long __syscall_ret(unsigned long),
27 __syscall_cp(syscall_arg_t
, syscall_arg_t
, syscall_arg_t
, syscall_arg_t
,
28 syscall_arg_t
, syscall_arg_t
, syscall_arg_t
);
30 #define __syscall1(n,a) __syscall1(n,__scc(a))
31 #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
32 #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
33 #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
34 #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
35 #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
36 #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 #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
39 #define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)
40 #define __SYSCALL_CONCAT_X(a,b) a##b
41 #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b)
42 #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
44 #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
45 #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__))
47 #define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f))
48 #define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f))
50 #define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
51 #define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0)
52 #define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0)
53 #define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0)
54 #define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0)
55 #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0)
56 #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 #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
59 #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
61 static inline long __alt_socketcall(int sys
, int sock
, int cp
, syscall_arg_t a
, syscall_arg_t b
, syscall_arg_t c
, syscall_arg_t d
, syscall_arg_t e
, syscall_arg_t f
)
64 if (cp
) r
= __syscall_cp(sys
, a
, b
, c
, d
, e
, f
);
65 else r
= __syscall(sys
, a
, b
, c
, d
, e
, f
);
66 if (r
!= -ENOSYS
) return r
;
68 if (cp
) r
= __syscall_cp(SYS_socketcall
, sock
, ((long[6]){a
, b
, c
, d
, e
, f
}));
69 else r
= __syscall(SYS_socketcall
, sock
, ((long[6]){a
, b
, c
, d
, e
, f
}));
73 #define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \
74 __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f))
75 #define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \
76 __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f))
78 /* fixup legacy 16-bit junk */
100 #define SYS_lchown SYS_lchown32
101 #define SYS_getuid SYS_getuid32
102 #define SYS_getgid SYS_getgid32
103 #define SYS_geteuid SYS_geteuid32
104 #define SYS_getegid SYS_getegid32
105 #define SYS_setreuid SYS_setreuid32
106 #define SYS_setregid SYS_setregid32
107 #define SYS_getgroups SYS_getgroups32
108 #define SYS_setgroups SYS_setgroups32
109 #define SYS_fchown SYS_fchown32
110 #define SYS_setresuid SYS_setresuid32
111 #define SYS_getresuid SYS_getresuid32
112 #define SYS_setresgid SYS_setresgid32
113 #define SYS_getresgid SYS_getresgid32
114 #define SYS_chown SYS_chown32
115 #define SYS_setuid SYS_setuid32
116 #define SYS_setgid SYS_setgid32
117 #define SYS_setfsuid SYS_setfsuid32
118 #define SYS_setfsgid SYS_setfsgid32
122 /* fixup legacy 32-bit-vs-lfs64 junk */
126 #define SYS_fcntl SYS_fcntl64
129 #ifdef SYS_getdents64
131 #define SYS_getdents SYS_getdents64
134 #ifdef SYS_ftruncate64
137 #define SYS_ftruncate SYS_ftruncate64
138 #define SYS_truncate SYS_truncate64
143 #define SYS_stat SYS_stat64
148 #define SYS_fstat SYS_fstat64
153 #define SYS_lstat SYS_lstat64
158 #define SYS_statfs SYS_statfs64
163 #define SYS_fstatfs SYS_fstatfs64
166 #if defined(SYS_newfstatat)
168 #define SYS_fstatat SYS_newfstatat
169 #elif defined(SYS_fstatat64)
171 #define SYS_fstatat SYS_fstatat64
174 #ifdef SYS_ugetrlimit
176 #define SYS_getrlimit SYS_ugetrlimit
179 #ifdef SYS__newselect
181 #define SYS_select SYS__newselect
187 #define SYS_pread SYS_pread64
188 #define SYS_pwrite SYS_pwrite64
191 #ifdef SYS_fadvise64_64
193 #define SYS_fadvise SYS_fadvise64_64
194 #elif defined(SYS_fadvise64)
196 #define SYS_fadvise SYS_fadvise64
199 #ifdef SYS_sendfile64
201 #define SYS_sendfile SYS_sendfile64
204 #ifdef SYS_timer_settime32
205 #define SYS_timer_settime SYS_timer_settime32
208 #ifdef SYS_timer_gettime32
209 #define SYS_timer_gettime SYS_timer_gettime32
212 #ifdef SYS_timerfd_settime32
213 #define SYS_timerfd_settime SYS_timerfd_settime32
216 #ifdef SYS_timerfd_gettime32
217 #define SYS_timerfd_gettime SYS_timerfd_gettime32
220 #ifdef SYS_clock_settime32
221 #define SYS_clock_settime SYS_clock_settime32
224 #ifdef SYS_clock_gettime32
225 #define SYS_clock_gettime SYS_clock_gettime32
228 #ifdef SYS_clock_getres_time32
229 #define SYS_clock_getres SYS_clock_getres_time32
232 #ifdef SYS_clock_nanosleep_time32
233 #define SYS_clock_nanosleep SYS_clock_nanosleep_time32
236 #ifdef SYS_gettimeofday_time32
237 #define SYS_gettimeofday SYS_gettimeofday_time32
240 #ifdef SYS_settimeofday_time32
241 #define SYS_settimeofday SYS_settimeofday_time32
244 /* Ensure that the plain syscall names are defined even for "time64-only"
245 * archs. These facilitate callers passing null time arguments, and make
246 * tests for establishing which to use/fallback-to more consistent when
247 * they do need to be called with time arguments. */
249 #ifndef SYS_clock_gettime
250 #define SYS_clock_gettime SYS_clock_gettime64
253 #ifndef SYS_clock_settime
254 #define SYS_clock_settime SYS_clock_settime64
257 #ifndef SYS_clock_adjtime
258 #define SYS_clock_adjtime SYS_clock_adjtime64
261 #ifndef SYS_clock_getres
262 #define SYS_clock_getres SYS_clock_getres_time64
265 #ifndef SYS_clock_nanosleep
266 #define SYS_clock_nanosleep SYS_clock_nanosleep_time64
269 #ifndef SYS_timer_gettime
270 #define SYS_timer_gettime SYS_timer_gettime64
273 #ifndef SYS_timer_settime
274 #define SYS_timer_settime SYS_timer_settime64
277 #ifndef SYS_timerfd_gettime
278 #define SYS_timerfd_gettime SYS_timerfd_gettime64
281 #ifndef SYS_timerfd_settime
282 #define SYS_timerfd_settime SYS_timerfd_settime64
285 #ifndef SYS_utimensat
286 #define SYS_utimensat SYS_utimensat_time64
290 #define SYS_pselect6 SYS_pselect6_time64
294 #define SYS_ppoll SYS_ppoll_time64
298 #define SYS_recvmmsg SYS_recvmmsg_time64
301 #ifndef SYS_mq_timedsend
302 #define SYS_mq_timedsend SYS_mq_timedsend_time64
305 #ifndef SYS_mq_timedreceive
306 #define SYS_mq_timedreceive SYS_mq_timedreceive_time64
309 /* SYS_semtimedop omitted because SYS_ipc may provide it */
311 #ifndef SYS_rt_sigtimedwait
312 #define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64
316 #define SYS_futex SYS_futex_time64
319 #ifndef SYS_sched_rr_get_interval
320 #define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64
326 /* socketcall calls */
328 #define __SC_socket 1
330 #define __SC_connect 3
331 #define __SC_listen 4
332 #define __SC_accept 5
333 #define __SC_getsockname 6
334 #define __SC_getpeername 7
335 #define __SC_socketpair 8
338 #define __SC_sendto 11
339 #define __SC_recvfrom 12
340 #define __SC_shutdown 13
341 #define __SC_setsockopt 14
342 #define __SC_getsockopt 15
343 #define __SC_sendmsg 16
344 #define __SC_recvmsg 17
345 #define __SC_accept4 18
346 #define __SC_recvmmsg 19
347 #define __SC_sendmmsg 20
349 /* This is valid only because all socket syscalls are made via
350 * socketcall, which always fills unused argument slots with zeros. */
352 #define SYS_accept SYS_accept4
355 #ifndef SO_RCVTIMEO_OLD
356 #define SO_RCVTIMEO_OLD 20
358 #ifndef SO_SNDTIMEO_OLD
359 #define SO_SNDTIMEO_OLD 21
362 #define SO_TIMESTAMP_OLD 29
363 #define SO_TIMESTAMPNS_OLD 35
364 #define SO_TIMESTAMPING_OLD 37
365 #define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD
366 #define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD
367 #define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD
369 #ifndef SIOCGSTAMP_OLD
370 #define SIOCGSTAMP_OLD 0x8906
372 #ifndef SIOCGSTAMPNS_OLD
373 #define SIOCGSTAMPNS_OLD 0x8907
377 #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE)
378 #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
379 #define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE)
380 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
382 #define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
383 #define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
384 #define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
385 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
388 #define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)
389 #define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__))
391 #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__)
392 #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__))
395 #define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d)
396 #define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d)
398 hidden
long __emulate_wait4(int, int *, int, void *, int);
399 #define __sys_wait4(a,b,c,d) __emulate_wait4(a,b,c,d,0)
400 #define __sys_wait4_cp(a,b,c,d) __emulate_wait4(a,b,c,d,1)
403 #define sys_wait4(a,b,c,d) __syscall_ret(__sys_wait4(a,b,c,d))
404 #define sys_wait4_cp(a,b,c,d) __syscall_ret(__sys_wait4_cp(a,b,c,d))
406 hidden
void __procfdname(char __buf
[static 15+3*sizeof(int)], unsigned);
408 hidden
void *__vdsosym(const char *, const char *);