- if (uio->uio_rw == UIO_READ)
- {
- KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
- (int)cp, (uintptr_t)uio->uio_iovs.kiovp->iov_base, acnt, 2,0);
-
- error = copypv((addr64_t)cp, uio->uio_iovs.kiovp->iov_base, acnt, cppvKmap | cppvPsrc | cppvNoRefSrc);
- if (error) /* Copy physical to virtual */
- error = EFAULT;
-
- KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
- (int)cp, (uintptr_t)uio->uio_iovs.kiovp->iov_base, acnt, 2,0);
- }
- else
- {
- KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
- (uintptr_t)uio->uio_iovs.kiovp->iov_base, (int)cp, acnt, 2,0);
-
- error = copypv(uio->uio_iovs.kiovp->iov_base, (addr64_t)cp, acnt, cppvKmap | cppvPsnk | cppvNoRefSrc | cppvNoModSnk);
- if (error) /* Copy virtual to physical */
- error = EFAULT;
-
- KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
- (uintptr_t)uio->uio_iovs.kiovp->iov_base, (int)cp, acnt, 2,0);
- }
- if (error)
- return (error);
+ acnt = MIN(acnt, UINT_MAX);
+
+ if (uio->uio_rw == UIO_READ) {
+ KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
+ (int)cp, (uintptr_t)uio->uio_iovs.kiovp->iov_base, acnt, 2, 0);
+
+ error = copypv((addr64_t)cp, uio->uio_iovs.kiovp->iov_base, (unsigned int)acnt, cppvKmap | cppvPsrc | cppvNoRefSrc);
+ if (error) { /* Copy physical to virtual */
+ error = EFAULT;
+ }
+
+ KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
+ (int)cp, (uintptr_t)uio->uio_iovs.kiovp->iov_base, acnt, 2, 0);
+ } else {
+ KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
+ (uintptr_t)uio->uio_iovs.kiovp->iov_base, (int)cp, acnt, 2, 0);
+
+ error = copypv(uio->uio_iovs.kiovp->iov_base, (addr64_t)cp, (unsigned int)acnt, cppvKmap | cppvPsnk | cppvNoRefSrc | cppvNoModSnk);
+ if (error) { /* Copy virtual to physical */
+ error = EFAULT;
+ }
+
+ KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
+ (uintptr_t)uio->uio_iovs.kiovp->iov_base, (int)cp, acnt, 2, 0);
+ }
+ if (error) {
+ return error;
+ }