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 | * |
Willy Tarreau | 1bc4aab | 2012-10-08 20:11:03 +0200 | [diff] [blame] | 5 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 40 | tr nr(t1 n1) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 41 | return syscall(__NR_##nr, n1); \ |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | #ifndef _syscall2 |
| 46 | #define _syscall2(tr, nr, t1, n1, t2, n2) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 47 | tr nr(t1 n1, t2 n2) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 54 | tr nr(t1 n1, t2 n2, t3 n3) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 61 | tr nr(t1 n1, t2 n2, t3 n3, t4 n4) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 68 | tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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) \ |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 75 | tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6) { \ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 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 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 83 | #endif /* __linux__ */ |
| 84 | #endif /* _COMMON_SYSCALL_H */ |
| 85 | |
| 86 | /* |
| 87 | * Local variables: |
| 88 | * c-indent-level: 8 |
| 89 | * c-basic-offset: 8 |
| 90 | * End: |
| 91 | */ |