1 #ifndef _INTERNAL_SYSCALL_H 2 #define _INTERNAL_SYSCALL_H 3 4 #include <features.h> 5 #include <sys/syscall.h> 6 #include "syscall_arch.h" 7 8 #ifndef SYSCALL_RLIM_INFINITY 9 #define SYSCALL_RLIM_INFINITY (~0ULL) 10 #endif 11 12 #ifndef SYSCALL_MMAP2_UNIT 13 #define SYSCALL_MMAP2_UNIT 4096ULL 14 #endif 15 16 #ifndef __SYSCALL_LL_PRW 17 #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x) 18 #endif 19 20 #ifndef __scc 21 #define __scc(X) ((long) (X)) 22 typedef long syscall_arg_t; 23 #endif 24 25 hidden long __syscall_ret(unsigned long), 26 __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, 27 syscall_arg_t, syscall_arg_t, syscall_arg_t); 28 29 #define __syscall1(n,a) __syscall1(n,__scc(a)) 30 #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b)) 31 #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c)) 32 #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d)) 33 #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) 34 #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) 35 #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)) 36 37 #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n 38 #define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) 39 #define __SYSCALL_CONCAT_X(a,b) a##b 40 #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) 41 #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) 42 43 #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) 44 #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) 45 46 #define socketcall __socketcall 47 #define socketcall_cp __socketcall_cp 48 49 #define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0) 50 #define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0) 51 #define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0) 52 #define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0) 53 #define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0) 54 #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0) 55 #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)) 56 57 #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) 58 #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) 59 60 #ifndef SYSCALL_USE_SOCKETCALL 61 #define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f) 62 #define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f) 63 #else 64 #define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_socketcall, __SC_##nm, \ 65 ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) 66 #define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_socketcall, __SC_##nm, \ 67 ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) 68 #endif 69 70 /* fixup legacy 16-bit junk */ 71 72 #ifdef SYS_getuid32 73 #undef SYS_lchown 74 #undef SYS_getuid 75 #undef SYS_getgid 76 #undef SYS_geteuid 77 #undef SYS_getegid 78 #undef SYS_setreuid 79 #undef SYS_setregid 80 #undef SYS_getgroups 81 #undef SYS_setgroups 82 #undef SYS_fchown 83 #undef SYS_setresuid 84 #undef SYS_getresuid 85 #undef SYS_setresgid 86 #undef SYS_getresgid 87 #undef SYS_chown 88 #undef SYS_setuid 89 #undef SYS_setgid 90 #undef SYS_setfsuid 91 #undef SYS_setfsgid 92 #define SYS_lchown SYS_lchown32 93 #define SYS_getuid SYS_getuid32 94 #define SYS_getgid SYS_getgid32 95 #define SYS_geteuid SYS_geteuid32 96 #define SYS_getegid SYS_getegid32 97 #define SYS_setreuid SYS_setreuid32 98 #define SYS_setregid SYS_setregid32 99 #define SYS_getgroups SYS_getgroups32 100 #define SYS_setgroups SYS_setgroups32 101 #define SYS_fchown SYS_fchown32 102 #define SYS_setresuid SYS_setresuid32 103 #define SYS_getresuid SYS_getresuid32 104 #define SYS_setresgid SYS_setresgid32 105 #define SYS_getresgid SYS_getresgid32 106 #define SYS_chown SYS_chown32 107 #define SYS_setuid SYS_setuid32 108 #define SYS_setgid SYS_setgid32 109 #define SYS_setfsuid SYS_setfsuid32 110 #define SYS_setfsgid SYS_setfsgid32 111 #endif 112 113 114 /* fixup legacy 32-bit-vs-lfs64 junk */ 115 116 #ifdef SYS_fcntl64 117 #undef SYS_fcntl 118 #define SYS_fcntl SYS_fcntl64 119 #endif 120 121 #ifdef SYS_getdents64 122 #undef SYS_getdents 123 #define SYS_getdents SYS_getdents64 124 #endif 125 126 #ifdef SYS_ftruncate64 127 #undef SYS_ftruncate 128 #undef SYS_truncate 129 #define SYS_ftruncate SYS_ftruncate64 130 #define SYS_truncate SYS_truncate64 131 #endif 132 133 #ifdef SYS_stat64 134 #undef SYS_stat 135 #define SYS_stat SYS_stat64 136 #endif 137 138 #ifdef SYS_fstat64 139 #undef SYS_fstat 140 #define SYS_fstat SYS_fstat64 141 #endif 142 143 #ifdef SYS_lstat64 144 #undef SYS_lstat 145 #define SYS_lstat SYS_lstat64 146 #endif 147 148 #ifdef SYS_statfs64 149 #undef SYS_statfs 150 #define SYS_statfs SYS_statfs64 151 #endif 152 153 #ifdef SYS_fstatfs64 154 #undef SYS_fstatfs 155 #define SYS_fstatfs SYS_fstatfs64 156 #endif 157 158 #if defined(SYS_newfstatat) 159 #undef SYS_fstatat 160 #define SYS_fstatat SYS_newfstatat 161 #elif defined(SYS_fstatat64) 162 #undef SYS_fstatat 163 #define SYS_fstatat SYS_fstatat64 164 #endif 165 166 #ifdef SYS_ugetrlimit 167 #undef SYS_getrlimit 168 #define SYS_getrlimit SYS_ugetrlimit 169 #endif 170 171 #ifdef SYS__newselect 172 #undef SYS_select 173 #define SYS_select SYS__newselect 174 #endif 175 176 #ifdef SYS_pread64 177 #undef SYS_pread 178 #undef SYS_pwrite 179 #define SYS_pread SYS_pread64 180 #define SYS_pwrite SYS_pwrite64 181 #endif 182 183 #ifdef SYS_fadvise64_64 184 #undef SYS_fadvise 185 #define SYS_fadvise SYS_fadvise64_64 186 #elif defined(SYS_fadvise64) 187 #undef SYS_fadvise 188 #define SYS_fadvise SYS_fadvise64 189 #endif 190 191 #ifdef SYS_sendfile64 192 #undef SYS_sendfile 193 #define SYS_sendfile SYS_sendfile64 194 #endif 195 196 /* socketcall calls */ 197 198 #define __SC_socket 1 199 #define __SC_bind 2 200 #define __SC_connect 3 201 #define __SC_listen 4 202 #define __SC_accept 5 203 #define __SC_getsockname 6 204 #define __SC_getpeername 7 205 #define __SC_socketpair 8 206 #define __SC_send 9 207 #define __SC_recv 10 208 #define __SC_sendto 11 209 #define __SC_recvfrom 12 210 #define __SC_shutdown 13 211 #define __SC_setsockopt 14 212 #define __SC_getsockopt 15 213 #define __SC_sendmsg 16 214 #define __SC_recvmsg 17 215 #define __SC_accept4 18 216 #define __SC_recvmmsg 19 217 #define __SC_sendmmsg 20 218 219 #ifdef SYS_open 220 #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) 221 #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) 222 #define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE) 223 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo) 224 #else 225 #define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) 226 #define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) 227 #define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) 228 #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) 229 #endif 230 231 #define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__) 232 #define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__)) 233 234 #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) 235 #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) 236 237 hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); 238 239 hidden void *__vdsosym(const char *, const char *); 240 241 #endif 242