| 1 | /* Copyright (C) 2015-2020 Free Software Foundation, Inc. | 
|---|
| 2 | This file is part of the GNU C Library. | 
|---|
| 3 |  | 
|---|
| 4 | The GNU C Library is free software; you can redistribute it and/or | 
|---|
| 5 | modify it under the terms of the GNU Lesser General Public | 
|---|
| 6 | License as published by the Free Software Foundation; either | 
|---|
| 7 | version 2.1 of the License, or (at your option) any later version. | 
|---|
| 8 |  | 
|---|
| 9 | The GNU C Library is distributed in the hope that it will be useful, | 
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 12 | Lesser General Public License for more details. | 
|---|
| 13 |  | 
|---|
| 14 | You should have received a copy of the GNU Lesser General Public | 
|---|
| 15 | License along with the GNU C Library; if not, see | 
|---|
| 16 | <https://www.gnu.org/licenses/>.  */ | 
|---|
| 17 |  | 
|---|
| 18 | #ifndef _SYSDEP_LINUX_H | 
|---|
| 19 | #define _SYSDEP_LINUX_H | 
|---|
| 20 |  | 
|---|
| 21 | #include <bits/wordsize.h> | 
|---|
| 22 | #include <kernel-features.h> | 
|---|
| 23 | #include <errno.h> | 
|---|
| 24 |  | 
|---|
| 25 | #undef INTERNAL_SYSCALL_ERROR_P | 
|---|
| 26 | #define INTERNAL_SYSCALL_ERROR_P(val) \ | 
|---|
| 27 | ((unsigned long int) (val) > -4096UL) | 
|---|
| 28 |  | 
|---|
| 29 | #ifndef SYSCALL_ERROR_LABEL | 
|---|
| 30 | # define SYSCALL_ERROR_LABEL(sc_err)					\ | 
|---|
| 31 | ({									\ | 
|---|
| 32 | __set_errno (sc_err);						\ | 
|---|
| 33 | -1L;								\ | 
|---|
| 34 | }) | 
|---|
| 35 | #endif | 
|---|
| 36 |  | 
|---|
| 37 | /* Define a macro which expands into the inline wrapper code for a system | 
|---|
| 38 | call.  It sets the errno and returns -1 on a failure, or the syscall | 
|---|
| 39 | return value otherwise.  */ | 
|---|
| 40 | #undef INLINE_SYSCALL | 
|---|
| 41 | #define INLINE_SYSCALL(name, nr, args...)				\ | 
|---|
| 42 | ({									\ | 
|---|
| 43 | long int sc_ret = INTERNAL_SYSCALL (name, nr, args);		\ | 
|---|
| 44 | __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (sc_ret))		\ | 
|---|
| 45 | ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (sc_ret))		\ | 
|---|
| 46 | : sc_ret;								\ | 
|---|
| 47 | }) | 
|---|
| 48 |  | 
|---|
| 49 | #undef INTERNAL_SYSCALL_ERRNO | 
|---|
| 50 | #define INTERNAL_SYSCALL_ERRNO(val)     (-(val)) | 
|---|
| 51 |  | 
|---|
| 52 | /* Set error number and return -1.  A target may choose to return the | 
|---|
| 53 | internal function, __syscall_error, which sets errno and returns -1. | 
|---|
| 54 | We use -1l, instead of -1, so that it can be casted to (void *).  */ | 
|---|
| 55 | #define INLINE_SYSCALL_ERROR_RETURN_VALUE(err)  \ | 
|---|
| 56 | ({						\ | 
|---|
| 57 | __set_errno (err);				\ | 
|---|
| 58 | -1l;					\ | 
|---|
| 59 | }) | 
|---|
| 60 |  | 
|---|
| 61 | /* Provide a dummy argument that can be used to force register | 
|---|
| 62 | alignment for register pairs if required by the syscall ABI.  */ | 
|---|
| 63 | #ifdef __ASSUME_ALIGNED_REGISTER_PAIRS | 
|---|
| 64 | #define __ALIGNMENT_ARG 0, | 
|---|
| 65 | #define __ALIGNMENT_COUNT(a,b) b | 
|---|
| 66 | #else | 
|---|
| 67 | #define __ALIGNMENT_ARG | 
|---|
| 68 | #define __ALIGNMENT_COUNT(a,b) a | 
|---|
| 69 | #endif | 
|---|
| 70 |  | 
|---|
| 71 | /* Provide a common macro to pass 64-bit value on syscalls.  */ | 
|---|
| 72 | #if __WORDSIZE == 64 || defined __ASSUME_WORDSIZE64_ILP32 | 
|---|
| 73 | # define SYSCALL_LL(val)   (val) | 
|---|
| 74 | # define SYSCALL_LL64(val) (val) | 
|---|
| 75 | #else | 
|---|
| 76 | #define SYSCALL_LL(val)   \ | 
|---|
| 77 | __LONG_LONG_PAIR ((val) >> 31, (val)) | 
|---|
| 78 | #define SYSCALL_LL64(val) \ | 
|---|
| 79 | __LONG_LONG_PAIR ((long) ((val) >> 32), (long) ((val) & 0xffffffff)) | 
|---|
| 80 | #endif | 
|---|
| 81 |  | 
|---|
| 82 | /* Provide a common macro to pass 64-bit value on pread and pwrite | 
|---|
| 83 | syscalls.  */ | 
|---|
| 84 | #ifdef __ASSUME_PRW_DUMMY_ARG | 
|---|
| 85 | # define SYSCALL_LL_PRW(val)   0, SYSCALL_LL (val) | 
|---|
| 86 | # define SYSCALL_LL64_PRW(val) 0, SYSCALL_LL64 (val) | 
|---|
| 87 | #else | 
|---|
| 88 | # define SYSCALL_LL_PRW(val)   __ALIGNMENT_ARG SYSCALL_LL (val) | 
|---|
| 89 | # define SYSCALL_LL64_PRW(val) __ALIGNMENT_ARG SYSCALL_LL64 (val) | 
|---|
| 90 | #endif | 
|---|
| 91 |  | 
|---|
| 92 | /* Provide a macro to pass the off{64}_t argument on p{readv,writev}{64}.  */ | 
|---|
| 93 | #define LO_HI_LONG(val) \ | 
|---|
| 94 | (long) (val), \ | 
|---|
| 95 | (long) (((uint64_t) (val)) >> 32) | 
|---|
| 96 |  | 
|---|
| 97 | /* Exports the __send symbol on send.c linux implementation (some ABI have | 
|---|
| 98 | it missing due the usage of a old generic version without it).  */ | 
|---|
| 99 | #define HAVE_INTERNAL_SEND_SYMBOL	1 | 
|---|
| 100 |  | 
|---|
| 101 | #endif /* _SYSDEP_LINUX_H  */ | 
|---|
| 102 |  | 
|---|