Module Name: src Committed By: rmind Date: Fri Apr 23 15:19:21 UTC 2010
Modified Files: src/sys/compat/netbsd32: netbsd32_compat_10.c netbsd32_compat_20.c netbsd32_compat_30.c netbsd32_compat_43.c netbsd32_compat_50.c netbsd32_event.c netbsd32_exec_aout.c netbsd32_fs.c netbsd32_ioctl.c netbsd32_netbsd.c netbsd32_select.c netbsd32_signal.c netbsd32_socket.c netbsd32_sysctl.c src/sys/compat/osf1: osf1_cvt.c osf1_descrip.c osf1_file.c osf1_generic.c osf1_misc.c osf1_signal.c osf1_socket.c src/sys/kern: uipc_syscalls.c src/sys/sys: uio.h Log Message: Replace M_IOV and some malloc(9)s with kmem(9), and while there: - Fix invalid free (M_TEMP vs M_IOV) in do_sys_recvmsg(), spotted by jakll...@. Also, same fix in osf1_sys_sendmsg_xopen(). - Fix attempt to free non-allocated memory in error path in netbsd32___getfh30(). - Plug a memory leak in compat_43_netbsd32_orecvmsg(). To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/compat/netbsd32/netbsd32_compat_10.c cvs rdiff -u -r1.27 -r1.28 src/sys/compat/netbsd32/netbsd32_compat_20.c cvs rdiff -u -r1.29 -r1.30 src/sys/compat/netbsd32/netbsd32_compat_30.c cvs rdiff -u -r1.51 -r1.52 src/sys/compat/netbsd32/netbsd32_compat_43.c cvs rdiff -u -r1.15 -r1.16 src/sys/compat/netbsd32/netbsd32_compat_50.c cvs rdiff -u -r1.7 -r1.8 src/sys/compat/netbsd32/netbsd32_event.c cvs rdiff -u -r1.24 -r1.25 src/sys/compat/netbsd32/netbsd32_exec_aout.c cvs rdiff -u -r1.58 -r1.59 src/sys/compat/netbsd32/netbsd32_fs.c cvs rdiff -u -r1.46 -r1.47 src/sys/compat/netbsd32/netbsd32_ioctl.c cvs rdiff -u -r1.166 -r1.167 src/sys/compat/netbsd32/netbsd32_netbsd.c cvs rdiff -u -r1.18 -r1.19 src/sys/compat/netbsd32/netbsd32_select.c cvs rdiff -u -r1.33 -r1.34 src/sys/compat/netbsd32/netbsd32_signal.c cvs rdiff -u -r1.36 -r1.37 src/sys/compat/netbsd32/netbsd32_socket.c cvs rdiff -u -r1.30 -r1.31 src/sys/compat/netbsd32/netbsd32_sysctl.c cvs rdiff -u -r1.26 -r1.27 src/sys/compat/osf1/osf1_cvt.c cvs rdiff -u -r1.28 -r1.29 src/sys/compat/osf1/osf1_descrip.c cvs rdiff -u -r1.38 -r1.39 src/sys/compat/osf1/osf1_file.c cvs rdiff -u -r1.16 -r1.17 src/sys/compat/osf1/osf1_generic.c cvs rdiff -u -r1.84 -r1.85 src/sys/compat/osf1/osf1_misc.c cvs rdiff -u -r1.35 -r1.36 src/sys/compat/osf1/osf1_signal.c cvs rdiff -u -r1.19 -r1.20 src/sys/compat/osf1/osf1_socket.c cvs rdiff -u -r1.140 -r1.141 src/sys/kern/uipc_syscalls.c cvs rdiff -u -r1.34 -r1.35 src/sys/sys/uio.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/netbsd32/netbsd32_compat_10.c diff -u src/sys/compat/netbsd32/netbsd32_compat_10.c:1.23 src/sys/compat/netbsd32/netbsd32_compat_10.c:1.24 --- src/sys/compat/netbsd32/netbsd32_compat_10.c:1.23 Sun Jan 11 02:45:49 2009 +++ src/sys/compat/netbsd32/netbsd32_compat_10.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_10.c,v 1.23 2009/01/11 02:45:49 christos Exp $ */ +/* $NetBSD: netbsd32_compat_10.c,v 1.24 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_10.c,v 1.23 2009/01/11 02:45:49 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_10.c,v 1.24 2010/04/23 15:19:20 rmind Exp $"); #ifdef _KERNEL_OPT #include "opt_sysv.h" @@ -42,7 +42,6 @@ #include <sys/kernel.h> #include <sys/proc.h> #include <sys/sem.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/syscallargs.h> Index: src/sys/compat/netbsd32/netbsd32_compat_20.c diff -u src/sys/compat/netbsd32/netbsd32_compat_20.c:1.27 src/sys/compat/netbsd32/netbsd32_compat_20.c:1.28 --- src/sys/compat/netbsd32/netbsd32_compat_20.c:1.27 Mon Jun 29 05:08:16 2009 +++ src/sys/compat/netbsd32/netbsd32_compat_20.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_20.c,v 1.27 2009/06/29 05:08:16 dholland Exp $ */ +/* $NetBSD: netbsd32_compat_20.c,v 1.28 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.27 2009/06/29 05:08:16 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.28 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/time.h> Index: src/sys/compat/netbsd32/netbsd32_compat_30.c diff -u src/sys/compat/netbsd32/netbsd32_compat_30.c:1.29 src/sys/compat/netbsd32/netbsd32_compat_30.c:1.30 --- src/sys/compat/netbsd32/netbsd32_compat_30.c:1.29 Mon Jan 26 13:00:04 2009 +++ src/sys/compat/netbsd32/netbsd32_compat_30.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_30.c,v 1.29 2009/01/26 13:00:04 njoly Exp $ */ +/* $NetBSD: netbsd32_compat_30.c,v 1.30 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.29 2009/01/26 13:00:04 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.30 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -79,13 +78,13 @@ error = EBADF; goto out; } - buf = malloc(count, M_TEMP, M_WAITOK); + buf = kmem_alloc(count, KM_SLEEP); error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0); if (error == 0) { *retval = netbsd32_to_dirent12(buf, done); error = copyout(buf, SCARG_P32(uap, buf), *retval); } - free(buf, M_TEMP); + kmem_free(buf, count); out: fd_putfile(SCARG(uap, fd)); return (error); @@ -210,10 +209,10 @@ SCARG(uap, flags)); if (error != 0) { - s32 = malloc(sizeof *s32, M_TEMP, M_WAITOK); + s32 = kmem_alloc(sizeof(*s32), KM_SLEEP); netbsd32_from_statvfs(sbuf, s32); error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32); - free(s32, M_TEMP); + kmem_free(s32, sizeof(*s32)); } STATVFSBUF_PUT(sbuf); Index: src/sys/compat/netbsd32/netbsd32_compat_43.c diff -u src/sys/compat/netbsd32/netbsd32_compat_43.c:1.51 src/sys/compat/netbsd32/netbsd32_compat_43.c:1.52 --- src/sys/compat/netbsd32/netbsd32_compat_43.c:1.51 Fri Jan 30 13:01:36 2009 +++ src/sys/compat/netbsd32/netbsd32_compat_43.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_43.c,v 1.51 2009/01/30 13:01:36 njoly Exp $ */ +/* $NetBSD: netbsd32_compat_43.c,v 1.52 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_43.c,v 1.51 2009/01/30 13:01:36 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_43.c,v 1.52 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_43.h" @@ -37,7 +37,6 @@ #include <sys/systm.h> #include <sys/fcntl.h> #include <sys/filedesc.h> -#include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/mount.h> #include <sys/namei.h> @@ -456,7 +455,7 @@ NETBSD32PTR64(omsg.msg_accrights) != NULL ? &control : NULL, retval); if (error != 0) - return error; + goto out; /* * If there is any control information and it's SCM_RIGHTS, @@ -493,7 +492,10 @@ if (error != 0) error = copyout(&omsg, SCARG_P32(uap, msg), sizeof(omsg)); - +out: + if (iov != aiov) { + kmem_free(iov, omsg.msg_iovlen * sizeof(struct iov)); + } return error; } @@ -508,10 +510,10 @@ struct iovec *iov, aiov[UIO_SMALLIOV]; struct netbsd32_omsghdr omsg; struct msghdr msg; - int error; struct mbuf *nam; struct osockaddr *osa; struct sockaddr *sa; + int error; error = copyin(SCARG_P32(uap, msg), &omsg, sizeof (struct omsghdr)); if (error != 0) @@ -549,7 +551,7 @@ out: if (iov != aiov) - free(iov, M_TEMP); + kmem_free(iov, omsg.msg_iovlen * sizeof(struct iov)); return (error); } Index: src/sys/compat/netbsd32/netbsd32_compat_50.c diff -u src/sys/compat/netbsd32/netbsd32_compat_50.c:1.15 src/sys/compat/netbsd32/netbsd32_compat_50.c:1.16 --- src/sys/compat/netbsd32/netbsd32_compat_50.c:1.15 Thu Apr 8 11:51:14 2010 +++ src/sys/compat/netbsd32/netbsd32_compat_50.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_50.c,v 1.15 2010/04/08 11:51:14 njoly Exp $ */ +/* $NetBSD: netbsd32_compat_50.c,v 1.16 2010/04/23 15:19:20 rmind Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.15 2010/04/08 11:51:14 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.16 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_sysv.h" @@ -44,7 +44,6 @@ #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -630,17 +629,16 @@ nevents = SCARG(uap, nevents); maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents)); netbsd32_kevent_ops.keo_private = - malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP, - M_WAITOK); + kmem_alloc(maxalloc * sizeof(struct netbsd32_kevent), KM_SLEEP); error = kevent1(retval, SCARG(uap, fd), NETBSD32PTR64(SCARG(uap, changelist)), nchanges, NETBSD32PTR64(SCARG(uap, eventlist)), nevents, NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops); - free(netbsd32_kevent_ops.keo_private, M_TEMP); + kmem_free(netbsd32_kevent_ops.keo_private, + maxalloc * sizeof(struct netbsd32_kevent)); return error; - return 0; } int Index: src/sys/compat/netbsd32/netbsd32_event.c diff -u src/sys/compat/netbsd32/netbsd32_event.c:1.7 src/sys/compat/netbsd32/netbsd32_event.c:1.8 --- src/sys/compat/netbsd32/netbsd32_event.c:1.7 Sun Jan 11 02:45:49 2009 +++ src/sys/compat/netbsd32/netbsd32_event.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_event.c,v 1.7 2009/01/11 02:45:49 christos Exp $ */ +/* $NetBSD: netbsd32_event.c,v 1.8 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_event.c,v 1.7 2009/01/11 02:45:49 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_event.c,v 1.8 2010/04/23 15:19:20 rmind Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -37,7 +37,6 @@ #include <sys/select.h> #include <sys/event.h> #include <sys/eventvar.h> -#include <sys/malloc.h> #include <sys/proc.h> #include <sys/dirent.h> @@ -115,14 +114,14 @@ nevents = SCARG(uap, nevents); maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents)); netbsd32_kevent_ops.keo_private = - malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP, - M_WAITOK); + kmem_alloc(maxalloc * sizeof(struct netbsd32_kevent), KM_SLEEP); error = kevent1(retval, SCARG(uap, fd), NETBSD32PTR64(SCARG(uap, changelist)), nchanges, NETBSD32PTR64(SCARG(uap, eventlist)), nevents, NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops); - free(netbsd32_kevent_ops.keo_private, M_TEMP); + kmem_free(netbsd32_kevent_ops.keo_private, + maxalloc * sizeof(struct netbsd32_kevent)); return error; } Index: src/sys/compat/netbsd32/netbsd32_exec_aout.c diff -u src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.24 src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.25 --- src/sys/compat/netbsd32/netbsd32_exec_aout.c:1.24 Thu May 29 14:51:26 2008 +++ src/sys/compat/netbsd32/netbsd32_exec_aout.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_exec_aout.c,v 1.24 2008/05/29 14:51:26 mrg Exp $ */ +/* $NetBSD: netbsd32_exec_aout.c,v 1.25 2010/04/23 15:19:20 rmind Exp $ */ /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ /* @@ -57,12 +57,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_aout.c,v 1.24 2008/05/29 14:51:26 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_aout.c,v 1.25 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/proc.h> -#include <sys/malloc.h> #include <sys/vnode.h> #include <sys/exec.h> #include <sys/exec_aout.h> Index: src/sys/compat/netbsd32/netbsd32_fs.c diff -u src/sys/compat/netbsd32/netbsd32_fs.c:1.58 src/sys/compat/netbsd32/netbsd32_fs.c:1.59 --- src/sys/compat/netbsd32/netbsd32_fs.c:1.58 Mon Dec 14 00:47:11 2009 +++ src/sys/compat/netbsd32/netbsd32_fs.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_fs.c,v 1.58 2009/12/14 00:47:11 matt Exp $ */ +/* $NetBSD: netbsd32_fs.c,v 1.59 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.58 2009/12/14 00:47:11 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.59 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -79,7 +78,7 @@ return NULL; if (iovlen > aiov_len) - iov = malloc(iovlen * sizeof (*iov), M_TEMP, M_WAITOK); + iov = kmem_alloc(iovlen * sizeof(*iov), KM_SLEEP); iovp = iov; for (i = 0; i < iovlen; iov32 += N_IOV32, i += N_IOV32) { @@ -89,7 +88,7 @@ error = copyin(iov32, aiov32, n * sizeof (*iov32)); if (error != 0) { if (iov != aiov) - free(iov, M_TEMP); + kmem_free(iov, iovlen * sizeof(*iov)); return NULL; } for (j = 0; j < n; iovp++, j++) { @@ -144,7 +143,7 @@ error = EINVAL; goto out; } - iov = malloc(iovlen, M_IOV, M_WAITOK); + iov = kmem_alloc(iovlen, KM_SLEEP); needfree = iov; } else if ((u_int)iovcnt > 0) { iov = aiov; @@ -180,7 +179,7 @@ * if tracing, save a copy of iovec */ if (ktrpoint(KTR_GENIO)) { - ktriov = malloc(iovlen, M_TEMP, M_WAITOK); + ktriov = kmem_alloc(iovlen, KM_SLEEP); memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen); } @@ -194,13 +193,13 @@ if (ktriov != NULL) { ktrgeniov(fd, UIO_READ, ktriov, cnt, error); - free(ktriov, M_TEMP); + kmem_free(ktriov, iovlen); } *retval = cnt; done: if (needfree) - free(needfree, M_IOV); + kmem_free(needfree, iovlen); out: fd_putfile(fd); return (error); @@ -248,7 +247,7 @@ error = EINVAL; goto out; } - iov = malloc(iovlen, M_IOV, M_WAITOK); + iov = kmem_alloc(iovlen, KM_SLEEP); needfree = iov; } else if ((u_int)iovcnt > 0) { iov = aiov; @@ -284,7 +283,7 @@ * if tracing, save a copy of iovec */ if (ktrpoint(KTR_GENIO)) { - ktriov = malloc(iovlen, M_TEMP, M_WAITOK); + ktriov = kmem_alloc(iovlen, KM_SLEEP); memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen); } @@ -303,12 +302,12 @@ cnt -= auio.uio_resid; if (ktriov != NULL) { ktrgenio(fd, UIO_WRITE, ktriov, cnt, error); - free(ktriov, M_TEMP); + kmem_free(ktriov, iovlen); } *retval = cnt; done: if (needfree) - free(needfree, M_IOV); + kmem_free(needfree, iovlen); out: fd_putfile(fd); return (error); @@ -363,10 +362,10 @@ struct netbsd32_statvfs *sbuf_32; int error; - sbuf_32 = malloc(sizeof *sbuf_32, M_TEMP, M_WAITOK); + sbuf_32 = kmem_alloc(sizeof(*sbuf_32), KM_SLEEP); netbsd32_from_statvfs(kp, sbuf_32); error = copyout(sbuf_32, up, sizeof(*sbuf_32)); - free(sbuf_32, M_TEMP); + kmem_free(sbuf_32, sizeof(*sbuf_32)); return error; } @@ -723,7 +722,7 @@ else if (len < 2) return ERANGE; - path = (char *)malloc(len, M_TEMP, M_WAITOK); + path = kmem_alloc(len, KM_SLEEP); if (!path) return ENOMEM; @@ -751,7 +750,7 @@ error = copyout(bp, SCARG_P32(uap, bufp), lenused); out: - free(path, M_TEMP); + kmem_free(path, len); return error; } Index: src/sys/compat/netbsd32/netbsd32_ioctl.c diff -u src/sys/compat/netbsd32/netbsd32_ioctl.c:1.46 src/sys/compat/netbsd32/netbsd32_ioctl.c:1.47 --- src/sys/compat/netbsd32/netbsd32_ioctl.c:1.46 Fri Dec 11 11:14:34 2009 +++ src/sys/compat/netbsd32/netbsd32_ioctl.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_ioctl.c,v 1.46 2009/12/11 11:14:34 njoly Exp $ */ +/* $NetBSD: netbsd32_ioctl.c,v 1.47 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.46 2009/12/11 11:14:34 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.47 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -43,7 +43,6 @@ #include <sys/audioio.h> #include <sys/disklabel.h> #include <sys/dkio.h> -#include <sys/malloc.h> #include <sys/sockio.h> #include <sys/socket.h> #include <sys/ttycom.h> @@ -575,7 +574,7 @@ size32, error); } - /* if we malloced data, free it here */ + /* If we allocated data, free it here. */ if (memp32) kmem_free(memp32, (size_t)size32); if (memp) Index: src/sys/compat/netbsd32/netbsd32_netbsd.c diff -u src/sys/compat/netbsd32/netbsd32_netbsd.c:1.166 src/sys/compat/netbsd32/netbsd32_netbsd.c:1.167 --- src/sys/compat/netbsd32/netbsd32_netbsd.c:1.166 Tue Mar 2 21:09:21 2010 +++ src/sys/compat/netbsd32/netbsd32_netbsd.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_netbsd.c,v 1.166 2010/03/02 21:09:21 pooka Exp $ */ +/* $NetBSD: netbsd32_netbsd.c,v 1.167 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001, 2008 Matthew R. Green @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.166 2010/03/02 21:09:21 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.167 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -50,7 +50,6 @@ #include <sys/systm.h> #include <sys/kernel.h> //#define msg __msg /* Don't ask me! */ -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/sockio.h> @@ -1234,24 +1233,28 @@ vp = nd.ni_vp; error = copyin(SCARG_P32(uap, fh_size), &sz32, sizeof(netbsd32_size_t)); - if (!error) { - fh = malloc(sz32, M_TEMP, M_WAITOK); - if (fh == NULL) - return EINVAL; - sz = sz32; - error = vfs_composefh(vp, fh, &sz); - sz32 = sz; + if (error) { + vput(vp); + return error; } + fh = kmem_alloc(sz32, KM_SLEEP); + if (fh == NULL) + return EINVAL; + sz = sz32; + error = vfs_composefh(vp, fh, &sz); vput(vp); - if (error == E2BIG) - copyout(&sz, SCARG_P32(uap, fh_size), sizeof(size_t)); + if (error == 0) { - error = copyout(&sz32, SCARG_P32(uap, fh_size), + const netbsd32_size_t nsz32 = sz; + error = copyout(&nsz32, SCARG_P32(uap, fh_size), sizeof(netbsd32_size_t)); - if (!error) + if (!error) { error = copyout(fh, SCARG_P32(uap, fhp), sz); + } + } else if (error == E2BIG) { + error = copyout(&sz, SCARG_P32(uap, fh_size), sizeof(size_t)); } - free(fh, M_TEMP); + kmem_free(fh, sz32); return (error); } Index: src/sys/compat/netbsd32/netbsd32_select.c diff -u src/sys/compat/netbsd32/netbsd32_select.c:1.18 src/sys/compat/netbsd32/netbsd32_select.c:1.19 --- src/sys/compat/netbsd32/netbsd32_select.c:1.18 Wed Nov 11 09:48:51 2009 +++ src/sys/compat/netbsd32/netbsd32_select.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_select.c,v 1.18 2009/11/11 09:48:51 rmind Exp $ */ +/* $NetBSD: netbsd32_select.c,v 1.19 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_select.c,v 1.18 2009/11/11 09:48:51 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_select.c,v 1.19 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/time.h> #include <sys/vnode.h> Index: src/sys/compat/netbsd32/netbsd32_signal.c diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.33 src/sys/compat/netbsd32/netbsd32_signal.c:1.34 --- src/sys/compat/netbsd32/netbsd32_signal.c:1.33 Tue Jan 19 23:15:50 2010 +++ src/sys/compat/netbsd32/netbsd32_signal.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_signal.c,v 1.33 2010/01/19 23:15:50 pooka Exp $ */ +/* $NetBSD: netbsd32_signal.c,v 1.34 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.33 2010/01/19 23:15:50 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.34 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/time.h> Index: src/sys/compat/netbsd32/netbsd32_socket.c diff -u src/sys/compat/netbsd32/netbsd32_socket.c:1.36 src/sys/compat/netbsd32/netbsd32_socket.c:1.37 --- src/sys/compat/netbsd32/netbsd32_socket.c:1.36 Wed Jul 22 17:19:44 2009 +++ src/sys/compat/netbsd32/netbsd32_socket.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_socket.c,v 1.36 2009/07/22 17:19:44 njoly Exp $ */ +/* $NetBSD: netbsd32_socket.c,v 1.37 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,12 +27,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.36 2009/07/22 17:19:44 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_socket.c,v 1.37 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> #define msg __msg /* Don't ask me! */ -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/sockio.h> @@ -49,9 +48,12 @@ #include <compat/netbsd32/netbsd32_syscallargs.h> #include <compat/netbsd32/netbsd32_conv.h> -/* note that the netbsd32_msghdr's iov really points to a struct iovec, not a netbsd32_iovec. */ -static int recvit32(struct lwp *, int, struct netbsd32_msghdr *, struct iovec *, void *, - register_t *); +/* + * Note that the netbsd32_msghdr's iov really points to a struct iovec, + * not a netbsd32_iovec. + */ +static int recvit32(struct lwp *, int, struct netbsd32_msghdr *, + struct iovec *, void *, register_t *); int netbsd32_recvmsg(struct lwp *l, const struct netbsd32_recvmsg_args *uap, register_t *retval) @@ -64,18 +66,18 @@ struct netbsd32_msghdr msg; struct iovec aiov[UIO_SMALLIOV], *iov; struct netbsd32_iovec *iov32; + size_t iovsz; int error; error = copyin(SCARG_P32(uap, msg), &msg, sizeof(msg)); /* netbsd32_msghdr needs the iov pre-allocated */ if (error) return (error); + iovsz = msg.msg_iovlen * sizeof(struct iovec); if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) { if ((u_int)msg.msg_iovlen > IOV_MAX) return (EMSGSIZE); - iov = (struct iovec *)malloc( - sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, - M_WAITOK); + iov = kmem_alloc(iovsz, KM_SLEEP); } else iov = aiov; msg.msg_flags = SCARG(uap, flags); @@ -89,7 +91,7 @@ } done: if (iov != aiov) - free(iov, M_IOV); + kmem_free(iov, iovsz); return (error); } @@ -97,12 +99,11 @@ recvit32(struct lwp *l, int s, struct netbsd32_msghdr *mp, struct iovec *iov, void *namelenp, register_t *retsize) { struct uio auio; - int i, len, error, iovlen; struct mbuf *from = 0, *control = 0; struct socket *so; - struct proc *p; struct iovec *ktriov = NULL; - p = l->l_proc; + size_t len, iovsz; + int i, error; /* fd_getsock() will use the descriptor for us */ if ((error = fd_getsock(s, &so)) != 0) @@ -114,13 +115,6 @@ auio.uio_offset = 0; /* XXX */ auio.uio_resid = 0; for (i = 0; i < mp->msg_iovlen; i++, iov++) { -#if 0 - /* cannot happen iov_len is unsigned */ - if (iov->iov_len < 0) { - error = EINVAL; - goto out1; - } -#endif /* * Reads return ssize_t because -1 is returned on error. * Therefore we must restrict the length to SSIZE_MAX to @@ -133,10 +127,10 @@ } } + iovsz = mp->msg_iovlen * sizeof(struct iovec); if (ktrpoint(KTR_GENIO)) { - iovlen = auio.uio_iovcnt * sizeof(struct iovec); - ktriov = (struct iovec *)malloc(iovlen, M_TEMP, M_WAITOK); - memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen); + ktriov = kmem_alloc(iovsz, KM_SLEEP); + memcpy(ktriov, auio.uio_iov, iovsz); } len = auio.uio_resid; @@ -151,7 +145,7 @@ if (ktriov != NULL) { ktrgeniov(s, UIO_READ, ktriov, len - auio.uio_resid, error); - free(ktriov, M_TEMP); + kmem_free(ktriov, iovsz); } if (error) @@ -225,6 +219,7 @@ struct netbsd32_msghdr msg32; struct iovec aiov[UIO_SMALLIOV], *iov; struct netbsd32_iovec *iov32; + size_t iovsz; int error; error = copyin(SCARG_P32(uap, msg), &msg32, sizeof(msg32)); @@ -232,12 +227,11 @@ return (error); netbsd32_to_msghdr(&msg32, &msg); + iovsz = msg.msg_iovlen * sizeof(struct iovec); if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) { if ((u_int)msg.msg_iovlen > IOV_MAX) return (EMSGSIZE); - iov = (struct iovec *)malloc( - sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, - M_WAITOK); + iov = kmem_alloc(iovsz, KM_SLEEP); } else iov = aiov; @@ -253,7 +247,7 @@ error = do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval); done: if (iov != aiov) - free(iov, M_IOV); + kmem_free(iov, iovsz); return (error); } Index: src/sys/compat/netbsd32/netbsd32_sysctl.c diff -u src/sys/compat/netbsd32/netbsd32_sysctl.c:1.30 src/sys/compat/netbsd32/netbsd32_sysctl.c:1.31 --- src/sys/compat/netbsd32/netbsd32_sysctl.c:1.30 Sun Jan 11 02:45:49 2009 +++ src/sys/compat/netbsd32/netbsd32_sysctl.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_sysctl.c,v 1.30 2009/01/11 02:45:49 christos Exp $ */ +/* $NetBSD: netbsd32_sysctl.c,v 1.31 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.30 2009/01/11 02:45:49 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.31 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -41,7 +41,6 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/time.h> Index: src/sys/compat/osf1/osf1_cvt.c diff -u src/sys/compat/osf1/osf1_cvt.c:1.26 src/sys/compat/osf1/osf1_cvt.c:1.27 --- src/sys/compat/osf1/osf1_cvt.c:1.26 Sat Mar 14 21:04:18 2009 +++ src/sys/compat/osf1/osf1_cvt.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_cvt.c,v 1.26 2009/03/14 21:04:18 dsl Exp $ */ +/* $NetBSD: osf1_cvt.c,v 1.27 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_cvt.c,v 1.26 2009/03/14 21:04:18 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_cvt.c,v 1.27 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -68,7 +68,6 @@ #include <sys/stat.h> #include <sys/filedesc.h> #include <sys/kernel.h> -#include <sys/malloc.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/signal.h> Index: src/sys/compat/osf1/osf1_descrip.c diff -u src/sys/compat/osf1/osf1_descrip.c:1.28 src/sys/compat/osf1/osf1_descrip.c:1.29 --- src/sys/compat/osf1/osf1_descrip.c:1.28 Mon May 18 12:39:02 2009 +++ src/sys/compat/osf1/osf1_descrip.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_descrip.c,v 1.28 2009/05/18 12:39:02 njoly Exp $ */ +/* $NetBSD: osf1_descrip.c,v 1.29 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_descrip.c,v 1.28 2009/05/18 12:39:02 njoly Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_descrip.c,v 1.29 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -68,7 +68,6 @@ #include <sys/stat.h> #include <sys/filedesc.h> #include <sys/kernel.h> -#include <sys/malloc.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/signal.h> Index: src/sys/compat/osf1/osf1_file.c diff -u src/sys/compat/osf1/osf1_file.c:1.38 src/sys/compat/osf1/osf1_file.c:1.39 --- src/sys/compat/osf1/osf1_file.c:1.38 Wed Mar 3 08:20:38 2010 +++ src/sys/compat/osf1/osf1_file.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_file.c,v 1.38 2010/03/03 08:20:38 he Exp $ */ +/* $NetBSD: osf1_file.c,v 1.39 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_file.c,v 1.38 2010/03/03 08:20:38 he Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_file.c,v 1.39 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_syscall_debug.h" @@ -162,7 +162,7 @@ } buflen = min(MAXBSIZE, SCARG(uap, nbytes)); - buf = malloc(buflen, M_TEMP, M_WAITOK); + buf = kmem_alloc(buflen, KM_SLEEP); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); off = off1 = fp->f_offset; again: @@ -175,7 +175,7 @@ auio.uio_offset = off; UIO_SETUP_SYSSPACE(&auio); /* - * First we read into the malloc'ed buffer, then + * First we read into the allocated buffer, then * we massage it into user space, one record at a time. */ error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf, @@ -246,7 +246,7 @@ VOP_UNLOCK(vp, 0); if (cookiebuf) free(cookiebuf, M_TEMP); - free(buf, M_TEMP); + kmem_free(buf, buflen); if (SCARG(uap, basep) != NULL) error = copyout(&off1, SCARG(uap, basep), sizeof(long)); out1: Index: src/sys/compat/osf1/osf1_generic.c diff -u src/sys/compat/osf1/osf1_generic.c:1.16 src/sys/compat/osf1/osf1_generic.c:1.17 --- src/sys/compat/osf1/osf1_generic.c:1.16 Wed Nov 11 09:48:51 2009 +++ src/sys/compat/osf1/osf1_generic.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_generic.c,v 1.16 2009/11/11 09:48:51 rmind Exp $ */ +/* $NetBSD: osf1_generic.c,v 1.17 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_generic.c,v 1.16 2009/11/11 09:48:51 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_generic.c,v 1.17 2010/04/23 15:19:20 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -66,7 +66,6 @@ #include <sys/proc.h> #include <sys/file.h> #include <sys/stat.h> -#include <sys/malloc.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/select.h> @@ -82,10 +81,7 @@ * the other word of our iov_len is zero! */ -#if __GNUC_PREREQ__(3, 0) -__attribute ((noinline)) -#endif -static int +static int __noinline osf1_get_iov(struct osf1_iovec *uiov, unsigned int iovcnt, struct iovec **iovp) { struct iovec *iov = *iovp; @@ -96,7 +92,7 @@ return EINVAL; if (iovcnt > UIO_SMALLIOV) { - iov = malloc(iovcnt * sizeof *iov, M_IOV, M_WAITOK); + iov = kmem_alloc(iovcnt * sizeof(*iov), KM_SLEEP); *iovp = iov; /* Caller must free - even if we return an error */ } @@ -133,7 +129,7 @@ } if (niov != aiov) - free(niov, M_IOV); + kmem_free(niov, SCARG(uap, iovcnt) * sizeof(*niov)); return error; } @@ -153,7 +149,7 @@ } if (niov != aiov) - free(niov, M_IOV); + kmem_free(niov, SCARG(uap, iovcnt) * sizeof(*niov)); return error; } Index: src/sys/compat/osf1/osf1_misc.c diff -u src/sys/compat/osf1/osf1_misc.c:1.84 src/sys/compat/osf1/osf1_misc.c:1.85 --- src/sys/compat/osf1/osf1_misc.c:1.84 Mon Nov 23 00:46:07 2009 +++ src/sys/compat/osf1/osf1_misc.c Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_misc.c,v 1.84 2009/11/23 00:46:07 rmind Exp $ */ +/* $NetBSD: osf1_misc.c,v 1.85 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_misc.c,v 1.84 2009/11/23 00:46:07 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_misc.c,v 1.85 2010/04/23 15:19:20 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_syscall_debug.h" @@ -72,7 +72,6 @@ #include <sys/stat.h> #include <sys/filedesc.h> #include <sys/kernel.h> -#include <sys/malloc.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/signal.h> Index: src/sys/compat/osf1/osf1_signal.c diff -u src/sys/compat/osf1/osf1_signal.c:1.35 src/sys/compat/osf1/osf1_signal.c:1.36 --- src/sys/compat/osf1/osf1_signal.c:1.35 Thu Apr 24 18:39:23 2008 +++ src/sys/compat/osf1/osf1_signal.c Fri Apr 23 15:19:21 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_signal.c,v 1.35 2008/04/24 18:39:23 ad Exp $ */ +/* $NetBSD: osf1_signal.c,v 1.36 2010/04/23 15:19:21 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_signal.c,v 1.35 2008/04/24 18:39:23 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_signal.c,v 1.36 2010/04/23 15:19:21 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -43,7 +43,6 @@ #include <sys/kernel.h> #include <sys/signal.h> #include <sys/signalvar.h> -#include <sys/malloc.h> #include <sys/syscallargs.h> Index: src/sys/compat/osf1/osf1_socket.c diff -u src/sys/compat/osf1/osf1_socket.c:1.19 src/sys/compat/osf1/osf1_socket.c:1.20 --- src/sys/compat/osf1/osf1_socket.c:1.19 Thu Dec 20 23:03:03 2007 +++ src/sys/compat/osf1/osf1_socket.c Fri Apr 23 15:19:21 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: osf1_socket.c,v 1.19 2007/12/20 23:03:03 dsl Exp $ */ +/* $NetBSD: osf1_socket.c,v 1.20 2010/04/23 15:19:21 rmind Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -58,14 +58,13 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: osf1_socket.c,v 1.19 2007/12/20 23:03:03 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: osf1_socket.c,v 1.20 2010/04/23 15:19:21 rmind Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/namei.h> #include <sys/proc.h> #include <sys/file.h> -#include <sys/malloc.h> #include <sys/mount.h> #include <sys/syscallargs.h> #include <sys/socket.h> @@ -114,30 +113,26 @@ flags = emul_flags_translate(osf1_sendrecv_msg_flags_xtab, SCARG(uap, flags), &leftovers); if (leftovers != 0) -{ -printf("sendmsg flags leftover: 0x%lx\n", leftovers); return (EINVAL); -} iov_len = bsd_msghdr.msg_iovlen; if (iov_len > IOV_MAX) return EMSGSIZE; - bsd_iovec = malloc(iov_len * sizeof (struct iovec), M_IOV, M_WAITOK); + bsd_iovec = kmem_alloc(iov_len * sizeof(struct iovec), KM_SLEEP); bsd_msghdr.msg_iov = bsd_iovec; osf_iovec_ptr = osf_msghdr.msg_iov; for (i = 0; i < iov_len; i++) { error = copyin(&osf_iovec_ptr[i], &osf_iovec, sizeof osf_iovec); - if (error != 0) { - free(bsd_iovec, M_TEMP); - return (error); - } + if (error != 0) + goto err; bsd_iovec[i].iov_base = osf_iovec.iov_base; bsd_iovec[i].iov_len = osf_iovec.iov_len; } error = do_sys_sendmsg(l, SCARG(uap, s), &bsd_msghdr, flags, retval); - free(bsd_iovec, M_TEMP); +err: + kmem_free(bsd_iovec, iov_len * sizeof(struct iovec)); return error; } Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.140 src/sys/kern/uipc_syscalls.c:1.141 --- src/sys/kern/uipc_syscalls.c:1.140 Thu Jan 21 04:40:22 2010 +++ src/sys/kern/uipc_syscalls.c Fri Apr 23 15:19:19 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.140 2010/01/21 04:40:22 pgoyette Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.141 2010/04/23 15:19:19 rmind Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.140 2010/01/21 04:40:22 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.141 2010/04/23 15:19:19 rmind Exp $"); #include "opt_pipe.h" @@ -463,26 +463,19 @@ do_sys_sendmsg(struct lwp *l, int s, struct msghdr *mp, int flags, register_t *retsize) { - struct uio auio; - int i, len, error, iovlen; + struct iovec aiov[UIO_SMALLIOV], *iov = aiov, *tiov, *ktriov = NULL; struct mbuf *to, *control; struct socket *so; - struct iovec *tiov; - struct iovec aiov[UIO_SMALLIOV], *iov = aiov; - struct iovec *ktriov = NULL; + struct uio auio; + size_t len, iovsz; + int i, error; ktrkuser("msghdr", mp, sizeof *mp); - /* If the caller passed us stuff in mbufs, we must free them */ - if (mp->msg_flags & MSG_NAMEMBUF) - to = mp->msg_name; - else - to = NULL; - - if (mp->msg_flags & MSG_CONTROLMBUF) - control = mp->msg_control; - else - control = NULL; + /* If the caller passed us stuff in mbufs, we must free them. */ + to = (mp->msg_flags & MSG_NAMEMBUF) ? mp->msg_name : NULL; + control = (mp->msg_flags & MSG_CONTROLMBUF) ? mp->msg_control : NULL; + iovsz = mp->msg_iovlen * sizeof(struct iovec); if (mp->msg_flags & MSG_IOVUSRSPACE) { if ((unsigned int)mp->msg_iovlen > UIO_SMALLIOV) { @@ -490,12 +483,10 @@ error = EMSGSIZE; goto bad; } - iov = malloc(sizeof(struct iovec) * mp->msg_iovlen, - M_IOV, M_WAITOK); + iov = kmem_alloc(iovsz, KM_SLEEP); } if (mp->msg_iovlen != 0) { - error = copyin(mp->msg_iov, iov, - (size_t)(mp->msg_iovlen * sizeof(struct iovec))); + error = copyin(mp->msg_iov, iov, iovsz); if (error) goto bad; } @@ -511,13 +502,6 @@ auio.uio_vmspace = l->l_proc->p_vmspace; for (i = 0, tiov = mp->msg_iov; i < mp->msg_iovlen; i++, tiov++) { -#if 0 - /* cannot happen; iov_len is unsigned */ - if (tiov->iov_len < 0) { - error = EINVAL; - goto bad; - } -#endif /* * Writes return ssize_t because -1 is returned on error. * Therefore, we must restrict the length to SSIZE_MAX to @@ -551,9 +535,8 @@ } if (ktrpoint(KTR_GENIO)) { - iovlen = auio.uio_iovcnt * sizeof(struct iovec); - ktriov = malloc(iovlen, M_TEMP, M_WAITOK); - memcpy(ktriov, auio.uio_iov, iovlen); + ktriov = kmem_alloc(iovsz, KM_SLEEP); + memcpy(ktriov, auio.uio_iov, iovsz); } if ((error = fd_getsock(s, &so)) != 0) @@ -587,11 +570,11 @@ bad: if (ktriov != NULL) { ktrgeniov(s, UIO_WRITE, ktriov, *retsize, error); - free(ktriov, M_TEMP); + kmem_free(ktriov, iovsz); } if (iov != aiov) - free(iov, M_IOV); + kmem_free(iov, iovsz); if (to) m_freem(to); if (control) @@ -771,12 +754,11 @@ do_sys_recvmsg(struct lwp *l, int s, struct msghdr *mp, struct mbuf **from, struct mbuf **control, register_t *retsize) { - struct uio auio; - struct iovec aiov[UIO_SMALLIOV], *iov = aiov; - struct iovec *tiov; - int i, len, error, iovlen; + struct iovec aiov[UIO_SMALLIOV], *iov = aiov, *tiov, *ktriov; struct socket *so; - struct iovec *ktriov; + struct uio auio; + size_t len, iovsz; + int i, error; ktrkuser("msghdr", mp, sizeof *mp); @@ -787,18 +769,18 @@ if ((error = fd_getsock(s, &so)) != 0) return (error); + iovsz = mp->msg_iovlen * sizeof(struct iovec); + if (mp->msg_flags & MSG_IOVUSRSPACE) { if ((unsigned int)mp->msg_iovlen > UIO_SMALLIOV) { if ((unsigned int)mp->msg_iovlen > IOV_MAX) { error = EMSGSIZE; goto out; } - iov = malloc(sizeof(struct iovec) * mp->msg_iovlen, - M_IOV, M_WAITOK); + iov = kmem_alloc(iovsz, KM_SLEEP); } if (mp->msg_iovlen != 0) { - error = copyin(mp->msg_iov, iov, - (size_t)(mp->msg_iovlen * sizeof(struct iovec))); + error = copyin(mp->msg_iov, iov, iovsz); if (error) goto out; } @@ -814,13 +796,6 @@ tiov = auio.uio_iov; for (i = 0; i < mp->msg_iovlen; i++, tiov++) { -#if 0 - /* cannot happen iov_len is unsigned */ - if (tiov->iov_len < 0) { - error = EINVAL; - goto out; - } -#endif /* * Reads return ssize_t because -1 is returned on error. * Therefore we must restrict the length to SSIZE_MAX to @@ -835,9 +810,8 @@ ktriov = NULL; if (ktrpoint(KTR_GENIO)) { - iovlen = auio.uio_iovcnt * sizeof(struct iovec); - ktriov = malloc(iovlen, M_TEMP, M_WAITOK); - memcpy(ktriov, auio.uio_iov, iovlen); + ktriov = kmem_alloc(iovsz, KM_SLEEP); + memcpy(ktriov, auio.uio_iov, iovsz); } len = auio.uio_resid; @@ -853,7 +827,7 @@ if (ktriov != NULL) { ktrgeniov(s, UIO_READ, ktriov, len, error); - free(ktriov, M_TEMP); + kmem_free(ktriov, iovsz); } if (error != 0) { @@ -866,7 +840,7 @@ } out: if (iov != aiov) - free(iov, M_TEMP); + kmem_free(iov, iovsz); fd_putfile(s); return (error); } Index: src/sys/sys/uio.h diff -u src/sys/sys/uio.h:1.34 src/sys/sys/uio.h:1.35 --- src/sys/sys/uio.h:1.34 Wed Mar 1 12:38:32 2006 +++ src/sys/sys/uio.h Fri Apr 23 15:19:20 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: uio.h,v 1.34 2006/03/01 12:38:32 yamt Exp $ */ +/* $NetBSD: uio.h,v 1.35 2010/04/23 15:19:20 rmind Exp $ */ /* * Copyright (c) 1982, 1986, 1993, 1994 @@ -96,11 +96,9 @@ #endif /* _NETBSD_SOURCE */ #ifdef _KERNEL -#include <sys/mallocvar.h> -MALLOC_DECLARE(M_IOV); - -#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ +/* 8 on stack, more will be dynamically allocated. */ +#define UIO_SMALLIOV 8 void uio_setup_sysspace(struct uio *); #endif