• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _INTERNAL_SYSCALL_H
2 #define _INTERNAL_SYSCALL_H
3 
4 #include <features.h>
5 #include <errno.h>
6 #include <sys/syscall.h>
7 #include "syscall_arch.h"
8 
9 #ifndef SYSCALL_RLIM_INFINITY
10 #define SYSCALL_RLIM_INFINITY (~0ULL)
11 #endif
12 
13 #ifndef SYSCALL_MMAP2_UNIT
14 #define SYSCALL_MMAP2_UNIT 4096ULL
15 #endif
16 
17 #ifndef __SYSCALL_LL_PRW
18 #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x)
19 #endif
20 
21 #ifndef __scc
22 #define __scc(X) ((long) (X))
23 typedef long syscall_arg_t;
24 #endif
25 
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);
29 
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))
37 
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__)
43 
44 #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
45 #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__))
46 
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))
49 
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))
57 
58 #ifdef FEATURE_PTHREAD_CANCEL
59 #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
60 #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
61 #else
62 #define __syscall_cp(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
63 #define syscall_cp(...) __syscall_ret(__syscall(__VA_ARGS__))
64 #endif
65 
__alt_socketcall(int sys,int sock,int cp,long a,long b,long c,long d,long e,long f)66 static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f)
67 {
68 	long r;
69 	if (cp) r = __syscall_cp(sys, a, b, c, d, e, f);
70 	else r = __syscall(sys, a, b, c, d, e, f);
71 	if (r != -ENOSYS) return r;
72 #ifdef SYS_socketcall
73 	if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
74 	else r = __syscall(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f}));
75 #endif
76 	return r;
77 }
78 #define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \
79 	(long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
80 #define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \
81 	(long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
82 
83 /* fixup legacy 16-bit junk */
84 
85 #ifdef SYS_getuid32
86 #undef SYS_lchown
87 #undef SYS_getuid
88 #undef SYS_getgid
89 #undef SYS_geteuid
90 #undef SYS_getegid
91 #undef SYS_setreuid
92 #undef SYS_setregid
93 #undef SYS_getgroups
94 #undef SYS_setgroups
95 #undef SYS_fchown
96 #undef SYS_setresuid
97 #undef SYS_getresuid
98 #undef SYS_setresgid
99 #undef SYS_getresgid
100 #undef SYS_chown
101 #undef SYS_setuid
102 #undef SYS_setgid
103 #undef SYS_setfsuid
104 #undef SYS_setfsgid
105 #define SYS_lchown SYS_lchown32
106 #define SYS_getuid SYS_getuid32
107 #define SYS_getgid SYS_getgid32
108 #define SYS_geteuid SYS_geteuid32
109 #define SYS_getegid SYS_getegid32
110 #define SYS_setreuid SYS_setreuid32
111 #define SYS_setregid SYS_setregid32
112 #define SYS_getgroups SYS_getgroups32
113 #define SYS_setgroups SYS_setgroups32
114 #define SYS_fchown SYS_fchown32
115 #define SYS_setresuid SYS_setresuid32
116 #define SYS_getresuid SYS_getresuid32
117 #define SYS_setresgid SYS_setresgid32
118 #define SYS_getresgid SYS_getresgid32
119 #define SYS_chown SYS_chown32
120 #define SYS_setuid SYS_setuid32
121 #define SYS_setgid SYS_setgid32
122 #define SYS_setfsuid SYS_setfsuid32
123 #define SYS_setfsgid SYS_setfsgid32
124 #endif
125 
126 
127 /* fixup legacy 32-bit-vs-lfs64 junk */
128 
129 #ifdef SYS_fcntl64
130 #undef SYS_fcntl
131 #define SYS_fcntl SYS_fcntl64
132 #endif
133 
134 #ifdef SYS_getdents64
135 #undef SYS_getdents
136 #define SYS_getdents SYS_getdents64
137 #endif
138 
139 #ifdef SYS_ftruncate64
140 #undef SYS_ftruncate
141 #undef SYS_truncate
142 #define SYS_ftruncate SYS_ftruncate64
143 #define SYS_truncate SYS_truncate64
144 #endif
145 
146 #ifdef SYS_stat64
147 #undef SYS_stat
148 #define SYS_stat SYS_stat64
149 #endif
150 
151 #ifdef SYS_fstat64
152 #undef SYS_fstat
153 #define SYS_fstat SYS_fstat64
154 #endif
155 
156 #ifdef SYS_lstat64
157 #undef SYS_lstat
158 #define SYS_lstat SYS_lstat64
159 #endif
160 
161 #ifdef SYS_statfs64
162 #undef SYS_statfs
163 #define SYS_statfs SYS_statfs64
164 #endif
165 
166 #ifdef SYS_fstatfs64
167 #undef SYS_fstatfs
168 #define SYS_fstatfs SYS_fstatfs64
169 #endif
170 
171 #if defined(SYS_newfstatat)
172 #undef SYS_fstatat
173 #define SYS_fstatat SYS_newfstatat
174 #elif defined(SYS_fstatat64)
175 #undef SYS_fstatat
176 #define SYS_fstatat SYS_fstatat64
177 #endif
178 
179 #ifdef SYS_ugetrlimit
180 #undef SYS_getrlimit
181 #define SYS_getrlimit SYS_ugetrlimit
182 #endif
183 
184 #ifdef SYS__newselect
185 #undef SYS_select
186 #define SYS_select SYS__newselect
187 #endif
188 
189 #ifdef SYS_pread64
190 #undef SYS_pread
191 #undef SYS_pwrite
192 #define SYS_pread SYS_pread64
193 #define SYS_pwrite SYS_pwrite64
194 #endif
195 
196 #ifdef SYS_fadvise64_64
197 #undef SYS_fadvise
198 #define SYS_fadvise SYS_fadvise64_64
199 #elif defined(SYS_fadvise64)
200 #undef SYS_fadvise
201 #define SYS_fadvise SYS_fadvise64
202 #endif
203 
204 #ifdef SYS_sendfile64
205 #undef SYS_sendfile
206 #define SYS_sendfile SYS_sendfile64
207 #endif
208 
209 #ifndef SYS_timer_settime
210 #define SYS_timer_settime SYS_timer_settime32
211 #endif
212 
213 #ifndef SYS_timer_gettime
214 #define SYS_timer_gettime SYS_timer_gettime32
215 #endif
216 
217 #ifndef SYS_timerfd_settime
218 #define SYS_timerfd_settime SYS_timerfd_settime32
219 #endif
220 
221 #ifndef SYS_timerfd_gettime
222 #define SYS_timerfd_gettime SYS_timerfd_gettime32
223 #endif
224 
225 #ifndef SYS_clock_settime
226 #define SYS_clock_settime SYS_clock_settime32
227 #endif
228 
229 #ifndef SYS_clock_gettime
230 #define SYS_clock_gettime SYS_clock_gettime32
231 #endif
232 
233 #ifndef SYS_clock_getres
234 #define SYS_clock_getres SYS_clock_getres_time32
235 #endif
236 
237 #ifndef SYS_clock_nanosleep
238 #define SYS_clock_nanosleep SYS_clock_nanosleep_time32
239 #endif
240 
241 #ifndef SYS_gettimeofday
242 #define SYS_gettimeofday SYS_gettimeofday_time32
243 #endif
244 
245 #ifndef SYS_settimeofday
246 #define SYS_settimeofday SYS_settimeofday_time32
247 #endif
248 
249 /* Ensure that the plain syscall names are defined even for "time64-only"
250  * archs. These facilitate callers passing null time arguments, and make
251  * tests for establishing which to use/fallback-to more consistent when
252  * they do need to be called with time arguments. */
253 
254 #ifndef SYS_clock_gettime
255 #define SYS_clock_gettime SYS_clock_gettime64
256 #endif
257 
258 #ifndef SYS_clock_settime
259 #define SYS_clock_settime SYS_clock_settime64
260 #endif
261 
262 #ifndef SYS_clock_adjtime
263 #define SYS_clock_adjtime SYS_clock_adjtime64
264 #endif
265 
266 #ifndef SYS_clock_getres
267 #define SYS_clock_getres SYS_clock_getres_time64
268 #endif
269 
270 #ifndef SYS_clock_nanosleep
271 #define SYS_clock_nanosleep SYS_clock_nanosleep_time64
272 #endif
273 
274 #ifndef SYS_timer_gettime
275 #define SYS_timer_gettime SYS_timer_gettime64
276 #endif
277 
278 #ifndef SYS_timer_settime
279 #define SYS_timer_settime SYS_timer_settime64
280 #endif
281 
282 #ifndef SYS_timerfd_gettime
283 #define SYS_timerfd_gettime SYS_timerfd_gettime64
284 #endif
285 
286 #ifndef SYS_timerfd_settime
287 #define SYS_timerfd_settime SYS_timerfd_settime64
288 #endif
289 
290 #ifndef SYS_utimensat
291 #define SYS_utimensat SYS_utimensat_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 hidden void __get_vdso_info();
400 hidden void *__get_vdso_addr(const char *, const char *);
401 
402 #endif
403