uipc_syscalls_43.c revision 1.1 1 /* $NetBSD: uipc_syscalls_43.c,v 1.1 1995/06/24 20:16:23 christos 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 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/filedesc.h>
41 #include <sys/kernel.h>
42 #include <sys/proc.h>
43 #include <sys/file.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <sys/stat.h>
47 #include <sys/ioctl.h>
48 #include <sys/fcntl.h>
49 #include <sys/malloc.h>
50 #include <sys/syslog.h>
51 #include <sys/unistd.h>
52 #include <sys/resourcevar.h>
53
54 #include <sys/mount.h>
55 #include <sys/syscallargs.h>
56
57 #define MSG_COMPAT 0x8000 /* XXX */
58
59 int
60 compat_43_accept(p, uap, retval)
61 struct proc *p;
62 struct accept_args /* {
63 syscallarg(int) s;
64 syscallarg(caddr_t) name;
65 syscallarg(int *) anamelen;
66 } */ *uap;
67 register_t *retval;
68 {
69 int error;
70
71 if ((error = accept(p, uap, retval)) != 0)
72 return error;
73
74 if (SCARG(uap, name)) {
75 struct sockaddr sa;
76
77 if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
78 return error;
79
80 ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
81
82 if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
83 return error;
84 }
85 return 0;
86 }
87
88
89 int
90 compat_43_getpeername(p, uap, retval)
91 struct proc *p;
92 struct getpeername_args /* {
93 syscallarg(int) fdes;
94 syscallarg(caddr_t) asa;
95 syscallarg(int *) alen;
96 } */ *uap;
97 register_t *retval;
98 {
99 struct sockaddr sa;
100
101 int error;
102
103 if ((error = getpeername(p, uap, retval)) != 0)
104 return error;
105
106 if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
107 return error;
108
109 ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
110
111 if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
112 return error;
113
114 return 0;
115 }
116
117
118 int
119 compat_43_getsockname(p, uap, retval)
120 struct proc *p;
121 struct getsockname_args /* {
122 syscallarg(int) fdes;
123 syscallarg(caddr_t) asa;
124 syscallarg(int *) alen;
125 } */ *uap;
126 register_t *retval;
127 {
128 struct sockaddr sa;
129 int error;
130
131 if ((error = getsockname(p, uap, retval)) != 0)
132 return error;
133
134 if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
135 return error;
136
137 ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
138
139 if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
140 return error;
141
142 return 0;
143 }
144
145
146 int
147 compat_43_recv(p, uap, retval)
148 struct proc *p;
149 register struct compat_43_recv_args /* {
150 syscallarg(int) s;
151 syscallarg(caddr_t) buf;
152 syscallarg(int) len;
153 syscallarg(int) flags;
154 } */ *uap;
155 register_t *retval;
156 {
157 struct msghdr msg;
158 struct iovec aiov;
159
160 msg.msg_name = 0;
161 msg.msg_namelen = 0;
162 msg.msg_iov = &aiov;
163 msg.msg_iovlen = 1;
164 aiov.iov_base = SCARG(uap, buf);
165 aiov.iov_len = SCARG(uap, len);
166 msg.msg_control = 0;
167 msg.msg_flags = SCARG(uap, flags);
168 return (recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval));
169 }
170
171
172 int
173 compat_43_recvfrom(p, uap, retval)
174 struct proc *p;
175 struct recvfrom_args /* {
176 syscallarg(int) s;
177 syscallarg(caddr_t) buf;
178 syscallarg(size_t) len;
179 syscallarg(int) flags;
180 syscallarg(caddr_t) from;
181 syscallarg(int *) fromlenaddr;
182 } */ *uap;
183 register_t *retval;
184 {
185
186 SCARG(uap, flags) |= MSG_COMPAT;
187 return (recvfrom(p, uap, retval));
188 }
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_recvmsg(p, uap, retval)
198 struct proc *p;
199 register struct compat_43_recvmsg_args /* {
200 syscallarg(int) s;
201 syscallarg(struct omsghdr *) msg;
202 syscallarg(int) flags;
203 } */ *uap;
204 register_t *retval;
205 {
206 struct msghdr msg;
207 struct iovec aiov[UIO_SMALLIOV], *iov;
208 int error;
209
210 if (error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
211 sizeof (struct omsghdr)))
212 return (error);
213 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
214 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
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 if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
223 (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
224 goto done;
225 msg.msg_iov = iov;
226 error = recvit(p, SCARG(uap, s), &msg,
227 (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
228
229 if (msg.msg_controllen && error == 0)
230 error = copyout((caddr_t)&msg.msg_controllen,
231 (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
232 done:
233 if (iov != aiov)
234 FREE(iov, M_IOV);
235 return (error);
236 }
237
238 int
239 compat_43_send(p, uap, retval)
240 struct proc *p;
241 register struct compat_43_send_args /* {
242 syscallarg(int) s;
243 syscallarg(caddr_t) buf;
244 syscallarg(int) len;
245 syscallarg(int) flags;
246 } */ *uap;
247 register_t *retval;
248 {
249 struct msghdr msg;
250 struct iovec aiov;
251
252 msg.msg_name = 0;
253 msg.msg_namelen = 0;
254 msg.msg_iov = &aiov;
255 msg.msg_iovlen = 1;
256 aiov.iov_base = SCARG(uap, buf);
257 aiov.iov_len = SCARG(uap, len);
258 msg.msg_control = 0;
259 msg.msg_flags = 0;
260 return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
261 }
262
263 int
264 compat_43_sendmsg(p, uap, retval)
265 struct proc *p;
266 register struct compat_43_sendmsg_args /* {
267 syscallarg(int) s;
268 syscallarg(caddr_t) msg;
269 syscallarg(int) flags;
270 } */ *uap;
271 register_t *retval;
272 {
273 struct msghdr msg;
274 struct iovec aiov[UIO_SMALLIOV], *iov;
275 int error;
276
277 if (error = copyin(SCARG(uap, msg), (caddr_t)&msg,
278 sizeof (struct omsghdr)))
279 return (error);
280 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
281 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
282 return (EMSGSIZE);
283 MALLOC(iov, struct iovec *,
284 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
285 M_WAITOK);
286 } else
287 iov = aiov;
288 if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
289 (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
290 goto done;
291 msg.msg_flags = MSG_COMPAT;
292 msg.msg_iov = iov;
293 error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
294 done:
295 if (iov != aiov)
296 FREE(iov, M_IOV);
297 return (error);
298 }
299