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