1 /*	$NetBSD: linux_socketcall.h,v 1.22 2021/09/23 06:56:27 ryo Exp $	*/
2 
3 /*-
4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Frank van der Linden and Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1995 Frank van der Linden
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. All advertising materials mentioning features or use of this software
45  *    must display the following acknowledgement:
46  *      This product includes software developed for the NetBSD Project
47  *      by Frank van der Linden
48  * 4. The name of the author may not be used to endorse or promote products
49  *    derived from this software without specific prior written permission
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61  */
62 
63 #ifndef _LINUX_SOCKETCALL_H
64 #define _LINUX_SOCKETCALL_H
65 
66 /* Alpha does not use the socketcall multiplexer */
67 #if !defined(__aarch64__) && !defined(__alpha__) && !defined(__amd64__) && !defined(COMPAT_LINUX32)
68 /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
69 /* Used for COMPAT_LINUX32 on amd64 */
70 /* Not used on: aarch64, alpha */
71 #include <compat/linux/linux_syscall.h>
72 #include <compat/linux/linux_syscallargs.h>
73 
74 /*
75  * Values passed to the Linux socketcall() syscall, determining the actual
76  * action to take.
77  */
78 
79 #define LINUX_SYS_SOCKET	1
80 #define LINUX_SYS_BIND		2
81 #define LINUX_SYS_CONNECT	3
82 #define LINUX_SYS_LISTEN	4
83 #define LINUX_SYS_ACCEPT	5
84 #define LINUX_SYS_GETSOCKNAME	6
85 #define LINUX_SYS_GETPEERNAME	7
86 #define LINUX_SYS_SOCKETPAIR	8
87 #define LINUX_SYS_SEND		9
88 #define LINUX_SYS_RECV		10
89 #define LINUX_SYS_SENDTO	11
90 #define LINUX_SYS_RECVFROM	12
91 #define LINUX_SYS_SHUTDOWN	13
92 #define LINUX_SYS_SETSOCKOPT	14
93 #define LINUX_SYS_GETSOCKOPT	15
94 #define LINUX_SYS_SENDMSG	16
95 #define LINUX_SYS_RECVMSG	17
96 #define LINUX_SYS_ACCEPT4	18
97 #define LINUX_SYS_RECVMMSG	19
98 #define LINUX_SYS_SENDMMSG	20
99 
100 #define LINUX_MAX_SOCKETCALL	20
101 
102 
103 /*
104  * Structures for the arguments of the different system calls. This looks
105  * a little better than copyin() of all values one by one.
106  */
107 
108 /* !!!: This should be at least as large as any other struct here. */
109 struct linux_socketcall_dummy_args {
110 	int dummy_ints[4];		/* Max 4 ints */
111 	void *dummy_ptrs[3];		/* Max 3 pointers */
112 };
113 
114 #ifndef LINUX_SYS_socket
115 struct linux_sys_socket_args {
116 	syscallarg(int) domain;
117 	syscallarg(int) type;
118 	syscallarg(int) protocol;
119 };
120 #endif
121 
122 #ifndef LINUX_SYS_socketpair
123 struct linux_sys_socketpair_args {
124 	syscallarg(int) domain;
125 	syscallarg(int) type;
126 	syscallarg(int) protocol;
127 	syscallarg(int *) rsv;
128 };
129 #endif
130 
131 #ifndef LINUX_SYS_sendto
132 struct linux_sys_sendto_args {
133 	syscallarg(int) s;
134 	syscallarg(void *) msg;
135 	syscallarg(int) len;
136 	syscallarg(int) flags;
137 	syscallarg(struct osockaddr *) to;
138 	syscallarg(int) tolen;
139 };
140 #endif
141 
142 #ifndef LINUX_SYS_recvfrom
143 struct linux_sys_recvfrom_args {
144 	syscallarg(int) s;
145 	syscallarg(void *) buf;
146 	syscallarg(int) len;
147 	syscallarg(int) flags;
148 	syscallarg(struct osockaddr *) from;
149 	syscallarg(int *) fromlenaddr;
150 };
151 #endif
152 
153 #ifndef LINUX_SYS_setsockopt
154 struct linux_sys_setsockopt_args {
155 	syscallarg(int) s;
156 	syscallarg(int) level;
157 	syscallarg(int) optname;
158 	syscallarg(void *) optval;
159 	syscallarg(int) optlen;
160 };
161 #endif
162 
163 #ifndef LINUX_SYS_getsockopt
164 struct linux_sys_getsockopt_args {
165 	syscallarg(int) s;
166 	syscallarg(int) level;
167 	syscallarg(int) optname;
168 	syscallarg(void *) optval;
169 	syscallarg(int *) optlen;
170 };
171 #endif
172 
173 #ifndef LINUX_SYS_bind
174 struct linux_sys_bind_args {
175 	syscallarg(int) s;
176 	syscallarg(struct osockaddr *) name;
177 	syscallarg(int) namelen;
178 };
179 #endif
180 
181 #ifndef LINUX_SYS_connect
182 struct linux_sys_connect_args {
183 	syscallarg(int) s;
184 	syscallarg(struct osockaddr *) name;
185 	syscallarg(int) namelen;
186 };
187 #endif
188 
189 #ifndef LINUX_SYS_accept
190 struct linux_sys_accept_args {
191 	syscallarg(int) s;
192 	syscallarg(struct osockaddr *) name;
193 	syscallarg(int *) anamelen;
194 };
195 #endif
196 
197 #ifndef LINUX_SYS_getsockname
198 struct linux_sys_getsockname_args {
199 	syscallarg(int) fdes;
200 	syscallarg(struct osockaddr *) asa;
201 	syscallarg(int *) alen;
202 };
203 #endif
204 
205 #ifndef LINUX_SYS_getpeername
206 struct linux_sys_getpeername_args {
207 	syscallarg(int) fdes;
208 	syscallarg(struct osockaddr *) asa;
209 	syscallarg(int *) alen;
210 };
211 #endif
212 
213 #ifndef LINUX_SYS_sendmsg
214 struct linux_sys_sendmsg_args {
215 	syscallarg(int) s;
216 	syscallarg(struct linux_msghdr *) msg;
217 	syscallarg(u_int) flags;
218 };
219 #endif
220 
221 #ifndef LINUX_SYS_recvmsg
222 struct linux_sys_recvmsg_args {
223 	syscallarg(int) s;
224 	syscallarg(struct linux_msghdr *) msg;
225 	syscallarg(u_int) flags;
226 };
227 #endif
228 
229 #ifndef LINUX_SYS_send
230 struct linux_sys_send_args {
231 	syscallarg(int) s;
232 	syscallarg(void *) buf;
233 	syscallarg(int) len;
234 	syscallarg(int) flags;
235 };
236 #endif
237 
238 #ifndef LINUX_SYS_recv
239 struct linux_sys_recv_args {
240 	syscallarg(int) s;
241 	syscallarg(void *) buf;
242 	syscallarg(int) len;
243 	syscallarg(int) flags;
244 };
245 #endif
246 
247 #ifndef LINUX_SYS_accept4
248 struct linux_sys_accept4_args {
249 	syscallarg(int) s;
250 	syscallarg(struct osockaddr *) name;
251 	syscallarg(int *) anamelen;
252 	syscallarg(int) flags;
253 };
254 #endif
255 
256 #ifndef LINUX_SYS_recvmmsg
257 struct linux_sys_recvmmsg_args {
258 	syscallarg(int) s;
259 	syscallarg(struct linux_mmsghdr *) msgvec;
260 	syscallarg(unsigned int) vlen;
261 	syscallarg(unsigned int) flags;
262 	syscallarg(struct linux_timespec *) timeout;
263 };
264 #endif
265 
266 #ifndef LINUX_SYS_sendmmsg
267 struct linux_sys_sendmmsg_args {
268 	syscallarg(int) s;
269 	syscallarg(struct linux_mmsghdr *) msgvec;
270 	syscallarg(unsigned int) vlen;
271 	syscallarg(unsigned int) flags;
272 };
273 #endif
274 
275 # ifdef _KERNEL
276 __BEGIN_DECLS
277 #define SYS_DEF(foo) int foo(struct lwp *, const struct foo##_args *, register_t *);
278 SYS_DEF(linux_sys_socket)
279 SYS_DEF(linux_sys_socketpair)
280 SYS_DEF(linux_sys_sendto)
281 SYS_DEF(linux_sys_recvfrom)
282 SYS_DEF(linux_sys_setsockopt)
283 SYS_DEF(linux_sys_getsockopt)
284 SYS_DEF(linux_sys_connect)
285 SYS_DEF(linux_sys_bind)
286 SYS_DEF(linux_sys_getsockname)
287 SYS_DEF(linux_sys_getpeername)
288 SYS_DEF(linux_sys_sendmsg)
289 SYS_DEF(linux_sys_recvmsg)
290 SYS_DEF(linux_sys_recv)
291 SYS_DEF(linux_sys_send)
292 SYS_DEF(linux_sys_accept)
293 SYS_DEF(linux_sys_accept4)
294 SYS_DEF(linux_sys_recvmmsg)
295 SYS_DEF(linux_sys_sendmmsg)
296 #undef SYS_DEF
297 __END_DECLS
298 # endif /* !_KERNEL */
299 
300 # endif
301 
302 #endif /* !_LINUX_SOCKETCALL_H */
303