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