PageRenderTime 174ms CodeModel.GetById 139ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 1ms

/thirdparty/breakpad/third_party/lss/linux_syscall_support.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 1826 lines | 1525 code | 55 blank | 246 comment | 52 complexity | 2d6c0b86fe3575499d978cafe72ba750 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* Copyright (c) 2005-2010, Google Inc.
   2 * All rights reserved.
   3 *
   4 * Redistribution and use in source and binary forms, with or without
   5 * modification, are permitted provided that the following conditions are
   6 * met:
   7 *
   8 *     * Redistributions of source code must retain the above copyright
   9 * notice, this list of conditions and the following disclaimer.
  10 *     * Redistributions in binary form must reproduce the above
  11 * copyright notice, this list of conditions and the following disclaimer
  12 * in the documentation and/or other materials provided with the
  13 * distribution.
  14 *     * Neither the name of Google Inc. nor the names of its
  15 * contributors may be used to endorse or promote products derived from
  16 * this software without specific prior written permission.
  17 *
  18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 *
  30 * ---
  31 * Author: Markus Gutschke
  32 */
  33
  34/* This file includes Linux-specific support functions common to the
  35 * coredumper and the thread lister; primarily, this is a collection
  36 * of direct system calls, and a couple of symbols missing from
  37 * standard header files.
  38 * There are a few options that the including file can set to control
  39 * the behavior of this file:
  40 *
  41 * SYS_CPLUSPLUS:
  42 *   The entire header file will normally be wrapped in 'extern "C" { }",
  43 *   making it suitable for compilation as both C and C++ source. If you
  44 *   do not want to do this, you can set the SYS_CPLUSPLUS macro to inhibit
  45 *   the wrapping. N.B. doing so will suppress inclusion of all prerequisite
  46 *   system header files, too. It is the caller's responsibility to provide
  47 *   the necessary definitions.
  48 *
  49 * SYS_ERRNO:
  50 *   All system calls will update "errno" unless overriden by setting the
  51 *   SYS_ERRNO macro prior to including this file. SYS_ERRNO should be
  52 *   an l-value.
  53 *
  54 * SYS_INLINE:
  55 *   New symbols will be defined "static inline", unless overridden by
  56 *   the SYS_INLINE macro.
  57 *
  58 * SYS_LINUX_SYSCALL_SUPPORT_H
  59 *   This macro is used to avoid multiple inclusions of this header file.
  60 *   If you need to include this file more than once, make sure to
  61 *   unset SYS_LINUX_SYSCALL_SUPPORT_H before each inclusion.
  62 *
  63 * SYS_PREFIX:
  64 *   New system calls will have a prefix of "sys_" unless overridden by
  65 *   the SYS_PREFIX macro. Valid values for this macro are [0..9] which
  66 *   results in prefixes "sys[0..9]_". It is also possible to set this
  67 *   macro to -1, which avoids all prefixes.
  68 *
  69 * SYS_SYSCALL_ENTRYPOINT:
  70 *   Some applications (such as sandboxes that filter system calls), need
  71 *   to be able to run custom-code each time a system call is made. If this
  72 *   macro is defined, it expands to the name of a "common" symbol. If
  73 *   this symbol is assigned a non-NULL pointer value, it is used as the
  74 *   address of the system call entrypoint.
  75 *   A pointer to this symbol can be obtained by calling
  76 *   get_syscall_entrypoint()
  77 *
  78 * This file defines a few internal symbols that all start with "LSS_".
  79 * Do not access these symbols from outside this file. They are not part
  80 * of the supported API.
  81 */
  82#ifndef SYS_LINUX_SYSCALL_SUPPORT_H
  83#define SYS_LINUX_SYSCALL_SUPPORT_H
  84
  85/* We currently only support x86-32, x86-64, ARM, MIPS, and PPC on Linux.
  86 * Porting to other related platforms should not be difficult.
  87 */
  88#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) ||   \
  89     defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__)) \
  90  && (defined(__linux) || defined(__ANDROID__))
  91
  92#ifndef SYS_CPLUSPLUS
  93#ifdef __cplusplus
  94/* Some system header files in older versions of gcc neglect to properly
  95 * handle being included from C++. As it appears to be harmless to have
  96 * multiple nested 'extern "C"' blocks, just add another one here.
  97 */
  98extern "C" {
  99#endif
 100
 101#include <errno.h>
 102#include <fcntl.h>
 103#include <signal.h>
 104#include <stdarg.h>
 105#include <stddef.h>
 106#include <string.h>
 107#include <sys/ptrace.h>
 108#include <sys/resource.h>
 109#include <sys/time.h>
 110#include <sys/types.h>
 111#include <sys/syscall.h>
 112#include <unistd.h>
 113#include <linux/unistd.h>
 114#include <endian.h>
 115
 116#ifdef __mips__
 117/* Include definitions of the ABI currently in use.                          */
 118#include <sgidefs.h>
 119#endif
 120#endif
 121
 122/* As glibc often provides subtly incompatible data structures (and implicit
 123 * wrapper functions that convert them), we provide our own kernel data
 124 * structures for use by the system calls.
 125 * These structures have been developed by using Linux 2.6.23 headers for
 126 * reference. Note though, we do not care about exact API compatibility
 127 * with the kernel, and in fact the kernel often does not have a single
 128 * API that works across architectures. Instead, we try to mimic the glibc
 129 * API where reasonable, and only guarantee ABI compatibility with the
 130 * kernel headers.
 131 * Most notably, here are a few changes that were made to the structures
 132 * defined by kernel headers:
 133 *
 134 * - we only define structures, but not symbolic names for kernel data
 135 *   types. For the latter, we directly use the native C datatype
 136 *   (i.e. "unsigned" instead of "mode_t").
 137 * - in a few cases, it is possible to define identical structures for
 138 *   both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by
 139 *   standardizing on the 64bit version of the data types. In particular,
 140 *   this means that we use "unsigned" where the 32bit headers say
 141 *   "unsigned long".
 142 * - overall, we try to minimize the number of cases where we need to
 143 *   conditionally define different structures.
 144 * - the "struct kernel_sigaction" class of structures have been
 145 *   modified to more closely mimic glibc's API by introducing an
 146 *   anonymous union for the function pointer.
 147 * - a small number of field names had to have an underscore appended to
 148 *   them, because glibc defines a global macro by the same name.
 149 */
 150
 151/* include/linux/dirent.h                                                    */
 152struct kernel_dirent64 {
 153  unsigned long long d_ino;
 154  long long          d_off;
 155  unsigned short     d_reclen;
 156  unsigned char      d_type;
 157  char               d_name[256];
 158};
 159
 160/* include/linux/dirent.h                                                    */
 161struct kernel_dirent {
 162  long               d_ino;
 163  long               d_off;
 164  unsigned short     d_reclen;
 165  char               d_name[256];
 166};
 167
 168/* include/linux/uio.h                                                       */
 169struct kernel_iovec {
 170  void               *iov_base;
 171  unsigned long      iov_len;
 172};
 173
 174/* include/linux/socket.h                                                    */
 175struct kernel_msghdr {
 176  void               *msg_name;
 177  int                msg_namelen;
 178  struct kernel_iovec*msg_iov;
 179  unsigned long      msg_iovlen;
 180  void               *msg_control;
 181  unsigned long      msg_controllen;
 182  unsigned           msg_flags;
 183};
 184
 185/* include/asm-generic/poll.h                                                */
 186struct kernel_pollfd {
 187  int                fd;
 188  short              events;
 189  short              revents;
 190};
 191
 192/* include/linux/resource.h                                                  */
 193struct kernel_rlimit {
 194  unsigned long      rlim_cur;
 195  unsigned long      rlim_max;
 196};
 197
 198/* include/linux/time.h                                                      */
 199struct kernel_timespec {
 200  long               tv_sec;
 201  long               tv_nsec;
 202};
 203
 204/* include/linux/time.h                                                      */
 205struct kernel_timeval {
 206  long               tv_sec;
 207  long               tv_usec;
 208};
 209
 210/* include/linux/resource.h                                                  */
 211struct kernel_rusage {
 212  struct kernel_timeval ru_utime;
 213  struct kernel_timeval ru_stime;
 214  long               ru_maxrss;
 215  long               ru_ixrss;
 216  long               ru_idrss;
 217  long               ru_isrss;
 218  long               ru_minflt;
 219  long               ru_majflt;
 220  long               ru_nswap;
 221  long               ru_inblock;
 222  long               ru_oublock;
 223  long               ru_msgsnd;
 224  long               ru_msgrcv;
 225  long               ru_nsignals;
 226  long               ru_nvcsw;
 227  long               ru_nivcsw;
 228};
 229
 230struct siginfo;
 231#if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \
 232  || defined(__PPC__)
 233
 234/* include/asm-{arm,i386,mips,ppc}/signal.h                                  */
 235struct kernel_old_sigaction {
 236  union {
 237    void             (*sa_handler_)(int);
 238    void             (*sa_sigaction_)(int, struct siginfo *, void *);
 239  };
 240  unsigned long      sa_mask;
 241  unsigned long      sa_flags;
 242  void               (*sa_restorer)(void);
 243} __attribute__((packed,aligned(4)));
 244#elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
 245  #define kernel_old_sigaction kernel_sigaction
 246#endif
 247
 248/* Some kernel functions (e.g. sigaction() in 2.6.23) require that the
 249 * exactly match the size of the signal set, even though the API was
 250 * intended to be extensible. We define our own KERNEL_NSIG to deal with
 251 * this.
 252 * Please note that glibc provides signals [1.._NSIG-1], whereas the
 253 * kernel (and this header) provides the range [1..KERNEL_NSIG]. The
 254 * actual number of signals is obviously the same, but the constants
 255 * differ by one.
 256 */
 257#ifdef __mips__
 258#define KERNEL_NSIG 128
 259#else
 260#define KERNEL_NSIG  64
 261#endif
 262
 263/* include/asm-{arm,i386,mips,x86_64}/signal.h                               */
 264struct kernel_sigset_t {
 265  unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/
 266                    (8*sizeof(unsigned long))];
 267};
 268
 269/* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h                           */
 270struct kernel_sigaction {
 271#ifdef __mips__
 272  unsigned long      sa_flags;
 273  union {
 274    void             (*sa_handler_)(int);
 275    void             (*sa_sigaction_)(int, struct siginfo *, void *);
 276  };
 277  struct kernel_sigset_t sa_mask;
 278#else
 279  union {
 280    void             (*sa_handler_)(int);
 281    void             (*sa_sigaction_)(int, struct siginfo *, void *);
 282  };
 283  unsigned long      sa_flags;
 284  void               (*sa_restorer)(void);
 285  struct kernel_sigset_t sa_mask;
 286#endif
 287};
 288
 289/* include/linux/socket.h                                                    */
 290struct kernel_sockaddr {
 291  unsigned short     sa_family;
 292  char               sa_data[14];
 293};
 294
 295/* include/asm-{arm,i386,mips,ppc}/stat.h                                    */
 296#ifdef __mips__
 297#if _MIPS_SIM == _MIPS_SIM_ABI64
 298struct kernel_stat {
 299#else
 300struct kernel_stat64 {
 301#endif
 302  unsigned           st_dev;
 303  unsigned           __pad0[3];
 304  unsigned long long st_ino;
 305  unsigned           st_mode;
 306  unsigned           st_nlink;
 307  unsigned           st_uid;
 308  unsigned           st_gid;
 309  unsigned           st_rdev;
 310  unsigned           __pad1[3];
 311  long long          st_size;
 312  unsigned           st_atime_;
 313  unsigned           st_atime_nsec_;
 314  unsigned           st_mtime_;
 315  unsigned           st_mtime_nsec_;
 316  unsigned           st_ctime_;
 317  unsigned           st_ctime_nsec_;
 318  unsigned           st_blksize;
 319  unsigned           __pad2;
 320  unsigned long long st_blocks;
 321};
 322#elif defined __PPC__
 323struct kernel_stat64 {
 324  unsigned long long st_dev;
 325  unsigned long long st_ino;
 326  unsigned           st_mode;
 327  unsigned           st_nlink;
 328  unsigned           st_uid;
 329  unsigned           st_gid;
 330  unsigned long long st_rdev;
 331  unsigned short int __pad2;
 332  long long          st_size;
 333  long               st_blksize;
 334  long long          st_blocks;
 335  long               st_atime_;
 336  unsigned long      st_atime_nsec_;
 337  long               st_mtime_;
 338  unsigned long      st_mtime_nsec_;
 339  long               st_ctime_;
 340  unsigned long      st_ctime_nsec_;
 341  unsigned long      __unused4;
 342  unsigned long      __unused5;
 343};
 344#else
 345struct kernel_stat64 {
 346  unsigned long long st_dev;
 347  unsigned char      __pad0[4];
 348  unsigned           __st_ino;
 349  unsigned           st_mode;
 350  unsigned           st_nlink;
 351  unsigned           st_uid;
 352  unsigned           st_gid;
 353  unsigned long long st_rdev;
 354  unsigned char      __pad3[4];
 355  long long          st_size;
 356  unsigned           st_blksize;
 357  unsigned long long st_blocks;
 358  unsigned           st_atime_;
 359  unsigned           st_atime_nsec_;
 360  unsigned           st_mtime_;
 361  unsigned           st_mtime_nsec_;
 362  unsigned           st_ctime_;
 363  unsigned           st_ctime_nsec_;
 364  unsigned long long st_ino;
 365};
 366#endif
 367
 368/* include/asm-{arm,i386,mips,x86_64,ppc}/stat.h                             */
 369#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
 370struct kernel_stat {
 371  /* The kernel headers suggest that st_dev and st_rdev should be 32bit
 372   * quantities encoding 12bit major and 20bit minor numbers in an interleaved
 373   * format. In reality, we do not see useful data in the top bits. So,
 374   * we'll leave the padding in here, until we find a better solution.
 375   */
 376  unsigned short     st_dev;
 377  short              pad1;
 378  unsigned           st_ino;
 379  unsigned short     st_mode;
 380  unsigned short     st_nlink;
 381  unsigned short     st_uid;
 382  unsigned short     st_gid;
 383  unsigned short     st_rdev;
 384  short              pad2;
 385  unsigned           st_size;
 386  unsigned           st_blksize;
 387  unsigned           st_blocks;
 388  unsigned           st_atime_;
 389  unsigned           st_atime_nsec_;
 390  unsigned           st_mtime_;
 391  unsigned           st_mtime_nsec_;
 392  unsigned           st_ctime_;
 393  unsigned           st_ctime_nsec_;
 394  unsigned           __unused4;
 395  unsigned           __unused5;
 396};
 397#elif defined(__x86_64__)
 398struct kernel_stat {
 399  unsigned long      st_dev;
 400  unsigned long      st_ino;
 401  unsigned long      st_nlink;
 402  unsigned           st_mode;
 403  unsigned           st_uid;
 404  unsigned           st_gid;
 405  unsigned           __pad0;
 406  unsigned long      st_rdev;
 407  long               st_size;
 408  long               st_blksize;
 409  long               st_blocks;
 410  unsigned long      st_atime_;
 411  unsigned long      st_atime_nsec_;
 412  unsigned long      st_mtime_;
 413  unsigned long      st_mtime_nsec_;
 414  unsigned long      st_ctime_;
 415  unsigned long      st_ctime_nsec_;
 416  long               __unused[3];
 417};
 418#elif defined(__PPC__)
 419struct kernel_stat {
 420  unsigned           st_dev;
 421  unsigned long      st_ino;      // ino_t
 422  unsigned long      st_mode;     // mode_t
 423  unsigned short     st_nlink;    // nlink_t
 424  unsigned           st_uid;      // uid_t
 425  unsigned           st_gid;      // gid_t
 426  unsigned           st_rdev;
 427  long               st_size;     // off_t
 428  unsigned long      st_blksize;
 429  unsigned long      st_blocks;
 430  unsigned long      st_atime_;
 431  unsigned long      st_atime_nsec_;
 432  unsigned long      st_mtime_;
 433  unsigned long      st_mtime_nsec_;
 434  unsigned long      st_ctime_;
 435  unsigned long      st_ctime_nsec_;
 436  unsigned long      __unused4;
 437  unsigned long      __unused5;
 438};
 439#elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
 440struct kernel_stat {
 441  unsigned           st_dev;
 442  int                st_pad1[3];
 443  unsigned           st_ino;
 444  unsigned           st_mode;
 445  unsigned           st_nlink;
 446  unsigned           st_uid;
 447  unsigned           st_gid;
 448  unsigned           st_rdev;
 449  int                st_pad2[2];
 450  long               st_size;
 451  int                st_pad3;
 452  long               st_atime_;
 453  long               st_atime_nsec_;
 454  long               st_mtime_;
 455  long               st_mtime_nsec_;
 456  long               st_ctime_;
 457  long               st_ctime_nsec_;
 458  int                st_blksize;
 459  int                st_blocks;
 460  int                st_pad4[14];
 461};
 462#endif
 463
 464/* include/asm-{arm,i386,mips,x86_64,ppc}/statfs.h                           */
 465#ifdef __mips__
 466#if _MIPS_SIM != _MIPS_SIM_ABI64
 467struct kernel_statfs64 {
 468  unsigned long      f_type;
 469  unsigned long      f_bsize;
 470  unsigned long      f_frsize;
 471  unsigned long      __pad;
 472  unsigned long long f_blocks;
 473  unsigned long long f_bfree;
 474  unsigned long long f_files;
 475  unsigned long long f_ffree;
 476  unsigned long long f_bavail;
 477  struct { int val[2]; } f_fsid;
 478  unsigned long      f_namelen;
 479  unsigned long      f_spare[6];
 480};
 481#endif
 482#elif !defined(__x86_64__)
 483struct kernel_statfs64 {
 484  unsigned long      f_type;
 485  unsigned long      f_bsize;
 486  unsigned long long f_blocks;
 487  unsigned long long f_bfree;
 488  unsigned long long f_bavail;
 489  unsigned long long f_files;
 490  unsigned long long f_ffree;
 491  struct { int val[2]; } f_fsid;
 492  unsigned long      f_namelen;
 493  unsigned long      f_frsize;
 494  unsigned long      f_spare[5];
 495};
 496#endif
 497
 498/* include/asm-{arm,i386,mips,x86_64,ppc,generic}/statfs.h                   */
 499#ifdef __mips__
 500struct kernel_statfs {
 501  long               f_type;
 502  long               f_bsize;
 503  long               f_frsize;
 504  long               f_blocks;
 505  long               f_bfree;
 506  long               f_files;
 507  long               f_ffree;
 508  long               f_bavail;
 509  struct { int val[2]; } f_fsid;
 510  long               f_namelen;
 511  long               f_spare[6];
 512};
 513#else
 514struct kernel_statfs {
 515  /* x86_64 actually defines all these fields as signed, whereas all other  */
 516  /* platforms define them as unsigned. Leaving them at unsigned should not */
 517  /* cause any problems.                                                    */
 518  unsigned long      f_type;
 519  unsigned long      f_bsize;
 520  unsigned long      f_blocks;
 521  unsigned long      f_bfree;
 522  unsigned long      f_bavail;
 523  unsigned long      f_files;
 524  unsigned long      f_ffree;
 525  struct { int val[2]; } f_fsid;
 526  unsigned long      f_namelen;
 527  unsigned long      f_frsize;
 528  unsigned long      f_spare[5];
 529};
 530#endif
 531
 532
 533/* Definitions missing from the standard header files                        */
 534#ifndef O_DIRECTORY
 535#if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
 536#define O_DIRECTORY             0040000
 537#else
 538#define O_DIRECTORY             0200000
 539#endif
 540#endif
 541#ifndef NT_PRXFPREG
 542#define NT_PRXFPREG             0x46e62b7f
 543#endif
 544#ifndef PTRACE_GETFPXREGS
 545#define PTRACE_GETFPXREGS       ((enum __ptrace_request)18)
 546#endif
 547#ifndef PR_GET_DUMPABLE
 548#define PR_GET_DUMPABLE         3
 549#endif
 550#ifndef PR_SET_DUMPABLE
 551#define PR_SET_DUMPABLE         4
 552#endif
 553#ifndef PR_GET_SECCOMP
 554#define PR_GET_SECCOMP          21
 555#endif
 556#ifndef PR_SET_SECCOMP
 557#define PR_SET_SECCOMP          22
 558#endif
 559#ifndef AT_FDCWD
 560#define AT_FDCWD                (-100)
 561#endif
 562#ifndef AT_SYMLINK_NOFOLLOW
 563#define AT_SYMLINK_NOFOLLOW     0x100
 564#endif
 565#ifndef AT_REMOVEDIR
 566#define AT_REMOVEDIR            0x200
 567#endif
 568#ifndef MREMAP_FIXED
 569#define MREMAP_FIXED            2
 570#endif
 571#ifndef SA_RESTORER
 572#define SA_RESTORER             0x04000000
 573#endif
 574#ifndef CPUCLOCK_PROF
 575#define CPUCLOCK_PROF           0
 576#endif
 577#ifndef CPUCLOCK_VIRT
 578#define CPUCLOCK_VIRT           1
 579#endif
 580#ifndef CPUCLOCK_SCHED
 581#define CPUCLOCK_SCHED          2
 582#endif
 583#ifndef CPUCLOCK_PERTHREAD_MASK
 584#define CPUCLOCK_PERTHREAD_MASK 4
 585#endif
 586#ifndef MAKE_PROCESS_CPUCLOCK
 587#define MAKE_PROCESS_CPUCLOCK(pid, clock)                                     \
 588        ((~(int)(pid) << 3) | (int)(clock))
 589#endif
 590#ifndef MAKE_THREAD_CPUCLOCK
 591#define MAKE_THREAD_CPUCLOCK(tid, clock)                                      \
 592        ((~(int)(tid) << 3) | (int)((clock) | CPUCLOCK_PERTHREAD_MASK))
 593#endif
 594
 595#ifndef FUTEX_WAIT
 596#define FUTEX_WAIT                0
 597#endif
 598#ifndef FUTEX_WAKE
 599#define FUTEX_WAKE                1
 600#endif
 601#ifndef FUTEX_FD
 602#define FUTEX_FD                  2
 603#endif
 604#ifndef FUTEX_REQUEUE
 605#define FUTEX_REQUEUE             3
 606#endif
 607#ifndef FUTEX_CMP_REQUEUE
 608#define FUTEX_CMP_REQUEUE         4
 609#endif
 610#ifndef FUTEX_WAKE_OP
 611#define FUTEX_WAKE_OP             5
 612#endif
 613#ifndef FUTEX_LOCK_PI
 614#define FUTEX_LOCK_PI             6
 615#endif
 616#ifndef FUTEX_UNLOCK_PI
 617#define FUTEX_UNLOCK_PI           7
 618#endif
 619#ifndef FUTEX_TRYLOCK_PI
 620#define FUTEX_TRYLOCK_PI          8
 621#endif
 622#ifndef FUTEX_PRIVATE_FLAG
 623#define FUTEX_PRIVATE_FLAG        128
 624#endif
 625#ifndef FUTEX_CMD_MASK
 626#define FUTEX_CMD_MASK            ~FUTEX_PRIVATE_FLAG
 627#endif
 628#ifndef FUTEX_WAIT_PRIVATE
 629#define FUTEX_WAIT_PRIVATE        (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
 630#endif
 631#ifndef FUTEX_WAKE_PRIVATE
 632#define FUTEX_WAKE_PRIVATE        (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
 633#endif
 634#ifndef FUTEX_REQUEUE_PRIVATE
 635#define FUTEX_REQUEUE_PRIVATE     (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
 636#endif
 637#ifndef FUTEX_CMP_REQUEUE_PRIVATE
 638#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
 639#endif
 640#ifndef FUTEX_WAKE_OP_PRIVATE
 641#define FUTEX_WAKE_OP_PRIVATE     (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
 642#endif
 643#ifndef FUTEX_LOCK_PI_PRIVATE
 644#define FUTEX_LOCK_PI_PRIVATE     (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
 645#endif
 646#ifndef FUTEX_UNLOCK_PI_PRIVATE
 647#define FUTEX_UNLOCK_PI_PRIVATE   (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
 648#endif
 649#ifndef FUTEX_TRYLOCK_PI_PRIVATE
 650#define FUTEX_TRYLOCK_PI_PRIVATE  (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
 651#endif
 652
 653
 654#if defined(__x86_64__)
 655#ifndef ARCH_SET_GS
 656#define ARCH_SET_GS             0x1001
 657#endif
 658#ifndef ARCH_GET_GS
 659#define ARCH_GET_GS             0x1004
 660#endif
 661#endif
 662
 663#if defined(__i386__)
 664#ifndef __NR_quotactl
 665#define __NR_quotactl           131
 666#endif
 667#ifndef __NR_setresuid
 668#define __NR_setresuid          164
 669#define __NR_getresuid          165
 670#define __NR_setresgid          170
 671#define __NR_getresgid          171
 672#endif
 673#ifndef __NR_rt_sigaction
 674#define __NR_rt_sigreturn       173
 675#define __NR_rt_sigaction       174
 676#define __NR_rt_sigprocmask     175
 677#define __NR_rt_sigpending      176
 678#define __NR_rt_sigsuspend      179
 679#endif
 680#ifndef __NR_pread64
 681#define __NR_pread64            180
 682#endif
 683#ifndef __NR_pwrite64
 684#define __NR_pwrite64           181
 685#endif
 686#ifndef __NR_ugetrlimit
 687#define __NR_ugetrlimit         191
 688#endif
 689#ifndef __NR_stat64
 690#define __NR_stat64             195
 691#endif
 692#ifndef __NR_fstat64
 693#define __NR_fstat64            197
 694#endif
 695#ifndef __NR_setresuid32
 696#define __NR_setresuid32        208
 697#define __NR_getresuid32        209
 698#define __NR_setresgid32        210
 699#define __NR_getresgid32        211
 700#endif
 701#ifndef __NR_setfsuid32
 702#define __NR_setfsuid32         215
 703#define __NR_setfsgid32         216
 704#endif
 705#ifndef __NR_getdents64
 706#define __NR_getdents64         220
 707#endif
 708#ifndef __NR_gettid
 709#define __NR_gettid             224
 710#endif
 711#ifndef __NR_readahead
 712#define __NR_readahead          225
 713#endif
 714#ifndef __NR_setxattr
 715#define __NR_setxattr           226
 716#endif
 717#ifndef __NR_lsetxattr
 718#define __NR_lsetxattr          227
 719#endif
 720#ifndef __NR_getxattr
 721#define __NR_getxattr           229
 722#endif
 723#ifndef __NR_lgetxattr
 724#define __NR_lgetxattr          230
 725#endif
 726#ifndef __NR_listxattr
 727#define __NR_listxattr          232
 728#endif
 729#ifndef __NR_llistxattr
 730#define __NR_llistxattr         233
 731#endif
 732#ifndef __NR_tkill
 733#define __NR_tkill              238
 734#endif
 735#ifndef __NR_futex
 736#define __NR_futex              240
 737#endif
 738#ifndef __NR_sched_setaffinity
 739#define __NR_sched_setaffinity  241
 740#define __NR_sched_getaffinity  242
 741#endif
 742#ifndef __NR_set_tid_address
 743#define __NR_set_tid_address    258
 744#endif
 745#ifndef __NR_clock_gettime
 746#define __NR_clock_gettime      265
 747#endif
 748#ifndef __NR_clock_getres
 749#define __NR_clock_getres       266
 750#endif
 751#ifndef __NR_statfs64
 752#define __NR_statfs64           268
 753#endif
 754#ifndef __NR_fstatfs64
 755#define __NR_fstatfs64          269
 756#endif
 757#ifndef __NR_fadvise64_64
 758#define __NR_fadvise64_64       272
 759#endif
 760#ifndef __NR_ioprio_set
 761#define __NR_ioprio_set         289
 762#endif
 763#ifndef __NR_ioprio_get
 764#define __NR_ioprio_get         290
 765#endif
 766#ifndef __NR_openat
 767#define __NR_openat             295
 768#endif
 769#ifndef __NR_fstatat64
 770#define __NR_fstatat64          300
 771#endif
 772#ifndef __NR_unlinkat
 773#define __NR_unlinkat           301
 774#endif
 775#ifndef __NR_move_pages
 776#define __NR_move_pages         317
 777#endif
 778#ifndef __NR_getcpu
 779#define __NR_getcpu             318
 780#endif
 781#ifndef __NR_fallocate
 782#define __NR_fallocate          324
 783#endif
 784/* End of i386 definitions                                                   */
 785#elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
 786#ifndef __NR_setresuid
 787#define __NR_setresuid          (__NR_SYSCALL_BASE + 164)
 788#define __NR_getresuid          (__NR_SYSCALL_BASE + 165)
 789#define __NR_setresgid          (__NR_SYSCALL_BASE + 170)
 790#define __NR_getresgid          (__NR_SYSCALL_BASE + 171)
 791#endif
 792#ifndef __NR_rt_sigaction
 793#define __NR_rt_sigreturn       (__NR_SYSCALL_BASE + 173)
 794#define __NR_rt_sigaction       (__NR_SYSCALL_BASE + 174)
 795#define __NR_rt_sigprocmask     (__NR_SYSCALL_BASE + 175)
 796#define __NR_rt_sigpending      (__NR_SYSCALL_BASE + 176)
 797#define __NR_rt_sigsuspend      (__NR_SYSCALL_BASE + 179)
 798#endif
 799#ifndef __NR_pread64
 800#define __NR_pread64            (__NR_SYSCALL_BASE + 180)
 801#endif
 802#ifndef __NR_pwrite64
 803#define __NR_pwrite64           (__NR_SYSCALL_BASE + 181)
 804#endif
 805#ifndef __NR_ugetrlimit
 806#define __NR_ugetrlimit         (__NR_SYSCALL_BASE + 191)
 807#endif
 808#ifndef __NR_stat64
 809#define __NR_stat64             (__NR_SYSCALL_BASE + 195)
 810#endif
 811#ifndef __NR_fstat64
 812#define __NR_fstat64            (__NR_SYSCALL_BASE + 197)
 813#endif
 814#ifndef __NR_setresuid32
 815#define __NR_setresuid32        (__NR_SYSCALL_BASE + 208)
 816#define __NR_getresuid32        (__NR_SYSCALL_BASE + 209)
 817#define __NR_setresgid32        (__NR_SYSCALL_BASE + 210)
 818#define __NR_getresgid32        (__NR_SYSCALL_BASE + 211)
 819#endif
 820#ifndef __NR_setfsuid32
 821#define __NR_setfsuid32         (__NR_SYSCALL_BASE + 215)
 822#define __NR_setfsgid32         (__NR_SYSCALL_BASE + 216)
 823#endif
 824#ifndef __NR_getdents64
 825#define __NR_getdents64         (__NR_SYSCALL_BASE + 217)
 826#endif
 827#ifndef __NR_gettid
 828#define __NR_gettid             (__NR_SYSCALL_BASE + 224)
 829#endif
 830#ifndef __NR_readahead
 831#define __NR_readahead          (__NR_SYSCALL_BASE + 225)
 832#endif
 833#ifndef __NR_setxattr
 834#define __NR_setxattr           (__NR_SYSCALL_BASE + 226)
 835#endif
 836#ifndef __NR_lsetxattr
 837#define __NR_lsetxattr          (__NR_SYSCALL_BASE + 227)
 838#endif
 839#ifndef __NR_getxattr
 840#define __NR_getxattr           (__NR_SYSCALL_BASE + 229)
 841#endif
 842#ifndef __NR_lgetxattr
 843#define __NR_lgetxattr          (__NR_SYSCALL_BASE + 230)
 844#endif
 845#ifndef __NR_listxattr
 846#define __NR_listxattr          (__NR_SYSCALL_BASE + 232)
 847#endif
 848#ifndef __NR_llistxattr
 849#define __NR_llistxattr         (__NR_SYSCALL_BASE + 233)
 850#endif
 851#ifndef __NR_tkill
 852#define __NR_tkill              (__NR_SYSCALL_BASE + 238)
 853#endif
 854#ifndef __NR_futex
 855#define __NR_futex              (__NR_SYSCALL_BASE + 240)
 856#endif
 857#ifndef __NR_sched_setaffinity
 858#define __NR_sched_setaffinity  (__NR_SYSCALL_BASE + 241)
 859#define __NR_sched_getaffinity  (__NR_SYSCALL_BASE + 242)
 860#endif
 861#ifndef __NR_set_tid_address
 862#define __NR_set_tid_address    (__NR_SYSCALL_BASE + 256)
 863#endif
 864#ifndef __NR_clock_gettime
 865#define __NR_clock_gettime      (__NR_SYSCALL_BASE + 263)
 866#endif
 867#ifndef __NR_clock_getres
 868#define __NR_clock_getres       (__NR_SYSCALL_BASE + 264)
 869#endif
 870#ifndef __NR_statfs64
 871#define __NR_statfs64           (__NR_SYSCALL_BASE + 266)
 872#endif
 873#ifndef __NR_fstatfs64
 874#define __NR_fstatfs64          (__NR_SYSCALL_BASE + 267)
 875#endif
 876#ifndef __NR_ioprio_set
 877#define __NR_ioprio_set         (__NR_SYSCALL_BASE + 314)
 878#endif
 879#ifndef __NR_ioprio_get
 880#define __NR_ioprio_get         (__NR_SYSCALL_BASE + 315)
 881#endif
 882#ifndef __NR_move_pages
 883#define __NR_move_pages         (__NR_SYSCALL_BASE + 344)
 884#endif
 885#ifndef __NR_getcpu
 886#define __NR_getcpu             (__NR_SYSCALL_BASE + 345)
 887#endif
 888/* End of ARM 3/EABI definitions                                                */
 889#elif defined(__x86_64__)
 890#ifndef __NR_pread64
 891#define __NR_pread64             17
 892#endif
 893#ifndef __NR_pwrite64
 894#define __NR_pwrite64            18
 895#endif
 896#ifndef __NR_setresuid
 897#define __NR_setresuid          117
 898#define __NR_getresuid          118
 899#define __NR_setresgid          119
 900#define __NR_getresgid          120
 901#endif
 902#ifndef __NR_quotactl
 903#define __NR_quotactl           179
 904#endif
 905#ifndef __NR_gettid
 906#define __NR_gettid             186
 907#endif
 908#ifndef __NR_readahead
 909#define __NR_readahead          187
 910#endif
 911#ifndef __NR_setxattr
 912#define __NR_setxattr           188
 913#endif
 914#ifndef __NR_lsetxattr
 915#define __NR_lsetxattr          189
 916#endif
 917#ifndef __NR_getxattr
 918#define __NR_getxattr           191
 919#endif
 920#ifndef __NR_lgetxattr
 921#define __NR_lgetxattr          192
 922#endif
 923#ifndef __NR_listxattr
 924#define __NR_listxattr          194
 925#endif
 926#ifndef __NR_llistxattr
 927#define __NR_llistxattr         195
 928#endif
 929#ifndef __NR_tkill
 930#define __NR_tkill              200
 931#endif
 932#ifndef __NR_futex
 933#define __NR_futex              202
 934#endif
 935#ifndef __NR_sched_setaffinity
 936#define __NR_sched_setaffinity  203
 937#define __NR_sched_getaffinity  204
 938#endif
 939#ifndef __NR_getdents64
 940#define __NR_getdents64         217
 941#endif
 942#ifndef __NR_set_tid_address
 943#define __NR_set_tid_address    218
 944#endif
 945#ifndef __NR_fadvise64
 946#define __NR_fadvise64          221
 947#endif
 948#ifndef __NR_clock_gettime
 949#define __NR_clock_gettime      228
 950#endif
 951#ifndef __NR_clock_getres
 952#define __NR_clock_getres       229
 953#endif
 954#ifndef __NR_ioprio_set
 955#define __NR_ioprio_set         251
 956#endif
 957#ifndef __NR_ioprio_get
 958#define __NR_ioprio_get         252
 959#endif
 960#ifndef __NR_openat
 961#define __NR_openat             257
 962#endif
 963#ifndef __NR_newfstatat
 964#define __NR_newfstatat         262
 965#endif
 966#ifndef __NR_unlinkat
 967#define __NR_unlinkat           263
 968#endif
 969#ifndef __NR_move_pages
 970#define __NR_move_pages         279
 971#endif
 972#ifndef __NR_fallocate
 973#define __NR_fallocate          285
 974#endif
 975/* End of x86-64 definitions                                                 */
 976#elif defined(__mips__)
 977#if _MIPS_SIM == _MIPS_SIM_ABI32
 978#ifndef __NR_setresuid
 979#define __NR_setresuid          (__NR_Linux + 185)
 980#define __NR_getresuid          (__NR_Linux + 186)
 981#define __NR_setresgid          (__NR_Linux + 190)
 982#define __NR_getresgid          (__NR_Linux + 191)
 983#endif
 984#ifndef __NR_rt_sigaction
 985#define __NR_rt_sigreturn       (__NR_Linux + 193)
 986#define __NR_rt_sigaction       (__NR_Linux + 194)
 987#define __NR_rt_sigprocmask     (__NR_Linux + 195)
 988#define __NR_rt_sigpending      (__NR_Linux + 196)
 989#define __NR_rt_sigsuspend      (__NR_Linux + 199)
 990#endif
 991#ifndef __NR_pread64
 992#define __NR_pread64            (__NR_Linux + 200)
 993#endif
 994#ifndef __NR_pwrite64
 995#define __NR_pwrite64           (__NR_Linux + 201)
 996#endif
 997#ifndef __NR_stat64
 998#define __NR_stat64             (__NR_Linux + 213)
 999#endif
1000#ifndef __NR_fstat64
1001#define __NR_fstat64            (__NR_Linux + 215)
1002#endif
1003#ifndef __NR_getdents64
1004#define __NR_getdents64         (__NR_Linux + 219)
1005#endif
1006#ifndef __NR_gettid
1007#define __NR_gettid             (__NR_Linux + 222)
1008#endif
1009#ifndef __NR_readahead
1010#define __NR_readahead          (__NR_Linux + 223)
1011#endif
1012#ifndef __NR_setxattr
1013#define __NR_setxattr           (__NR_Linux + 224)
1014#endif
1015#ifndef __NR_lsetxattr
1016#define __NR_lsetxattr          (__NR_Linux + 225)
1017#endif
1018#ifndef __NR_getxattr
1019#define __NR_getxattr           (__NR_Linux + 227)
1020#endif
1021#ifndef __NR_lgetxattr
1022#define __NR_lgetxattr          (__NR_Linux + 228)
1023#endif
1024#ifndef __NR_listxattr
1025#define __NR_listxattr          (__NR_Linux + 230)
1026#endif
1027#ifndef __NR_llistxattr
1028#define __NR_llistxattr         (__NR_Linux + 231)
1029#endif
1030#ifndef __NR_tkill
1031#define __NR_tkill              (__NR_Linux + 236)
1032#endif
1033#ifndef __NR_futex
1034#define __NR_futex              (__NR_Linux + 238)
1035#endif
1036#ifndef __NR_sched_setaffinity
1037#define __NR_sched_setaffinity  (__NR_Linux + 239)
1038#define __NR_sched_getaffinity  (__NR_Linux + 240)
1039#endif
1040#ifndef __NR_set_tid_address
1041#define __NR_set_tid_address    (__NR_Linux + 252)
1042#endif
1043#ifndef __NR_statfs64
1044#define __NR_statfs64           (__NR_Linux + 255)
1045#endif
1046#ifndef __NR_fstatfs64
1047#define __NR_fstatfs64          (__NR_Linux + 256)
1048#endif
1049#ifndef __NR_clock_gettime
1050#define __NR_clock_gettime      (__NR_Linux + 263)
1051#endif
1052#ifndef __NR_clock_getres
1053#define __NR_clock_getres       (__NR_Linux + 264)
1054#endif
1055#ifndef __NR_openat
1056#define __NR_openat             (__NR_Linux + 288)
1057#endif
1058#ifndef __NR_fstatat
1059#define __NR_fstatat            (__NR_Linux + 293)
1060#endif
1061#ifndef __NR_unlinkat
1062#define __NR_unlinkat           (__NR_Linux + 294)
1063#endif
1064#ifndef __NR_move_pages
1065#define __NR_move_pages         (__NR_Linux + 308)
1066#endif
1067#ifndef __NR_getcpu
1068#define __NR_getcpu             (__NR_Linux + 312)
1069#endif
1070#ifndef __NR_ioprio_set
1071#define __NR_ioprio_set         (__NR_Linux + 314)
1072#endif
1073#ifndef __NR_ioprio_get
1074#define __NR_ioprio_get         (__NR_Linux + 315)
1075#endif
1076/* End of MIPS (old 32bit API) definitions */
1077#elif  _MIPS_SIM == _MIPS_SIM_ABI64
1078#ifndef __NR_pread64
1079#define __NR_pread64            (__NR_Linux +  16)
1080#endif
1081#ifndef __NR_pwrite64
1082#define __NR_pwrite64           (__NR_Linux +  17)
1083#endif
1084#ifndef __NR_setresuid
1085#define __NR_setresuid          (__NR_Linux + 115)
1086#define __NR_getresuid          (__NR_Linux + 116)
1087#define __NR_setresgid          (__NR_Linux + 117)
1088#define __NR_getresgid          (__NR_Linux + 118)
1089#endif
1090#ifndef __NR_gettid
1091#define __NR_gettid             (__NR_Linux + 178)
1092#endif
1093#ifndef __NR_readahead
1094#define __NR_readahead          (__NR_Linux + 179)
1095#endif
1096#ifndef __NR_setxattr
1097#define __NR_setxattr           (__NR_Linux + 180)
1098#endif
1099#ifndef __NR_lsetxattr
1100#define __NR_lsetxattr          (__NR_Linux + 181)
1101#endif
1102#ifndef __NR_getxattr
1103#define __NR_getxattr           (__NR_Linux + 183)
1104#endif
1105#ifndef __NR_lgetxattr
1106#define __NR_lgetxattr          (__NR_Linux + 184)
1107#endif
1108#ifndef __NR_listxattr
1109#define __NR_listxattr          (__NR_Linux + 186)
1110#endif
1111#ifndef __NR_llistxattr
1112#define __NR_llistxattr         (__NR_Linux + 187)
1113#endif
1114#ifndef __NR_tkill
1115#define __NR_tkill              (__NR_Linux + 192)
1116#endif
1117#ifndef __NR_futex
1118#define __NR_futex              (__NR_Linux + 194)
1119#endif
1120#ifndef __NR_sched_setaffinity
1121#define __NR_sched_setaffinity  (__NR_Linux + 195)
1122#define __NR_sched_getaffinity  (__NR_Linux + 196)
1123#endif
1124#ifndef __NR_set_tid_address
1125#define __NR_set_tid_address    (__NR_Linux + 212)
1126#endif
1127#ifndef __NR_clock_gettime
1128#define __NR_clock_gettime      (__NR_Linux + 222)
1129#endif
1130#ifndef __NR_clock_getres
1131#define __NR_clock_getres       (__NR_Linux + 223)
1132#endif
1133#ifndef __NR_openat
1134#define __NR_openat             (__NR_Linux + 247)
1135#endif
1136#ifndef __NR_fstatat
1137#define __NR_fstatat            (__NR_Linux + 252)
1138#endif
1139#ifndef __NR_unlinkat
1140#define __NR_unlinkat           (__NR_Linux + 253)
1141#endif
1142#ifndef __NR_move_pages
1143#define __NR_move_pages         (__NR_Linux + 267)
1144#endif
1145#ifndef __NR_getcpu
1146#define __NR_getcpu             (__NR_Linux + 271)
1147#endif
1148#ifndef __NR_ioprio_set
1149#define __NR_ioprio_set         (__NR_Linux + 273)
1150#endif
1151#ifndef __NR_ioprio_get
1152#define __NR_ioprio_get         (__NR_Linux + 274)
1153#endif
1154/* End of MIPS (64bit API) definitions */
1155#else
1156#ifndef __NR_setresuid
1157#define __NR_setresuid          (__NR_Linux + 115)
1158#define __NR_getresuid          (__NR_Linux + 116)
1159#define __NR_setresgid          (__NR_Linux + 117)
1160#define __NR_getresgid          (__NR_Linux + 118)
1161#endif
1162#ifndef __NR_gettid
1163#define __NR_gettid             (__NR_Linux + 178)
1164#endif
1165#ifndef __NR_readahead
1166#define __NR_readahead          (__NR_Linux + 179)
1167#endif
1168#ifndef __NR_setxattr
1169#define __NR_setxattr           (__NR_Linux + 180)
1170#endif
1171#ifndef __NR_lsetxattr
1172#define __NR_lsetxattr          (__NR_Linux + 181)
1173#endif
1174#ifndef __NR_getxattr
1175#define __NR_getxattr           (__NR_Linux + 183)
1176#endif
1177#ifndef __NR_lgetxattr
1178#define __NR_lgetxattr          (__NR_Linux + 184)
1179#endif
1180#ifndef __NR_listxattr
1181#define __NR_listxattr          (__NR_Linux + 186)
1182#endif
1183#ifndef __NR_llistxattr
1184#define __NR_llistxattr         (__NR_Linux + 187)
1185#endif
1186#ifndef __NR_tkill
1187#define __NR_tkill              (__NR_Linux + 192)
1188#endif
1189#ifndef __NR_futex
1190#define __NR_futex              (__NR_Linux + 194)
1191#endif
1192#ifndef __NR_sched_setaffinity
1193#define __NR_sched_setaffinity  (__NR_Linux + 195)
1194#define __NR_sched_getaffinity  (__NR_Linux + 196)
1195#endif
1196#ifndef __NR_set_tid_address
1197#define __NR_set_tid_address    (__NR_Linux + 213)
1198#endif
1199#ifndef __NR_statfs64
1200#define __NR_statfs64           (__NR_Linux + 217)
1201#endif
1202#ifndef __NR_fstatfs64
1203#define __NR_fstatfs64          (__NR_Linux + 218)
1204#endif
1205#ifndef __NR_clock_gettime
1206#define __NR_clock_gettime      (__NR_Linux + 226)
1207#endif
1208#ifndef __NR_clock_getres
1209#define __NR_clock_getres       (__NR_Linux + 227)
1210#endif
1211#ifndef __NR_openat
1212#define __NR_openat             (__NR_Linux + 251)
1213#endif
1214#ifndef __NR_fstatat
1215#define __NR_fstatat            (__NR_Linux + 256)
1216#endif
1217#ifndef __NR_unlinkat
1218#define __NR_unlinkat           (__NR_Linux + 257)
1219#endif
1220#ifndef __NR_move_pages
1221#define __NR_move_pages         (__NR_Linux + 271)
1222#endif
1223#ifndef __NR_getcpu
1224#define __NR_getcpu             (__NR_Linux + 275)
1225#endif
1226#ifndef __NR_ioprio_set
1227#define __NR_ioprio_set         (__NR_Linux + 277)
1228#endif
1229#ifndef __NR_ioprio_get
1230#define __NR_ioprio_get         (__NR_Linux + 278)
1231#endif
1232/* End of MIPS (new 32bit API) definitions                                   */
1233#endif
1234/* End of MIPS definitions                                                   */
1235#elif defined(__PPC__)
1236#ifndef __NR_setfsuid
1237#define __NR_setfsuid           138
1238#define __NR_setfsgid           139
1239#endif
1240#ifndef __NR_setresuid
1241#define __NR_setresuid          164
1242#define __NR_getresuid          165
1243#define __NR_setresgid          169
1244#define __NR_getresgid          170
1245#endif
1246#ifndef __NR_rt_sigaction
1247#define __NR_rt_sigreturn       172
1248#define __NR_rt_sigaction       173
1249#define __NR_rt_sigprocmask     174
1250#define __NR_rt_sigpending      175
1251#define __NR_rt_sigsuspend      178
1252#endif
1253#ifndef __NR_pread64
1254#define __NR_pread64            179
1255#endif
1256#ifndef __NR_pwrite64
1257#define __NR_pwrite64           180
1258#endif
1259#ifndef __NR_ugetrlimit
1260#define __NR_ugetrlimit         190
1261#endif
1262#ifndef __NR_readahead
1263#define __NR_readahead          191
1264#endif
1265#ifndef __NR_stat64
1266#define __NR_stat64             195
1267#endif
1268#ifndef __NR_fstat64
1269#define __NR_fstat64            197
1270#endif
1271#ifndef __NR_getdents64
1272#define __NR_getdents64         202
1273#endif
1274#ifndef __NR_gettid
1275#define __NR_gettid             207
1276#endif
1277#ifndef __NR_tkill
1278#define __NR_tkill              208
1279#endif
1280#ifndef __NR_setxattr
1281#define __NR_setxattr           209
1282#endif
1283#ifndef __NR_lsetxattr
1284#define __NR_lsetxattr          210
1285#endif
1286#ifndef __NR_getxattr
1287#define __NR_getxattr           212
1288#endif
1289#ifndef __NR_lgetxattr
1290#define __NR_lgetxattr          213
1291#endif
1292#ifndef __NR_listxattr
1293#define __NR_listxattr          215
1294#endif
1295#ifndef __NR_llistxattr
1296#define __NR_llistxattr         216
1297#endif
1298#ifndef __NR_futex
1299#define __NR_futex              221
1300#endif
1301#ifndef __NR_sched_setaffinity
1302#define __NR_sched_setaffinity  222
1303#define __NR_sched_getaffinity  223
1304#endif
1305#ifndef __NR_set_tid_address
1306#define __NR_set_tid_address    232
1307#endif
1308#ifndef __NR_clock_gettime
1309#define __NR_clock_gettime      246
1310#endif
1311#ifndef __NR_clock_getres
1312#define __NR_clock_getres       247
1313#endif
1314#ifndef __NR_statfs64
1315#define __NR_statfs64           252
1316#endif
1317#ifndef __NR_fstatfs64
1318#define __NR_fstatfs64          253
1319#endif
1320#ifndef __NR_fadvise64_64
1321#define __NR_fadvise64_64       254
1322#endif
1323#ifndef __NR_ioprio_set
1324#define __NR_ioprio_set         273
1325#endif
1326#ifndef __NR_ioprio_get
1327#define __NR_ioprio_get         274
1328#endif
1329#ifndef __NR_openat
1330#define __NR_openat             286
1331#endif
1332#ifndef __NR_fstatat64
1333#define __NR_fstatat64          291
1334#endif
1335#ifndef __NR_unlinkat
1336#define __NR_unlinkat           292
1337#endif
1338#ifndef __NR_move_pages
1339#define __NR_move_pages         301
1340#endif
1341#ifndef __NR_getcpu
1342#define __NR_getcpu             302
1343#endif
1344/* End of powerpc defininitions                                              */
1345#endif
1346
1347
1348/* After forking, we must make sure to only call system calls.               */
1349#if defined __BOUNDED_POINTERS__
1350  #error "Need to port invocations of syscalls for bounded ptrs"
1351#else
1352  /* The core dumper and the thread lister get executed after threads
1353   * have been suspended. As a consequence, we cannot call any functions
1354   * that acquire locks. Unfortunately, libc wraps most system calls
1355   * (e.g. in order to implement pthread_atfork, and to make calls
1356   * cancellable), which means we cannot call these functions. Instead,
1357   * we have to call syscall() directly.
1358   */
1359  #undef LSS_ERRNO
1360  #ifdef SYS_ERRNO
1361    /* Allow the including file to override the location of errno. This can
1362     * be useful when using clone() with the CLONE_VM option.
1363     */
1364    #define LSS_ERRNO SYS_ERRNO
1365  #else
1366    #define LSS_ERRNO errno
1367  #endif
1368
1369  #undef LSS_INLINE
1370  #ifdef SYS_INLINE
1371    #define LSS_INLINE SYS_INLINE
1372  #else
1373    #define LSS_INLINE static inline
1374  #endif
1375
1376  /* Allow the including file to override the prefix used for all new
1377   * system calls. By default, it will be set to "sys_".
1378   */
1379  #undef LSS_NAME
1380  #ifndef SYS_PREFIX
1381    #define LSS_NAME(name) sys_##name
1382  #elif defined SYS_PREFIX && SYS_PREFIX < 0
1383    #define LSS_NAME(name) name
1384  #elif defined SYS_PREFIX && SYS_PREFIX == 0
1385    #define LSS_NAME(name) sys0_##name
1386  #elif defined SYS_PREFIX && SYS_PREFIX == 1
1387    #define LSS_NAME(name) sys1_##name
1388  #elif defined SYS_PREFIX && SYS_PREFIX == 2
1389    #define LSS_NAME(name) sys2_##name
1390  #elif defined SYS_PREFIX && SYS_PREFIX == 3
1391    #define LSS_NAME(name) sys3_##name
1392  #elif defined SYS_PREFIX && SYS_PREFIX == 4
1393    #define LSS_NAME(name) sys4_##name
1394  #elif defined SYS_PREFIX && SYS_PREFIX == 5
1395    #define LSS_NAME(name) sys5_##name
1396  #elif defined SYS_PREFIX && SYS_PREFIX == 6
1397    #define LSS_NAME(name) sys6_##name
1398  #elif defined SYS_PREFIX && SYS_PREFIX == 7
1399    #define LSS_NAME(name) sys7_##name
1400  #elif defined SYS_PREFIX && SYS_PREFIX == 8
1401    #define LSS_NAME(name) sys8_##name
1402  #elif defined SYS_PREFIX && SYS_PREFIX == 9
1403    #define LSS_NAME(name) sys9_##name
1404  #endif
1405
1406  #undef  LSS_RETURN
1407  #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) \
1408       || defined(__ARM_EABI__))
1409  /* Failing system calls return a negative result in the range of
1410   * -1..-4095. These are "errno" values with the sign inverted.
1411   */
1412  #define LSS_RETURN(type, res)                                               \
1413    do {                                                                      \
1414      if ((unsigned long)(res) >= (unsigned long)(-4095)) {                   \
1415        LSS_ERRNO = -(res);                                                   \
1416        res = -1;                                                             \
1417      }                                                                       \
1418      return (type) (res);                                                    \
1419    } while (0)
1420  #elif defined(__mips__)
1421  /* On MIPS, failing system calls return -1, and set errno in a
1422   * separate CPU register.
1423   */
1424  #define LSS_RETURN(type, res, err)                                          \
1425    do {                                                                      \
1426      if (err) {                                                              \
1427        LSS_ERRNO = (res);                                                    \
1428        res = -1;                                                             \
1429      }                                                                       \
1430      return (type) (res);                                                    \
1431    } while (0)
1432  #elif defined(__PPC__)
1433  /* On PPC, failing system calls return -1, and set errno in a
1434   * separate CPU register. See linux/unistd.h.
1435   */
1436  #define LSS_RETURN(type, res, err)                                          \
1437   do {                                                                       \
1438     if (err & 0x10000000 ) {                                                 \
1439       LSS_ERRNO = (res);                                                     \
1440       res = -1;                                                              \
1441     }                                                                        \
1442     return (type) (res);                                                     \
1443   } while (0)
1444  #endif
1445  #if defined(__i386__)
1446    /* In PIC mode (e.g. when building shared libraries), gcc for i386
1447     * reserves ebx. Unfortunately, most distribution ship with implementations
1448     * of _syscallX() which clobber ebx.
1449     * Also, most definitions of _syscallX() neglect to mark "memory" as being
1450     * clobbered. This causes problems with compilers, that do a better job
1451     * at optimizing across __asm__ calls.
1452     * So, we just have to redefine all of the _syscallX() macros.
1453     */
1454    #undef LSS_ENTRYPOINT
1455    #ifdef SYS_SYSCALL_ENTRYPOINT
1456    static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
1457      void (**entrypoint)(void);
1458      asm volatile(".bss\n"
1459                   ".align 8\n"
1460                   ".globl "SYS_SYSCALL_ENTRYPOINT"\n"
1461                   ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n"
1462                   ".previous\n"
1463                   /* This logically does 'lea "SYS_SYSCALL_ENTRYPOINT", %0' */
1464                   "call 0f\n"
1465                 "0:pop  %0\n"
1466                   "add  $_GLOBAL_OFFSET_TABLE_+[.-0b], %0\n"
1467                   "mov  "SYS_SYSCALL_ENTRYPOINT"@GOT(%0), %0\n"
1468                   : "=r"(entrypoint));
1469      return entrypoint;
1470    }
1471
1472    #define LSS_ENTRYPOINT ".bss\n"                                           \
1473                           ".align 8\n"                                       \
1474                           ".globl "SYS_SYSCALL_ENTRYPOINT"\n"                \
1475                           ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n"           \
1476                           ".previous\n"                                      \
1477                           /* Check the SYS_SYSCALL_ENTRYPOINT vector      */ \
1478                           "push %%eax\n"                                     \
1479                           "call 10000f\n"                                    \
1480                     "10000:pop  %%eax\n"                                     \
1481                           "add  $_GLOBAL_OFFSET_TABLE_+[.-10000b], %%eax\n"  \
1482                           "mov  "SYS_SYSCALL_ENTRYPOINT"@GOT(%%eax), %%eax\n"\
1483                           "mov  0(%%eax), %%eax\n"                           \
1484                           "test %%eax, %%eax\n"                              \
1485                           "jz   10001f\n"                                    \
1486                           "push %%eax\n"                                     \
1487                           "lea  10002f, %%eax\n"                             \
1488                           "xchg 4(%%esp), %%eax\n"                           \
1489                           "ret\n"                                            \
1490                     "10001:pop  %%eax\n"                                     \
1491                           "int $0x80\n"                                      \
1492                     "10002:\n"
1493    #else
1494    #define LSS_ENTRYPOINT "int $0x80\n"
1495    #endif
1496    #undef  LSS_BODY
1497    #define LSS_BODY(type,args...)                                            \
1498      long __res;                                                             \
1499      __asm__ __volatile__("push %%ebx\n"                                     \
1500                           "movl %2,%%ebx\n"                                  \
1501                           LSS_ENTRYPOINT                                     \
1502                           "pop %%ebx"                                        \
1503                           args                                               \
1504                           : "esp", "memory");                                \
1505      LSS_RETURN(type,__res)
1506    #undef  _syscall0
1507    #define _syscall0(type,name)                                              \
1508      type LSS_NAME(name)(void) {                                             \
1509        long __res;                                                           \
1510        __asm__ volatile(LSS_ENTRYPOINT                                       \
1511                         : "=a" (__res)                                       \
1512                         : "0" (__NR_##name)                                  \
1513                         : "esp", "memory");                                  \
1514        LSS_RETURN(type,__res);                                               \
1515      }
1516    #undef  _syscall1
1517    #define _syscall1(type,name,type1,arg1)                                   \
1518      type LSS_NAME(name)(type1 arg1) {                                       \
1519        LSS_BODY(type,                                                        \
1520             : "=a" (__res)                                                   \
1521             : "0" (__NR_##name), "ri" ((long)(arg1)));                       \
1522      }
1523    #undef  _syscall2
1524    #define _syscall2(type,name,type1,arg1,type2,arg2)                        \
1525      type LSS_NAME(name)(type1 arg1,type2 arg2) {                            \
1526        LSS_BODY(type,                                                        \
1527             : "=a" (__res)                                                   \
1528             : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2)));    \
1529      }
1530    #undef  _syscall3
1531    #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3)             \
1532      type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) {                 \
1533        LSS_BODY(type,                                                        \
1534             : "=a" (__res)                                                   \…

Large files files are truncated, but you can click here to view the full file