uipc_syscalls_43.c revision 1.14 1 1.14 jdolecek /* $NetBSD: uipc_syscalls_43.c,v 1.14 2001/07/07 14:44:45 jdolecek Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1982, 1986, 1989, 1990, 1993
5 1.1 christos * The Regents of the University of California. All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos * 1. Redistributions of source code must retain the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer.
12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer in the
14 1.1 christos * documentation and/or other materials provided with the distribution.
15 1.1 christos * 3. All advertising materials mentioning features or use of this software
16 1.1 christos * must display the following acknowledgement:
17 1.1 christos * This product includes software developed by the University of
18 1.1 christos * California, Berkeley and its contributors.
19 1.1 christos * 4. Neither the name of the University nor the names of its contributors
20 1.1 christos * may be used to endorse or promote products derived from this software
21 1.1 christos * without specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 christos * SUCH DAMAGE.
34 1.1 christos *
35 1.1 christos * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
36 1.1 christos */
37 1.1 christos
38 1.10 drochner #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
39 1.10 drochner
40 1.1 christos #include <sys/param.h>
41 1.1 christos #include <sys/systm.h>
42 1.1 christos #include <sys/filedesc.h>
43 1.1 christos #include <sys/kernel.h>
44 1.1 christos #include <sys/proc.h>
45 1.1 christos #include <sys/file.h>
46 1.1 christos #include <sys/socket.h>
47 1.1 christos #include <sys/socketvar.h>
48 1.1 christos #include <sys/stat.h>
49 1.1 christos #include <sys/ioctl.h>
50 1.1 christos #include <sys/fcntl.h>
51 1.1 christos #include <sys/malloc.h>
52 1.1 christos #include <sys/syslog.h>
53 1.1 christos #include <sys/unistd.h>
54 1.1 christos #include <sys/resourcevar.h>
55 1.1 christos
56 1.1 christos #include <sys/mount.h>
57 1.1 christos #include <sys/syscallargs.h>
58 1.1 christos
59 1.1 christos int
60 1.3 mycroft compat_43_sys_accept(p, v, retval)
61 1.1 christos struct proc *p;
62 1.2 thorpej void *v;
63 1.2 thorpej register_t *retval;
64 1.2 thorpej {
65 1.3 mycroft struct sys_accept_args /* {
66 1.1 christos syscallarg(int) s;
67 1.1 christos syscallarg(caddr_t) name;
68 1.1 christos syscallarg(int *) anamelen;
69 1.2 thorpej } */ *uap = v;
70 1.1 christos int error;
71 1.1 christos
72 1.3 mycroft if ((error = sys_accept(p, uap, retval)) != 0)
73 1.1 christos return error;
74 1.1 christos
75 1.1 christos if (SCARG(uap, name)) {
76 1.1 christos struct sockaddr sa;
77 1.1 christos
78 1.1 christos if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
79 1.1 christos return error;
80 1.1 christos
81 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
82 1.1 christos
83 1.1 christos if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
84 1.1 christos return error;
85 1.1 christos }
86 1.1 christos return 0;
87 1.1 christos }
88 1.1 christos
89 1.1 christos int
90 1.3 mycroft compat_43_sys_getpeername(p, v, retval)
91 1.1 christos struct proc *p;
92 1.2 thorpej void *v;
93 1.2 thorpej register_t *retval;
94 1.2 thorpej {
95 1.3 mycroft struct sys_getpeername_args /* {
96 1.1 christos syscallarg(int) fdes;
97 1.1 christos syscallarg(caddr_t) asa;
98 1.1 christos syscallarg(int *) alen;
99 1.2 thorpej } */ *uap = v;
100 1.1 christos struct sockaddr sa;
101 1.1 christos
102 1.1 christos int error;
103 1.1 christos
104 1.3 mycroft if ((error = sys_getpeername(p, uap, retval)) != 0)
105 1.1 christos return error;
106 1.1 christos
107 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
108 1.1 christos return error;
109 1.1 christos
110 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
111 1.1 christos
112 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
113 1.1 christos return error;
114 1.1 christos
115 1.1 christos return 0;
116 1.1 christos }
117 1.1 christos
118 1.1 christos int
119 1.3 mycroft compat_43_sys_getsockname(p, v, retval)
120 1.1 christos struct proc *p;
121 1.2 thorpej void *v;
122 1.2 thorpej register_t *retval;
123 1.2 thorpej {
124 1.3 mycroft struct sys_getsockname_args /* {
125 1.1 christos syscallarg(int) fdes;
126 1.1 christos syscallarg(caddr_t) asa;
127 1.1 christos syscallarg(int *) alen;
128 1.2 thorpej } */ *uap = v;
129 1.1 christos struct sockaddr sa;
130 1.1 christos int error;
131 1.1 christos
132 1.3 mycroft if ((error = sys_getsockname(p, uap, retval)) != 0)
133 1.1 christos return error;
134 1.1 christos
135 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
136 1.1 christos return error;
137 1.1 christos
138 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
139 1.1 christos
140 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
141 1.1 christos return error;
142 1.1 christos
143 1.1 christos return 0;
144 1.1 christos }
145 1.1 christos
146 1.1 christos int
147 1.3 mycroft compat_43_sys_recv(p, v, retval)
148 1.1 christos struct proc *p;
149 1.2 thorpej void *v;
150 1.2 thorpej register_t *retval;
151 1.2 thorpej {
152 1.11 augustss struct compat_43_sys_recv_args /* {
153 1.1 christos syscallarg(int) s;
154 1.1 christos syscallarg(caddr_t) buf;
155 1.1 christos syscallarg(int) len;
156 1.1 christos syscallarg(int) flags;
157 1.2 thorpej } */ *uap = v;
158 1.14 jdolecek struct sys_recvfrom_args bra;
159 1.14 jdolecek
160 1.14 jdolecek SCARG(&bra, s) = SCARG(uap, s);
161 1.14 jdolecek SCARG(&bra, buf) = SCARG(uap, buf);
162 1.14 jdolecek SCARG(&bra, len) = (size_t) SCARG(uap, len);
163 1.14 jdolecek SCARG(&bra, flags) = SCARG(uap, flags);
164 1.14 jdolecek SCARG(&bra, from) = NULL;
165 1.14 jdolecek SCARG(&bra, fromlenaddr) = NULL;
166 1.1 christos
167 1.14 jdolecek return (sys_recvfrom(p, &bra, retval));
168 1.1 christos }
169 1.1 christos
170 1.1 christos int
171 1.3 mycroft compat_43_sys_recvfrom(p, v, retval)
172 1.1 christos struct proc *p;
173 1.2 thorpej void *v;
174 1.2 thorpej register_t *retval;
175 1.2 thorpej {
176 1.3 mycroft struct sys_recvfrom_args /* {
177 1.1 christos syscallarg(int) s;
178 1.1 christos syscallarg(caddr_t) buf;
179 1.1 christos syscallarg(size_t) len;
180 1.1 christos syscallarg(int) flags;
181 1.1 christos syscallarg(caddr_t) from;
182 1.1 christos syscallarg(int *) fromlenaddr;
183 1.2 thorpej } */ *uap = v;
184 1.1 christos
185 1.1 christos SCARG(uap, flags) |= MSG_COMPAT;
186 1.3 mycroft return (sys_recvfrom(p, uap, retval));
187 1.1 christos }
188 1.1 christos
189 1.1 christos /*
190 1.1 christos * Old recvmsg. This code takes advantage of the fact that the old msghdr
191 1.1 christos * overlays the new one, missing only the flags, and with the (old) access
192 1.1 christos * rights where the control fields are now.
193 1.1 christos */
194 1.1 christos int
195 1.3 mycroft compat_43_sys_recvmsg(p, v, retval)
196 1.1 christos struct proc *p;
197 1.2 thorpej void *v;
198 1.2 thorpej register_t *retval;
199 1.2 thorpej {
200 1.11 augustss struct compat_43_sys_recvmsg_args /* {
201 1.1 christos syscallarg(int) s;
202 1.1 christos syscallarg(struct omsghdr *) msg;
203 1.1 christos syscallarg(int) flags;
204 1.2 thorpej } */ *uap = v;
205 1.1 christos struct msghdr msg;
206 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
207 1.1 christos int error;
208 1.1 christos
209 1.5 christos error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
210 1.5 christos sizeof (struct omsghdr));
211 1.5 christos if (error)
212 1.1 christos return (error);
213 1.6 kleink if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
214 1.7 kleink if ((u_int)msg.msg_iovlen > IOV_MAX)
215 1.1 christos return (EMSGSIZE);
216 1.1 christos MALLOC(iov, struct iovec *,
217 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
218 1.1 christos M_WAITOK);
219 1.1 christos } else
220 1.1 christos iov = aiov;
221 1.1 christos msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
222 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
223 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
224 1.5 christos if (error)
225 1.1 christos goto done;
226 1.1 christos msg.msg_iov = iov;
227 1.1 christos error = recvit(p, SCARG(uap, s), &msg,
228 1.13 jdolecek (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
229 1.1 christos
230 1.1 christos if (msg.msg_controllen && error == 0)
231 1.1 christos error = copyout((caddr_t)&msg.msg_controllen,
232 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
233 1.1 christos done:
234 1.1 christos if (iov != aiov)
235 1.1 christos FREE(iov, M_IOV);
236 1.1 christos return (error);
237 1.1 christos }
238 1.1 christos
239 1.1 christos int
240 1.3 mycroft compat_43_sys_send(p, v, retval)
241 1.1 christos struct proc *p;
242 1.2 thorpej void *v;
243 1.2 thorpej register_t *retval;
244 1.2 thorpej {
245 1.11 augustss struct compat_43_sys_send_args /* {
246 1.1 christos syscallarg(int) s;
247 1.1 christos syscallarg(caddr_t) buf;
248 1.1 christos syscallarg(int) len;
249 1.1 christos syscallarg(int) flags;
250 1.2 thorpej } */ *uap = v;
251 1.14 jdolecek struct sys_sendto_args bsa;
252 1.14 jdolecek
253 1.14 jdolecek SCARG(&bsa, s) = SCARG(uap, s);
254 1.14 jdolecek SCARG(&bsa, buf) = SCARG(uap, buf);
255 1.14 jdolecek SCARG(&bsa, len) = SCARG(uap, len);
256 1.14 jdolecek SCARG(&bsa, flags) = SCARG(uap, flags);
257 1.14 jdolecek SCARG(&bsa, to) = NULL;
258 1.14 jdolecek SCARG(&bsa, tolen) = 0;
259 1.1 christos
260 1.14 jdolecek return (sys_sendto(p, &bsa, retval));
261 1.1 christos }
262 1.1 christos
263 1.1 christos int
264 1.3 mycroft compat_43_sys_sendmsg(p, v, retval)
265 1.1 christos struct proc *p;
266 1.2 thorpej void *v;
267 1.2 thorpej register_t *retval;
268 1.2 thorpej {
269 1.11 augustss struct compat_43_sys_sendmsg_args /* {
270 1.1 christos syscallarg(int) s;
271 1.1 christos syscallarg(caddr_t) msg;
272 1.1 christos syscallarg(int) flags;
273 1.2 thorpej } */ *uap = v;
274 1.1 christos struct msghdr msg;
275 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
276 1.1 christos int error;
277 1.1 christos
278 1.5 christos error = copyin(SCARG(uap, msg), (caddr_t)&msg,
279 1.5 christos sizeof (struct omsghdr));
280 1.5 christos if (error)
281 1.1 christos return (error);
282 1.6 kleink if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
283 1.7 kleink if ((u_int)msg.msg_iovlen > IOV_MAX)
284 1.1 christos return (EMSGSIZE);
285 1.1 christos MALLOC(iov, struct iovec *,
286 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
287 1.1 christos M_WAITOK);
288 1.1 christos } else
289 1.1 christos iov = aiov;
290 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
291 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
292 1.5 christos if (error)
293 1.1 christos goto done;
294 1.1 christos msg.msg_flags = MSG_COMPAT;
295 1.1 christos msg.msg_iov = iov;
296 1.13 jdolecek error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
297 1.1 christos done:
298 1.1 christos if (iov != aiov)
299 1.1 christos FREE(iov, M_IOV);
300 1.1 christos return (error);
301 1.1 christos }
302