]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/kern_subr.c
xnu-792.21.3.tar.gz
[apple/xnu.git] / bsd / kern / kern_subr.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29 /*
30 * Copyright (c) 1982, 1986, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)kern_subr.c 8.3 (Berkeley) 1/21/94
67 */
68
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/proc_internal.h>
72 #include <sys/malloc.h>
73 #include <sys/queue.h>
74 #include <vm/pmap.h>
75 #include <sys/uio_internal.h>
76 #include <kern/kalloc.h>
77
78 #include <kdebug.h>
79
80 #include <sys/kdebug.h>
81 #define DBG_UIO_COPYOUT 16
82 #define DBG_UIO_COPYIN 17
83
84 #if DEBUG
85 #include <kern/simple_lock.h>
86
87 static int uio_t_count = 0;
88 #endif /* DEBUG */
89
90
91 int
92 uiomove(cp, n, uio)
93 register caddr_t cp;
94 register int n;
95 register uio_t uio;
96 {
97 return uiomove64((addr64_t)((unsigned int)cp), n, uio);
98 }
99
100 // LP64todo - fix this! 'n' should be int64_t?
101 int
102 uiomove64(addr64_t cp, int n, register struct uio *uio)
103 {
104 #if LP64KERN
105 register uint64_t acnt;
106 #else
107 register u_int acnt;
108 #endif
109 int error = 0;
110
111 #if DIAGNOSTIC
112 if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
113 panic("uiomove: mode");
114 #endif
115
116 #if LP64_DEBUG
117 if (IS_VALID_UIO_SEGFLG(uio->uio_segflg) == 0) {
118 panic("%s :%d - invalid uio_segflg\n", __FILE__, __LINE__);
119 }
120 #endif /* LP64_DEBUG */
121
122 while (n > 0 && uio_resid(uio)) {
123 acnt = uio_iov_len(uio);
124 if (acnt == 0) {
125 uio_next_iov(uio);
126 uio->uio_iovcnt--;
127 continue;
128 }
129 if (n > 0 && acnt > (uint64_t)n)
130 acnt = n;
131
132 switch (uio->uio_segflg) {
133
134 case UIO_USERSPACE64:
135 case UIO_USERISPACE64:
136 // LP64 - 3rd argument in debug code is 64 bit, expected to be 32 bit
137 if (uio->uio_rw == UIO_READ)
138 {
139 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
140 (int)cp, (int)uio->uio_iovs.iov64p->iov_base, acnt, 0,0);
141
142 error = copyout( CAST_DOWN(caddr_t, cp), uio->uio_iovs.iov64p->iov_base, acnt );
143
144 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
145 (int)cp, (int)uio->uio_iovs.iov64p->iov_base, acnt, 0,0);
146 }
147 else
148 {
149 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
150 (int)uio->uio_iovs.iov64p->iov_base, (int)cp, acnt, 0,0);
151
152 error = copyin(uio->uio_iovs.iov64p->iov_base, CAST_DOWN(caddr_t, cp), acnt);
153
154 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
155 (int)uio->uio_iovs.iov64p->iov_base, (int)cp, acnt, 0,0);
156 }
157 if (error)
158 return (error);
159 break;
160
161 case UIO_USERSPACE32:
162 case UIO_USERISPACE32:
163 case UIO_USERSPACE:
164 case UIO_USERISPACE:
165 if (uio->uio_rw == UIO_READ)
166 {
167 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
168 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 0,0);
169
170 error = copyout( CAST_DOWN(caddr_t, cp), CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base), acnt );
171
172 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
173 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 0,0);
174 }
175 else
176 {
177 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
178 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 0,0);
179
180 error = copyin(CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base), CAST_DOWN(caddr_t, cp), acnt);
181
182 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
183 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 0,0);
184 }
185 if (error)
186 return (error);
187 break;
188
189 case UIO_SYSSPACE32:
190 case UIO_SYSSPACE:
191 if (uio->uio_rw == UIO_READ)
192 error = copywithin(CAST_DOWN(caddr_t, cp), (caddr_t)uio->uio_iovs.iov32p->iov_base,
193 acnt);
194 else
195 error = copywithin((caddr_t)uio->uio_iovs.iov32p->iov_base, CAST_DOWN(caddr_t, cp),
196 acnt);
197 break;
198
199 case UIO_PHYS_USERSPACE64:
200 if (uio->uio_rw == UIO_READ)
201 {
202 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
203 (int)cp, (int)uio->uio_iovs.iov64p->iov_base, acnt, 1,0);
204
205 error = copypv((addr64_t)cp, uio->uio_iovs.iov64p->iov_base, acnt, cppvPsrc | cppvNoRefSrc);
206 if (error) /* Copy physical to virtual */
207 error = EFAULT;
208
209 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
210 (int)cp, (int)uio->uio_iovs.iov64p->iov_base, acnt, 1,0);
211 }
212 else
213 {
214 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
215 (int)uio->uio_iovs.iov64p->iov_base, (int)cp, acnt, 1,0);
216
217 error = copypv(uio->uio_iovs.iov64p->iov_base, (addr64_t)cp, acnt, cppvPsnk | cppvNoRefSrc | cppvNoModSnk);
218 if (error) /* Copy virtual to physical */
219 error = EFAULT;
220
221 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
222 (int)uio->uio_iovs.iov64p->iov_base, (int)cp, acnt, 1,0);
223 }
224 if (error)
225 return (error);
226 break;
227
228 case UIO_PHYS_USERSPACE32:
229 case UIO_PHYS_USERSPACE:
230 if (uio->uio_rw == UIO_READ)
231 {
232 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
233 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 1,0);
234
235 error = copypv((addr64_t)cp, (addr64_t)uio->uio_iovs.iov32p->iov_base, acnt, cppvPsrc | cppvNoRefSrc);
236 if (error) /* Copy physical to virtual */
237 error = EFAULT;
238
239 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
240 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 1,0);
241 }
242 else
243 {
244 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
245 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 1,0);
246
247 error = copypv((addr64_t)uio->uio_iovs.iov32p->iov_base, (addr64_t)cp, acnt, cppvPsnk | cppvNoRefSrc | cppvNoModSnk);
248 if (error) /* Copy virtual to physical */
249 error = EFAULT;
250
251 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
252 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 1,0);
253 }
254 if (error)
255 return (error);
256 break;
257
258 case UIO_PHYS_SYSSPACE32:
259 case UIO_PHYS_SYSSPACE:
260 if (uio->uio_rw == UIO_READ)
261 {
262 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_START,
263 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 2,0);
264
265 error = copypv((addr64_t)cp, uio->uio_iovs.iov32p->iov_base, acnt, cppvKmap | cppvPsrc | cppvNoRefSrc);
266 if (error) /* Copy physical to virtual */
267 error = EFAULT;
268
269 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYOUT)) | DBG_FUNC_END,
270 (int)cp, (int)uio->uio_iovs.iov32p->iov_base, acnt, 2,0);
271 }
272 else
273 {
274 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_START,
275 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 2,0);
276
277 error = copypv(uio->uio_iovs.iov32p->iov_base, (addr64_t)cp, acnt, cppvKmap | cppvPsnk | cppvNoRefSrc | cppvNoModSnk);
278 if (error) /* Copy virtual to physical */
279 error = EFAULT;
280
281 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, DBG_UIO_COPYIN)) | DBG_FUNC_END,
282 (int)uio->uio_iovs.iov32p->iov_base, (int)cp, acnt, 2,0);
283 }
284 if (error)
285 return (error);
286 break;
287
288 default:
289 break;
290 }
291 uio_iov_base_add(uio, acnt);
292 #if LP64KERN
293 uio_iov_len_add(uio, -((int64_t)acnt));
294 uio_setresid(uio, (uio_resid(uio) - ((int64_t)acnt)));
295 #else
296 uio_iov_len_add(uio, -((int)acnt));
297 uio_setresid(uio, (uio_resid(uio) - ((int)acnt)));
298 #endif
299 uio->uio_offset += acnt;
300 cp += acnt;
301 n -= acnt;
302 }
303 return (error);
304 }
305
306 /*
307 * Give next character to user as result of read.
308 */
309 int
310 ureadc(c, uio)
311 register int c;
312 register struct uio *uio;
313 {
314 if (uio_resid(uio) <= 0)
315 panic("ureadc: non-positive resid");
316 again:
317 if (uio->uio_iovcnt == 0)
318 panic("ureadc: non-positive iovcnt");
319 if (uio_iov_len(uio) <= 0) {
320 uio->uio_iovcnt--;
321 uio_next_iov(uio);
322 goto again;
323 }
324 switch (uio->uio_segflg) {
325
326 case UIO_USERSPACE32:
327 case UIO_USERSPACE:
328 if (subyte(CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base), c) < 0)
329 return (EFAULT);
330 break;
331
332 case UIO_USERSPACE64:
333 if (subyte((user_addr_t)uio->uio_iovs.iov64p->iov_base, c) < 0)
334 return (EFAULT);
335 break;
336
337 case UIO_SYSSPACE32:
338 case UIO_SYSSPACE:
339 *((caddr_t)uio->uio_iovs.iov32p->iov_base) = c;
340 break;
341
342 case UIO_USERISPACE32:
343 case UIO_USERISPACE:
344 if (suibyte(CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base), c) < 0)
345 return (EFAULT);
346 break;
347
348 default:
349 break;
350 }
351 uio_iov_base_add(uio, 1);
352 uio_iov_len_add(uio, -1);
353 uio_setresid(uio, (uio_resid(uio) - 1));
354 uio->uio_offset++;
355 return (0);
356 }
357
358 #if defined(vax) || defined(ppc)
359 /* unused except by ct.c, other oddities XXX */
360 /*
361 * Get next character written in by user from uio.
362 */
363 int
364 uwritec(uio)
365 uio_t uio;
366 {
367 register int c = 0;
368
369 if (uio_resid(uio) <= 0)
370 return (-1);
371 again:
372 if (uio->uio_iovcnt <= 0)
373 panic("uwritec: non-positive iovcnt");
374
375 if (uio_iov_len(uio) == 0) {
376 uio_next_iov(uio);
377 if (--uio->uio_iovcnt == 0)
378 return (-1);
379 goto again;
380 }
381 switch (uio->uio_segflg) {
382
383 case UIO_USERSPACE32:
384 case UIO_USERSPACE:
385 c = fubyte(CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base));
386 break;
387
388 case UIO_USERSPACE64:
389 c = fubyte((user_addr_t)uio->uio_iovs.iov64p->iov_base);
390 break;
391
392 case UIO_SYSSPACE32:
393 case UIO_SYSSPACE:
394 c = *((caddr_t)uio->uio_iovs.iov32p->iov_base) & 0377;
395 break;
396
397 case UIO_USERISPACE32:
398 case UIO_USERISPACE:
399 c = fuibyte(CAST_USER_ADDR_T(uio->uio_iovs.iov32p->iov_base));
400 break;
401
402 default:
403 c = 0; /* avoid uninitialized variable warning */
404 panic("uwritec: bogus uio_segflg");
405 break;
406 }
407 if (c < 0)
408 return (-1);
409 uio_iov_base_add(uio, 1);
410 uio_iov_len_add(uio, -1);
411 uio_setresid(uio, (uio_resid(uio) - 1));
412 uio->uio_offset++;
413 return (c);
414 }
415 #endif /* vax || ppc */
416
417 /*
418 * General routine to allocate a hash table.
419 */
420 void *
421 hashinit(elements, type, hashmask)
422 int elements, type;
423 u_long *hashmask;
424 {
425 long hashsize;
426 LIST_HEAD(generic, generic) *hashtbl;
427 int i;
428
429 if (elements <= 0)
430 panic("hashinit: bad cnt");
431 for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
432 continue;
433 hashsize >>= 1;
434 MALLOC(hashtbl, struct generic *,
435 (u_long)hashsize * sizeof(*hashtbl), type, M_WAITOK|M_ZERO);
436 if (hashtbl != NULL) {
437 for (i = 0; i < hashsize; i++)
438 LIST_INIT(&hashtbl[i]);
439 *hashmask = hashsize - 1;
440 }
441 return (hashtbl);
442 }
443
444 /*
445 * uio_resid - return the residual IO value for the given uio_t
446 */
447 user_ssize_t uio_resid( uio_t a_uio )
448 {
449 #if DEBUG
450 if (a_uio == NULL) {
451 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
452 }
453 /* if (IS_VALID_UIO_SEGFLG(a_uio->uio_segflg) == 0) { */
454 /* panic("%s :%d - invalid uio_segflg\n", __FILE__, __LINE__); */
455 /* } */
456 #endif /* DEBUG */
457
458 /* return 0 if there are no active iovecs */
459 if (a_uio == NULL) {
460 return( 0 );
461 }
462
463 if (UIO_IS_64_BIT_SPACE(a_uio)) {
464 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
465 return( (user_ssize_t)a_uio->uio_resid );
466 #else
467 return( a_uio->uio_resid_64 );
468 #endif
469 }
470 return( (user_ssize_t)a_uio->uio_resid );
471 }
472
473 /*
474 * uio_setresid - set the residual IO value for the given uio_t
475 */
476 void uio_setresid( uio_t a_uio, user_ssize_t a_value )
477 {
478 #if DEBUG
479 if (a_uio == NULL) {
480 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
481 }
482 /* if (IS_VALID_UIO_SEGFLG(a_uio->uio_segflg) == 0) { */
483 /* panic("%s :%d - invalid uio_segflg\n", __FILE__, __LINE__); */
484 /* } */
485 #endif /* DEBUG */
486
487 if (a_uio == NULL) {
488 return;
489 }
490
491 if (UIO_IS_64_BIT_SPACE(a_uio)) {
492 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
493 a_uio->uio_resid = (int)a_value;
494 #else
495 a_uio->uio_resid_64 = a_value;
496 #endif
497 }
498 else {
499 a_uio->uio_resid = (int)a_value;
500 }
501 return;
502 }
503
504 #if 0 // obsolete
505 /*
506 * uio_proc_t - return the proc_t for the given uio_t
507 * WARNING - This call is going away. Find another way to get the proc_t!!
508 */
509 __private_extern__ proc_t uio_proc_t( uio_t a_uio )
510 {
511 #if LP64_DEBUG
512 if (a_uio == NULL) {
513 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
514 }
515 #endif /* LP64_DEBUG */
516
517 /* return 0 if there are no active iovecs */
518 if (a_uio == NULL) {
519 return( NULL );
520 }
521 return( a_uio->uio_procp );
522 }
523
524 /*
525 * uio_setproc_t - set the residual IO value for the given uio_t
526 * WARNING - This call is going away.
527 */
528 __private_extern__ void uio_setproc_t( uio_t a_uio, proc_t a_proc_t )
529 {
530 if (a_uio == NULL) {
531 #if LP64_DEBUG
532 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
533 #endif /* LP64_DEBUG */
534 return;
535 }
536
537 a_uio->uio_procp = a_proc_t;
538 return;
539 }
540 #endif // obsolete
541
542 /*
543 * uio_curriovbase - return the base address of the current iovec associated
544 * with the given uio_t. May return 0.
545 */
546 user_addr_t uio_curriovbase( uio_t a_uio )
547 {
548 #if LP64_DEBUG
549 if (a_uio == NULL) {
550 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
551 }
552 #endif /* LP64_DEBUG */
553
554 if (a_uio == NULL || a_uio->uio_iovcnt < 1) {
555 return(0);
556 }
557
558 if (UIO_IS_64_BIT_SPACE(a_uio)) {
559 return(a_uio->uio_iovs.uiovp->iov_base);
560 }
561 return((user_addr_t)((uintptr_t)a_uio->uio_iovs.kiovp->iov_base));
562
563 }
564
565 /*
566 * uio_curriovlen - return the length value of the current iovec associated
567 * with the given uio_t.
568 */
569 user_size_t uio_curriovlen( uio_t a_uio )
570 {
571 #if LP64_DEBUG
572 if (a_uio == NULL) {
573 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
574 }
575 #endif /* LP64_DEBUG */
576
577 if (a_uio == NULL || a_uio->uio_iovcnt < 1) {
578 return(0);
579 }
580
581 if (UIO_IS_64_BIT_SPACE(a_uio)) {
582 return(a_uio->uio_iovs.uiovp->iov_len);
583 }
584 return((user_size_t)a_uio->uio_iovs.kiovp->iov_len);
585 }
586
587 /*
588 * uio_setcurriovlen - set the length value of the current iovec associated
589 * with the given uio_t.
590 */
591 __private_extern__ void uio_setcurriovlen( uio_t a_uio, user_size_t a_value )
592 {
593 #if LP64_DEBUG
594 if (a_uio == NULL) {
595 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
596 }
597 #endif /* LP64_DEBUG */
598
599 if (a_uio == NULL) {
600 return;
601 }
602
603 if (UIO_IS_64_BIT_SPACE(a_uio)) {
604 a_uio->uio_iovs.uiovp->iov_len = a_value;
605 }
606 else {
607 #if LP64_DEBUG
608 if (a_value > 0xFFFFFFFFull) {
609 panic("%s :%d - invalid a_value\n", __FILE__, __LINE__);
610 }
611 #endif /* LP64_DEBUG */
612 a_uio->uio_iovs.kiovp->iov_len = (size_t)a_value;
613 }
614 return;
615 }
616
617 /*
618 * uio_iovcnt - return count of active iovecs for the given uio_t
619 */
620 int uio_iovcnt( uio_t a_uio )
621 {
622 #if LP64_DEBUG
623 if (a_uio == NULL) {
624 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
625 }
626 #endif /* LP64_DEBUG */
627
628 if (a_uio == NULL) {
629 return(0);
630 }
631
632 return( a_uio->uio_iovcnt );
633 }
634
635 /*
636 * uio_offset - return the current offset value for the given uio_t
637 */
638 off_t uio_offset( uio_t a_uio )
639 {
640 #if LP64_DEBUG
641 if (a_uio == NULL) {
642 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
643 }
644 #endif /* LP64_DEBUG */
645
646 if (a_uio == NULL) {
647 return(0);
648 }
649 return( a_uio->uio_offset );
650 }
651
652 /*
653 * uio_setoffset - set the current offset value for the given uio_t
654 */
655 void uio_setoffset( uio_t a_uio, off_t a_offset )
656 {
657 #if LP64_DEBUG
658 if (a_uio == NULL) {
659 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
660 }
661 #endif /* LP64_DEBUG */
662
663 if (a_uio == NULL) {
664 return;
665 }
666 a_uio->uio_offset = a_offset;
667 return;
668 }
669
670 /*
671 * uio_rw - return the read / write flag for the given uio_t
672 */
673 int uio_rw( uio_t a_uio )
674 {
675 #if LP64_DEBUG
676 if (a_uio == NULL) {
677 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
678 }
679 #endif /* LP64_DEBUG */
680
681 if (a_uio == NULL) {
682 return(-1);
683 }
684 return( a_uio->uio_rw );
685 }
686
687 /*
688 * uio_setrw - set the read / write flag for the given uio_t
689 */
690 void uio_setrw( uio_t a_uio, int a_value )
691 {
692 if (a_uio == NULL) {
693 #if LP64_DEBUG
694 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
695 #endif /* LP64_DEBUG */
696 return;
697 }
698
699 #if LP64_DEBUG
700 if (!(a_value == UIO_READ || a_value == UIO_WRITE)) {
701 panic("%s :%d - invalid a_value\n", __FILE__, __LINE__);
702 }
703 #endif /* LP64_DEBUG */
704
705 if (a_value == UIO_READ || a_value == UIO_WRITE) {
706 a_uio->uio_rw = a_value;
707 }
708 return;
709 }
710
711 /*
712 * uio_isuserspace - return non zero value if the address space
713 * flag is for a user address space (could be 32 or 64 bit).
714 */
715 int uio_isuserspace( uio_t a_uio )
716 {
717 if (a_uio == NULL) {
718 #if LP64_DEBUG
719 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
720 #endif /* LP64_DEBUG */
721 return(0);
722 }
723
724 if (UIO_SEG_IS_USER_SPACE(a_uio->uio_segflg)) {
725 return( 1 );
726 }
727 return( 0 );
728 }
729
730
731 /*
732 * uio_create - create an uio_t.
733 * Space is allocated to hold up to a_iovcount number of iovecs. The uio_t
734 * is not fully initialized until all iovecs are added using uio_addiov calls.
735 * a_iovcount is the maximum number of iovecs you may add.
736 */
737 uio_t uio_create( int a_iovcount, /* number of iovecs */
738 off_t a_offset, /* current offset */
739 int a_spacetype, /* type of address space */
740 int a_iodirection ) /* read or write flag */
741 {
742 void * my_buf_p;
743 int my_size;
744 uio_t my_uio;
745
746 my_size = sizeof(struct uio) + (sizeof(struct user_iovec) * a_iovcount);
747 my_buf_p = kalloc(my_size);
748 my_uio = uio_createwithbuffer( a_iovcount,
749 a_offset,
750 a_spacetype,
751 a_iodirection,
752 my_buf_p,
753 my_size );
754 if (my_uio != 0) {
755 /* leave a note that we allocated this uio_t */
756 my_uio->uio_flags |= UIO_FLAGS_WE_ALLOCED;
757 #if DEBUG
758 hw_atomic_add(&uio_t_count, 1);
759 #endif
760 }
761
762 return( my_uio );
763 }
764
765
766 /*
767 * uio_createwithbuffer - create an uio_t.
768 * Create a uio_t using the given buffer. The uio_t
769 * is not fully initialized until all iovecs are added using uio_addiov calls.
770 * a_iovcount is the maximum number of iovecs you may add.
771 * This call may fail if the given buffer is not large enough.
772 */
773 __private_extern__ uio_t
774 uio_createwithbuffer( int a_iovcount, /* number of iovecs */
775 off_t a_offset, /* current offset */
776 int a_spacetype, /* type of address space */
777 int a_iodirection, /* read or write flag */
778 void *a_buf_p, /* pointer to a uio_t buffer */
779 int a_buffer_size ) /* size of uio_t buffer */
780 {
781 uio_t my_uio = (uio_t) a_buf_p;
782 int my_size;
783
784 my_size = sizeof(struct uio) + (sizeof(struct user_iovec) * a_iovcount);
785 if (a_buffer_size < my_size) {
786 #if DEBUG
787 panic("%s :%d - a_buffer_size is too small\n", __FILE__, __LINE__);
788 #endif /* DEBUG */
789 return( NULL );
790 }
791 my_size = a_buffer_size;
792
793 #if DEBUG
794 if (my_uio == 0) {
795 panic("%s :%d - could not allocate uio_t\n", __FILE__, __LINE__);
796 }
797 if (!IS_VALID_UIO_SEGFLG(a_spacetype)) {
798 panic("%s :%d - invalid address space type\n", __FILE__, __LINE__);
799 }
800 if (!(a_iodirection == UIO_READ || a_iodirection == UIO_WRITE)) {
801 panic("%s :%d - invalid IO direction flag\n", __FILE__, __LINE__);
802 }
803 if (a_iovcount > UIO_MAXIOV) {
804 panic("%s :%d - invalid a_iovcount\n", __FILE__, __LINE__);
805 }
806 #endif /* DEBUG */
807
808 bzero(my_uio, my_size);
809 my_uio->uio_size = my_size;
810
811 /* we use uio_segflg to indicate if the uio_t is the new format or */
812 /* old (pre LP64 support) legacy format */
813 switch (a_spacetype) {
814 case UIO_USERSPACE:
815 my_uio->uio_segflg = UIO_USERSPACE32;
816 case UIO_SYSSPACE:
817 my_uio->uio_segflg = UIO_SYSSPACE32;
818 case UIO_PHYS_USERSPACE:
819 my_uio->uio_segflg = UIO_PHYS_USERSPACE32;
820 case UIO_PHYS_SYSSPACE:
821 my_uio->uio_segflg = UIO_PHYS_SYSSPACE32;
822 default:
823 my_uio->uio_segflg = a_spacetype;
824 break;
825 }
826
827 if (a_iovcount > 0) {
828 my_uio->uio_iovs.uiovp = (struct user_iovec *)
829 (((uint8_t *)my_uio) + sizeof(struct uio));
830 }
831 else {
832 my_uio->uio_iovs.uiovp = NULL;
833 }
834
835 my_uio->uio_max_iovs = a_iovcount;
836 my_uio->uio_offset = a_offset;
837 my_uio->uio_rw = a_iodirection;
838 my_uio->uio_flags = UIO_FLAGS_INITED;
839
840 return( my_uio );
841 }
842
843 /*
844 * uio_spacetype - return the address space type for the given uio_t
845 */
846 int uio_spacetype( uio_t a_uio )
847 {
848 if (a_uio == NULL) {
849 #if LP64_DEBUG
850 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
851 #endif /* LP64_DEBUG */
852 return(-1);
853 }
854
855 return( a_uio->uio_segflg );
856 }
857
858 /*
859 * uio_iovsaddr - get the address of the iovec array for the given uio_t.
860 * This returns the location of the iovecs within the uio.
861 * NOTE - for compatibility mode we just return the current value in uio_iovs
862 * which will increase as the IO is completed and is NOT embedded within the
863 * uio, it is a seperate array of one or more iovecs.
864 */
865 struct user_iovec * uio_iovsaddr( uio_t a_uio )
866 {
867 struct user_iovec * my_addr;
868
869 if (a_uio == NULL) {
870 return(NULL);
871 }
872
873 if (a_uio->uio_segflg == UIO_USERSPACE || a_uio->uio_segflg == UIO_SYSSPACE) {
874 /* we need this for compatibility mode. */
875 my_addr = (struct user_iovec *) a_uio->uio_iovs.iovp;
876 }
877 else {
878 my_addr = (struct user_iovec *) (((uint8_t *)a_uio) + sizeof(struct uio));
879 }
880 return(my_addr);
881 }
882
883 /*
884 * uio_reset - reset an uio_t.
885 * Reset the given uio_t to initial values. The uio_t is not fully initialized
886 * until all iovecs are added using uio_addiov calls.
887 * The a_iovcount value passed in the uio_create is the maximum number of
888 * iovecs you may add.
889 */
890 void uio_reset( uio_t a_uio,
891 off_t a_offset, /* current offset */
892 int a_spacetype, /* type of address space */
893 int a_iodirection ) /* read or write flag */
894 {
895 vm_size_t my_size;
896 int my_max_iovs;
897 u_int32_t my_old_flags;
898
899 #if LP64_DEBUG
900 if (a_uio == NULL) {
901 panic("%s :%d - could not allocate uio_t\n", __FILE__, __LINE__);
902 }
903 if (!IS_VALID_UIO_SEGFLG(a_spacetype)) {
904 panic("%s :%d - invalid address space type\n", __FILE__, __LINE__);
905 }
906 if (!(a_iodirection == UIO_READ || a_iodirection == UIO_WRITE)) {
907 panic("%s :%d - invalid IO direction flag\n", __FILE__, __LINE__);
908 }
909 #endif /* LP64_DEBUG */
910
911 if (a_uio == NULL) {
912 return;
913 }
914
915 my_size = a_uio->uio_size;
916 my_old_flags = a_uio->uio_flags;
917 my_max_iovs = a_uio->uio_max_iovs;
918 bzero(a_uio, my_size);
919 a_uio->uio_size = my_size;
920 a_uio->uio_segflg = a_spacetype;
921 if (my_max_iovs > 0) {
922 a_uio->uio_iovs.uiovp = (struct user_iovec *)
923 (((uint8_t *)a_uio) + sizeof(struct uio));
924 }
925 else {
926 a_uio->uio_iovs.uiovp = NULL;
927 }
928 a_uio->uio_max_iovs = my_max_iovs;
929 a_uio->uio_offset = a_offset;
930 a_uio->uio_rw = a_iodirection;
931 a_uio->uio_flags = my_old_flags;
932
933 return;
934 }
935
936 /*
937 * uio_free - free a uio_t allocated via uio_init. this also frees all
938 * associated iovecs.
939 */
940 void uio_free( uio_t a_uio )
941 {
942 #if DEBUG
943 if (a_uio == NULL) {
944 panic("%s :%d - passing NULL uio_t\n", __FILE__, __LINE__);
945 }
946 #endif /* LP64_DEBUG */
947
948 if (a_uio != NULL && (a_uio->uio_flags & UIO_FLAGS_WE_ALLOCED) != 0) {
949 #if DEBUG
950 if ((int)(hw_atomic_sub(&uio_t_count, 1)) < 0) {
951 panic("%s :%d - uio_t_count has gone negative\n", __FILE__, __LINE__);
952 }
953 #endif
954 kfree(a_uio, a_uio->uio_size);
955 }
956
957
958 }
959
960 /*
961 * uio_addiov - add an iovec to the given uio_t. You may call this up to
962 * the a_iovcount number that was passed to uio_create. This call will
963 * increment the residual IO count as iovecs are added to the uio_t.
964 * returns 0 if add was successful else non zero.
965 */
966 int uio_addiov( uio_t a_uio, user_addr_t a_baseaddr, user_size_t a_length )
967 {
968 int i;
969
970 if (a_uio == NULL) {
971 #if DEBUG
972 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
973 #endif /* LP64_DEBUG */
974 return(-1);
975 }
976
977 if (UIO_IS_64_BIT_SPACE(a_uio)) {
978 for ( i = 0; i < a_uio->uio_max_iovs; i++ ) {
979 if (a_uio->uio_iovs.uiovp[i].iov_len == 0 && a_uio->uio_iovs.uiovp[i].iov_base == 0) {
980 a_uio->uio_iovs.uiovp[i].iov_len = a_length;
981 a_uio->uio_iovs.uiovp[i].iov_base = a_baseaddr;
982 a_uio->uio_iovcnt++;
983 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
984 a_uio->uio_resid += a_length;
985 #else
986 a_uio->uio_resid_64 += a_length;
987 #endif
988 return( 0 );
989 }
990 }
991 }
992 else {
993 for ( i = 0; i < a_uio->uio_max_iovs; i++ ) {
994 if (a_uio->uio_iovs.kiovp[i].iov_len == 0 && a_uio->uio_iovs.kiovp[i].iov_base == 0) {
995 a_uio->uio_iovs.kiovp[i].iov_len = (u_int32_t)a_length;
996 a_uio->uio_iovs.kiovp[i].iov_base = (u_int32_t)((uintptr_t)a_baseaddr);
997 a_uio->uio_iovcnt++;
998 a_uio->uio_resid += a_length;
999 return( 0 );
1000 }
1001 }
1002 }
1003
1004 return( -1 );
1005 }
1006
1007 /*
1008 * uio_getiov - get iovec data associated with the given uio_t. Use
1009 * a_index to iterate over each iovec (0 to (uio_iovcnt(uio_t) - 1)).
1010 * a_baseaddr_p and a_length_p may be NULL.
1011 * returns -1 when a_index is >= uio_t.uio_iovcnt or invalid uio_t.
1012 * returns 0 when data is returned.
1013 */
1014 int uio_getiov( uio_t a_uio,
1015 int a_index,
1016 user_addr_t * a_baseaddr_p,
1017 user_size_t * a_length_p )
1018 {
1019 if (a_uio == NULL) {
1020 #if DEBUG
1021 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
1022 #endif /* DEBUG */
1023 return(-1);
1024 }
1025 if ( a_index < 0 || a_index >= a_uio->uio_iovcnt) {
1026 return(-1);
1027 }
1028
1029 if (UIO_IS_64_BIT_SPACE(a_uio)) {
1030 if (a_baseaddr_p != NULL) {
1031 *a_baseaddr_p = a_uio->uio_iovs.uiovp[a_index].iov_base;
1032 }
1033 if (a_length_p != NULL) {
1034 *a_length_p = a_uio->uio_iovs.uiovp[a_index].iov_len;
1035 }
1036 }
1037 else {
1038 if (a_baseaddr_p != NULL) {
1039 *a_baseaddr_p = a_uio->uio_iovs.kiovp[a_index].iov_base;
1040 }
1041 if (a_length_p != NULL) {
1042 *a_length_p = a_uio->uio_iovs.kiovp[a_index].iov_len;
1043 }
1044 }
1045
1046 return( 0 );
1047 }
1048
1049 /*
1050 * uio_calculateresid - runs through all iovecs associated with this
1051 * uio_t and calculates (and sets) the residual IO count.
1052 */
1053 __private_extern__ void uio_calculateresid( uio_t a_uio )
1054 {
1055 int i;
1056
1057 if (a_uio == NULL) {
1058 #if LP64_DEBUG
1059 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
1060 #endif /* LP64_DEBUG */
1061 return;
1062 }
1063
1064 a_uio->uio_iovcnt = a_uio->uio_max_iovs;
1065 if (UIO_IS_64_BIT_SPACE(a_uio)) {
1066 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
1067 a_uio->uio_resid = 0;
1068 #else
1069 a_uio->uio_resid_64 = 0;
1070 #endif
1071 for ( i = 0; i < a_uio->uio_max_iovs; i++ ) {
1072 if (a_uio->uio_iovs.uiovp[i].iov_len != 0 && a_uio->uio_iovs.uiovp[i].iov_base != 0) {
1073 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
1074 a_uio->uio_resid += a_uio->uio_iovs.uiovp[i].iov_len;
1075 #else
1076 a_uio->uio_resid_64 += a_uio->uio_iovs.uiovp[i].iov_len;
1077 #endif
1078 }
1079 }
1080
1081 /* position to first non zero length iovec (4235922) */
1082 while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.uiovp->iov_len == 0) {
1083 a_uio->uio_iovcnt--;
1084 if (a_uio->uio_iovcnt > 0) {
1085 a_uio->uio_iovs.uiovp++;
1086 }
1087 }
1088 }
1089 else {
1090 a_uio->uio_resid = 0;
1091 for ( i = 0; i < a_uio->uio_max_iovs; i++ ) {
1092 if (a_uio->uio_iovs.kiovp[i].iov_len != 0 && a_uio->uio_iovs.kiovp[i].iov_base != 0) {
1093 a_uio->uio_resid += a_uio->uio_iovs.kiovp[i].iov_len;
1094 }
1095 }
1096
1097 /* position to first non zero length iovec (4235922) */
1098 while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.kiovp->iov_len == 0) {
1099 a_uio->uio_iovcnt--;
1100 if (a_uio->uio_iovcnt > 0) {
1101 a_uio->uio_iovs.kiovp++;
1102 }
1103 }
1104 }
1105
1106 return;
1107 }
1108
1109 /*
1110 * uio_update - update the given uio_t for a_count of completed IO.
1111 * This call decrements the current iovec length and residual IO value
1112 * and increments the current iovec base address and offset value.
1113 * If the current iovec length is 0 then advance to the next
1114 * iovec (if any).
1115 * If the a_count passed in is 0, than only do the advancement
1116 * over any 0 length iovec's.
1117 */
1118 void uio_update( uio_t a_uio, user_size_t a_count )
1119 {
1120 #if LP64_DEBUG
1121 if (a_uio == NULL) {
1122 panic("%s :%d - invalid uio_t\n", __FILE__, __LINE__);
1123 }
1124 if (UIO_IS_32_BIT_SPACE(a_uio) && a_count > 0xFFFFFFFFull) {
1125 panic("%s :%d - invalid count value \n", __FILE__, __LINE__);
1126 }
1127 #endif /* LP64_DEBUG */
1128
1129 if (a_uio == NULL || a_uio->uio_iovcnt < 1) {
1130 return;
1131 }
1132
1133 if (UIO_IS_64_BIT_SPACE(a_uio)) {
1134 /*
1135 * if a_count == 0, then we are asking to skip over
1136 * any empty iovs
1137 */
1138 if (a_count) {
1139 if (a_count > a_uio->uio_iovs.uiovp->iov_len) {
1140 a_uio->uio_iovs.uiovp->iov_base += a_uio->uio_iovs.uiovp->iov_len;
1141 a_uio->uio_iovs.uiovp->iov_len = 0;
1142 }
1143 else {
1144 a_uio->uio_iovs.uiovp->iov_base += a_count;
1145 a_uio->uio_iovs.uiovp->iov_len -= a_count;
1146 }
1147 #if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
1148 if (a_uio->uio_resid < 0) {
1149 a_uio->uio_resid = 0;
1150 }
1151 if (a_count > (user_size_t)a_uio->uio_resid) {
1152 a_uio->uio_offset += a_uio->uio_resid;
1153 a_uio->uio_resid = 0;
1154 }
1155 else {
1156 a_uio->uio_offset += a_count;
1157 a_uio->uio_resid -= a_count;
1158 }
1159 #else
1160 if (a_uio->uio_resid_64 < 0) {
1161 a_uio->uio_resid_64 = 0;
1162 }
1163 if (a_count > (user_size_t)a_uio->uio_resid_64) {
1164 a_uio->uio_offset += a_uio->uio_resid_64;
1165 a_uio->uio_resid_64 = 0;
1166 }
1167 else {
1168 a_uio->uio_offset += a_count;
1169 a_uio->uio_resid_64 -= a_count;
1170 }
1171 #endif // LP64todo
1172 }
1173 /*
1174 * advance to next iovec if current one is totally consumed
1175 */
1176 while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.uiovp->iov_len == 0) {
1177 a_uio->uio_iovcnt--;
1178 if (a_uio->uio_iovcnt > 0) {
1179 a_uio->uio_iovs.uiovp++;
1180 }
1181 }
1182 }
1183 else {
1184 /*
1185 * if a_count == 0, then we are asking to skip over
1186 * any empty iovs
1187 */
1188 if (a_count) {
1189 if (a_count > a_uio->uio_iovs.kiovp->iov_len) {
1190 a_uio->uio_iovs.kiovp->iov_base += a_uio->uio_iovs.kiovp->iov_len;
1191 a_uio->uio_iovs.kiovp->iov_len = 0;
1192 }
1193 else {
1194 a_uio->uio_iovs.kiovp->iov_base += a_count;
1195 a_uio->uio_iovs.kiovp->iov_len -= a_count;
1196 }
1197 if (a_uio->uio_resid < 0) {
1198 a_uio->uio_resid = 0;
1199 }
1200 if (a_count > (user_size_t)a_uio->uio_resid) {
1201 a_uio->uio_offset += a_uio->uio_resid;
1202 a_uio->uio_resid = 0;
1203 }
1204 else {
1205 a_uio->uio_offset += a_count;
1206 a_uio->uio_resid -= a_count;
1207 }
1208 }
1209 /*
1210 * advance to next iovec if current one is totally consumed
1211 */
1212 while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.kiovp->iov_len == 0) {
1213 a_uio->uio_iovcnt--;
1214 if (a_uio->uio_iovcnt > 0) {
1215 a_uio->uio_iovs.kiovp++;
1216 }
1217 }
1218 }
1219 return;
1220 }
1221
1222
1223 /*
1224 * uio_duplicate - allocate a new uio and make a copy of the given uio_t.
1225 * may return NULL.
1226 */
1227 uio_t uio_duplicate( uio_t a_uio )
1228 {
1229 uio_t my_uio;
1230 int i;
1231
1232 if (a_uio == NULL) {
1233 return(NULL);
1234 }
1235
1236 my_uio = (uio_t) kalloc(a_uio->uio_size);
1237 if (my_uio == 0) {
1238 panic("%s :%d - allocation failed\n", __FILE__, __LINE__);
1239 }
1240
1241 bcopy((void *)a_uio, (void *)my_uio, a_uio->uio_size);
1242 /* need to set our iovec pointer to point to first active iovec */
1243 if (my_uio->uio_max_iovs > 0) {
1244 my_uio->uio_iovs.uiovp = (struct user_iovec *)
1245 (((uint8_t *)my_uio) + sizeof(struct uio));
1246
1247 /* advance to first nonzero iovec */
1248 if (my_uio->uio_iovcnt > 0) {
1249 for ( i = 0; i < my_uio->uio_max_iovs; i++ ) {
1250 if (UIO_IS_64_BIT_SPACE(a_uio)) {
1251 if (my_uio->uio_iovs.uiovp->iov_len != 0) {
1252 break;
1253 }
1254 my_uio->uio_iovs.uiovp++;
1255 }
1256 else {
1257 if (my_uio->uio_iovs.kiovp->iov_len != 0) {
1258 break;
1259 }
1260 my_uio->uio_iovs.kiovp++;
1261 }
1262 }
1263 }
1264 }
1265
1266 return(my_uio);
1267 }
1268