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