blob: 22f576dfe9ba3fe3ec072bc41a6d0d89bd971569 [file] [log] [blame]
zodiac@gmail.com71d26df2010-09-15 01:31:22 +00001/* Copyright (c) 2005-2010, Google Inc.
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * ---
31 * Author: Markus Gutschke
32 */
33
34/* This file includes Linux-specific support functions common to the
35 * coredumper and the thread lister; primarily, this is a collection
36 * of direct system calls, and a couple of symbols missing from
37 * standard header files.
38 * There are a few options that the including file can set to control
39 * the behavior of this file:
40 *
41 * SYS_CPLUSPLUS:
42 * The entire header file will normally be wrapped in 'extern "C" { }",
43 * making it suitable for compilation as both C and C++ source. If you
44 * do not want to do this, you can set the SYS_CPLUSPLUS macro to inhibit
45 * the wrapping. N.B. doing so will suppress inclusion of all prerequisite
46 * system header files, too. It is the caller's responsibility to provide
47 * the necessary definitions.
48 *
49 * SYS_ERRNO:
50 * All system calls will update "errno" unless overriden by setting the
51 * SYS_ERRNO macro prior to including this file. SYS_ERRNO should be
52 * an l-value.
53 *
54 * SYS_INLINE:
55 * New symbols will be defined "static inline", unless overridden by
56 * the SYS_INLINE macro.
57 *
58 * SYS_LINUX_SYSCALL_SUPPORT_H
59 * This macro is used to avoid multiple inclusions of this header file.
60 * If you need to include this file more than once, make sure to
61 * unset SYS_LINUX_SYSCALL_SUPPORT_H before each inclusion.
62 *
63 * SYS_PREFIX:
64 * New system calls will have a prefix of "sys_" unless overridden by
65 * the SYS_PREFIX macro. Valid values for this macro are [0..9] which
66 * results in prefixes "sys[0..9]_". It is also possible to set this
67 * macro to -1, which avoids all prefixes.
68 *
69 * SYS_SYSCALL_ENTRYPOINT:
70 * Some applications (such as sandboxes that filter system calls), need
71 * to be able to run custom-code each time a system call is made. If this
72 * macro is defined, it expands to the name of a "common" symbol. If
73 * this symbol is assigned a non-NULL pointer value, it is used as the
74 * address of the system call entrypoint.
75 * A pointer to this symbol can be obtained by calling
76 * get_syscall_entrypoint()
77 *
78 * This file defines a few internal symbols that all start with "LSS_".
79 * Do not access these symbols from outside this file. They are not part
80 * of the supported API.
81 */
82#ifndef SYS_LINUX_SYSCALL_SUPPORT_H
83#define SYS_LINUX_SYSCALL_SUPPORT_H
84
85/* We currently only support x86-32, x86-64, ARM, MIPS, and PPC on Linux.
86 * Porting to other related platforms should not be difficult.
87 */
88#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
89 defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__)) \
90 && defined(__linux)
91
92#ifndef SYS_CPLUSPLUS
93#ifdef __cplusplus
94/* Some system header files in older versions of gcc neglect to properly
95 * handle being included from C++. As it appears to be harmless to have
96 * multiple nested 'extern "C"' blocks, just add another one here.
97 */
98extern "C" {
99#endif
100
101#include <errno.h>
102#include <signal.h>
103#include <stdarg.h>
104#include <stddef.h>
105#include <string.h>
106#include <sys/ptrace.h>
107#include <sys/resource.h>
108#include <sys/time.h>
109#include <sys/types.h>
110#include <syscall.h>
111#include <unistd.h>
112#include <linux/unistd.h>
113#include <endian.h>
114
115#ifdef __mips__
116/* Include definitions of the ABI currently in use. */
117#include <sgidefs.h>
118#endif
119#endif
120
121/* As glibc often provides subtly incompatible data structures (and implicit
122 * wrapper functions that convert them), we provide our own kernel data
123 * structures for use by the system calls.
124 * These structures have been developed by using Linux 2.6.23 headers for
125 * reference. Note though, we do not care about exact API compatibility
126 * with the kernel, and in fact the kernel often does not have a single
127 * API that works across architectures. Instead, we try to mimic the glibc
128 * API where reasonable, and only guarantee ABI compatibility with the
129 * kernel headers.
130 * Most notably, here are a few changes that were made to the structures
131 * defined by kernel headers:
132 *
133 * - we only define structures, but not symbolic names for kernel data
134 * types. For the latter, we directly use the native C datatype
135 * (i.e. "unsigned" instead of "mode_t").
136 * - in a few cases, it is possible to define identical structures for
137 * both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by
138 * standardizing on the 64bit version of the data types. In particular,
139 * this means that we use "unsigned" where the 32bit headers say
140 * "unsigned long".
141 * - overall, we try to minimize the number of cases where we need to
142 * conditionally define different structures.
143 * - the "struct kernel_sigaction" class of structures have been
144 * modified to more closely mimic glibc's API by introducing an
145 * anonymous union for the function pointer.
146 * - a small number of field names had to have an underscore appended to
147 * them, because glibc defines a global macro by the same name.
148 */
149
150/* include/linux/dirent.h */
151struct kernel_dirent64 {
152 unsigned long long d_ino;
153 long long d_off;
154 unsigned short d_reclen;
155 unsigned char d_type;
156 char d_name[256];
157};
158
159/* include/linux/dirent.h */
160struct kernel_dirent {
161 long d_ino;
162 long d_off;
163 unsigned short d_reclen;
164 char d_name[256];
165};
166
167/* include/linux/uio.h */
168struct kernel_iovec {
169 void *iov_base;
170 unsigned long iov_len;
171};
172
173/* include/linux/socket.h */
174struct kernel_msghdr {
175 void *msg_name;
176 int msg_namelen;
177 struct kernel_iovec*msg_iov;
178 unsigned long msg_iovlen;
179 void *msg_control;
180 unsigned long msg_controllen;
181 unsigned msg_flags;
182};
183
184/* include/asm-generic/poll.h */
185struct kernel_pollfd {
186 int fd;
187 short events;
188 short revents;
189};
190
191/* include/linux/resource.h */
192struct kernel_rlimit {
193 unsigned long rlim_cur;
194 unsigned long rlim_max;
195};
196
197/* include/linux/time.h */
198struct kernel_timespec {
199 long tv_sec;
200 long tv_nsec;
201};
202
203/* include/linux/time.h */
204struct kernel_timeval {
205 long tv_sec;
206 long tv_usec;
207};
208
209/* include/linux/resource.h */
210struct kernel_rusage {
211 struct kernel_timeval ru_utime;
212 struct kernel_timeval ru_stime;
213 long ru_maxrss;
214 long ru_ixrss;
215 long ru_idrss;
216 long ru_isrss;
217 long ru_minflt;
218 long ru_majflt;
219 long ru_nswap;
220 long ru_inblock;
221 long ru_oublock;
222 long ru_msgsnd;
223 long ru_msgrcv;
224 long ru_nsignals;
225 long ru_nvcsw;
226 long ru_nivcsw;
227};
228
229struct siginfo;
230#if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \
231 || defined(__PPC__)
232
233/* include/asm-{arm,i386,mips,ppc}/signal.h */
234struct kernel_old_sigaction {
235 union {
236 void (*sa_handler_)(int);
237 void (*sa_sigaction_)(int, struct siginfo *, void *);
238 };
239 unsigned long sa_mask;
240 unsigned long sa_flags;
241 void (*sa_restorer)(void);
242} __attribute__((packed,aligned(4)));
243#elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
244 #define kernel_old_sigaction kernel_sigaction
245#endif
246
247/* Some kernel functions (e.g. sigaction() in 2.6.23) require that the
248 * exactly match the size of the signal set, even though the API was
249 * intended to be extensible. We define our own KERNEL_NSIG to deal with
250 * this.
251 * Please note that glibc provides signals [1.._NSIG-1], whereas the
252 * kernel (and this header) provides the range [1..KERNEL_NSIG]. The
253 * actual number of signals is obviously the same, but the constants
254 * differ by one.
255 */
256#ifdef __mips__
257#define KERNEL_NSIG 128
258#else
259#define KERNEL_NSIG 64
260#endif
261
262/* include/asm-{arm,i386,mips,x86_64}/signal.h */
263struct kernel_sigset_t {
264 unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/
265 (8*sizeof(unsigned long))];
266};
267
268/* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h */
269struct kernel_sigaction {
270#ifdef __mips__
271 unsigned long sa_flags;
272 union {
273 void (*sa_handler_)(int);
274 void (*sa_sigaction_)(int, struct siginfo *, void *);
275 };
276 struct kernel_sigset_t sa_mask;
277#else
278 union {
279 void (*sa_handler_)(int);
280 void (*sa_sigaction_)(int, struct siginfo *, void *);
281 };
282 unsigned long sa_flags;
283 void (*sa_restorer)(void);
284 struct kernel_sigset_t sa_mask;
285#endif
286};
287
288/* include/linux/socket.h */
289struct kernel_sockaddr {
290 unsigned short sa_family;
291 char sa_data[14];
292};
293
294/* include/asm-{arm,i386,mips,ppc}/stat.h */
295#ifdef __mips__
296#if _MIPS_SIM == _MIPS_SIM_ABI64
297struct kernel_stat {
298#else
299struct kernel_stat64 {
300#endif
301 unsigned st_dev;
302 unsigned __pad0[3];
303 unsigned long long st_ino;
304 unsigned st_mode;
305 unsigned st_nlink;
306 unsigned st_uid;
307 unsigned st_gid;
308 unsigned st_rdev;
309 unsigned __pad1[3];
310 long long st_size;
311 unsigned st_atime_;
312 unsigned st_atime_nsec_;
313 unsigned st_mtime_;
314 unsigned st_mtime_nsec_;
315 unsigned st_ctime_;
316 unsigned st_ctime_nsec_;
317 unsigned st_blksize;
318 unsigned __pad2;
319 unsigned long long st_blocks;
320};
321#elif defined __PPC__
322struct kernel_stat64 {
323 unsigned long long st_dev;
324 unsigned long long st_ino;
325 unsigned st_mode;
326 unsigned st_nlink;
327 unsigned st_uid;
328 unsigned st_gid;
329 unsigned long long st_rdev;
330 unsigned short int __pad2;
331 long long st_size;
332 long st_blksize;
333 long long st_blocks;
334 long st_atime_;
335 unsigned long st_atime_nsec_;
336 long st_mtime_;
337 unsigned long st_mtime_nsec_;
338 long st_ctime_;
339 unsigned long st_ctime_nsec_;
340 unsigned long __unused4;
341 unsigned long __unused5;
342};
343#else
344struct kernel_stat64 {
345 unsigned long long st_dev;
346 unsigned char __pad0[4];
347 unsigned __st_ino;
348 unsigned st_mode;
349 unsigned st_nlink;
350 unsigned st_uid;
351 unsigned st_gid;
352 unsigned long long st_rdev;
353 unsigned char __pad3[4];
354 long long st_size;
355 unsigned st_blksize;
356 unsigned long long st_blocks;
357 unsigned st_atime_;
358 unsigned st_atime_nsec_;
359 unsigned st_mtime_;
360 unsigned st_mtime_nsec_;
361 unsigned st_ctime_;
362 unsigned st_ctime_nsec_;
363 unsigned long long st_ino;
364};
365#endif
366
367/* include/asm-{arm,i386,mips,x86_64,ppc}/stat.h */
368#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
369struct kernel_stat {
370 /* The kernel headers suggest that st_dev and st_rdev should be 32bit
371 * quantities encoding 12bit major and 20bit minor numbers in an interleaved
372 * format. In reality, we do not see useful data in the top bits. So,
373 * we'll leave the padding in here, until we find a better solution.
374 */
375 unsigned short st_dev;
376 short pad1;
377 unsigned st_ino;
378 unsigned short st_mode;
379 unsigned short st_nlink;
380 unsigned short st_uid;
381 unsigned short st_gid;
382 unsigned short st_rdev;
383 short pad2;
384 unsigned st_size;
385 unsigned st_blksize;
386 unsigned st_blocks;
387 unsigned st_atime_;
388 unsigned st_atime_nsec_;
389 unsigned st_mtime_;
390 unsigned st_mtime_nsec_;
391 unsigned st_ctime_;
392 unsigned st_ctime_nsec_;
393 unsigned __unused4;
394 unsigned __unused5;
395};
396#elif defined(__x86_64__)
397struct kernel_stat {
398 unsigned long st_dev;
399 unsigned long st_ino;
400 unsigned long st_nlink;
401 unsigned st_mode;
402 unsigned st_uid;
403 unsigned st_gid;
404 unsigned __pad0;
405 unsigned long st_rdev;
406 long st_size;
407 long st_blksize;
408 long st_blocks;
409 unsigned long st_atime_;
410 unsigned long st_atime_nsec_;
411 unsigned long st_mtime_;
412 unsigned long st_mtime_nsec_;
413 unsigned long st_ctime_;
414 unsigned long st_ctime_nsec_;
415 long __unused[3];
416};
417#elif defined(__PPC__)
418struct kernel_stat {
419 unsigned st_dev;
420 unsigned long st_ino; // ino_t
421 unsigned long st_mode; // mode_t
422 unsigned short st_nlink; // nlink_t
423 unsigned st_uid; // uid_t
424 unsigned st_gid; // gid_t
425 unsigned st_rdev;
426 long st_size; // off_t
427 unsigned long st_blksize;
428 unsigned long st_blocks;
429 unsigned long st_atime_;
430 unsigned long st_atime_nsec_;
431 unsigned long st_mtime_;
432 unsigned long st_mtime_nsec_;
433 unsigned long st_ctime_;
434 unsigned long st_ctime_nsec_;
435 unsigned long __unused4;
436 unsigned long __unused5;
437};
438#elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
439struct kernel_stat {
440 unsigned st_dev;
441 int st_pad1[3];
442 unsigned st_ino;
443 unsigned st_mode;
444 unsigned st_nlink;
445 unsigned st_uid;
446 unsigned st_gid;
447 unsigned st_rdev;
448 int st_pad2[2];
449 long st_size;
450 int st_pad3;
451 long st_atime_;
452 long st_atime_nsec_;
453 long st_mtime_;
454 long st_mtime_nsec_;
455 long st_ctime_;
456 long st_ctime_nsec_;
457 int st_blksize;
458 int st_blocks;
459 int st_pad4[14];
460};
461#endif
462
463/* include/asm-{arm,i386,mips,x86_64,ppc}/statfs.h */
464#ifdef __mips__
465#if _MIPS_SIM != _MIPS_SIM_ABI64
466struct kernel_statfs64 {
467 unsigned long f_type;
468 unsigned long f_bsize;
469 unsigned long f_frsize;
470 unsigned long __pad;
471 unsigned long long f_blocks;
472 unsigned long long f_bfree;
473 unsigned long long f_files;
474 unsigned long long f_ffree;
475 unsigned long long f_bavail;
476 struct { int val[2]; } f_fsid;
477 unsigned long f_namelen;
478 unsigned long f_spare[6];
479};
480#endif
481#elif !defined(__x86_64__)
482struct kernel_statfs64 {
483 unsigned long f_type;
484 unsigned long f_bsize;
485 unsigned long long f_blocks;
486 unsigned long long f_bfree;
487 unsigned long long f_bavail;
488 unsigned long long f_files;
489 unsigned long long f_ffree;
490 struct { int val[2]; } f_fsid;
491 unsigned long f_namelen;
492 unsigned long f_frsize;
493 unsigned long f_spare[5];
494};
495#endif
496
497/* include/asm-{arm,i386,mips,x86_64,ppc,generic}/statfs.h */
498#ifdef __mips__
499struct kernel_statfs {
500 long f_type;
501 long f_bsize;
502 long f_frsize;
503 long f_blocks;
504 long f_bfree;
505 long f_files;
506 long f_ffree;
507 long f_bavail;
508 struct { int val[2]; } f_fsid;
509 long f_namelen;
510 long f_spare[6];
511};
512#else
513struct kernel_statfs {
514 /* x86_64 actually defines all these fields as signed, whereas all other */
515 /* platforms define them as unsigned. Leaving them at unsigned should not */
516 /* cause any problems. */
517 unsigned long f_type;
518 unsigned long f_bsize;
519 unsigned long f_blocks;
520 unsigned long f_bfree;
521 unsigned long f_bavail;
522 unsigned long f_files;
523 unsigned long f_ffree;
524 struct { int val[2]; } f_fsid;
525 unsigned long f_namelen;
526 unsigned long f_frsize;
527 unsigned long f_spare[5];
528};
529#endif
530
531
532/* Definitions missing from the standard header files */
533#ifndef O_DIRECTORY
534#if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
535#define O_DIRECTORY 0040000
536#else
537#define O_DIRECTORY 0200000
538#endif
539#endif
540#ifndef NT_PRXFPREG
541#define NT_PRXFPREG 0x46e62b7f
542#endif
543#ifndef PTRACE_GETFPXREGS
544#define PTRACE_GETFPXREGS ((enum __ptrace_request)18)
545#endif
546#ifndef PR_GET_DUMPABLE
547#define PR_GET_DUMPABLE 3
548#endif
549#ifndef PR_SET_DUMPABLE
550#define PR_SET_DUMPABLE 4
551#endif
552#ifndef PR_GET_SECCOMP
553#define PR_GET_SECCOMP 21
554#endif
555#ifndef PR_SET_SECCOMP
556#define PR_SET_SECCOMP 22
557#endif
558#ifndef AT_FDCWD
559#define AT_FDCWD (-100)
560#endif
561#ifndef AT_SYMLINK_NOFOLLOW
562#define AT_SYMLINK_NOFOLLOW 0x100
563#endif
564#ifndef AT_REMOVEDIR
565#define AT_REMOVEDIR 0x200
566#endif
567#ifndef MREMAP_FIXED
568#define MREMAP_FIXED 2
569#endif
570#ifndef SA_RESTORER
571#define SA_RESTORER 0x04000000
572#endif
573#ifndef CPUCLOCK_PROF
574#define CPUCLOCK_PROF 0
575#endif
576#ifndef CPUCLOCK_VIRT
577#define CPUCLOCK_VIRT 1
578#endif
579#ifndef CPUCLOCK_SCHED
580#define CPUCLOCK_SCHED 2
581#endif
582#ifndef CPUCLOCK_PERTHREAD_MASK
583#define CPUCLOCK_PERTHREAD_MASK 4
584#endif
585#ifndef MAKE_PROCESS_CPUCLOCK
586#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
587 ((~(int)(pid) << 3) | (int)(clock))
588#endif
589#ifndef MAKE_THREAD_CPUCLOCK
590#define MAKE_THREAD_CPUCLOCK(tid, clock) \
591 ((~(int)(tid) << 3) | (int)((clock) | CPUCLOCK_PERTHREAD_MASK))
592#endif
593
594#ifndef FUTEX_WAIT
595#define FUTEX_WAIT 0
596#endif
597#ifndef FUTEX_WAKE
598#define FUTEX_WAKE 1
599#endif
600#ifndef FUTEX_FD
601#define FUTEX_FD 2
602#endif
603#ifndef FUTEX_REQUEUE
604#define FUTEX_REQUEUE 3
605#endif
606#ifndef FUTEX_CMP_REQUEUE
607#define FUTEX_CMP_REQUEUE 4
608#endif
609#ifndef FUTEX_WAKE_OP
610#define FUTEX_WAKE_OP 5
611#endif
612#ifndef FUTEX_LOCK_PI
613#define FUTEX_LOCK_PI 6
614#endif
615#ifndef FUTEX_UNLOCK_PI
616#define FUTEX_UNLOCK_PI 7
617#endif
618#ifndef FUTEX_TRYLOCK_PI
619#define FUTEX_TRYLOCK_PI 8
620#endif
621#ifndef FUTEX_PRIVATE_FLAG
622#define FUTEX_PRIVATE_FLAG 128
623#endif
624#ifndef FUTEX_CMD_MASK
625#define FUTEX_CMD_MASK ~FUTEX_PRIVATE_FLAG
626#endif
627#ifndef FUTEX_WAIT_PRIVATE
628#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
629#endif
630#ifndef FUTEX_WAKE_PRIVATE
631#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
632#endif
633#ifndef FUTEX_REQUEUE_PRIVATE
634#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
635#endif
636#ifndef FUTEX_CMP_REQUEUE_PRIVATE
637#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
638#endif
639#ifndef FUTEX_WAKE_OP_PRIVATE
640#define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
641#endif
642#ifndef FUTEX_LOCK_PI_PRIVATE
643#define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
644#endif
645#ifndef FUTEX_UNLOCK_PI_PRIVATE
646#define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
647#endif
648#ifndef FUTEX_TRYLOCK_PI_PRIVATE
649#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
650#endif
651
652
653#if defined(__x86_64__)
654#ifndef ARCH_SET_GS
655#define ARCH_SET_GS 0x1001
656#endif
657#ifndef ARCH_GET_GS
658#define ARCH_GET_GS 0x1004
659#endif
660#endif
661
662#if defined(__i386__)
663#ifndef __NR_quotactl
664#define __NR_quotactl 131
665#endif
666#ifndef __NR_setresuid
667#define __NR_setresuid 164
668#define __NR_getresuid 165
669#define __NR_setresgid 170
670#define __NR_getresgid 171
671#endif
672#ifndef __NR_rt_sigaction
673#define __NR_rt_sigreturn 173
674#define __NR_rt_sigaction 174
675#define __NR_rt_sigprocmask 175
676#define __NR_rt_sigpending 176
677#define __NR_rt_sigsuspend 179
678#endif
679#ifndef __NR_pread64
680#define __NR_pread64 180
681#endif
682#ifndef __NR_pwrite64
683#define __NR_pwrite64 181
684#endif
685#ifndef __NR_ugetrlimit
686#define __NR_ugetrlimit 191
687#endif
688#ifndef __NR_stat64
689#define __NR_stat64 195
690#endif
691#ifndef __NR_fstat64
692#define __NR_fstat64 197
693#endif
694#ifndef __NR_setresuid32
695#define __NR_setresuid32 208
696#define __NR_getresuid32 209
697#define __NR_setresgid32 210
698#define __NR_getresgid32 211
699#endif
700#ifndef __NR_setfsuid32
701#define __NR_setfsuid32 215
702#define __NR_setfsgid32 216
703#endif
704#ifndef __NR_getdents64
705#define __NR_getdents64 220
706#endif
707#ifndef __NR_gettid
708#define __NR_gettid 224
709#endif
710#ifndef __NR_readahead
711#define __NR_readahead 225
712#endif
713#ifndef __NR_setxattr
714#define __NR_setxattr 226
715#endif
716#ifndef __NR_lsetxattr
717#define __NR_lsetxattr 227
718#endif
719#ifndef __NR_getxattr
720#define __NR_getxattr 229
721#endif
722#ifndef __NR_lgetxattr
723#define __NR_lgetxattr 230
724#endif
725#ifndef __NR_listxattr
726#define __NR_listxattr 232
727#endif
728#ifndef __NR_llistxattr
729#define __NR_llistxattr 233
730#endif
731#ifndef __NR_tkill
732#define __NR_tkill 238
733#endif
734#ifndef __NR_futex
735#define __NR_futex 240
736#endif
737#ifndef __NR_sched_setaffinity
738#define __NR_sched_setaffinity 241
739#define __NR_sched_getaffinity 242
740#endif
741#ifndef __NR_set_tid_address
742#define __NR_set_tid_address 258
743#endif
744#ifndef __NR_clock_gettime
745#define __NR_clock_gettime 265
746#endif
747#ifndef __NR_clock_getres
748#define __NR_clock_getres 266
749#endif
750#ifndef __NR_statfs64
751#define __NR_statfs64 268
752#endif
753#ifndef __NR_fstatfs64
754#define __NR_fstatfs64 269
755#endif
756#ifndef __NR_fadvise64_64
757#define __NR_fadvise64_64 272
758#endif
759#ifndef __NR_ioprio_set
760#define __NR_ioprio_set 289
761#endif
762#ifndef __NR_ioprio_get
763#define __NR_ioprio_get 290
764#endif
765#ifndef __NR_openat
766#define __NR_openat 295
767#endif
768#ifndef __NR_fstatat64
769#define __NR_fstatat64 300
770#endif
771#ifndef __NR_unlinkat
772#define __NR_unlinkat 301
773#endif
774#ifndef __NR_move_pages
775#define __NR_move_pages 317
776#endif
777#ifndef __NR_getcpu
778#define __NR_getcpu 318
779#endif
780#ifndef __NR_fallocate
781#define __NR_fallocate 324
782#endif
783/* End of i386 definitions */
784#elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
785#ifndef __NR_setresuid
786#define __NR_setresuid (__NR_SYSCALL_BASE + 164)
787#define __NR_getresuid (__NR_SYSCALL_BASE + 165)
788#define __NR_setresgid (__NR_SYSCALL_BASE + 170)
789#define __NR_getresgid (__NR_SYSCALL_BASE + 171)
790#endif
791#ifndef __NR_rt_sigaction
792#define __NR_rt_sigreturn (__NR_SYSCALL_BASE + 173)
793#define __NR_rt_sigaction (__NR_SYSCALL_BASE + 174)
794#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE + 175)
795#define __NR_rt_sigpending (__NR_SYSCALL_BASE + 176)
796#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE + 179)
797#endif
798#ifndef __NR_pread64
799#define __NR_pread64 (__NR_SYSCALL_BASE + 180)
800#endif
801#ifndef __NR_pwrite64
802#define __NR_pwrite64 (__NR_SYSCALL_BASE + 181)
803#endif
804#ifndef __NR_ugetrlimit
805#define __NR_ugetrlimit (__NR_SYSCALL_BASE + 191)
806#endif
807#ifndef __NR_stat64
808#define __NR_stat64 (__NR_SYSCALL_BASE + 195)
809#endif
810#ifndef __NR_fstat64
811#define __NR_fstat64 (__NR_SYSCALL_BASE + 197)
812#endif
813#ifndef __NR_setresuid32
814#define __NR_setresuid32 (__NR_SYSCALL_BASE + 208)
815#define __NR_getresuid32 (__NR_SYSCALL_BASE + 209)
816#define __NR_setresgid32 (__NR_SYSCALL_BASE + 210)
817#define __NR_getresgid32 (__NR_SYSCALL_BASE + 211)
818#endif
819#ifndef __NR_setfsuid32
820#define __NR_setfsuid32 (__NR_SYSCALL_BASE + 215)
821#define __NR_setfsgid32 (__NR_SYSCALL_BASE + 216)
822#endif
823#ifndef __NR_getdents64
824#define __NR_getdents64 (__NR_SYSCALL_BASE + 217)
825#endif
826#ifndef __NR_gettid
827#define __NR_gettid (__NR_SYSCALL_BASE + 224)
828#endif
829#ifndef __NR_readahead
830#define __NR_readahead (__NR_SYSCALL_BASE + 225)
831#endif
832#ifndef __NR_setxattr
833#define __NR_setxattr (__NR_SYSCALL_BASE + 226)
834#endif
835#ifndef __NR_lsetxattr
836#define __NR_lsetxattr (__NR_SYSCALL_BASE + 227)
837#endif
838#ifndef __NR_getxattr
839#define __NR_getxattr (__NR_SYSCALL_BASE + 229)
840#endif
841#ifndef __NR_lgetxattr
842#define __NR_lgetxattr (__NR_SYSCALL_BASE + 230)
843#endif
844#ifndef __NR_listxattr
845#define __NR_listxattr (__NR_SYSCALL_BASE + 232)
846#endif
847#ifndef __NR_llistxattr
848#define __NR_llistxattr (__NR_SYSCALL_BASE + 233)
849#endif
850#ifndef __NR_tkill
851#define __NR_tkill (__NR_SYSCALL_BASE + 238)
852#endif
853#ifndef __NR_futex
854#define __NR_futex (__NR_SYSCALL_BASE + 240)
855#endif
856#ifndef __NR_sched_setaffinity
857#define __NR_sched_setaffinity (__NR_SYSCALL_BASE + 241)
858#define __NR_sched_getaffinity (__NR_SYSCALL_BASE + 242)
859#endif
860#ifndef __NR_set_tid_address
861#define __NR_set_tid_address (__NR_SYSCALL_BASE + 256)
862#endif
863#ifndef __NR_clock_gettime
864#define __NR_clock_gettime (__NR_SYSCALL_BASE + 263)
865#endif
866#ifndef __NR_clock_getres
867#define __NR_clock_getres (__NR_SYSCALL_BASE + 264)
868#endif
869#ifndef __NR_statfs64
870#define __NR_statfs64 (__NR_SYSCALL_BASE + 266)
871#endif
872#ifndef __NR_fstatfs64
873#define __NR_fstatfs64 (__NR_SYSCALL_BASE + 267)
874#endif
875#ifndef __NR_ioprio_set
876#define __NR_ioprio_set (__NR_SYSCALL_BASE + 314)
877#endif
878#ifndef __NR_ioprio_get
879#define __NR_ioprio_get (__NR_SYSCALL_BASE + 315)
880#endif
881#ifndef __NR_move_pages
882#define __NR_move_pages (__NR_SYSCALL_BASE + 344)
883#endif
884#ifndef __NR_getcpu
885#define __NR_getcpu (__NR_SYSCALL_BASE + 345)
886#endif
887/* End of ARM 3/EABI definitions */
888#elif defined(__x86_64__)
889#ifndef __NR_pread64
890#define __NR_pread64 17
891#endif
892#ifndef __NR_pwrite64
893#define __NR_pwrite64 18
894#endif
895#ifndef __NR_setresuid
896#define __NR_setresuid 117
897#define __NR_getresuid 118
898#define __NR_setresgid 119
899#define __NR_getresgid 120
900#endif
901#ifndef __NR_quotactl
902#define __NR_quotactl 179
903#endif
904#ifndef __NR_gettid
905#define __NR_gettid 186
906#endif
907#ifndef __NR_readahead
908#define __NR_readahead 187
909#endif
910#ifndef __NR_setxattr
911#define __NR_setxattr 188
912#endif
913#ifndef __NR_lsetxattr
914#define __NR_lsetxattr 189
915#endif
916#ifndef __NR_getxattr
917#define __NR_getxattr 191
918#endif
919#ifndef __NR_lgetxattr
920#define __NR_lgetxattr 192
921#endif
922#ifndef __NR_listxattr
923#define __NR_listxattr 194
924#endif
925#ifndef __NR_llistxattr
926#define __NR_llistxattr 195
927#endif
928#ifndef __NR_tkill
929#define __NR_tkill 200
930#endif
931#ifndef __NR_futex
932#define __NR_futex 202
933#endif
934#ifndef __NR_sched_setaffinity
935#define __NR_sched_setaffinity 203
936#define __NR_sched_getaffinity 204
937#endif
938#ifndef __NR_getdents64
939#define __NR_getdents64 217
940#endif
941#ifndef __NR_set_tid_address
942#define __NR_set_tid_address 218
943#endif
944#ifndef __NR_fadvise64
945#define __NR_fadvise64 221
946#endif
947#ifndef __NR_clock_gettime
948#define __NR_clock_gettime 228
949#endif
950#ifndef __NR_clock_getres
951#define __NR_clock_getres 229
952#endif
953#ifndef __NR_ioprio_set
954#define __NR_ioprio_set 251
955#endif
956#ifndef __NR_ioprio_get
957#define __NR_ioprio_get 252
958#endif
959#ifndef __NR_openat
960#define __NR_openat 257
961#endif
962#ifndef __NR_newfstatat
963#define __NR_newfstatat 262
964#endif
965#ifndef __NR_unlinkat
966#define __NR_unlinkat 263
967#endif
968#ifndef __NR_move_pages
969#define __NR_move_pages 279
970#endif
971#ifndef __NR_fallocate
972#define __NR_fallocate 285
973#endif
974/* End of x86-64 definitions */
975#elif defined(__mips__)
976#if _MIPS_SIM == _MIPS_SIM_ABI32
977#ifndef __NR_setresuid
978#define __NR_setresuid (__NR_Linux + 185)
979#define __NR_getresuid (__NR_Linux + 186)
980#define __NR_setresgid (__NR_Linux + 190)
981#define __NR_getresgid (__NR_Linux + 191)
982#endif
983#ifndef __NR_rt_sigaction
984#define __NR_rt_sigreturn (__NR_Linux + 193)
985#define __NR_rt_sigaction (__NR_Linux + 194)
986#define __NR_rt_sigprocmask (__NR_Linux + 195)
987#define __NR_rt_sigpending (__NR_Linux + 196)
988#define __NR_rt_sigsuspend (__NR_Linux + 199)
989#endif
990#ifndef __NR_pread64
991#define __NR_pread64 (__NR_Linux + 200)
992#endif
993#ifndef __NR_pwrite64
994#define __NR_pwrite64 (__NR_Linux + 201)
995#endif
996#ifndef __NR_stat64
997#define __NR_stat64 (__NR_Linux + 213)
998#endif
999#ifndef __NR_fstat64
1000#define __NR_fstat64 (__NR_Linux + 215)
1001#endif
1002#ifndef __NR_getdents64
1003#define __NR_getdents64 (__NR_Linux + 219)
1004#endif
1005#ifndef __NR_gettid
1006#define __NR_gettid (__NR_Linux + 222)
1007#endif
1008#ifndef __NR_readahead
1009#define __NR_readahead (__NR_Linux + 223)
1010#endif
1011#ifndef __NR_setxattr
1012#define __NR_setxattr (__NR_Linux + 224)
1013#endif
1014#ifndef __NR_lsetxattr
1015#define __NR_lsetxattr (__NR_Linux + 225)
1016#endif
1017#ifndef __NR_getxattr
1018#define __NR_getxattr (__NR_Linux + 227)
1019#endif
1020#ifndef __NR_lgetxattr
1021#define __NR_lgetxattr (__NR_Linux + 228)
1022#endif
1023#ifndef __NR_listxattr
1024#define __NR_listxattr (__NR_Linux + 230)
1025#endif
1026#ifndef __NR_llistxattr
1027#define __NR_llistxattr (__NR_Linux + 231)
1028#endif
1029#ifndef __NR_tkill
1030#define __NR_tkill (__NR_Linux + 236)
1031#endif
1032#ifndef __NR_futex
1033#define __NR_futex (__NR_Linux + 238)
1034#endif
1035#ifndef __NR_sched_setaffinity
1036#define __NR_sched_setaffinity (__NR_Linux + 239)
1037#define __NR_sched_getaffinity (__NR_Linux + 240)
1038#endif
1039#ifndef __NR_set_tid_address
1040#define __NR_set_tid_address (__NR_Linux + 252)
1041#endif
1042#ifndef __NR_statfs64
1043#define __NR_statfs64 (__NR_Linux + 255)
1044#endif
1045#ifndef __NR_fstatfs64
1046#define __NR_fstatfs64 (__NR_Linux + 256)
1047#endif
1048#ifndef __NR_clock_gettime
1049#define __NR_clock_gettime (__NR_Linux + 263)
1050#endif
1051#ifndef __NR_clock_getres
1052#define __NR_clock_getres (__NR_Linux + 264)
1053#endif
1054#ifndef __NR_openat
1055#define __NR_openat (__NR_Linux + 288)
1056#endif
1057#ifndef __NR_fstatat
1058#define __NR_fstatat (__NR_Linux + 293)
1059#endif
1060#ifndef __NR_unlinkat
1061#define __NR_unlinkat (__NR_Linux + 294)
1062#endif
1063#ifndef __NR_move_pages
1064#define __NR_move_pages (__NR_Linux + 308)
1065#endif
1066#ifndef __NR_getcpu
1067#define __NR_getcpu (__NR_Linux + 312)
1068#endif
1069#ifndef __NR_ioprio_set
1070#define __NR_ioprio_set (__NR_Linux + 314)
1071#endif
1072#ifndef __NR_ioprio_get
1073#define __NR_ioprio_get (__NR_Linux + 315)
1074#endif
1075/* End of MIPS (old 32bit API) definitions */
1076#elif _MIPS_SIM == _MIPS_SIM_ABI64
1077#ifndef __NR_pread64
1078#define __NR_pread64 (__NR_Linux + 16)
1079#endif
1080#ifndef __NR_pwrite64
1081#define __NR_pwrite64 (__NR_Linux + 17)
1082#endif
1083#ifndef __NR_setresuid
1084#define __NR_setresuid (__NR_Linux + 115)
1085#define __NR_getresuid (__NR_Linux + 116)
1086#define __NR_setresgid (__NR_Linux + 117)
1087#define __NR_getresgid (__NR_Linux + 118)
1088#endif
1089#ifndef __NR_gettid
1090#define __NR_gettid (__NR_Linux + 178)
1091#endif
1092#ifndef __NR_readahead
1093#define __NR_readahead (__NR_Linux + 179)
1094#endif
1095#ifndef __NR_setxattr
1096#define __NR_setxattr (__NR_Linux + 180)
1097#endif
1098#ifndef __NR_lsetxattr
1099#define __NR_lsetxattr (__NR_Linux + 181)
1100#endif
1101#ifndef __NR_getxattr
1102#define __NR_getxattr (__NR_Linux + 183)
1103#endif
1104#ifndef __NR_lgetxattr
1105#define __NR_lgetxattr (__NR_Linux + 184)
1106#endif
1107#ifndef __NR_listxattr
1108#define __NR_listxattr (__NR_Linux + 186)
1109#endif
1110#ifndef __NR_llistxattr
1111#define __NR_llistxattr (__NR_Linux + 187)
1112#endif
1113#ifndef __NR_tkill
1114#define __NR_tkill (__NR_Linux + 192)
1115#endif
1116#ifndef __NR_futex
1117#define __NR_futex (__NR_Linux + 194)
1118#endif
1119#ifndef __NR_sched_setaffinity
1120#define __NR_sched_setaffinity (__NR_Linux + 195)
1121#define __NR_sched_getaffinity (__NR_Linux + 196)
1122#endif
1123#ifndef __NR_set_tid_address
1124#define __NR_set_tid_address (__NR_Linux + 212)
1125#endif
1126#ifndef __NR_clock_gettime
1127#define __NR_clock_gettime (__NR_Linux + 222)
1128#endif
1129#ifndef __NR_clock_getres
1130#define __NR_clock_getres (__NR_Linux + 223)
1131#endif
1132#ifndef __NR_openat
1133#define __NR_openat (__NR_Linux + 247)
1134#endif
1135#ifndef __NR_fstatat
1136#define __NR_fstatat (__NR_Linux + 252)
1137#endif
1138#ifndef __NR_unlinkat
1139#define __NR_unlinkat (__NR_Linux + 253)
1140#endif
1141#ifndef __NR_move_pages
1142#define __NR_move_pages (__NR_Linux + 267)
1143#endif
1144#ifndef __NR_getcpu
1145#define __NR_getcpu (__NR_Linux + 271)
1146#endif
1147#ifndef __NR_ioprio_set
1148#define __NR_ioprio_set (__NR_Linux + 273)
1149#endif
1150#ifndef __NR_ioprio_get
1151#define __NR_ioprio_get (__NR_Linux + 274)
1152#endif
1153/* End of MIPS (64bit API) definitions */
1154#else
1155#ifndef __NR_setresuid
1156#define __NR_setresuid (__NR_Linux + 115)
1157#define __NR_getresuid (__NR_Linux + 116)
1158#define __NR_setresgid (__NR_Linux + 117)
1159#define __NR_getresgid (__NR_Linux + 118)
1160#endif
1161#ifndef __NR_gettid
1162#define __NR_gettid (__NR_Linux + 178)
1163#endif
1164#ifndef __NR_readahead
1165#define __NR_readahead (__NR_Linux + 179)
1166#endif
1167#ifndef __NR_setxattr
1168#define __NR_setxattr (__NR_Linux + 180)
1169#endif
1170#ifndef __NR_lsetxattr
1171#define __NR_lsetxattr (__NR_Linux + 181)
1172#endif
1173#ifndef __NR_getxattr
1174#define __NR_getxattr (__NR_Linux + 183)
1175#endif
1176#ifndef __NR_lgetxattr
1177#define __NR_lgetxattr (__NR_Linux + 184)
1178#endif
1179#ifndef __NR_listxattr
1180#define __NR_listxattr (__NR_Linux + 186)
1181#endif
1182#ifndef __NR_llistxattr
1183#define __NR_llistxattr (__NR_Linux + 187)
1184#endif
1185#ifndef __NR_tkill
1186#define __NR_tkill (__NR_Linux + 192)
1187#endif
1188#ifndef __NR_futex
1189#define __NR_futex (__NR_Linux + 194)
1190#endif
1191#ifndef __NR_sched_setaffinity
1192#define __NR_sched_setaffinity (__NR_Linux + 195)
1193#define __NR_sched_getaffinity (__NR_Linux + 196)
1194#endif
1195#ifndef __NR_set_tid_address
1196#define __NR_set_tid_address (__NR_Linux + 213)
1197#endif
1198#ifndef __NR_statfs64
1199#define __NR_statfs64 (__NR_Linux + 217)
1200#endif
1201#ifndef __NR_fstatfs64
1202#define __NR_fstatfs64 (__NR_Linux + 218)
1203#endif
1204#ifndef __NR_clock_gettime
1205#define __NR_clock_gettime (__NR_Linux + 226)
1206#endif
1207#ifndef __NR_clock_getres
1208#define __NR_clock_getres (__NR_Linux + 227)
1209#endif
1210#ifndef __NR_openat
1211#define __NR_openat (__NR_Linux + 251)
1212#endif
1213#ifndef __NR_fstatat
1214#define __NR_fstatat (__NR_Linux + 256)
1215#endif
1216#ifndef __NR_unlinkat
1217#define __NR_unlinkat (__NR_Linux + 257)
1218#endif
1219#ifndef __NR_move_pages
1220#define __NR_move_pages (__NR_Linux + 271)
1221#endif
1222#ifndef __NR_getcpu
1223#define __NR_getcpu (__NR_Linux + 275)
1224#endif
1225#ifndef __NR_ioprio_set
1226#define __NR_ioprio_set (__NR_Linux + 277)
1227#endif
1228#ifndef __NR_ioprio_get
1229#define __NR_ioprio_get (__NR_Linux + 278)
1230#endif
1231/* End of MIPS (new 32bit API) definitions */
1232#endif
1233/* End of MIPS definitions */
1234#elif defined(__PPC__)
1235#ifndef __NR_setfsuid
1236#define __NR_setfsuid 138
1237#define __NR_setfsgid 139
1238#endif
1239#ifndef __NR_setresuid
1240#define __NR_setresuid 164
1241#define __NR_getresuid 165
1242#define __NR_setresgid 169
1243#define __NR_getresgid 170
1244#endif
1245#ifndef __NR_rt_sigaction
1246#define __NR_rt_sigreturn 172
1247#define __NR_rt_sigaction 173
1248#define __NR_rt_sigprocmask 174
1249#define __NR_rt_sigpending 175
1250#define __NR_rt_sigsuspend 178
1251#endif
1252#ifndef __NR_pread64
1253#define __NR_pread64 179
1254#endif
1255#ifndef __NR_pwrite64
1256#define __NR_pwrite64 180
1257#endif
1258#ifndef __NR_ugetrlimit
1259#define __NR_ugetrlimit 190
1260#endif
1261#ifndef __NR_readahead
1262#define __NR_readahead 191
1263#endif
1264#ifndef __NR_stat64
1265#define __NR_stat64 195
1266#endif
1267#ifndef __NR_fstat64
1268#define __NR_fstat64 197
1269#endif
1270#ifndef __NR_getdents64
1271#define __NR_getdents64 202
1272#endif
1273#ifndef __NR_gettid
1274#define __NR_gettid 207
1275#endif
1276#ifndef __NR_tkill
1277#define __NR_tkill 208
1278#endif
1279#ifndef __NR_setxattr
1280#define __NR_setxattr 209
1281#endif
1282#ifndef __NR_lsetxattr
1283#define __NR_lsetxattr 210
1284#endif
1285#ifndef __NR_getxattr
1286#define __NR_getxattr 212
1287#endif
1288#ifndef __NR_lgetxattr
1289#define __NR_lgetxattr 213
1290#endif
1291#ifndef __NR_listxattr
1292#define __NR_listxattr 215
1293#endif
1294#ifndef __NR_llistxattr
1295#define __NR_llistxattr 216
1296#endif
1297#ifndef __NR_futex
1298#define __NR_futex 221
1299#endif
1300#ifndef __NR_sched_setaffinity
1301#define __NR_sched_setaffinity 222
1302#define __NR_sched_getaffinity 223
1303#endif
1304#ifndef __NR_set_tid_address
1305#define __NR_set_tid_address 232
1306#endif
1307#ifndef __NR_clock_gettime
1308#define __NR_clock_gettime 246
1309#endif
1310#ifndef __NR_clock_getres
1311#define __NR_clock_getres 247
1312#endif
1313#ifndef __NR_statfs64
1314#define __NR_statfs64 252
1315#endif
1316#ifndef __NR_fstatfs64
1317#define __NR_fstatfs64 253
1318#endif
1319#ifndef __NR_fadvise64_64
1320#define __NR_fadvise64_64 254
1321#endif
1322#ifndef __NR_ioprio_set
1323#define __NR_ioprio_set 273
1324#endif
1325#ifndef __NR_ioprio_get
1326#define __NR_ioprio_get 274
1327#endif
1328#ifndef __NR_openat
1329#define __NR_openat 286
1330#endif
1331#ifndef __NR_fstatat64
1332#define __NR_fstatat64 291
1333#endif
1334#ifndef __NR_unlinkat
1335#define __NR_unlinkat 292
1336#endif
1337#ifndef __NR_move_pages
1338#define __NR_move_pages 301
1339#endif
1340#ifndef __NR_getcpu
1341#define __NR_getcpu 302
1342#endif
1343/* End of powerpc defininitions */
1344#endif
1345
1346
1347/* After forking, we must make sure to only call system calls. */
1348#if __BOUNDED_POINTERS__
1349 #error "Need to port invocations of syscalls for bounded ptrs"
1350#else
1351 /* The core dumper and the thread lister get executed after threads
1352 * have been suspended. As a consequence, we cannot call any functions
1353 * that acquire locks. Unfortunately, libc wraps most system calls
1354 * (e.g. in order to implement pthread_atfork, and to make calls
1355 * cancellable), which means we cannot call these functions. Instead,
1356 * we have to call syscall() directly.
1357 */
1358 #undef LSS_ERRNO
1359 #ifdef SYS_ERRNO
1360 /* Allow the including file to override the location of errno. This can
1361 * be useful when using clone() with the CLONE_VM option.
1362 */
1363 #define LSS_ERRNO SYS_ERRNO
1364 #else
1365 #define LSS_ERRNO errno
1366 #endif
1367
1368 #undef LSS_INLINE
1369 #ifdef SYS_INLINE
1370 #define LSS_INLINE SYS_INLINE
1371 #else
1372 #define LSS_INLINE static inline
1373 #endif
1374
1375 /* Allow the including file to override the prefix used for all new
1376 * system calls. By default, it will be set to "sys_".
1377 */
1378 #undef LSS_NAME
1379 #ifndef SYS_PREFIX
1380 #define LSS_NAME(name) sys_##name
1381 #elif SYS_PREFIX < 0
1382 #define LSS_NAME(name) name
1383 #elif SYS_PREFIX == 0
1384 #define LSS_NAME(name) sys0_##name
1385 #elif SYS_PREFIX == 1
1386 #define LSS_NAME(name) sys1_##name
1387 #elif SYS_PREFIX == 2
1388 #define LSS_NAME(name) sys2_##name
1389 #elif SYS_PREFIX == 3
1390 #define LSS_NAME(name) sys3_##name
1391 #elif SYS_PREFIX == 4
1392 #define LSS_NAME(name) sys4_##name
1393 #elif SYS_PREFIX == 5
1394 #define LSS_NAME(name) sys5_##name
1395 #elif SYS_PREFIX == 6
1396 #define LSS_NAME(name) sys6_##name
1397 #elif SYS_PREFIX == 7
1398 #define LSS_NAME(name) sys7_##name
1399 #elif SYS_PREFIX == 8
1400 #define LSS_NAME(name) sys8_##name
1401 #elif SYS_PREFIX == 9
1402 #define LSS_NAME(name) sys9_##name
1403 #endif
1404
1405 #undef LSS_RETURN
1406 #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) \
1407 || defined(__ARM_EABI__))
1408 /* Failing system calls return a negative result in the range of
1409 * -1..-4095. These are "errno" values with the sign inverted.
1410 */
1411 #define LSS_RETURN(type, res) \
1412 do { \
1413 if ((unsigned long)(res) >= (unsigned long)(-4095)) { \
1414 LSS_ERRNO = -(res); \
1415 res = -1; \
1416 } \
1417 return (type) (res); \
1418 } while (0)
1419 #elif defined(__mips__)
1420 /* On MIPS, failing system calls return -1, and set errno in a
1421 * separate CPU register.
1422 */
1423 #define LSS_RETURN(type, res, err) \
1424 do { \
1425 if (err) { \
1426 LSS_ERRNO = (res); \
1427 res = -1; \
1428 } \
1429 return (type) (res); \
1430 } while (0)
1431 #elif defined(__PPC__)
1432 /* On PPC, failing system calls return -1, and set errno in a
1433 * separate CPU register. See linux/unistd.h.
1434 */
1435 #define LSS_RETURN(type, res, err) \
1436 do { \
1437 if (err & 0x10000000 ) { \
1438 LSS_ERRNO = (res); \
1439 res = -1; \
1440 } \
1441 return (type) (res); \
1442 } while (0)
1443 #endif
1444 #if defined(__i386__)
1445 /* In PIC mode (e.g. when building shared libraries), gcc for i386
1446 * reserves ebx. Unfortunately, most distribution ship with implementations
1447 * of _syscallX() which clobber ebx.
1448 * Also, most definitions of _syscallX() neglect to mark "memory" as being
1449 * clobbered. This causes problems with compilers, that do a better job
1450 * at optimizing across __asm__ calls.
1451 * So, we just have to redefine all of the _syscallX() macros.
1452 */
1453 #undef LSS_ENTRYPOINT
1454 #ifdef SYS_SYSCALL_ENTRYPOINT
1455 static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
1456 void (**entrypoint)(void);
1457 asm volatile(".bss\n"
1458 ".align 8\n"
1459 ".globl "SYS_SYSCALL_ENTRYPOINT"\n"
1460 ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n"
1461 ".previous\n"
1462 /* This logically does 'lea "SYS_SYSCALL_ENTRYPOINT", %0' */
1463 "call 0f\n"
1464 "0:pop %0\n"
1465 "add $_GLOBAL_OFFSET_TABLE_+[.-0b], %0\n"
1466 "mov "SYS_SYSCALL_ENTRYPOINT"@GOT(%0), %0\n"
1467 : "=r"(entrypoint));
1468 return entrypoint;
1469 }
1470
1471 #define LSS_ENTRYPOINT ".bss\n" \
1472 ".align 8\n" \
1473 ".globl "SYS_SYSCALL_ENTRYPOINT"\n" \
1474 ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n" \
1475 ".previous\n" \
1476 /* Check the SYS_SYSCALL_ENTRYPOINT vector */ \
1477 "push %%eax\n" \
1478 "call 10000f\n" \
1479 "10000:pop %%eax\n" \
1480 "add $_GLOBAL_OFFSET_TABLE_+[.-10000b], %%eax\n" \
1481 "mov "SYS_SYSCALL_ENTRYPOINT"@GOT(%%eax), %%eax\n"\
1482 "mov 0(%%eax), %%eax\n" \
1483 "test %%eax, %%eax\n" \
1484 "jz 10001f\n" \
1485 "push %%eax\n" \
1486 "lea 10002f, %%eax\n" \
1487 "xchg 4(%%esp), %%eax\n" \
1488 "ret\n" \
1489 "10001:pop %%eax\n" \
1490 "int $0x80\n" \
1491 "10002:\n"
1492 #else
1493 #define LSS_ENTRYPOINT "int $0x80\n"
1494 #endif
1495 #undef LSS_BODY
1496 #define LSS_BODY(type,args...) \
1497 long __res; \
1498 __asm__ __volatile__("push %%ebx\n" \
1499 "movl %2,%%ebx\n" \
1500 LSS_ENTRYPOINT \
1501 "pop %%ebx" \
1502 args \
1503 : "esp", "memory"); \
1504 LSS_RETURN(type,__res)
1505 #undef _syscall0
1506 #define _syscall0(type,name) \
1507 type LSS_NAME(name)(void) { \
1508 long __res; \
1509 __asm__ volatile(LSS_ENTRYPOINT \
1510 : "=a" (__res) \
1511 : "0" (__NR_##name) \
1512 : "esp", "memory"); \
1513 LSS_RETURN(type,__res); \
1514 }
1515 #undef _syscall1
1516 #define _syscall1(type,name,type1,arg1) \
1517 type LSS_NAME(name)(type1 arg1) { \
1518 LSS_BODY(type, \
1519 : "=a" (__res) \
1520 : "0" (__NR_##name), "ri" ((long)(arg1))); \
1521 }
1522 #undef _syscall2
1523 #define _syscall2(type,name,type1,arg1,type2,arg2) \
1524 type LSS_NAME(name)(type1 arg1,type2 arg2) { \
1525 LSS_BODY(type, \
1526 : "=a" (__res) \
1527 : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2))); \
1528 }
1529 #undef _syscall3
1530 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
1531 type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) { \
1532 LSS_BODY(type, \
1533 : "=a" (__res) \
1534 : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
1535 "d" ((long)(arg3))); \
1536 }
1537 #undef _syscall4
1538 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
1539 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
1540 LSS_BODY(type, \
1541 : "=a" (__res) \
1542 : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \
1543 "d" ((long)(arg3)),"S" ((long)(arg4))); \
1544 }
1545 #undef _syscall5
1546 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1547 type5,arg5) \
1548 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1549 type5 arg5) { \
1550 long __res; \
1551 __asm__ __volatile__("push %%ebx\n" \
1552 "movl %2,%%ebx\n" \
1553 "movl %1,%%eax\n" \
1554 LSS_ENTRYPOINT \
1555 "pop %%ebx" \
1556 : "=a" (__res) \
1557 : "i" (__NR_##name), "ri" ((long)(arg1)), \
1558 "c" ((long)(arg2)), "d" ((long)(arg3)), \
1559 "S" ((long)(arg4)), "D" ((long)(arg5)) \
1560 : "esp", "memory"); \
1561 LSS_RETURN(type,__res); \
1562 }
1563 #undef _syscall6
1564 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1565 type5,arg5,type6,arg6) \
1566 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1567 type5 arg5, type6 arg6) { \
1568 long __res; \
1569 struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 }; \
1570 __asm__ __volatile__("push %%ebp\n" \
1571 "push %%ebx\n" \
1572 "movl 4(%2),%%ebp\n" \
1573 "movl 0(%2), %%ebx\n" \
1574 "movl %1,%%eax\n" \
1575 LSS_ENTRYPOINT \
1576 "pop %%ebx\n" \
1577 "pop %%ebp" \
1578 : "=a" (__res) \
1579 : "i" (__NR_##name), "0" ((long)(&__s)), \
1580 "c" ((long)(arg2)), "d" ((long)(arg3)), \
1581 "S" ((long)(arg4)), "D" ((long)(arg5)) \
1582 : "esp", "memory"); \
1583 LSS_RETURN(type,__res); \
1584 }
1585 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
1586 int flags, void *arg, int *parent_tidptr,
1587 void *newtls, int *child_tidptr) {
1588 long __res;
1589 __asm__ __volatile__(/* if (fn == NULL)
1590 * return -EINVAL;
1591 */
1592 "movl %3,%%ecx\n"
1593 "jecxz 1f\n"
1594
1595 /* if (child_stack == NULL)
1596 * return -EINVAL;
1597 */
1598 "movl %4,%%ecx\n"
1599 "jecxz 1f\n"
1600
1601 /* Set up alignment of the child stack:
1602 * child_stack = (child_stack & ~0xF) - 20;
1603 */
1604 "andl $-16,%%ecx\n"
1605 "subl $20,%%ecx\n"
1606
1607 /* Push "arg" and "fn" onto the stack that will be
1608 * used by the child.
1609 */
1610 "movl %6,%%eax\n"
1611 "movl %%eax,4(%%ecx)\n"
1612 "movl %3,%%eax\n"
1613 "movl %%eax,(%%ecx)\n"
1614
1615 /* %eax = syscall(%eax = __NR_clone,
1616 * %ebx = flags,
1617 * %ecx = child_stack,
1618 * %edx = parent_tidptr,
1619 * %esi = newtls,
1620 * %edi = child_tidptr)
1621 * Also, make sure that %ebx gets preserved as it is
1622 * used in PIC mode.
1623 */
1624 "movl %8,%%esi\n"
1625 "movl %7,%%edx\n"
1626 "movl %5,%%eax\n"
1627 "movl %9,%%edi\n"
1628 "pushl %%ebx\n"
1629 "movl %%eax,%%ebx\n"
1630 "movl %2,%%eax\n"
1631 LSS_ENTRYPOINT
1632
1633 /* In the parent: restore %ebx
1634 * In the child: move "fn" into %ebx
1635 */
1636 "popl %%ebx\n"
1637
1638 /* if (%eax != 0)
1639 * return %eax;
1640 */
1641 "test %%eax,%%eax\n"
1642 "jnz 1f\n"
1643
1644 /* In the child, now. Terminate frame pointer chain.
1645 */
1646 "movl $0,%%ebp\n"
1647
1648 /* Call "fn". "arg" is already on the stack.
1649 */
1650 "call *%%ebx\n"
1651
1652 /* Call _exit(%ebx). Unfortunately older versions
1653 * of gcc restrict the number of arguments that can
1654 * be passed to asm(). So, we need to hard-code the
1655 * system call number.
1656 */
1657 "movl %%eax,%%ebx\n"
1658 "movl $1,%%eax\n"
1659 LSS_ENTRYPOINT
1660
1661 /* Return to parent.
1662 */
1663 "1:\n"
1664 : "=a" (__res)
1665 : "0"(-EINVAL), "i"(__NR_clone),
1666 "m"(fn), "m"(child_stack), "m"(flags), "m"(arg),
1667 "m"(parent_tidptr), "m"(newtls), "m"(child_tidptr)
1668 : "esp", "memory", "ecx", "edx", "esi", "edi");
1669 LSS_RETURN(int, __res);
1670 }
1671
1672 #define __NR__fadvise64_64 __NR_fadvise64_64
1673 LSS_INLINE _syscall6(int, _fadvise64_64, int, fd,
1674 unsigned, offset_lo, unsigned, offset_hi,
1675 unsigned, len_lo, unsigned, len_hi,
1676 int, advice)
1677
1678 LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset,
1679 loff_t len, int advice) {
1680 return LSS_NAME(_fadvise64_64)(fd,
1681 (unsigned)offset, (unsigned)(offset >>32),
1682 (unsigned)len, (unsigned)(len >> 32),
1683 advice);
1684 }
1685
1686 #define __NR__fallocate __NR_fallocate
1687 LSS_INLINE _syscall6(int, _fallocate, int, fd,
1688 int, mode,
1689 unsigned, offset_lo, unsigned, offset_hi,
1690 unsigned, len_lo, unsigned, len_hi)
1691
1692 LSS_INLINE int LSS_NAME(fallocate)(int fd, int mode,
1693 loff_t offset, loff_t len) {
1694 union { loff_t off; unsigned w[2]; } o = { offset }, l = { len };
1695 return LSS_NAME(_fallocate)(fd, mode, o.w[0], o.w[1], l.w[0], l.w[1]);
1696 }
1697
1698 LSS_INLINE _syscall1(int, set_thread_area, void *, u)
1699 LSS_INLINE _syscall1(int, get_thread_area, void *, u)
1700
1701 LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
1702 /* On i386, the kernel does not know how to return from a signal
1703 * handler. Instead, it relies on user space to provide a
1704 * restorer function that calls the {rt_,}sigreturn() system call.
1705 * Unfortunately, we cannot just reference the glibc version of this
1706 * function, as glibc goes out of its way to make it inaccessible.
1707 */
1708 void (*res)(void);
1709 __asm__ __volatile__("call 2f\n"
1710 "0:.align 16\n"
1711 "1:movl %1,%%eax\n"
1712 LSS_ENTRYPOINT
1713 "2:popl %0\n"
1714 "addl $(1b-0b),%0\n"
1715 : "=a" (res)
1716 : "i" (__NR_rt_sigreturn));
1717 return res;
1718 }
1719 LSS_INLINE void (*LSS_NAME(restore)(void))(void) {
1720 /* On i386, the kernel does not know how to return from a signal
1721 * handler. Instead, it relies on user space to provide a
1722 * restorer function that calls the {rt_,}sigreturn() system call.
1723 * Unfortunately, we cannot just reference the glibc version of this
1724 * function, as glibc goes out of its way to make it inaccessible.
1725 */
1726 void (*res)(void);
1727 __asm__ __volatile__("call 2f\n"
1728 "0:.align 16\n"
1729 "1:pop %%eax\n"
1730 "movl %1,%%eax\n"
1731 LSS_ENTRYPOINT
1732 "2:popl %0\n"
1733 "addl $(1b-0b),%0\n"
1734 : "=a" (res)
1735 : "i" (__NR_sigreturn));
1736 return res;
1737 }
1738 #elif defined(__x86_64__)
1739 /* There are no known problems with any of the _syscallX() macros
1740 * currently shipping for x86_64, but we still need to be able to define
1741 * our own version so that we can override the location of the errno
1742 * location (e.g. when using the clone() system call with the CLONE_VM
1743 * option).
1744 */
1745 #undef LSS_ENTRYPOINT
1746 #ifdef SYS_SYSCALL_ENTRYPOINT
1747 static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) {
1748 void (**entrypoint)(void);
1749 asm volatile(".bss\n"
1750 ".align 8\n"
1751 ".globl "SYS_SYSCALL_ENTRYPOINT"\n"
1752 ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n"
1753 ".previous\n"
1754 "mov "SYS_SYSCALL_ENTRYPOINT"@GOTPCREL(%%rip), %0\n"
1755 : "=r"(entrypoint));
1756 return entrypoint;
1757 }
1758
1759 #define LSS_ENTRYPOINT \
1760 ".bss\n" \
1761 ".align 8\n" \
1762 ".globl "SYS_SYSCALL_ENTRYPOINT"\n" \
1763 ".common "SYS_SYSCALL_ENTRYPOINT",8,8\n" \
1764 ".previous\n" \
1765 "mov "SYS_SYSCALL_ENTRYPOINT"@GOTPCREL(%%rip), %%rcx\n" \
1766 "mov 0(%%rcx), %%rcx\n" \
1767 "test %%rcx, %%rcx\n" \
1768 "jz 10001f\n" \
1769 "call *%%rcx\n" \
1770 "jmp 10002f\n" \
1771 "10001:syscall\n" \
1772 "10002:\n"
1773
1774 #else
1775 #define LSS_ENTRYPOINT "syscall\n"
1776 #endif
1777 #undef LSS_BODY
1778 #define LSS_BODY(type,name, ...) \
1779 long __res; \
1780 __asm__ __volatile__(LSS_ENTRYPOINT \
1781 : "=a" (__res) : "0" (__NR_##name), \
1782 ##__VA_ARGS__ : "r11", "rcx", "memory"); \
1783 LSS_RETURN(type, __res)
1784 #undef _syscall0
1785 #define _syscall0(type,name) \
1786 type LSS_NAME(name)() { \
1787 LSS_BODY(type, name); \
1788 }
1789 #undef _syscall1
1790 #define _syscall1(type,name,type1,arg1) \
1791 type LSS_NAME(name)(type1 arg1) { \
1792 LSS_BODY(type, name, "D" ((long)(arg1))); \
1793 }
1794 #undef _syscall2
1795 #define _syscall2(type,name,type1,arg1,type2,arg2) \
1796 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
1797 LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2))); \
1798 }
1799 #undef _syscall3
1800 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
1801 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
1802 LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2)), \
1803 "d" ((long)(arg3))); \
1804 }
1805 #undef _syscall4
1806 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
1807 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
1808 long __res; \
1809 __asm__ __volatile__("movq %5,%%r10;" LSS_ENTRYPOINT : \
1810 "=a" (__res) : "0" (__NR_##name), \
1811 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
1812 "r" ((long)(arg4)) : "r10", "r11", "rcx", "memory"); \
1813 LSS_RETURN(type, __res); \
1814 }
1815 #undef _syscall5
1816 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1817 type5,arg5) \
1818 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1819 type5 arg5) { \
1820 long __res; \
1821 __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8;" LSS_ENTRYPOINT :\
1822 "=a" (__res) : "0" (__NR_##name), \
1823 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
1824 "r" ((long)(arg4)), "r" ((long)(arg5)) : \
1825 "r8", "r10", "r11", "rcx", "memory"); \
1826 LSS_RETURN(type, __res); \
1827 }
1828 #undef _syscall6
1829 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1830 type5,arg5,type6,arg6) \
1831 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1832 type5 arg5, type6 arg6) { \
1833 long __res; \
1834 __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; movq %7,%%r9;" \
1835 LSS_ENTRYPOINT : \
1836 "=a" (__res) : "0" (__NR_##name), \
1837 "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \
1838 "r" ((long)(arg4)), "r" ((long)(arg5)), "r" ((long)(arg6)) : \
1839 "r8", "r9", "r10", "r11", "rcx", "memory"); \
1840 LSS_RETURN(type, __res); \
1841 }
1842 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
1843 int flags, void *arg, int *parent_tidptr,
1844 void *newtls, int *child_tidptr) {
1845 long __res;
1846 {
1847 register void *__tls __asm__("r8") = newtls;
1848 register int *__ctid __asm__("r10") = child_tidptr;
1849 __asm__ __volatile__(/* if (fn == NULL)
1850 * return -EINVAL;
1851 */
1852 "testq %4,%4\n"
1853 "jz 1f\n"
1854
1855 /* if (child_stack == NULL)
1856 * return -EINVAL;
1857 */
1858 "testq %5,%5\n"
1859 "jz 1f\n"
1860
1861 /* childstack -= 2*sizeof(void *);
1862 */
1863 "subq $16,%5\n"
1864
1865 /* Push "arg" and "fn" onto the stack that will be
1866 * used by the child.
1867 */
1868 "movq %7,8(%5)\n"
1869 "movq %4,0(%5)\n"
1870
1871 /* %rax = syscall(%rax = __NR_clone,
1872 * %rdi = flags,
1873 * %rsi = child_stack,
1874 * %rdx = parent_tidptr,
1875 * %r8 = new_tls,
1876 * %r10 = child_tidptr)
1877 */
1878 "movq %2,%%rax\n"
1879 LSS_ENTRYPOINT
1880
1881 /* if (%rax != 0)
1882 * return;
1883 */
1884 "testq %%rax,%%rax\n"
1885 "jnz 1f\n"
1886
1887 /* In the child. Terminate frame pointer chain.
1888 */
1889 "xorq %%rbp,%%rbp\n"
1890
1891 /* Call "fn(arg)".
1892 */
1893 "popq %%rax\n"
1894 "popq %%rdi\n"
1895 "call *%%rax\n"
1896
1897 /* Call _exit(%ebx).
1898 */
1899 "movq %%rax,%%rdi\n"
1900 "movq %3,%%rax\n"
1901 LSS_ENTRYPOINT
1902
1903 /* Return to parent.
1904 */
1905 "1:\n"
1906 : "=a" (__res)
1907 : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
1908 "r"(fn), "S"(child_stack), "D"(flags), "r"(arg),
1909 "d"(parent_tidptr), "r"(__tls), "r"(__ctid)
1910 : "rsp", "memory", "r11", "rcx");
1911 }
1912 LSS_RETURN(int, __res);
1913 }
1914 LSS_INLINE _syscall2(int, arch_prctl, int, c, void *, a)
1915 LSS_INLINE _syscall4(int, fadvise64, int, fd, loff_t, offset, loff_t, len,
1916 int, advice)
1917
1918 LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
1919 /* On x86-64, the kernel does not know how to return from
1920 * a signal handler. Instead, it relies on user space to provide a
1921 * restorer function that calls the rt_sigreturn() system call.
1922 * Unfortunately, we cannot just reference the glibc version of this
1923 * function, as glibc goes out of its way to make it inaccessible.
1924 */
1925 void (*res)(void);
1926 __asm__ __volatile__("call 2f\n"
1927 "0:.align 16\n"
1928 "1:movq %1,%%rax\n"
1929 LSS_ENTRYPOINT
1930 "2:popq %0\n"
1931 "addq $(1b-0b),%0\n"
1932 : "=a" (res)
1933 : "i" (__NR_rt_sigreturn));
1934 return res;
1935 }
1936 #elif defined(__ARM_ARCH_3__)
1937 /* Most definitions of _syscallX() neglect to mark "memory" as being
1938 * clobbered. This causes problems with compilers, that do a better job
1939 * at optimizing across __asm__ calls.
1940 * So, we just have to redefine all of the _syscallX() macros.
1941 */
1942 #undef LSS_REG
1943 #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
1944 #undef LSS_BODY
1945 #define LSS_BODY(type,name,args...) \
1946 register long __res_r0 __asm__("r0"); \
1947 long __res; \
1948 __asm__ __volatile__ (__syscall(name) \
1949 : "=r"(__res_r0) : args : "lr", "memory"); \
1950 __res = __res_r0; \
1951 LSS_RETURN(type, __res)
1952 #undef _syscall0
1953 #define _syscall0(type, name) \
1954 type LSS_NAME(name)() { \
1955 LSS_BODY(type, name); \
1956 }
1957 #undef _syscall1
1958 #define _syscall1(type, name, type1, arg1) \
1959 type LSS_NAME(name)(type1 arg1) { \
1960 LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
1961 }
1962 #undef _syscall2
1963 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1964 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
1965 LSS_REG(0, arg1); LSS_REG(1, arg2); \
1966 LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
1967 }
1968 #undef _syscall3
1969 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1970 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
1971 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
1972 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
1973 }
1974 #undef _syscall4
1975 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
1976 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
1977 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
1978 LSS_REG(3, arg4); \
1979 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
1980 }
1981 #undef _syscall5
1982 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1983 type5,arg5) \
1984 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1985 type5 arg5) { \
1986 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
1987 LSS_REG(3, arg4); LSS_REG(4, arg5); \
1988 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
1989 "r"(__r4)); \
1990 }
1991 #undef _syscall6
1992 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
1993 type5,arg5,type6,arg6) \
1994 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
1995 type5 arg5, type6 arg6) { \
1996 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
1997 LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
1998 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
1999 "r"(__r4), "r"(__r5)); \
2000 }
2001 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
2002 int flags, void *arg, int *parent_tidptr,
2003 void *newtls, int *child_tidptr) {
2004 long __res;
2005 {
2006 register int __flags __asm__("r0") = flags;
2007 register void *__stack __asm__("r1") = child_stack;
2008 register void *__ptid __asm__("r2") = parent_tidptr;
2009 register void *__tls __asm__("r3") = newtls;
2010 register int *__ctid __asm__("r4") = child_tidptr;
2011 __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)
2012 * return -EINVAL;
2013 */
2014 "cmp %2,#0\n"
2015 "cmpne %3,#0\n"
2016 "moveq %0,%1\n"
2017 "beq 1f\n"
2018
2019 /* Push "arg" and "fn" onto the stack that will be
2020 * used by the child.
2021 */
2022 "str %5,[%3,#-4]!\n"
2023 "str %2,[%3,#-4]!\n"
2024
2025 /* %r0 = syscall(%r0 = flags,
2026 * %r1 = child_stack,
2027 * %r2 = parent_tidptr,
2028 * %r3 = newtls,
2029 * %r4 = child_tidptr)
2030 */
2031 __syscall(clone)"\n"
2032
2033 /* if (%r0 != 0)
2034 * return %r0;
2035 */
2036 "movs %0,r0\n"
2037 "bne 1f\n"
2038
2039 /* In the child, now. Call "fn(arg)".
2040 */
2041 "ldr r0,[sp, #4]\n"
2042 "mov lr,pc\n"
2043 "ldr pc,[sp]\n"
2044
2045 /* Call _exit(%r0).
2046 */
2047 __syscall(exit)"\n"
2048 "1:\n"
2049 : "=r" (__res)
2050 : "i"(-EINVAL),
2051 "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
2052 "r"(__ptid), "r"(__tls), "r"(__ctid)
2053 : "cc", "lr", "memory");
2054 }
2055 LSS_RETURN(int, __res);
2056 }
2057 #elif defined(__ARM_EABI__)
2058 /* Most definitions of _syscallX() neglect to mark "memory" as being
2059 * clobbered. This causes problems with compilers, that do a better job
2060 * at optimizing across __asm__ calls.
2061 * So, we just have to redefine all fo the _syscallX() macros.
2062 */
2063 #undef LSS_REG
2064 #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a
2065 #undef LSS_BODY
2066 #define LSS_BODY(type,name,args...) \
2067 register long __res_r0 __asm__("r0"); \
2068 long __res; \
2069 __asm__ __volatile__ ("push {r7}\n" \
2070 "mov r7, %1\n" \
2071 "swi 0x0\n" \
2072 "pop {r7}\n" \
2073 : "=r"(__res_r0) \
2074 : "i"(__NR_##name) , ## args \
2075 : "lr", "memory"); \
2076 __res = __res_r0; \
2077 LSS_RETURN(type, __res)
2078 #undef _syscall0
2079 #define _syscall0(type, name) \
2080 type LSS_NAME(name)() { \
2081 LSS_BODY(type, name); \
2082 }
2083 #undef _syscall1
2084 #define _syscall1(type, name, type1, arg1) \
2085 type LSS_NAME(name)(type1 arg1) { \
2086 LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \
2087 }
2088 #undef _syscall2
2089 #define _syscall2(type, name, type1, arg1, type2, arg2) \
2090 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
2091 LSS_REG(0, arg1); LSS_REG(1, arg2); \
2092 LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \
2093 }
2094 #undef _syscall3
2095 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
2096 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
2097 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
2098 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \
2099 }
2100 #undef _syscall4
2101 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
2102 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
2103 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
2104 LSS_REG(3, arg4); \
2105 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \
2106 }
2107 #undef _syscall5
2108 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2109 type5,arg5) \
2110 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2111 type5 arg5) { \
2112 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
2113 LSS_REG(3, arg4); LSS_REG(4, arg5); \
2114 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
2115 "r"(__r4)); \
2116 }
2117 #undef _syscall6
2118 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2119 type5,arg5,type6,arg6) \
2120 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2121 type5 arg5, type6 arg6) { \
2122 LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \
2123 LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \
2124 LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \
2125 "r"(__r4), "r"(__r5)); \
2126 }
2127 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
2128 int flags, void *arg, int *parent_tidptr,
2129 void *newtls, int *child_tidptr) {
2130 long __res;
2131 {
2132 register int __flags __asm__("r0") = flags;
2133 register void *__stack __asm__("r1") = child_stack;
2134 register void *__ptid __asm__("r2") = parent_tidptr;
2135 register void *__tls __asm__("r3") = newtls;
2136 register int *__ctid __asm__("r4") = child_tidptr;
2137 __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)
2138 * return -EINVAL;
2139 */
2140 "cmp %2,#0\n"
2141 "cmpne %3,#0\n"
2142 "moveq %0,%1\n"
2143 "beq 1f\n"
2144
2145 /* Push "arg" and "fn" onto the stack that will be
2146 * used by the child.
2147 */
2148 "str %5,[%3,#-4]!\n"
2149 "str %2,[%3,#-4]!\n"
2150
2151 /* %r0 = syscall(%r0 = flags,
2152 * %r1 = child_stack,
2153 * %r2 = parent_tidptr,
2154 * %r3 = newtls,
2155 * %r4 = child_tidptr)
2156 */
2157 "mov r7, %9\n"
2158 "swi 0x0\n"
2159
2160 /* if (%r0 != 0)
2161 * return %r0;
2162 */
2163 "movs %0,r0\n"
2164 "bne 1f\n"
2165
2166 /* In the child, now. Call "fn(arg)".
2167 */
2168 "ldr r0,[sp, #4]\n"
2169 "mov lr,pc\n"
2170 "ldr pc,[sp]\n"
2171
2172 /* Call _exit(%r0).
2173 */
2174 "mov r7, %10\n"
2175 "swi 0x0\n"
2176 "1:\n"
2177 : "=r" (__res)
2178 : "i"(-EINVAL),
2179 "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
2180 "r"(__ptid), "r"(__tls), "r"(__ctid),
2181 "i"(__NR_clone), "i"(__NR_exit)
2182 : "cc", "r7", "lr", "memory");
2183 }
2184 LSS_RETURN(int, __res);
2185 }
2186 #elif defined(__mips__)
2187 #undef LSS_REG
2188 #define LSS_REG(r,a) register unsigned long __r##r __asm__("$"#r) = \
2189 (unsigned long)(a)
2190 #undef LSS_BODY
2191 #define LSS_BODY(type,name,r7,...) \
2192 register unsigned long __v0 __asm__("$2") = __NR_##name; \
2193 __asm__ __volatile__ ("syscall\n" \
2194 : "=&r"(__v0), r7 (__r7) \
2195 : "0"(__v0), ##__VA_ARGS__ \
2196 : "$8", "$9", "$10", "$11", "$12", \
2197 "$13", "$14", "$15", "$24", "memory"); \
2198 LSS_RETURN(type, __v0, __r7)
2199 #undef _syscall0
2200 #define _syscall0(type, name) \
2201 type LSS_NAME(name)() { \
2202 register unsigned long __r7 __asm__("$7"); \
2203 LSS_BODY(type, name, "=r"); \
2204 }
2205 #undef _syscall1
2206 #define _syscall1(type, name, type1, arg1) \
2207 type LSS_NAME(name)(type1 arg1) { \
2208 register unsigned long __r7 __asm__("$7"); \
2209 LSS_REG(4, arg1); LSS_BODY(type, name, "=r", "r"(__r4)); \
2210 }
2211 #undef _syscall2
2212 #define _syscall2(type, name, type1, arg1, type2, arg2) \
2213 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
2214 register unsigned long __r7 __asm__("$7"); \
2215 LSS_REG(4, arg1); LSS_REG(5, arg2); \
2216 LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5)); \
2217 }
2218 #undef _syscall3
2219 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
2220 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
2221 register unsigned long __r7 __asm__("$7"); \
2222 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2223 LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5), "r"(__r6)); \
2224 }
2225 #undef _syscall4
2226 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
2227 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
2228 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2229 LSS_REG(7, arg4); \
2230 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6)); \
2231 }
2232 #undef _syscall5
2233 #if _MIPS_SIM == _MIPS_SIM_ABI32
2234 /* The old 32bit MIPS system call API passes the fifth and sixth argument
2235 * on the stack, whereas the new APIs use registers "r8" and "r9".
2236 */
2237 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2238 type5,arg5) \
2239 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2240 type5 arg5) { \
2241 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2242 LSS_REG(7, arg4); \
2243 register unsigned long __v0 __asm__("$2"); \
2244 __asm__ __volatile__ (".set noreorder\n" \
2245 "lw $2, %6\n" \
2246 "subu $29, 32\n" \
2247 "sw $2, 16($29)\n" \
2248 "li $2, %2\n" \
2249 "syscall\n" \
2250 "addiu $29, 32\n" \
2251 ".set reorder\n" \
2252 : "=&r"(__v0), "+r" (__r7) \
2253 : "i" (__NR_##name), "r"(__r4), "r"(__r5), \
2254 "r"(__r6), "m" ((unsigned long)arg5) \
2255 : "$8", "$9", "$10", "$11", "$12", \
2256 "$13", "$14", "$15", "$24", "memory"); \
2257 LSS_RETURN(type, __v0, __r7); \
2258 }
2259 #else
2260 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2261 type5,arg5) \
2262 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2263 type5 arg5) { \
2264 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2265 LSS_REG(7, arg4); LSS_REG(8, arg5); \
2266 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
2267 "r"(__r8)); \
2268 }
2269 #endif
2270 #undef _syscall6
2271 #if _MIPS_SIM == _MIPS_SIM_ABI32
2272 /* The old 32bit MIPS system call API passes the fifth and sixth argument
2273 * on the stack, whereas the new APIs use registers "r8" and "r9".
2274 */
2275 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2276 type5,arg5,type6,arg6) \
2277 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2278 type5 arg5, type6 arg6) { \
2279 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2280 LSS_REG(7, arg4); \
2281 register unsigned long __v0 __asm__("$2"); \
2282 __asm__ __volatile__ (".set noreorder\n" \
2283 "lw $2, %6\n" \
2284 "lw $8, %7\n" \
2285 "subu $29, 32\n" \
2286 "sw $2, 16($29)\n" \
2287 "sw $8, 20($29)\n" \
2288 "li $2, %2\n" \
2289 "syscall\n" \
2290 "addiu $29, 32\n" \
2291 ".set reorder\n" \
2292 : "=&r"(__v0), "+r" (__r7) \
2293 : "i" (__NR_##name), "r"(__r4), "r"(__r5), \
2294 "r"(__r6), "r" ((unsigned long)arg5), \
2295 "r" ((unsigned long)arg6) \
2296 : "$8", "$9", "$10", "$11", "$12", \
2297 "$13", "$14", "$15", "$24", "memory"); \
2298 LSS_RETURN(type, __v0, __r7); \
2299 }
2300 #else
2301 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
2302 type5,arg5,type6,arg6) \
2303 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2304 type5 arg5,type6 arg6) { \
2305 LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \
2306 LSS_REG(7, arg4); LSS_REG(8, arg5); LSS_REG(9, arg6); \
2307 LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \
2308 "r"(__r8), "r"(__r9)); \
2309 }
2310 #endif
2311 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
2312 int flags, void *arg, int *parent_tidptr,
2313 void *newtls, int *child_tidptr) {
2314 register unsigned long __v0 __asm__("$2");
2315 register unsigned long __r7 __asm__("$7") = (unsigned long)newtls;
2316 {
2317 register int __flags __asm__("$4") = flags;
2318 register void *__stack __asm__("$5") = child_stack;
2319 register void *__ptid __asm__("$6") = parent_tidptr;
2320 register int *__ctid __asm__("$8") = child_tidptr;
2321 __asm__ __volatile__(
2322 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
2323 "subu $29,24\n"
2324 #elif _MIPS_SIM == _MIPS_SIM_NABI32
2325 "sub $29,16\n"
2326 #else
2327 "dsubu $29,16\n"
2328 #endif
2329
2330 /* if (fn == NULL || child_stack == NULL)
2331 * return -EINVAL;
2332 */
2333 "li %0,%2\n"
2334 "beqz %5,1f\n"
2335 "beqz %6,1f\n"
2336
2337 /* Push "arg" and "fn" onto the stack that will be
2338 * used by the child.
2339 */
2340 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
2341 "subu %6,32\n"
2342 "sw %5,0(%6)\n"
2343 "sw %8,4(%6)\n"
2344 #elif _MIPS_SIM == _MIPS_SIM_NABI32
2345 "sub %6,32\n"
2346 "sw %5,0(%6)\n"
2347 "sw %8,8(%6)\n"
2348 #else
2349 "dsubu %6,32\n"
2350 "sd %5,0(%6)\n"
2351 "sd %8,8(%6)\n"
2352 #endif
2353
2354 /* $7 = syscall($4 = flags,
2355 * $5 = child_stack,
2356 * $6 = parent_tidptr,
2357 * $7 = newtls,
2358 * $8 = child_tidptr)
2359 */
2360 "li $2,%3\n"
2361 "syscall\n"
2362
2363 /* if ($7 != 0)
2364 * return $2;
2365 */
2366 "bnez $7,1f\n"
2367 "bnez $2,1f\n"
2368
2369 /* In the child, now. Call "fn(arg)".
2370 */
2371 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
2372 "lw $25,0($29)\n"
2373 "lw $4,4($29)\n"
2374 #elif _MIPS_SIM == _MIPS_SIM_NABI32
2375 "lw $25,0($29)\n"
2376 "lw $4,8($29)\n"
2377 #else
2378 "ld $25,0($29)\n"
2379 "ld $4,8($29)\n"
2380 #endif
2381 "jalr $25\n"
2382
2383 /* Call _exit($2)
2384 */
2385 "move $4,$2\n"
2386 "li $2,%4\n"
2387 "syscall\n"
2388
2389 "1:\n"
2390 #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
2391 "addu $29, 24\n"
2392 #elif _MIPS_SIM == _MIPS_SIM_NABI32
2393 "add $29, 16\n"
2394 #else
2395 "daddu $29,16\n"
2396 #endif
2397 : "=&r" (__v0), "=r" (__r7)
2398 : "i"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
2399 "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
2400 "r"(__ptid), "r"(__r7), "r"(__ctid)
2401 : "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2402 "$24", "memory");
2403 }
2404 LSS_RETURN(int, __v0, __r7);
2405 }
2406 #elif defined (__PPC__)
2407 #undef LSS_LOADARGS_0
2408 #define LSS_LOADARGS_0(name, dummy...) \
2409 __sc_0 = __NR_##name
2410 #undef LSS_LOADARGS_1
2411 #define LSS_LOADARGS_1(name, arg1) \
2412 LSS_LOADARGS_0(name); \
2413 __sc_3 = (unsigned long) (arg1)
2414 #undef LSS_LOADARGS_2
2415 #define LSS_LOADARGS_2(name, arg1, arg2) \
2416 LSS_LOADARGS_1(name, arg1); \
2417 __sc_4 = (unsigned long) (arg2)
2418 #undef LSS_LOADARGS_3
2419 #define LSS_LOADARGS_3(name, arg1, arg2, arg3) \
2420 LSS_LOADARGS_2(name, arg1, arg2); \
2421 __sc_5 = (unsigned long) (arg3)
2422 #undef LSS_LOADARGS_4
2423 #define LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4) \
2424 LSS_LOADARGS_3(name, arg1, arg2, arg3); \
2425 __sc_6 = (unsigned long) (arg4)
2426 #undef LSS_LOADARGS_5
2427 #define LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5) \
2428 LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4); \
2429 __sc_7 = (unsigned long) (arg5)
2430 #undef LSS_LOADARGS_6
2431 #define LSS_LOADARGS_6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
2432 LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5); \
2433 __sc_8 = (unsigned long) (arg6)
2434 #undef LSS_ASMINPUT_0
2435 #define LSS_ASMINPUT_0 "0" (__sc_0)
2436 #undef LSS_ASMINPUT_1
2437 #define LSS_ASMINPUT_1 LSS_ASMINPUT_0, "1" (__sc_3)
2438 #undef LSS_ASMINPUT_2
2439 #define LSS_ASMINPUT_2 LSS_ASMINPUT_1, "2" (__sc_4)
2440 #undef LSS_ASMINPUT_3
2441 #define LSS_ASMINPUT_3 LSS_ASMINPUT_2, "3" (__sc_5)
2442 #undef LSS_ASMINPUT_4
2443 #define LSS_ASMINPUT_4 LSS_ASMINPUT_3, "4" (__sc_6)
2444 #undef LSS_ASMINPUT_5
2445 #define LSS_ASMINPUT_5 LSS_ASMINPUT_4, "5" (__sc_7)
2446 #undef LSS_ASMINPUT_6
2447 #define LSS_ASMINPUT_6 LSS_ASMINPUT_5, "6" (__sc_8)
2448 #undef LSS_BODY
2449 #define LSS_BODY(nr, type, name, args...) \
2450 long __sc_ret, __sc_err; \
2451 { \
2452 register unsigned long __sc_0 __asm__ ("r0"); \
2453 register unsigned long __sc_3 __asm__ ("r3"); \
2454 register unsigned long __sc_4 __asm__ ("r4"); \
2455 register unsigned long __sc_5 __asm__ ("r5"); \
2456 register unsigned long __sc_6 __asm__ ("r6"); \
2457 register unsigned long __sc_7 __asm__ ("r7"); \
2458 register unsigned long __sc_8 __asm__ ("r8"); \
2459 \
2460 LSS_LOADARGS_##nr(name, args); \
2461 __asm__ __volatile__ \
2462 ("sc\n\t" \
2463 "mfcr %0" \
2464 : "=&r" (__sc_0), \
2465 "=&r" (__sc_3), "=&r" (__sc_4), \
2466 "=&r" (__sc_5), "=&r" (__sc_6), \
2467 "=&r" (__sc_7), "=&r" (__sc_8) \
2468 : LSS_ASMINPUT_##nr \
2469 : "cr0", "ctr", "memory", \
2470 "r9", "r10", "r11", "r12"); \
2471 __sc_ret = __sc_3; \
2472 __sc_err = __sc_0; \
2473 } \
2474 LSS_RETURN(type, __sc_ret, __sc_err)
2475 #undef _syscall0
2476 #define _syscall0(type, name) \
2477 type LSS_NAME(name)(void) { \
2478 LSS_BODY(0, type, name); \
2479 }
2480 #undef _syscall1
2481 #define _syscall1(type, name, type1, arg1) \
2482 type LSS_NAME(name)(type1 arg1) { \
2483 LSS_BODY(1, type, name, arg1); \
2484 }
2485 #undef _syscall2
2486 #define _syscall2(type, name, type1, arg1, type2, arg2) \
2487 type LSS_NAME(name)(type1 arg1, type2 arg2) { \
2488 LSS_BODY(2, type, name, arg1, arg2); \
2489 }
2490 #undef _syscall3
2491 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
2492 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \
2493 LSS_BODY(3, type, name, arg1, arg2, arg3); \
2494 }
2495 #undef _syscall4
2496 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
2497 type4, arg4) \
2498 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
2499 LSS_BODY(4, type, name, arg1, arg2, arg3, arg4); \
2500 }
2501 #undef _syscall5
2502 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
2503 type4, arg4, type5, arg5) \
2504 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2505 type5 arg5) { \
2506 LSS_BODY(5, type, name, arg1, arg2, arg3, arg4, arg5); \
2507 }
2508 #undef _syscall6
2509 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
2510 type4, arg4, type5, arg5, type6, arg6) \
2511 type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2512 type5 arg5, type6 arg6) { \
2513 LSS_BODY(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6); \
2514 }
2515 /* clone function adapted from glibc 2.3.6 clone.S */
2516 /* TODO(csilvers): consider wrapping some args up in a struct, like we
2517 * do for i386's _syscall6, so we can compile successfully on gcc 2.95
2518 */
2519 LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
2520 int flags, void *arg, int *parent_tidptr,
2521 void *newtls, int *child_tidptr) {
2522 long __ret, __err;
2523 {
2524 register int (*__fn)(void *) __asm__ ("r8") = fn;
2525 register void *__cstack __asm__ ("r4") = child_stack;
2526 register int __flags __asm__ ("r3") = flags;
2527 register void * __arg __asm__ ("r9") = arg;
2528 register int * __ptidptr __asm__ ("r5") = parent_tidptr;
2529 register void * __newtls __asm__ ("r6") = newtls;
2530 register int * __ctidptr __asm__ ("r7") = child_tidptr;
2531 __asm__ __volatile__(
2532 /* check for fn == NULL
2533 * and child_stack == NULL
2534 */
2535 "cmpwi cr0, %6, 0\n\t"
2536 "cmpwi cr1, %7, 0\n\t"
2537 "cror cr0*4+eq, cr1*4+eq, cr0*4+eq\n\t"
2538 "beq- cr0, 1f\n\t"
2539
2540 /* set up stack frame for child */
2541 "clrrwi %7, %7, 4\n\t"
2542 "li 0, 0\n\t"
2543 "stwu 0, -16(%7)\n\t"
2544
2545 /* fn, arg, child_stack are saved across the syscall: r28-30 */
2546 "mr 28, %6\n\t"
2547 "mr 29, %7\n\t"
2548 "mr 27, %9\n\t"
2549
2550 /* syscall */
2551 "li 0, %4\n\t"
2552 /* flags already in r3
2553 * child_stack already in r4
2554 * ptidptr already in r5
2555 * newtls already in r6
2556 * ctidptr already in r7
2557 */
2558 "sc\n\t"
2559
2560 /* Test if syscall was successful */
2561 "cmpwi cr1, 3, 0\n\t"
2562 "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t"
2563 "bne- cr1, 1f\n\t"
2564
2565 /* Do the function call */
2566 "mtctr 28\n\t"
2567 "mr 3, 27\n\t"
2568 "bctrl\n\t"
2569
2570 /* Call _exit(r3) */
2571 "li 0, %5\n\t"
2572 "sc\n\t"
2573
2574 /* Return to parent */
2575 "1:\n"
2576 "mfcr %1\n\t"
2577 "mr %0, 3\n\t"
2578 : "=r" (__ret), "=r" (__err)
2579 : "0" (-1), "1" (EINVAL),
2580 "i" (__NR_clone), "i" (__NR_exit),
2581 "r" (__fn), "r" (__cstack), "r" (__flags),
2582 "r" (__arg), "r" (__ptidptr), "r" (__newtls),
2583 "r" (__ctidptr)
2584 : "cr0", "cr1", "memory", "ctr",
2585 "r0", "r29", "r27", "r28");
2586 }
2587 LSS_RETURN(int, __ret, __err);
2588 }
2589 #endif
2590 #define __NR__exit __NR_exit
2591 #define __NR__gettid __NR_gettid
2592 #define __NR__mremap __NR_mremap
2593 LSS_INLINE _syscall1(int, brk, void *, e)
2594 LSS_INLINE _syscall1(int, chdir, const char *,p)
2595 LSS_INLINE _syscall1(int, close, int, f)
2596 LSS_INLINE _syscall2(int, clock_getres, int, c,
2597 struct kernel_timespec*, t)
2598 LSS_INLINE _syscall2(int, clock_gettime, int, c,
2599 struct kernel_timespec*, t)
2600 LSS_INLINE _syscall1(int, dup, int, f)
2601 LSS_INLINE _syscall2(int, dup2, int, s,
2602 int, d)
2603 LSS_INLINE _syscall3(int, execve, const char*, f,
2604 const char*const*,a,const char*const*, e)
2605 LSS_INLINE _syscall1(int, _exit, int, e)
2606 LSS_INLINE _syscall1(int, exit_group, int, e)
2607 LSS_INLINE _syscall3(int, fcntl, int, f,
2608 int, c, long, a)
2609 LSS_INLINE _syscall0(pid_t, fork)
2610 LSS_INLINE _syscall2(int, fstat, int, f,
2611 struct kernel_stat*, b)
2612 LSS_INLINE _syscall2(int, fstatfs, int, f,
2613 struct kernel_statfs*, b)
2614 LSS_INLINE _syscall2(int, ftruncate, int, f,
2615 off_t, l)
2616 LSS_INLINE _syscall4(int, futex, int*, a,
2617 int, o, int, v,
2618 struct kernel_timespec*, t)
2619 LSS_INLINE _syscall3(int, getdents, int, f,
2620 struct kernel_dirent*, d, int, c)
2621 LSS_INLINE _syscall3(int, getdents64, int, f,
2622 struct kernel_dirent64*, d, int, c)
2623 LSS_INLINE _syscall0(gid_t, getegid)
2624 LSS_INLINE _syscall0(uid_t, geteuid)
2625 LSS_INLINE _syscall0(pid_t, getpgrp)
2626 LSS_INLINE _syscall0(pid_t, getpid)
2627 LSS_INLINE _syscall0(pid_t, getppid)
2628 LSS_INLINE _syscall2(int, getpriority, int, a,
2629 int, b)
2630 LSS_INLINE _syscall3(int, getresgid, gid_t *, r,
2631 gid_t *, e, gid_t *, s)
2632 LSS_INLINE _syscall3(int, getresuid, uid_t *, r,
2633 uid_t *, e, uid_t *, s)
2634#if !defined(__ARM_EABI__)
2635 LSS_INLINE _syscall2(int, getrlimit, int, r,
2636 struct kernel_rlimit*, l)
2637#endif
2638 LSS_INLINE _syscall1(pid_t, getsid, pid_t, p)
2639 LSS_INLINE _syscall0(pid_t, _gettid)
2640 LSS_INLINE _syscall2(pid_t, gettimeofday, struct kernel_timeval*, t,
2641 void*, tz)
2642 LSS_INLINE _syscall5(int, setxattr, const char *,p,
2643 const char *, n, const void *,v,
2644 size_t, s, int, f)
2645 LSS_INLINE _syscall5(int, lsetxattr, const char *,p,
2646 const char *, n, const void *,v,
2647 size_t, s, int, f)
2648 LSS_INLINE _syscall4(ssize_t, getxattr, const char *,p,
2649 const char *, n, void *, v, size_t, s)
2650 LSS_INLINE _syscall4(ssize_t, lgetxattr, const char *,p,
2651 const char *, n, void *, v, size_t, s)
2652 LSS_INLINE _syscall3(ssize_t, listxattr, const char *,p,
2653 char *, l, size_t, s)
2654 LSS_INLINE _syscall3(ssize_t, llistxattr, const char *,p,
2655 char *, l, size_t, s)
2656 LSS_INLINE _syscall3(int, ioctl, int, d,
2657 int, r, void *, a)
2658 LSS_INLINE _syscall2(int, ioprio_get, int, which,
2659 int, who)
2660 LSS_INLINE _syscall3(int, ioprio_set, int, which,
2661 int, who, int, ioprio)
2662 LSS_INLINE _syscall2(int, kill, pid_t, p,
2663 int, s)
2664 LSS_INLINE _syscall3(off_t, lseek, int, f,
2665 off_t, o, int, w)
2666 LSS_INLINE _syscall2(int, munmap, void*, s,
2667 size_t, l)
2668 LSS_INLINE _syscall6(long, move_pages, pid_t, p,
2669 unsigned long, n, void **,g, int *, d,
2670 int *, s, int, f)
2671 LSS_INLINE _syscall3(int, mprotect, const void *,a,
2672 size_t, l, int, p)
2673 LSS_INLINE _syscall5(void*, _mremap, void*, o,
2674 size_t, os, size_t, ns,
2675 unsigned long, f, void *, a)
2676 LSS_INLINE _syscall3(int, open, const char*, p,
2677 int, f, int, m)
2678 LSS_INLINE _syscall3(int, poll, struct kernel_pollfd*, u,
2679 unsigned int, n, int, t)
2680 LSS_INLINE _syscall2(int, prctl, int, o,
2681 long, a)
2682 LSS_INLINE _syscall4(long, ptrace, int, r,
2683 pid_t, p, void *, a, void *, d)
2684 #if defined(__NR_quotactl)
2685 // Defined on x86_64 / i386 only
2686 LSS_INLINE _syscall4(int, quotactl, int, cmd, const char *, special,
2687 int, id, caddr_t, addr)
2688 #endif
2689 LSS_INLINE _syscall3(ssize_t, read, int, f,
2690 void *, b, size_t, c)
2691 LSS_INLINE _syscall3(int, readlink, const char*, p,
2692 char*, b, size_t, s)
2693 LSS_INLINE _syscall4(int, rt_sigaction, int, s,
2694 const struct kernel_sigaction*, a,
2695 struct kernel_sigaction*, o, size_t, c)
2696 LSS_INLINE _syscall2(int, rt_sigpending, struct kernel_sigset_t *, s,
2697 size_t, c)
2698 LSS_INLINE _syscall4(int, rt_sigprocmask, int, h,
2699 const struct kernel_sigset_t*, s,
2700 struct kernel_sigset_t*, o, size_t, c)
2701 LSS_INLINE _syscall2(int, rt_sigsuspend,
2702 const struct kernel_sigset_t*, s, size_t, c)
2703 LSS_INLINE _syscall3(int, sched_getaffinity,pid_t, p,
2704 unsigned int, l, unsigned long *, m)
2705 LSS_INLINE _syscall3(int, sched_setaffinity,pid_t, p,
2706 unsigned int, l, unsigned long *, m)
2707 LSS_INLINE _syscall0(int, sched_yield)
2708 LSS_INLINE _syscall1(long, set_tid_address, int *, t)
2709 LSS_INLINE _syscall1(int, setfsgid, gid_t, g)
2710 LSS_INLINE _syscall1(int, setfsuid, uid_t, u)
2711 LSS_INLINE _syscall1(int, setuid, uid_t, u)
2712 LSS_INLINE _syscall1(int, setgid, gid_t, g)
2713 LSS_INLINE _syscall2(int, setpgid, pid_t, p,
2714 pid_t, g)
2715 LSS_INLINE _syscall3(int, setpriority, int, a,
2716 int, b, int, p)
2717 LSS_INLINE _syscall3(int, setresgid, gid_t, r,
2718 gid_t, e, gid_t, s)
2719 LSS_INLINE _syscall3(int, setresuid, uid_t, r,
2720 uid_t, e, uid_t, s)
2721 LSS_INLINE _syscall2(int, setrlimit, int, r,
2722 const struct kernel_rlimit*, l)
2723 LSS_INLINE _syscall0(pid_t, setsid)
2724 LSS_INLINE _syscall2(int, sigaltstack, const stack_t*, s,
2725 const stack_t*, o)
2726 #if defined(__NR_sigreturn)
2727 LSS_INLINE _syscall1(int, sigreturn, unsigned long, u);
2728 #endif
2729 LSS_INLINE _syscall2(int, stat, const char*, f,
2730 struct kernel_stat*, b)
2731 LSS_INLINE _syscall2(int, statfs, const char*, f,
2732 struct kernel_statfs*, b)
2733 LSS_INLINE _syscall3(int, tgkill, pid_t, p,
2734 pid_t, t, int, s)
2735 LSS_INLINE _syscall2(int, tkill, pid_t, p,
2736 int, s)
2737 LSS_INLINE _syscall1(int, unlink, const char*, f)
2738 LSS_INLINE _syscall3(ssize_t, write, int, f,
2739 const void *, b, size_t, c)
2740 LSS_INLINE _syscall3(ssize_t, writev, int, f,
2741 const struct kernel_iovec*, v, size_t, c)
2742 #if defined(__NR_getcpu)
2743 LSS_INLINE _syscall3(long, getcpu, unsigned *, cpu,
2744 unsigned *, node, void *, unused);
2745 #endif
2746 #if defined(__x86_64__) || \
2747 (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32)
2748 LSS_INLINE _syscall3(int, recvmsg, int, s,
2749 struct kernel_msghdr*, m, int, f)
2750 LSS_INLINE _syscall3(int, sendmsg, int, s,
2751 const struct kernel_msghdr*, m, int, f)
2752 LSS_INLINE _syscall6(int, sendto, int, s,
2753 const void*, m, size_t, l,
2754 int, f,
2755 const struct kernel_sockaddr*, a, int, t)
2756 LSS_INLINE _syscall2(int, shutdown, int, s,
2757 int, h)
2758 LSS_INLINE _syscall3(int, socket, int, d,
2759 int, t, int, p)
2760 LSS_INLINE _syscall4(int, socketpair, int, d,
2761 int, t, int, p, int*, s)
2762 #endif
2763 #if defined(__x86_64__)
2764 LSS_INLINE _syscall4(int, fallocate, int, fd, int, mode,
2765 loff_t, offset, loff_t, len)
2766
2767 LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
2768 gid_t *egid,
2769 gid_t *sgid) {
2770 return LSS_NAME(getresgid)(rgid, egid, sgid);
2771 }
2772
2773 LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
2774 uid_t *euid,
2775 uid_t *suid) {
2776 return LSS_NAME(getresuid)(ruid, euid, suid);
2777 }
2778
2779 LSS_INLINE _syscall6(void*, mmap, void*, s,
2780 size_t, l, int, p,
2781 int, f, int, d,
2782 __off64_t, o)
2783
2784 LSS_INLINE _syscall4(int, newfstatat, int, d,
2785 const char *, p,
2786 struct kernel_stat*, b, int, f)
2787
2788 LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
2789 return LSS_NAME(setfsgid)(gid);
2790 }
2791
2792 LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
2793 return LSS_NAME(setfsuid)(uid);
2794 }
2795
2796 LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
2797 return LSS_NAME(setresgid)(rgid, egid, sgid);
2798 }
2799
2800 LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
2801 return LSS_NAME(setresuid)(ruid, euid, suid);
2802 }
2803
2804 LSS_INLINE int LSS_NAME(sigaction)(int signum,
2805 const struct kernel_sigaction *act,
2806 struct kernel_sigaction *oldact) {
2807 /* On x86_64, the kernel requires us to always set our own
2808 * SA_RESTORER in order to be able to return from a signal handler.
2809 * This function must have a "magic" signature that the "gdb"
2810 * (and maybe the kernel?) can recognize.
2811 */
2812 if (act != NULL && !(act->sa_flags & SA_RESTORER)) {
2813 struct kernel_sigaction a = *act;
2814 a.sa_flags |= SA_RESTORER;
2815 a.sa_restorer = LSS_NAME(restore_rt)();
2816 return LSS_NAME(rt_sigaction)(signum, &a, oldact,
2817 (KERNEL_NSIG+7)/8);
2818 } else {
2819 return LSS_NAME(rt_sigaction)(signum, act, oldact,
2820 (KERNEL_NSIG+7)/8);
2821 }
2822 }
2823
2824 LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
2825 return LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
2826 }
2827
2828 LSS_INLINE int LSS_NAME(sigprocmask)(int how,
2829 const struct kernel_sigset_t *set,
2830 struct kernel_sigset_t *oldset) {
2831 return LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
2832 }
2833
2834 LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
2835 return LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
2836 }
2837 #endif
2838 #if defined(__x86_64__) || defined(__ARM_ARCH_3__) || \
2839 defined(__ARM_EABI__) || \
2840 (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32)
2841 LSS_INLINE _syscall4(pid_t, wait4, pid_t, p,
2842 int*, s, int, o,
2843 struct kernel_rusage*, r)
2844
2845 LSS_INLINE pid_t LSS_NAME(waitpid)(pid_t pid, int *status, int options){
2846 return LSS_NAME(wait4)(pid, status, options, 0);
2847 }
2848 #endif
2849 #if defined(__i386__) || defined(__x86_64__)
2850 LSS_INLINE _syscall4(int, openat, int, d, const char *, p, int, f, int, m)
2851 LSS_INLINE _syscall3(int, unlinkat, int, d, const char *, p, int, f)
2852 #endif
2853 #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
2854 #define __NR__getresgid32 __NR_getresgid32
2855 #define __NR__getresuid32 __NR_getresuid32
2856 #define __NR__setfsgid32 __NR_setfsgid32
2857 #define __NR__setfsuid32 __NR_setfsuid32
2858 #define __NR__setresgid32 __NR_setresgid32
2859 #define __NR__setresuid32 __NR_setresuid32
2860#if defined(__ARM_EABI__)
2861 LSS_INLINE _syscall2(int, ugetrlimit, int, r,
2862 struct kernel_rlimit*, l)
2863#endif
2864 LSS_INLINE _syscall3(int, _getresgid32, gid_t *, r,
2865 gid_t *, e, gid_t *, s)
2866 LSS_INLINE _syscall3(int, _getresuid32, uid_t *, r,
2867 uid_t *, e, uid_t *, s)
2868 LSS_INLINE _syscall1(int, _setfsgid32, gid_t, f)
2869 LSS_INLINE _syscall1(int, _setfsuid32, uid_t, f)
2870 LSS_INLINE _syscall3(int, _setresgid32, gid_t, r,
2871 gid_t, e, gid_t, s)
2872 LSS_INLINE _syscall3(int, _setresuid32, uid_t, r,
2873 uid_t, e, uid_t, s)
2874
2875 LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
2876 gid_t *egid,
2877 gid_t *sgid) {
2878 int rc;
2879 if ((rc = LSS_NAME(_getresgid32)(rgid, egid, sgid)) < 0 &&
2880 LSS_ERRNO == ENOSYS) {
2881 if ((rgid == NULL) || (egid == NULL) || (sgid == NULL)) {
2882 return EFAULT;
2883 }
2884 // Clear the high bits first, since getresgid only sets 16 bits
2885 *rgid = *egid = *sgid = 0;
2886 rc = LSS_NAME(getresgid)(rgid, egid, sgid);
2887 }
2888 return rc;
2889 }
2890
2891 LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid,
2892 uid_t *euid,
2893 uid_t *suid) {
2894 int rc;
2895 if ((rc = LSS_NAME(_getresuid32)(ruid, euid, suid)) < 0 &&
2896 LSS_ERRNO == ENOSYS) {
2897 if ((ruid == NULL) || (euid == NULL) || (suid == NULL)) {
2898 return EFAULT;
2899 }
2900 // Clear the high bits first, since getresuid only sets 16 bits
2901 *ruid = *euid = *suid = 0;
2902 rc = LSS_NAME(getresuid)(ruid, euid, suid);
2903 }
2904 return rc;
2905 }
2906
2907 LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) {
2908 int rc;
2909 if ((rc = LSS_NAME(_setfsgid32)(gid)) < 0 &&
2910 LSS_ERRNO == ENOSYS) {
2911 if ((unsigned int)gid & ~0xFFFFu) {
2912 rc = EINVAL;
2913 } else {
2914 rc = LSS_NAME(setfsgid)(gid);
2915 }
2916 }
2917 return rc;
2918 }
2919
2920 LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) {
2921 int rc;
2922 if ((rc = LSS_NAME(_setfsuid32)(uid)) < 0 &&
2923 LSS_ERRNO == ENOSYS) {
2924 if ((unsigned int)uid & ~0xFFFFu) {
2925 rc = EINVAL;
2926 } else {
2927 rc = LSS_NAME(setfsuid)(uid);
2928 }
2929 }
2930 return rc;
2931 }
2932
2933 LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) {
2934 int rc;
2935 if ((rc = LSS_NAME(_setresgid32)(rgid, egid, sgid)) < 0 &&
2936 LSS_ERRNO == ENOSYS) {
2937 if ((unsigned int)rgid & ~0xFFFFu ||
2938 (unsigned int)egid & ~0xFFFFu ||
2939 (unsigned int)sgid & ~0xFFFFu) {
2940 rc = EINVAL;
2941 } else {
2942 rc = LSS_NAME(setresgid)(rgid, egid, sgid);
2943 }
2944 }
2945 return rc;
2946 }
2947
2948 LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) {
2949 int rc;
2950 if ((rc = LSS_NAME(_setresuid32)(ruid, euid, suid)) < 0 &&
2951 LSS_ERRNO == ENOSYS) {
2952 if ((unsigned int)ruid & ~0xFFFFu ||
2953 (unsigned int)euid & ~0xFFFFu ||
2954 (unsigned int)suid & ~0xFFFFu) {
2955 rc = EINVAL;
2956 } else {
2957 rc = LSS_NAME(setresuid)(ruid, euid, suid);
2958 }
2959 }
2960 return rc;
2961 }
2962 #endif
2963 LSS_INLINE int LSS_NAME(sigemptyset)(struct kernel_sigset_t *set) {
2964 memset(&set->sig, 0, sizeof(set->sig));
2965 return 0;
2966 }
2967
2968 LSS_INLINE int LSS_NAME(sigfillset)(struct kernel_sigset_t *set) {
2969 memset(&set->sig, -1, sizeof(set->sig));
2970 return 0;
2971 }
2972
2973 LSS_INLINE int LSS_NAME(sigaddset)(struct kernel_sigset_t *set,
2974 int signum) {
2975 if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
2976 LSS_ERRNO = EINVAL;
2977 return -1;
2978 } else {
2979 set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
2980 |= 1UL << ((signum - 1) % (8*sizeof(set->sig[0])));
2981 return 0;
2982 }
2983 }
2984
2985 LSS_INLINE int LSS_NAME(sigdelset)(struct kernel_sigset_t *set,
2986 int signum) {
2987 if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
2988 LSS_ERRNO = EINVAL;
2989 return -1;
2990 } else {
2991 set->sig[(signum - 1)/(8*sizeof(set->sig[0]))]
2992 &= ~(1UL << ((signum - 1) % (8*sizeof(set->sig[0]))));
2993 return 0;
2994 }
2995 }
2996
2997 LSS_INLINE int LSS_NAME(sigismember)(struct kernel_sigset_t *set,
2998 int signum) {
2999 if (signum < 1 || signum > (int)(8*sizeof(set->sig))) {
3000 LSS_ERRNO = EINVAL;
3001 return -1;
3002 } else {
3003 return !!(set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] &
3004 (1UL << ((signum - 1) % (8*sizeof(set->sig[0])))));
3005 }
3006 }
3007 #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
3008 defined(__ARM_EABI__) || \
3009 (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || defined(__PPC__)
3010 #define __NR__sigaction __NR_sigaction
3011 #define __NR__sigpending __NR_sigpending
3012 #define __NR__sigprocmask __NR_sigprocmask
3013 #define __NR__sigsuspend __NR_sigsuspend
3014 #define __NR__socketcall __NR_socketcall
3015 LSS_INLINE _syscall2(int, fstat64, int, f,
3016 struct kernel_stat64 *, b)
3017 LSS_INLINE _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
3018 loff_t *, res, uint, wh)
3019#if !defined(__ARM_EABI__)
3020 LSS_INLINE _syscall1(void*, mmap, void*, a)
3021#endif
3022 LSS_INLINE _syscall6(void*, mmap2, void*, s,
3023 size_t, l, int, p,
3024 int, f, int, d,
3025 __off64_t, o)
3026 LSS_INLINE _syscall3(int, _sigaction, int, s,
3027 const struct kernel_old_sigaction*, a,
3028 struct kernel_old_sigaction*, o)
3029 LSS_INLINE _syscall1(int, _sigpending, unsigned long*, s)
3030 LSS_INLINE _syscall3(int, _sigprocmask, int, h,
3031 const unsigned long*, s,
3032 unsigned long*, o)
3033 #ifdef __PPC__
3034 LSS_INLINE _syscall1(int, _sigsuspend, unsigned long, s)
3035 #else
3036 LSS_INLINE _syscall3(int, _sigsuspend, const void*, a,
3037 int, b,
3038 unsigned long, s)
3039 #endif
3040 LSS_INLINE _syscall2(int, stat64, const char *, p,
3041 struct kernel_stat64 *, b)
3042
3043 LSS_INLINE int LSS_NAME(sigaction)(int signum,
3044 const struct kernel_sigaction *act,
3045 struct kernel_sigaction *oldact) {
3046 int old_errno = LSS_ERRNO;
3047 int rc;
3048 struct kernel_sigaction a;
3049 if (act != NULL) {
3050 a = *act;
3051 #ifdef __i386__
3052 /* On i386, the kernel requires us to always set our own
3053 * SA_RESTORER when using realtime signals. Otherwise, it does not
3054 * know how to return from a signal handler. This function must have
3055 * a "magic" signature that the "gdb" (and maybe the kernel?) can
3056 * recognize.
3057 * Apparently, a SA_RESTORER is implicitly set by the kernel, when
3058 * using non-realtime signals.
3059 *
3060 * TODO: Test whether ARM needs a restorer
3061 */
3062 if (!(a.sa_flags & SA_RESTORER)) {
3063 a.sa_flags |= SA_RESTORER;
3064 a.sa_restorer = (a.sa_flags & SA_SIGINFO)
3065 ? LSS_NAME(restore_rt)() : LSS_NAME(restore)();
3066 }
3067 #endif
3068 }
3069 rc = LSS_NAME(rt_sigaction)(signum, act ? &a : act, oldact,
3070 (KERNEL_NSIG+7)/8);
3071 if (rc < 0 && LSS_ERRNO == ENOSYS) {
3072 struct kernel_old_sigaction oa, ooa, *ptr_a = &oa, *ptr_oa = &ooa;
3073 if (!act) {
3074 ptr_a = NULL;
3075 } else {
3076 oa.sa_handler_ = act->sa_handler_;
3077 memcpy(&oa.sa_mask, &act->sa_mask, sizeof(oa.sa_mask));
3078 #ifndef __mips__
3079 oa.sa_restorer = act->sa_restorer;
3080 #endif
3081 oa.sa_flags = act->sa_flags;
3082 }
3083 if (!oldact) {
3084 ptr_oa = NULL;
3085 }
3086 LSS_ERRNO = old_errno;
3087 rc = LSS_NAME(_sigaction)(signum, ptr_a, ptr_oa);
3088 if (rc == 0 && oldact) {
3089 if (act) {
3090 memcpy(oldact, act, sizeof(*act));
3091 } else {
3092 memset(oldact, 0, sizeof(*oldact));
3093 }
3094 oldact->sa_handler_ = ptr_oa->sa_handler_;
3095 oldact->sa_flags = ptr_oa->sa_flags;
3096 memcpy(&oldact->sa_mask, &ptr_oa->sa_mask, sizeof(ptr_oa->sa_mask));
3097 #ifndef __mips__
3098 oldact->sa_restorer = ptr_oa->sa_restorer;
3099 #endif
3100 }
3101 }
3102 return rc;
3103 }
3104
3105 LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) {
3106 int old_errno = LSS_ERRNO;
3107 int rc = LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8);
3108 if (rc < 0 && LSS_ERRNO == ENOSYS) {
3109 LSS_ERRNO = old_errno;
3110 LSS_NAME(sigemptyset)(set);
3111 rc = LSS_NAME(_sigpending)(&set->sig[0]);
3112 }
3113 return rc;
3114 }
3115
3116 LSS_INLINE int LSS_NAME(sigprocmask)(int how,
3117 const struct kernel_sigset_t *set,
3118 struct kernel_sigset_t *oldset) {
3119 int olderrno = LSS_ERRNO;
3120 int rc = LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8);
3121 if (rc < 0 && LSS_ERRNO == ENOSYS) {
3122 LSS_ERRNO = olderrno;
3123 if (oldset) {
3124 LSS_NAME(sigemptyset)(oldset);
3125 }
3126 rc = LSS_NAME(_sigprocmask)(how,
3127 set ? &set->sig[0] : NULL,
3128 oldset ? &oldset->sig[0] : NULL);
3129 }
3130 return rc;
3131 }
3132
3133 LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) {
3134 int olderrno = LSS_ERRNO;
3135 int rc = LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8);
3136 if (rc < 0 && LSS_ERRNO == ENOSYS) {
3137 LSS_ERRNO = olderrno;
3138 rc = LSS_NAME(_sigsuspend)(
3139 #ifndef __PPC__
3140 set, 0,
3141 #endif
3142 set->sig[0]);
3143 }
3144 return rc;
3145 }
3146 #endif
3147 #if defined(__PPC__)
3148 #undef LSS_SC_LOADARGS_0
3149 #define LSS_SC_LOADARGS_0(dummy...)
3150 #undef LSS_SC_LOADARGS_1
3151 #define LSS_SC_LOADARGS_1(arg1) \
3152 __sc_4 = (unsigned long) (arg1)
3153 #undef LSS_SC_LOADARGS_2
3154 #define LSS_SC_LOADARGS_2(arg1, arg2) \
3155 LSS_SC_LOADARGS_1(arg1); \
3156 __sc_5 = (unsigned long) (arg2)
3157 #undef LSS_SC_LOADARGS_3
3158 #define LSS_SC_LOADARGS_3(arg1, arg2, arg3) \
3159 LSS_SC_LOADARGS_2(arg1, arg2); \
3160 __sc_6 = (unsigned long) (arg3)
3161 #undef LSS_SC_LOADARGS_4
3162 #define LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4) \
3163 LSS_SC_LOADARGS_3(arg1, arg2, arg3); \
3164 __sc_7 = (unsigned long) (arg4)
3165 #undef LSS_SC_LOADARGS_5
3166 #define LSS_SC_LOADARGS_5(arg1, arg2, arg3, arg4, arg5) \
3167 LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4); \
3168 __sc_8 = (unsigned long) (arg5)
3169 #undef LSS_SC_BODY
3170 #define LSS_SC_BODY(nr, type, opt, args...) \
3171 long __sc_ret, __sc_err; \
3172 { \
3173 register unsigned long __sc_0 __asm__ ("r0") = __NR_socketcall; \
3174 register unsigned long __sc_3 __asm__ ("r3") = opt; \
3175 register unsigned long __sc_4 __asm__ ("r4"); \
3176 register unsigned long __sc_5 __asm__ ("r5"); \
3177 register unsigned long __sc_6 __asm__ ("r6"); \
3178 register unsigned long __sc_7 __asm__ ("r7"); \
3179 register unsigned long __sc_8 __asm__ ("r8"); \
3180 LSS_SC_LOADARGS_##nr(args); \
3181 __asm__ __volatile__ \
3182 ("stwu 1, -48(1)\n\t" \
3183 "stw 4, 20(1)\n\t" \
3184 "stw 5, 24(1)\n\t" \
3185 "stw 6, 28(1)\n\t" \
3186 "stw 7, 32(1)\n\t" \
3187 "stw 8, 36(1)\n\t" \
3188 "addi 4, 1, 20\n\t" \
3189 "sc\n\t" \
3190 "mfcr %0" \
3191 : "=&r" (__sc_0), \
3192 "=&r" (__sc_3), "=&r" (__sc_4), \
3193 "=&r" (__sc_5), "=&r" (__sc_6), \
3194 "=&r" (__sc_7), "=&r" (__sc_8) \
3195 : LSS_ASMINPUT_##nr \
3196 : "cr0", "ctr", "memory"); \
3197 __sc_ret = __sc_3; \
3198 __sc_err = __sc_0; \
3199 } \
3200 LSS_RETURN(type, __sc_ret, __sc_err)
3201
3202 LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
3203 int flags){
3204 LSS_SC_BODY(3, ssize_t, 17, s, msg, flags);
3205 }
3206
3207 LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
3208 const struct kernel_msghdr *msg,
3209 int flags) {
3210 LSS_SC_BODY(3, ssize_t, 16, s, msg, flags);
3211 }
3212
3213 // TODO(csilvers): why is this ifdef'ed out?
3214#if 0
3215 LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
3216 int flags,
3217 const struct kernel_sockaddr *to,
3218 unsigned int tolen) {
3219 LSS_BODY(6, ssize_t, 11, s, buf, len, flags, to, tolen);
3220 }
3221#endif
3222
3223 LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
3224 LSS_SC_BODY(2, int, 13, s, how);
3225 }
3226
3227 LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
3228 LSS_SC_BODY(3, int, 1, domain, type, protocol);
3229 }
3230
3231 LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
3232 int sv[2]) {
3233 LSS_SC_BODY(4, int, 8, d, type, protocol, sv);
3234 }
3235 #endif
3236 #if defined(__ARM_EABI__)
3237 LSS_INLINE _syscall3(ssize_t, recvmsg, int, s, struct kernel_msghdr*, msg,
3238 int, flags)
3239 LSS_INLINE _syscall3(ssize_t, sendmsg, int, s, const struct kernel_msghdr*,
3240 msg, int, flags)
3241 LSS_INLINE _syscall6(ssize_t, sendto, int, s, const void*, buf, size_t, len,
3242 int, falgs, const struct kernel_sockaddr*, to,
3243 unsigned int, tolen)
3244 LSS_INLINE _syscall2(int, shutdown, int, s, int, how)
3245 LSS_INLINE _syscall3(int, socket, int, domain, int, type, int, protocol)
3246 LSS_INLINE _syscall4(int, socketpair, int, d, int, type, int, protocol,
3247 int*, sv)
3248 #endif
3249 #if defined(__ARM_EABI__)
3250 LSS_INLINE _syscall3(ssize_t, recvmsg, int, s, struct kernel_msghdr*, msg,
3251 int, flags)
3252 LSS_INLINE _syscall3(ssize_t, sendmsg, int, s, const struct kernel_msghdr*,
3253 msg, int, flags)
3254 LSS_INLINE _syscall6(ssize_t, sendto, int, s, const void*, buf, size_t,len,
3255 int, flags, const struct kernel_sockaddr*, to,
3256 unsigned int, tolen)
3257 LSS_INLINE _syscall2(int, shutdown, int, s, int, how)
3258 LSS_INLINE _syscall3(int, socket, int, domain, int, type, int, protocol)
3259 LSS_INLINE _syscall4(int, socketpair, int, d, int, type, int, protocol,
3260 int*, sv)
3261 #endif
3262 #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
3263 (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
3264 #define __NR__socketcall __NR_socketcall
3265 LSS_INLINE _syscall2(int, _socketcall, int, c,
3266 va_list, a)
3267 LSS_INLINE int LSS_NAME(socketcall)(int op, ...) {
3268 int rc;
3269 va_list ap;
3270 va_start(ap, op);
3271 rc = LSS_NAME(_socketcall)(op, ap);
3272 va_end(ap);
3273 return rc;
3274 }
3275
3276 LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg,
3277 int flags){
3278 return (ssize_t)LSS_NAME(socketcall)(17, s, msg, flags);
3279 }
3280
3281 LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s,
3282 const struct kernel_msghdr *msg,
3283 int flags) {
3284 return (ssize_t)LSS_NAME(socketcall)(16, s, msg, flags);
3285 }
3286
3287 LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len,
3288 int flags,
3289 const struct kernel_sockaddr *to,
3290 unsigned int tolen) {
3291 return (ssize_t)LSS_NAME(socketcall)(11, s, buf, len, flags, to, tolen);
3292 }
3293
3294 LSS_INLINE int LSS_NAME(shutdown)(int s, int how) {
3295 return LSS_NAME(socketcall)(13, s, how);
3296 }
3297
3298 LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) {
3299 return LSS_NAME(socketcall)(1, domain, type, protocol);
3300 }
3301
3302 LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol,
3303 int sv[2]) {
3304 return LSS_NAME(socketcall)(8, d, type, protocol, sv);
3305 }
3306 #endif
3307 #if defined(__i386__) || defined(__PPC__)
3308 LSS_INLINE _syscall4(int, fstatat64, int, d,
3309 const char *, p,
3310 struct kernel_stat64 *, b, int, f)
3311 #endif
3312 #if defined(__i386__) || defined(__PPC__) || \
3313 (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32)
3314 LSS_INLINE _syscall3(pid_t, waitpid, pid_t, p,
3315 int*, s, int, o)
3316 #endif
3317 #if defined(__mips__)
3318 /* sys_pipe() on MIPS has non-standard calling conventions, as it returns
3319 * both file handles through CPU registers.
3320 */
3321 LSS_INLINE int LSS_NAME(pipe)(int *p) {
3322 register unsigned long __v0 __asm__("$2") = __NR_pipe;
3323 register unsigned long __v1 __asm__("$3");
3324 register unsigned long __r7 __asm__("$7");
3325 __asm__ __volatile__ ("syscall\n"
3326 : "=&r"(__v0), "=&r"(__v1), "+r" (__r7)
3327 : "0"(__v0)
3328 : "$8", "$9", "$10", "$11", "$12",
3329 "$13", "$14", "$15", "$24", "memory");
3330 if (__r7) {
3331 LSS_ERRNO = __v0;
3332 return -1;
3333 } else {
3334 p[0] = __v0;
3335 p[1] = __v1;
3336 return 0;
3337 }
3338 }
3339 #else
3340 LSS_INLINE _syscall1(int, pipe, int *, p)
3341 #endif
3342 /* TODO(csilvers): see if ppc can/should support this as well */
3343 #if defined(__i386__) || defined(__ARM_ARCH_3__) || \
3344 defined(__ARM_EABI__) || \
3345 (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64)
3346 #define __NR__statfs64 __NR_statfs64
3347 #define __NR__fstatfs64 __NR_fstatfs64
3348 LSS_INLINE _syscall3(int, _statfs64, const char*, p,
3349 size_t, s,struct kernel_statfs64*, b)
3350 LSS_INLINE _syscall3(int, _fstatfs64, int, f,
3351 size_t, s,struct kernel_statfs64*, b)
3352 LSS_INLINE int LSS_NAME(statfs64)(const char *p,
3353 struct kernel_statfs64 *b) {
3354 return LSS_NAME(_statfs64)(p, sizeof(*b), b);
3355 }
3356 LSS_INLINE int LSS_NAME(fstatfs64)(int f,struct kernel_statfs64 *b) {
3357 return LSS_NAME(_fstatfs64)(f, sizeof(*b), b);
3358 }
3359 #endif
3360
3361 LSS_INLINE int LSS_NAME(execv)(const char *path, const char *const argv[]) {
3362 extern char **environ;
3363 return LSS_NAME(execve)(path, argv, (const char *const *)environ);
3364 }
3365
3366 LSS_INLINE pid_t LSS_NAME(gettid)() {
3367 pid_t tid = LSS_NAME(_gettid)();
3368 if (tid != -1) {
3369 return tid;
3370 }
3371 return LSS_NAME(getpid)();
3372 }
3373
3374 LSS_INLINE void *LSS_NAME(mremap)(void *old_address, size_t old_size,
3375 size_t new_size, int flags, ...) {
3376 va_list ap;
3377 void *new_address, *rc;
3378 va_start(ap, flags);
3379 new_address = va_arg(ap, void *);
3380 rc = LSS_NAME(_mremap)(old_address, old_size, new_size,
3381 flags, new_address);
3382 va_end(ap);
3383 return rc;
3384 }
3385
3386 LSS_INLINE int LSS_NAME(ptrace_detach)(pid_t pid) {
3387 /* PTRACE_DETACH can sometimes forget to wake up the tracee and it
3388 * then sends job control signals to the real parent, rather than to
3389 * the tracer. We reduce the risk of this happening by starting a
3390 * whole new time slice, and then quickly sending a SIGCONT signal
3391 * right after detaching from the tracee.
3392 *
3393 * We use tkill to ensure that we only issue a wakeup for the thread being
3394 * detached. Large multi threaded apps can take a long time in the kernel
3395 * processing SIGCONT.
3396 */
3397 int rc, err;
3398 LSS_NAME(sched_yield)();
3399 rc = LSS_NAME(ptrace)(PTRACE_DETACH, pid, (void *)0, (void *)0);
3400 err = LSS_ERRNO;
3401 LSS_NAME(tkill)(pid, SIGCONT);
3402 /* Old systems don't have tkill */
3403 if (LSS_ERRNO == ENOSYS)
3404 LSS_NAME(kill)(pid, SIGCONT);
3405 LSS_ERRNO = err;
3406 return rc;
3407 }
3408
3409 LSS_INLINE int LSS_NAME(raise)(int sig) {
3410 return LSS_NAME(kill)(LSS_NAME(getpid)(), sig);
3411 }
3412
3413 LSS_INLINE int LSS_NAME(setpgrp)() {
3414 return LSS_NAME(setpgid)(0, 0);
3415 }
3416
3417 LSS_INLINE int LSS_NAME(sysconf)(int name) {
3418 extern int __getpagesize(void);
3419 switch (name) {
3420 case _SC_OPEN_MAX: {
3421 struct kernel_rlimit limit;
3422#if defined(__ARM_EABI__)
3423 return LSS_NAME(ugetrlimit)(RLIMIT_NOFILE, &limit) < 0
3424 ? 8192 : limit.rlim_cur;
3425#else
3426 return LSS_NAME(getrlimit)(RLIMIT_NOFILE, &limit) < 0
3427 ? 8192 : limit.rlim_cur;
3428#endif
3429 }
3430 case _SC_PAGESIZE:
3431 return __getpagesize();
3432 default:
3433 LSS_ERRNO = ENOSYS;
3434 return -1;
3435 }
3436 }
3437 #if defined(__x86_64__) || \
3438 (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64)
3439 LSS_INLINE _syscall4(ssize_t, pread64, int, f,
3440 void *, b, size_t, c,
3441 loff_t, o)
3442 LSS_INLINE _syscall4(ssize_t, pwrite64, int, f,
3443 const void *, b, size_t, c,
3444 loff_t, o)
3445 LSS_INLINE _syscall3(int, readahead, int, f,
3446 loff_t, o, unsigned, c)
3447 #else
3448 #define __NR__pread64 __NR_pread64
3449 #define __NR__pwrite64 __NR_pwrite64
3450 #define __NR__readahead __NR_readahead
3451 LSS_INLINE _syscall5(ssize_t, _pread64, int, f,
3452 void *, b, size_t, c, unsigned, o1,
3453 unsigned, o2)
3454 LSS_INLINE _syscall5(ssize_t, _pwrite64, int, f,
3455 const void *, b, size_t, c, unsigned, o1,
3456 long, o2)
3457 LSS_INLINE _syscall4(int, _readahead, int, f,
3458 unsigned, o1, unsigned, o2, size_t, c)
3459 /* We force 64bit-wide parameters onto the stack, then access each
3460 * 32-bit component individually. This guarantees that we build the
3461 * correct parameters independent of the native byte-order of the
3462 * underlying architecture.
3463 */
3464 LSS_INLINE ssize_t LSS_NAME(pread64)(int fd, void *buf, size_t count,
3465 loff_t off) {
3466 union { loff_t off; unsigned arg[2]; } o = { off };
3467 return LSS_NAME(_pread64)(fd, buf, count, o.arg[0], o.arg[1]);
3468 }
3469 LSS_INLINE ssize_t LSS_NAME(pwrite64)(int fd, const void *buf,
3470 size_t count, loff_t off) {
3471 union { loff_t off; unsigned arg[2]; } o = { off };
3472 return LSS_NAME(_pwrite64)(fd, buf, count, o.arg[0], o.arg[1]);
3473 }
3474 LSS_INLINE int LSS_NAME(readahead)(int fd, loff_t off, int len) {
3475 union { loff_t off; unsigned arg[2]; } o = { off };
3476 return LSS_NAME(_readahead)(fd, o.arg[0], o.arg[1], len);
3477 }
3478 #endif
3479#endif
3480
3481#if defined(__cplusplus) && !defined(SYS_CPLUSPLUS)
3482}
3483#endif
3484
3485#endif
3486#endif