LCOV - code coverage report
Current view: top level - toolkit/crashreporter/google-breakpad/src/third_party/lss - linux_syscall_support.h (source / functions) Hit Total Coverage
Test: output.info Lines: 5 40 12.5 %
Date: 2017-07-14 16:53:18 Functions: 2 24 8.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (c) 2005-2011, 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, PPC, s390 and s390x
      86             :  * on Linux.
      87             :  * Porting to other related platforms should not be difficult.
      88             :  */
      89             : #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) ||   \
      90             :      defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__) || \
      91             :      defined(__aarch64__) || defined(__s390__)) \
      92             :   && (defined(__linux) || defined(__ANDROID__))
      93             : 
      94             : #ifndef SYS_CPLUSPLUS
      95             : #ifdef __cplusplus
      96             : /* Some system header files in older versions of gcc neglect to properly
      97             :  * handle being included from C++. As it appears to be harmless to have
      98             :  * multiple nested 'extern "C"' blocks, just add another one here.
      99             :  */
     100             : extern "C" {
     101             : #endif
     102             : 
     103             : #include <errno.h>
     104             : #include <fcntl.h>
     105             : #include <sched.h>
     106             : #include <signal.h>
     107             : #include <stdarg.h>
     108             : #include <stddef.h>
     109             : #include <stdint.h>
     110             : #include <string.h>
     111             : #include <sys/ptrace.h>
     112             : #include <sys/resource.h>
     113             : #include <sys/time.h>
     114             : #include <sys/types.h>
     115             : #include <sys/syscall.h>
     116             : #include <unistd.h>
     117             : #include <linux/unistd.h>
     118             : #include <endian.h>
     119             : 
     120             : #ifdef __mips__
     121             : /* Include definitions of the ABI currently in use.                          */
     122             : #ifdef __ANDROID__
     123             : /* Android doesn't have sgidefs.h, but does have asm/sgidefs.h,
     124             :  * which has the definitions we need.
     125             :  */
     126             : #include <asm/sgidefs.h>
     127             : #else
     128             : #include <sgidefs.h>
     129             : #endif
     130             : #endif
     131             : #endif
     132             : 
     133             : /* The Android NDK's <sys/stat.h> #defines these macros as aliases
     134             :  * to their non-64 counterparts. To avoid naming conflict, remove them. */
     135             : #ifdef __ANDROID__
     136             :   /* These are restored by the corresponding #pragma pop_macro near
     137             :    * the end of this file. */
     138             : # pragma push_macro("stat64")
     139             : # pragma push_macro("fstat64")
     140             : # pragma push_macro("lstat64")
     141             : # undef stat64
     142             : # undef fstat64
     143             : # undef lstat64
     144             : #endif
     145             : 
     146             : /* As glibc often provides subtly incompatible data structures (and implicit
     147             :  * wrapper functions that convert them), we provide our own kernel data
     148             :  * structures for use by the system calls.
     149             :  * These structures have been developed by using Linux 2.6.23 headers for
     150             :  * reference. Note though, we do not care about exact API compatibility
     151             :  * with the kernel, and in fact the kernel often does not have a single
     152             :  * API that works across architectures. Instead, we try to mimic the glibc
     153             :  * API where reasonable, and only guarantee ABI compatibility with the
     154             :  * kernel headers.
     155             :  * Most notably, here are a few changes that were made to the structures
     156             :  * defined by kernel headers:
     157             :  *
     158             :  * - we only define structures, but not symbolic names for kernel data
     159             :  *   types. For the latter, we directly use the native C datatype
     160             :  *   (i.e. "unsigned" instead of "mode_t").
     161             :  * - in a few cases, it is possible to define identical structures for
     162             :  *   both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by
     163             :  *   standardizing on the 64bit version of the data types. In particular,
     164             :  *   this means that we use "unsigned" where the 32bit headers say
     165             :  *   "unsigned long".
     166             :  * - overall, we try to minimize the number of cases where we need to
     167             :  *   conditionally define different structures.
     168             :  * - the "struct kernel_sigaction" class of structures have been
     169             :  *   modified to more closely mimic glibc's API by introducing an
     170             :  *   anonymous union for the function pointer.
     171             :  * - a small number of field names had to have an underscore appended to
     172             :  *   them, because glibc defines a global macro by the same name.
     173             :  */
     174             : 
     175             : /* include/linux/dirent.h                                                    */
     176             : struct kernel_dirent64 {
     177             :   unsigned long long d_ino;
     178             :   long long          d_off;
     179             :   unsigned short     d_reclen;
     180             :   unsigned char      d_type;
     181             :   char               d_name[256];
     182             : };
     183             : 
     184             : /* include/linux/dirent.h                                                    */
     185             : #if defined(__aarch64__)
     186             : // aarch64 only defines dirent64, just uses that for dirent too.
     187             : #define kernel_dirent kernel_dirent64
     188             : #else
     189             : struct kernel_dirent {
     190             :   long               d_ino;
     191             :   long               d_off;
     192             :   unsigned short     d_reclen;
     193             :   char               d_name[256];
     194             : };
     195             : #endif
     196             : 
     197             : /* include/linux/uio.h                                                       */
     198             : struct kernel_iovec {
     199             :   void               *iov_base;
     200             :   unsigned long      iov_len;
     201             : };
     202             : 
     203             : /* include/linux/socket.h                                                    */
     204             : struct kernel_msghdr {
     205             :   void               *msg_name;
     206             :   int                msg_namelen;
     207             :   struct kernel_iovec*msg_iov;
     208             :   unsigned long      msg_iovlen;
     209             :   void               *msg_control;
     210             :   unsigned long      msg_controllen;
     211             :   unsigned           msg_flags;
     212             : };
     213             : 
     214             : /* include/asm-generic/poll.h                                                */
     215             : struct kernel_pollfd {
     216             :   int                fd;
     217             :   short              events;
     218             :   short              revents;
     219             : };
     220             : 
     221             : /* include/linux/resource.h                                                  */
     222             : struct kernel_rlimit {
     223             :   unsigned long      rlim_cur;
     224             :   unsigned long      rlim_max;
     225             : };
     226             : 
     227             : /* include/linux/time.h                                                      */
     228             : struct kernel_timespec {
     229             :   long               tv_sec;
     230             :   long               tv_nsec;
     231             : };
     232             : 
     233             : /* include/linux/time.h                                                      */
     234             : struct kernel_timeval {
     235             :   long               tv_sec;
     236             :   long               tv_usec;
     237             : };
     238             : 
     239             : /* include/linux/resource.h                                                  */
     240             : struct kernel_rusage {
     241             :   struct kernel_timeval ru_utime;
     242             :   struct kernel_timeval ru_stime;
     243             :   long               ru_maxrss;
     244             :   long               ru_ixrss;
     245             :   long               ru_idrss;
     246             :   long               ru_isrss;
     247             :   long               ru_minflt;
     248             :   long               ru_majflt;
     249             :   long               ru_nswap;
     250             :   long               ru_inblock;
     251             :   long               ru_oublock;
     252             :   long               ru_msgsnd;
     253             :   long               ru_msgrcv;
     254             :   long               ru_nsignals;
     255             :   long               ru_nvcsw;
     256             :   long               ru_nivcsw;
     257             : };
     258             : 
     259             : #if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \
     260             :   || defined(__PPC__) || (defined(__s390__) && !defined(__s390x__))
     261             : 
     262             : /* include/asm-{arm,i386,mips,ppc}/signal.h                                  */
     263             : struct kernel_old_sigaction {
     264             :   union {
     265             :     void             (*sa_handler_)(int);
     266             :     void             (*sa_sigaction_)(int, siginfo_t *, void *);
     267             :   };
     268             :   unsigned long      sa_mask;
     269             :   unsigned long      sa_flags;
     270             :   void               (*sa_restorer)(void);
     271             : } __attribute__((packed,aligned(4)));
     272             : #elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
     273             :   #define kernel_old_sigaction kernel_sigaction
     274             : #elif defined(__aarch64__)
     275             :   // No kernel_old_sigaction defined for arm64.
     276             : #endif
     277             : 
     278             : /* Some kernel functions (e.g. sigaction() in 2.6.23) require that the
     279             :  * exactly match the size of the signal set, even though the API was
     280             :  * intended to be extensible. We define our own KERNEL_NSIG to deal with
     281             :  * this.
     282             :  * Please note that glibc provides signals [1.._NSIG-1], whereas the
     283             :  * kernel (and this header) provides the range [1..KERNEL_NSIG]. The
     284             :  * actual number of signals is obviously the same, but the constants
     285             :  * differ by one.
     286             :  */
     287             : #ifdef __mips__
     288             : #define KERNEL_NSIG 128
     289             : #else
     290             : #define KERNEL_NSIG  64
     291             : #endif
     292             : 
     293             : /* include/asm-{arm,aarch64,i386,mips,x86_64}/signal.h                       */
     294             : struct kernel_sigset_t {
     295             :   unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/
     296             :                     (8*sizeof(unsigned long))];
     297             : };
     298             : 
     299             : /* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h                           */
     300             : struct kernel_sigaction {
     301             : #ifdef __mips__
     302             :   unsigned long      sa_flags;
     303             :   union {
     304             :     void             (*sa_handler_)(int);
     305             :     void             (*sa_sigaction_)(int, siginfo_t *, void *);
     306             :   };
     307             :   struct kernel_sigset_t sa_mask;
     308             : #else
     309             :   union {
     310             :     void             (*sa_handler_)(int);
     311             :     void             (*sa_sigaction_)(int, siginfo_t *, void *);
     312             :   };
     313             :   unsigned long      sa_flags;
     314             :   void               (*sa_restorer)(void);
     315             :   struct kernel_sigset_t sa_mask;
     316             : #endif
     317             : };
     318             : 
     319             : /* include/linux/socket.h                                                    */
     320             : struct kernel_sockaddr {
     321             :   unsigned short     sa_family;
     322             :   char               sa_data[14];
     323             : };
     324             : 
     325             : /* include/asm-{arm,aarch64,i386,mips,ppc,s390}/stat.h                       */
     326             : #ifdef __mips__
     327             : #if _MIPS_SIM == _MIPS_SIM_ABI64
     328             : struct kernel_stat {
     329             : #else
     330             : struct kernel_stat64 {
     331             : #endif
     332             :   unsigned           st_dev;
     333             :   unsigned           __pad0[3];
     334             :   unsigned long long st_ino;
     335             :   unsigned           st_mode;
     336             :   unsigned           st_nlink;
     337             :   unsigned           st_uid;
     338             :   unsigned           st_gid;
     339             :   unsigned           st_rdev;
     340             :   unsigned           __pad1[3];
     341             :   long long          st_size;
     342             :   unsigned           st_atime_;
     343             :   unsigned           st_atime_nsec_;
     344             :   unsigned           st_mtime_;
     345             :   unsigned           st_mtime_nsec_;
     346             :   unsigned           st_ctime_;
     347             :   unsigned           st_ctime_nsec_;
     348             :   unsigned           st_blksize;
     349             :   unsigned           __pad2;
     350             :   unsigned long long st_blocks;
     351             : };
     352             : #elif defined __PPC__
     353             : struct kernel_stat64 {
     354             :   unsigned long long st_dev;
     355             :   unsigned long long st_ino;
     356             :   unsigned           st_mode;
     357             :   unsigned           st_nlink;
     358             :   unsigned           st_uid;
     359             :   unsigned           st_gid;
     360             :   unsigned long long st_rdev;
     361             :   unsigned short int __pad2;
     362             :   long long          st_size;
     363             :   long               st_blksize;
     364             :   long long          st_blocks;
     365             :   long               st_atime_;
     366             :   unsigned long      st_atime_nsec_;
     367             :   long               st_mtime_;
     368             :   unsigned long      st_mtime_nsec_;
     369             :   long               st_ctime_;
     370             :   unsigned long      st_ctime_nsec_;
     371             :   unsigned long      __unused4;
     372             :   unsigned long      __unused5;
     373             : };
     374             : #else
     375             : struct kernel_stat64 {
     376             :   unsigned long long st_dev;
     377             :   unsigned char      __pad0[4];
     378             :   unsigned           __st_ino;
     379             :   unsigned           st_mode;
     380             :   unsigned           st_nlink;
     381             :   unsigned           st_uid;
     382             :   unsigned           st_gid;
     383             :   unsigned long long st_rdev;
     384             :   unsigned char      __pad3[4];
     385             :   long long          st_size;
     386             :   unsigned           st_blksize;
     387             :   unsigned long long 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 long long st_ino;
     395             : };
     396             : #endif
     397             : 
     398             : /* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/stat.h                */
     399             : #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
     400             : struct kernel_stat {
     401             :   /* The kernel headers suggest that st_dev and st_rdev should be 32bit
     402             :    * quantities encoding 12bit major and 20bit minor numbers in an interleaved
     403             :    * format. In reality, we do not see useful data in the top bits. So,
     404             :    * we'll leave the padding in here, until we find a better solution.
     405             :    */
     406             :   unsigned short     st_dev;
     407             :   short              pad1;
     408             :   unsigned           st_ino;
     409             :   unsigned short     st_mode;
     410             :   unsigned short     st_nlink;
     411             :   unsigned short     st_uid;
     412             :   unsigned short     st_gid;
     413             :   unsigned short     st_rdev;
     414             :   short              pad2;
     415             :   unsigned           st_size;
     416             :   unsigned           st_blksize;
     417             :   unsigned           st_blocks;
     418             :   unsigned           st_atime_;
     419             :   unsigned           st_atime_nsec_;
     420             :   unsigned           st_mtime_;
     421             :   unsigned           st_mtime_nsec_;
     422             :   unsigned           st_ctime_;
     423             :   unsigned           st_ctime_nsec_;
     424             :   unsigned           __unused4;
     425             :   unsigned           __unused5;
     426             : };
     427             : #elif defined(__x86_64__)
     428             : struct kernel_stat {
     429             :   uint64_t           st_dev;
     430             :   uint64_t           st_ino;
     431             :   uint64_t           st_nlink;
     432             :   unsigned           st_mode;
     433             :   unsigned           st_uid;
     434             :   unsigned           st_gid;
     435             :   unsigned           __pad0;
     436             :   uint64_t           st_rdev;
     437             :   int64_t            st_size;
     438             :   int64_t            st_blksize;
     439             :   int64_t            st_blocks;
     440             :   uint64_t           st_atime_;
     441             :   uint64_t           st_atime_nsec_;
     442             :   uint64_t           st_mtime_;
     443             :   uint64_t           st_mtime_nsec_;
     444             :   uint64_t           st_ctime_;
     445             :   uint64_t           st_ctime_nsec_;
     446             :   int64_t            __unused4[3];
     447             : };
     448             : #elif defined(__PPC__)
     449             : struct kernel_stat {
     450             :   unsigned           st_dev;
     451             :   unsigned long      st_ino;      // ino_t
     452             :   unsigned long      st_mode;     // mode_t
     453             :   unsigned short     st_nlink;    // nlink_t
     454             :   unsigned           st_uid;      // uid_t
     455             :   unsigned           st_gid;      // gid_t
     456             :   unsigned           st_rdev;
     457             :   long               st_size;     // off_t
     458             :   unsigned long      st_blksize;
     459             :   unsigned long      st_blocks;
     460             :   unsigned long      st_atime_;
     461             :   unsigned long      st_atime_nsec_;
     462             :   unsigned long      st_mtime_;
     463             :   unsigned long      st_mtime_nsec_;
     464             :   unsigned long      st_ctime_;
     465             :   unsigned long      st_ctime_nsec_;
     466             :   unsigned long      __unused4;
     467             :   unsigned long      __unused5;
     468             : };
     469             : #elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
     470             : struct kernel_stat {
     471             :   unsigned           st_dev;
     472             :   int                st_pad1[3];
     473             :   unsigned           st_ino;
     474             :   unsigned           st_mode;
     475             :   unsigned           st_nlink;
     476             :   unsigned           st_uid;
     477             :   unsigned           st_gid;
     478             :   unsigned           st_rdev;
     479             :   int                st_pad2[2];
     480             :   long               st_size;
     481             :   int                st_pad3;
     482             :   long               st_atime_;
     483             :   long               st_atime_nsec_;
     484             :   long               st_mtime_;
     485             :   long               st_mtime_nsec_;
     486             :   long               st_ctime_;
     487             :   long               st_ctime_nsec_;
     488             :   int                st_blksize;
     489             :   int                st_blocks;
     490             :   int                st_pad4[14];
     491             : };
     492             : #elif defined(__aarch64__)
     493             : struct kernel_stat {
     494             :   unsigned long      st_dev;
     495             :   unsigned long      st_ino;
     496             :   unsigned int       st_mode;
     497             :   unsigned int       st_nlink;
     498             :   unsigned int       st_uid;
     499             :   unsigned int       st_gid;
     500             :   unsigned long      st_rdev;
     501             :   unsigned long      __pad1;
     502             :   long               st_size;
     503             :   int                st_blksize;
     504             :   int                __pad2;
     505             :   long               st_blocks;
     506             :   long               st_atime_;
     507             :   unsigned long      st_atime_nsec_;
     508             :   long               st_mtime_;
     509             :   unsigned long      st_mtime_nsec_;
     510             :   long               st_ctime_;
     511             :   unsigned long      st_ctime_nsec_;
     512             :   unsigned int       __unused4;
     513             :   unsigned int       __unused5;
     514             : };
     515             : #elif defined(__s390x__)
     516             : struct kernel_stat {
     517             :   unsigned long      st_dev;
     518             :   unsigned long      st_ino;
     519             :   unsigned long      st_nlink;
     520             :   unsigned int       st_mode;
     521             :   unsigned int       st_uid;
     522             :   unsigned int       st_gid;
     523             :   unsigned int       __pad1;
     524             :   unsigned long      st_rdev;
     525             :   unsigned long      st_size;
     526             :   unsigned long      st_atime_;
     527             :   unsigned long      st_atime_nsec_;
     528             :   unsigned long      st_mtime_;
     529             :   unsigned long      st_mtime_nsec_;
     530             :   unsigned long      st_ctime_;
     531             :   unsigned long      st_ctime_nsec_;
     532             :   unsigned long      st_blksize;
     533             :   long               st_blocks;
     534             :   unsigned long      __unused[3];
     535             : };
     536             : #elif defined(__s390__)
     537             : struct kernel_stat {
     538             :   unsigned short     st_dev;
     539             :   unsigned short     __pad1;
     540             :   unsigned long      st_ino;
     541             :   unsigned short     st_mode;
     542             :   unsigned short     st_nlink;
     543             :   unsigned short     st_uid;
     544             :   unsigned short     st_gid;
     545             :   unsigned short     st_rdev;
     546             :   unsigned short     __pad2;
     547             :   unsigned long      st_size;
     548             :   unsigned long      st_blksize;
     549             :   unsigned long      st_blocks;
     550             :   unsigned long      st_atime_;
     551             :   unsigned long      st_atime_nsec_;
     552             :   unsigned long      st_mtime_;
     553             :   unsigned long      st_mtime_nsec_;
     554             :   unsigned long      st_ctime_;
     555             :   unsigned long      st_ctime_nsec_;
     556             :   unsigned long      __unused4;
     557             :   unsigned long      __unused5;
     558             : };
     559             : #endif
     560             : 
     561             : /* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/statfs.h              */
     562             : #ifdef __mips__
     563             : #if _MIPS_SIM != _MIPS_SIM_ABI64
     564             : struct kernel_statfs64 {
     565             :   unsigned long      f_type;
     566             :   unsigned long      f_bsize;
     567             :   unsigned long      f_frsize;
     568             :   unsigned long      __pad;
     569             :   unsigned long long f_blocks;
     570             :   unsigned long long f_bfree;
     571             :   unsigned long long f_files;
     572             :   unsigned long long f_ffree;
     573             :   unsigned long long f_bavail;
     574             :   struct { int val[2]; } f_fsid;
     575             :   unsigned long      f_namelen;
     576             :   unsigned long      f_spare[6];
     577             : };
     578             : #endif
     579             : #elif defined(__s390__)
     580             : /* See also arch/s390/include/asm/compat.h                                   */
     581             : struct kernel_statfs64 {
     582             :   unsigned int       f_type;
     583             :   unsigned int       f_bsize;
     584             :   unsigned long long f_blocks;
     585             :   unsigned long long f_bfree;
     586             :   unsigned long long f_bavail;
     587             :   unsigned long long f_files;
     588             :   unsigned long long f_ffree;
     589             :   struct { int val[2]; } f_fsid;
     590             :   unsigned int       f_namelen;
     591             :   unsigned int       f_frsize;
     592             :   unsigned int       f_flags;
     593             :   unsigned int       f_spare[4];
     594             : };
     595             : #elif !defined(__x86_64__)
     596             : struct kernel_statfs64 {
     597             :   unsigned long      f_type;
     598             :   unsigned long      f_bsize;
     599             :   unsigned long long f_blocks;
     600             :   unsigned long long f_bfree;
     601             :   unsigned long long f_bavail;
     602             :   unsigned long long f_files;
     603             :   unsigned long long f_ffree;
     604             :   struct { int val[2]; } f_fsid;
     605             :   unsigned long      f_namelen;
     606             :   unsigned long      f_frsize;
     607             :   unsigned long      f_spare[5];
     608             : };
     609             : #endif
     610             : 
     611             : /* include/asm-{arm,i386,mips,x86_64,ppc,generic,s390}/statfs.h              */
     612             : #ifdef __mips__
     613             : struct kernel_statfs {
     614             :   long               f_type;
     615             :   long               f_bsize;
     616             :   long               f_frsize;
     617             :   long               f_blocks;
     618             :   long               f_bfree;
     619             :   long               f_files;
     620             :   long               f_ffree;
     621             :   long               f_bavail;
     622             :   struct { int val[2]; } f_fsid;
     623             :   long               f_namelen;
     624             :   long               f_spare[6];
     625             : };
     626             : #elif defined(__x86_64__)
     627             : struct kernel_statfs {
     628             :   /* x86_64 actually defines all these fields as signed, whereas all other  */
     629             :   /* platforms define them as unsigned. Leaving them at unsigned should not */
     630             :   /* cause any problems. Make sure these are 64-bit even on x32.            */
     631             :   uint64_t           f_type;
     632             :   uint64_t           f_bsize;
     633             :   uint64_t           f_blocks;
     634             :   uint64_t           f_bfree;
     635             :   uint64_t           f_bavail;
     636             :   uint64_t           f_files;
     637             :   uint64_t           f_ffree;
     638             :   struct { int val[2]; } f_fsid;
     639             :   uint64_t           f_namelen;
     640             :   uint64_t           f_frsize;
     641             :   uint64_t           f_spare[5];
     642             : };
     643             : #elif defined(__s390__)
     644             : struct kernel_statfs {
     645             :   unsigned int       f_type;
     646             :   unsigned int       f_bsize;
     647             :   unsigned long      f_blocks;
     648             :   unsigned long      f_bfree;
     649             :   unsigned long      f_bavail;
     650             :   unsigned long      f_files;
     651             :   unsigned long      f_ffree;
     652             :   struct { int val[2]; } f_fsid;
     653             :   unsigned int       f_namelen;
     654             :   unsigned int       f_frsize;
     655             :   unsigned int       f_flags;
     656             :   unsigned int       f_spare[4];
     657             : };
     658             : #else
     659             : struct kernel_statfs {
     660             :   unsigned long      f_type;
     661             :   unsigned long      f_bsize;
     662             :   unsigned long      f_blocks;
     663             :   unsigned long      f_bfree;
     664             :   unsigned long      f_bavail;
     665             :   unsigned long      f_files;
     666             :   unsigned long      f_ffree;
     667             :   struct { int val[2]; } f_fsid;
     668             :   unsigned long      f_namelen;
     669             :   unsigned long      f_frsize;
     670             :   unsigned long      f_spare[5];
     671             : };
     672             : #endif
     673             : 
     674             : 
     675             : /* Definitions missing from the standard header files                        */
     676             : #ifndef O_DIRECTORY
     677             : #if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || defined(__aarch64__)
     678             : #define O_DIRECTORY             0040000
     679             : #else
     680             : #define O_DIRECTORY             0200000
     681             : #endif
     682             : #endif
     683             : #ifndef NT_PRXFPREG
     684             : #define NT_PRXFPREG             0x46e62b7f
     685             : #endif
     686             : #ifndef PTRACE_GETFPXREGS
     687             : #define PTRACE_GETFPXREGS       ((enum __ptrace_request)18)
     688             : #endif
     689             : #ifndef PR_GET_DUMPABLE
     690             : #define PR_GET_DUMPABLE         3
     691             : #endif
     692             : #ifndef PR_SET_DUMPABLE
     693             : #define PR_SET_DUMPABLE         4
     694             : #endif
     695             : #ifndef PR_GET_SECCOMP
     696             : #define PR_GET_SECCOMP          21
     697             : #endif
     698             : #ifndef PR_SET_SECCOMP
     699             : #define PR_SET_SECCOMP          22
     700             : #endif
     701             : #ifndef AT_FDCWD
     702             : #define AT_FDCWD                (-100)
     703             : #endif
     704             : #ifndef AT_SYMLINK_NOFOLLOW
     705             : #define AT_SYMLINK_NOFOLLOW     0x100
     706             : #endif
     707             : #ifndef AT_REMOVEDIR
     708             : #define AT_REMOVEDIR            0x200
     709             : #endif
     710             : #ifndef MREMAP_FIXED
     711             : #define MREMAP_FIXED            2
     712             : #endif
     713             : #ifndef SA_RESTORER
     714             : #define SA_RESTORER             0x04000000
     715             : #endif
     716             : #ifndef CPUCLOCK_PROF
     717             : #define CPUCLOCK_PROF           0
     718             : #endif
     719             : #ifndef CPUCLOCK_VIRT
     720             : #define CPUCLOCK_VIRT           1
     721             : #endif
     722             : #ifndef CPUCLOCK_SCHED
     723             : #define CPUCLOCK_SCHED          2
     724             : #endif
     725             : #ifndef CPUCLOCK_PERTHREAD_MASK
     726             : #define CPUCLOCK_PERTHREAD_MASK 4
     727             : #endif
     728             : #ifndef MAKE_PROCESS_CPUCLOCK
     729             : #define MAKE_PROCESS_CPUCLOCK(pid, clock)                                     \
     730             :         ((~(int)(pid) << 3) | (int)(clock))
     731             : #endif
     732             : #ifndef MAKE_THREAD_CPUCLOCK
     733             : #define MAKE_THREAD_CPUCLOCK(tid, clock)                                      \
     734             :         ((~(int)(tid) << 3) | (int)((clock) | CPUCLOCK_PERTHREAD_MASK))
     735             : #endif
     736             : 
     737             : #ifndef FUTEX_WAIT
     738             : #define FUTEX_WAIT                0
     739             : #endif
     740             : #ifndef FUTEX_WAKE
     741             : #define FUTEX_WAKE                1
     742             : #endif
     743             : #ifndef FUTEX_FD
     744             : #define FUTEX_FD                  2
     745             : #endif
     746             : #ifndef FUTEX_REQUEUE
     747             : #define FUTEX_REQUEUE             3
     748             : #endif
     749             : #ifndef FUTEX_CMP_REQUEUE
     750             : #define FUTEX_CMP_REQUEUE         4
     751             : #endif
     752             : #ifndef FUTEX_WAKE_OP
     753             : #define FUTEX_WAKE_OP             5
     754             : #endif
     755             : #ifndef FUTEX_LOCK_PI
     756             : #define FUTEX_LOCK_PI             6
     757             : #endif
     758             : #ifndef FUTEX_UNLOCK_PI
     759             : #define FUTEX_UNLOCK_PI           7
     760             : #endif
     761             : #ifndef FUTEX_TRYLOCK_PI
     762             : #define FUTEX_TRYLOCK_PI          8
     763             : #endif
     764             : #ifndef FUTEX_PRIVATE_FLAG
     765             : #define FUTEX_PRIVATE_FLAG        128
     766             : #endif
     767             : #ifndef FUTEX_CMD_MASK
     768             : #define FUTEX_CMD_MASK            ~FUTEX_PRIVATE_FLAG
     769             : #endif
     770             : #ifndef FUTEX_WAIT_PRIVATE
     771             : #define FUTEX_WAIT_PRIVATE        (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
     772             : #endif
     773             : #ifndef FUTEX_WAKE_PRIVATE
     774             : #define FUTEX_WAKE_PRIVATE        (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
     775             : #endif
     776             : #ifndef FUTEX_REQUEUE_PRIVATE
     777             : #define FUTEX_REQUEUE_PRIVATE     (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
     778             : #endif
     779             : #ifndef FUTEX_CMP_REQUEUE_PRIVATE
     780             : #define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
     781             : #endif
     782             : #ifndef FUTEX_WAKE_OP_PRIVATE
     783             : #define FUTEX_WAKE_OP_PRIVATE     (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
     784             : #endif
     785             : #ifndef FUTEX_LOCK_PI_PRIVATE
     786             : #define FUTEX_LOCK_PI_PRIVATE     (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
     787             : #endif
     788             : #ifndef FUTEX_UNLOCK_PI_PRIVATE
     789             : #define FUTEX_UNLOCK_PI_PRIVATE   (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
     790             : #endif
     791             : #ifndef FUTEX_TRYLOCK_PI_PRIVATE
     792             : #define FUTEX_TRYLOCK_PI_PRIVATE  (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
     793             : #endif
     794             : 
     795             : 
     796             : #if defined(__x86_64__)
     797             : #ifndef ARCH_SET_GS
     798             : #define ARCH_SET_GS             0x1001
     799             : #endif
     800             : #ifndef ARCH_GET_GS
     801             : #define ARCH_GET_GS             0x1004
     802             : #endif
     803             : #endif
     804             : 
     805             : #if defined(__i386__)
     806             : #ifndef __NR_quotactl
     807             : #define __NR_quotactl           131
     808             : #endif
     809             : #ifndef __NR_setresuid
     810             : #define __NR_setresuid          164
     811             : #define __NR_getresuid          165
     812             : #define __NR_setresgid          170
     813             : #define __NR_getresgid          171
     814             : #endif
     815             : #ifndef __NR_rt_sigaction
     816             : #define __NR_rt_sigreturn       173
     817             : #define __NR_rt_sigaction       174
     818             : #define __NR_rt_sigprocmask     175
     819             : #define __NR_rt_sigpending      176
     820             : #define __NR_rt_sigsuspend      179
     821             : #endif
     822             : #ifndef __NR_pread64
     823             : #define __NR_pread64            180
     824             : #endif
     825             : #ifndef __NR_pwrite64
     826             : #define __NR_pwrite64           181
     827             : #endif
     828             : #ifndef __NR_ugetrlimit
     829             : #define __NR_ugetrlimit         191
     830             : #endif
     831             : #ifndef __NR_stat64
     832             : #define __NR_stat64             195
     833             : #endif
     834             : #ifndef __NR_fstat64
     835             : #define __NR_fstat64            197
     836             : #endif
     837             : #ifndef __NR_setresuid32
     838             : #define __NR_setresuid32        208
     839             : #define __NR_getresuid32        209
     840             : #define __NR_setresgid32        210
     841             : #define __NR_getresgid32        211
     842             : #endif
     843             : #ifndef __NR_setfsuid32
     844             : #define __NR_setfsuid32         215
     845             : #define __NR_setfsgid32         216
     846             : #endif
     847             : #ifndef __NR_getdents64
     848             : #define __NR_getdents64         220
     849             : #endif
     850             : #ifndef __NR_gettid
     851             : #define __NR_gettid             224
     852             : #endif
     853             : #ifndef __NR_readahead
     854             : #define __NR_readahead          225
     855             : #endif
     856             : #ifndef __NR_setxattr
     857             : #define __NR_setxattr           226
     858             : #endif
     859             : #ifndef __NR_lsetxattr
     860             : #define __NR_lsetxattr          227
     861             : #endif
     862             : #ifndef __NR_getxattr
     863             : #define __NR_getxattr           229
     864             : #endif
     865             : #ifndef __NR_lgetxattr
     866             : #define __NR_lgetxattr          230
     867             : #endif
     868             : #ifndef __NR_listxattr
     869             : #define __NR_listxattr          232
     870             : #endif
     871             : #ifndef __NR_llistxattr
     872             : #define __NR_llistxattr         233
     873             : #endif
     874             : #ifndef __NR_tkill
     875             : #define __NR_tkill              238
     876             : #endif
     877             : #ifndef __NR_futex
     878             : #define __NR_futex              240
     879             : #endif
     880             : #ifndef __NR_sched_setaffinity
     881             : #define __NR_sched_setaffinity  241
     882             : #define __NR_sched_getaffinity  242
     883             : #endif
     884             : #ifndef __NR_set_tid_address
     885             : #define __NR_set_tid_address    258
     886             : #endif
     887             : #ifndef __NR_clock_gettime
     888             : #define __NR_clock_gettime      265
     889             : #endif
     890             : #ifndef __NR_clock_getres
     891             : #define __NR_clock_getres       266
     892             : #endif
     893             : #ifndef __NR_statfs64
     894             : #define __NR_statfs64           268
     895             : #endif
     896             : #ifndef __NR_fstatfs64
     897             : #define __NR_fstatfs64          269
     898             : #endif
     899             : #ifndef __NR_fadvise64_64
     900             : #define __NR_fadvise64_64       272
     901             : #endif
     902             : #ifndef __NR_ioprio_set
     903             : #define __NR_ioprio_set         289
     904             : #endif
     905             : #ifndef __NR_ioprio_get
     906             : #define __NR_ioprio_get         290
     907             : #endif
     908             : #ifndef __NR_openat
     909             : #define __NR_openat             295
     910             : #endif
     911             : #ifndef __NR_fstatat64
     912             : #define __NR_fstatat64          300
     913             : #endif
     914             : #ifndef __NR_unlinkat
     915             : #define __NR_unlinkat           301
     916             : #endif
     917             : #ifndef __NR_move_pages
     918             : #define __NR_move_pages         317
     919             : #endif
     920             : #ifndef __NR_getcpu
     921             : #define __NR_getcpu             318
     922             : #endif
     923             : #ifndef __NR_fallocate
     924             : #define __NR_fallocate          324
     925             : #endif
     926             : /* End of i386 definitions                                                   */
     927             : #elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
     928             : #ifndef __NR_setresuid
     929             : #define __NR_setresuid          (__NR_SYSCALL_BASE + 164)
     930             : #define __NR_getresuid          (__NR_SYSCALL_BASE + 165)
     931             : #define __NR_setresgid          (__NR_SYSCALL_BASE + 170)
     932             : #define __NR_getresgid          (__NR_SYSCALL_BASE + 171)
     933             : #endif
     934             : #ifndef __NR_rt_sigaction
     935             : #define __NR_rt_sigreturn       (__NR_SYSCALL_BASE + 173)
     936             : #define __NR_rt_sigaction       (__NR_SYSCALL_BASE + 174)
     937             : #define __NR_rt_sigprocmask     (__NR_SYSCALL_BASE + 175)
     938             : #define __NR_rt_sigpending      (__NR_SYSCALL_BASE + 176)
     939             : #define __NR_rt_sigsuspend      (__NR_SYSCALL_BASE + 179)
     940             : #endif
     941             : #ifndef __NR_pread64
     942             : #define __NR_pread64            (__NR_SYSCALL_BASE + 180)
     943             : #endif
     944             : #ifndef __NR_pwrite64
     945             : #define __NR_pwrite64           (__NR_SYSCALL_BASE + 181)
     946             : #endif
     947             : #ifndef __NR_ugetrlimit
     948             : #define __NR_ugetrlimit         (__NR_SYSCALL_BASE + 191)
     949             : #endif
     950             : #ifndef __NR_stat64
     951             : #define __NR_stat64             (__NR_SYSCALL_BASE + 195)
     952             : #endif
     953             : #ifndef __NR_fstat64
     954             : #define __NR_fstat64            (__NR_SYSCALL_BASE + 197)
     955             : #endif
     956             : #ifndef __NR_setresuid32
     957             : #define __NR_setresuid32        (__NR_SYSCALL_BASE + 208)
     958             : #define __NR_getresuid32        (__NR_SYSCALL_BASE + 209)
     959             : #define __NR_setresgid32        (__NR_SYSCALL_BASE + 210)
     960             : #define __NR_getresgid32        (__NR_SYSCALL_BASE + 211)
     961             : #endif
     962             : #ifndef __NR_setfsuid32
     963             : #define __NR_setfsuid32         (__NR_SYSCALL_BASE + 215)
     964             : #define __NR_setfsgid32         (__NR_SYSCALL_BASE + 216)
     965             : #endif
     966             : #ifndef __NR_getdents64
     967             : #define __NR_getdents64         (__NR_SYSCALL_BASE + 217)
     968             : #endif
     969             : #ifndef __NR_gettid
     970             : #define __NR_gettid             (__NR_SYSCALL_BASE + 224)
     971             : #endif
     972             : #ifndef __NR_readahead
     973             : #define __NR_readahead          (__NR_SYSCALL_BASE + 225)
     974             : #endif
     975             : #ifndef __NR_setxattr
     976             : #define __NR_setxattr           (__NR_SYSCALL_BASE + 226)
     977             : #endif
     978             : #ifndef __NR_lsetxattr
     979             : #define __NR_lsetxattr          (__NR_SYSCALL_BASE + 227)
     980             : #endif
     981             : #ifndef __NR_getxattr
     982             : #define __NR_getxattr           (__NR_SYSCALL_BASE + 229)
     983             : #endif
     984             : #ifndef __NR_lgetxattr
     985             : #define __NR_lgetxattr          (__NR_SYSCALL_BASE + 230)
     986             : #endif
     987             : #ifndef __NR_listxattr
     988             : #define __NR_listxattr          (__NR_SYSCALL_BASE + 232)
     989             : #endif
     990             : #ifndef __NR_llistxattr
     991             : #define __NR_llistxattr         (__NR_SYSCALL_BASE + 233)
     992             : #endif
     993             : #ifndef __NR_tkill
     994             : #define __NR_tkill              (__NR_SYSCALL_BASE + 238)
     995             : #endif
     996             : #ifndef __NR_futex
     997             : #define __NR_futex              (__NR_SYSCALL_BASE + 240)
     998             : #endif
     999             : #ifndef __NR_sched_setaffinity
    1000             : #define __NR_sched_setaffinity  (__NR_SYSCALL_BASE + 241)
    1001             : #define __NR_sched_getaffinity  (__NR_SYSCALL_BASE + 242)
    1002             : #endif
    1003             : #ifndef __NR_set_tid_address
    1004             : #define __NR_set_tid_address    (__NR_SYSCALL_BASE + 256)
    1005             : #endif
    1006             : #ifndef __NR_clock_gettime
    1007             : #define __NR_clock_gettime      (__NR_SYSCALL_BASE + 263)
    1008             : #endif
    1009             : #ifndef __NR_clock_getres
    1010             : #define __NR_clock_getres       (__NR_SYSCALL_BASE + 264)
    1011             : #endif
    1012             : #ifndef __NR_statfs64
    1013             : #define __NR_statfs64           (__NR_SYSCALL_BASE + 266)
    1014             : #endif
    1015             : #ifndef __NR_fstatfs64
    1016             : #define __NR_fstatfs64          (__NR_SYSCALL_BASE + 267)
    1017             : #endif
    1018             : #ifndef __NR_ioprio_set
    1019             : #define __NR_ioprio_set         (__NR_SYSCALL_BASE + 314)
    1020             : #endif
    1021             : #ifndef __NR_ioprio_get
    1022             : #define __NR_ioprio_get         (__NR_SYSCALL_BASE + 315)
    1023             : #endif
    1024             : #ifndef __NR_move_pages
    1025             : #define __NR_move_pages         (__NR_SYSCALL_BASE + 344)
    1026             : #endif
    1027             : #ifndef __NR_getcpu
    1028             : #define __NR_getcpu             (__NR_SYSCALL_BASE + 345)
    1029             : #endif
    1030             : /* End of ARM 3/EABI definitions                                             */
    1031             : #elif defined(__aarch64__)
    1032             : #ifndef __NR_setxattr
    1033             : #define __NR_setxattr             5
    1034             : #endif
    1035             : #ifndef __NR_lsetxattr
    1036             : #define __NR_lsetxattr            6
    1037             : #endif
    1038             : #ifndef __NR_getxattr
    1039             : #define __NR_getxattr             8
    1040             : #endif
    1041             : #ifndef __NR_lgetxattr
    1042             : #define __NR_lgetxattr            9
    1043             : #endif
    1044             : #ifndef __NR_listxattr
    1045             : #define __NR_listxattr           11
    1046             : #endif
    1047             : #ifndef __NR_llistxattr
    1048             : #define __NR_llistxattr          12
    1049             : #endif
    1050             : #ifndef __NR_ioprio_set
    1051             : #define __NR_ioprio_set          30
    1052             : #endif
    1053             : #ifndef __NR_ioprio_get
    1054             : #define __NR_ioprio_get          31
    1055             : #endif
    1056             : #ifndef __NR_unlinkat
    1057             : #define __NR_unlinkat            35
    1058             : #endif
    1059             : #ifndef __NR_fallocate
    1060             : #define __NR_fallocate           47
    1061             : #endif
    1062             : #ifndef __NR_openat
    1063             : #define __NR_openat              56
    1064             : #endif
    1065             : #ifndef __NR_quotactl
    1066             : #define __NR_quotactl            60
    1067             : #endif
    1068             : #ifndef __NR_getdents64
    1069             : #define __NR_getdents64          61
    1070             : #endif
    1071             : #ifndef __NR_getdents
    1072             : #define __NR_getdents            __NR_getdents64
    1073             : #endif
    1074             : #ifndef __NR_pread64
    1075             : #define __NR_pread64             67
    1076             : #endif
    1077             : #ifndef __NR_pwrite64
    1078             : #define __NR_pwrite64            68
    1079             : #endif
    1080             : #ifndef __NR_ppoll
    1081             : #define __NR_ppoll               73
    1082             : #endif
    1083             : #ifndef __NR_readlinkat
    1084             : #define __NR_readlinkat          78
    1085             : #endif
    1086             : #ifndef __NR_newfstatat
    1087             : #define __NR_newfstatat          79
    1088             : #endif
    1089             : #ifndef __NR_set_tid_address
    1090             : #define __NR_set_tid_address     96
    1091             : #endif
    1092             : #ifndef __NR_futex
    1093             : #define __NR_futex               98
    1094             : #endif
    1095             : #ifndef __NR_clock_gettime
    1096             : #define __NR_clock_gettime      113
    1097             : #endif
    1098             : #ifndef __NR_clock_getres
    1099             : #define __NR_clock_getres       114
    1100             : #endif
    1101             : #ifndef __NR_sched_setaffinity
    1102             : #define __NR_sched_setaffinity  122
    1103             : #define __NR_sched_getaffinity  123
    1104             : #endif
    1105             : #ifndef __NR_tkill
    1106             : #define __NR_tkill              130
    1107             : #endif
    1108             : #ifndef __NR_setresuid
    1109             : #define __NR_setresuid          147
    1110             : #define __NR_getresuid          148
    1111             : #define __NR_setresgid          149
    1112             : #define __NR_getresgid          150
    1113             : #endif
    1114             : #ifndef __NR_gettid
    1115             : #define __NR_gettid             178
    1116             : #endif
    1117             : #ifndef __NR_readahead
    1118             : #define __NR_readahead          213
    1119             : #endif
    1120             : #ifndef __NR_fadvise64
    1121             : #define __NR_fadvise64          223
    1122             : #endif
    1123             : #ifndef __NR_move_pages
    1124             : #define __NR_move_pages         239
    1125             : #endif
    1126             : /* End of aarch64 definitions                                                */
    1127             : #elif defined(__x86_64__)
    1128             : #ifndef __NR_pread64
    1129             : #define __NR_pread64             17
    1130             : #endif
    1131             : #ifndef __NR_pwrite64
    1132             : #define __NR_pwrite64            18
    1133             : #endif
    1134             : #ifndef __NR_setresuid
    1135             : #define __NR_setresuid          117
    1136             : #define __NR_getresuid          118
    1137             : #define __NR_setresgid          119
    1138             : #define __NR_getresgid          120
    1139             : #endif
    1140             : #ifndef __NR_quotactl
    1141             : #define __NR_quotactl           179
    1142             : #endif
    1143             : #ifndef __NR_gettid
    1144             : #define __NR_gettid             186
    1145             : #endif
    1146             : #ifndef __NR_readahead
    1147             : #define __NR_readahead          187
    1148             : #endif
    1149             : #ifndef __NR_setxattr
    1150             : #define __NR_setxattr           188
    1151             : #endif
    1152             : #ifndef __NR_lsetxattr
    1153             : #define __NR_lsetxattr          189
    1154             : #endif
    1155             : #ifndef __NR_getxattr
    1156             : #define __NR_getxattr           191
    1157             : #endif
    1158             : #ifndef __NR_lgetxattr
    1159             : #define __NR_lgetxattr          192
    1160             : #endif
    1161             : #ifndef __NR_listxattr
    1162             : #define __NR_listxattr          194
    1163             : #endif
    1164             : #ifndef __NR_llistxattr
    1165             : #define __NR_llistxattr         195
    1166             : #endif
    1167             : #ifndef __NR_tkill
    1168             : #define __NR_tkill              200
    1169             : #endif
    1170             : #ifndef __NR_futex
    1171             : #define __NR_futex              202
    1172             : #endif
    1173             : #ifndef __NR_sched_setaffinity
    1174             : #define __NR_sched_setaffinity  203
    1175             : #define __NR_sched_getaffinity  204
    1176             : #endif
    1177             : #ifndef __NR_getdents64
    1178             : #define __NR_getdents64         217
    1179             : #endif
    1180             : #ifndef __NR_set_tid_address
    1181             : #define __NR_set_tid_address    218
    1182             : #endif
    1183             : #ifndef __NR_fadvise64
    1184             : #define __NR_fadvise64          221
    1185             : #endif
    1186             : #ifndef __NR_clock_gettime
    1187             : #define __NR_clock_gettime      228
    1188             : #endif
    1189             : #ifndef __NR_clock_getres
    1190             : #define __NR_clock_getres       229
    1191             : #endif
    1192             : #ifndef __NR_ioprio_set
    1193             : #define __NR_ioprio_set         251
    1194             : #endif
    1195             : #ifndef __NR_ioprio_get
    1196             : #define __NR_ioprio_get         252
    1197             : #endif
    1198             : #ifndef __NR_openat
    1199             : #define __NR_openat             257
    1200             : #endif
    1201             : #ifndef __NR_newfstatat
    1202             : #define __NR_newfstatat         262
    1203             : #endif
    1204             : #ifndef __NR_unlinkat
    1205             : #define __NR_unlinkat           263
    1206             : #endif
    1207             : #ifndef __NR_move_pages
    1208             : #define __NR_move_pages         279
    1209             : #endif
    1210             : #ifndef __NR_fallocate
    1211             : #define __NR_fallocate          285
    1212             : #endif
    1213             : /* End of x86-64 definitions                                                 */
    1214             : #elif defined(__mips__)
    1215             : #if _MIPS_SIM == _MIPS_SIM_ABI32
    1216             : #ifndef __NR_setresuid
    1217             : #define __NR_setresuid          (__NR_Linux + 185)
    1218             : #define __NR_getresuid          (__NR_Linux + 186)
    1219             : #define __NR_setresgid          (__NR_Linux + 190)
    1220             : #define __NR_getresgid          (__NR_Linux + 191)
    1221             : #endif
    1222             : #ifndef __NR_rt_sigaction
    1223             : #define __NR_rt_sigreturn       (__NR_Linux + 193)
    1224             : #define __NR_rt_sigaction       (__NR_Linux + 194)
    1225             : #define __NR_rt_sigprocmask     (__NR_Linux + 195)
    1226             : #define __NR_rt_sigpending      (__NR_Linux + 196)
    1227             : #define __NR_rt_sigsuspend      (__NR_Linux + 199)
    1228             : #endif
    1229             : #ifndef __NR_pread64
    1230             : #define __NR_pread64            (__NR_Linux + 200)
    1231             : #endif
    1232             : #ifndef __NR_pwrite64
    1233             : #define __NR_pwrite64           (__NR_Linux + 201)
    1234             : #endif
    1235             : #ifndef __NR_stat64
    1236             : #define __NR_stat64             (__NR_Linux + 213)
    1237             : #endif
    1238             : #ifndef __NR_fstat64
    1239             : #define __NR_fstat64            (__NR_Linux + 215)
    1240             : #endif
    1241             : #ifndef __NR_getdents64
    1242             : #define __NR_getdents64         (__NR_Linux + 219)
    1243             : #endif
    1244             : #ifndef __NR_gettid
    1245             : #define __NR_gettid             (__NR_Linux + 222)
    1246             : #endif
    1247             : #ifndef __NR_readahead
    1248             : #define __NR_readahead          (__NR_Linux + 223)
    1249             : #endif
    1250             : #ifndef __NR_setxattr
    1251             : #define __NR_setxattr           (__NR_Linux + 224)
    1252             : #endif
    1253             : #ifndef __NR_lsetxattr
    1254             : #define __NR_lsetxattr          (__NR_Linux + 225)
    1255             : #endif
    1256             : #ifndef __NR_getxattr
    1257             : #define __NR_getxattr           (__NR_Linux + 227)
    1258             : #endif
    1259             : #ifndef __NR_lgetxattr
    1260             : #define __NR_lgetxattr          (__NR_Linux + 228)
    1261             : #endif
    1262             : #ifndef __NR_listxattr
    1263             : #define __NR_listxattr          (__NR_Linux + 230)
    1264             : #endif
    1265             : #ifndef __NR_llistxattr
    1266             : #define __NR_llistxattr         (__NR_Linux + 231)
    1267             : #endif
    1268             : #ifndef __NR_tkill
    1269             : #define __NR_tkill              (__NR_Linux + 236)
    1270             : #endif
    1271             : #ifndef __NR_futex
    1272             : #define __NR_futex              (__NR_Linux + 238)
    1273             : #endif
    1274             : #ifndef __NR_sched_setaffinity
    1275             : #define __NR_sched_setaffinity  (__NR_Linux + 239)
    1276             : #define __NR_sched_getaffinity  (__NR_Linux + 240)
    1277             : #endif
    1278             : #ifndef __NR_set_tid_address
    1279             : #define __NR_set_tid_address    (__NR_Linux + 252)
    1280             : #endif
    1281             : #ifndef __NR_statfs64
    1282             : #define __NR_statfs64           (__NR_Linux + 255)
    1283             : #endif
    1284             : #ifndef __NR_fstatfs64
    1285             : #define __NR_fstatfs64          (__NR_Linux + 256)
    1286             : #endif
    1287             : #ifndef __NR_clock_gettime
    1288             : #define __NR_clock_gettime      (__NR_Linux + 263)
    1289             : #endif
    1290             : #ifndef __NR_clock_getres
    1291             : #define __NR_clock_getres       (__NR_Linux + 264)
    1292             : #endif
    1293             : #ifndef __NR_openat
    1294             : #define __NR_openat             (__NR_Linux + 288)
    1295             : #endif
    1296             : #ifndef __NR_fstatat
    1297             : #define __NR_fstatat            (__NR_Linux + 293)
    1298             : #endif
    1299             : #ifndef __NR_unlinkat
    1300             : #define __NR_unlinkat           (__NR_Linux + 294)
    1301             : #endif
    1302             : #ifndef __NR_move_pages
    1303             : #define __NR_move_pages         (__NR_Linux + 308)
    1304             : #endif
    1305             : #ifndef __NR_getcpu
    1306             : #define __NR_getcpu             (__NR_Linux + 312)
    1307             : #endif
    1308             : #ifndef __NR_ioprio_set
    1309             : #define __NR_ioprio_set         (__NR_Linux + 314)
    1310             : #endif
    1311             : #ifndef __NR_ioprio_get
    1312             : #define __NR_ioprio_get         (__NR_Linux + 315)
    1313             : #endif
    1314             : /* End of MIPS (old 32bit API) definitions */
    1315             : #elif  _MIPS_SIM == _MIPS_SIM_ABI64
    1316             : #ifndef __NR_pread64
    1317             : #define __NR_pread64            (__NR_Linux +  16)
    1318             : #endif
    1319             : #ifndef __NR_pwrite64
    1320             : #define __NR_pwrite64           (__NR_Linux +  17)
    1321             : #endif
    1322             : #ifndef __NR_setresuid
    1323             : #define __NR_setresuid          (__NR_Linux + 115)
    1324             : #define __NR_getresuid          (__NR_Linux + 116)
    1325             : #define __NR_setresgid          (__NR_Linux + 117)
    1326             : #define __NR_getresgid          (__NR_Linux + 118)
    1327             : #endif
    1328             : #ifndef __NR_gettid
    1329             : #define __NR_gettid             (__NR_Linux + 178)
    1330             : #endif
    1331             : #ifndef __NR_readahead
    1332             : #define __NR_readahead          (__NR_Linux + 179)
    1333             : #endif
    1334             : #ifndef __NR_setxattr
    1335             : #define __NR_setxattr           (__NR_Linux + 180)
    1336             : #endif
    1337             : #ifndef __NR_lsetxattr
    1338             : #define __NR_lsetxattr          (__NR_Linux + 181)
    1339             : #endif
    1340             : #ifndef __NR_getxattr
    1341             : #define __NR_getxattr           (__NR_Linux + 183)
    1342             : #endif
    1343             : #ifndef __NR_lgetxattr
    1344             : #define __NR_lgetxattr          (__NR_Linux + 184)
    1345             : #endif
    1346             : #ifndef __NR_listxattr
    1347             : #define __NR_listxattr          (__NR_Linux + 186)
    1348             : #endif
    1349             : #ifndef __NR_llistxattr
    1350             : #define __NR_llistxattr         (__NR_Linux + 187)
    1351             : #endif
    1352             : #ifndef __NR_tkill
    1353             : #define __NR_tkill              (__NR_Linux + 192)
    1354             : #endif
    1355             : #ifndef __NR_futex
    1356             : #define __NR_futex              (__NR_Linux + 194)
    1357             : #endif
    1358             : #ifndef __NR_sched_setaffinity
    1359             : #define __NR_sched_setaffinity  (__NR_Linux + 195)
    1360             : #define __NR_sched_getaffinity  (__NR_Linux + 196)
    1361             : #endif
    1362             : #ifndef __NR_set_tid_address
    1363             : #define __NR_set_tid_address    (__NR_Linux + 212)
    1364             : #endif
    1365             : #ifndef __NR_clock_gettime
    1366             : #define __NR_clock_gettime      (__NR_Linux + 222)
    1367             : #endif
    1368             : #ifndef __NR_clock_getres
    1369             : #define __NR_clock_getres       (__NR_Linux + 223)
    1370             : #endif
    1371             : #ifndef __NR_openat
    1372             : #define __NR_openat             (__NR_Linux + 247)
    1373             : #endif
    1374             : #ifndef __NR_fstatat
    1375             : #define __NR_fstatat            (__NR_Linux + 252)
    1376             : #endif
    1377             : #ifndef __NR_unlinkat
    1378             : #define __NR_unlinkat           (__NR_Linux + 253)
    1379             : #endif
    1380             : #ifndef __NR_move_pages
    1381             : #define __NR_move_pages         (__NR_Linux + 267)
    1382             : #endif
    1383             : #ifndef __NR_getcpu
    1384             : #define __NR_getcpu             (__NR_Linux + 271)
    1385             : #endif
    1386             : #ifndef __NR_ioprio_set
    1387             : #define __NR_ioprio_set         (__NR_Linux + 273)
    1388             : #endif
    1389             : #ifndef __NR_ioprio_get
    1390             : #define __NR_ioprio_get         (__NR_Linux + 274)
    1391             : #endif
    1392             : /* End of MIPS (64bit API) definitions */
    1393             : #else
    1394             : #ifndef __NR_setresuid
    1395             : #define __NR_setresuid          (__NR_Linux + 115)
    1396             : #define __NR_getresuid          (__NR_Linux + 116)
    1397             : #define __NR_setresgid          (__NR_Linux + 117)
    1398             : #define __NR_getresgid          (__NR_Linux + 118)
    1399             : #endif
    1400             : #ifndef __NR_gettid
    1401             : #define __NR_gettid             (__NR_Linux + 178)
    1402             : #endif
    1403             : #ifndef __NR_readahead
    1404             : #define __NR_readahead          (__NR_Linux + 179)
    1405             : #endif
    1406             : #ifndef __NR_setxattr
    1407             : #define __NR_setxattr           (__NR_Linux + 180)
    1408             : #endif
    1409             : #ifndef __NR_lsetxattr
    1410             : #define __NR_lsetxattr          (__NR_Linux + 181)
    1411             : #endif
    1412             : #ifndef __NR_getxattr
    1413             : #define __NR_getxattr           (__NR_Linux + 183)
    1414             : #endif
    1415             : #ifndef __NR_lgetxattr
    1416             : #define __NR_lgetxattr          (__NR_Linux + 184)
    1417             : #endif
    1418             : #ifndef __NR_listxattr
    1419             : #define __NR_listxattr          (__NR_Linux + 186)
    1420             : #endif
    1421             : #ifndef __NR_llistxattr
    1422             : #define __NR_llistxattr         (__NR_Linux + 187)
    1423             : #endif
    1424             : #ifndef __NR_tkill
    1425             : #define __NR_tkill              (__NR_Linux + 192)
    1426             : #endif
    1427             : #ifndef __NR_futex
    1428             : #define __NR_futex              (__NR_Linux + 194)
    1429             : #endif
    1430             : #ifndef __NR_sched_setaffinity
    1431             : #define __NR_sched_setaffinity  (__NR_Linux + 195)
    1432             : #define __NR_sched_getaffinity  (__NR_Linux + 196)
    1433             : #endif
    1434             : #ifndef __NR_set_tid_address
    1435             : #define __NR_set_tid_address    (__NR_Linux + 213)
    1436             : #endif
    1437             : #ifndef __NR_statfs64
    1438             : #define __NR_statfs64           (__NR_Linux + 217)
    1439             : #endif
    1440             : #ifndef __NR_fstatfs64
    1441             : #define __NR_fstatfs64          (__NR_Linux + 218)
    1442             : #endif
    1443             : #ifndef __NR_clock_gettime
    1444             : #define __NR_clock_gettime      (__NR_Linux + 226)
    1445             : #endif
    1446             : #ifndef __NR_clock_getres
    1447             : #define __NR_clock_getres       (__NR_Linux + 227)
    1448             : #endif
    1449             : #ifndef __NR_openat
    1450             : #define __NR_openat             (__NR_Linux + 251)
    1451             : #endif
    1452             : #ifndef __NR_fstatat
    1453             : #define __NR_fstatat            (__NR_Linux + 256)
    1454             : #endif
    1455             : #ifndef __NR_unlinkat
    1456             : #define __NR_unlinkat           (__NR_Linux + 257)
    1457             : #endif
    1458             : #ifndef __NR_move_pages
    1459             : #define __NR_move_pages         (__NR_Linux + 271)
    1460             : #endif
    1461             : #ifndef __NR_getcpu
    1462             : #define __NR_getcpu             (__NR_Linux + 275)
    1463             : #endif
    1464             : #ifndef __NR_ioprio_set
    1465             : #define __NR_ioprio_set         (__NR_Linux + 277)
    1466             : #endif
    1467             : #ifndef __NR_ioprio_get
    1468             : #define __NR_ioprio_get         (__NR_Linux + 278)
    1469             : #endif
    1470             : /* End of MIPS (new 32bit API) definitions                                   */
    1471             : #endif
    1472             : /* End of MIPS definitions                                                   */
    1473             : #elif defined(__PPC__)
    1474             : #ifndef __NR_setfsuid
    1475             : #define __NR_setfsuid           138
    1476             : #define __NR_setfsgid           139
    1477             : #endif
    1478             : #ifndef __NR_setresuid
    1479             : #define __NR_setresuid          164
    1480             : #define __NR_getresuid          165
    1481             : #define __NR_setresgid          169
    1482             : #define __NR_getresgid          170
    1483             : #endif
    1484             : #ifndef __NR_rt_sigaction
    1485             : #define __NR_rt_sigreturn       172
    1486             : #define __NR_rt_sigaction       173
    1487             : #define __NR_rt_sigprocmask     174
    1488             : #define __NR_rt_sigpending      175
    1489             : #define __NR_rt_sigsuspend      178
    1490             : #endif
    1491             : #ifndef __NR_pread64
    1492             : #define __NR_pread64            179
    1493             : #endif
    1494             : #ifndef __NR_pwrite64
    1495             : #define __NR_pwrite64           180
    1496             : #endif
    1497             : #ifndef __NR_ugetrlimit
    1498             : #define __NR_ugetrlimit         190
    1499             : #endif
    1500             : #ifndef __NR_readahead
    1501             : #define __NR_readahead          191
    1502             : #endif
    1503             : #ifndef __NR_stat64
    1504             : #define __NR_stat64             195
    1505             : #endif
    1506             : #ifndef __NR_fstat64
    1507             : #define __NR_fstat64            197
    1508             : #endif
    1509             : #ifndef __NR_getdents64
    1510             : #define __NR_getdents64         202
    1511             : #endif
    1512             : #ifndef __NR_gettid
    1513             : #define __NR_gettid             207
    1514             : #endif
    1515             : #ifndef __NR_tkill
    1516             : #define __NR_tkill              208
    1517             : #endif
    1518             : #ifndef __NR_setxattr
    1519             : #define __NR_setxattr           209
    1520             : #endif
    1521             : #ifndef __NR_lsetxattr
    1522             : #define __NR_lsetxattr          210
    1523             : #endif
    1524             : #ifndef __NR_getxattr
    1525             : #define __NR_getxattr           212
    1526             : #endif
    1527             : #ifndef __NR_lgetxattr
    1528             : #define __NR_lgetxattr          213
    1529             : #endif
    1530             : #ifndef __NR_listxattr
    1531             : #define __NR_listxattr          215
    1532             : #endif
    1533             : #ifndef __NR_llistxattr
    1534             : #define __NR_llistxattr         216
    1535             : #endif
    1536             : #ifndef __NR_futex
    1537             : #define __NR_futex              221
    1538             : #endif
    1539             : #ifndef __NR_sched_setaffinity
    1540             : #define __NR_sched_setaffinity  222
    1541             : #define __NR_sched_getaffinity  223
    1542             : #endif
    1543             : #ifndef __NR_set_tid_address
    1544             : #define __NR_set_tid_address    232
    1545             : #endif
    1546             : #ifndef __NR_clock_gettime
    1547             : #define __NR_clock_gettime      246
    1548             : #endif
    1549             : #ifndef __NR_clock_getres
    1550             : #define __NR_clock_getres       247
    1551             : #endif
    1552             : #ifndef __NR_statfs64
    1553             : #define __NR_statfs64           252
    1554             : #endif
    1555             : #ifndef __NR_fstatfs64
    1556             : #define __NR_fstatfs64          253
    1557             : #endif
    1558             : #ifndef __NR_fadvise64_64
    1559             : #define __NR_fadvise64_64       254
    1560             : #endif
    1561             : #ifndef __NR_ioprio_set
    1562             : #define __NR_ioprio_set         273
    1563             : #endif
    1564             : #ifndef __NR_ioprio_get
    1565             : #define __NR_ioprio_get         274
    1566             : #endif
    1567             : #ifndef __NR_openat
    1568             : #define __NR_openat             286
    1569             : #endif
    1570             : #ifndef __NR_fstatat64
    1571             : #define __NR_fstatat64          291
    1572             : #endif
    1573             : #ifndef __NR_unlinkat
    1574             : #define __NR_unlinkat           292
    1575             : #endif
    1576             : #ifndef __NR_move_pages
    1577             : #define __NR_move_pages         301
    1578             : #endif
    1579             : #ifndef __NR_getcpu
    1580             : #define __NR_getcpu             302
    1581             : #endif
    1582             : /* End of powerpc defininitions                                              */
    1583             : #elif defined(__s390__)
    1584             : #ifndef __NR_quotactl
    1585             : #define __NR_quotactl           131
    1586             : #endif
    1587             : #ifndef __NR_rt_sigreturn
    1588             : #define __NR_rt_sigreturn       173
    1589             : #endif
    1590             : #ifndef __NR_rt_sigaction
    1591             : #define __NR_rt_sigaction       174
    1592             : #endif
    1593             : #ifndef __NR_rt_sigprocmask
    1594             : #define __NR_rt_sigprocmask     175
    1595             : #endif
    1596             : #ifndef __NR_rt_sigpending
    1597             : #define __NR_rt_sigpending      176
    1598             : #endif
    1599             : #ifndef __NR_rt_sigsuspend
    1600             : #define __NR_rt_sigsuspend      179
    1601             : #endif
    1602             : #ifndef __NR_pread64
    1603             : #define __NR_pread64            180
    1604             : #endif
    1605             : #ifndef __NR_pwrite64
    1606             : #define __NR_pwrite64           181
    1607             : #endif
    1608             : #ifndef __NR_getdents64
    1609             : #define __NR_getdents64         220
    1610             : #endif
    1611             : #ifndef __NR_readahead
    1612             : #define __NR_readahead          222
    1613             : #endif
    1614             : #ifndef __NR_setxattr
    1615             : #define __NR_setxattr           224
    1616             : #endif
    1617             : #ifndef __NR_lsetxattr
    1618             : #define __NR_lsetxattr          225
    1619             : #endif
    1620             : #ifndef __NR_getxattr
    1621             : #define __NR_getxattr           227
    1622             : #endif
    1623             : #ifndef __NR_lgetxattr
    1624             : #define __NR_lgetxattr          228
    1625             : #endif
    1626             : #ifndef __NR_listxattr
    1627             : #define __NR_listxattr          230
    1628             : #endif
    1629             : #ifndef __NR_llistxattr
    1630             : #define __NR_llistxattr         231
    1631             : #endif
    1632             : #ifndef __NR_gettid
    1633             : #define __NR_gettid             236
    1634             : #endif
    1635             : #ifndef __NR_tkill
    1636             : #define __NR_tkill              237
    1637             : #endif
    1638             : #ifndef __NR_futex
    1639             : #define __NR_futex              238
    1640             : #endif
    1641             : #ifndef __NR_sched_setaffinity
    1642             : #define __NR_sched_setaffinity  239
    1643             : #endif
    1644             : #ifndef __NR_sched_getaffinity
    1645             : #define __NR_sched_getaffinity  240
    1646             : #endif
    1647             : #ifndef __NR_set_tid_address
    1648             : #define __NR_set_tid_address    252
    1649             : #endif
    1650             : #ifndef __NR_clock_gettime
    1651             : #define __NR_clock_gettime      260
    1652             : #endif
    1653             : #ifndef __NR_clock_getres
    1654             : #define __NR_clock_getres       261
    1655             : #endif
    1656             : #ifndef __NR_statfs64
    1657             : #define __NR_statfs64           265
    1658             : #endif
    1659             : #ifndef __NR_fstatfs64
    1660             : #define __NR_fstatfs64          266
    1661             : #endif
    1662             : #ifndef __NR_ioprio_set
    1663             : #define __NR_ioprio_set         282
    1664             : #endif
    1665             : #ifndef __NR_ioprio_get
    1666             : #define __NR_ioprio_get         283
    1667             : #endif
    1668             : #ifndef __NR_openat
    1669             : #define __NR_openat             288
    1670             : #endif
    1671             : #ifndef __NR_unlinkat
    1672             : #define __NR_unlinkat           294
    1673             : #endif
    1674             : #ifndef __NR_move_pages
    1675             : #define __NR_move_pages         310
    1676             : #endif
    1677             : #ifndef __NR_getcpu
    1678             : #define __NR_getcpu             311
    1679             : #endif
    1680             : #ifndef __NR_fallocate
    1681             : #define __NR_fallocate          314
    1682             : #endif
    1683             : /* Some syscalls are named/numbered differently between s390 and s390x. */
    1684             : #ifdef __s390x__
    1685             : # ifndef __NR_getrlimit
    1686             : # define __NR_getrlimit          191
    1687             : # endif
    1688             : # ifndef __NR_setresuid
    1689             : # define __NR_setresuid          208
    1690             : # endif
    1691             : # ifndef __NR_getresuid
    1692             : # define __NR_getresuid          209
    1693             : # endif
    1694             : # ifndef __NR_setresgid
    1695             : # define __NR_setresgid          210
    1696             : # endif
    1697             : # ifndef __NR_getresgid
    1698             : # define __NR_getresgid          211
    1699             : # endif
    1700             : # ifndef __NR_setfsuid
    1701             : # define __NR_setfsuid           215
    1702             : # endif
    1703             : # ifndef __NR_setfsgid
    1704             : # define __NR_setfsgid           216
    1705             : # endif
    1706             : # ifndef __NR_fadvise64
    1707             : # define __NR_fadvise64          253
    1708             : # endif
    1709             : # ifndef __NR_newfstatat
    1710             : # define __NR_newfstatat         293
    1711             : # endif
    1712             : #else /* __s390x__ */
    1713             : # ifndef __NR_getrlimit
    1714             : # define __NR_getrlimit          76
    1715             : # endif
    1716             : # ifndef __NR_setfsuid
    1717             : # define __NR_setfsuid           138
    1718             : # endif
    1719             : # ifndef __NR_setfsgid
    1720             : # define __NR_setfsgid           139
    1721             : # endif
    1722             : # ifndef __NR_setresuid
    1723             : # define __NR_setresuid          164
    1724             : # endif
    1725             : # ifndef __NR_getresuid
    1726             : # define __NR_getresuid          165
    1727             : # endif
    1728             : # ifndef __NR_setresgid
    1729             : # define __NR_setresgid          170
    1730             : # endif
    1731             : # ifndef __NR_getresgid
    1732             : # define __NR_getresgid          171
    1733             : # endif
    1734             : # ifndef __NR_ugetrlimit
    1735             : # define __NR_ugetrlimit         191
    1736             : # endif
    1737             : # ifndef __NR_mmap2
    1738             : # define __NR_mmap2              192
    1739             : # endif
    1740             : # ifndef __NR_setresuid32
    1741             : # define __NR_setresuid32        208
    1742             : # endif
    1743             : # ifndef __NR_getresuid32
    1744             : # define __NR_getresuid32        209
    1745             : # endif
    1746             : # ifndef __NR_setresgid32
    1747             : # define __NR_setresgid32        210
    1748             : # endif
    1749             : # ifndef __NR_getresgid32
    1750             : # define __NR_getresgid32        211
    1751             : # endif
    1752             : # ifndef __NR_setfsuid32
    1753             : # define __NR_setfsuid32         215
    1754             : # endif
    1755             : # ifndef __NR_setfsgid32
    1756             : # define __NR_setfsgid32         216
    1757             : # endif
    1758             : # ifndef __NR_fadvise64_64
    1759             : # define __NR_fadvise64_64       264
    1760             : # endif
    1761             : # ifndef __NR_fstatat64
    1762             : # define __NR_fstatat64          293
    1763             : # endif
    1764             : #endif /* __s390__ */
    1765             : /* End of s390/s390x definitions                                             */
    1766             : #endif
    1767             : 
    1768             : 
    1769             : /* After forking, we must make sure to only call system calls.               */
    1770             : #if defined(__BOUNDED_POINTERS__)
    1771             :   #error "Need to port invocations of syscalls for bounded ptrs"
    1772             : #else
    1773             :   /* The core dumper and the thread lister get executed after threads
    1774             :    * have been suspended. As a consequence, we cannot call any functions
    1775             :    * that acquire locks. Unfortunately, libc wraps most system calls
    1776             :    * (e.g. in order to implement pthread_atfork, and to make calls
    1777             :    * cancellable), which means we cannot call these functions. Instead,
    1778             :    * we have to call syscall() directly.
    1779             :    */
    1780             :   #undef LSS_ERRNO
    1781             :   #ifdef SYS_ERRNO
    1782             :     /* Allow the including file to override the location of errno. This can
    1783             :      * be useful when using clone() with the CLONE_VM option.
    1784             :      */
    1785             :     #define LSS_ERRNO SYS_ERRNO
    1786             :   #else
    1787             :     #define LSS_ERRNO errno
    1788             :   #endif
    1789             : 
    1790             :   #undef LSS_INLINE
    1791             :   #ifdef SYS_INLINE
    1792             :     #define LSS_INLINE SYS_INLINE
    1793             :   #else
    1794             :     #define LSS_INLINE static inline
    1795             :   #endif
    1796             : 
    1797             :   /* Allow the including file to override the prefix used for all new
    1798             :    * system calls. By default, it will be set to "sys_".
    1799             :    */
    1800             :   #undef LSS_NAME
    1801             :   #ifndef SYS_PREFIX
    1802             :     #define LSS_NAME(name) sys_##name
    1803             :   #elif defined(SYS_PREFIX) && SYS_PREFIX < 0
    1804             :     #define LSS_NAME(name) name
    1805             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 0
    1806             :     #define LSS_NAME(name) sys0_##name
    1807             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 1
    1808             :     #define LSS_NAME(name) sys1_##name
    1809             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 2
    1810             :     #define LSS_NAME(name) sys2_##name
    1811             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 3
    1812             :     #define LSS_NAME(name) sys3_##name
    1813             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 4
    1814             :     #define LSS_NAME(name) sys4_##name
    1815             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 5
    1816             :     #define LSS_NAME(name) sys5_##name
    1817             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 6
    1818             :     #define LSS_NAME(name) sys6_##name
    1819             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 7
    1820             :     #define LSS_NAME(name) sys7_##name
    1821             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 8
    1822             :     #define LSS_NAME(name) sys8_##name
    1823             :   #elif defined(SYS_PREFIX) && SYS_PREFIX == 9
    1824             :     #define LSS_NAME(name) sys9_##name
    1825             :   #endif
    1826             : 
    1827             :   #undef  LSS_RETURN
    1828             :   #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) \
    1829             :        || defined(__ARM_EABI__) || defined(__aarch64__) || defined(__s390__))
    1830             :   /* Failing system calls return a negative result in the range of
    1831             :    * -1..-4095. These are "errno" values with the sign inverted.
    1832             :    */
    1833             :   #define LSS_RETURN(type, res)                                               \
    1834             :     do {                                                                      \
    1835             :       if ((unsigned long)(res) >= (unsigned long)(-4095)) {                   \
    1836             :         LSS_ERRNO = -(res);                                                   \
    1837             :         res = -1;                                                             \
    1838             :       }                                                                       \
    1839             :       return (type) (res);                                                    \
    1840             :     } while (0)
    1841             :   #elif defined(__mips__)
    1842             :   /* On MIPS, failing system calls return -1, and set errno in a
    1843             :    * separate CPU register.
    1844             :    */
    1845             :   #define LSS_RETURN(type, res, err)                                          \
    1846             :     do {                                                                      \
    1847             :       if (err) {                                                              \
    1848             :         unsigned long __errnovalue = (res);                                   \
    1849             :         LSS_ERRNO = __errnovalue;                                             \
    1850             :         res = -1;                                                             \
    1851             :       }                                                                       \
    1852             :       return (type) (res);                                                    \
    1853             :     } while (0)
    1854             :   #elif defined(__PPC__)
    1855             :   /* On PPC, failing system calls return -1, and set errno in a
    1856             :    * separate CPU register. See linux/unistd.h.
    1857             :    */
    1858             :   #define LSS_RETURN(type, res, err)                                          \
    1859             :    do {                                                                       \
    1860             :      if (err & 0x10000000 ) {                                                 \
    1861             :        LSS_ERRNO = (res);                                                     \
    1862             :        res = -1;                                                              \
    1863             :      }                                                                        \
    1864             :      return (type) (res);                                                     \
    1865             :    } while (0)
    1866             :   #endif
    1867             :   #if defined(__i386__)
    1868             :     /* In PIC mode (e.g. when building shared libraries), gcc for i386
    1869             :      * reserves ebx. Unfortunately, most distribution ship with implementations
    1870             :      * of _syscallX() which clobber ebx.
    1871             :      * Also, most definitions of _syscallX() neglect to mark "memory" as being
    1872             :      * clobbered. This causes problems with compilers, that do a better job
    1873             :      * at optimizing across __asm__ calls.
    1874             :      * So, we just have to redefine all of the _syscallX() macros.
    1875             :      */
    1876             :     #undef LSS_ENTRYPOINT
    1877             :     #ifdef SYS_SYSCALL_ENTRYPOINT
    1878             :     static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
    1879             :       void (**entrypoint)(void);
    1880             :       asm volatile(".bss\n"
    1881             :                    ".align 8\n"
    1882             :                    ".globl " SYS_SYSCALL_ENTRYPOINT "\n"
    1883             :                    ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"
    1884             :                    ".previous\n"
    1885             :                    /* This logically does 'lea "SYS_SYSCALL_ENTRYPOINT", %0' */
    1886             :                    "call 0f\n"
    1887             :                  "0:pop  %0\n"
    1888             :                    "add  $_GLOBAL_OFFSET_TABLE_+[.-0b], %0\n"
    1889             :                    "mov  " SYS_SYSCALL_ENTRYPOINT "@GOT(%0), %0\n"
    1890             :                    : "=r"(entrypoint));
    1891             :       return entrypoint;
    1892             :     }
    1893             : 
    1894             :     #define LSS_ENTRYPOINT ".bss\n"                                           \
    1895             :                            ".align 8\n"                                       \
    1896             :                            ".globl " SYS_SYSCALL_ENTRYPOINT "\n"              \
    1897             :                            ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"         \
    1898             :                            ".previous\n"                                      \
    1899             :                            /* Check the SYS_SYSCALL_ENTRYPOINT vector      */ \
    1900             :                            "push %%eax\n"                                     \
    1901             :                            "call 10000f\n"                                    \
    1902             :                      "10000:pop  %%eax\n"                                     \
    1903             :                            "add  $_GLOBAL_OFFSET_TABLE_+[.-10000b], %%eax\n"  \
    1904             :                            "mov  " SYS_SYSCALL_ENTRYPOINT                     \
    1905             :                                  "@GOT(%%eax), %%eax\n"                       \
    1906             :                            "mov  0(%%eax), %%eax\n"                           \
    1907             :                            "test %%eax, %%eax\n"                              \
    1908             :                            "jz   10002f\n"                                    \
    1909             :                            "push %%eax\n"                                     \
    1910             :                            "call 10001f\n"                                    \
    1911             :                      "10001:pop  %%eax\n"                                     \
    1912             :                            "add  $(10003f-10001b), %%eax\n"                   \
    1913             :                            "xchg 4(%%esp), %%eax\n"                           \
    1914             :                            "ret\n"                                            \
    1915             :                      "10002:pop  %%eax\n"                                     \
    1916             :                            "int $0x80\n"                                      \
    1917             :                      "10003:\n"
    1918             :     #else
    1919             :     #define LSS_ENTRYPOINT "int $0x80\n"
    1920             :     #endif
    1921             :     #undef  LSS_BODY
    1922             :     #define LSS_BODY(type,args...)                                            \
    1923             :       long __res;                                                             \
    1924             :       __asm__ __volatile__("push %%ebx\n"                                     \
    1925             :                            "movl %2,%%ebx\n"                                  \
    1926             :                            LSS_ENTRYPOINT                                     \
    1927             :                            "pop %%ebx"                                        \
    1928             :                            args                                               \
    1929             :                            : "esp", "memory");                                \
    1930             :       LSS_RETURN(type,__res)
    1931             :     #undef  _syscall0
    1932             :     #define _syscall0(type,name)                                              \
    1933             :       type LSS_NAME(name)(void) {                                             \
    1934             :         long __res;                                                           \
    1935             :         __asm__ volatile(LSS_ENTRYPOINT                                       \
    1936             :                          : "=a" (__res)                                       \
    1937             :                          : "0" (__NR_##name)                                  \
    1938             :                          : "esp", "memory");                                  \
    1939             :         LSS_RETURN(type,__res);                                               \
    1940             :       }
    1941             :     #undef  _syscall1
    1942             :     #define _syscall1(type,name,type1,arg1)                                   \
    1943             :       type LSS_NAME(name)(type1 arg1) {                                       \
    1944             :         LSS_BODY(type,                                                        \
    1945             :              : "=a" (__res)                                                   \
    1946             :              : "0" (__NR_##name), "ri" ((long)(arg1)));                       \
    1947             :       }
    1948             :     #undef  _syscall2
    1949             :     #define _syscall2(type,name,type1,arg1,type2,arg2)                        \
    1950             :       type LSS_NAME(name)(type1 arg1,type2 arg2) {                            \
    1951             :         LSS_BODY(type,                                                        \
    1952             :              : "=a" (__res)                                                   \
    1953             :              : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2)));    \
    1954             :       }
    1955             :     #undef  _syscall3
    1956             :     #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3)             \
    1957             :       type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) {                 \
    1958             :         LSS_BODY(type,                                                        \
    1959             :              : "=a" (__res)                                                   \
    1960             :              : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)),    \
    1961             :                "d" ((long)(arg3)));                                           \
    1962             :       }
    1963             :     #undef  _syscall4
    1964             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    1965             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    1966             :         LSS_BODY(type,                                                        \
    1967             :              : "=a" (__res)                                                   \
    1968             :              : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)),    \
    1969             :                "d" ((long)(arg3)),"S" ((long)(arg4)));                        \
    1970             :       }
    1971             :     #undef  _syscall5
    1972             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    1973             :                       type5,arg5)                                             \
    1974             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    1975             :                           type5 arg5) {                                       \
    1976             :         long __res;                                                           \
    1977             :         __asm__ __volatile__("push %%ebx\n"                                   \
    1978             :                              "movl %2,%%ebx\n"                                \
    1979             :                              "movl %1,%%eax\n"                                \
    1980             :                              LSS_ENTRYPOINT                                   \
    1981             :                              "pop  %%ebx"                                     \
    1982             :                              : "=a" (__res)                                   \
    1983             :                              : "i" (__NR_##name), "ri" ((long)(arg1)),        \
    1984             :                                "c" ((long)(arg2)), "d" ((long)(arg3)),        \
    1985             :                                "S" ((long)(arg4)), "D" ((long)(arg5))         \
    1986             :                              : "esp", "memory");                              \
    1987             :         LSS_RETURN(type,__res);                                               \
    1988             :       }
    1989             :     #undef  _syscall6
    1990             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    1991             :                       type5,arg5,type6,arg6)                                  \
    1992             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    1993             :                           type5 arg5, type6 arg6) {                           \
    1994             :         long __res;                                                           \
    1995             :         struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 };   \
    1996             :         __asm__ __volatile__("push %%ebp\n"                                   \
    1997             :                              "push %%ebx\n"                                   \
    1998             :                              "movl 4(%2),%%ebp\n"                             \
    1999             :                              "movl 0(%2), %%ebx\n"                            \
    2000             :                              "movl %1,%%eax\n"                                \
    2001             :                              LSS_ENTRYPOINT                                   \
    2002             :                              "pop  %%ebx\n"                                   \
    2003             :                              "pop  %%ebp"                                     \
    2004             :                              : "=a" (__res)                                   \
    2005             :                              : "i" (__NR_##name),  "0" ((long)(&__s)),        \
    2006             :                                "c" ((long)(arg2)), "d" ((long)(arg3)),        \
    2007             :                                "S" ((long)(arg4)), "D" ((long)(arg5))         \
    2008             :                              : "esp", "memory");                              \
    2009             :         LSS_RETURN(type,__res);                                               \
    2010             :       }
    2011             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2012             :                                    int flags, void *arg, int *parent_tidptr,
    2013             :                                    void *newtls, int *child_tidptr) {
    2014             :       long __res;
    2015             :       __asm__ __volatile__(/* if (fn == NULL)
    2016             :                             *   return -EINVAL;
    2017             :                             */
    2018             :                            "movl   %3,%%ecx\n"
    2019             :                            "jecxz  1f\n"
    2020             : 
    2021             :                            /* if (child_stack == NULL)
    2022             :                             *   return -EINVAL;
    2023             :                             */
    2024             :                            "movl   %4,%%ecx\n"
    2025             :                            "jecxz  1f\n"
    2026             : 
    2027             :                            /* Set up alignment of the child stack:
    2028             :                             * child_stack = (child_stack & ~0xF) - 20;
    2029             :                             */
    2030             :                            "andl   $-16,%%ecx\n"
    2031             :                            "subl   $20,%%ecx\n"
    2032             : 
    2033             :                            /* Push "arg" and "fn" onto the stack that will be
    2034             :                             * used by the child.
    2035             :                             */
    2036             :                            "movl   %6,%%eax\n"
    2037             :                            "movl   %%eax,4(%%ecx)\n"
    2038             :                            "movl   %3,%%eax\n"
    2039             :                            "movl   %%eax,(%%ecx)\n"
    2040             : 
    2041             :                            /* %eax = syscall(%eax = __NR_clone,
    2042             :                             *                %ebx = flags,
    2043             :                             *                %ecx = child_stack,
    2044             :                             *                %edx = parent_tidptr,
    2045             :                             *                %esi = newtls,
    2046             :                             *                %edi = child_tidptr)
    2047             :                             * Also, make sure that %ebx gets preserved as it is
    2048             :                             * used in PIC mode.
    2049             :                             */
    2050             :                            "movl   %8,%%esi\n"
    2051             :                            "movl   %7,%%edx\n"
    2052             :                            "movl   %5,%%eax\n"
    2053             :                            "movl   %9,%%edi\n"
    2054             :                            "pushl  %%ebx\n"
    2055             :                            "movl   %%eax,%%ebx\n"
    2056             :                            "movl   %2,%%eax\n"
    2057             :                            LSS_ENTRYPOINT
    2058             : 
    2059             :                            /* In the parent: restore %ebx
    2060             :                             * In the child:  move "fn" into %ebx
    2061             :                             */
    2062             :                            "popl   %%ebx\n"
    2063             : 
    2064             :                            /* if (%eax != 0)
    2065             :                             *   return %eax;
    2066             :                             */
    2067             :                            "test   %%eax,%%eax\n"
    2068             :                            "jnz    1f\n"
    2069             : 
    2070             :                            /* In the child, now. Terminate frame pointer chain.
    2071             :                             */
    2072             :                            "movl   $0,%%ebp\n"
    2073             : 
    2074             :                            /* Call "fn". "arg" is already on the stack.
    2075             :                             */
    2076             :                            "call   *%%ebx\n"
    2077             : 
    2078             :                            /* Call _exit(%ebx). Unfortunately older versions
    2079             :                             * of gcc restrict the number of arguments that can
    2080             :                             * be passed to asm(). So, we need to hard-code the
    2081             :                             * system call number.
    2082             :                             */
    2083             :                            "movl   %%eax,%%ebx\n"
    2084             :                            "movl   $1,%%eax\n"
    2085             :                            LSS_ENTRYPOINT
    2086             : 
    2087             :                            /* Return to parent.
    2088             :                             */
    2089             :                          "1:\n"
    2090             :                            : "=a" (__res)
    2091             :                            : "0"(-EINVAL), "i"(__NR_clone),
    2092             :                              "m"(fn), "m"(child_stack), "m"(flags), "m"(arg),
    2093             :                              "m"(parent_tidptr), "m"(newtls), "m"(child_tidptr)
    2094             :                            : "esp", "memory", "ecx", "edx", "esi", "edi");
    2095             :       LSS_RETURN(int, __res);
    2096             :     }
    2097             : 
    2098             :     LSS_INLINE _syscall1(int, set_thread_area, void *, u)
    2099             :     LSS_INLINE _syscall1(int, get_thread_area, void *, u)
    2100             : 
    2101             :     LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
    2102             :       /* On i386, the kernel does not know how to return from a signal
    2103             :        * handler. Instead, it relies on user space to provide a
    2104             :        * restorer function that calls the {rt_,}sigreturn() system call.
    2105             :        * Unfortunately, we cannot just reference the glibc version of this
    2106             :        * function, as glibc goes out of its way to make it inaccessible.
    2107             :        */
    2108             :       void (*res)(void);
    2109             :       __asm__ __volatile__("call   2f\n"
    2110             :                          "0:.align 16\n"
    2111             :                          "1:movl   %1,%%eax\n"
    2112             :                            LSS_ENTRYPOINT
    2113             :                          "2:popl   %0\n"
    2114             :                            "addl   $(1b-0b),%0\n"
    2115             :                            : "=a" (res)
    2116             :                            : "i"  (__NR_rt_sigreturn));
    2117             :       return res;
    2118             :     }
    2119             :     LSS_INLINE void (*LSS_NAME(restore)(void))(void) {
    2120             :       /* On i386, the kernel does not know how to return from a signal
    2121             :        * handler. Instead, it relies on user space to provide a
    2122             :        * restorer function that calls the {rt_,}sigreturn() system call.
    2123             :        * Unfortunately, we cannot just reference the glibc version of this
    2124             :        * function, as glibc goes out of its way to make it inaccessible.
    2125             :        */
    2126             :       void (*res)(void);
    2127             :       __asm__ __volatile__("call   2f\n"
    2128             :                          "0:.align 16\n"
    2129             :                          "1:pop    %%eax\n"
    2130             :                            "movl   %1,%%eax\n"
    2131             :                            LSS_ENTRYPOINT
    2132             :                          "2:popl   %0\n"
    2133             :                            "addl   $(1b-0b),%0\n"
    2134             :                            : "=a" (res)
    2135             :                            : "i"  (__NR_sigreturn));
    2136             :       return res;
    2137             :     }
    2138             :   #elif defined(__x86_64__)
    2139             :     /* There are no known problems with any of the _syscallX() macros
    2140             :      * currently shipping for x86_64, but we still need to be able to define
    2141             :      * our own version so that we can override the location of the errno
    2142             :      * location (e.g. when using the clone() system call with the CLONE_VM
    2143             :      * option).
    2144             :      */
    2145             :     #undef LSS_ENTRYPOINT
    2146             :     #ifdef SYS_SYSCALL_ENTRYPOINT
    2147             :     static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
    2148             :       void (**entrypoint)(void);
    2149             :       asm volatile(".bss\n"
    2150             :                    ".align 8\n"
    2151             :                    ".globl " SYS_SYSCALL_ENTRYPOINT "\n"
    2152             :                    ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"
    2153             :                    ".previous\n"
    2154             :                    "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %0\n"
    2155             :                    : "=r"(entrypoint));
    2156             :       return entrypoint;
    2157             :     }
    2158             : 
    2159             :     #define LSS_ENTRYPOINT                                                    \
    2160             :               ".bss\n"                                                        \
    2161             :               ".align 8\n"                                                    \
    2162             :               ".globl " SYS_SYSCALL_ENTRYPOINT "\n"                           \
    2163             :               ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n"                      \
    2164             :               ".previous\n"                                                   \
    2165             :               "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %%rcx\n"       \
    2166             :               "mov  0(%%rcx), %%rcx\n"                                        \
    2167             :               "test %%rcx, %%rcx\n"                                           \
    2168             :               "jz   10001f\n"                                                 \
    2169             :               "call *%%rcx\n"                                                 \
    2170             :               "jmp  10002f\n"                                                 \
    2171             :         "10001:syscall\n"                                                     \
    2172             :         "10002:\n"
    2173             : 
    2174             :     #else
    2175             :     #define LSS_ENTRYPOINT "syscall\n"
    2176             :     #endif
    2177             : 
    2178             :     /* The x32 ABI has 32 bit longs, but the syscall interface is 64 bit.
    2179             :      * We need to explicitly cast to an unsigned 64 bit type to avoid implicit
    2180             :      * sign extension.  We can't cast pointers directly because those are
    2181             :      * 32 bits, and gcc will dump ugly warnings about casting from a pointer
    2182             :      * to an integer of a different size.
    2183             :      */
    2184             :     #undef  LSS_SYSCALL_ARG
    2185             :     #define LSS_SYSCALL_ARG(a) ((uint64_t)(uintptr_t)(a))
    2186             :     #undef  _LSS_RETURN
    2187             :     #define _LSS_RETURN(type, res, cast)                                      \
    2188             :       do {                                                                    \
    2189             :         if ((uint64_t)(res) >= (uint64_t)(-4095)) {                           \
    2190             :           LSS_ERRNO = -(res);                                                 \
    2191             :           res = -1;                                                           \
    2192             :         }                                                                     \
    2193             :         return (type)(cast)(res);                                             \
    2194             :       } while (0)
    2195             :     #undef  LSS_RETURN
    2196             :     #define LSS_RETURN(type, res) _LSS_RETURN(type, res, uintptr_t)
    2197             : 
    2198             :     #undef  _LSS_BODY
    2199             :     #define _LSS_BODY(nr, type, name, cast, ...)                              \
    2200             :           long long __res;                                                    \
    2201             :           __asm__ __volatile__(LSS_BODY_ASM##nr LSS_ENTRYPOINT                \
    2202             :             : "=a" (__res)                                                    \
    2203             :             : "0" (__NR_##name) LSS_BODY_ARG##nr(__VA_ARGS__)                 \
    2204             :             : LSS_BODY_CLOBBER##nr "r11", "rcx", "memory");                   \
    2205             :           _LSS_RETURN(type, __res, cast)
    2206             :     #undef  LSS_BODY
    2207             :     #define LSS_BODY(nr, type, name, args...) \
    2208             :       _LSS_BODY(nr, type, name, uintptr_t, ## args)
    2209             : 
    2210             :     #undef  LSS_BODY_ASM0
    2211             :     #undef  LSS_BODY_ASM1
    2212             :     #undef  LSS_BODY_ASM2
    2213             :     #undef  LSS_BODY_ASM3
    2214             :     #undef  LSS_BODY_ASM4
    2215             :     #undef  LSS_BODY_ASM5
    2216             :     #undef  LSS_BODY_ASM6
    2217             :     #define LSS_BODY_ASM0
    2218             :     #define LSS_BODY_ASM1 LSS_BODY_ASM0
    2219             :     #define LSS_BODY_ASM2 LSS_BODY_ASM1
    2220             :     #define LSS_BODY_ASM3 LSS_BODY_ASM2
    2221             :     #define LSS_BODY_ASM4 LSS_BODY_ASM3 "movq %5,%%r10;"
    2222             :     #define LSS_BODY_ASM5 LSS_BODY_ASM4 "movq %6,%%r8;"
    2223             :     #define LSS_BODY_ASM6 LSS_BODY_ASM5 "movq %7,%%r9;"
    2224             : 
    2225             :     #undef  LSS_BODY_CLOBBER0
    2226             :     #undef  LSS_BODY_CLOBBER1
    2227             :     #undef  LSS_BODY_CLOBBER2
    2228             :     #undef  LSS_BODY_CLOBBER3
    2229             :     #undef  LSS_BODY_CLOBBER4
    2230             :     #undef  LSS_BODY_CLOBBER5
    2231             :     #undef  LSS_BODY_CLOBBER6
    2232             :     #define LSS_BODY_CLOBBER0
    2233             :     #define LSS_BODY_CLOBBER1 LSS_BODY_CLOBBER0
    2234             :     #define LSS_BODY_CLOBBER2 LSS_BODY_CLOBBER1
    2235             :     #define LSS_BODY_CLOBBER3 LSS_BODY_CLOBBER2
    2236             :     #define LSS_BODY_CLOBBER4 LSS_BODY_CLOBBER3 "r10",
    2237             :     #define LSS_BODY_CLOBBER5 LSS_BODY_CLOBBER4 "r8",
    2238             :     #define LSS_BODY_CLOBBER6 LSS_BODY_CLOBBER5 "r9",
    2239             : 
    2240             :     #undef  LSS_BODY_ARG0
    2241             :     #undef  LSS_BODY_ARG1
    2242             :     #undef  LSS_BODY_ARG2
    2243             :     #undef  LSS_BODY_ARG3
    2244             :     #undef  LSS_BODY_ARG4
    2245             :     #undef  LSS_BODY_ARG5
    2246             :     #undef  LSS_BODY_ARG6
    2247             :     #define LSS_BODY_ARG0()
    2248             :     #define LSS_BODY_ARG1(arg1) \
    2249             :       LSS_BODY_ARG0(), "D" (arg1)
    2250             :     #define LSS_BODY_ARG2(arg1, arg2) \
    2251             :       LSS_BODY_ARG1(arg1), "S" (arg2)
    2252             :     #define LSS_BODY_ARG3(arg1, arg2, arg3) \
    2253             :       LSS_BODY_ARG2(arg1, arg2), "d" (arg3)
    2254             :     #define LSS_BODY_ARG4(arg1, arg2, arg3, arg4) \
    2255             :       LSS_BODY_ARG3(arg1, arg2, arg3), "r" (arg4)
    2256             :     #define LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5) \
    2257             :       LSS_BODY_ARG4(arg1, arg2, arg3, arg4), "r" (arg5)
    2258             :     #define LSS_BODY_ARG6(arg1, arg2, arg3, arg4, arg5, arg6) \
    2259             :       LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5), "r" (arg6)
    2260             : 
    2261             :     #undef _syscall0
    2262             :     #define _syscall0(type,name)                                              \
    2263             :       type LSS_NAME(name)(void) {                                             \
    2264             :         LSS_BODY(0, type, name);                                              \
    2265             :       }
    2266             :     #undef _syscall1
    2267             :     #define _syscall1(type,name,type1,arg1)                                   \
    2268             :       type LSS_NAME(name)(type1 arg1) {                                       \
    2269             :         LSS_BODY(1, type, name, LSS_SYSCALL_ARG(arg1));                       \
    2270             :       }
    2271             :     #undef _syscall2
    2272             :     #define _syscall2(type,name,type1,arg1,type2,arg2)                        \
    2273             :       type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \
    2274             :         LSS_BODY(2, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2));\
    2275             :       }
    2276             :     #undef _syscall3
    2277             :     #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3)             \
    2278             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \
    2279             :         LSS_BODY(3, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
    2280             :                                 LSS_SYSCALL_ARG(arg3));                       \
    2281             :       }
    2282             :     #undef _syscall4
    2283             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    2284             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    2285             :         LSS_BODY(4, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
    2286             :                                 LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4));\
    2287             :       }
    2288             :     #undef _syscall5
    2289             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2290             :                       type5,arg5)                                             \
    2291             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2292             :                           type5 arg5) {                                       \
    2293             :         LSS_BODY(5, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
    2294             :                                 LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
    2295             :                                 LSS_SYSCALL_ARG(arg5));                       \
    2296             :       }
    2297             :     #undef _syscall6
    2298             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2299             :                       type5,arg5,type6,arg6)                                  \
    2300             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2301             :                           type5 arg5, type6 arg6) {                           \
    2302             :         LSS_BODY(6, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
    2303             :                                 LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
    2304             :                                 LSS_SYSCALL_ARG(arg5), LSS_SYSCALL_ARG(arg6));\
    2305             :       }
    2306           0 :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2307             :                                    int flags, void *arg, int *parent_tidptr,
    2308             :                                    void *newtls, int *child_tidptr) {
    2309             :       long long __res;
    2310             :       {
    2311             :         __asm__ __volatile__(/* if (fn == NULL)
    2312             :                               *   return -EINVAL;
    2313             :                               */
    2314             :                              "testq  %4,%4\n"
    2315             :                              "jz     1f\n"
    2316             : 
    2317             :                              /* if (child_stack == NULL)
    2318             :                               *   return -EINVAL;
    2319             :                               */
    2320             :                              "testq  %5,%5\n"
    2321             :                              "jz     1f\n"
    2322             : 
    2323             :                              /* childstack -= 2*sizeof(void *);
    2324             :                               */
    2325             :                              "subq   $16,%5\n"
    2326             : 
    2327             :                              /* Push "arg" and "fn" onto the stack that will be
    2328             :                               * used by the child.
    2329             :                               */
    2330             :                              "movq   %7,8(%5)\n"
    2331             :                              "movq   %4,0(%5)\n"
    2332             : 
    2333             :                              /* %rax = syscall(%rax = __NR_clone,
    2334             :                               *                %rdi = flags,
    2335             :                               *                %rsi = child_stack,
    2336             :                               *                %rdx = parent_tidptr,
    2337             :                               *                %r8  = new_tls,
    2338             :                               *                %r10 = child_tidptr)
    2339             :                               */
    2340             :                              "movq   %2,%%rax\n"
    2341             :                              "movq   %9,%%r8\n"
    2342             :                              "movq   %10,%%r10\n"
    2343             :                              LSS_ENTRYPOINT
    2344             : 
    2345             :                              /* if (%rax != 0)
    2346             :                               *   return;
    2347             :                               */
    2348             :                              "testq  %%rax,%%rax\n"
    2349             :                              "jnz    1f\n"
    2350             : 
    2351             :                              /* In the child. Terminate frame pointer chain.
    2352             :                               */
    2353             :                              "xorq   %%rbp,%%rbp\n"
    2354             : 
    2355             :                              /* Call "fn(arg)".
    2356             :                               */
    2357             :                              "popq   %%rax\n"
    2358             :                              "popq   %%rdi\n"
    2359             :                              "call   *%%rax\n"
    2360             : 
    2361             :                              /* Call _exit(%ebx).
    2362             :                               */
    2363             :                              "movq   %%rax,%%rdi\n"
    2364             :                              "movq   %3,%%rax\n"
    2365             :                              LSS_ENTRYPOINT
    2366             : 
    2367             :                              /* Return to parent.
    2368             :                               */
    2369             :                            "1:\n"
    2370             :                              : "=a" (__res)
    2371             :                              : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
    2372           0 :                                "r"(LSS_SYSCALL_ARG(fn)),
    2373           0 :                                "S"(LSS_SYSCALL_ARG(child_stack)),
    2374           0 :                                "D"(LSS_SYSCALL_ARG(flags)),
    2375           0 :                                "r"(LSS_SYSCALL_ARG(arg)),
    2376           0 :                                "d"(LSS_SYSCALL_ARG(parent_tidptr)),
    2377           0 :                                "r"(LSS_SYSCALL_ARG(newtls)),
    2378           0 :                                "r"(LSS_SYSCALL_ARG(child_tidptr))
    2379           0 :                              : "rsp", "memory", "r8", "r10", "r11", "rcx");
    2380             :       }
    2381           0 :       LSS_RETURN(int, __res);
    2382             :     }
    2383             :     LSS_INLINE _syscall2(int, arch_prctl, int, c, void *, a)
    2384             : 
    2385             :     LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
    2386             :       /* On x86-64, the kernel does not know how to return from
    2387             :        * a signal handler. Instead, it relies on user space to provide a
    2388             :        * restorer function that calls the rt_sigreturn() system call.
    2389             :        * Unfortunately, we cannot just reference the glibc version of this
    2390             :        * function, as glibc goes out of its way to make it inaccessible.
    2391             :        */
    2392             :       long long res;
    2393             :       __asm__ __volatile__("jmp    2f\n"
    2394             :                            ".align 16\n"
    2395             :                          "1:movq   %1,%%rax\n"
    2396             :                            LSS_ENTRYPOINT
    2397             :                          "2:leaq   1b(%%rip),%0\n"
    2398             :                            : "=r" (res)
    2399             :                            : "i"  (__NR_rt_sigreturn));
    2400             :       return (void (*)(void))(uintptr_t)res;
    2401             :     }
    2402             :   #elif defined(__ARM_ARCH_3__)
    2403             :     /* Most definitions of _syscallX() neglect to mark "memory" as being
    2404             :      * clobbered. This causes problems with compilers, that do a better job
    2405             :      * at optimizing across __asm__ calls.
    2406             :      * So, we just have to redefine all of the _syscallX() macros.
    2407             :      */
    2408             :     #undef LSS_REG
    2409             :     #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
    2410             :     #undef  LSS_BODY
    2411             :     #define LSS_BODY(type,name,args...)                                       \
    2412             :           register long __res_r0 __asm__("r0");                               \
    2413             :           long __res;                                                         \
    2414             :           __asm__ __volatile__ (__syscall(name)                               \
    2415             :                                 : "=r"(__res_r0) : args : "lr", "memory");    \
    2416             :           __res = __res_r0;                                                   \
    2417             :           LSS_RETURN(type, __res)
    2418             :     #undef _syscall0
    2419             :     #define _syscall0(type, name)                                             \
    2420             :       type LSS_NAME(name)(void) {                                             \
    2421             :         LSS_BODY(type, name);                                                 \
    2422             :       }
    2423             :     #undef _syscall1
    2424             :     #define _syscall1(type, name, type1, arg1)                                \
    2425             :       type LSS_NAME(name)(type1 arg1) {                                       \
    2426             :         LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0));                    \
    2427             :       }
    2428             :     #undef _syscall2
    2429             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    2430             :       type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \
    2431             :         LSS_REG(0, arg1); LSS_REG(1, arg2);                                   \
    2432             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1));                           \
    2433             :       }
    2434             :     #undef _syscall3
    2435             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    2436             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \
    2437             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2438             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2));                \
    2439             :       }
    2440             :     #undef _syscall4
    2441             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    2442             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    2443             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2444             :         LSS_REG(3, arg4);                                                     \
    2445             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3));     \
    2446             :       }
    2447             :     #undef _syscall5
    2448             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2449             :                       type5,arg5)                                             \
    2450             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2451             :                           type5 arg5) {                                       \
    2452             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2453             :         LSS_REG(3, arg4); LSS_REG(4, arg5);                                   \
    2454             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2455             :                              "r"(__r4));                                      \
    2456             :       }
    2457             :     #undef _syscall6
    2458             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2459             :                       type5,arg5,type6,arg6)                                  \
    2460             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2461             :                           type5 arg5, type6 arg6) {                           \
    2462             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2463             :         LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6);                 \
    2464             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2465             :                              "r"(__r4), "r"(__r5));                           \
    2466             :       }
    2467             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2468             :                                    int flags, void *arg, int *parent_tidptr,
    2469             :                                    void *newtls, int *child_tidptr) {
    2470             :       long __res;
    2471             :       {
    2472             :         register int   __flags __asm__("r0") = flags;
    2473             :         register void *__stack __asm__("r1") = child_stack;
    2474             :         register void *__ptid  __asm__("r2") = parent_tidptr;
    2475             :         register void *__tls   __asm__("r3") = newtls;
    2476             :         register int  *__ctid  __asm__("r4") = child_tidptr;
    2477             :         __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)
    2478             :                               *   return -EINVAL;
    2479             :                               */
    2480             :                              "cmp   %2,#0\n"
    2481             :                              "cmpne %3,#0\n"
    2482             :                              "moveq %0,%1\n"
    2483             :                              "beq   1f\n"
    2484             : 
    2485             :                              /* Push "arg" and "fn" onto the stack that will be
    2486             :                               * used by the child.
    2487             :                               */
    2488             :                              "str   %5,[%3,#-4]!\n"
    2489             :                              "str   %2,[%3,#-4]!\n"
    2490             : 
    2491             :                              /* %r0 = syscall(%r0 = flags,
    2492             :                               *               %r1 = child_stack,
    2493             :                               *               %r2 = parent_tidptr,
    2494             :                               *               %r3 = newtls,
    2495             :                               *               %r4 = child_tidptr)
    2496             :                               */
    2497             :                              __syscall(clone)"\n"
    2498             : 
    2499             :                              /* if (%r0 != 0)
    2500             :                               *   return %r0;
    2501             :                               */
    2502             :                              "movs  %0,r0\n"
    2503             :                              "bne   1f\n"
    2504             : 
    2505             :                              /* In the child, now. Call "fn(arg)".
    2506             :                               */
    2507             :                              "ldr   r0,[sp, #4]\n"
    2508             :                              "mov   lr,pc\n"
    2509             :                              "ldr   pc,[sp]\n"
    2510             : 
    2511             :                              /* Call _exit(%r0).
    2512             :                               */
    2513             :                              __syscall(exit)"\n"
    2514             :                            "1:\n"
    2515             :                              : "=r" (__res)
    2516             :                              : "i"(-EINVAL),
    2517             :                                "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
    2518             :                                "r"(__ptid), "r"(__tls), "r"(__ctid)
    2519             :                              : "cc", "lr", "memory");
    2520             :       }
    2521             :       LSS_RETURN(int, __res);
    2522             :     }
    2523             :   #elif defined(__ARM_EABI__)
    2524             :     /* Most definitions of _syscallX() neglect to mark "memory" as being
    2525             :      * clobbered. This causes problems with compilers, that do a better job
    2526             :      * at optimizing across __asm__ calls.
    2527             :      * So, we just have to redefine all fo the _syscallX() macros.
    2528             :      */
    2529             :     #undef LSS_REG
    2530             :     #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
    2531             :     #undef  LSS_BODY
    2532             :     #define LSS_BODY(type,name,args...)                                       \
    2533             :           register long __res_r0 __asm__("r0");                               \
    2534             :           long __res;                                                         \
    2535             :           __asm__ __volatile__ ("push {r7}\n"                                 \
    2536             :                                 "mov r7, %1\n"                                \
    2537             :                                 "swi 0x0\n"                                   \
    2538             :                                 "pop {r7}\n"                                  \
    2539             :                                 : "=r"(__res_r0)                              \
    2540             :                                 : "i"(__NR_##name) , ## args                  \
    2541             :                                 : "lr", "memory");                            \
    2542             :           __res = __res_r0;                                                   \
    2543             :           LSS_RETURN(type, __res)
    2544             :     #undef _syscall0
    2545             :     #define _syscall0(type, name)                                             \
    2546             :       type LSS_NAME(name)(void) {                                             \
    2547             :         LSS_BODY(type, name);                                                 \
    2548             :       }
    2549             :     #undef _syscall1
    2550             :     #define _syscall1(type, name, type1, arg1)                                \
    2551             :       type LSS_NAME(name)(type1 arg1) {                                       \
    2552             :         LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0));                    \
    2553             :       }
    2554             :     #undef _syscall2
    2555             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    2556             :       type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \
    2557             :         LSS_REG(0, arg1); LSS_REG(1, arg2);                                   \
    2558             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1));                           \
    2559             :       }
    2560             :     #undef _syscall3
    2561             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    2562             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \
    2563             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2564             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2));                \
    2565             :       }
    2566             :     #undef _syscall4
    2567             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    2568             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    2569             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2570             :         LSS_REG(3, arg4);                                                     \
    2571             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3));     \
    2572             :       }
    2573             :     #undef _syscall5
    2574             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2575             :                       type5,arg5)                                             \
    2576             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2577             :                           type5 arg5) {                                       \
    2578             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2579             :         LSS_REG(3, arg4); LSS_REG(4, arg5);                                   \
    2580             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2581             :                              "r"(__r4));                                      \
    2582             :       }
    2583             :     #undef _syscall6
    2584             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2585             :                       type5,arg5,type6,arg6)                                  \
    2586             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2587             :                           type5 arg5, type6 arg6) {                           \
    2588             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2589             :         LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6);                 \
    2590             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2591             :                              "r"(__r4), "r"(__r5));                           \
    2592             :       }
    2593             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2594             :                                    int flags, void *arg, int *parent_tidptr,
    2595             :                                    void *newtls, int *child_tidptr) {
    2596             :       long __res;
    2597             :       {
    2598             :         register int   __flags __asm__("r0") = flags;
    2599             :         register void *__stack __asm__("r1") = child_stack;
    2600             :         register void *__ptid  __asm__("r2") = parent_tidptr;
    2601             :         register void *__tls   __asm__("r3") = newtls;
    2602             :         register int  *__ctid  __asm__("r4") = child_tidptr;
    2603             :         __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)
    2604             :                               *   return -EINVAL;
    2605             :                               */
    2606             :                              "cmp   %2,#0\n"
    2607             :                              "it    ne\n"
    2608             :                              "cmpne %3,#0\n"
    2609             :                              "it    eq\n"
    2610             :                              "moveq %0,%1\n"
    2611             :                              "beq   1f\n"
    2612             : 
    2613             :                              /* Push "arg" and "fn" onto the stack that will be
    2614             :                               * used by the child.
    2615             :                               */
    2616             :                              "str   %5,[%3,#-4]!\n"
    2617             :                              "str   %2,[%3,#-4]!\n"
    2618             : 
    2619             :                              /* %r0 = syscall(%r0 = flags,
    2620             :                               *               %r1 = child_stack,
    2621             :                               *               %r2 = parent_tidptr,
    2622             :                               *               %r3 = newtls,
    2623             :                               *               %r4 = child_tidptr)
    2624             :                               */
    2625             :                              "mov r7, %9\n"
    2626             :                              "swi 0x0\n"
    2627             : 
    2628             :                              /* if (%r0 != 0)
    2629             :                               *   return %r0;
    2630             :                               */
    2631             :                              "movs  %0,r0\n"
    2632             :                              "bne   1f\n"
    2633             : 
    2634             :                              /* In the child, now. Call "fn(arg)".
    2635             :                               */
    2636             :                              "ldr   r0,[sp, #4]\n"
    2637             : 
    2638             :                              /* When compiling for Thumb-2 the "MOV LR,PC" here
    2639             :                               * won't work because it loads PC+4 into LR,
    2640             :                               * whereas the LDR is a 4-byte instruction.
    2641             :                               * This results in the child thread always
    2642             :                               * crashing with an "Illegal Instruction" when it
    2643             :                               * returned into the middle of the LDR instruction
    2644             :                               * The instruction sequence used instead was
    2645             :                               * recommended by
    2646             :                               * "https://wiki.edubuntu.org/ARM/Thumb2PortingHowto#Quick_Reference".
    2647             :                               */
    2648             :                            #ifdef __thumb2__
    2649             :                              "ldr   r7,[sp]\n"
    2650             :                              "blx   r7\n"
    2651             :                            #else
    2652             :                              "mov   lr,pc\n"
    2653             :                              "ldr   pc,[sp]\n"
    2654             :                            #endif
    2655             : 
    2656             :                              /* Call _exit(%r0).
    2657             :                               */
    2658             :                              "mov r7, %10\n"
    2659             :                              "swi 0x0\n"
    2660             :                            "1:\n"
    2661             :                              : "=r" (__res)
    2662             :                              : "i"(-EINVAL),
    2663             :                                "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
    2664             :                                "r"(__ptid), "r"(__tls), "r"(__ctid),
    2665             :                                "i"(__NR_clone), "i"(__NR_exit)
    2666             :                              : "cc", "r7", "lr", "memory");
    2667             :       }
    2668             :       LSS_RETURN(int, __res);
    2669             :     }
    2670             :   #elif defined(__aarch64__)
    2671             :     /* Most definitions of _syscallX() neglect to mark "memory" as being
    2672             :      * clobbered. This causes problems with compilers, that do a better job
    2673             :      * at optimizing across __asm__ calls.
    2674             :      * So, we just have to redefine all of the _syscallX() macros.
    2675             :      */
    2676             :     #undef LSS_REG
    2677             :     #define LSS_REG(r,a) register int64_t __r##r __asm__("x"#r) = (int64_t)a
    2678             :     #undef  LSS_BODY
    2679             :     #define LSS_BODY(type,name,args...)                                       \
    2680             :           register int64_t __res_x0 __asm__("x0");                            \
    2681             :           int64_t __res;                                                      \
    2682             :           __asm__ __volatile__ ("mov x8, %1\n"                                \
    2683             :                                 "svc 0x0\n"                                   \
    2684             :                                 : "=r"(__res_x0)                              \
    2685             :                                 : "i"(__NR_##name) , ## args                  \
    2686             :                                 : "x8", "memory");                            \
    2687             :           __res = __res_x0;                                                   \
    2688             :           LSS_RETURN(type, __res)
    2689             :     #undef _syscall0
    2690             :     #define _syscall0(type, name)                                             \
    2691             :       type LSS_NAME(name)(void) {                                             \
    2692             :         LSS_BODY(type, name);                                                 \
    2693             :       }
    2694             :     #undef _syscall1
    2695             :     #define _syscall1(type, name, type1, arg1)                                \
    2696             :       type LSS_NAME(name)(type1 arg1) {                                       \
    2697             :         LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0));                    \
    2698             :       }
    2699             :     #undef _syscall2
    2700             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    2701             :       type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \
    2702             :         LSS_REG(0, arg1); LSS_REG(1, arg2);                                   \
    2703             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1));                           \
    2704             :       }
    2705             :     #undef _syscall3
    2706             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    2707             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \
    2708             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2709             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2));                \
    2710             :       }
    2711             :     #undef _syscall4
    2712             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    2713             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    2714             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2715             :         LSS_REG(3, arg4);                                                     \
    2716             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3));     \
    2717             :       }
    2718             :     #undef _syscall5
    2719             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2720             :                       type5,arg5)                                             \
    2721             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2722             :                           type5 arg5) {                                       \
    2723             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2724             :         LSS_REG(3, arg4); LSS_REG(4, arg5);                                   \
    2725             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2726             :                              "r"(__r4));                                      \
    2727             :       }
    2728             :     #undef _syscall6
    2729             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2730             :                       type5,arg5,type6,arg6)                                  \
    2731             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2732             :                           type5 arg5, type6 arg6) {                           \
    2733             :         LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \
    2734             :         LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6);                 \
    2735             :         LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \
    2736             :                              "r"(__r4), "r"(__r5));                           \
    2737             :       }
    2738             : 
    2739             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2740             :                                    int flags, void *arg, int *parent_tidptr,
    2741             :                                    void *newtls, int *child_tidptr) {
    2742             :       int64_t __res;
    2743             :       {
    2744             :         register uint64_t __flags __asm__("x0") = flags;
    2745             :         register void *__stack __asm__("x1") = child_stack;
    2746             :         register void *__ptid  __asm__("x2") = parent_tidptr;
    2747             :         register void *__tls   __asm__("x3") = newtls;
    2748             :         register int  *__ctid  __asm__("x4") = child_tidptr;
    2749             :         __asm__ __volatile__(/* Push "arg" and "fn" onto the stack that will be
    2750             :                               * used by the child.
    2751             :                               */
    2752             :                              "stp     %1, %4, [%2, #-16]!\n"
    2753             : 
    2754             :                              /* %x0 = syscall(%x0 = flags,
    2755             :                               *               %x1 = child_stack,
    2756             :                               *               %x2 = parent_tidptr,
    2757             :                               *               %x3 = newtls,
    2758             :                               *               %x4 = child_tidptr)
    2759             :                               */
    2760             :                              "mov     x8, %8\n"
    2761             :                              "svc     0x0\n"
    2762             : 
    2763             :                              /* if (%r0 != 0)
    2764             :                               *   return %r0;
    2765             :                               */
    2766             :                              "mov     %0, x0\n"
    2767             :                              "cbnz    x0, 1f\n"
    2768             : 
    2769             :                              /* In the child, now. Call "fn(arg)".
    2770             :                               */
    2771             :                              "ldp     x1, x0, [sp], #16\n"
    2772             :                              "blr     x1\n"
    2773             : 
    2774             :                              /* Call _exit(%r0).
    2775             :                               */
    2776             :                              "mov     x8, %9\n"
    2777             :                              "svc     0x0\n"
    2778             :                            "1:\n"
    2779             :                              : "=r" (__res)
    2780             :                              : "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
    2781             :                                "r"(__ptid), "r"(__tls), "r"(__ctid),
    2782             :                                "i"(__NR_clone), "i"(__NR_exit)
    2783             :                              : "cc", "x8", "memory");
    2784             :       }
    2785             :       LSS_RETURN(int, __res);
    2786             :     }
    2787             :   #elif defined(__mips__)
    2788             :     #undef LSS_REG
    2789             :     #define LSS_REG(r,a) register unsigned long __r##r __asm__("$"#r) =       \
    2790             :                                  (unsigned long)(a)
    2791             :     #undef  LSS_BODY
    2792             :     #undef LSS_SYSCALL_CLOBBERS
    2793             :     #if _MIPS_SIM == _MIPS_SIM_ABI32
    2794             :     #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10",               \
    2795             :                                  "$11", "$12", "$13", "$14", "$15",           \
    2796             :                                  "$24", "$25", "hi", "lo", "memory"
    2797             :     #else
    2798             :     #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12",             \
    2799             :                                  "$13", "$14", "$15", "$24", "$25",           \
    2800             :                                  "hi", "lo", "memory"
    2801             :     #endif
    2802             :     #define LSS_BODY(type,name,r7,...)                                        \
    2803             :           register unsigned long __v0 __asm__("$2") = __NR_##name;            \
    2804             :           __asm__ __volatile__ ("syscall\n"                                   \
    2805             :                                 : "=r"(__v0), r7 (__r7)                       \
    2806             :                                 : "0"(__v0), ##__VA_ARGS__                    \
    2807             :                                 : LSS_SYSCALL_CLOBBERS);                      \
    2808             :           LSS_RETURN(type, __v0, __r7)
    2809             :     #undef _syscall0
    2810             :     #define _syscall0(type, name)                                             \
    2811             :       type LSS_NAME(name)(void) {                                             \
    2812             :         register unsigned long __r7 __asm__("$7");                            \
    2813             :         LSS_BODY(type, name, "=r");                                           \
    2814             :       }
    2815             :     #undef _syscall1
    2816             :     #define _syscall1(type, name, type1, arg1)                                \
    2817             :       type LSS_NAME(name)(type1 arg1) {                                       \
    2818             :         register unsigned long __r7 __asm__("$7");                            \
    2819             :         LSS_REG(4, arg1); LSS_BODY(type, name, "=r", "r"(__r4));              \
    2820             :       }
    2821             :     #undef _syscall2
    2822             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    2823             :       type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \
    2824             :         register unsigned long __r7 __asm__("$7");                            \
    2825             :         LSS_REG(4, arg1); LSS_REG(5, arg2);                                   \
    2826             :         LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5));                     \
    2827             :       }
    2828             :     #undef _syscall3
    2829             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    2830             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \
    2831             :         register unsigned long __r7 __asm__("$7");                            \
    2832             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2833             :         LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5), "r"(__r6));          \
    2834             :       }
    2835             :     #undef _syscall4
    2836             :     #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \
    2837             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \
    2838             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2839             :         LSS_REG(7, arg4);                                                     \
    2840             :         LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6));          \
    2841             :       }
    2842             :     #undef _syscall5
    2843             :     #if _MIPS_SIM == _MIPS_SIM_ABI32
    2844             :     /* The old 32bit MIPS system call API passes the fifth and sixth argument
    2845             :      * on the stack, whereas the new APIs use registers "r8" and "r9".
    2846             :      */
    2847             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2848             :                       type5,arg5)                                             \
    2849             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2850             :                           type5 arg5) {                                       \
    2851             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2852             :         LSS_REG(7, arg4);                                                     \
    2853             :         register unsigned long __v0 __asm__("$2") = __NR_##name;              \
    2854             :         __asm__ __volatile__ (".set noreorder\n"                              \
    2855             :                               "subu  $29, 32\n"                               \
    2856             :                               "sw    %5, 16($29)\n"                           \
    2857             :                               "syscall\n"                                     \
    2858             :                               "addiu $29, 32\n"                               \
    2859             :                               ".set reorder\n"                                \
    2860             :                               : "+r"(__v0), "+r" (__r7)                       \
    2861             :                               : "r"(__r4), "r"(__r5),                         \
    2862             :                                 "r"(__r6), "r" ((unsigned long)arg5)          \
    2863             :                               : "$8", "$9", "$10", "$11", "$12",              \
    2864             :                                 "$13", "$14", "$15", "$24", "$25",            \
    2865             :                                 "memory");                                    \
    2866             :         LSS_RETURN(type, __v0, __r7);                                         \
    2867             :       }
    2868             :     #else
    2869             :     #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2870             :                       type5,arg5)                                             \
    2871             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2872             :                           type5 arg5) {                                       \
    2873             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2874             :         LSS_REG(7, arg4); LSS_REG(8, arg5);                                   \
    2875             :         LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6),           \
    2876             :                  "r"(__r8));                                                  \
    2877             :       }
    2878             :     #endif
    2879             :     #undef _syscall6
    2880             :     #if _MIPS_SIM == _MIPS_SIM_ABI32
    2881             :     /* The old 32bit MIPS system call API passes the fifth and sixth argument
    2882             :      * on the stack, whereas the new APIs use registers "r8" and "r9".
    2883             :      */
    2884             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2885             :                       type5,arg5,type6,arg6)                                  \
    2886             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2887             :                           type5 arg5, type6 arg6) {                           \
    2888             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2889             :         LSS_REG(7, arg4);                                                     \
    2890             :         register unsigned long __v0 __asm__("$2") = __NR_##name;              \
    2891             :         __asm__ __volatile__ (".set noreorder\n"                              \
    2892             :                               "subu  $29, 32\n"                               \
    2893             :                               "sw    %5, 16($29)\n"                           \
    2894             :                               "sw    %6, 20($29)\n"                           \
    2895             :                               "syscall\n"                                     \
    2896             :                               "addiu $29, 32\n"                               \
    2897             :                               ".set reorder\n"                                \
    2898             :                               : "+r"(__v0), "+r" (__r7)                       \
    2899             :                               : "r"(__r4), "r"(__r5),                         \
    2900             :                                 "r"(__r6), "r" ((unsigned long)arg5),         \
    2901             :                                 "r" ((unsigned long)arg6)                     \
    2902             :                               : "$8", "$9", "$10", "$11", "$12",              \
    2903             :                                 "$13", "$14", "$15", "$24", "$25",            \
    2904             :                                 "memory");                                    \
    2905             :         LSS_RETURN(type, __v0, __r7);                                         \
    2906             :       }
    2907             :     #else
    2908             :     #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \
    2909             :                       type5,arg5,type6,arg6)                                  \
    2910             :       type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \
    2911             :                           type5 arg5,type6 arg6) {                            \
    2912             :         LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3);                 \
    2913             :         LSS_REG(7, arg4); LSS_REG(8, arg5); LSS_REG(9, arg6);                 \
    2914             :         LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6),           \
    2915             :                  "r"(__r8), "r"(__r9));                                       \
    2916             :       }
    2917             :     #endif
    2918             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    2919             :                                    int flags, void *arg, int *parent_tidptr,
    2920             :                                    void *newtls, int *child_tidptr) {
    2921             :       register unsigned long __v0 __asm__("$2") = -EINVAL;
    2922             :       register unsigned long __r7 __asm__("$7") = (unsigned long)newtls;
    2923             :       {
    2924             :         register int   __flags __asm__("$4") = flags;
    2925             :         register void *__stack __asm__("$5") = child_stack;
    2926             :         register void *__ptid  __asm__("$6") = parent_tidptr;
    2927             :         register int  *__ctid  __asm__("$8") = child_tidptr;
    2928             :         __asm__ __volatile__(
    2929             :           #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
    2930             :                              "subu  $29,24\n"
    2931             :           #elif _MIPS_SIM == _MIPS_SIM_NABI32
    2932             :                              "sub   $29,16\n"
    2933             :           #else
    2934             :                              "dsubu $29,16\n"
    2935             :           #endif
    2936             : 
    2937             :                              /* if (fn == NULL || child_stack == NULL)
    2938             :                               *   return -EINVAL;
    2939             :                               */
    2940             :                              "beqz  %4,1f\n"
    2941             :                              "beqz  %5,1f\n"
    2942             : 
    2943             :                              /* Push "arg" and "fn" onto the stack that will be
    2944             :                               * used by the child.
    2945             :                               */
    2946             :           #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
    2947             :                              "subu  %5,32\n"
    2948             :                              "sw    %4,0(%5)\n"
    2949             :                              "sw    %7,4(%5)\n"
    2950             :           #elif _MIPS_SIM == _MIPS_SIM_NABI32
    2951             :                              "sub   %5,32\n"
    2952             :                              "sw    %4,0(%5)\n"
    2953             :                              "sw    %7,8(%5)\n"
    2954             :           #else
    2955             :                              "dsubu %5,32\n"
    2956             :                              "sd    %4,0(%5)\n"
    2957             :                              "sd    %7,8(%5)\n"
    2958             :           #endif
    2959             : 
    2960             :                              /* $7 = syscall($4 = flags,
    2961             :                               *              $5 = child_stack,
    2962             :                               *              $6 = parent_tidptr,
    2963             :                               *              $7 = newtls,
    2964             :                               *              $8 = child_tidptr)
    2965             :                               */
    2966             :                              "li    $2,%2\n"
    2967             :                              "syscall\n"
    2968             : 
    2969             :                              /* if ($7 != 0)
    2970             :                               *   return $2;
    2971             :                               */
    2972             :                              "bnez  $7,1f\n"
    2973             :                              "bnez  $2,1f\n"
    2974             : 
    2975             :                              /* In the child, now. Call "fn(arg)".
    2976             :                               */
    2977             :           #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
    2978             :                             "lw    $25,0($29)\n"
    2979             :                             "lw    $4,4($29)\n"
    2980             :           #elif _MIPS_SIM == _MIPS_SIM_NABI32
    2981             :                             "lw    $25,0($29)\n"
    2982             :                             "lw    $4,8($29)\n"
    2983             :           #else
    2984             :                             "ld    $25,0($29)\n"
    2985             :                             "ld    $4,8($29)\n"
    2986             :           #endif
    2987             :                             "jalr  $25\n"
    2988             : 
    2989             :                              /* Call _exit($2)
    2990             :                               */
    2991             :                             "move  $4,$2\n"
    2992             :                             "li    $2,%3\n"
    2993             :                             "syscall\n"
    2994             : 
    2995             :                            "1:\n"
    2996             :           #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
    2997             :                              "addu  $29, 24\n"
    2998             :           #elif _MIPS_SIM == _MIPS_SIM_NABI32
    2999             :                              "add   $29, 16\n"
    3000             :           #else
    3001             :                              "daddu $29,16\n"
    3002             :           #endif
    3003             :                              : "+r" (__v0), "+r" (__r7)
    3004             :                              : "i"(__NR_clone), "i"(__NR_exit), "r"(fn),
    3005             :                                "r"(__stack), "r"(__flags), "r"(arg),
    3006             :                                "r"(__ptid), "r"(__ctid)
    3007             :                              : "$9", "$10", "$11", "$12", "$13", "$14", "$15",
    3008             :                                "$24", "$25", "memory");
    3009             :       }
    3010             :       LSS_RETURN(int, __v0, __r7);
    3011             :     }
    3012             :   #elif defined (__PPC__)
    3013             :     #undef  LSS_LOADARGS_0
    3014             :     #define LSS_LOADARGS_0(name, dummy...)                                    \
    3015             :         __sc_0 = __NR_##name
    3016             :     #undef  LSS_LOADARGS_1
    3017             :     #define LSS_LOADARGS_1(name, arg1)                                        \
    3018             :             LSS_LOADARGS_0(name);                                             \
    3019             :             __sc_3 = (unsigned long) (arg1)
    3020             :     #undef  LSS_LOADARGS_2
    3021             :     #define LSS_LOADARGS_2(name, arg1, arg2)                                  \
    3022             :             LSS_LOADARGS_1(name, arg1);                                       \
    3023             :             __sc_4 = (unsigned long) (arg2)
    3024             :     #undef  LSS_LOADARGS_3
    3025             :     #define LSS_LOADARGS_3(name, arg1, arg2, arg3)                            \
    3026             :             LSS_LOADARGS_2(name, arg1, arg2);                                 \
    3027             :             __sc_5 = (unsigned long) (arg3)
    3028             :     #undef  LSS_LOADARGS_4
    3029             :     #define LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4)                      \
    3030             :             LSS_LOADARGS_3(name, arg1, arg2, arg3);                           \
    3031             :             __sc_6 = (unsigned long) (arg4)
    3032             :     #undef  LSS_LOADARGS_5
    3033             :     #define LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5)                \
    3034             :             LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4);                     \
    3035             :             __sc_7 = (unsigned long) (arg5)
    3036             :     #undef  LSS_LOADARGS_6
    3037             :     #define LSS_LOADARGS_6(name, arg1, arg2, arg3, arg4, arg5, arg6)          \
    3038             :             LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5);               \
    3039             :             __sc_8 = (unsigned long) (arg6)
    3040             :     #undef  LSS_ASMINPUT_0
    3041             :     #define LSS_ASMINPUT_0 "0" (__sc_0)
    3042             :     #undef  LSS_ASMINPUT_1
    3043             :     #define LSS_ASMINPUT_1 LSS_ASMINPUT_0, "1" (__sc_3)
    3044             :     #undef  LSS_ASMINPUT_2
    3045             :     #define LSS_ASMINPUT_2 LSS_ASMINPUT_1, "2" (__sc_4)
    3046             :     #undef  LSS_ASMINPUT_3
    3047             :     #define LSS_ASMINPUT_3 LSS_ASMINPUT_2, "3" (__sc_5)
    3048             :     #undef  LSS_ASMINPUT_4
    3049             :     #define LSS_ASMINPUT_4 LSS_ASMINPUT_3, "4" (__sc_6)
    3050             :     #undef  LSS_ASMINPUT_5
    3051             :     #define LSS_ASMINPUT_5 LSS_ASMINPUT_4, "5" (__sc_7)
    3052             :     #undef  LSS_ASMINPUT_6
    3053             :     #define LSS_ASMINPUT_6 LSS_ASMINPUT_5, "6" (__sc_8)
    3054             :     #undef  LSS_BODY
    3055             :     #define LSS_BODY(nr, type, name, args...)                                 \
    3056             :         long __sc_ret, __sc_err;                                              \
    3057             :         {                                                                     \
    3058             :                         register unsigned long __sc_0 __asm__ ("r0");         \
    3059             :                         register unsigned long __sc_3 __asm__ ("r3");         \
    3060             :                         register unsigned long __sc_4 __asm__ ("r4");         \
    3061             :                         register unsigned long __sc_5 __asm__ ("r5");         \
    3062             :                         register unsigned long __sc_6 __asm__ ("r6");         \
    3063             :                         register unsigned long __sc_7 __asm__ ("r7");         \
    3064             :                         register unsigned long __sc_8 __asm__ ("r8");         \
    3065             :                                                                               \
    3066             :             LSS_LOADARGS_##nr(name, args);                                    \
    3067             :             __asm__ __volatile__                                              \
    3068             :                 ("sc\n\t"                                                     \
    3069             :                  "mfcr %0"                                                    \
    3070             :                  : "=&r" (__sc_0),                                            \
    3071             :                    "=&r" (__sc_3), "=&r" (__sc_4),                            \
    3072             :                    "=&r" (__sc_5), "=&r" (__sc_6),                            \
    3073             :                    "=&r" (__sc_7), "=&r" (__sc_8)                             \
    3074             :                  : LSS_ASMINPUT_##nr                                          \
    3075             :                  : "cr0", "ctr", "memory",                                    \
    3076             :                    "r9", "r10", "r11", "r12");                                \
    3077             :             __sc_ret = __sc_3;                                                \
    3078             :             __sc_err = __sc_0;                                                \
    3079             :         }                                                                     \
    3080             :         LSS_RETURN(type, __sc_ret, __sc_err)
    3081             :     #undef _syscall0
    3082             :     #define _syscall0(type, name)                                             \
    3083             :        type LSS_NAME(name)(void) {                                            \
    3084             :           LSS_BODY(0, type, name);                                            \
    3085             :        }
    3086             :     #undef _syscall1
    3087             :     #define _syscall1(type, name, type1, arg1)                                \
    3088             :        type LSS_NAME(name)(type1 arg1) {                                      \
    3089             :           LSS_BODY(1, type, name, arg1);                                      \
    3090             :        }
    3091             :     #undef _syscall2
    3092             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    3093             :        type LSS_NAME(name)(type1 arg1, type2 arg2) {                          \
    3094             :           LSS_BODY(2, type, name, arg1, arg2);                                \
    3095             :        }
    3096             :     #undef _syscall3
    3097             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    3098             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {              \
    3099             :           LSS_BODY(3, type, name, arg1, arg2, arg3);                          \
    3100             :        }
    3101             :     #undef _syscall4
    3102             :     #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3103             :                                   type4, arg4)                                \
    3104             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {  \
    3105             :           LSS_BODY(4, type, name, arg1, arg2, arg3, arg4);                    \
    3106             :        }
    3107             :     #undef _syscall5
    3108             :     #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3109             :                                   type4, arg4, type5, arg5)                   \
    3110             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,    \
    3111             :                                                type5 arg5) {                  \
    3112             :           LSS_BODY(5, type, name, arg1, arg2, arg3, arg4, arg5);              \
    3113             :        }
    3114             :     #undef _syscall6
    3115             :     #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3116             :                                   type4, arg4, type5, arg5, type6, arg6)      \
    3117             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,    \
    3118             :                                                type5 arg5, type6 arg6) {      \
    3119             :           LSS_BODY(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6);        \
    3120             :        }
    3121             :     /* clone function adapted from glibc 2.3.6 clone.S                       */
    3122             :     /* TODO(csilvers): consider wrapping some args up in a struct, like we
    3123             :      * do for i386's _syscall6, so we can compile successfully on gcc 2.95
    3124             :      */
    3125             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    3126             :                                    int flags, void *arg, int *parent_tidptr,
    3127             :                                    void *newtls, int *child_tidptr) {
    3128             :       long __ret, __err;
    3129             :       {
    3130             :         register int (*__fn)(void *)    __asm__ ("r8")  = fn;
    3131             :         register void *__cstack                 __asm__ ("r4")  = child_stack;
    3132             :         register int __flags                    __asm__ ("r3")  = flags;
    3133             :         register void * __arg                   __asm__ ("r9")  = arg;
    3134             :         register int * __ptidptr                __asm__ ("r5")  = parent_tidptr;
    3135             :         register void * __newtls                __asm__ ("r6")  = newtls;
    3136             :         register int * __ctidptr                __asm__ ("r7")  = child_tidptr;
    3137             :         __asm__ __volatile__(
    3138             :             /* check for fn == NULL
    3139             :              * and child_stack == NULL
    3140             :              */
    3141             :             "cmpwi cr0, %6, 0\n\t"
    3142             :             "cmpwi cr1, %7, 0\n\t"
    3143             :             "cror cr0*4+eq, cr1*4+eq, cr0*4+eq\n\t"
    3144             :             "beq- cr0, 1f\n\t"
    3145             : 
    3146             :             /* set up stack frame for child                                  */
    3147             :             "clrrwi %7, %7, 4\n\t"
    3148             :             "li 0, 0\n\t"
    3149             :             "stwu 0, -16(%7)\n\t"
    3150             : 
    3151             :             /* fn, arg, child_stack are saved across the syscall: r28-30     */
    3152             :             "mr 28, %6\n\t"
    3153             :             "mr 29, %7\n\t"
    3154             :             "mr 27, %9\n\t"
    3155             : 
    3156             :             /* syscall                                                       */
    3157             :             "li 0, %4\n\t"
    3158             :             /* flags already in r3
    3159             :              * child_stack already in r4
    3160             :              * ptidptr already in r5
    3161             :              * newtls already in r6
    3162             :              * ctidptr already in r7
    3163             :              */
    3164             :             "sc\n\t"
    3165             : 
    3166             :             /* Test if syscall was successful                                */
    3167             :             "cmpwi cr1, 3, 0\n\t"
    3168             :             "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t"
    3169             :             "bne- cr1, 1f\n\t"
    3170             : 
    3171             :             /* Do the function call                                          */
    3172             :             "mtctr 28\n\t"
    3173             :             "mr 3, 27\n\t"
    3174             :             "bctrl\n\t"
    3175             : 
    3176             :             /* Call _exit(r3)                                                */
    3177             :             "li 0, %5\n\t"
    3178             :             "sc\n\t"
    3179             : 
    3180             :             /* Return to parent                                              */
    3181             :             "1:\n"
    3182             :             "mfcr %1\n\t"
    3183             :             "mr %0, 3\n\t"
    3184             :               : "=r" (__ret), "=r" (__err)
    3185             :               : "0" (-1), "1" (EINVAL),
    3186             :                 "i" (__NR_clone), "i" (__NR_exit),
    3187             :                 "r" (__fn), "r" (__cstack), "r" (__flags),
    3188             :                 "r" (__arg), "r" (__ptidptr), "r" (__newtls),
    3189             :                 "r" (__ctidptr)
    3190             :               : "cr0", "cr1", "memory", "ctr",
    3191             :                 "r0", "r29", "r27", "r28");
    3192             :       }
    3193             :       LSS_RETURN(int, __ret, __err);
    3194             :     }
    3195             :   #elif defined(__s390__)
    3196             :     #undef  LSS_REG
    3197             :     #define LSS_REG(r, a) register unsigned long __r##r __asm__("r"#r) = (unsigned long) a
    3198             :     #undef  LSS_BODY
    3199             :     #define LSS_BODY(type, name, args...)                                     \
    3200             :         register unsigned long __nr __asm__("r1")                             \
    3201             :             = (unsigned long)(__NR_##name);                                   \
    3202             :         register long __res_r2 __asm__("r2");                                 \
    3203             :         long __res;                                                           \
    3204             :         __asm__ __volatile__                                                  \
    3205             :             ("svc 0\n\t"                                                      \
    3206             :              : "=d"(__res_r2)                                                 \
    3207             :              : "d"(__nr), ## args                                             \
    3208             :              : "memory");                                                     \
    3209             :         __res = __res_r2;                                                     \
    3210             :         LSS_RETURN(type, __res)
    3211             :     #undef _syscall0
    3212             :     #define _syscall0(type, name)                                             \
    3213             :        type LSS_NAME(name)(void) {                                            \
    3214             :           LSS_BODY(type, name);                                               \
    3215             :        }
    3216             :     #undef _syscall1
    3217             :     #define _syscall1(type, name, type1, arg1)                                \
    3218             :        type LSS_NAME(name)(type1 arg1) {                                      \
    3219             :           LSS_REG(2, arg1);                                                   \
    3220             :           LSS_BODY(type, name, "0"(__r2));                                    \
    3221             :        }
    3222             :     #undef _syscall2
    3223             :     #define _syscall2(type, name, type1, arg1, type2, arg2)                   \
    3224             :        type LSS_NAME(name)(type1 arg1, type2 arg2) {                          \
    3225             :           LSS_REG(2, arg1); LSS_REG(3, arg2);                                 \
    3226             :           LSS_BODY(type, name, "0"(__r2), "d"(__r3));                         \
    3227             :        }
    3228             :     #undef _syscall3
    3229             :     #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \
    3230             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {              \
    3231             :           LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3);               \
    3232             :           LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4));              \
    3233             :        }
    3234             :     #undef _syscall4
    3235             :     #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3236             :                                   type4, arg4)                                \
    3237             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3,                \
    3238             :                            type4 arg4) {                                      \
    3239             :           LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3);               \
    3240             :           LSS_REG(5, arg4);                                                   \
    3241             :           LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4),               \
    3242             :                                "d"(__r5));                                    \
    3243             :        }
    3244             :     #undef _syscall5
    3245             :     #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3246             :                                   type4, arg4, type5, arg5)                   \
    3247             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3,                \
    3248             :                            type4 arg4, type5 arg5) {                          \
    3249             :           LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3);               \
    3250             :           LSS_REG(5, arg4); LSS_REG(6, arg5);                                 \
    3251             :           LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4),               \
    3252             :                                "d"(__r5), "d"(__r6));                         \
    3253             :        }
    3254             :     #undef _syscall6
    3255             :     #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,      \
    3256             :                                   type4, arg4, type5, arg5, type6, arg6)      \
    3257             :        type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3,                \
    3258             :                            type4 arg4, type5 arg5, type6 arg6) {              \
    3259             :           LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3);               \
    3260             :           LSS_REG(5, arg4); LSS_REG(6, arg5); LSS_REG(7, arg6);               \
    3261             :           LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4),               \
    3262             :                                "d"(__r5), "d"(__r6), "d"(__r7));              \
    3263             :        }
    3264             :     LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
    3265             :                                    int flags, void *arg, int *parent_tidptr,
    3266             :                                    void *newtls, int *child_tidptr) {
    3267             :       long __ret;
    3268             :       {
    3269             :         register int  (*__fn)(void *)    __asm__ ("r1")  = fn;
    3270             :         register void  *__cstack         __asm__ ("r2")  = child_stack;
    3271             :         register int    __flags          __asm__ ("r3")  = flags;
    3272             :         register void  *__arg            __asm__ ("r0")  = arg;
    3273             :         register int   *__ptidptr        __asm__ ("r4")  = parent_tidptr;
    3274             :         register void  *__newtls         __asm__ ("r6")  = newtls;
    3275             :         register int   *__ctidptr        __asm__ ("r5")  = child_tidptr;
    3276             :         __asm__ __volatile__ (
    3277             :     #ifndef __s390x__
    3278             :                                   /* arg already in r0 */
    3279             :           "ltr %4, %4\n\t"        /* check fn, which is already in r1 */
    3280             :           "jz 1f\n\t"             /* NULL function pointer, return -EINVAL */
    3281             :           "ltr %5, %5\n\t"        /* check child_stack, which is already in r2 */
    3282             :           "jz 1f\n\t"             /* NULL stack pointer, return -EINVAL */
    3283             :                                   /* flags already in r3 */
    3284             :                                   /* parent_tidptr already in r4 */
    3285             :                                   /* child_tidptr already in r5 */
    3286             :                                   /* newtls already in r6 */
    3287             :           "svc %2\n\t"            /* invoke clone syscall */
    3288             :           "ltr %0,%%r2\n\t"       /* load return code into __ret and test */
    3289             :           "jnz 1f\n\t"            /* return to parent if non-zero */
    3290             :                                   /* start child thread */
    3291             :           "lr %%r2, %7\n\t"       /* set first parameter to void *arg */
    3292             :           "ahi %%r15, -96\n\t"    /* make room on the stack for the save area */
    3293             :           "xc 0(4,%%r15), 0(%%r15)\n\t"
    3294             :           "basr %%r14, %4\n\t"    /* jump to fn */
    3295             :           "svc %3\n"              /* invoke exit syscall */
    3296             :           "1:\n"
    3297             :     #else
    3298             :                                   /* arg already in r0 */
    3299             :           "ltgr %4, %4\n\t"       /* check fn, which is already in r1 */
    3300             :           "jz 1f\n\t"             /* NULL function pointer, return -EINVAL */
    3301             :           "ltgr %5, %5\n\t"       /* check child_stack, which is already in r2 */
    3302             :           "jz 1f\n\t"             /* NULL stack pointer, return -EINVAL */
    3303             :                                   /* flags already in r3 */
    3304             :                                   /* parent_tidptr already in r4 */
    3305             :                                   /* child_tidptr already in r5 */
    3306             :                                   /* newtls already in r6 */
    3307             :           "svc %2\n\t"            /* invoke clone syscall */
    3308             :           "ltgr %0, %%r2\n\t"     /* load return code into __ret and test */
    3309             :           "jnz 1f\n\t"            /* return to parent if non-zero */
    3310             :                                   /* start child thread */
    3311             :           "lgr %%r2, %7\n\t"      /* set first parameter to void *arg */
    3312             :           "aghi %%r15, -160\n\t"  /* make room on the stack for the save area */
    3313             :           "xc 0(8,%%r15), 0(%%r15)\n\t"
    3314             :           "basr %%r14, %4\n\t"    /* jump to fn */
    3315             :           "svc %3\n"              /* invoke exit syscall */
    3316             :           "1:\n"
    3317             :     #endif
    3318             :           : "=r" (__ret)
    3319             :           : "0" (-EINVAL), "i" (__NR_clone), "i" (__NR_exit),
    3320             :             "d" (__fn), "d" (__cstack), "d" (__flags), "d" (__arg),
    3321             :             "d" (__ptidptr), "d" (__newtls), "d" (__ctidptr)
    3322             :           : "cc", "r14", "memory"
    3323             :         );
    3324             :       }
    3325             :       LSS_RETURN(int, __ret);
    3326             :     }
    3327             :   #endif
    3328             :   #define __NR__exit   __NR_exit
    3329             :   #define __NR__gettid __NR_gettid
    3330             :   #define __NR__mremap __NR_mremap
    3331             :   LSS_INLINE _syscall1(void *,  brk,             void *,      e)
    3332             :   LSS_INLINE _syscall1(int,     chdir,           const char *,p)
    3333           0 :   LSS_INLINE _syscall1(int,     close,           int,         f)
    3334             :   LSS_INLINE _syscall2(int,     clock_getres,    int,         c,
    3335             :                        struct kernel_timespec*, t)
    3336             :   LSS_INLINE _syscall2(int,     clock_gettime,   int,         c,
    3337             :                        struct kernel_timespec*, t)
    3338             :   LSS_INLINE _syscall1(int,     dup,             int,         f)
    3339             :   #if !defined(__aarch64__)
    3340             :     // The dup2 syscall has been deprecated on aarch64. We polyfill it below.
    3341             :     LSS_INLINE _syscall2(int,     dup2,            int,         s,
    3342             :                          int,            d)
    3343             :   #endif
    3344             :   LSS_INLINE _syscall3(int,     execve,          const char*, f,
    3345             :                        const char*const*,a,const char*const*, e)
    3346             :   LSS_INLINE _syscall1(int,     _exit,           int,         e)
    3347             :   LSS_INLINE _syscall1(int,     exit_group,      int,         e)
    3348             :   LSS_INLINE _syscall3(int,     fcntl,           int,         f,
    3349             :                        int,            c, long,   a)
    3350             :   #if !defined(__aarch64__)
    3351             :     // The fork syscall has been deprecated on aarch64. We polyfill it below.
    3352           0 :     LSS_INLINE _syscall0(pid_t,   fork)
    3353             :   #endif
    3354           0 :   LSS_INLINE _syscall2(int,     fstat,           int,         f,
    3355             :                       struct kernel_stat*,   b)
    3356             :   LSS_INLINE _syscall2(int,     fstatfs,         int,         f,
    3357             :                       struct kernel_statfs*, b)
    3358             :   #if defined(__x86_64__)
    3359             :     /* Need to make sure off_t isn't truncated to 32-bits under x32.  */
    3360             :     LSS_INLINE int LSS_NAME(ftruncate)(int f, off_t l) {
    3361             :       LSS_BODY(2, int, ftruncate, LSS_SYSCALL_ARG(f), (uint64_t)(l));
    3362             :     }
    3363             :   #else
    3364             :     LSS_INLINE _syscall2(int, ftruncate,           int,         f,
    3365             :                          off_t,          l)
    3366             :   #endif
    3367             :   LSS_INLINE _syscall4(int,     futex,           int*,        a,
    3368             :                        int,            o, int,    v,
    3369             :                       struct kernel_timespec*, t)
    3370           0 :   LSS_INLINE _syscall3(int,     getdents,        int,         f,
    3371             :                        struct kernel_dirent*, d, int,    c)
    3372             :   LSS_INLINE _syscall3(int,     getdents64,      int,         f,
    3373             :                       struct kernel_dirent64*, d, int,    c)
    3374             :   LSS_INLINE _syscall0(gid_t,   getegid)
    3375             :   LSS_INLINE _syscall0(uid_t,   geteuid)
    3376             :   #if !defined(__aarch64__)
    3377             :     // The getgprp syscall has been deprecated on aarch64.
    3378             :     LSS_INLINE _syscall0(pid_t,   getpgrp)
    3379             :   #endif
    3380           0 :   LSS_INLINE _syscall0(pid_t,   getpid)
    3381             :   LSS_INLINE _syscall0(pid_t,   getppid)
    3382             :   LSS_INLINE _syscall2(int,     getpriority,     int,         a,
    3383             :                        int,            b)
    3384             :   LSS_INLINE _syscall3(int,     getresgid,       gid_t *,     r,
    3385             :                        gid_t *,         e,       gid_t *,     s)
    3386             :   LSS_INLINE _syscall3(int,     getresuid,       uid_t *,     r,
    3387             :                        uid_t *,         e,       uid_t *,     s)
    3388             : #if !defined(__ARM_EABI__)
    3389             :   LSS_INLINE _syscall2(int,     getrlimit,       int,         r,
    3390             :                       struct kernel_rlimit*, l)
    3391             : #endif
    3392             :   LSS_INLINE _syscall1(pid_t,   getsid,          pid_t,       p)
    3393           2 :   LSS_INLINE _syscall0(pid_t,   _gettid)
    3394           0 :   LSS_INLINE _syscall2(pid_t,   gettimeofday,    struct kernel_timeval*, t,
    3395             :                        void*, tz)
    3396             :   LSS_INLINE _syscall5(int,     setxattr,        const char *,p,
    3397             :                        const char *,   n,        const void *,v,
    3398             :                        size_t,         s,        int,         f)
    3399             :   LSS_INLINE _syscall5(int,     lsetxattr,       const char *,p,
    3400             :                        const char *,   n,        const void *,v,
    3401             :                        size_t,         s,        int,         f)
    3402             :   LSS_INLINE _syscall4(ssize_t, getxattr,        const char *,p,
    3403             :                        const char *,   n,        void *,      v, size_t, s)
    3404             :   LSS_INLINE _syscall4(ssize_t, lgetxattr,       const char *,p,
    3405             :                        const char *,   n,        void *,      v, size_t, s)
    3406             :   LSS_INLINE _syscall3(ssize_t, listxattr,       const char *,p,
    3407             :                        char *,   l,              size_t,      s)
    3408             :   LSS_INLINE _syscall3(ssize_t, llistxattr,      const char *,p,
    3409             :                        char *,   l,              size_t,      s)
    3410             :   LSS_INLINE _syscall3(int,     ioctl,           int,         d,
    3411             :                        int,     r,               void *,      a)
    3412             :   LSS_INLINE _syscall2(int,     ioprio_get,      int,         which,
    3413             :                        int,     who)
    3414             :   LSS_INLINE _syscall3(int,     ioprio_set,      int,         which,
    3415             :                        int,     who,             int,         ioprio)
    3416             :   LSS_INLINE _syscall2(int,     kill,            pid_t,       p,
    3417             :                        int,            s)
    3418             :   #if defined(__x86_64__)
    3419             :     /* Need to make sure off_t isn't truncated to 32-bits under x32.  */
    3420           0 :     LSS_INLINE off_t LSS_NAME(lseek)(int f, off_t o, int w) {
    3421           0 :       _LSS_BODY(3, off_t, lseek, off_t, LSS_SYSCALL_ARG(f), (uint64_t)(o),
    3422             :                                         LSS_SYSCALL_ARG(w));
    3423             :     }
    3424             :   #else
    3425             :     LSS_INLINE _syscall3(off_t,   lseek,           int,         f,
    3426             :                          off_t,          o, int,    w)
    3427             :   #endif
    3428           0 :   LSS_INLINE _syscall2(int,     munmap,          void*,       s,
    3429             :                        size_t,         l)
    3430             :   LSS_INLINE _syscall6(long,    move_pages,      pid_t,       p,
    3431             :                        unsigned long,  n, void **,g, int *,   d,
    3432             :                        int *,          s, int,    f)
    3433             :   LSS_INLINE _syscall3(int,     mprotect,        const void *,a,
    3434             :                        size_t,         l,        int,         p)
    3435             :   LSS_INLINE _syscall5(void*,   _mremap,         void*,       o,
    3436             :                        size_t,         os,       size_t,      ns,
    3437             :                        unsigned long,  f, void *, a)
    3438             :   #if !defined(__aarch64__)
    3439             :     // The open and poll syscalls have been deprecated on aarch64. We polyfill
    3440             :     // them below.
    3441           0 :     LSS_INLINE _syscall3(int,     open,            const char*, p,
    3442             :                          int,            f, int,    m)
    3443             :     LSS_INLINE _syscall3(int,     poll,           struct kernel_pollfd*, u,
    3444             :                          unsigned int,   n, int,    t)
    3445             :   #endif
    3446           0 :   LSS_INLINE _syscall5(int,     prctl,           int,         option,
    3447             :                        unsigned long,  arg2,
    3448             :                        unsigned long,  arg3,
    3449             :                        unsigned long,  arg4,
    3450             :                        unsigned long,  arg5)
    3451           0 :   LSS_INLINE _syscall4(long,    ptrace,          int,         r,
    3452             :                        pid_t,          p, void *, a, void *, d)
    3453             :   #if defined(__NR_quotactl)
    3454             :     // Defined on x86_64 / i386 only
    3455             :     LSS_INLINE _syscall4(int,  quotactl,  int,  cmd,  const char *, special,
    3456             :                          int, id, caddr_t, addr)
    3457             :   #endif
    3458           0 :   LSS_INLINE _syscall3(ssize_t, read,            int,         f,
    3459             :                        void *,         b, size_t, c)
    3460             :   #if !defined(__aarch64__)
    3461             :     // The readlink syscall has been deprecated on aarch64. We polyfill below.
    3462           0 :     LSS_INLINE _syscall3(int,     readlink,        const char*, p,
    3463             :                          char*,          b, size_t, s)
    3464             :   #endif
    3465             :   LSS_INLINE _syscall4(int,     rt_sigaction,    int,         s,
    3466             :                        const struct kernel_sigaction*, a,
    3467             :                        struct kernel_sigaction*, o, size_t,   c)
    3468             :   LSS_INLINE _syscall2(int, rt_sigpending, struct kernel_sigset_t *, s,
    3469             :                        size_t,         c)
    3470             :   LSS_INLINE _syscall4(int, rt_sigprocmask,      int,         h,
    3471             :                        const struct kernel_sigset_t*,  s,
    3472             :                        struct kernel_sigset_t*,        o, size_t, c)
    3473             :   LSS_INLINE _syscall2(int, rt_sigsuspend,
    3474             :                        const struct kernel_sigset_t*, s,  size_t, c)
    3475             :   LSS_INLINE _syscall3(int,     sched_getaffinity,pid_t,      p,
    3476             :                        unsigned int,   l, unsigned long *, m)
    3477             :   LSS_INLINE _syscall3(int,     sched_setaffinity,pid_t,      p,
    3478             :                        unsigned int,   l, unsigned long *, m)
    3479             :   LSS_INLINE _syscall0(int,     sched_yield)
    3480             :   LSS_INLINE _syscall1(long,    set_tid_address, int *,       t)
    3481             :   LSS_INLINE _syscall1(int,     setfsgid,        gid_t,       g)
    3482             :   LSS_INLINE _syscall1(int,     setfsuid,        uid_t,       u)
    3483             :   LSS_INLINE _syscall1(int,     setuid,          uid_t,       u)
    3484             :   LSS_INLINE _syscall1(int,     setgid,          gid_t,       g)
    3485             :   LSS_INLINE _syscall2(int,     setpgid,         pid_t,       p,
    3486             :                        pid_t,          g)
    3487             :   LSS_INLINE _syscall3(int,     setpriority,     int,         a,
    3488             :                        int,            b, int,    p)
    3489             :   LSS_INLINE _syscall3(int,     setresgid,       gid_t,       r,
    3490             :                        gid_t,          e, gid_t,  s)
    3491             :   LSS_INLINE _syscall3(int,     setresuid,       uid_t,       r,
    3492             :                        uid_t,          e, uid_t,  s)
    3493             :   LSS_INLINE _syscall2(int,     setrlimit,       int,         r,
    3494             :                        const struct kernel_rlimit*, l)
    3495             :   LSS_INLINE _syscall0(pid_t,    setsid)
    3496           0 :   LSS_INLINE _syscall2(int,     sigaltstack,     const stack_t*, s,
    3497             :                        const stack_t*, o)
    3498             :   #if defined(__NR_sigreturn)
    3499             :     LSS_INLINE _syscall1(int,     sigreturn,       unsigned long, u)
    3500             :   #endif
    3501             :   #if !defined(__aarch64__)
    3502             :     // The stat syscall has been deprecated on aarch64. We polyfill it below.
    3503           0 :     LSS_INLINE _syscall2(int,     stat,            const char*, f,
    3504             :                         struct kernel_stat*,   b)
    3505             :   #endif
    3506             :   LSS_INLINE _syscall2(int,     statfs,          const char*, f,
    3507             :                       struct kernel_statfs*, b)
    3508             :   LSS_INLINE _syscall3(int,     tgkill,          pid_t,       p,
    3509             :                        pid_t,          t, int,            s)
    3510             :   LSS_INLINE _syscall2(int,     tkill,           pid_t,       p,
    3511             :                        int,            s)
    3512             :   #if !defined(__aarch64__)
    3513             :     // The unlink syscall has been deprecated on aarch64. We polyfill it below.
    3514             :     LSS_INLINE _syscall1(int,     unlink,           const char*, f)
    3515             :   #endif
    3516           0 :   LSS_INLINE _syscall3(ssize_t, write,            int,        f,
    3517             :                        const void *,   b, size_t, c)
    3518             :   LSS_INLINE _syscall3(ssize_t, writev,           int,        f,
    3519             :                        const struct kernel_iovec*, v, size_t, c)
    3520             :   #if defined(__NR_getcpu)
    3521             :     LSS_INLINE _syscall3(long, getcpu, unsigned *, cpu,
    3522             :                          unsigned *, node, void *, unused)
    3523             :   #endif
    3524             :   #if defined(__x86_64__) ||                                                  \
    3525             :      (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32)
    3526             :     LSS_INLINE _syscall3(int, recvmsg,            int,   s,
    3527             :                         struct kernel_msghdr*,     m, int, f)
    3528           0 :     LSS_INLINE _syscall3(int, sendmsg,            int,   s,
    3529             :                          const struct kernel_msghdr*, m, int, f)
    3530             :     LSS_INLINE _syscall6(int, sendto,             int,   s,
    3531             :                          const void*,             m, size_t, l,
    3532             :                          int,                     f,
    3533             :                          const struct kernel_sockaddr*, a, int, t)
    3534             :     LSS_INLINE _syscall2(int, shutdown,           int,   s,
    3535             :                          int,                     h)
    3536             :     LSS_INLINE _syscall3(int, socket,             int,   d,
    3537             :                          int,                     t, int,       p)
    3538             :     LSS_INLINE _syscall4(int, socketpair,         int,   d,
    3539             :                          int,                     t, int,       p, int*, s)
    3540             :   #endif
    3541             :   #if defined(__NR_fadvise64)
    3542             :     #if defined(__x86_64__)
    3543             :     /* Need to make sure loff_t isn't truncated to 32-bits under x32.  */
    3544             :     LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, loff_t len,
    3545             :                                        int advice) {
    3546             :       LSS_BODY(4, int, fadvise64, LSS_SYSCALL_ARG(fd), (uint64_t)(offset),
    3547             :                                   (uint64_t)(len), LSS_SYSCALL_ARG(advice));
    3548             :     }
    3549             :     #else
    3550             :     LSS_INLINE _syscall4(int, fadvise64,
    3551             :                          int, fd, loff_t, offset, loff_t, len, int, advice)
    3552             :     #endif
    3553             :   #elif defined(__i386__)
    3554             :     #define __NR__fadvise64_64 __NR_fadvise64_64
    3555             :     LSS_INLINE _syscall6(int, _fadvise64_64, int, fd,
    3556             :                          unsigned, offset_lo, unsigned, offset_hi,
    3557             :                          unsigned, len_lo, unsigned, len_hi,
    3558             :                          int, advice)
    3559             : 
    3560             :     LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset,
    3561             :                                        loff_t len, int advice) {
    3562             :       return LSS_NAME(_fadvise64_64)(fd,
    3563             :                                      (unsigned)offset, (unsigned)(offset >>32),
    3564             :                                      (unsigned)len, (unsigned)(len >> 32),
    3565             :                                      advice);
    3566             :     }
    3567             : 
    3568             :   #elif defined(__s390__) && !defined(__s390x__)
    3569             :     #define __NR__fadvise64_64 __NR_fadvise64_64
    3570             :     struct kernel_fadvise64_64_args {
    3571             :       int fd;
    3572             :       long long offset;
    3573             :       long long len;
    3574             :       int advice;
    3575             :     };
    3576             : 
    3577             :     LSS_INLINE _syscall1(int, _fadvise64_64,
    3578             :                          struct kernel_fadvise64_64_args *args)
    3579             : 
    3580             :     LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset,
    3581             :                                        loff_t len, int advice) {
    3582             :       struct kernel_fadvise64_64_args args = { fd, offset, len, advice };
    3583             :       return LSS_NAME(_fadvise64_64)(&args);
    3584             :     }
    3585             :   #endif
    3586             :   #if defined(__NR_fallocate)
    3587             :     #if defined(__x86_64__)
    3588             :     /* Need to make sure loff_t isn't truncated to 32-bits under x32.  */
    3589             :     LSS_INLINE int LSS_NAME(fallocate)(int f, int mode, loff_t offset,
    3590             :                                        loff_t len) {
    3591             :       LSS_BODY(4, int, fallocate, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(mode),
    3592             :                                   (uint64_t)(offset), (uint64_t)(len));
    3593             :     }
    3594             :     #elif defined(__i386__) || (defined(__s390__) && !defined(__s390x__))
    3595             :     #define __NR__fallocate __NR_fallocate
    3596             :     LSS_INLINE _syscall6(int, _fallocate, int, fd,
    3597             :                          int, mode,
    3598             :                          unsigned, offset_lo, unsigned, offset_hi,
    3599             :                          unsigned, len_lo, unsigned, len_hi)
    3600             : 
    3601             :     LSS_INLINE int LSS_NAME(fallocate)(int fd, int mode,
    3602             :                                        loff_t offset, loff_t len) {
    3603             :       union { loff_t off; unsigned w[2]; } o = { offset }, l = { len };
    3604             :       return LSS_NAME(_fallocate)(fd, mode, o.w[0], o.w[1], l.w[0], l.w[1]);
    3605             :     }
    3606             :     #else
    3607             :     LSS_INLINE _syscall4(int, fallocate,
    3608             :                          int, f, int, mode, loff_t, offset, loff_t, len)
    3609             :     #endif
    3610             :   #endif
    3611             :   #if defined(__x86_64__) || defined(__s390x__)
    3612             :     LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
    3613             :                                          gid_t *egid,
    3614             :                                          gid_t *sgid) {
    3615             :       return LSS_NAME(getresgid)(rgid, egid, sgid);
    3616             :     }
    3617             : 
    3618             :     LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
    3619             :                                          uid_t *euid,
    3620             :                                          uid_t *suid) {
    3621             :       return LSS_NAME(getresuid)(ruid, euid, suid);
    3622             :     }
    3623             :     LSS_INLINE _syscall4(int, newfstatat,         int,   d,
    3624             :                          const char *,            p,
    3625             :                         struct kernel_stat*,       b, int, f)
    3626             : 
    3627             :     LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
    3628             :       return LSS_NAME(setfsgid)(gid);
    3629             :     }
    3630             : 
    3631             :     LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
    3632             :       return LSS_NAME(setfsuid)(uid);
    3633             :     }
    3634             : 
    3635             :     LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
    3636             :       return LSS_NAME(setresgid)(rgid, egid, sgid);
    3637             :     }
    3638             : 
    3639             :     LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
    3640             :       return LSS_NAME(setresuid)(ruid, euid, suid);
    3641             :     }
    3642             : 
    3643             :     LSS_INLINE int LSS_NAME(sigaction)(int signum,
    3644             :                                        const struct kernel_sigaction *act,
    3645             :                                        struct kernel_sigaction *oldact) {
    3646             :       #if defined(__x86_64__)
    3647             :       /* On x86_64, the kernel requires us to always set our own
    3648             :        * SA_RESTORER in order to be able to return from a signal handler.
    3649             :        * This function must have a "magic" signature that the "gdb"
    3650             :        * (and maybe the kernel?) can recognize.
    3651             :        */
    3652             :       if (act != NULL && !(act->sa_flags & SA_RESTORER)) {
    3653             :         struct kernel_sigaction a = *act;
    3654             :         a.sa_flags   |= SA_RESTORER;
    3655             :         a.sa_restorer = LSS_NAME(restore_rt)();
    3656             :         return LSS_NAME(rt_sigaction)(signum, &a, oldact,
    3657             :                                       (KERNEL_NSIG+7)/8);
    3658             :       } else
    3659             :       #endif
    3660             :         return LSS_NAME(rt_sigaction)(signum, act, oldact,
    3661             :                                       (KERNEL_NSIG+7)/8);
    3662             :     }
    3663             : 
    3664             :     LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
    3665             :       return LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
    3666             :     }
    3667             : 
    3668             :     LSS_INLINE int LSS_NAME(sigprocmask)(int how,
    3669             :                                          const struct kernel_sigset_t *set,
    3670             :                                          struct kernel_sigset_t *oldset) {
    3671             :       return LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
    3672             :     }
    3673             : 
    3674             :     LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
    3675             :       return LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
    3676             :     }
    3677             :   #endif
    3678             :   #if defined(__x86_64__) || defined(__ARM_ARCH_3__) ||                       \
    3679             :       defined(__ARM_EABI__) || defined(__aarch64__) ||                        \
    3680             :      (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32) ||                   \
    3681             :       defined(__s390__)
    3682           0 :     LSS_INLINE _syscall4(pid_t, wait4,            pid_t, p,
    3683             :                          int*,                    s, int,       o,
    3684             :                         struct kernel_rusage*,     r)
    3685             : 
    3686           0 :     LSS_INLINE pid_t LSS_NAME(waitpid)(pid_t pid, int *status, int options){
    3687           0 :       return LSS_NAME(wait4)(pid, status, options, 0);
    3688             :     }
    3689             :   #endif
    3690             :   #if defined(__NR_openat)
    3691             :     LSS_INLINE _syscall4(int, openat, int, d, const char *, p, int, f, int, m)
    3692             :   #endif
    3693             :   #if defined(__NR_unlinkat)
    3694             :     LSS_INLINE _syscall3(int, unlinkat, int, d, const char *, p, int, f)
    3695             :   #endif
    3696             :   #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
    3697             :       (defined(__s390__) && !defined(__s390x__))
    3698             :     #define __NR__getresgid32 __NR_getresgid32
    3699             :     #define __NR__getresuid32 __NR_getresuid32
    3700             :     #define __NR__setfsgid32  __NR_setfsgid32
    3701             :     #define __NR__setfsuid32  __NR_setfsuid32
    3702             :     #define __NR__setresgid32 __NR_setresgid32
    3703             :     #define __NR__setresuid32 __NR_setresuid32
    3704             : #if defined(__ARM_EABI__)
    3705             :     LSS_INLINE _syscall2(int,   ugetrlimit,        int,          r,
    3706             :                         struct kernel_rlimit*, l)
    3707             : #endif
    3708             :     LSS_INLINE _syscall3(int,     _getresgid32,    gid_t *,      r,
    3709             :                          gid_t *,            e,    gid_t *,      s)
    3710             :     LSS_INLINE _syscall3(int,     _getresuid32,    uid_t *,      r,
    3711             :                          uid_t *,            e,    uid_t *,      s)
    3712             :     LSS_INLINE _syscall1(int,     _setfsgid32,     gid_t,        f)
    3713             :     LSS_INLINE _syscall1(int,     _setfsuid32,     uid_t,        f)
    3714             :     LSS_INLINE _syscall3(int,     _setresgid32,    gid_t,        r,
    3715             :                          gid_t,              e,    gid_t,        s)
    3716             :     LSS_INLINE _syscall3(int,     _setresuid32,    uid_t,        r,
    3717             :                          uid_t,              e,    uid_t,        s)
    3718             : 
    3719             :     LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
    3720             :                                          gid_t *egid,
    3721             :                                          gid_t *sgid) {
    3722             :       int rc;
    3723             :       if ((rc = LSS_NAME(_getresgid32)(rgid, egid, sgid)) < 0 &&
    3724             :           LSS_ERRNO == ENOSYS) {
    3725             :         if ((rgid == NULL) || (egid == NULL) || (sgid == NULL)) {
    3726             :           return EFAULT;
    3727             :         }
    3728             :         // Clear the high bits first, since getresgid only sets 16 bits
    3729             :         *rgid = *egid = *sgid = 0;
    3730             :         rc = LSS_NAME(getresgid)(rgid, egid, sgid);
    3731             :       }
    3732             :       return rc;
    3733             :     }
    3734             : 
    3735             :     LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
    3736             :                                          uid_t *euid,
    3737             :                                          uid_t *suid) {
    3738             :       int rc;
    3739             :       if ((rc = LSS_NAME(_getresuid32)(ruid, euid, suid)) < 0 &&
    3740             :           LSS_ERRNO == ENOSYS) {
    3741             :         if ((ruid == NULL) || (euid == NULL) || (suid == NULL)) {
    3742             :           return EFAULT;
    3743             :         }
    3744             :         // Clear the high bits first, since getresuid only sets 16 bits
    3745             :         *ruid = *euid = *suid = 0;
    3746             :         rc = LSS_NAME(getresuid)(ruid, euid, suid);
    3747             :       }
    3748             :       return rc;
    3749             :     }
    3750             : 
    3751             :     LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
    3752             :       int rc;
    3753             :       if ((rc = LSS_NAME(_setfsgid32)(gid)) < 0 &&
    3754             :           LSS_ERRNO == ENOSYS) {
    3755             :         if ((unsigned int)gid & ~0xFFFFu) {
    3756             :           rc = EINVAL;
    3757             :         } else {
    3758             :           rc = LSS_NAME(setfsgid)(gid);
    3759             :         }
    3760             :       }
    3761             :       return rc;
    3762             :     }
    3763             : 
    3764             :     LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
    3765             :       int rc;
    3766             :       if ((rc = LSS_NAME(_setfsuid32)(uid)) < 0 &&
    3767             :           LSS_ERRNO == ENOSYS) {
    3768             :         if ((unsigned int)uid & ~0xFFFFu) {
    3769             :           rc = EINVAL;
    3770             :         } else {
    3771             :           rc = LSS_NAME(setfsuid)(uid);
    3772             :         }
    3773             :       }
    3774             :       return rc;
    3775             :     }
    3776             : 
    3777             :     LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
    3778             :       int rc;
    3779             :       if ((rc = LSS_NAME(_setresgid32)(rgid, egid, sgid)) < 0 &&
    3780             :           LSS_ERRNO == ENOSYS) {
    3781             :         if ((unsigned int)rgid & ~0xFFFFu ||
    3782             :             (unsigned int)egid & ~0xFFFFu ||
    3783             :             (unsigned int)sgid & ~0xFFFFu) {
    3784             :           rc = EINVAL;
    3785             :         } else {
    3786             :           rc = LSS_NAME(setresgid)(rgid, egid, sgid);
    3787             :         }
    3788             :       }
    3789             :       return rc;
    3790             :     }
    3791             : 
    3792             :     LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
    3793             :       int rc;
    3794             :       if ((rc = LSS_NAME(_setresuid32)(ruid, euid, suid)) < 0 &&
    3795             :           LSS_ERRNO == ENOSYS) {
    3796             :         if ((unsigned int)ruid & ~0xFFFFu ||
    3797             :             (unsigned int)euid & ~0xFFFFu ||
    3798             :             (unsigned int)suid & ~0xFFFFu) {
    3799             :           rc = EINVAL;
    3800             :         } else {
    3801             :           rc = LSS_NAME(setresuid)(ruid, euid, suid);
    3802             :         }
    3803             :       }
    3804             :       return rc;
    3805             :     }
    3806             :   #endif
    3807             :   LSS_INLINE int LSS_NAME(sigemptyset)(struct kernel_sigset_t *set) {
    3808             :     memset(&set->sig, 0, sizeof(set->sig));
    3809             :     return 0;
    3810             :   }
    3811             : 
    3812             :   LSS_INLINE int LSS_NAME(sigfillset)(struct kernel_sigset_t *set) {
    3813             :     memset(&set->sig, -1, sizeof(set->sig));
    3814             :     return 0;
    3815             :   }
    3816             : 
    3817             :   LSS_INLINE int LSS_NAME(sigaddset)(struct kernel_sigset_t *set,
    3818             :                                      int signum) {
    3819             :     if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
    3820             :       LSS_ERRNO = EINVAL;
    3821             :       return -1;
    3822             :     } else {
    3823             :       set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
    3824             :           |= 1UL << ((signum - 1) % (8*sizeof(set->sig[0])));
    3825             :       return 0;
    3826             :     }
    3827             :   }
    3828             : 
    3829             :   LSS_INLINE int LSS_NAME(sigdelset)(struct kernel_sigset_t *set,
    3830             :                                         int signum) {
    3831             :     if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
    3832             :       LSS_ERRNO = EINVAL;
    3833             :       return -1;
    3834             :     } else {
    3835             :       set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
    3836             :           &= ~(1UL << ((signum - 1) % (8*sizeof(set->sig[0]))));
    3837             :       return 0;
    3838             :     }
    3839             :   }
    3840             : 
    3841             :   LSS_INLINE int LSS_NAME(sigismember)(struct kernel_sigset_t *set,
    3842             :                                           int signum) {
    3843             :     if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
    3844             :       LSS_ERRNO = EINVAL;
    3845             :       return -1;
    3846             :     } else {
    3847             :       return !!(set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] &
    3848             :                 (1UL << ((signum - 1) % (8*sizeof(set->sig[0])))));
    3849             :     }
    3850             :   }
    3851             :   #if defined(__i386__) ||                                                    \
    3852             :       defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) ||                     \
    3853             :      (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) ||                   \
    3854             :       defined(__PPC__) ||                                                     \
    3855             :      (defined(__s390__) && !defined(__s390x__))
    3856             :     #define __NR__sigaction   __NR_sigaction
    3857             :     #define __NR__sigpending  __NR_sigpending
    3858             :     #define __NR__sigprocmask __NR_sigprocmask
    3859             :     #define __NR__sigsuspend  __NR_sigsuspend
    3860             :     #define __NR__socketcall  __NR_socketcall
    3861             :     LSS_INLINE _syscall2(int, fstat64,             int, f,
    3862             :                          struct kernel_stat64 *, b)
    3863             :     LSS_INLINE _syscall5(int, _llseek,     uint, fd,
    3864             :                          unsigned long, hi, unsigned long, lo,
    3865             :                          loff_t *, res, uint, wh)
    3866             : #if defined(__s390__) && !defined(__s390x__)
    3867             :     /* On s390, mmap2() arguments are passed in memory. */
    3868             :     LSS_INLINE void* LSS_NAME(_mmap2)(void *s, size_t l, int p, int f, int d,
    3869             :                                       off_t o) {
    3870             :       unsigned long buf[6] = { (unsigned long) s, (unsigned long) l,
    3871             :                                (unsigned long) p, (unsigned long) f,
    3872             :                                (unsigned long) d, (unsigned long) o };
    3873             :       LSS_REG(2, buf);
    3874             :       LSS_BODY(void*, mmap2, "0"(__r2));
    3875             :     }
    3876             : #else
    3877             :     #define __NR__mmap2 __NR_mmap2
    3878             :     LSS_INLINE _syscall6(void*, _mmap2,            void*, s,
    3879             :                          size_t,                   l, int,               p,
    3880             :                          int,                      f, int,               d,
    3881             :                          off_t,                    o)
    3882             : #endif
    3883             :     LSS_INLINE _syscall3(int,   _sigaction,        int,   s,
    3884             :                          const struct kernel_old_sigaction*,  a,
    3885             :                          struct kernel_old_sigaction*,        o)
    3886             :     LSS_INLINE _syscall1(int,   _sigpending, unsigned long*, s)
    3887             :     LSS_INLINE _syscall3(int,   _sigprocmask,      int,   h,
    3888             :                          const unsigned long*,     s,
    3889             :                          unsigned long*,           o)
    3890             :     #ifdef __PPC__
    3891             :     LSS_INLINE _syscall1(int, _sigsuspend,         unsigned long, s)
    3892             :     #else
    3893             :     LSS_INLINE _syscall3(int, _sigsuspend,         const void*, a,
    3894             :                          int,                      b,
    3895             :                          unsigned long,            s)
    3896             :     #endif
    3897             :     LSS_INLINE _syscall2(int, stat64,              const char *, p,
    3898             :                          struct kernel_stat64 *, b)
    3899             : 
    3900             :     LSS_INLINE int LSS_NAME(sigaction)(int signum,
    3901             :                                        const struct kernel_sigaction *act,
    3902             :                                        struct kernel_sigaction *oldact) {
    3903             :       int old_errno = LSS_ERRNO;
    3904             :       int rc;
    3905             :       struct kernel_sigaction a;
    3906             :       if (act != NULL) {
    3907             :         a             = *act;
    3908             :         #ifdef __i386__
    3909             :         /* On i386, the kernel requires us to always set our own
    3910             :          * SA_RESTORER when using realtime signals. Otherwise, it does not
    3911             :          * know how to return from a signal handler. This function must have
    3912             :          * a "magic" signature that the "gdb" (and maybe the kernel?) can
    3913             :          * recognize.
    3914             :          * Apparently, a SA_RESTORER is implicitly set by the kernel, when
    3915             :          * using non-realtime signals.
    3916             :          *
    3917             :          * TODO: Test whether ARM needs a restorer
    3918             :          */
    3919             :         if (!(a.sa_flags & SA_RESTORER)) {
    3920             :           a.sa_flags   |= SA_RESTORER;
    3921             :           a.sa_restorer = (a.sa_flags & SA_SIGINFO)
    3922             :                           ? LSS_NAME(restore_rt)() : LSS_NAME(restore)();
    3923             :         }
    3924             :         #endif
    3925             :       }
    3926             :       rc = LSS_NAME(rt_sigaction)(signum, act ? &a : act, oldact,
    3927             :                                   (KERNEL_NSIG+7)/8);
    3928             :       if (rc < 0 && LSS_ERRNO == ENOSYS) {
    3929             :         struct kernel_old_sigaction oa, ooa, *ptr_a = &oa, *ptr_oa = &ooa;
    3930             :         if (!act) {
    3931             :           ptr_a            = NULL;
    3932             :         } else {
    3933             :           oa.sa_handler_   = act->sa_handler_;
    3934             :           memcpy(&oa.sa_mask, &act->sa_mask, sizeof(oa.sa_mask));
    3935             :           #ifndef __mips__
    3936             :           oa.sa_restorer   = act->sa_restorer;
    3937             :           #endif
    3938             :           oa.sa_flags      = act->sa_flags;
    3939             :         }
    3940             :         if (!oldact) {
    3941             :           ptr_oa           = NULL;
    3942             :         }
    3943             :         LSS_ERRNO = old_errno;
    3944             :         rc = LSS_NAME(_sigaction)(signum, ptr_a, ptr_oa);
    3945             :         if (rc == 0 && oldact) {
    3946             :           if (act) {
    3947             :             memcpy(oldact, act, sizeof(*act));
    3948             :           } else {
    3949             :             memset(oldact, 0, sizeof(*oldact));
    3950             :           }
    3951             :           oldact->sa_handler_    = ptr_oa->sa_handler_;
    3952             :           oldact->sa_flags       = ptr_oa->sa_flags;
    3953             :           memcpy(&oldact->sa_mask, &ptr_oa->sa_mask, sizeof(ptr_oa->sa_mask));
    3954             :           #ifndef __mips__
    3955             :           oldact->sa_restorer    = ptr_oa->sa_restorer;
    3956             :           #endif
    3957             :         }
    3958             :       }
    3959             :       return rc;
    3960             :     }
    3961             : 
    3962             :     LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
    3963             :       int old_errno = LSS_ERRNO;
    3964             :       int rc = LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
    3965             :       if (rc < 0 && LSS_ERRNO == ENOSYS) {
    3966             :         LSS_ERRNO = old_errno;
    3967             :         LSS_NAME(sigemptyset)(set);
    3968             :         rc = LSS_NAME(_sigpending)(&set->sig[0]);
    3969             :       }
    3970             :       return rc;
    3971             :     }
    3972             : 
    3973             :     LSS_INLINE int LSS_NAME(sigprocmask)(int how,
    3974             :                                          const struct kernel_sigset_t *set,
    3975             :                                          struct kernel_sigset_t *oldset) {
    3976             :       int olderrno = LSS_ERRNO;
    3977             :       int rc = LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
    3978             :       if (rc < 0 && LSS_ERRNO == ENOSYS) {
    3979             :         LSS_ERRNO = olderrno;
    3980             :         if (oldset) {
    3981             :           LSS_NAME(sigemptyset)(oldset);
    3982             :         }
    3983             :         rc = LSS_NAME(_sigprocmask)(how,
    3984             :                                     set ? &set->sig[0] : NULL,
    3985             :                                     oldset ? &oldset->sig[0] : NULL);
    3986             :       }
    3987             :       return rc;
    3988             :     }
    3989             : 
    3990             :     LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
    3991             :       int olderrno = LSS_ERRNO;
    3992             :       int rc = LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
    3993             :       if (rc < 0 && LSS_ERRNO == ENOSYS) {
    3994             :         LSS_ERRNO = olderrno;
    3995             :         rc = LSS_NAME(_sigsuspend)(
    3996             :         #ifndef __PPC__
    3997             :                                    set, 0,
    3998             :         #endif
    3999             :                                    set->sig[0]);
    4000             :       }
    4001             :       return rc;
    4002             :     }
    4003             :   #endif
    4004             :   #if defined(__i386__) ||                                                    \
    4005             :       defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) ||                     \
    4006             :      (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) ||                   \
    4007             :       defined(__PPC__) ||                                                     \
    4008             :      (defined(__s390__) && !defined(__s390x__))
    4009             :     /* On these architectures, implement mmap() with mmap2(). */
    4010             :     LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
    4011             :                                     int64_t o) {
    4012             :       if (o % 4096) {
    4013             :         LSS_ERRNO = EINVAL;
    4014             :         return (void *) -1;
    4015             :       }
    4016             :       return LSS_NAME(_mmap2)(s, l, p, f, d, (o / 4096));
    4017             :     }
    4018             :   #elif defined(__s390x__)
    4019             :     /* On s390x, mmap() arguments are passed in memory. */
    4020             :     LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
    4021             :                                     int64_t o) {
    4022             :       unsigned long buf[6] = { (unsigned long) s, (unsigned long) l,
    4023             :                                (unsigned long) p, (unsigned long) f,
    4024             :                                (unsigned long) d, (unsigned long) o };
    4025             :       LSS_REG(2, buf);
    4026             :       LSS_BODY(void*, mmap, "0"(__r2));
    4027             :     }
    4028             :   #elif defined(__x86_64__)
    4029             :     /* Need to make sure __off64_t isn't truncated to 32-bits under x32.  */
    4030           0 :     LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
    4031             :                                     int64_t o) {
    4032           0 :       LSS_BODY(6, void*, mmap, LSS_SYSCALL_ARG(s), LSS_SYSCALL_ARG(l),
    4033             :                                LSS_SYSCALL_ARG(p), LSS_SYSCALL_ARG(f),
    4034             :                                LSS_SYSCALL_ARG(d), (uint64_t)(o));
    4035             :     }
    4036             :   #else
    4037             :     /* Remaining 64-bit architectures. */
    4038             :     LSS_INLINE _syscall6(void*, mmap, void*, addr, size_t, length, int, prot,
    4039             :                          int, flags, int, fd, int64_t, offset)
    4040             :   #endif
    4041             :   #if defined(__PPC__)
    4042             :     #undef LSS_SC_LOADARGS_0
    4043             :     #define LSS_SC_LOADARGS_0(dummy...)
    4044             :     #undef LSS_SC_LOADARGS_1
    4045             :     #define LSS_SC_LOADARGS_1(arg1)                                           \
    4046             :         __sc_4  = (unsigned long) (arg1)
    4047             :     #undef LSS_SC_LOADARGS_2
    4048             :     #define LSS_SC_LOADARGS_2(arg1, arg2)                                     \
    4049             :         LSS_SC_LOADARGS_1(arg1);                                              \
    4050             :         __sc_5  = (unsigned long) (arg2)
    4051             :     #undef LSS_SC_LOADARGS_3
    4052             :     #define LSS_SC_LOADARGS_3(arg1, arg2, arg3)                               \
    4053             :         LSS_SC_LOADARGS_2(arg1, arg2);                                        \
    4054             :         __sc_6  = (unsigned long) (arg3)
    4055             :     #undef LSS_SC_LOADARGS_4
    4056             :     #define LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4)                         \
    4057             :         LSS_SC_LOADARGS_3(arg1, arg2, arg3);                                  \
    4058             :         __sc_7  = (unsigned long) (arg4)
    4059             :     #undef LSS_SC_LOADARGS_5
    4060             :     #define LSS_SC_LOADARGS_5(arg1, arg2, arg3, arg4, arg5)                   \
    4061             :         LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4);                            \
    4062             :         __sc_8  = (unsigned long) (arg5)
    4063             :     #undef LSS_SC_BODY
    4064             :     #define LSS_SC_BODY(nr, type, opt, args...)                               \
    4065             :         long __sc_ret, __sc_err;                                              \
    4066             :         {                                                                     \
    4067             :           register unsigned long __sc_0 __asm__ ("r0") = __NR_socketcall;     \
    4068             :           register unsigned long __sc_3 __asm__ ("r3") = opt;                 \
    4069             :           register unsigned long __sc_4 __asm__ ("r4");                       \
    4070             :           register unsigned long __sc_5 __asm__ ("r5");                       \
    4071             :           register unsigned long __sc_6 __asm__ ("r6");                       \
    4072             :           register unsigned long __sc_7 __asm__ ("r7");                       \
    4073             :           register unsigned long __sc_8 __asm__ ("r8");                       \
    4074             :           LSS_SC_LOADARGS_##nr(args);                                         \
    4075             :           __asm__ __volatile__                                                \
    4076             :               ("stwu 1, -48(1)\n\t"                                           \
    4077             :                "stw 4, 20(1)\n\t"                                             \
    4078             :                "stw 5, 24(1)\n\t"                                             \
    4079             :                "stw 6, 28(1)\n\t"                                             \
    4080             :                "stw 7, 32(1)\n\t"                                             \
    4081             :                "stw 8, 36(1)\n\t"                                             \
    4082             :                "addi 4, 1, 20\n\t"                                            \
    4083             :                "sc\n\t"                                                       \
    4084             :                "mfcr %0"                                                      \
    4085             :                  : "=&r" (__sc_0),                                            \
    4086             :                    "=&r" (__sc_3), "=&r" (__sc_4),                            \
    4087             :                    "=&r" (__sc_5), "=&r" (__sc_6),                            \
    4088             :                    "=&r" (__sc_7), "=&r" (__sc_8)                             \
    4089             :                  : LSS_ASMINPUT_##nr                                          \
    4090             :                  : "cr0", "ctr", "memory");                                   \
    4091             :           __sc_ret = __sc_3;                                                  \
    4092             :           __sc_err = __sc_0;                                                  \
    4093             :         }                                                                     \
    4094             :         LSS_RETURN(type, __sc_ret, __sc_err)
    4095             : 
    4096             :     LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
    4097             :                                          int flags){
    4098             :       LSS_SC_BODY(3, ssize_t, 17, s, msg, flags);
    4099             :     }
    4100             : 
    4101             :     LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
    4102             :                                          const struct kernel_msghdr *msg,
    4103             :                                          int flags) {
    4104             :       LSS_SC_BODY(3, ssize_t, 16, s, msg, flags);
    4105             :     }
    4106             : 
    4107             :     // TODO(csilvers): why is this ifdef'ed out?
    4108             : #if 0
    4109             :     LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
    4110             :                                         int flags,
    4111             :                                         const struct kernel_sockaddr *to,
    4112             :                                         unsigned int tolen) {
    4113             :       LSS_BODY(6, ssize_t, 11, s, buf, len, flags, to, tolen);
    4114             :     }
    4115             : #endif
    4116             : 
    4117             :     LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
    4118             :       LSS_SC_BODY(2, int, 13, s, how);
    4119             :     }
    4120             : 
    4121             :     LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
    4122             :       LSS_SC_BODY(3, int, 1, domain, type, protocol);
    4123             :     }
    4124             : 
    4125             :     LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
    4126             :                                         int sv[2]) {
    4127             :       LSS_SC_BODY(4, int, 8, d, type, protocol, sv);
    4128             :     }
    4129             :   #endif
    4130             :   #if defined(__ARM_EABI__) || defined (__aarch64__)
    4131             :     LSS_INLINE _syscall3(ssize_t, recvmsg, int, s, struct kernel_msghdr*, msg,
    4132             :                          int, flags)
    4133             :     LSS_INLINE _syscall3(ssize_t, sendmsg, int, s, const struct kernel_msghdr*,
    4134             :                          msg, int, flags)
    4135             :     LSS_INLINE _syscall6(ssize_t, sendto, int, s, const void*, buf, size_t,len,
    4136             :                          int, flags, const struct kernel_sockaddr*, to,
    4137             :                          unsigned int, tolen)
    4138             :     LSS_INLINE _syscall2(int, shutdown, int, s, int, how)
    4139             :     LSS_INLINE _syscall3(int, socket, int, domain, int, type, int, protocol)
    4140             :     LSS_INLINE _syscall4(int, socketpair, int, d, int, type, int, protocol,
    4141             :                          int*, sv)
    4142             :   #endif
    4143             :   #if defined(__i386__) || defined(__ARM_ARCH_3__) ||                         \
    4144             :       (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) ||                  \
    4145             :       defined(__s390__)
    4146             :     #define __NR__socketcall  __NR_socketcall
    4147             :     LSS_INLINE _syscall2(int,      _socketcall,    int,   c,
    4148             :                          va_list,                  a)
    4149             :     LSS_INLINE int LSS_NAME(socketcall)(int op, ...) {
    4150             :       int rc;
    4151             :       va_list ap;
    4152             :       va_start(ap, op);
    4153             :       rc = LSS_NAME(_socketcall)(op, ap);
    4154             :       va_end(ap);
    4155             :       return rc;
    4156             :     }
    4157             : 
    4158             :     LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
    4159             :                                          int flags){
    4160             :       return (ssize_t)LSS_NAME(socketcall)(17, s, msg, flags);
    4161             :     }
    4162             : 
    4163             :     LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
    4164             :                                          const struct kernel_msghdr *msg,
    4165             :                                          int flags) {
    4166             :       return (ssize_t)LSS_NAME(socketcall)(16, s, msg, flags);
    4167             :     }
    4168             : 
    4169             :     LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
    4170             :                                         int flags,
    4171             :                                         const struct kernel_sockaddr *to,
    4172             :                                         unsigned int tolen) {
    4173             :       return (ssize_t)LSS_NAME(socketcall)(11, s, buf, len, flags, to, tolen);
    4174             :     }
    4175             : 
    4176             :     LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
    4177             :       return LSS_NAME(socketcall)(13, s, how);
    4178             :     }
    4179             : 
    4180             :     LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
    4181             :       return LSS_NAME(socketcall)(1, domain, type, protocol);
    4182             :     }
    4183             : 
    4184             :     LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
    4185             :                                         int sv[2]) {
    4186             :       return LSS_NAME(socketcall)(8, d, type, protocol, sv);
    4187             :     }
    4188             :   #endif
    4189             :   #if defined(__NR_fstatat64)
    4190             :     LSS_INLINE _syscall4(int,   fstatat64,        int,   d,
    4191             :                          const char *,      p,
    4192             :                          struct kernel_stat64 *,   b,    int,   f)
    4193             :   #endif
    4194             :   #if defined(__i386__) || defined(__PPC__) ||                                \
    4195             :      (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
    4196             :     LSS_INLINE _syscall3(pid_t, waitpid,          pid_t, p,
    4197             :                          int*,              s,    int,   o)
    4198             :   #endif
    4199             :   #if defined(__mips__)
    4200             :     /* sys_pipe() on MIPS has non-standard calling conventions, as it returns
    4201             :      * both file handles through CPU registers.
    4202             :      */
    4203             :     LSS_INLINE int LSS_NAME(pipe)(int *p) {
    4204             :       register unsigned long __v0 __asm__("$2") = __NR_pipe;
    4205             :       register unsigned long __v1 __asm__("$3");
    4206             :       register unsigned long __r7 __asm__("$7");
    4207             :       __asm__ __volatile__ ("syscall\n"
    4208             :                             : "=r"(__v0), "=r"(__v1), "=r" (__r7)
    4209             :                             : "0"(__v0)
    4210             :                             : "$8", "$9", "$10", "$11", "$12",
    4211             :                               "$13", "$14", "$15", "$24", "$25", "memory");
    4212             :       if (__r7) {
    4213             :         unsigned long __errnovalue = __v0;
    4214             :         LSS_ERRNO = __errnovalue;
    4215             :         return -1;
    4216             :       } else {
    4217             :         p[0] = __v0;
    4218             :         p[1] = __v1;
    4219             :         return 0;
    4220             :       }
    4221             :     }
    4222             :   #elif !defined(__aarch64__)
    4223             :     // The unlink syscall has been deprecated on aarch64. We polyfill it below.
    4224           0 :     LSS_INLINE _syscall1(int,     pipe,           int *, p)
    4225             :   #endif
    4226             :   /* TODO(csilvers): see if ppc can/should support this as well              */
    4227             :   #if defined(__i386__) || defined(__ARM_ARCH_3__) ||                         \
    4228             :       defined(__ARM_EABI__) ||                                                \
    4229             :      (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64) ||                   \
    4230             :      (defined(__s390__) && !defined(__s390x__))
    4231             :     #define __NR__statfs64  __NR_statfs64
    4232             :     #define __NR__fstatfs64 __NR_fstatfs64
    4233             :     LSS_INLINE _syscall3(int, _statfs64,     const char*, p,
    4234             :                          size_t, s,struct kernel_statfs64*, b)
    4235             :     LSS_INLINE _syscall3(int, _fstatfs64,          int,   f,
    4236             :                          size_t, s,struct kernel_statfs64*, b)
    4237             :     LSS_INLINE int LSS_NAME(statfs64)(const char *p,
    4238             :                                      struct kernel_statfs64 *b) {
    4239             :       return LSS_NAME(_statfs64)(p, sizeof(*b), b);
    4240             :     }
    4241             :     LSS_INLINE int LSS_NAME(fstatfs64)(int f,struct kernel_statfs64 *b) {
    4242             :       return LSS_NAME(_fstatfs64)(f, sizeof(*b), b);
    4243             :     }
    4244             :   #endif
    4245             : 
    4246             :   LSS_INLINE int LSS_NAME(execv)(const char *path, const char *const argv[]) {
    4247             :     extern char **environ;
    4248             :     return LSS_NAME(execve)(path, argv, (const char *const *)environ);
    4249             :   }
    4250             : 
    4251           2 :   LSS_INLINE pid_t LSS_NAME(gettid)(void) {
    4252           2 :     pid_t tid = LSS_NAME(_gettid)();
    4253           2 :     if (tid != -1) {
    4254           2 :       return tid;
    4255             :     }
    4256           0 :     return LSS_NAME(getpid)();
    4257             :   }
    4258             : 
    4259             :   LSS_INLINE void *LSS_NAME(mremap)(void *old_address, size_t old_size,
    4260             :                                     size_t new_size, int flags, ...) {
    4261             :     va_list ap;
    4262             :     void *new_address, *rc;
    4263             :     va_start(ap, flags);
    4264             :     new_address = va_arg(ap, void *);
    4265             :     rc = LSS_NAME(_mremap)(old_address, old_size, new_size,
    4266             :                            flags, new_address);
    4267             :     va_end(ap);
    4268             :     return rc;
    4269             :   }
    4270             : 
    4271             :   LSS_INLINE int LSS_NAME(ptrace_detach)(pid_t pid) {
    4272             :     /* PTRACE_DETACH can sometimes forget to wake up the tracee and it
    4273             :      * then sends job control signals to the real parent, rather than to
    4274             :      * the tracer. We reduce the risk of this happening by starting a
    4275             :      * whole new time slice, and then quickly sending a SIGCONT signal
    4276             :      * right after detaching from the tracee.
    4277             :      *
    4278             :      * We use tkill to ensure that we only issue a wakeup for the thread being
    4279             :      * detached.  Large multi threaded apps can take a long time in the kernel
    4280             :      * processing SIGCONT.
    4281             :      */
    4282             :     int rc, err;
    4283             :     LSS_NAME(sched_yield)();
    4284             :     rc = LSS_NAME(ptrace)(PTRACE_DETACH, pid, (void *)0, (void *)0);
    4285             :     err = LSS_ERRNO;
    4286             :     LSS_NAME(tkill)(pid, SIGCONT);
    4287             :     /* Old systems don't have tkill */
    4288             :     if (LSS_ERRNO == ENOSYS)
    4289             :       LSS_NAME(kill)(pid, SIGCONT);
    4290             :     LSS_ERRNO = err;
    4291             :     return rc;
    4292             :   }
    4293             : 
    4294             :   LSS_INLINE int LSS_NAME(raise)(int sig) {
    4295             :     return LSS_NAME(kill)(LSS_NAME(getpid)(), sig);
    4296             :   }
    4297             : 
    4298             :   LSS_INLINE int LSS_NAME(setpgrp)(void) {
    4299             :     return LSS_NAME(setpgid)(0, 0);
    4300             :   }
    4301             : 
    4302             :   LSS_INLINE int LSS_NAME(sysconf)(int name) {
    4303             :     extern int __getpagesize(void);
    4304             :     switch (name) {
    4305             :       case _SC_OPEN_MAX: {
    4306             :         struct kernel_rlimit limit;
    4307             : #if defined(__ARM_EABI__)
    4308             :         return LSS_NAME(ugetrlimit)(RLIMIT_NOFILE, &limit) < 0
    4309             :             ? 8192 : limit.rlim_cur;
    4310             : #else
    4311             :         return LSS_NAME(getrlimit)(RLIMIT_NOFILE, &limit) < 0
    4312             :             ? 8192 : limit.rlim_cur;
    4313             : #endif
    4314             :       }
    4315             :       case _SC_PAGESIZE:
    4316             :         return __getpagesize();
    4317             :       default:
    4318             :         LSS_ERRNO = ENOSYS;
    4319             :         return -1;
    4320             :     }
    4321             :   }
    4322             :   #if defined(__x86_64__)
    4323             :     /* Need to make sure loff_t isn't truncated to 32-bits under x32.  */
    4324             :     LSS_INLINE ssize_t LSS_NAME(pread64)(int f, void *b, size_t c, loff_t o) {
    4325             :       LSS_BODY(4, ssize_t, pread64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
    4326             :                                     LSS_SYSCALL_ARG(c), (uint64_t)(o));
    4327             :     }
    4328             : 
    4329             :     LSS_INLINE ssize_t LSS_NAME(pwrite64)(int f, const void *b, size_t c,
    4330             :                                           loff_t o) {
    4331             :       LSS_BODY(4, ssize_t, pwrite64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
    4332             :                                      LSS_SYSCALL_ARG(c), (uint64_t)(o));
    4333             :     }
    4334             : 
    4335             :     LSS_INLINE int LSS_NAME(readahead)(int f, loff_t o, unsigned c) {
    4336             :       LSS_BODY(3, int, readahead, LSS_SYSCALL_ARG(f), (uint64_t)(o),
    4337             :                                   LSS_SYSCALL_ARG(c));
    4338             :     }
    4339             :   #elif defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64
    4340             :     LSS_INLINE _syscall4(ssize_t, pread64,        int,         f,
    4341             :                          void *,         b, size_t,   c,
    4342             :                          loff_t,         o)
    4343             :     LSS_INLINE _syscall4(ssize_t, pwrite64,       int,         f,
    4344             :                          const void *,   b, size_t,   c,
    4345             :                          loff_t,         o)
    4346             :     LSS_INLINE _syscall3(int,     readahead,      int,         f,
    4347             :                          loff_t,         o, unsigned, c)
    4348             :   #else
    4349             :     #define __NR__pread64   __NR_pread64
    4350             :     #define __NR__pwrite64  __NR_pwrite64
    4351             :     #define __NR__readahead __NR_readahead
    4352             :     #if defined(__ARM_EABI__) || defined(__mips__)
    4353             :       /* On ARM and MIPS, a 64-bit parameter has to be in an even-odd register
    4354             :        * pair. Hence these calls ignore their fourth argument (r3) so that their
    4355             :        * fifth and sixth make such a pair (r4,r5).
    4356             :        */
    4357             :       #define LSS_LLARG_PAD 0,
    4358             :       LSS_INLINE _syscall6(ssize_t, _pread64,        int,         f,
    4359             :                            void *,         b, size_t, c,
    4360             :                            unsigned, skip, unsigned, o1, unsigned, o2)
    4361             :       LSS_INLINE _syscall6(ssize_t, _pwrite64,       int,         f,
    4362             :                            const void *,   b, size_t, c,
    4363             :                            unsigned, skip, unsigned, o1, unsigned, o2)
    4364             :       LSS_INLINE _syscall5(int, _readahead,          int,         f,
    4365             :                            unsigned,     skip,
    4366             :                            unsigned,       o1, unsigned, o2, size_t, c)
    4367             :     #else
    4368             :       #define LSS_LLARG_PAD
    4369             :       LSS_INLINE _syscall5(ssize_t, _pread64,        int,         f,
    4370             :                            void *,         b, size_t, c, unsigned, o1,
    4371             :                            unsigned, o2)
    4372             :       LSS_INLINE _syscall5(ssize_t, _pwrite64,       int,         f,
    4373             :                            const void *,   b, size_t, c, unsigned, o1,
    4374             :                            long, o2)
    4375             :       LSS_INLINE _syscall4(int, _readahead,          int,         f,
    4376             :                            unsigned,       o1, unsigned, o2, size_t, c)
    4377             :     #endif
    4378             :     /* We force 64bit-wide parameters onto the stack, then access each
    4379             :      * 32-bit component individually. This guarantees that we build the
    4380             :      * correct parameters independent of the native byte-order of the
    4381             :      * underlying architecture.
    4382             :      */
    4383             :     LSS_INLINE ssize_t LSS_NAME(pread64)(int fd, void *buf, size_t count,
    4384             :                                          loff_t off) {
    4385             :       union { loff_t off; unsigned arg[2]; } o = { off };
    4386             :       return LSS_NAME(_pread64)(fd, buf, count,
    4387             :                                 LSS_LLARG_PAD o.arg[0], o.arg[1]);
    4388             :     }
    4389             :     LSS_INLINE ssize_t LSS_NAME(pwrite64)(int fd, const void *buf,
    4390             :                                           size_t count, loff_t off) {
    4391             :       union { loff_t off; unsigned arg[2]; } o = { off };
    4392             :       return LSS_NAME(_pwrite64)(fd, buf, count,
    4393             :                                  LSS_LLARG_PAD o.arg[0], o.arg[1]);
    4394             :     }
    4395             :     LSS_INLINE int LSS_NAME(readahead)(int fd, loff_t off, int len) {
    4396             :       union { loff_t off; unsigned arg[2]; } o = { off };
    4397             :       return LSS_NAME(_readahead)(fd, LSS_LLARG_PAD o.arg[0], o.arg[1], len);
    4398             :     }
    4399             :   #endif
    4400             : #endif
    4401             : 
    4402             : #if defined(__aarch64__)
    4403             :   LSS_INLINE _syscall3(int, dup3,  int, s, int, d, int, f)
    4404             :   LSS_INLINE _syscall4(int, newfstatat, int, dirfd, const char *, pathname,
    4405             :                        struct kernel_stat *, buf, int, flags)
    4406             :   LSS_INLINE _syscall2(int, pipe2, int *, pipefd, int, flags)
    4407             :   LSS_INLINE _syscall5(int, ppoll, struct kernel_pollfd *, u,
    4408             :                        unsigned int, n, const struct kernel_timespec *, t,
    4409             :                        const struct kernel_sigset_t *, sigmask, size_t, s)
    4410             :   LSS_INLINE _syscall4(int, readlinkat, int, d, const char *, p, char *, b,
    4411             :                        size_t, s)
    4412             : #endif
    4413             : 
    4414             : /*
    4415             :  * Polyfills for deprecated syscalls.
    4416             :  */
    4417             : 
    4418             : #if defined(__aarch64__)
    4419             :   LSS_INLINE int LSS_NAME(dup2)(int s, int d) {
    4420             :     return LSS_NAME(dup3)(s, d, 0);
    4421             :   }
    4422             : 
    4423             :   LSS_INLINE int LSS_NAME(open)(const char *pathname, int flags, int mode) {
    4424             :     return LSS_NAME(openat)(AT_FDCWD, pathname, flags, mode);
    4425             :   }
    4426             : 
    4427             :   LSS_INLINE int LSS_NAME(unlink)(const char *pathname) {
    4428             :     return LSS_NAME(unlinkat)(AT_FDCWD, pathname, 0);
    4429             :   }
    4430             : 
    4431             :   LSS_INLINE int LSS_NAME(readlink)(const char *pathname, char *buffer,
    4432             :                                     size_t size) {
    4433             :     return LSS_NAME(readlinkat)(AT_FDCWD, pathname, buffer, size);
    4434             :   }
    4435             : 
    4436             :   LSS_INLINE pid_t LSS_NAME(pipe)(int *pipefd) {
    4437             :     return LSS_NAME(pipe2)(pipefd, 0);
    4438             :   }
    4439             : 
    4440             :   LSS_INLINE int LSS_NAME(poll)(struct kernel_pollfd *fds, unsigned int nfds,
    4441             :                                 int timeout) {
    4442             :    struct kernel_timespec timeout_ts;
    4443             :    struct kernel_timespec *timeout_ts_p = NULL;
    4444             : 
    4445             :     if (timeout >= 0) {
    4446             :       timeout_ts.tv_sec = timeout / 1000;
    4447             :       timeout_ts.tv_nsec = (timeout % 1000) * 1000000;
    4448             :       timeout_ts_p = &timeout_ts;
    4449             :     }
    4450             :     return LSS_NAME(ppoll)(fds, nfds, timeout_ts_p, NULL, 0);
    4451             :   }
    4452             : 
    4453             :   LSS_INLINE int LSS_NAME(stat)(const char *pathname,
    4454             :                                 struct kernel_stat *buf) {
    4455             :     return LSS_NAME(newfstatat)(AT_FDCWD, pathname, buf, 0);
    4456             :   }
    4457             : 
    4458             :   LSS_INLINE pid_t LSS_NAME(fork)(void) {
    4459             :     // No fork syscall on aarch64 - implement by means of the clone syscall.
    4460             :     // Note that this does not reset glibc's cached view of the PID/TID, so
    4461             :     // some glibc interfaces might go wrong in the forked subprocess.
    4462             :     int flags = SIGCHLD;
    4463             :     void *child_stack = NULL;
    4464             :     void *parent_tidptr = NULL;
    4465             :     void *newtls = NULL;
    4466             :     void *child_tidptr = NULL;
    4467             : 
    4468             :     LSS_REG(0, flags);
    4469             :     LSS_REG(1, child_stack);
    4470             :     LSS_REG(2, parent_tidptr);
    4471             :     LSS_REG(3, newtls);
    4472             :     LSS_REG(4, child_tidptr);
    4473             :     LSS_BODY(pid_t, clone, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),
    4474             :              "r"(__r4));
    4475             :   }
    4476             : #endif
    4477             : 
    4478             : #ifdef __ANDROID__
    4479             :   /* These restore the original values of these macros saved by the
    4480             :    * corresponding #pragma push_macro near the top of this file. */
    4481             : # pragma pop_macro("stat64")
    4482             : # pragma pop_macro("fstat64")
    4483             : # pragma pop_macro("lstat64")
    4484             : #endif
    4485             : 
    4486             : #if defined(__cplusplus) && !defined(SYS_CPLUSPLUS)
    4487             : }
    4488             : #endif
    4489             : 
    4490             : #endif
    4491             : #endif

Generated by: LCOV version 1.13