uipc_syscalls_43.c revision 1.14 1 /* $NetBSD: uipc_syscalls_43.c,v 1.14 2001/07/07 14:44:45 jdolecek 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 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 sys_recvfrom_args bra;
159
160 SCARG(&bra, s) = SCARG(uap, s);
161 SCARG(&bra, buf) = SCARG(uap, buf);
162 SCARG(&bra, len) = (size_t) SCARG(uap, len);
163 SCARG(&bra, flags) = SCARG(uap, flags);
164 SCARG(&bra, from) = NULL;
165 SCARG(&bra, fromlenaddr) = NULL;
166
167 return (sys_recvfrom(p, &bra, retval));
168 }
169
170 int
171 compat_43_sys_recvfrom(p, v, retval)
172 struct proc *p;
173 void *v;
174 register_t *retval;
175 {
176 struct sys_recvfrom_args /* {
177 syscallarg(int) s;
178 syscallarg(caddr_t) buf;
179 syscallarg(size_t) len;
180 syscallarg(int) flags;
181 syscallarg(caddr_t) from;
182 syscallarg(int *) fromlenaddr;
183 } */ *uap = v;
184
185 SCARG(uap, flags) |= MSG_COMPAT;
186 return (sys_recvfrom(p, uap, retval));
187 }
188
189 /*
190 * Old recvmsg. This code takes advantage of the fact that the old msghdr
191 * overlays the new one, missing only the flags, and with the (old) access
192 * rights where the control fields are now.
193 */
194 int
195 compat_43_sys_recvmsg(p, v, retval)
196 struct proc *p;
197 void *v;
198 register_t *retval;
199 {
200 struct compat_43_sys_recvmsg_args /* {
201 syscallarg(int) s;
202 syscallarg(struct omsghdr *) msg;
203 syscallarg(int) flags;
204 } */ *uap = v;
205 struct msghdr msg;
206 struct iovec aiov[UIO_SMALLIOV], *iov;
207 int error;
208
209 error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
210 sizeof (struct omsghdr));
211 if (error)
212 return (error);
213 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
214 if ((u_int)msg.msg_iovlen > IOV_MAX)
215 return (EMSGSIZE);
216 MALLOC(iov, struct iovec *,
217 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
218 M_WAITOK);
219 } else
220 iov = aiov;
221 msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
222 error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
223 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
224 if (error)
225 goto done;
226 msg.msg_iov = iov;
227 error = recvit(p, SCARG(uap, s), &msg,
228 (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
229
230 if (msg.msg_controllen && error == 0)
231 error = copyout((caddr_t)&msg.msg_controllen,
232 (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
233 done:
234 if (iov != aiov)
235 FREE(iov, M_IOV);
236 return (error);
237 }
238
239 int
240 compat_43_sys_send(p, v, retval)
241 struct proc *p;
242 void *v;
243 register_t *retval;
244 {
245 struct compat_43_sys_send_args /* {
246 syscallarg(int) s;
247 syscallarg(caddr_t) buf;
248 syscallarg(int) len;
249 syscallarg(int) flags;
250 } */ *uap = v;
251 struct sys_sendto_args bsa;
252
253 SCARG(&bsa, s) = SCARG(uap, s);
254 SCARG(&bsa, buf) = SCARG(uap, buf);
255 SCARG(&bsa, len) = SCARG(uap, len);
256 SCARG(&bsa, flags) = SCARG(uap, flags);
257 SCARG(&bsa, to) = NULL;
258 SCARG(&bsa, tolen) = 0;
259
260 return (sys_sendto(p, &bsa, retval));
261 }
262
263 int
264 compat_43_sys_sendmsg(p, v, retval)
265 struct proc *p;
266 void *v;
267 register_t *retval;
268 {
269 struct compat_43_sys_sendmsg_args /* {
270 syscallarg(int) s;
271 syscallarg(caddr_t) msg;
272 syscallarg(int) flags;
273 } */ *uap = v;
274 struct msghdr msg;
275 struct iovec aiov[UIO_SMALLIOV], *iov;
276 int error;
277
278 error = copyin(SCARG(uap, msg), (caddr_t)&msg,
279 sizeof (struct omsghdr));
280 if (error)
281 return (error);
282 if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
283 if ((u_int)msg.msg_iovlen > IOV_MAX)
284 return (EMSGSIZE);
285 MALLOC(iov, struct iovec *,
286 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
287 M_WAITOK);
288 } else
289 iov = aiov;
290 error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
291 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
292 if (error)
293 goto done;
294 msg.msg_flags = MSG_COMPAT;
295 msg.msg_iov = iov;
296 error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
297 done:
298 if (iov != aiov)
299 FREE(iov, M_IOV);
300 return (error);
301 }
302