1
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
3
* Permission is hereby granted, free of charge, to any person obtaining a copy
4
* of this software and associated documentation files (the "Software"), to
5
* deal in the Software without restriction, including without limitation the
6
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
* sell copies of the Software, and to permit persons to whom the Software is
8
* furnished to do so, subject to the following conditions:
10
* The above copyright notice and this permission notice shall be included in
11
* all copies or substantial portions of the Software.
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
#include "linux-syscalls.h"
24
#include <sys/syscall.h>
25
#include <sys/types.h>
29
# ifndef __NR_socketcall
30
# define __NR_socketcall 102
35
# if defined(__thumb__) || defined(__ARM_EABI__)
36
# define UV_SYSCALL_BASE 0
38
# define UV_SYSCALL_BASE 0x900000
43
# if defined(__x86_64__)
44
# define __NR_accept4 288
45
# elif defined(__i386__)
46
/* Nothing. Handled through socketcall(). */
47
# elif defined(__arm__)
48
# define __NR_accept4 (UV_SYSCALL_BASE + 366)
50
#endif /* __NR_accept4 */
53
# if defined(__x86_64__)
54
# define __NR_eventfd 284
55
# elif defined(__i386__)
56
# define __NR_eventfd 323
57
# elif defined(__arm__)
58
# define __NR_eventfd (UV_SYSCALL_BASE + 351)
60
#endif /* __NR_eventfd */
63
# if defined(__x86_64__)
64
# define __NR_eventfd2 290
65
# elif defined(__i386__)
66
# define __NR_eventfd2 328
67
# elif defined(__arm__)
68
# define __NR_eventfd2 (UV_SYSCALL_BASE + 356)
70
#endif /* __NR_eventfd2 */
72
#ifndef __NR_epoll_create
73
# if defined(__x86_64__)
74
# define __NR_epoll_create 213
75
# elif defined(__i386__)
76
# define __NR_epoll_create 254
77
# elif defined(__arm__)
78
# define __NR_epoll_create (UV_SYSCALL_BASE + 250)
80
#endif /* __NR_epoll_create */
82
#ifndef __NR_epoll_create1
83
# if defined(__x86_64__)
84
# define __NR_epoll_create1 291
85
# elif defined(__i386__)
86
# define __NR_epoll_create1 329
87
# elif defined(__arm__)
88
# define __NR_epoll_create1 (UV_SYSCALL_BASE + 357)
90
#endif /* __NR_epoll_create1 */
92
#ifndef __NR_epoll_ctl
93
# if defined(__x86_64__)
94
# define __NR_epoll_ctl 233 /* used to be 214 */
95
# elif defined(__i386__)
96
# define __NR_epoll_ctl 255
97
# elif defined(__arm__)
98
# define __NR_epoll_ctl (UV_SYSCALL_BASE + 251)
100
#endif /* __NR_epoll_ctl */
102
#ifndef __NR_epoll_wait
103
# if defined(__x86_64__)
104
# define __NR_epoll_wait 232 /* used to be 215 */
105
# elif defined(__i386__)
106
# define __NR_epoll_wait 256
107
# elif defined(__arm__)
108
# define __NR_epoll_wait (UV_SYSCALL_BASE + 252)
110
#endif /* __NR_epoll_wait */
112
#ifndef __NR_epoll_pwait
113
# if defined(__x86_64__)
114
# define __NR_epoll_pwait 281
115
# elif defined(__i386__)
116
# define __NR_epoll_pwait 319
117
# elif defined(__arm__)
118
# define __NR_epoll_pwait (UV_SYSCALL_BASE + 346)
120
#endif /* __NR_epoll_pwait */
122
#ifndef __NR_inotify_init
123
# if defined(__x86_64__)
124
# define __NR_inotify_init 253
125
# elif defined(__i386__)
126
# define __NR_inotify_init 291
127
# elif defined(__arm__)
128
# define __NR_inotify_init (UV_SYSCALL_BASE + 316)
130
#endif /* __NR_inotify_init */
132
#ifndef __NR_inotify_init1
133
# if defined(__x86_64__)
134
# define __NR_inotify_init1 294
135
# elif defined(__i386__)
136
# define __NR_inotify_init1 332
137
# elif defined(__arm__)
138
# define __NR_inotify_init1 (UV_SYSCALL_BASE + 360)
140
#endif /* __NR_inotify_init1 */
142
#ifndef __NR_inotify_add_watch
143
# if defined(__x86_64__)
144
# define __NR_inotify_add_watch 254
145
# elif defined(__i386__)
146
# define __NR_inotify_add_watch 292
147
# elif defined(__arm__)
148
# define __NR_inotify_add_watch (UV_SYSCALL_BASE + 317)
150
#endif /* __NR_inotify_add_watch */
152
#ifndef __NR_inotify_rm_watch
153
# if defined(__x86_64__)
154
# define __NR_inotify_rm_watch 255
155
# elif defined(__i386__)
156
# define __NR_inotify_rm_watch 293
157
# elif defined(__arm__)
158
# define __NR_inotify_rm_watch (UV_SYSCALL_BASE + 318)
160
#endif /* __NR_inotify_rm_watch */
163
# if defined(__x86_64__)
164
# define __NR_pipe2 293
165
# elif defined(__i386__)
166
# define __NR_pipe2 331
167
# elif defined(__arm__)
168
# define __NR_pipe2 (UV_SYSCALL_BASE + 359)
170
#endif /* __NR_pipe2 */
172
#ifndef __NR_recvmmsg
173
# if defined(__x86_64__)
174
# define __NR_recvmmsg 299
175
# elif defined(__i386__)
176
# define __NR_recvmmsg 337
177
# elif defined(__arm__)
178
# define __NR_recvmmsg (UV_SYSCALL_BASE + 365)
180
#endif /* __NR_recvmsg */
182
#ifndef __NR_sendmmsg
183
# if defined(__x86_64__)
184
# define __NR_sendmmsg 307
185
# elif defined(__i386__)
186
# define __NR_sendmmsg 345
187
# elif defined(__arm__)
188
# define __NR_sendmmsg (UV_SYSCALL_BASE + 374)
190
#endif /* __NR_sendmmsg */
192
#ifndef __NR_utimensat
193
# if defined(__x86_64__)
194
# define __NR_utimensat 280
195
# elif defined(__i386__)
196
# define __NR_utimensat 320
197
# elif defined(__arm__)
198
# define __NR_utimensat (UV_SYSCALL_BASE + 348)
200
#endif /* __NR_utimensat */
203
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) {
204
#if defined(__i386__)
205
unsigned long args[4];
208
args[0] = (unsigned long) fd;
209
args[1] = (unsigned long) addr;
210
args[2] = (unsigned long) addrlen;
211
args[3] = (unsigned long) flags;
213
r = syscall(__NR_socketcall, 18 /* SYS_ACCEPT4 */, args);
215
/* socketcall() raises EINVAL when SYS_ACCEPT4 is not supported but so does
216
* a bad flags argument. Try to distinguish between the two cases.
220
if ((flags & ~(UV__SOCK_CLOEXEC|UV__SOCK_NONBLOCK)) == 0)
224
#elif defined(__NR_accept4)
225
return syscall(__NR_accept4, fd, addr, addrlen, flags);
227
return errno = ENOSYS, -1;
232
int uv__eventfd(unsigned int count) {
233
#if defined(__NR_eventfd)
234
return syscall(__NR_eventfd, count);
236
return errno = ENOSYS, -1;
241
int uv__eventfd2(unsigned int count, int flags) {
242
#if defined(__NR_eventfd2)
243
return syscall(__NR_eventfd2, count, flags);
245
return errno = ENOSYS, -1;
250
int uv__epoll_create(int size) {
251
#if defined(__NR_epoll_create)
252
return syscall(__NR_epoll_create, size);
254
return errno = ENOSYS, -1;
259
int uv__epoll_create1(int flags) {
260
#if defined(__NR_epoll_create1)
261
return syscall(__NR_epoll_create1, flags);
263
return errno = ENOSYS, -1;
268
int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event* events) {
269
#if defined(__NR_epoll_ctl)
270
return syscall(__NR_epoll_ctl, epfd, op, fd, events);
272
return errno = ENOSYS, -1;
277
int uv__epoll_wait(int epfd,
278
struct uv__epoll_event* events,
281
#if defined(__NR_epoll_wait)
282
return syscall(__NR_epoll_wait, epfd, events, nevents, timeout);
284
return errno = ENOSYS, -1;
289
int uv__epoll_pwait(int epfd,
290
struct uv__epoll_event* events,
293
const sigset_t* sigmask) {
294
#if defined(__NR_epoll_pwait)
295
return syscall(__NR_epoll_pwait,
303
return errno = ENOSYS, -1;
308
int uv__inotify_init(void) {
309
#if defined(__NR_inotify_init)
310
return syscall(__NR_inotify_init);
312
return errno = ENOSYS, -1;
317
int uv__inotify_init1(int flags) {
318
#if defined(__NR_inotify_init1)
319
return syscall(__NR_inotify_init1, flags);
321
return errno = ENOSYS, -1;
326
int uv__inotify_add_watch(int fd, const char* path, uint32_t mask) {
327
#if defined(__NR_inotify_add_watch)
328
return syscall(__NR_inotify_add_watch, fd, path, mask);
330
return errno = ENOSYS, -1;
335
int uv__inotify_rm_watch(int fd, int32_t wd) {
336
#if defined(__NR_inotify_rm_watch)
337
return syscall(__NR_inotify_rm_watch, fd, wd);
339
return errno = ENOSYS, -1;
344
int uv__pipe2(int pipefd[2], int flags) {
345
#if defined(__NR_pipe2)
346
return syscall(__NR_pipe2, pipefd, flags);
348
return errno = ENOSYS, -1;
353
int uv__sendmmsg(int fd,
354
struct uv__mmsghdr* mmsg,
356
unsigned int flags) {
357
#if defined(__NR_sendmmsg)
358
return syscall(__NR_sendmmsg, fd, mmsg, vlen, flags);
360
return errno = ENOSYS, -1;
365
int uv__recvmmsg(int fd,
366
struct uv__mmsghdr* mmsg,
369
struct timespec* timeout) {
370
#if defined(__NR_recvmmsg)
371
return syscall(__NR_recvmmsg, fd, mmsg, vlen, flags, timeout);
373
return errno = ENOSYS, -1;
378
int uv__utimesat(int dirfd,
380
const struct timespec times[2],
383
#if defined(__NR_utimensat)
384
return syscall(__NR_utimensat, dirfd, path, times, flags);
386
return errno = ENOSYS, -1;