Deleted Added
full compact
uipc_syscalls.c (109153) uipc_syscalls.c (109623)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * sendfile(2) and related extensions:
6 * Copyright (c) 1998, David Greenman. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * sendfile(2) and related extensions:
6 * Copyright (c) 1998, David Greenman. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
37 * $FreeBSD: head/sys/kern/uipc_syscalls.c 109153 2003-01-13 00:33:17Z dillon $
37 * $FreeBSD: head/sys/kern/uipc_syscalls.c 109623 2003-01-21 08:56:16Z alfred $
38 */
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42#include "opt_mac.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>

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

643 error = sockargs(&control, mp->msg_control,
644 mp->msg_controllen, MT_CONTROL);
645 if (error)
646 goto bad;
647#ifdef COMPAT_OLDSOCK
648 if (mp->msg_flags == MSG_COMPAT) {
649 register struct cmsghdr *cm;
650
38 */
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42#include "opt_mac.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>

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

643 error = sockargs(&control, mp->msg_control,
644 mp->msg_controllen, MT_CONTROL);
645 if (error)
646 goto bad;
647#ifdef COMPAT_OLDSOCK
648 if (mp->msg_flags == MSG_COMPAT) {
649 register struct cmsghdr *cm;
650
651 M_PREPEND(control, sizeof(*cm), M_TRYWAIT);
651 M_PREPEND(control, sizeof(*cm), 0);
652 if (control == 0) {
653 error = ENOBUFS;
654 goto bad;
655 } else {
656 cm = mtod(control, struct cmsghdr *);
657 cm->cmsg_len = control->m_len;
658 cm->cmsg_level = SOL_SOCKET;
659 cm->cmsg_type = SCM_RIGHTS;
660 }
661 }
662#endif
663 } else {
664 control = 0;
665 }
666#ifdef KTRACE
667 if (KTRPOINT(td, KTR_GENIO)) {
668 iovlen = auio.uio_iovcnt * sizeof (struct iovec);
652 if (control == 0) {
653 error = ENOBUFS;
654 goto bad;
655 } else {
656 cm = mtod(control, struct cmsghdr *);
657 cm->cmsg_len = control->m_len;
658 cm->cmsg_level = SOL_SOCKET;
659 cm->cmsg_type = SCM_RIGHTS;
660 }
661 }
662#endif
663 } else {
664 control = 0;
665 }
666#ifdef KTRACE
667 if (KTRPOINT(td, KTR_GENIO)) {
668 iovlen = auio.uio_iovcnt * sizeof (struct iovec);
669 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
669 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, 0);
670 bcopy(auio.uio_iov, ktriov, iovlen);
671 ktruio = auio;
672 }
673#endif
674 len = auio.uio_resid;
675 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
676 flags, td);
677 if (error) {

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

793 goto done2;
794 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
795 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
796 error = EMSGSIZE;
797 goto done2;
798 }
799 MALLOC(iov, struct iovec *,
800 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
670 bcopy(auio.uio_iov, ktriov, iovlen);
671 ktruio = auio;
672 }
673#endif
674 len = auio.uio_resid;
675 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
676 flags, td);
677 if (error) {

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

793 goto done2;
794 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
795 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
796 error = EMSGSIZE;
797 goto done2;
798 }
799 MALLOC(iov, struct iovec *,
800 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
801 M_WAITOK);
801 0);
802 } else {
803 iov = aiov;
804 }
805 error = copyin(msg.msg_iov, iov,
806 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
807 if (error)
808 goto done;
809 msg.msg_flags = MSG_COMPAT;

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

840 goto done2;
841 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
842 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
843 error = EMSGSIZE;
844 goto done2;
845 }
846 MALLOC(iov, struct iovec *,
847 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
802 } else {
803 iov = aiov;
804 }
805 error = copyin(msg.msg_iov, iov,
806 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
807 if (error)
808 goto done;
809 msg.msg_flags = MSG_COMPAT;

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

840 goto done2;
841 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
842 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
843 error = EMSGSIZE;
844 goto done2;
845 }
846 MALLOC(iov, struct iovec *,
847 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
848 M_WAITOK);
848 0);
849 } else {
850 iov = aiov;
851 }
852 if (msg.msg_iovlen &&
853 (error = copyin(msg.msg_iov, iov,
854 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))))
855 goto done;
856 msg.msg_iov = iov;

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

910 if ((auio.uio_resid += iov->iov_len) < 0) {
911 fputsock(so);
912 return (EINVAL);
913 }
914 }
915#ifdef KTRACE
916 if (KTRPOINT(td, KTR_GENIO)) {
917 iovlen = auio.uio_iovcnt * sizeof (struct iovec);
849 } else {
850 iov = aiov;
851 }
852 if (msg.msg_iovlen &&
853 (error = copyin(msg.msg_iov, iov,
854 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))))
855 goto done;
856 msg.msg_iov = iov;

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

910 if ((auio.uio_resid += iov->iov_len) < 0) {
911 fputsock(so);
912 return (EINVAL);
913 }
914 }
915#ifdef KTRACE
916 if (KTRPOINT(td, KTR_GENIO)) {
917 iovlen = auio.uio_iovcnt * sizeof (struct iovec);
918 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
918 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, 0);
919 bcopy(auio.uio_iov, ktriov, iovlen);
920 ktruio = auio;
921 }
922#endif
923 len = auio.uio_resid;
924 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
925 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
926 &mp->msg_flags);

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

1143 mtx_lock(&Giant);
1144 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
1145 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
1146 error = EMSGSIZE;
1147 goto done2;
1148 }
1149 MALLOC(iov, struct iovec *,
1150 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
919 bcopy(auio.uio_iov, ktriov, iovlen);
920 ktruio = auio;
921 }
922#endif
923 len = auio.uio_resid;
924 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
925 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
926 &mp->msg_flags);

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

1143 mtx_lock(&Giant);
1144 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
1145 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
1146 error = EMSGSIZE;
1147 goto done2;
1148 }
1149 MALLOC(iov, struct iovec *,
1150 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1151 M_WAITOK);
1151 0);
1152 } else {
1153 iov = aiov;
1154 }
1155 msg.msg_flags = uap->flags | MSG_COMPAT;
1156 error = copyin(msg.msg_iov, iov,
1157 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
1158 if (error)
1159 goto done;

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

1194 goto done2;
1195 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
1196 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
1197 error = EMSGSIZE;
1198 goto done2;
1199 }
1200 MALLOC(iov, struct iovec *,
1201 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1152 } else {
1153 iov = aiov;
1154 }
1155 msg.msg_flags = uap->flags | MSG_COMPAT;
1156 error = copyin(msg.msg_iov, iov,
1157 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
1158 if (error)
1159 goto done;

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

1194 goto done2;
1195 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
1196 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) {
1197 error = EMSGSIZE;
1198 goto done2;
1199 }
1200 MALLOC(iov, struct iovec *,
1201 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
1202 M_WAITOK);
1202 0);
1203 } else {
1204 iov = aiov;
1205 }
1206#ifdef COMPAT_OLDSOCK
1207 msg.msg_flags = uap->flags &~ MSG_COMPAT;
1208#else
1209 msg.msg_flags = uap->flags;
1210#endif

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

1530 if ((u_int)buflen > MLEN) {
1531#ifdef COMPAT_OLDSOCK
1532 if (type == MT_SONAME && (u_int)buflen <= 112)
1533 buflen = MLEN; /* unix domain compat. hack */
1534 else
1535#endif
1536 return (EINVAL);
1537 }
1203 } else {
1204 iov = aiov;
1205 }
1206#ifdef COMPAT_OLDSOCK
1207 msg.msg_flags = uap->flags &~ MSG_COMPAT;
1208#else
1209 msg.msg_flags = uap->flags;
1210#endif

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

1530 if ((u_int)buflen > MLEN) {
1531#ifdef COMPAT_OLDSOCK
1532 if (type == MT_SONAME && (u_int)buflen <= 112)
1533 buflen = MLEN; /* unix domain compat. hack */
1534 else
1535#endif
1536 return (EINVAL);
1537 }
1538 m = m_get(M_TRYWAIT, type);
1538 m = m_get(0, type);
1539 if (m == NULL)
1540 return (ENOBUFS);
1541 m->m_len = buflen;
1542 error = copyin(buf, mtod(m, caddr_t), (u_int)buflen);
1543 if (error)
1544 (void) m_free(m);
1545 else {
1546 *mp = m;

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

1563 caddr_t uaddr;
1564 size_t len;
1565{
1566 struct sockaddr *sa;
1567 int error;
1568
1569 if (len > SOCK_MAXADDRLEN)
1570 return ENAMETOOLONG;
1539 if (m == NULL)
1540 return (ENOBUFS);
1541 m->m_len = buflen;
1542 error = copyin(buf, mtod(m, caddr_t), (u_int)buflen);
1543 if (error)
1544 (void) m_free(m);
1545 else {
1546 *mp = m;

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

1563 caddr_t uaddr;
1564 size_t len;
1565{
1566 struct sockaddr *sa;
1567 int error;
1568
1569 if (len > SOCK_MAXADDRLEN)
1570 return ENAMETOOLONG;
1571 MALLOC(sa, struct sockaddr *, len, M_SONAME, M_WAITOK);
1571 MALLOC(sa, struct sockaddr *, len, M_SONAME, 0);
1572 error = copyin(uaddr, sa, len);
1573 if (error) {
1574 FREE(sa, M_SONAME);
1575 } else {
1576#if defined(COMPAT_OLDSOCK) && BYTE_ORDER != BIG_ENDIAN
1577 if (sa->sa_family == 0 && sa->sa_len < AF_MAX)
1578 sa->sa_family = sa->sa_len;
1579#endif

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

1777 else
1778 hdtr_size += td->td_retval[0];
1779 }
1780 }
1781
1782 /*
1783 * Protect against multiple writers to the socket.
1784 */
1572 error = copyin(uaddr, sa, len);
1573 if (error) {
1574 FREE(sa, M_SONAME);
1575 } else {
1576#if defined(COMPAT_OLDSOCK) && BYTE_ORDER != BIG_ENDIAN
1577 if (sa->sa_family == 0 && sa->sa_len < AF_MAX)
1578 sa->sa_family = sa->sa_len;
1579#endif

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

1777 else
1778 hdtr_size += td->td_retval[0];
1779 }
1780 }
1781
1782 /*
1783 * Protect against multiple writers to the socket.
1784 */
1785 (void) sblock(&so->so_snd, M_WAITOK);
1785 (void) sblock(&so->so_snd, 0);
1786
1787 /*
1788 * Loop through the pages in the file, starting with the requested
1789 * offset. Get a file page (do I/O if necessary), map the file page
1790 * into an sf_buf, attach an mbuf header to the sf_buf, and queue
1791 * it on the socket.
1792 */
1793 for (off = uap->offset; ; off += xfsize, sbytes += xfsize) {

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

1921 * Allocate a kernel virtual page and insert the physical page
1922 * into it.
1923 */
1924 sf->m = pg;
1925 pmap_qenter(sf->kva, &pg, 1);
1926 /*
1927 * Get an mbuf header and set it up as having external storage.
1928 */
1786
1787 /*
1788 * Loop through the pages in the file, starting with the requested
1789 * offset. Get a file page (do I/O if necessary), map the file page
1790 * into an sf_buf, attach an mbuf header to the sf_buf, and queue
1791 * it on the socket.
1792 */
1793 for (off = uap->offset; ; off += xfsize, sbytes += xfsize) {

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

1921 * Allocate a kernel virtual page and insert the physical page
1922 * into it.
1923 */
1924 sf->m = pg;
1925 pmap_qenter(sf->kva, &pg, 1);
1926 /*
1927 * Get an mbuf header and set it up as having external storage.
1928 */
1929 MGETHDR(m, M_TRYWAIT, MT_DATA);
1929 MGETHDR(m, 0, MT_DATA);
1930 if (m == NULL) {
1931 error = ENOBUFS;
1932 sf_buf_free((void *)sf->kva, NULL);
1933 sbunlock(&so->so_snd);
1934 goto done;
1935 }
1936 /*
1937 * Setup external storage for mbuf.

--- 105 unchanged lines hidden ---
1930 if (m == NULL) {
1931 error = ENOBUFS;
1932 sf_buf_free((void *)sf->kva, NULL);
1933 sbunlock(&so->so_snd);
1934 goto done;
1935 }
1936 /*
1937 * Setup external storage for mbuf.

--- 105 unchanged lines hidden ---