1/* ID for functions called via socketcall system call.
2 Copyright (C) 1995-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKETCALL_H
20#define _SYS_SOCKETCALL_H 1
21
22/* Define unique numbers for the operations permitted on socket. Linux
23 uses a single system call for all these functions. The relevant code
24 file is /usr/include/linux/net.h.
25 We cannot use an enum here because the values are used in assembler
26 code. */
27
28#define SOCKOP_invalid -1
29#define SOCKOP_socket 1
30#define SOCKOP_bind 2
31#define SOCKOP_connect 3
32#define SOCKOP_listen 4
33#define SOCKOP_accept 5
34#define SOCKOP_getsockname 6
35#define SOCKOP_getpeername 7
36#define SOCKOP_socketpair 8
37#define SOCKOP_send 9
38#define SOCKOP_recv 10
39#define SOCKOP_sendto 11
40#define SOCKOP_recvfrom 12
41#define SOCKOP_shutdown 13
42#define SOCKOP_setsockopt 14
43#define SOCKOP_getsockopt 15
44#define SOCKOP_sendmsg 16
45#define SOCKOP_recvmsg 17
46#define SOCKOP_accept4 18
47#define SOCKOP_recvmmsg 19
48#define SOCKOP_sendmmsg 20
49
50#define __SOCKETCALL1(name, a1) \
51 INLINE_SYSCALL (socketcall, 2, name, \
52 ((long int [1]) { (long int) (a1) }))
53#define __SOCKETCALL2(name, a1, a2) \
54 INLINE_SYSCALL (socketcall, 2, name, \
55 ((long int [2]) { (long int) (a1), (long int) (a2) }))
56#define __SOCKETCALL3(name, a1, a2, a3) \
57 INLINE_SYSCALL (socketcall, 2, name, \
58 ((long int [3]) { (long int) (a1), (long int) (a2), (long int) (a3) }))
59#define __SOCKETCALL4(name, a1, a2, a3, a4) \
60 INLINE_SYSCALL (socketcall, 2, name, \
61 ((long int [4]) { (long int) (a1), (long int) (a2), (long int) (a3), \
62 (long int) (a4) }))
63#define __SOCKETCALL5(name, a1, a2, a3, a4, a5) \
64 INLINE_SYSCALL (socketcall, 2, name, \
65 ((long int [5]) { (long int) (a1), (long int) (a2), (long int) (a3), \
66 (long int) (a4), (long int) (a5) }))
67#define __SOCKETCALL6(name, a1, a2, a3, a4, a5, a6) \
68 INLINE_SYSCALL (socketcall, 2, name, \
69 ((long int [6]) { (long int) (a1), (long int) (a2), (long int) (a3), \
70 (long int) (a4), (long int) (a5), (long int) (a6) }))
71
72#define __SOCKETCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
73#define __SOCKETCALL_NARGS(...) \
74 __SOCKETCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
75#define __SOCKETCALL_CONCAT_X(a,b) a##b
76#define __SOCKETCALL_CONCAT(a,b) __SOCKETCALL_CONCAT_X (a, b)
77#define __SOCKETCALL_DISP(b,...) \
78 __SOCKETCALL_CONCAT (b,__SOCKETCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
79
80#define __SOCKETCALL(...) __SOCKETCALL_DISP (__SOCKETCALL, __VA_ARGS__)
81
82
83#define SOCKETCALL(name, args...) \
84 ({ \
85 long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \
86 sc_ret; \
87 })
88
89
90#if IS_IN (libc)
91# define __pthread_enable_asynccancel __libc_enable_asynccancel
92# define __pthread_disable_asynccancel __libc_disable_asynccancel
93#endif
94
95#define SOCKETCALL_CANCEL(name, args...) \
96 ({ \
97 int oldtype = LIBC_CANCEL_ASYNC (); \
98 long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \
99 LIBC_CANCEL_RESET (oldtype); \
100 sc_ret; \
101 })
102
103
104#endif /* sys/socketcall.h */
105