PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

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