Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/common/syscall.h |
| 3 | * Redefinition of some missing OS-specific system calls. |
| 4 | * |
| 5 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | #ifndef _COMMON_SYSCALL_H |
| 25 | #define _COMMON_SYSCALL_H |
| 26 | |
| 27 | #ifdef __linux__ |
| 28 | |
| 29 | #include <errno.h> |
| 30 | #include <unistd.h> |
| 31 | #include <sys/syscall.h> |
| 32 | |
| 33 | /* On Linux, _syscall macros were removed after 2.6.18, but we still prefer |
| 34 | * them because syscall() is buggy on old libcs. If _syscall is not defined, |
| 35 | * we're on a recent kernel with a recent libc and we should be safe, so we |
| 36 | * emulate is using syscall(). |
| 37 | */ |
| 38 | #ifndef _syscall1 |
| 39 | #define _syscall1(tr, nr, t1, n1) \ |
| 40 | inline tr nr(t1 n1) { \ |
| 41 | return syscall(__NR_##nr, n1); \ |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | #ifndef _syscall2 |
| 46 | #define _syscall2(tr, nr, t1, n1, t2, n2) \ |
| 47 | inline tr nr(t1 n1, t2 n2) { \ |
| 48 | return syscall(__NR_##nr, n1, n2); \ |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | #ifndef _syscall3 |
| 53 | #define _syscall3(tr, nr, t1, n1, t2, n2, t3, n3) \ |
| 54 | inline tr nr(t1 n1, t2 n2, t3 n3) { \ |
| 55 | return syscall(__NR_##nr, n1, n2, n3); \ |
| 56 | } |
| 57 | #endif |
| 58 | |
| 59 | #ifndef _syscall4 |
| 60 | #define _syscall4(tr, nr, t1, n1, t2, n2, t3, n3, t4, n4) \ |
| 61 | inline tr nr(t1 n1, t2 n2, t3 n3, t4 n4) { \ |
| 62 | return syscall(__NR_##nr, n1, n2, n3, n4); \ |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | #ifndef _syscall5 |
| 67 | #define _syscall5(tr, nr, t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) \ |
| 68 | inline tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5) { \ |
| 69 | return syscall(__NR_##nr, n1, n2, n3, n4, n5); \ |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | #ifndef _syscall6 |
| 74 | #define _syscall6(tr, nr, t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6) \ |
| 75 | inline tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6) { \ |
| 76 | return syscall(__NR_##nr, n1, n2, n3, n4, n5, n6); \ |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | |
| 81 | /* Define some syscall numbers that are sometimes needed */ |
| 82 | |
| 83 | /* Epoll was provided as a patch for 2.4 for a long time and was not always |
| 84 | * exported as a known sysctl number by libc. |
| 85 | */ |
| 86 | #if !defined(__NR_epoll_ctl) |
| 87 | #if defined(__powerpc__) || defined(__powerpc64__) |
| 88 | #define __NR_epoll_create 236 |
| 89 | #define __NR_epoll_ctl 237 |
| 90 | #define __NR_epoll_wait 238 |
| 91 | #elif defined(__sparc__) || defined(__sparc64__) |
| 92 | #define __NR_epoll_create 193 |
| 93 | #define __NR_epoll_ctl 194 |
| 94 | #define __NR_epoll_wait 195 |
| 95 | #elif defined(__x86_64__) |
| 96 | #define __NR_epoll_create 213 |
| 97 | #define __NR_epoll_ctl 214 |
| 98 | #define __NR_epoll_wait 215 |
| 99 | #elif defined(__alpha__) |
| 100 | #define __NR_epoll_create 407 |
| 101 | #define __NR_epoll_ctl 408 |
| 102 | #define __NR_epoll_wait 409 |
| 103 | #elif defined (__i386__) |
| 104 | #define __NR_epoll_create 254 |
| 105 | #define __NR_epoll_ctl 255 |
| 106 | #define __NR_epoll_wait 256 |
| 107 | #endif /* $arch */ |
| 108 | #endif /* __NR_epoll_ctl */ |
| 109 | |
| 110 | /* splice is even more recent than epoll. It appeared around 2.6.18 but was |
| 111 | * not in libc for a while. |
| 112 | */ |
| 113 | #ifndef __NR_splice |
| 114 | #if defined(__powerpc__) || defined(__powerpc64__) |
| 115 | #define __NR_splice 283 |
| 116 | #elif defined(__sparc__) || defined(__sparc64__) |
| 117 | #define __NR_splice 232 |
| 118 | #elif defined(__x86_64__) |
| 119 | #define __NR_splice 275 |
| 120 | #elif defined(__alpha__) |
| 121 | #define __NR_splice 468 |
| 122 | #elif defined (__i386__) |
| 123 | #define __NR_splice 313 |
| 124 | #endif /* $arch */ |
| 125 | #endif /* __NR_splice */ |
| 126 | |
| 127 | |
| 128 | #endif /* __linux__ */ |
| 129 | #endif /* _COMMON_SYSCALL_H */ |
| 130 | |
| 131 | /* |
| 132 | * Local variables: |
| 133 | * c-indent-level: 8 |
| 134 | * c-basic-offset: 8 |
| 135 | * End: |
| 136 | */ |