2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1993, 1994
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)uio.h 8.5 (Berkeley) 2/22/94
58 #ifndef _SYS_UIO_INTERNAL_H_
59 #define _SYS_UIO_INTERNAL_H_
61 #include <sys/appleapiopts.h>
65 #include <sys/malloc.h>
68 * user / kernel address space type flags.
69 * WARNING - make sure to check when adding flags! Be sure new flags
70 * don't overlap the definitions in uio.h
72 // UIO_USERSPACE 0 defined in uio.h
73 #define UIO_USERISPACE 1
74 // UIO_SYSSPACE 2 defined in uio.h
75 #define UIO_PHYS_USERSPACE 3
76 #define UIO_PHYS_SYSSPACE 4
77 // UIO_USERSPACE32 5 defined in uio.h
78 #define UIO_USERISPACE32 6
79 #define UIO_PHYS_USERSPACE32 7
80 // UIO_USERSPACE64 8 defined in uio.h
81 #define UIO_USERISPACE64 9
82 #define UIO_PHYS_USERSPACE64 10
83 // UIO_SYSSPACE32 11 defined in uio.h
84 #define UIO_PHYS_SYSSPACE32 12
85 #define UIO_SYSSPACE64 13
86 #define UIO_PHYS_SYSSPACE64 14
91 // uio_iovsaddr was __private_extern__ temporary chnage for 3777436
92 struct user_iovec
* uio_iovsaddr( uio_t a_uio
);
93 __private_extern__
void uio_calculateresid( uio_t a_uio
);
94 __private_extern__
void uio_setcurriovlen( uio_t a_uio
, user_size_t a_value
);
95 // uio_spacetype was __private_extern__ temporary chnage for 3777436
96 int uio_spacetype( uio_t a_uio
);
97 __private_extern__ uio_t
98 uio_createwithbuffer( int a_iovcount
, off_t a_offset
, int a_spacetype
,
99 int a_iodirection
, void *a_buf_p
, int a_buffer_size
);
101 /* use kern_iovec for system space requests */
103 u_int32_t iov_base
; /* Base address. */
104 u_int32_t iov_len
; /* Length. */
107 /* use user_iovec for user space requests */
109 user_addr_t iov_base
; /* Base address. */
110 user_size_t iov_len
; /* Length. */
113 #if 1 // LP64todo - remove this after kext adopt new KPI
114 #define uio_iov uio_iovs.iovp
115 #define iovec_32 kern_iovec
116 #define iovec_64 user_iovec
123 struct kern_iovec
*kiovp
;
124 struct user_iovec
*uiovp
;
127 /* WARNING - use accessor calls for uio_iov and uio_resid since these */
128 /* fields vary depending on the originating address space. */
130 union iovecs uio_iovs
; /* current iovec */
131 int uio_iovcnt
; /* active iovecs */
133 int uio_resid
; /* compatibility uio_resid (pre-LP64) */
134 enum uio_seg uio_segflg
;
136 proc_t uio_procp
; /* obsolete - not used! */
137 user_ssize_t uio_resid_64
;
138 int uio_size
; /* size for use with kfree */
139 int uio_max_iovs
; /* max number of iovecs this uio_t can hold */
143 /* values for uio_flags */
144 #define UIO_FLAGS_INITED 0x00000001
145 #define UIO_FLAGS_WE_ALLOCED 0x00000002
150 * UIO_SIZEOF - return the amount of space a uio_t requires to
151 * contain the given number of iovecs. Use this macro to
152 * create a stack buffer that can be passed to uio_createwithbuffer.
154 #define UIO_SIZEOF( a_iovcount ) \
155 ( sizeof(struct uio) + (sizeof(struct user_iovec) * (a_iovcount)) )
157 #define UIO_IS_64_BIT_SPACE( a_uio_t ) \
158 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_USERISPACE64 || \
159 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_SYSSPACE64 || \
160 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE64 )
162 #define UIO_IS_32_BIT_SPACE( a_uio_t ) \
163 ( (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
164 (a_uio_t)->uio_segflg == UIO_SYSSPACE || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE || \
165 (a_uio_t)->uio_segflg == UIO_USERISPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
166 (a_uio_t)->uio_segflg == UIO_SYSSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE32 || \
167 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE || (a_uio_t)->uio_segflg == UIO_USERSPACE32 )
169 #define UIO_IS_USER_SPACE32( a_uio_t ) \
170 ( (a_uio_t)->uio_segflg == UIO_USERSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
171 (a_uio_t)->uio_segflg == UIO_USERISPACE32 )
172 #define UIO_IS_USER_SPACE64( a_uio_t ) \
173 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || \
174 (a_uio_t)->uio_segflg == UIO_USERISPACE64 )
175 #define UIO_IS_USER_SPACE( a_uio_t ) \
176 ( UIO_IS_USER_SPACE32((a_uio_t)) || UIO_IS_USER_SPACE64((a_uio_t)) || \
177 (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
178 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE )
182 * W A R N I N G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
183 * anything in this section will be removed. please move to the uio KPI
186 #if 1 // UIO_KPI - WARNING OBSOLETE!!!! LP64todo - remove these!!!!
188 #define IS_UIO_USER_SPACE32( segflg ) \
189 ( (segflg) == UIO_USERSPACE32 || (segflg) == UIO_PHYS_USERSPACE32 || \
190 (segflg) == UIO_USERISPACE32 )
191 #define IS_UIO_USER_SPACE64( segflg ) \
192 ( (segflg) == UIO_USERSPACE64 || (segflg) == UIO_PHYS_USERSPACE64 || \
193 (segflg) == UIO_USERISPACE64 )
194 #define IS_UIO_USER_SPACE( segflg ) \
195 ( IS_UIO_USER_SPACE32((segflg)) || IS_UIO_USER_SPACE64((segflg)) || \
196 (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
197 (segflg) == UIO_PHYS_USERSPACE )
199 #define IS_UIO_SYS_SPACE32( segflg ) \
200 ( (segflg) == UIO_SYSSPACE32 || (segflg) == UIO_PHYS_SYSSPACE32 || \
201 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_SYSSPACE )
202 #define IS_UIO_SYS_SPACE64( segflg ) \
203 ( (segflg) == UIO_SYSSPACE64 || (segflg) == UIO_PHYS_SYSSPACE64 )
204 #define IS_UIO_SYS_SPACE( segflg ) \
205 ( IS_UIO_SYS_SPACE32((segflg)) || IS_UIO_SYS_SPACE64((segflg)) )
207 #define IS_OBSOLETE_UIO_SEGFLG(segflg) \
208 ( (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
209 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_USERSPACE || \
210 (segflg) == UIO_PHYS_SYSSPACE )
211 #define IS_VALID_UIO_SEGFLG(segflg) \
212 ( IS_UIO_USER_SPACE((segflg)) || IS_UIO_SYS_SPACE((segflg)) )
214 /* accessor routines for uio and embedded iovecs */
215 // WARNING all these are OBSOLETE!!!!
216 static inline int64_t uio_uio_resid( struct uio
*a_uiop
);
217 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
);
218 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
);
220 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
);
221 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
222 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
);
223 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
224 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
);
225 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
);
226 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
);
227 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
);
228 static inline void uio_next_iov( struct uio
*a_uiop
);
229 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
);
230 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
);
233 static inline int64_t uio_uio_resid( struct uio
*a_uiop
)
235 //#warning obsolete - use uio_resid call
236 return( (int64_t)a_uiop
->uio_resid
);
239 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
)
241 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
242 a_uiop
->uio_resid
+= ((int32_t) a_amount
);
245 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
)
247 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
248 a_uiop
->uio_resid
= a_value
;
251 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
)
253 //#warning obsolete - use uio_curriovbase call
254 return(uio_iov_base_at(a_uiop
, 0));
257 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
)
259 //#warning obsolete - use uio_curriovbase call
260 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) || IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
261 /* user space iovec was most likely a struct iovec so we must cast to uintptr_t first */
262 return((u_int64_t
)((uintptr_t)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
));
264 if (IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
)) {
265 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
);
267 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
268 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
);
273 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
)
275 //#warning obsolete - use uio_curriovlen call
276 return(uio_iov_len_at(a_uiop
, 0));
279 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
)
281 //#warning obsolete - use uio_curriovlen call
282 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
283 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
284 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
285 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
);
287 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
288 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
);
293 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
)
295 //#warning obsolete - use uio_addiov call
296 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
297 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
298 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
299 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
= a_value
;
301 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
302 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
= a_value
;
307 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
)
309 //#warning obsolete - use uio_addiov call
310 return(uio_iov_len_set_at(a_uiop
, a_value
, 0));
313 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
315 //#warning obsolete - use uio_addiov call
316 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
317 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
318 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
319 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
+= ((int32_t) a_amount
);
321 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
322 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
+= a_amount
;
327 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
)
329 //#warning obsolete - use uio_addiov call
330 return(uio_iov_len_add_at(a_uiop
, a_amount
, 0));
333 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
335 //#warning obsolete - use uio_addiov call
336 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
337 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
338 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
339 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
+= ((int32_t) a_amount
);
341 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
342 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
+= a_amount
;
347 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
)
349 //#warning obsolete - use uio_addiov call
350 return(uio_iov_base_add_at(a_uiop
, a_amount
, 0));
353 static inline void uio_next_iov( struct uio
*a_uiop
)
355 //#warning obsolete - use uio_update call
356 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
357 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
358 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
359 a_uiop
->uio_iovs
.iov32p
++;
361 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
362 a_uiop
->uio_iovs
.iov64p
++;
368 * WARNING - this routine relies on iovec_64 being larger than iovec_32 and will
369 * not work if you are going to initialize an array of iovec_64 as an array of
370 * iovec_32 then pass that array in a uio (since uio_iov is always expected to
371 * be an array of like sized iovecs - see how uio_next_iov gets to the next iovec)
373 static inline void init_iovec( u_int64_t a_base
,
375 struct iovec_64
*a_iovp
,
376 int is_64bit_process
)
378 //#warning obsolete - use uio_create call
379 if (is_64bit_process
) {
380 a_iovp
->iov_base
= a_base
;
381 a_iovp
->iov_len
= a_len
;
384 struct iovec_32
*a_iov32p
= (struct iovec_32
*) a_iovp
;
385 a_iov32p
->iov_base
= a_base
;
386 a_iov32p
->iov_len
= a_len
;
391 #define INIT_UIO_BASE( uiop, iovcnt, offset, resid, rw, procp ) \
393 (uiop)->uio_iovcnt = (iovcnt); \
394 (uiop)->uio_offset = (offset); \
395 (uiop)->uio_resid = (resid); \
396 (uiop)->uio_rw = (rw); \
397 (uiop)->uio_procp = (procp); \
399 #define INIT_UIO_USER32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
401 (uiop)->uio_iovs.iov32p = (iovp); \
402 (uiop)->uio_segflg = UIO_USERSPACE; \
403 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
405 #define INIT_UIO_USER64( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
407 (uiop)->uio_iovs.iov64p = (iovp); \
408 (uiop)->uio_segflg = UIO_USERSPACE64; \
409 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
411 #define INIT_UIO_SYS32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
413 (uiop)->uio_iovs.iov32p = (iovp); \
414 (uiop)->uio_segflg = UIO_SYSSPACE; \
415 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
417 #define INIT_UIO_USERSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
419 if (IS_64BIT_PROCESS((procp))) { \
420 (uiop)->uio_iovs.iov64p = (iovp); \
421 (uiop)->uio_segflg = UIO_USERSPACE64; \
424 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
425 (uiop)->uio_segflg = UIO_USERSPACE; \
427 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
429 #define INIT_UIO_SYSSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
431 if (0) { /* we do not support 64-bit system space yet */ \
432 (uiop)->uio_iovs.iov64p = (iovp); \
433 (uiop)->uio_segflg = UIO_SYSSPACE64; \
436 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
437 (uiop)->uio_segflg = UIO_SYSSPACE; \
439 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
441 #endif // UIO_KPI - WARNING OBSOLETE!!!!
445 #endif /* !_SYS_UIO_INTERNAL_H_ */