Deleted Added
full compact
svr4_stream.c (83366) svr4_stream.c (86487)
1/*
2 * Copyright (c) 1998 Mark Newton. All rights reserved.
3 * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
1/*
2 * Copyright (c) 1998 Mark Newton. All rights reserved.
3 * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $FreeBSD: head/sys/compat/svr4/svr4_stream.c 83366 2001-09-12 08:38:13Z julian $
30 * $FreeBSD: head/sys/compat/svr4/svr4_stream.c 86487 2001-11-17 03:07:11Z dillon $
31 */
32
33/*
34 * Pretend that we have streams...
35 * Yes, this is gross.
36 *
37 * ToDo: The state machine for getmsg needs re-thinking
38 */

--- 106 unchanged lines hidden (view full) ---

145 */
146static int
147svr4_sendit(td, s, mp, flags)
148 register struct thread *td;
149 int s;
150 register struct msghdr *mp;
151 int flags;
152{
31 */
32
33/*
34 * Pretend that we have streams...
35 * Yes, this is gross.
36 *
37 * ToDo: The state machine for getmsg needs re-thinking
38 */

--- 106 unchanged lines hidden (view full) ---

145 */
146static int
147svr4_sendit(td, s, mp, flags)
148 register struct thread *td;
149 int s;
150 register struct msghdr *mp;
151 int flags;
152{
153 struct file *fp;
154 struct uio auio;
155 register struct iovec *iov;
156 register int i;
157 struct mbuf *control;
158 struct sockaddr *to;
159 int len, error;
160 struct socket *so;
161#ifdef KTRACE
162 struct iovec *ktriov = NULL;
163 struct uio ktruio;
164#endif
165
153 struct uio auio;
154 register struct iovec *iov;
155 register int i;
156 struct mbuf *control;
157 struct sockaddr *to;
158 int len, error;
159 struct socket *so;
160#ifdef KTRACE
161 struct iovec *ktriov = NULL;
162 struct uio ktruio;
163#endif
164
166 error = holdsock(td->td_proc->p_fd, s, &fp);
167 if (error)
165 if ((error = fgetsock(td, s, &so, NULL)) != 0)
168 return (error);
169 auio.uio_iov = mp->msg_iov;
170 auio.uio_iovcnt = mp->msg_iovlen;
171 auio.uio_segflg = UIO_USERSPACE;
172 auio.uio_rw = UIO_WRITE;
173 auio.uio_td = td;
174 auio.uio_offset = 0; /* XXX */
175 auio.uio_resid = 0;
176 iov = mp->msg_iov;
177 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
178 if ((auio.uio_resid += iov->iov_len) < 0) {
166 return (error);
167 auio.uio_iov = mp->msg_iov;
168 auio.uio_iovcnt = mp->msg_iovlen;
169 auio.uio_segflg = UIO_USERSPACE;
170 auio.uio_rw = UIO_WRITE;
171 auio.uio_td = td;
172 auio.uio_offset = 0; /* XXX */
173 auio.uio_resid = 0;
174 iov = mp->msg_iov;
175 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
176 if ((auio.uio_resid += iov->iov_len) < 0) {
179 fdrop(fp, td);
180 return (EINVAL);
177 error = EINVAL;
178 goto done1;
181 }
182 }
183 if (mp->msg_name) {
184 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
179 }
180 }
181 if (mp->msg_name) {
182 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
185 if (error) {
186 fdrop(fp, td);
187 return (error);
188 }
183 if (error)
184 goto done1;
189 } else {
190 to = 0;
191 }
192 if (mp->msg_control) {
193 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
194 error = EINVAL;
195 goto bad;
196 }

--- 9 unchanged lines hidden (view full) ---

206 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
207
208 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
209 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
210 ktruio = auio;
211 }
212#endif
213 len = auio.uio_resid;
185 } else {
186 to = 0;
187 }
188 if (mp->msg_control) {
189 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
190 error = EINVAL;
191 goto bad;
192 }

--- 9 unchanged lines hidden (view full) ---

202 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
203
204 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
205 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
206 ktruio = auio;
207 }
208#endif
209 len = auio.uio_resid;
214 so = (struct socket *)fp->f_data;
215 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
216 flags, td);
217 if (error) {
218 if (auio.uio_resid != len && (error == ERESTART ||
219 error == EINTR || error == EWOULDBLOCK))
220 error = 0;
221 if (error == EPIPE) {
222 PROC_LOCK(td->td_proc);

--- 11 unchanged lines hidden (view full) ---

234 ktrgenio(td->td_proc->p_tracep, s, UIO_WRITE, &ktruio, error);
235 }
236 FREE(ktriov, M_TEMP);
237 }
238#endif
239bad:
240 if (to)
241 FREE(to, M_SONAME);
210 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
211 flags, td);
212 if (error) {
213 if (auio.uio_resid != len && (error == ERESTART ||
214 error == EINTR || error == EWOULDBLOCK))
215 error = 0;
216 if (error == EPIPE) {
217 PROC_LOCK(td->td_proc);

--- 11 unchanged lines hidden (view full) ---

229 ktrgenio(td->td_proc->p_tracep, s, UIO_WRITE, &ktruio, error);
230 }
231 FREE(ktriov, M_TEMP);
232 }
233#endif
234bad:
235 if (to)
236 FREE(to, M_SONAME);
242 fdrop(fp, td);
237done1:
238 fputsock(so);
243 return (error);
244}
245
246static int
247svr4_recvit(td, s, mp, namelenp)
248 register struct thread *td;
249 int s;
250 register struct msghdr *mp;
251 caddr_t namelenp;
252{
239 return (error);
240}
241
242static int
243svr4_recvit(td, s, mp, namelenp)
244 register struct thread *td;
245 int s;
246 register struct msghdr *mp;
247 caddr_t namelenp;
248{
253 struct file *fp;
254 struct uio auio;
255 register struct iovec *iov;
256 register int i;
257 int len, error;
258 struct mbuf *m, *control = 0;
259 caddr_t ctlbuf;
260 struct socket *so;
261 struct sockaddr *fromsa = 0;
262#ifdef KTRACE
263 struct iovec *ktriov = NULL;
264 struct uio ktruio;
265#endif
266
249 struct uio auio;
250 register struct iovec *iov;
251 register int i;
252 int len, error;
253 struct mbuf *m, *control = 0;
254 caddr_t ctlbuf;
255 struct socket *so;
256 struct sockaddr *fromsa = 0;
257#ifdef KTRACE
258 struct iovec *ktriov = NULL;
259 struct uio ktruio;
260#endif
261
267 error = holdsock(td->td_proc->p_fd, s, &fp);
268 if (error)
262 if ((error = fgetsock(td, s, &so, NULL)) != 0)
269 return (error);
270 auio.uio_iov = mp->msg_iov;
271 auio.uio_iovcnt = mp->msg_iovlen;
272 auio.uio_segflg = UIO_USERSPACE;
273 auio.uio_rw = UIO_READ;
274 auio.uio_td = td;
275 auio.uio_offset = 0; /* XXX */
276 auio.uio_resid = 0;
277 iov = mp->msg_iov;
278 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
279 if ((auio.uio_resid += iov->iov_len) < 0) {
263 return (error);
264 auio.uio_iov = mp->msg_iov;
265 auio.uio_iovcnt = mp->msg_iovlen;
266 auio.uio_segflg = UIO_USERSPACE;
267 auio.uio_rw = UIO_READ;
268 auio.uio_td = td;
269 auio.uio_offset = 0; /* XXX */
270 auio.uio_resid = 0;
271 iov = mp->msg_iov;
272 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
273 if ((auio.uio_resid += iov->iov_len) < 0) {
280 fdrop(fp, td);
281 return (EINVAL);
274 error = EINVAL;
275 goto done1;
282 }
283 }
284#ifdef KTRACE
285 if (KTRPOINT(td->td_proc, KTR_GENIO)) {
286 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
287
288 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
289 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
290 ktruio = auio;
291 }
292#endif
293 len = auio.uio_resid;
276 }
277 }
278#ifdef KTRACE
279 if (KTRPOINT(td->td_proc, KTR_GENIO)) {
280 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
281
282 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
283 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
284 ktruio = auio;
285 }
286#endif
287 len = auio.uio_resid;
294 so = (struct socket *)fp->f_data;
295 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
296 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
297 &mp->msg_flags);
298 if (error) {
299 if (auio.uio_resid != len && (error == ERESTART ||
300 error == EINTR || error == EWOULDBLOCK))
301 error = 0;
302 }

--- 57 unchanged lines hidden (view full) ---

360 }
361 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
362 }
363out:
364 if (fromsa)
365 FREE(fromsa, M_SONAME);
366 if (control)
367 m_freem(control);
288 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
289 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
290 &mp->msg_flags);
291 if (error) {
292 if (auio.uio_resid != len && (error == ERESTART ||
293 error == EINTR || error == EWOULDBLOCK))
294 error = 0;
295 }

--- 57 unchanged lines hidden (view full) ---

353 }
354 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
355 }
356out:
357 if (fromsa)
358 FREE(fromsa, M_SONAME);
359 if (control)
360 m_freem(control);
368 fdrop(fp, td);
361done1:
362 fputsock(so);
369 return (error);
370}
371
372#ifdef DEBUG_SVR4
373static void bufprint __P((u_char *, size_t));
374static int show_ioc __P((const char *, struct svr4_strioctl *));
375static int show_strbuf __P((struct svr4_strbuf *));
376static void show_msg __P((const char *, int, struct svr4_strbuf *,

--- 1903 unchanged lines hidden ---
363 return (error);
364}
365
366#ifdef DEBUG_SVR4
367static void bufprint __P((u_char *, size_t));
368static int show_ioc __P((const char *, struct svr4_strioctl *));
369static int show_strbuf __P((struct svr4_strbuf *));
370static void show_msg __P((const char *, int, struct svr4_strbuf *,

--- 1903 unchanged lines hidden ---