2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
25 * Copyright (c) 1982, 1986, 1993, 1994
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * @(#)uio.h 8.5 (Berkeley) 2/22/94
59 #ifndef _SYS_UIO_INTERNAL_H_
60 #define _SYS_UIO_INTERNAL_H_
62 #include <sys/appleapiopts.h>
66 #include <sys/malloc.h>
69 * user / kernel address space type flags.
70 * WARNING - make sure to check when adding flags! Be sure new flags
71 * don't overlap the definitions in uio.h
73 // UIO_USERSPACE 0 defined in uio.h
74 #define UIO_USERISPACE 1
75 // UIO_SYSSPACE 2 defined in uio.h
76 #define UIO_PHYS_USERSPACE 3
77 #define UIO_PHYS_SYSSPACE 4
78 // UIO_USERSPACE32 5 defined in uio.h
79 #define UIO_USERISPACE32 6
80 #define UIO_PHYS_USERSPACE32 7
81 // UIO_USERSPACE64 8 defined in uio.h
82 #define UIO_USERISPACE64 9
83 #define UIO_PHYS_USERSPACE64 10
84 // UIO_SYSSPACE32 11 defined in uio.h
85 #define UIO_PHYS_SYSSPACE32 12
86 #define UIO_SYSSPACE64 13
87 #define UIO_PHYS_SYSSPACE64 14
92 // uio_iovsaddr was __private_extern__ temporary chnage for 3777436
93 struct user_iovec
* uio_iovsaddr( uio_t a_uio
);
94 __private_extern__
void uio_calculateresid( uio_t a_uio
);
95 __private_extern__
void uio_setcurriovlen( uio_t a_uio
, user_size_t a_value
);
96 // uio_spacetype was __private_extern__ temporary chnage for 3777436
97 int uio_spacetype( uio_t a_uio
);
98 __private_extern__ uio_t
99 uio_createwithbuffer( int a_iovcount
, off_t a_offset
, int a_spacetype
,
100 int a_iodirection
, void *a_buf_p
, int a_buffer_size
);
102 /* use kern_iovec for system space requests */
104 u_int32_t iov_base
; /* Base address. */
105 u_int32_t iov_len
; /* Length. */
108 /* use user_iovec for user space requests */
110 user_addr_t iov_base
; /* Base address. */
111 user_size_t iov_len
; /* Length. */
114 #if 1 // LP64todo - remove this after kext adopt new KPI
115 #define uio_iov uio_iovs.iovp
116 #define iovec_32 kern_iovec
117 #define iovec_64 user_iovec
124 struct kern_iovec
*kiovp
;
125 struct user_iovec
*uiovp
;
128 /* WARNING - use accessor calls for uio_iov and uio_resid since these */
129 /* fields vary depending on the originating address space. */
131 union iovecs uio_iovs
; /* current iovec */
132 int uio_iovcnt
; /* active iovecs */
134 int uio_resid
; /* compatibility uio_resid (pre-LP64) */
135 enum uio_seg uio_segflg
;
137 proc_t uio_procp
; /* obsolete - not used! */
138 user_ssize_t uio_resid_64
;
139 int uio_size
; /* size for use with kfree */
140 int uio_max_iovs
; /* max number of iovecs this uio_t can hold */
144 /* values for uio_flags */
145 #define UIO_FLAGS_INITED 0x00000001
146 #define UIO_FLAGS_WE_ALLOCED 0x00000002
151 * UIO_SIZEOF - return the amount of space a uio_t requires to
152 * contain the given number of iovecs. Use this macro to
153 * create a stack buffer that can be passed to uio_createwithbuffer.
155 #define UIO_SIZEOF( a_iovcount ) \
156 ( sizeof(struct uio) + (sizeof(struct user_iovec) * (a_iovcount)) )
158 #define UIO_IS_64_BIT_SPACE( a_uio_t ) \
159 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_USERISPACE64 || \
160 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_SYSSPACE64 || \
161 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE64 )
163 #define UIO_IS_32_BIT_SPACE( a_uio_t ) \
164 ( (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
165 (a_uio_t)->uio_segflg == UIO_SYSSPACE || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE || \
166 (a_uio_t)->uio_segflg == UIO_USERISPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
167 (a_uio_t)->uio_segflg == UIO_SYSSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE32 || \
168 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE || (a_uio_t)->uio_segflg == UIO_USERSPACE32 )
170 #define UIO_IS_USER_SPACE32( a_uio_t ) \
171 ( (a_uio_t)->uio_segflg == UIO_USERSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
172 (a_uio_t)->uio_segflg == UIO_USERISPACE32 )
173 #define UIO_IS_USER_SPACE64( a_uio_t ) \
174 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || \
175 (a_uio_t)->uio_segflg == UIO_USERISPACE64 )
176 #define UIO_IS_USER_SPACE( a_uio_t ) \
177 ( UIO_IS_USER_SPACE32((a_uio_t)) || UIO_IS_USER_SPACE64((a_uio_t)) || \
178 (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
179 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE )
183 * W A R N I N G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
184 * anything in this section will be removed. please move to the uio KPI
187 #if 1 // UIO_KPI - WARNING OBSOLETE!!!! LP64todo - remove these!!!!
189 #define IS_UIO_USER_SPACE32( segflg ) \
190 ( (segflg) == UIO_USERSPACE32 || (segflg) == UIO_PHYS_USERSPACE32 || \
191 (segflg) == UIO_USERISPACE32 )
192 #define IS_UIO_USER_SPACE64( segflg ) \
193 ( (segflg) == UIO_USERSPACE64 || (segflg) == UIO_PHYS_USERSPACE64 || \
194 (segflg) == UIO_USERISPACE64 )
195 #define IS_UIO_USER_SPACE( segflg ) \
196 ( IS_UIO_USER_SPACE32((segflg)) || IS_UIO_USER_SPACE64((segflg)) || \
197 (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
198 (segflg) == UIO_PHYS_USERSPACE )
200 #define IS_UIO_SYS_SPACE32( segflg ) \
201 ( (segflg) == UIO_SYSSPACE32 || (segflg) == UIO_PHYS_SYSSPACE32 || \
202 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_SYSSPACE )
203 #define IS_UIO_SYS_SPACE64( segflg ) \
204 ( (segflg) == UIO_SYSSPACE64 || (segflg) == UIO_PHYS_SYSSPACE64 )
205 #define IS_UIO_SYS_SPACE( segflg ) \
206 ( IS_UIO_SYS_SPACE32((segflg)) || IS_UIO_SYS_SPACE64((segflg)) )
208 #define IS_OBSOLETE_UIO_SEGFLG(segflg) \
209 ( (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
210 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_USERSPACE || \
211 (segflg) == UIO_PHYS_SYSSPACE )
212 #define IS_VALID_UIO_SEGFLG(segflg) \
213 ( IS_UIO_USER_SPACE((segflg)) || IS_UIO_SYS_SPACE((segflg)) )
215 /* accessor routines for uio and embedded iovecs */
216 // WARNING all these are OBSOLETE!!!!
217 static inline int64_t uio_uio_resid( struct uio
*a_uiop
);
218 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
);
219 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
);
221 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
);
222 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
223 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
);
224 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
225 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
);
226 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
);
227 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
);
228 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
);
229 static inline void uio_next_iov( struct uio
*a_uiop
);
230 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
);
231 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
);
234 static inline int64_t uio_uio_resid( struct uio
*a_uiop
)
236 //#warning obsolete - use uio_resid call
237 return( (int64_t)a_uiop
->uio_resid
);
240 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
)
242 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
243 a_uiop
->uio_resid
+= ((int32_t) a_amount
);
246 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
)
248 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
249 a_uiop
->uio_resid
= a_value
;
252 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
)
254 //#warning obsolete - use uio_curriovbase call
255 return(uio_iov_base_at(a_uiop
, 0));
258 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
)
260 //#warning obsolete - use uio_curriovbase call
261 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) || IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
262 /* user space iovec was most likely a struct iovec so we must cast to uintptr_t first */
263 return((u_int64_t
)((uintptr_t)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
));
265 if (IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
)) {
266 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
);
268 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
269 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
);
274 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
)
276 //#warning obsolete - use uio_curriovlen call
277 return(uio_iov_len_at(a_uiop
, 0));
280 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
)
282 //#warning obsolete - use uio_curriovlen call
283 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
284 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
285 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
286 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
);
288 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
289 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
);
294 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
)
296 //#warning obsolete - use uio_addiov call
297 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
298 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
299 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
300 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
= a_value
;
302 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
303 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
= a_value
;
308 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
)
310 //#warning obsolete - use uio_addiov call
311 return(uio_iov_len_set_at(a_uiop
, a_value
, 0));
314 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
316 //#warning obsolete - use uio_addiov call
317 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
318 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
319 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
320 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
+= ((int32_t) a_amount
);
322 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
323 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
+= a_amount
;
328 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
)
330 //#warning obsolete - use uio_addiov call
331 return(uio_iov_len_add_at(a_uiop
, a_amount
, 0));
334 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
336 //#warning obsolete - use uio_addiov call
337 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
338 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
339 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
340 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
+= ((int32_t) a_amount
);
342 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
343 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
+= a_amount
;
348 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
)
350 //#warning obsolete - use uio_addiov call
351 return(uio_iov_base_add_at(a_uiop
, a_amount
, 0));
354 static inline void uio_next_iov( struct uio
*a_uiop
)
356 //#warning obsolete - use uio_update call
357 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
358 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
359 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
360 a_uiop
->uio_iovs
.iov32p
++;
362 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
363 a_uiop
->uio_iovs
.iov64p
++;
369 * WARNING - this routine relies on iovec_64 being larger than iovec_32 and will
370 * not work if you are going to initialize an array of iovec_64 as an array of
371 * iovec_32 then pass that array in a uio (since uio_iov is always expected to
372 * be an array of like sized iovecs - see how uio_next_iov gets to the next iovec)
374 static inline void init_iovec( u_int64_t a_base
,
376 struct iovec_64
*a_iovp
,
377 int is_64bit_process
)
379 //#warning obsolete - use uio_create call
380 if (is_64bit_process
) {
381 a_iovp
->iov_base
= a_base
;
382 a_iovp
->iov_len
= a_len
;
385 struct iovec_32
*a_iov32p
= (struct iovec_32
*) a_iovp
;
386 a_iov32p
->iov_base
= a_base
;
387 a_iov32p
->iov_len
= a_len
;
392 #define INIT_UIO_BASE( uiop, iovcnt, offset, resid, rw, procp ) \
394 (uiop)->uio_iovcnt = (iovcnt); \
395 (uiop)->uio_offset = (offset); \
396 (uiop)->uio_resid = (resid); \
397 (uiop)->uio_rw = (rw); \
398 (uiop)->uio_procp = (procp); \
400 #define INIT_UIO_USER32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
402 (uiop)->uio_iovs.iov32p = (iovp); \
403 (uiop)->uio_segflg = UIO_USERSPACE; \
404 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
406 #define INIT_UIO_USER64( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
408 (uiop)->uio_iovs.iov64p = (iovp); \
409 (uiop)->uio_segflg = UIO_USERSPACE64; \
410 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
412 #define INIT_UIO_SYS32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
414 (uiop)->uio_iovs.iov32p = (iovp); \
415 (uiop)->uio_segflg = UIO_SYSSPACE; \
416 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
418 #define INIT_UIO_USERSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
420 if (IS_64BIT_PROCESS((procp))) { \
421 (uiop)->uio_iovs.iov64p = (iovp); \
422 (uiop)->uio_segflg = UIO_USERSPACE64; \
425 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
426 (uiop)->uio_segflg = UIO_USERSPACE; \
428 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
430 #define INIT_UIO_SYSSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
432 if (0) { /* we do not support 64-bit system space yet */ \
433 (uiop)->uio_iovs.iov64p = (iovp); \
434 (uiop)->uio_segflg = UIO_SYSSPACE64; \
437 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
438 (uiop)->uio_segflg = UIO_SYSSPACE; \
440 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
442 #endif // UIO_KPI - WARNING OBSOLETE!!!!
446 #endif /* !_SYS_UIO_INTERNAL_H_ */