subr_hash.c (131473) | subr_hash.c (131897) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_subr.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_subr.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_subr.c 131473 2004-07-02 19:09:50Z jhb $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_subr.c 131897 2004-07-10 15:42:16Z phk $"); |
39 40#include "opt_zero.h" 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/ktr.h> 46#include <sys/limits.h> --- 422 unchanged lines hidden (view full) --- 469 break; 470 default: 471 panic("copyinstrfrom: bad seg %d\n", seg); 472 } 473 return (error); 474} 475 476int | 39 40#include "opt_zero.h" 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/ktr.h> 46#include <sys/limits.h> --- 422 unchanged lines hidden (view full) --- 469 break; 470 default: 471 panic("copyinstrfrom: bad seg %d\n", seg); 472 } 473 return (error); 474} 475 476int |
477uiofromiov(struct iovec *iovp, u_int iovcnt, struct uio *uio) | 477copyiniov(struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error) |
478{ | 478{ |
479 u_int iovlen; 480 481 *iov = NULL; 482 if (iovcnt > UIO_MAXIOV) 483 return (error); 484 iovlen = iovcnt * sizeof (struct iovec); 485 *iov = malloc(iovlen, M_IOV, M_WAITOK); 486 error = copyin(iovp, *iov, iovlen); 487 if (error) { 488 free(*iov, M_IOV); 489 *iov = NULL; 490 } 491 return (error); 492} 493 494int 495copyinuio(struct iovec *iovp, u_int iovcnt, struct uio **uiop) 496{ |
|
479 struct iovec *iov; | 497 struct iovec *iov; |
498 struct uio *uio; |
|
480 u_int iovlen; 481 int error, i; 482 | 499 u_int iovlen; 500 int error, i; 501 |
483 /* note: can't use iovlen until iovcnt is validated */ | 502 *uiop = NULL; 503 if (iovcnt > UIO_MAXIOV) 504 return (EINVAL); |
484 iovlen = iovcnt * sizeof (struct iovec); | 505 iovlen = iovcnt * sizeof (struct iovec); |
485 if (iovcnt > UIO_MAXIOV) { 486 error = EINVAL; 487 goto done; | 506 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK); 507 iov = (struct iovec *)(uio + 1); 508 error = copyin(iovp, iov, iovlen); 509 if (error) { 510 free(uio, M_IOV); 511 return (error); |
488 } | 512 } |
489 MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK); | |
490 uio->uio_iov = iov; 491 uio->uio_iovcnt = iovcnt; 492 uio->uio_segflg = UIO_USERSPACE; 493 uio->uio_offset = -1; | 513 uio->uio_iov = iov; 514 uio->uio_iovcnt = iovcnt; 515 uio->uio_segflg = UIO_USERSPACE; 516 uio->uio_offset = -1; |
494 if ((error = copyin(iovp, iov, iovlen))) 495 goto done; | |
496 uio->uio_resid = 0; 497 for (i = 0; i < iovcnt; i++) { 498 if (iov->iov_len > INT_MAX - uio->uio_resid) { | 517 uio->uio_resid = 0; 518 for (i = 0; i < iovcnt; i++) { 519 if (iov->iov_len > INT_MAX - uio->uio_resid) { |
499 error = EINVAL; 500 goto done; | 520 free(uio, M_IOV); 521 return (EINVAL); |
501 } 502 uio->uio_resid += iov->iov_len; 503 iov++; 504 } | 522 } 523 uio->uio_resid += iov->iov_len; 524 iov++; 525 } |
526 *uiop = uio; 527 return (0); 528} |
|
505 | 529 |
506done: 507 if (error && uio->uio_iov) { 508 FREE(uio->uio_iov, M_IOV); 509 uio->uio_iov = NULL; 510 } 511 return (error); | 530struct uio * 531cloneuio(struct uio *uiop) 532{ 533 struct uio *uio; 534 int iovlen; |
512 | 535 |
536 iovlen = uiop->uio_iovcnt * sizeof (struct iovec); 537 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK); 538 *uio = *uiop; 539 uio->uio_iov = (struct iovec *)(uio + 1); 540 bcopy(uiop->uio_iov, uio->uio_iov, iovlen); 541 return (uio); |
|
513} | 542} |