2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1982, 1986, 1993, 1994
31 * The Regents of the University of California. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)uio.h 8.5 (Berkeley) 2/22/94
64 #ifndef _SYS_UIO_INTERNAL_H_
65 #define _SYS_UIO_INTERNAL_H_
67 #include <sys/appleapiopts.h>
71 #include <sys/malloc.h>
74 * user / kernel address space type flags.
75 * WARNING - make sure to check when adding flags! Be sure new flags
76 * don't overlap the definitions in uio.h
78 // UIO_USERSPACE 0 defined in uio.h
79 #define UIO_USERISPACE 1
80 // UIO_SYSSPACE 2 defined in uio.h
81 #define UIO_PHYS_USERSPACE 3
82 #define UIO_PHYS_SYSSPACE 4
83 // UIO_USERSPACE32 5 defined in uio.h
84 #define UIO_USERISPACE32 6
85 #define UIO_PHYS_USERSPACE32 7
86 // UIO_USERSPACE64 8 defined in uio.h
87 #define UIO_USERISPACE64 9
88 #define UIO_PHYS_USERSPACE64 10
89 // UIO_SYSSPACE32 11 defined in uio.h
90 #define UIO_PHYS_SYSSPACE32 12
91 #define UIO_SYSSPACE64 13
92 #define UIO_PHYS_SYSSPACE64 14
97 // uio_iovsaddr was __private_extern__ temporary chnage for 3777436
98 struct user_iovec
* uio_iovsaddr( uio_t a_uio
);
99 __private_extern__
void uio_calculateresid( uio_t a_uio
);
100 __private_extern__
void uio_setcurriovlen( uio_t a_uio
, user_size_t a_value
);
101 // uio_spacetype was __private_extern__ temporary chnage for 3777436
102 int uio_spacetype( uio_t a_uio
);
103 __private_extern__ uio_t
104 uio_createwithbuffer( int a_iovcount
, off_t a_offset
, int a_spacetype
,
105 int a_iodirection
, void *a_buf_p
, int a_buffer_size
);
107 /* use kern_iovec for system space requests */
109 u_int32_t iov_base
; /* Base address. */
110 u_int32_t iov_len
; /* Length. */
113 /* use user_iovec for user space requests */
115 user_addr_t iov_base
; /* Base address. */
116 user_size_t iov_len
; /* Length. */
119 #if 1 // LP64todo - remove this after kext adopt new KPI
120 #define uio_iov uio_iovs.iovp
121 #define iovec_32 kern_iovec
122 #define iovec_64 user_iovec
129 struct kern_iovec
*kiovp
;
130 struct user_iovec
*uiovp
;
133 /* WARNING - use accessor calls for uio_iov and uio_resid since these */
134 /* fields vary depending on the originating address space. */
136 union iovecs uio_iovs
; /* current iovec */
137 int uio_iovcnt
; /* active iovecs */
139 int uio_resid
; /* compatibility uio_resid (pre-LP64) */
140 enum uio_seg uio_segflg
;
142 proc_t uio_procp
; /* obsolete - not used! */
143 user_ssize_t uio_resid_64
;
144 int uio_size
; /* size for use with kfree */
145 int uio_max_iovs
; /* max number of iovecs this uio_t can hold */
149 /* values for uio_flags */
150 #define UIO_FLAGS_INITED 0x00000001
151 #define UIO_FLAGS_WE_ALLOCED 0x00000002
156 * UIO_SIZEOF - return the amount of space a uio_t requires to
157 * contain the given number of iovecs. Use this macro to
158 * create a stack buffer that can be passed to uio_createwithbuffer.
160 #define UIO_SIZEOF( a_iovcount ) \
161 ( sizeof(struct uio) + (sizeof(struct user_iovec) * (a_iovcount)) )
163 #define UIO_IS_64_BIT_SPACE( a_uio_t ) \
164 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_USERISPACE64 || \
165 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_SYSSPACE64 || \
166 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE64 )
168 #define UIO_IS_32_BIT_SPACE( a_uio_t ) \
169 ( (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
170 (a_uio_t)->uio_segflg == UIO_SYSSPACE || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE || \
171 (a_uio_t)->uio_segflg == UIO_USERISPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
172 (a_uio_t)->uio_segflg == UIO_SYSSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE32 || \
173 (a_uio_t)->uio_segflg == UIO_PHYS_SYSSPACE || (a_uio_t)->uio_segflg == UIO_USERSPACE32 )
175 #define UIO_IS_USER_SPACE32( a_uio_t ) \
176 ( (a_uio_t)->uio_segflg == UIO_USERSPACE32 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE32 || \
177 (a_uio_t)->uio_segflg == UIO_USERISPACE32 )
178 #define UIO_IS_USER_SPACE64( a_uio_t ) \
179 ( (a_uio_t)->uio_segflg == UIO_USERSPACE64 || (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE64 || \
180 (a_uio_t)->uio_segflg == UIO_USERISPACE64 )
181 #define UIO_IS_USER_SPACE( a_uio_t ) \
182 ( UIO_IS_USER_SPACE32((a_uio_t)) || UIO_IS_USER_SPACE64((a_uio_t)) || \
183 (a_uio_t)->uio_segflg == UIO_USERSPACE || (a_uio_t)->uio_segflg == UIO_USERISPACE || \
184 (a_uio_t)->uio_segflg == UIO_PHYS_USERSPACE )
188 * W A R N I N G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
189 * anything in this section will be removed. please move to the uio KPI
192 #if 1 // UIO_KPI - WARNING OBSOLETE!!!! LP64todo - remove these!!!!
194 #define IS_UIO_USER_SPACE32( segflg ) \
195 ( (segflg) == UIO_USERSPACE32 || (segflg) == UIO_PHYS_USERSPACE32 || \
196 (segflg) == UIO_USERISPACE32 )
197 #define IS_UIO_USER_SPACE64( segflg ) \
198 ( (segflg) == UIO_USERSPACE64 || (segflg) == UIO_PHYS_USERSPACE64 || \
199 (segflg) == UIO_USERISPACE64 )
200 #define IS_UIO_USER_SPACE( segflg ) \
201 ( IS_UIO_USER_SPACE32((segflg)) || IS_UIO_USER_SPACE64((segflg)) || \
202 (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
203 (segflg) == UIO_PHYS_USERSPACE )
205 #define IS_UIO_SYS_SPACE32( segflg ) \
206 ( (segflg) == UIO_SYSSPACE32 || (segflg) == UIO_PHYS_SYSSPACE32 || \
207 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_SYSSPACE )
208 #define IS_UIO_SYS_SPACE64( segflg ) \
209 ( (segflg) == UIO_SYSSPACE64 || (segflg) == UIO_PHYS_SYSSPACE64 )
210 #define IS_UIO_SYS_SPACE( segflg ) \
211 ( IS_UIO_SYS_SPACE32((segflg)) || IS_UIO_SYS_SPACE64((segflg)) )
213 #define IS_OBSOLETE_UIO_SEGFLG(segflg) \
214 ( (segflg) == UIO_USERSPACE || (segflg) == UIO_USERISPACE || \
215 (segflg) == UIO_SYSSPACE || (segflg) == UIO_PHYS_USERSPACE || \
216 (segflg) == UIO_PHYS_SYSSPACE )
217 #define IS_VALID_UIO_SEGFLG(segflg) \
218 ( IS_UIO_USER_SPACE((segflg)) || IS_UIO_SYS_SPACE((segflg)) )
220 /* accessor routines for uio and embedded iovecs */
221 // WARNING all these are OBSOLETE!!!!
222 static inline int64_t uio_uio_resid( struct uio
*a_uiop
);
223 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
);
224 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
);
226 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
);
227 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
228 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
);
229 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
);
230 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
);
231 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
);
232 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
);
233 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
);
234 static inline void uio_next_iov( struct uio
*a_uiop
);
235 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
);
236 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
);
239 static inline int64_t uio_uio_resid( struct uio
*a_uiop
)
241 //#warning obsolete - use uio_resid call
242 return( (int64_t)a_uiop
->uio_resid
);
245 static inline void uio_uio_resid_add( struct uio
*a_uiop
, int64_t a_amount
)
247 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
248 a_uiop
->uio_resid
+= ((int32_t) a_amount
);
251 static inline void uio_uio_resid_set( struct uio
*a_uiop
, int64_t a_value
)
253 //#warning obsolete - use uio_update or uio_addiov or uio_setresid if in kernel and you must
254 a_uiop
->uio_resid
= a_value
;
257 static inline u_int64_t
uio_iov_base( struct uio
*a_uiop
)
259 //#warning obsolete - use uio_curriovbase call
260 return(uio_iov_base_at(a_uiop
, 0));
263 static inline u_int64_t
uio_iov_base_at( struct uio
*a_uiop
, int a_index
)
265 //#warning obsolete - use uio_curriovbase call
266 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) || IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
267 /* user space iovec was most likely a struct iovec so we must cast to uintptr_t first */
268 return((u_int64_t
)((uintptr_t)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
));
270 if (IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
)) {
271 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
);
273 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
274 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
);
279 static inline u_int64_t
uio_iov_len( struct uio
*a_uiop
)
281 //#warning obsolete - use uio_curriovlen call
282 return(uio_iov_len_at(a_uiop
, 0));
285 static inline u_int64_t
uio_iov_len_at( struct uio
*a_uiop
, int a_index
)
287 //#warning obsolete - use uio_curriovlen call
288 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
289 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
290 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
291 return((u_int64_t
)a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
);
293 if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
294 return(a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
);
299 static inline void uio_iov_len_set_at( struct uio
*a_uiop
, u_int64_t a_value
, int a_index
)
301 //#warning obsolete - use uio_addiov call
302 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
303 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
304 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
305 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
= a_value
;
307 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
308 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
= a_value
;
313 static inline void uio_iov_len_set( struct uio
*a_uiop
, u_int64_t a_value
)
315 //#warning obsolete - use uio_addiov call
316 return(uio_iov_len_set_at(a_uiop
, a_value
, 0));
319 static inline void uio_iov_len_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
321 //#warning obsolete - use uio_addiov call
322 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
323 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
324 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
325 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_len
+= ((int32_t) a_amount
);
327 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
328 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_len
+= a_amount
;
333 static inline void uio_iov_len_add( struct uio
*a_uiop
, int64_t a_amount
)
335 //#warning obsolete - use uio_addiov call
336 return(uio_iov_len_add_at(a_uiop
, a_amount
, 0));
339 static inline void uio_iov_base_add_at( struct uio
*a_uiop
, int64_t a_amount
, int a_index
)
341 //#warning obsolete - use uio_addiov call
342 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
343 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
344 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
345 a_uiop
->uio_iovs
.iov32p
[a_index
].iov_base
+= ((int32_t) a_amount
);
347 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
348 a_uiop
->uio_iovs
.iov64p
[a_index
].iov_base
+= a_amount
;
353 static inline void uio_iov_base_add( struct uio
*a_uiop
, int64_t a_amount
)
355 //#warning obsolete - use uio_addiov call
356 return(uio_iov_base_add_at(a_uiop
, a_amount
, 0));
359 static inline void uio_next_iov( struct uio
*a_uiop
)
361 //#warning obsolete - use uio_update call
362 if (IS_UIO_USER_SPACE32(a_uiop
->uio_segflg
) ||
363 IS_UIO_SYS_SPACE32(a_uiop
->uio_segflg
) ||
364 IS_OBSOLETE_UIO_SEGFLG(a_uiop
->uio_segflg
)) {
365 a_uiop
->uio_iovs
.iov32p
++;
367 else if (IS_UIO_USER_SPACE64(a_uiop
->uio_segflg
) || IS_UIO_SYS_SPACE64(a_uiop
->uio_segflg
)) {
368 a_uiop
->uio_iovs
.iov64p
++;
374 * WARNING - this routine relies on iovec_64 being larger than iovec_32 and will
375 * not work if you are going to initialize an array of iovec_64 as an array of
376 * iovec_32 then pass that array in a uio (since uio_iov is always expected to
377 * be an array of like sized iovecs - see how uio_next_iov gets to the next iovec)
379 static inline void init_iovec( u_int64_t a_base
,
381 struct iovec_64
*a_iovp
,
382 int is_64bit_process
)
384 //#warning obsolete - use uio_create call
385 if (is_64bit_process
) {
386 a_iovp
->iov_base
= a_base
;
387 a_iovp
->iov_len
= a_len
;
390 struct iovec_32
*a_iov32p
= (struct iovec_32
*) a_iovp
;
391 a_iov32p
->iov_base
= a_base
;
392 a_iov32p
->iov_len
= a_len
;
397 #define INIT_UIO_BASE( uiop, iovcnt, offset, resid, rw, procp ) \
399 (uiop)->uio_iovcnt = (iovcnt); \
400 (uiop)->uio_offset = (offset); \
401 (uiop)->uio_resid = (resid); \
402 (uiop)->uio_rw = (rw); \
403 (uiop)->uio_procp = (procp); \
405 #define INIT_UIO_USER32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
407 (uiop)->uio_iovs.iov32p = (iovp); \
408 (uiop)->uio_segflg = UIO_USERSPACE; \
409 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
411 #define INIT_UIO_USER64( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
413 (uiop)->uio_iovs.iov64p = (iovp); \
414 (uiop)->uio_segflg = UIO_USERSPACE64; \
415 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
417 #define INIT_UIO_SYS32( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
419 (uiop)->uio_iovs.iov32p = (iovp); \
420 (uiop)->uio_segflg = UIO_SYSSPACE; \
421 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
423 #define INIT_UIO_USERSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
425 if (IS_64BIT_PROCESS((procp))) { \
426 (uiop)->uio_iovs.iov64p = (iovp); \
427 (uiop)->uio_segflg = UIO_USERSPACE64; \
430 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
431 (uiop)->uio_segflg = UIO_USERSPACE; \
433 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
435 #define INIT_UIO_SYSSPACE( uiop, iovp, iovcnt, offset, resid, rw, procp ) \
437 if (0) { /* we do not support 64-bit system space yet */ \
438 (uiop)->uio_iovs.iov64p = (iovp); \
439 (uiop)->uio_segflg = UIO_SYSSPACE64; \
442 (uiop)->uio_iovs.iov32p = (struct iovec_32 *)(iovp); \
443 (uiop)->uio_segflg = UIO_SYSSPACE; \
445 INIT_UIO_BASE((uiop), (iovcnt), (offset), (resid), (rw), (procp)); \
447 #endif // UIO_KPI - WARNING OBSOLETE!!!!
451 #endif /* !_SYS_UIO_INTERNAL_H_ */