diff options
author | phk <phk@FreeBSD.org> | 2004-07-10 15:42:16 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-07-10 15:42:16 +0000 |
commit | b9f13e4266e1a358f8e0f5ee3542e657eabb8a19 (patch) | |
tree | de46976e3a829fc81580355aafed8ed3f3fcdb8e /sys/compat | |
parent | afe21b6175db45f3406c5cd8c0d1516078e4e32c (diff) | |
download | FreeBSD-src-b9f13e4266e1a358f8e0f5ee3542e657eabb8a19.zip FreeBSD-src-b9f13e4266e1a358f8e0f5ee3542e657eabb8a19.tar.gz |
Clean up and wash struct iovec and struct uio handling.
Add copyiniov() which copies a struct iovec array in from userland into
a malloc'ed struct iovec. Caller frees.
Change uiofromiov() to malloc the uio (caller frees) and name it
copyinuio() which is more appropriate.
Add cloneuio() which returns a malloc'ed copy. Caller frees.
Use them throughout.
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linux/linux_socket.c | 27 | ||||
-rw-r--r-- | sys/compat/svr4/svr4_stream.c | 44 |
2 files changed, 19 insertions, 52 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 465c573..c73a57a 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -993,35 +993,22 @@ linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args) { struct linux_sendmsg_args linux_args; struct msghdr msg; - struct iovec aiov[UIO_SMALLIOV], *iov; + struct iovec *iov; int error; - if ((error = copyin(args, &linux_args, sizeof(linux_args)))) + error = copyin(args, &linux_args, sizeof(linux_args)); + if (error) return (error); - error = copyin(linux_args.msg, &msg, sizeof(msg)); if (error) return (error); - if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { - if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) - return (EMSGSIZE); - MALLOC(iov, struct iovec *, - sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, - M_WAITOK); - } else { - iov = aiov; - } - if (msg.msg_iovlen && - (error = copyin(msg.msg_iov, iov, - (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))) - goto done; + error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE); + if (error) + return (error); msg.msg_iov = iov; msg.msg_flags = 0; - error = linux_sendit(td, linux_args.s, &msg, linux_args.flags); -done: - if (iov != aiov) - FREE(iov, M_IOV); + free(iov, M_IOV); return (error); } diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c index 853a272..d91c185 100644 --- a/sys/compat/svr4/svr4_stream.c +++ b/sys/compat/svr4/svr4_stream.c @@ -163,8 +163,7 @@ svr4_sendit(td, s, mp, flags) int len, error; struct socket *so; #ifdef KTRACE - struct iovec *ktriov = NULL; - struct uio ktruio; + struct uio *ktruio = NULL; #endif if ((error = fgetsock(td, s, &so, NULL)) != 0) @@ -212,13 +211,8 @@ svr4_sendit(td, s, mp, flags) control = 0; } #ifdef KTRACE - if (KTRPOINT(td, KTR_GENIO)) { - int iovlen = auio.uio_iovcnt * sizeof (struct iovec); - - MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); - bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); - ktruio = auio; - } + if (KTRPOINT(td, KTR_GENIO)) + ktruio = cloneuio(&auio); #endif len = auio.uio_resid; error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control, @@ -236,13 +230,9 @@ svr4_sendit(td, s, mp, flags) if (error == 0) td->td_retval[0] = len - auio.uio_resid; #ifdef KTRACE - if (ktriov != NULL) { - if (error == 0) { - ktruio.uio_iov = ktriov; - ktruio.uio_resid = td->td_retval[0]; - ktrgenio(s, UIO_WRITE, &ktruio, error); - } - FREE(ktriov, M_TEMP); + if (ktruio != NULL) { + ktruio->uio_resid = td->td_retval[0]; + ktrgenio(s, UIO_WRITE, ktruio, error); } #endif bad: @@ -269,8 +259,7 @@ svr4_recvit(td, s, mp, namelenp) struct socket *so; struct sockaddr *fromsa = 0; #ifdef KTRACE - struct iovec *ktriov = NULL; - struct uio ktruio; + struct uio *ktruio = NULL; #endif if ((error = fgetsock(td, s, &so, NULL)) != 0) @@ -299,13 +288,8 @@ svr4_recvit(td, s, mp, namelenp) } } #ifdef KTRACE - if (KTRPOINT(td, KTR_GENIO)) { - int iovlen = auio.uio_iovcnt * sizeof (struct iovec); - - MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); - bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); - ktruio = auio; - } + if (KTRPOINT(td, KTR_GENIO)) + ktruio = cloneuio(&auio); #endif len = auio.uio_resid; error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio, @@ -317,13 +301,9 @@ svr4_recvit(td, s, mp, namelenp) error = 0; } #ifdef KTRACE - if (ktriov != NULL) { - if (error == 0) { - ktruio.uio_iov = ktriov; - ktruio.uio_resid = len - auio.uio_resid; - ktrgenio(s, UIO_READ, &ktruio, error); - } - FREE(ktriov, M_TEMP); + if (ktruio != NULL) { + ktruio->uio_resid = len - auio.uio_resid; + ktrgenio(s, UIO_READ, ktruio, error); } #endif if (error) |