00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef SYS_LINUX_SYSCALL_SUPPORT_H
00074 #define SYS_LINUX_SYSCALL_SUPPORT_H
00075
00076
00077
00078
00079 #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
00080 defined(mips)) && defined(__linux)
00081
00082 #ifndef SYS_CPLUSPLUS
00083 #ifdef __cplusplus
00084
00085
00086
00087
00088 extern "C" {
00089 #endif
00090
00091 #include <errno.h>
00092 #include <signal.h>
00093 #include <stdarg.h>
00094 #include <sys/ptrace.h>
00095 #include <sys/resource.h>
00096 #include <sys/time.h>
00097 #include <sys/types.h>
00098 #include <syscall.h>
00099 #include <unistd.h>
00100 #include <linux/unistd.h>
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 struct dirent64;
00113 struct dirent;
00114 struct iovec;
00115 struct msghdr;
00116 struct pollfd;
00117 struct rlimit;
00118 struct sockaddr;
00119 struct stat;
00120 struct stat64;
00121
00122 #endif
00123
00124
00125
00126 #ifndef O_DIRECTORY
00127 #if defined(__ARM_ARCH_3__)
00128 #define O_DIRECTORY 0040000
00129 #else
00130 #define O_DIRECTORY 0200000
00131 #endif
00132 #endif
00133 #ifndef NT_PRXFPREG
00134 #define NT_PRXFPREG 0x46e62b7f
00135 #endif
00136 #ifndef PTRACE_GETFPXREGS
00137 #define PTRACE_GETFPXREGS ((enum __ptrace_request)18)
00138 #endif
00139 #ifndef PR_GET_DUMPABLE
00140 #define PR_GET_DUMPABLE 3
00141 #endif
00142 #ifndef PR_SET_DUMPABLE
00143 #define PR_SET_DUMPABLE 4
00144 #endif
00145 #ifndef AT_FDCWD
00146 #define AT_FDCWD (-100)
00147 #endif
00148 #ifndef AT_SYMLINK_NOFOLLOW
00149 #define AT_SYMLINK_NOFOLLOW 0x100
00150 #endif
00151 #ifndef AT_REMOVEDIR
00152 #define AT_REMOVEDIR 0x200
00153 #endif
00154 #ifndef MREMAP_FIXED
00155 #define MREMAP_FIXED 2
00156 #endif
00157
00158 #if defined(__i386__)
00159 #ifndef __NR_setresuid
00160 #define __NR_setresuid 164
00161 #define __NR_setresgid 170
00162 #endif
00163 #ifndef __NR_ugetrlimit
00164 #define __NR_ugetrlimit 191
00165 #endif
00166 #ifndef __NR_setresuid32
00167 #define __NR_setresuid32 208
00168 #define __NR_setresgid32 210
00169 #endif
00170 #ifndef __NR_setfsuid32
00171 #define __NR_setfsuid32 215
00172 #define __NR_setfsgid32 216
00173 #endif
00174 #ifndef __NR_getdents64
00175 #define __NR_getdents64 220
00176 #endif
00177 #ifndef __NR_gettid
00178 #define __NR_gettid 224
00179 #endif
00180 #ifndef __NR_futex
00181 #define __NR_futex 240
00182 #endif
00183 #ifndef __NR_sched_setaffinity
00184 #define __NR_sched_setaffinity 241
00185 #define __NR_sched_getaffinity 242
00186 #endif
00187 #ifndef __NR_set_tid_address
00188 #define __NR_set_tid_address 258
00189 #endif
00190 #ifndef __NR_openat
00191 #define __NR_openat 295
00192 #endif
00193 #ifndef __NR_fstatat64
00194 #define __NR_fstatat64 300
00195 #endif
00196 #ifndef __NR_unlinkat
00197 #define __NR_unlinkat 301
00198 #endif
00199 #ifndef __NR_move_pages
00200 #define __NR_move_pages 317
00201 #endif
00202
00203 #elif defined(__ARM_ARCH_3__)
00204 #ifndef __NR_setresuid
00205 #define __NR_setresuid (__NR_SYSCALL_BASE + 164)
00206 #define __NR_setresgid (__NR_SYSCALL_BASE + 170)
00207 #endif
00208 #ifndef __NR_ugetrlimit
00209 #define __NR_ugetrlimit (__NR_SYSCALL_BASE + 191)
00210 #endif
00211 #ifndef __NR_setresuid32
00212 #define __NR_setresuid32 (__NR_SYSCALL_BASE + 208)
00213 #define __NR_setresgid32 (__NR_SYSCALL_BASE + 210)
00214 #endif
00215 #ifndef __NR_setfsuid32
00216 #define __NR_setfsuid32 (__NR_SYSCALL_BASE + 215)
00217 #define __NR_setfsgid32 (__NR_SYSCALL_BASE + 216)
00218 #endif
00219 #ifndef __NR_getdents64
00220 #define __NR_getdents64 (__NR_SYSCALL_BASE + 217)
00221 #endif
00222 #ifndef __NR_gettid
00223 #define __NR_gettid (__NR_SYSCALL_BASE + 224)
00224 #endif
00225 #ifndef __NR_futex
00226 #define __NR_futex (__NR_SYSCALL_BASE + 240)
00227 #endif
00228 #ifndef __NR_sched_setaffinity
00229 #define __NR_sched_setaffinity (__NR_SYSCALL_BASE + 241)
00230 #define __NR_sched_getaffinity (__NR_SYSCALL_BASE + 242)
00231 #endif
00232 #ifndef __NR_set_tid_address
00233 #define __NR_set_tid_address (__NR_SYSCALL_BASE + 256)
00234 #endif
00235 #ifndef __NR_move_pages
00236 #define __NR_move_pages (__NR_SYSCALL_BASE + 344)
00237 #endif
00238
00239 #elif defined(__x86_64__)
00240 #ifndef __NR_setresuid
00241 #define __NR_setresuid 117
00242 #define __NR_setresgid 119
00243 #endif
00244 #ifndef __NR_gettid
00245 #define __NR_gettid 186
00246 #endif
00247 #ifndef __NR_futex
00248 #define __NR_futex 202
00249 #endif
00250 #ifndef __NR_sched_setaffinity
00251 #define __NR_sched_setaffinity 203
00252 #define __NR_sched_getaffinity 204
00253 #endif
00254 #ifndef __NR_getdents64
00255 #define __NR_getdents64 217
00256 #endif
00257 #ifndef __NR_set_tid_address
00258 #define __NR_set_tid_address 218
00259 #endif
00260 #ifndef __NR_openat
00261 #define __NR_openat 257
00262 #endif
00263 #ifndef __NR_newfstatat
00264 #define __NR_newfstatat 262
00265 #endif
00266 #ifndef __NR_unlinkat
00267 #define __NR_unlinkat 263
00268 #endif
00269 #ifndef __NR_move_pages
00270 #define __NR_move_pages 279
00271 #endif
00272
00273 #elif defined(mips)
00274 #if _MIPS_SIM == _MIPS_SIM_ABI32
00275 #ifndef __NR_setresuid
00276 #define __NR_setresuid (__NR_Linux + 185)
00277 #define __NR_setresgid (__NR_Linux + 190)
00278 #endif
00279 #ifndef __NR_getdents64
00280 #define __NR_getdents64 (__NR_Linux + 219)
00281 #endif
00282 #ifndef __NR_gettid
00283 #define __NR_gettid (__NR_Linux + 222)
00284 #endif
00285 #ifndef __NR_futex
00286 #define __NR_futex (__NR_Linux + 238)
00287 #endif
00288 #ifndef __NR_sched_setaffinity
00289 #define __NR_sched_setaffinity (__NR_Linux + 239)
00290 #define __NR_sched_getaffinity (__NR_Linux + 240)
00291 #endif
00292 #ifndef __NR_set_tid_address
00293 #define __NR_set_tid_address (__NR_Linux + 252)
00294 #endif
00295 #ifndef __NR_openat
00296 #define __NR_openat (__NR_Linux + 288)
00297 #endif
00298 #ifndef __NR_fstatat
00299 #define __NR_fstatat (__NR_Linux + 293)
00300 #endif
00301 #ifndef __NR_unlinkat
00302 #define __NR_unlinkat (__NR_Linux + 294)
00303 #endif
00304 #ifndef __NR_move_pages
00305 #define __NR_move_pages (__NR_Linux + 308)
00306 #endif
00307
00308 #elif _MIPS_SIM == _MIPS_SIM_ABI64
00309 #ifndef __NR_setresuid
00310 #define __NR_setresuid (__NR_Linux + 115)
00311 #define __NR_setresgid (__NR_Linux + 117)
00312 #endif
00313 #ifndef __NR_gettid
00314 #define __NR_gettid (__NR_Linux + 178)
00315 #endif
00316 #ifndef __NR_futex
00317 #define __NR_futex (__NR_Linux + 194)
00318 #endif
00319 #ifndef __NR_sched_setaffinity
00320 #define __NR_sched_setaffinity (__NR_Linux + 195)
00321 #define __NR_sched_getaffinity (__NR_Linux + 196)
00322 #endif
00323 #ifndef __NR_set_tid_address
00324 #define __NR_set_tid_address (__NR_Linux + 212)
00325 #endif
00326 #ifndef __NR_openat
00327 #define __NR_openat (__NR_Linux + 247)
00328 #endif
00329 #ifndef __NR_fstatat
00330 #define __NR_fstatat (__NR_Linux + 252)
00331 #endif
00332 #ifndef __NR_unlinkat
00333 #define __NR_unlinkat (__NR_Linux + 253)
00334 #endif
00335 #ifndef __NR_move_pages
00336 #define __NR_move_pages (__NR_Linux + 267)
00337 #endif
00338
00339 #else
00340 #ifndef __NR_setresuid
00341 #define __NR_setresuid (__NR_Linux + 115)
00342 #define __NR_setresgid (__NR_Linux + 117)
00343 #endif
00344 #ifndef __NR_gettid
00345 #define __NR_gettid (__NR_Linux + 178)
00346 #endif
00347 #ifndef __NR_futex
00348 #define __NR_futex (__NR_Linux + 194)
00349 #endif
00350 #ifndef __NR_sched_setaffinity
00351 #define __NR_sched_setaffinity (__NR_Linux + 195)
00352 #define __NR_sched_getaffinity (__NR_Linux + 196)
00353 #endif
00354 #ifndef __NR_set_tid_address
00355 #define __NR_set_tid_address (__NR_Linux + 213)
00356 #endif
00357 #ifndef __NR_openat
00358 #define __NR_openat (__NR_Linux + 251)
00359 #endif
00360 #ifndef __NR_fstatat
00361 #define __NR_fstatat (__NR_Linux + 256)
00362 #endif
00363 #ifndef __NR_unlinkat
00364 #define __NR_unlinkat (__NR_Linux + 257)
00365 #endif
00366 #ifndef __NR_move_pages
00367 #define __NR_move_pages (__NR_Linux + 271)
00368 #endif
00369
00370 #endif
00371
00372 #endif
00373
00374
00375
00376 #if __BOUNDED_POINTERS__
00377 #error "Need to port invocations of syscalls for bounded ptrs"
00378 #else
00379
00380
00381
00382
00383
00384
00385
00386 #undef LSS_ERRNO
00387 #ifdef SYS_ERRNO
00388
00389
00390
00391 #define LSS_ERRNO SYS_ERRNO
00392 #else
00393 #define LSS_ERRNO errno
00394 #endif
00395
00396 #undef LSS_INLINE
00397 #ifdef SYS_INLINE
00398 #define LSS_INLINE SYS_INLINE
00399 #else
00400 #define LSS_INLINE static inline
00401 #endif
00402
00403
00404
00405
00406 #undef LSS_NAME
00407 #ifndef SYS_PREFIX
00408 #define LSS_NAME(name) sys_##name
00409 #elif SYS_PREFIX < 0
00410 #define LSS_NAME(name) name
00411 #elif SYS_PREFIX == 0
00412 #define LSS_NAME(name) sys0_##name
00413 #elif SYS_PREFIX == 1
00414 #define LSS_NAME(name) sys1_##name
00415 #elif SYS_PREFIX == 2
00416 #define LSS_NAME(name) sys2_##name
00417 #elif SYS_PREFIX == 3
00418 #define LSS_NAME(name) sys3_##name
00419 #elif SYS_PREFIX == 4
00420 #define LSS_NAME(name) sys4_##name
00421 #elif SYS_PREFIX == 5
00422 #define LSS_NAME(name) sys5_##name
00423 #elif SYS_PREFIX == 6
00424 #define LSS_NAME(name) sys6_##name
00425 #elif SYS_PREFIX == 7
00426 #define LSS_NAME(name) sys7_##name
00427 #elif SYS_PREFIX == 8
00428 #define LSS_NAME(name) sys8_##name
00429 #elif SYS_PREFIX == 9
00430 #define LSS_NAME(name) sys9_##name
00431 #endif
00432
00433 #undef LSS_RETURN
00434 #ifndef mips
00435
00436
00437
00438 #define LSS_RETURN(type, res) \
00439 do { \
00440 if ((unsigned long)(res) >= (unsigned long)(-4095)) { \
00441 LSS_ERRNO = -(res); \
00442 res = -1; \
00443 } \
00444 return (type) (res); \
00445 } while (0)
00446 #else
00447
00448
00449
00450 #define LSS_RETURN(type, res, err) \
00451 do { \
00452 if (err) { \
00453 LSS_ERRNO = (res); \
00454 res = -1; \
00455 } \
00456 return (type) (res); \
00457 } while (0)
00458 #endif
00459 #if defined(__i386__)
00460
00461
00462
00463
00464
00465
00466
00467
00468 #undef LSS_BODY
00469 #define LSS_BODY(type,args...) \
00470 long __res; \
00471 __asm__ __volatile__("push %%ebx\n" \
00472 "movl %2,%%ebx\n" \
00473 "int $0x80\n" \
00474 "pop %%ebx" \
00475 args \
00476 : "memory"); \
00477 LSS_RETURN(type,__res)
00478 #undef _syscall0
00479 #define _syscall0(type,name) \
00480 type LSS_NAME(name)(void) { \
00481 long __res; \
00482 __asm__ volatile("int $0x80" \
00483 : "=a" (__res) \
00484 : "0" (__NR_##name) \
00485 : "memory"); \
00486 LSS_RETURN(type,__res); \
00487 }
00488 #undef _syscall1
00489 #define _syscall1(type,name,type1,arg1) \
00490 type LSS_NAME(name)(type1 arg1) { \
00491 LSS_BODY(type, \
00492 : "=a" (__res) \
00493 : "0" (__NR_##name), "ri" ((long)(arg1))); \
00494 }
00495 #undef _syscall2
00496 #define _syscall2(type,name,type1,arg1,type2,arg2) \
00497 type LSS_NAME(name)(type1 arg1,type2 arg2) { \
00498 LSS_BODY(type, \
00499 : "=a" (__res) \
00500 : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2))); \
00501 }
00502 #undef _syscall3
00503 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
00504 type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) { \
00505 LSS_BODY(type, \
00506 : "=a" (__res) \
00507 : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
00508 "d" ((long)(arg3))); \
00509 }
00510 #undef _syscall4
00511 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
00512 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
00513 LSS_BODY(type, \
00514 : "=a" (__res) \
00515 : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
00516 "d" ((long)(arg3)),"S" ((long)(arg4))); \
00517 }
00518 #undef _syscall5
00519 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00520 type5,arg5) \
00521 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00522 type5 arg5) { \
00523 long __res; \
00524 __asm__ __volatile__("push %%ebx\n" \
00525 "movl %2,%%ebx\n" \
00526 "movl %1,%%eax\n" \
00527 "int $0x80\n" \
00528 "pop %%ebx" \
00529 : "=a" (__res) \
00530 : "i" (__NR_##name), "ri" ((long)(arg1)), \
00531 "c" ((long)(arg2)), "d" ((long)(arg3)), \
00532 "S" ((long)(arg4)), "D" ((long)(arg5)) \
00533 : "memory"); \
00534 LSS_RETURN(type,__res); \
00535 }
00536 #undef _syscall6
00537 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00538 type5,arg5,type6,arg6) \
00539 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00540 type5 arg5, type6 arg6) { \
00541 long __res; \
00542 struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 }; \
00543 __asm__ __volatile__("push %%ebp\n" \
00544 "push %%ebx\n" \
00545 "movl 4(%2),%%ebp\n" \
00546 "movl 0(%2), %%ebx\n" \
00547 "movl %1,%%eax\n" \
00548 "int $0x80\n" \
00549 "pop %%ebx\n" \
00550 "pop %%ebp" \
00551 : "=a" (__res) \
00552 : "i" (__NR_##name), "0" ((long)(&__s)), \
00553 "c" ((long)(arg2)), "d" ((long)(arg3)), \
00554 "S" ((long)(arg4)), "D" ((long)(arg5)) \
00555 : "memory"); \
00556 LSS_RETURN(type,__res); \
00557 }
00558 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
00559 int flags, void *arg, int *parent_tidptr,
00560 void *newtls, int *child_tidptr) {
00561 long __res;
00562 __asm__ __volatile__(
00563
00564
00565 "movl %3,%%ecx\n"
00566 "jecxz 1f\n"
00567
00568
00569
00570
00571 "movl %4,%%ecx\n"
00572 "jecxz 1f\n"
00573
00574
00575
00576
00577 "andl $-16,%%ecx\n"
00578 "subl $20,%%ecx\n"
00579
00580
00581
00582
00583 "movl %6,%%eax\n"
00584 "movl %%eax,4(%%ecx)\n"
00585 "movl %3,%%eax\n"
00586 "movl %%eax,(%%ecx)\n"
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 "movl %8,%%esi\n"
00598 "movl %7,%%edx\n"
00599 "movl %5,%%eax\n"
00600 "movl %9,%%edi\n"
00601 "pushl %%ebx\n"
00602 "movl %%eax,%%ebx\n"
00603 "movl %2,%%eax\n"
00604 "int $0x80\n"
00605
00606
00607
00608
00609 "popl %%ebx\n"
00610
00611
00612
00613
00614 "test %%eax,%%eax\n"
00615 "jnz 1f\n"
00616
00617
00618
00619 "movl $0,%%ebp\n"
00620
00621
00622
00623 "call *%%ebx\n"
00624
00625
00626
00627
00628
00629
00630 "movl %%eax,%%ebx\n"
00631 "movl $1,%%eax\n"
00632 "int $0x80\n"
00633
00634
00635
00636 "1:\n"
00637 : "=a" (__res)
00638 : "0"(-EINVAL), "i"(__NR_clone),
00639 "m"(fn), "m"(child_stack), "m"(flags), "m"(arg),
00640 "m"(parent_tidptr), "m"(newtls), "m"(child_tidptr)
00641 : "memory", "ecx", "edx", "esi", "edi");
00642 LSS_RETURN(int, __res);
00643 }
00644 #elif defined(__x86_64__)
00645
00646
00647
00648
00649
00650
00651 #undef LSS_BODY
00652 #define LSS_BODY(type,name, ...) \
00653 long __res; \
00654 __asm__ __volatile__("syscall" : "=a" (__res) : "0" (__NR_##name), \
00655 ##__VA_ARGS__ : "r11", "rcx", "memory"); \
00656 LSS_RETURN(type, __res)
00657 #undef _syscall0
00658 #define _syscall0(type,name) \
00659 type LSS_NAME(name)() { \
00660 LSS_BODY(type, name); \
00661 }
00662 #undef _syscall1
00663 #define _syscall1(type,name,type1,arg1) \
00664 type LSS_NAME(name)(type1 arg1) { \
00665 LSS_BODY(type, name, "D" ((long)(arg1))); \
00666 }
00667 #undef _syscall2
00668 #define _syscall2(type,name,type1,arg1,type2,arg2) \
00669 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
00670 LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2))); \
00671 }
00672 #undef _syscall3
00673 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
00674 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
00675 LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2)), \
00676 "d" ((long)(arg3))); \
00677 }
00678 #undef _syscall4
00679 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
00680 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
00681 long __res; \
00682 __asm__ __volatile__("movq %5,%%r10; syscall" : \
00683 "=a" (__res) : "0" (__NR_##name), \
00684 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
00685 "g" ((long)(arg4)) : "r10", "r11", "rcx", "memory"); \
00686 LSS_RETURN(type, __res); \
00687 }
00688 #undef _syscall5
00689 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00690 type5,arg5) \
00691 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00692 type5 arg5) { \
00693 long __res; \
00694 __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; syscall" : \
00695 "=a" (__res) : "0" (__NR_##name), \
00696 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
00697 "g" ((long)(arg4)), "g" ((long)(arg5)) : \
00698 "r8", "r10", "r11", "rcx", "memory"); \
00699 LSS_RETURN(type, __res); \
00700 }
00701 #undef _syscall6
00702 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00703 type5,arg5,type6,arg6) \
00704 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00705 type5 arg5, type6 arg6) { \
00706 long __res; \
00707 __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; movq %7,%%r9;" \
00708 "syscall" : \
00709 "=a" (__res) : "0" (__NR_##name), \
00710 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
00711 "g" ((long)(arg4)), "g" ((long)(arg5)), "g" ((long)(arg6)) : \
00712 "r8", "r9", "r10", "r11", "rcx", "memory"); \
00713 LSS_RETURN(type, __res); \
00714 }
00715 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
00716 int flags, void *arg, int *parent_tidptr,
00717 void *newtls, int *child_tidptr) {
00718 long __res;
00719 {
00720 register void *__tls __asm__("r8") = newtls;
00721 register int *__ctid __asm__("r10") = child_tidptr;
00722 __asm__ __volatile__(
00723
00724
00725 "testq %4,%4\n"
00726 "jz 1f\n"
00727
00728
00729
00730
00731 "testq %5,%5\n"
00732 "jz 1f\n"
00733
00734
00735
00736 "subq $16,%5\n"
00737
00738
00739
00740
00741 "movq %7,8(%5)\n"
00742 "movq %4,0(%5)\n"
00743
00744
00745
00746
00747
00748
00749
00750
00751 "movq %2,%%rax\n"
00752 "syscall\n"
00753
00754
00755
00756
00757 "testq %%rax,%%rax\n"
00758 "jnz 1f\n"
00759
00760
00761
00762 "xorq %%rbp,%%rbp\n"
00763
00764
00765
00766 "popq %%rax\n"
00767 "popq %%rdi\n"
00768 "call *%%rax\n"
00769
00770
00771
00772 "movq %%rax,%%rdi\n"
00773 "movq %3,%%rax\n"
00774 "syscall\n"
00775
00776
00777
00778 "1:\n"
00779 : "=a" (__res)
00780 : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
00781 "r"(fn), "S"(child_stack), "D"(flags), "r"(arg),
00782 "d"(parent_tidptr), "r"(__tls), "r"(__ctid)
00783 : "memory", "r11", "rcx");
00784 }
00785 LSS_RETURN(int, __res);
00786 }
00787 #elif defined(__ARM_ARCH_3__)
00788
00789
00790
00791
00792
00793 #undef LSS_REG
00794 #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
00795 #undef LSS_BODY
00796 #define LSS_BODY(type,name,args...) \
00797 register long __res_r0 __asm__("r0"); \
00798 long __res; \
00799 __asm__ __volatile__ (__syscall(name) \
00800 : "=r"(__res_r0) : args : "lr", "memory"); \
00801 __res = __res_r0; \
00802 LSS_RETURN(type, __res)
00803 #undef _syscall0
00804 #define _syscall0(type, name) \
00805 type LSS_NAME(name)() { \
00806 LSS_BODY(type, name); \
00807 }
00808 #undef _syscall1
00809 #define _syscall1(type, name, type1, arg1) \
00810 type LSS_NAME(name)(type1 arg1) { \
00811 LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
00812 }
00813 #undef _syscall2
00814 #define _syscall2(type, name, type1, arg1, type2, arg2) \
00815 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
00816 LSS_REG(0, arg1); LSS_REG(1, arg2); \
00817 LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
00818 }
00819 #undef _syscall3
00820 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
00821 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
00822 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
00823 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
00824 }
00825 #undef _syscall4
00826 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
00827 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
00828 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
00829 LSS_REG(3, arg4); \
00830 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
00831 }
00832 #undef _syscall5
00833 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00834 type5,arg5) \
00835 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00836 type5 arg5) { \
00837 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
00838 LSS_REG(3, arg4); LSS_REG(4, arg5); \
00839 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
00840 "r"(__r4)); \
00841 }
00842 #undef _syscall6
00843 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00844 type5,arg5,type6,arg6) \
00845 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00846 type5 arg5, type6 arg6) { \
00847 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
00848 LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
00849 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
00850 "r"(__r4), "r"(__r5)); \
00851 }
00852 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
00853 int flags, void *arg, int *parent_tidptr,
00854 void *newtls, int *child_tidptr) {
00855 long __res;
00856 {
00857 register int __flags __asm__("r0") = flags;
00858 register void *__stack __asm__("r1") = child_stack;
00859 register void *__ptid __asm__("r2") = parent_tidptr;
00860 register void *__tls __asm__("r3") = newtls;
00861 register int *__ctid __asm__("r4") = child_tidptr;
00862 __asm__ __volatile__(
00863
00864
00865 "cmp %2,#0\n"
00866 "cmpne %3,#0\n"
00867 "moveq %0,%1\n"
00868 "beq 1f\n"
00869
00870
00871
00872
00873 "str %5,[%3,#-4]!\n"
00874 "str %2,[%3,#-4]!\n"
00875
00876
00877
00878
00879
00880
00881
00882 __syscall(clone)"\n"
00883
00884
00885
00886
00887 "movs %0,r0\n"
00888 "bne 1f\n"
00889
00890
00891
00892 "ldr r0,[sp, #4]\n"
00893 "mov lr,pc\n"
00894 "ldr pc,[sp]\n"
00895
00896
00897
00898 __syscall(exit)"\n"
00899 "1:\n"
00900 : "=r" (__res)
00901 : "i"(-EINVAL),
00902 "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
00903 "r"(__ptid), "r"(__tls), "r"(__ctid)
00904 : "lr", "memory");
00905 }
00906 LSS_RETURN(int, __res);
00907 }
00908 #elif defined(mips)
00909 #undef LSS_REG
00910 #define LSS_REG(r,a) register unsigned long __r##r __asm__("$"#r) = \
00911 (unsigned long)(a)
00912 #undef LSS_BODY
00913 #define LSS_BODY(type,name,r7,...) \
00914 register unsigned long __v0 __asm__("$2") = __NR_##name; \
00915 __asm__ __volatile__ ("syscall\n" \
00916 : "=&r"(__v0), r7 (__r7) \
00917 : "0"(__v0), ##__VA_ARGS__ \
00918 : "$8", "$9", "$10", "$11", "$12", \
00919 "$13", "$14", "$15", "$24", "memory"); \
00920 LSS_RETURN(type, __v0, __r7)
00921 #undef _syscall0
00922 #define _syscall0(type, name) \
00923 type LSS_NAME(name)() { \
00924 register unsigned long __r7 __asm__("$7"); \
00925 LSS_BODY(type, name, "=r"); \
00926 }
00927 #undef _syscall1
00928 #define _syscall1(type, name, type1, arg1) \
00929 type LSS_NAME(name)(type1 arg1) { \
00930 register unsigned long __r7 __asm__("$7"); \
00931 LSS_REG(4, arg1); LSS_BODY(type, name, "=r", "r"(__r4)); \
00932 }
00933 #undef _syscall2
00934 #define _syscall2(type, name, type1, arg1, type2, arg2) \
00935 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
00936 register unsigned long __r7 __asm__("$7"); \
00937 LSS_REG(4, arg1); LSS_REG(5, arg2); \
00938 LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5)); \
00939 }
00940 #undef _syscall3
00941 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
00942 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
00943 register unsigned long __r7 __asm__("$7"); \
00944 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
00945 LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5), "r"(__r6)); \
00946 }
00947 #undef _syscall4
00948 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
00949 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
00950 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
00951 LSS_REG(7, arg4); \
00952 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6)); \
00953 }
00954 #undef _syscall5
00955 #if _MIPS_SIM == _MIPS_SIM_ABI32
00956
00957
00958
00959 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00960 type5,arg5) \
00961 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00962 type5 arg5) { \
00963 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
00964 LSS_REG(7, arg4); \
00965 register unsigned long __v0 __asm__("$2"); \
00966 __asm__ __volatile__ (".set noreorder\n" \
00967 "lw $2, %6\n" \
00968 "subu $29, 32\n" \
00969 "sw $2, 16($29)\n" \
00970 "li $2, %2\n" \
00971 "syscall\n" \
00972 "addiu $29, 32\n" \
00973 ".set reorder\n" \
00974 : "=&r"(__v0), "+r" (__r7) \
00975 : "i" (__NR_##name), "r"(__r4), "r"(__r5), \
00976 "r"(__r6), "m" ((unsigned long)arg5) \
00977 : "$8", "$9", "$10", "$11", "$12", \
00978 "$13", "$14", "$15", "$24", "memory"); \
00979 LSS_RETURN(type, __v0, __r7); \
00980 }
00981 #else
00982 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00983 type5,arg5) \
00984 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
00985 type5 arg5) { \
00986 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
00987 LSS_REG(7, arg4); LSS_REG(8, arg5); \
00988 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
00989 "r"(__r8)); \
00990 }
00991 #endif
00992 #undef _syscall6
00993 #if _MIPS_SIM == _MIPS_SIM_ABI32
00994
00995
00996
00997 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
00998 type5,arg5,type6,arg6) \
00999 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
01000 type5 arg5, type6 arg6) { \
01001 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
01002 LSS_REG(7, arg4); \
01003 register unsigned long __v0 __asm__("$2"); \
01004 __asm__ __volatile__ (".set noreorder\n" \
01005 "lw $2, %6\n" \
01006 "lw $8, %7\n" \
01007 "subu $29, 32\n" \
01008 "sw $2, 16($29)\n" \
01009 "sw $8, 20($29)\n" \
01010 "li $2, %2\n" \
01011 "syscall\n" \
01012 "addiu $29, 32\n" \
01013 ".set reorder\n" \
01014 : "=&r"(__v0), "+r" (__r7) \
01015 : "i" (__NR_##name), "r"(__r4), "r"(__r5), \
01016 "r"(__r6), "m" ((unsigned long)arg5), \
01017 "m" ((unsigned long)arg6) \
01018 : "$8", "$9", "$10", "$11", "$12", \
01019 "$13", "$14", "$15", "$24", "memory"); \
01020 LSS_RETURN(type, __v0, __r7); \
01021 }
01022 #else
01023 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
01024 type5,arg5,type6,arg6) \
01025 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
01026 type5 arg5,type6 arg6) { \
01027 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
01028 LSS_REG(7, arg4); LSS_REG(8, arg5); LSS_REG(9, arg6); \
01029 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
01030 "r"(__r8), "r"(__r9)); \
01031 }
01032 #endif
01033 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
01034 int flags, void *arg, int *parent_tidptr,
01035 void *newtls, int *child_tidptr) {
01036 register unsigned long __v0 __asm__("$2");
01037 register unsigned long __r7 __asm__("$7") = (unsigned long)newtls;
01038 {
01039 register int __flags __asm__("$4") = flags;
01040 register void *__stack __asm__("$5") = child_stack;
01041 register void *__ptid __asm__("$6") = parent_tidptr;
01042 register int *__ctid __asm__("$8") = child_tidptr;
01043 __asm__ __volatile__(
01044 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
01045 "subu $29,24\n"
01046 #elif _MIPS_SIM == _MIPS_SIM_NABI32
01047 "sub $29,16\n"
01048 #else
01049 "dsubu $29,16\n"
01050 #endif
01051
01052
01053
01054
01055 "li %0,%2\n"
01056 "beqz %5,1f\n"
01057 "beqz %6,1f\n"
01058
01059
01060
01061
01062 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
01063 "subu %6,32\n"
01064 "sw %5,0(%6)\n"
01065 "sw %8,4(%6)\n"
01066 #elif _MIPS_SIM == _MIPS_SIM_NABI32
01067 "sub %6,32\n"
01068 "sw %5,0(%6)\n"
01069 "sw %8,8(%6)\n"
01070 #else
01071 "dsubu %6,32\n"
01072 "sd %5,0(%6)\n"
01073 "sd %8,8(%6)\n"
01074 #endif
01075
01076
01077
01078
01079
01080
01081
01082 "li $2,%3\n"
01083 "syscall\n"
01084
01085
01086
01087
01088 "bnez $7,1f\n"
01089 "bnez $2,1f\n"
01090
01091
01092
01093 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
01094 "lw $25,0($29)\n"
01095 "lw $4,4($29)\n"
01096 #elif _MIPS_SIM == _MIPS_SIM_NABI32
01097 "lw $25,0($29)\n"
01098 "lw $4,8($29)\n"
01099 #else
01100 "ld $25,0($29)\n"
01101 "ld $4,8($29)\n"
01102 #endif
01103 "jalr $25\n"
01104
01105
01106
01107 "move $4,$2\n"
01108 "li $2,%4\n"
01109 "syscall\n"
01110
01111 "1:\n"
01112 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
01113 "addu $29, 24\n"
01114 #elif _MIPS_SIM == _MIPS_SIM_NABI32
01115 "add $29, 16\n"
01116 #else
01117 "daddu $29,16\n"
01118 #endif
01119 : "=&r" (__v0), "=r" (__r7)
01120 : "i"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
01121 "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
01122 "r"(__ptid), "r"(__r7), "r"(__ctid)
01123 : "$9", "$10", "$11", "$12", "$13", "$14", "$15",
01124 "$24", "memory");
01125 }
01126 LSS_RETURN(int, __v0, __r7);
01127 }
01128 #endif
01129 #define __NR__exit __NR_exit
01130 #define __NR__gettid __NR_gettid
01131 #define __NR__mremap __NR_mremap
01132 LSS_INLINE _syscall1(int, chdir, const char *,p)
01133 LSS_INLINE _syscall1(int, close, int, f)
01134 LSS_INLINE _syscall1(int, dup, int, f)
01135 LSS_INLINE _syscall2(int, dup2, int, s,
01136 int, d)
01137 LSS_INLINE _syscall3(int, execve, const char*, f,
01138 const char*const*,a,const char*const*, e)
01139 LSS_INLINE _syscall1(int, _exit, int, e)
01140 LSS_INLINE _syscall3(int, fcntl, int, f,
01141 int, c, long, a)
01142 LSS_INLINE _syscall0(pid_t, fork)
01143 LSS_INLINE _syscall2(int, fstat, int, f,
01144 struct stat*, b)
01145 LSS_INLINE _syscall4(int, futex, int*, a,
01146 int, o, int, v, struct timespec *, t)
01147 LSS_INLINE _syscall3(int, getdents, int, f,
01148 struct dirent*, d, int, c)
01149 LSS_INLINE _syscall3(int, getdents64, int, f,
01150 struct dirent64*, d, int, c)
01151 LSS_INLINE _syscall0(gid_t, getegid)
01152 LSS_INLINE _syscall0(uid_t, geteuid)
01153 LSS_INLINE _syscall0(pid_t, getpgrp)
01154 LSS_INLINE _syscall0(pid_t, getpid)
01155 LSS_INLINE _syscall0(pid_t, getppid)
01156 LSS_INLINE _syscall2(int, getpriority, int, a,
01157 int, b)
01158 LSS_INLINE _syscall2(int, getrlimit, int, r,
01159 struct rlimit*, l)
01160 LSS_INLINE _syscall1(pid_t, getsid, pid_t, p)
01161 LSS_INLINE _syscall0(pid_t, _gettid)
01162 LSS_INLINE _syscall2(int, kill, pid_t, p,
01163 int, s)
01164 LSS_INLINE _syscall3(off_t, lseek, int, f,
01165 off_t, o, int, w)
01166 LSS_INLINE _syscall2(int, munmap, void*, s,
01167 size_t, l)
01168 LSS_INLINE _syscall6(long, move_pages, pid_t, p,
01169 unsigned long, n, void **,g, int *, d,
01170 int *, s, int, f)
01171 LSS_INLINE _syscall5(void*, _mremap, void*, o,
01172 size_t, os, size_t, ns,
01173 unsigned long, f, void *, a)
01174 LSS_INLINE _syscall3(int, open, const char*, p,
01175 int, f, int, m)
01176 LSS_INLINE _syscall3(int, poll, struct pollfd*, u,
01177 unsigned int, n, int, t)
01178 LSS_INLINE _syscall2(int, prctl, int, o,
01179 long, a)
01180 LSS_INLINE _syscall4(long, ptrace, int, r,
01181 pid_t, p, void *, a, void *, d)
01182 LSS_INLINE _syscall3(ssize_t, read, int, f,
01183 void *, b, size_t, c)
01184 LSS_INLINE _syscall3(int, readlink, const char*, p,
01185 char*, b, size_t, s)
01186 LSS_INLINE _syscall3(int, sched_getaffinity,pid_t, p,
01187 unsigned int, l, unsigned long *, m)
01188 LSS_INLINE _syscall3(int, sched_setaffinity,pid_t, p,
01189 unsigned int, l, unsigned long *, m)
01190 LSS_INLINE _syscall0(int, sched_yield)
01191 LSS_INLINE _syscall1(long, set_tid_address, int *, t)
01192 LSS_INLINE _syscall1(int, setfsgid, gid_t, g)
01193 LSS_INLINE _syscall1(int, setfsuid, uid_t, u)
01194 LSS_INLINE _syscall2(int, setpgid, pid_t, p,
01195 pid_t, g)
01196 LSS_INLINE _syscall3(int, setpriority, int, a,
01197 int, b, int, p)
01198 LSS_INLINE _syscall3(int, setresgid, gid_t, r,
01199 gid_t, e, gid_t, s)
01200 LSS_INLINE _syscall3(int, setresuid, uid_t, r,
01201 uid_t, e, uid_t, s)
01202 LSS_INLINE _syscall2(int, setrlimit, int, r,
01203 const struct rlimit*, l)
01204 LSS_INLINE _syscall2(int, sigaltstack, const stack_t*, s,
01205 const stack_t*, o)
01206 LSS_INLINE _syscall2(int, stat, const char*, f,
01207 struct stat*, b)
01208 LSS_INLINE _syscall3(ssize_t, write, int, f,
01209 const void *, b, size_t, c)
01210 LSS_INLINE _syscall3(ssize_t, writev, int, f,
01211 const struct iovec *, v, size_t, c)
01212 #if defined(__x86_64__) || \
01213 (defined(mips) && _MIPS_SIM != _MIPS_SIM_ABI32)
01214 LSS_INLINE _syscall3(int, recvmsg, int, s,
01215 struct msghdr*, m, int, f)
01216 LSS_INLINE _syscall3(int, sendmsg, int, s,
01217 const struct msghdr*, m, int, f)
01218 LSS_INLINE _syscall6(int, sendto, int, s,
01219 const void*, m, size_t, l,
01220 int, f,
01221 const struct sockaddr*, a, int, t)
01222 LSS_INLINE _syscall2(int, shutdown, int, s,
01223 int, h)
01224 LSS_INLINE _syscall3(int, socket, int, d,
01225 int, t, int, p)
01226 LSS_INLINE _syscall4(int, socketpair, int, d,
01227 int, t, int, p, int*, s)
01228 #endif
01229 #if defined(__x86_64__)
01230 LSS_INLINE _syscall6(void*, mmap, void*, s,
01231 size_t, l, int, p,
01232 int, f, int, d,
01233 __off64_t, o)
01234 LSS_INLINE _syscall4(int, newfstatat, int, d,
01235 const char *, p,
01236 struct stat *, b, int, f)
01237 LSS_INLINE _syscall4(int, rt_sigaction, int, s,
01238 const struct sigaction*, a,
01239 struct sigaction*, o, int, c)
01240 LSS_INLINE _syscall2(int, rt_sigpending, sigset_t*, s,
01241 int, c)
01242 LSS_INLINE _syscall4(int, rt_sigprocmask, int, h,
01243 const sigset_t*, s, sigset_t*, o, int, c);
01244
01245 LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
01246 return LSS_NAME(setfsgid)(gid);
01247 }
01248
01249 LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
01250 return LSS_NAME(setfsuid)(uid);
01251 }
01252
01253 LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
01254 return LSS_NAME(setresgid)(rgid, egid, sgid);
01255 }
01256
01257 LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
01258 return LSS_NAME(setresuid)(ruid, euid, suid);
01259 }
01260
01261 LSS_INLINE int LSS_NAME(sigaction)(int signum,
01262 const struct sigaction *act,
01263 struct sigaction *oldact) {
01264 return LSS_NAME(rt_sigaction)(signum, act, oldact, (_NSIG+6)/8);
01265 }
01266
01267 LSS_INLINE int LSS_NAME(sigpending)(sigset_t *set) {
01268 return LSS_NAME(rt_sigpending)(set, (_NSIG+6)/8);
01269 }
01270
01271 LSS_INLINE int LSS_NAME(sigprocmask)(int how, const sigset_t *set,
01272 sigset_t *oldset) {
01273 return LSS_NAME(rt_sigprocmask)(how, set, oldset, (_NSIG+6)/8);
01274 }
01275 #endif
01276 #if defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
01277 (defined(mips) && _MIPS_SIM != _MIPS_SIM_ABI32)
01278 LSS_INLINE _syscall4(pid_t, wait4, pid_t, p,
01279 int*, s, int, o,
01280 struct rusage*, r)
01281
01282 LSS_INLINE pid_t LSS_NAME(waitpid)(pid_t pid, int *status, int options){
01283 return LSS_NAME(wait4)(pid, status, options, 0);
01284 }
01285 #endif
01286 #if defined(__i386__) || defined(__x86_64__)
01287 LSS_INLINE _syscall4(int, openat, int, d, const char *, p, int, f, int, m)
01288 LSS_INLINE _syscall3(int, unlinkat, int, d, const char *, p, int, f)
01289 #endif
01290 #if defined(__i386__) || defined(__ARM_ARCH_3__)
01291 #define __NR__setfsgid32 __NR_setfsgid32
01292 #define __NR__setfsuid32 __NR_setfsuid32
01293 #define __NR__setresgid32 __NR_setresgid32
01294 #define __NR__setresuid32 __NR_setresuid32
01295 LSS_INLINE _syscall2(int, ugetrlimit, int, r,struct rlimit*,l)
01296 LSS_INLINE _syscall1(int, _setfsgid32, gid_t, f)
01297 LSS_INLINE _syscall1(int, _setfsuid32, uid_t, f)
01298 LSS_INLINE _syscall3(int, _setresgid32, gid_t, r,
01299 gid_t, e, gid_t, s)
01300 LSS_INLINE _syscall3(int, _setresuid32, uid_t, r,
01301 uid_t, e, uid_t, s)
01302
01303 LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
01304 int rc;
01305 if ((rc = LSS_NAME(_setfsgid32)(gid)) < 0 &&
01306 LSS_ERRNO == ENOSYS) {
01307 if ((unsigned int)gid & ~0xFFFFu) {
01308 rc = EINVAL;
01309 } else {
01310 rc = LSS_NAME(setfsgid)(gid);
01311 }
01312 }
01313 return rc;
01314 }
01315
01316 LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
01317 int rc;
01318 if ((rc = LSS_NAME(_setfsuid32)(uid)) < 0 &&
01319 LSS_ERRNO == ENOSYS) {
01320 if ((unsigned int)uid & ~0xFFFFu) {
01321 rc = EINVAL;
01322 } else {
01323 rc = LSS_NAME(setfsuid)(uid);
01324 }
01325 }
01326 return rc;
01327 }
01328
01329 LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
01330 int rc;
01331 if ((rc = LSS_NAME(_setresgid32)(rgid, egid, sgid)) < 0 &&
01332 LSS_ERRNO == ENOSYS) {
01333 if ((unsigned int)rgid & ~0xFFFFu ||
01334 (unsigned int)egid & ~0xFFFFu ||
01335 (unsigned int)sgid & ~0xFFFFu) {
01336 rc = EINVAL;
01337 } else {
01338 rc = LSS_NAME(setresgid)(rgid, egid, sgid);
01339 }
01340 }
01341 return rc;
01342 }
01343
01344 LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
01345 int rc;
01346 if ((rc = LSS_NAME(_setresuid32)(ruid, euid, suid)) < 0 &&
01347 LSS_ERRNO == ENOSYS) {
01348 if ((unsigned int)ruid & ~0xFFFFu ||
01349 (unsigned int)euid & ~0xFFFFu ||
01350 (unsigned int)suid & ~0xFFFFu) {
01351 rc = EINVAL;
01352 } else {
01353 rc = LSS_NAME(setresuid)(ruid, euid, suid);
01354 }
01355 }
01356 return rc;
01357 }
01358 #endif
01359 #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
01360 (defined(mips) && _MIPS_SIM == _MIPS_SIM_ABI32)
01361 #define __NR__socketcall __NR_socketcall
01362 LSS_INLINE _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
01363 loff_t *, res, uint, wh)
01364 LSS_INLINE _syscall1(void*, mmap, void*, a)
01365 LSS_INLINE _syscall6(void*, mmap2, void*, s,
01366 size_t, l, int, p,
01367 int, f, int, d,
01368 __off64_t, o)
01369 LSS_INLINE _syscall3(int, sigaction, int, s,
01370 const struct sigaction*, a, struct sigaction*, o)
01371 LSS_INLINE _syscall1(int, sigpending, sigset_t*, s)
01372 LSS_INLINE _syscall3(int, sigprocmask, int, h,
01373 const sigset_t*, s, sigset_t*, o)
01374 LSS_INLINE _syscall2(int, _socketcall, int, c,
01375 va_list, a)
01376
01377 LSS_INLINE int LSS_NAME(socketcall)(int op, ...) {
01378 int rc;
01379 va_list ap;
01380 va_start(ap, op);
01381 rc = LSS_NAME(_socketcall)(op, ap);
01382 va_end(ap);
01383 return rc;
01384 }
01385
01386 LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct msghdr*msg,int flags){
01387 return (ssize_t)LSS_NAME(socketcall)(17, s, msg, flags);
01388 }
01389
01390 LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s, const struct msghdr *msg,
01391 int flags) {
01392 return (ssize_t)LSS_NAME(socketcall)(16, s, msg, flags);
01393 }
01394
01395 LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
01396 int flags, const struct sockaddr*to,
01397 unsigned int tolen) {
01398 return (ssize_t)LSS_NAME(socketcall)(11, s, buf, len, flags, to, tolen);
01399 }
01400
01401 LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
01402 return LSS_NAME(socketcall)(13, s, how);
01403 }
01404
01405 LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
01406 return LSS_NAME(socketcall)(1, domain, type, protocol);
01407 }
01408
01409 LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
01410 int sv[2]) {
01411 return LSS_NAME(socketcall)(8, d, type, protocol, sv);
01412 }
01413 #endif
01414 #if defined(__i386__)
01415 LSS_INLINE _syscall4(int, fstatat64, int, d,
01416 const char *, p,
01417 struct stat64 *, b, int, f)
01418 #endif
01419 #if defined(__i386__) || \
01420 (defined(mips) && _MIPS_SIM == _MIPS_SIM_ABI32)
01421 LSS_INLINE _syscall3(pid_t, waitpid, pid_t, p,
01422 int*, s, int, o)
01423 #endif
01424 #if defined(mips)
01425
01426
01427
01428 LSS_INLINE int LSS_NAME(pipe)(int *p) {
01429 register unsigned long __v0 __asm__("$2") = __NR_pipe;
01430 register unsigned long __v1 __asm__("$3");
01431 register unsigned long __r7 __asm__("$7");
01432 __asm__ __volatile__ ("syscall\n"
01433 : "=&r"(__v0), "=&r"(__v1), "+r" (__r7)
01434 : "0"(__v0)
01435 : "$8", "$9", "$10", "$11", "$12",
01436 "$13", "$14", "$15", "$24", "memory");
01437 if (__r7) {
01438 LSS_ERRNO = __v0;
01439 return -1;
01440 } else {
01441 p[0] = __v0;
01442 p[1] = __v1;
01443 return 0;
01444 }
01445 }
01446 #else
01447 LSS_INLINE _syscall1(int, pipe, int*, p)
01448 #endif
01449
01450 LSS_INLINE int LSS_NAME(execv)(const char *path, const char * const argv[]) {
01451 extern char **environ;
01452 return LSS_NAME(execve)(path, argv, (const char * const *)environ);
01453 }
01454
01455 LSS_INLINE pid_t LSS_NAME(gettid)() {
01456 pid_t tid = LSS_NAME(_gettid)();
01457 if (tid != -1) {
01458 return tid;
01459 }
01460 return LSS_NAME(getpid)();
01461 }
01462
01463 LSS_INLINE void *LSS_NAME(mremap)(void *old_address, size_t old_size,
01464 size_t new_size, int flags, ...) {
01465 va_list ap;
01466 void *new_address, *rc;
01467 va_start(ap, flags);
01468 new_address = va_arg(ap, void *);
01469 rc = LSS_NAME(_mremap)(old_address, old_size, new_size,
01470 flags, new_address);
01471 va_end(ap);
01472 return rc;
01473 }
01474
01475 LSS_INLINE int LSS_NAME(ptrace_detach)(pid_t pid) {
01476
01477
01478
01479
01480
01481
01482 int rc, err;
01483 LSS_NAME(sched_yield)();
01484 rc = LSS_NAME(ptrace)(PTRACE_DETACH, pid, (void *)0, (void *)0);
01485 err = LSS_ERRNO;
01486 LSS_NAME(kill)(pid, SIGCONT);
01487 LSS_ERRNO = err;
01488 return rc;
01489 }
01490
01491 LSS_INLINE int LSS_NAME(raise)(int sig) {
01492 return LSS_NAME(kill)(LSS_NAME(getpid)(), sig);
01493 }
01494
01495 LSS_INLINE int LSS_NAME(setpgrp)() {
01496 return LSS_NAME(setpgid)(0, 0);
01497 }
01498
01499 LSS_INLINE int LSS_NAME(sysconf)(int name) {
01500 extern int __getpagesize(void);
01501 switch (name) {
01502 case _SC_OPEN_MAX: {
01503 unsigned long limit[2];
01504 return LSS_NAME(getrlimit)(RLIMIT_NOFILE, (struct rlimit *)limit)<0
01505 ? 8192 : limit[0];
01506 }
01507 case _SC_PAGESIZE:
01508 return __getpagesize();
01509 default:
01510 errno = ENOSYS;
01511 return -1;
01512 }
01513 }
01514 #endif
01515
01516 #if defined(__cplusplus) && !defined(SYS_CPLUSPLUS)
01517 }
01518 #endif
01519
01520 #endif
01521 #endif