blob: 9554d5ad8c130e0317f652230438334764de8b2b [file] [log] [blame]
Willy Tarreau43d8fb22011-08-22 17:12:02 +02001/*
2 * include/common/syscall.h
3 * Redefinition of some missing OS-specific system calls.
4 *
Willy Tarreau1bc4aab2012-10-08 20:11:03 +02005 * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
Willy Tarreau43d8fb22011-08-22 17:12:02 +02006 *
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 Tarreaucefad672014-05-08 22:36:29 +020040 tr nr(t1 n1) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020041 return syscall(__NR_##nr, n1); \
42 }
43#endif
44
45#ifndef _syscall2
46#define _syscall2(tr, nr, t1, n1, t2, n2) \
Willy Tarreaucefad672014-05-08 22:36:29 +020047 tr nr(t1 n1, t2 n2) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020048 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 Tarreaucefad672014-05-08 22:36:29 +020054 tr nr(t1 n1, t2 n2, t3 n3) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020055 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 Tarreaucefad672014-05-08 22:36:29 +020061 tr nr(t1 n1, t2 n2, t3 n3, t4 n4) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020062 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 Tarreaucefad672014-05-08 22:36:29 +020068 tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020069 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 Tarreaucefad672014-05-08 22:36:29 +020075 tr nr(t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6) { \
Willy Tarreau43d8fb22011-08-22 17:12:02 +020076 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
Neale Ferguson66b3c152015-10-12 20:58:51 +0200107#elif defined (__s390__) || defined(__s390x__)
108#define __NR_epoll_create 249
109#define __NR_epoll_ctl 250
110#define __NR_epoll_wait 251
Willy Tarreau43d8fb22011-08-22 17:12:02 +0200111#endif /* $arch */
112#endif /* __NR_epoll_ctl */
113
114/* splice is even more recent than epoll. It appeared around 2.6.18 but was
115 * not in libc for a while.
116 */
117#ifndef __NR_splice
118#if defined(__powerpc__) || defined(__powerpc64__)
119#define __NR_splice 283
120#elif defined(__sparc__) || defined(__sparc64__)
121#define __NR_splice 232
122#elif defined(__x86_64__)
123#define __NR_splice 275
124#elif defined(__alpha__)
125#define __NR_splice 468
126#elif defined (__i386__)
127#define __NR_splice 313
Neale Ferguson66b3c152015-10-12 20:58:51 +0200128#elif defined(__s390__) || defined(__s390x__)
129#define __NR_splace 306
Willy Tarreau43d8fb22011-08-22 17:12:02 +0200130#endif /* $arch */
131#endif /* __NR_splice */
132
Willy Tarreau1bc4aab2012-10-08 20:11:03 +0200133/* accept4() appeared in Linux 2.6.28, but it might not be in all libcs. Some
134 * archs have it as a native syscall, other ones use the socketcall instead.
135 */
136#ifndef __NR_accept4
137#if defined(__x86_64__)
138#define __NR_accept4 288
139#elif defined(__sparc__) || defined(__sparc64__)
Willy Tarreaub26cc862013-03-04 07:31:08 +0100140#define __NR_accept4 323
Willy Tarreau4f4b18b2013-03-04 07:38:08 +0100141#elif defined(__arm__) || defined(__thumb__)
142#define __NR_accept4 (__NR_SYSCALL_BASE+366)
Willy Tarreau1bc4aab2012-10-08 20:11:03 +0200143#else
144#define ACCEPT4_USE_SOCKETCALL 1
145#ifndef SYS_ACCEPT4
146#define SYS_ACCEPT4 18
147#endif /* SYS_ACCEPT4 */
148#endif /* $arch */
149#endif /* __NR_accept4 */
Willy Tarreau43d8fb22011-08-22 17:12:02 +0200150
151#endif /* __linux__ */
152#endif /* _COMMON_SYSCALL_H */
153
154/*
155 * Local variables:
156 * c-indent-level: 8
157 * c-basic-offset: 8
158 * End:
159 */