X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..d190cdc3f5544636abb56dc1874be391d3e1b148:/bsd/sys/uio.h diff --git a/bsd/sys/uio.h b/bsd/sys/uio.h index 11b8e75a6..84f9f690b 100644 --- a/bsd/sys/uio.h +++ b/bsd/sys/uio.h @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2008 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ /* @@ -61,54 +64,198 @@ #ifndef _SYS_UIO_H_ #define _SYS_UIO_H_ +#include +#include + /* - * XXX - * iov_base should be a void *. + * [XSI] The ssize_t and size_t types shall be defined as described + * in . */ -struct iovec { - char *iov_base; /* Base address. */ - size_t iov_len; /* Length. */ -}; +#include +#include -enum uio_rw { UIO_READ, UIO_WRITE }; +/* + * [XSI] Structure whose address is passed as the second parameter to the + * readv() and writev() functions. + */ +#include -/* Segment flag values. */ -enum uio_seg { - UIO_USERSPACE, /* from user data space */ - UIO_USERISPACE, /* from user I space */ - UIO_SYSSPACE, /* from system space */ - UIO_PHYS_USERSPACE /* kernel address is physical, to/from user data space */ -}; + +#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) +/* + * IO direction for uio_t. + * UIO_READ - data moves into iovec(s) associated with uio_t + * UIO_WRITE - data moves out of iovec(s) associated with uio_t + */ +enum uio_rw { UIO_READ, UIO_WRITE }; +#endif #ifdef KERNEL -struct uio { - struct iovec *uio_iov; - int uio_iovcnt; - off_t uio_offset; - int uio_resid; - enum uio_seg uio_segflg; - enum uio_rw uio_rw; - struct proc *uio_procp; + +/* + * XXX This all really wants a uio_internal.h + */ + +#include + + +/* + * user / kernel address space type flags. + * WARNING - make sure to check when adding flags! Be sure new flags + * don't overlap the definitions in uio_internal.h + * NOTES - + * UIO_USERSPACE is equivalent to UIO_USERSPACE32, but UIO_USERSPACE32 + * is preferred. UIO_USERSPACE remains for backwards compatibility. + * UIO_SYSSPACE is equivalent to UIO_SYSSPACE32, but UIO_SYSSPACE + * is preferred. + */ +enum uio_seg { + UIO_USERSPACE = 0, /* kernel address is virtual, to/from user virtual */ + UIO_SYSSPACE = 2, /* kernel address is virtual, to/from system virtual */ + UIO_USERSPACE32 = 5, /* kernel address is virtual, to/from user 32-bit virtual */ + UIO_USERSPACE64 = 8, /* kernel address is virtual, to/from user 64-bit virtual */ + UIO_SYSSPACE32 = 11 /* deprecated */ }; +#define UIO_SEG_IS_USER_SPACE( a_uio_seg ) \ + ( (a_uio_seg) == UIO_USERSPACE64 || (a_uio_seg) == UIO_USERSPACE32 || \ + (a_uio_seg) == UIO_USERSPACE ) + + +__BEGIN_DECLS + +/* + * uio_create - create an uio_t. + * Space is allocated to hold up to a_iovcount number of iovecs. The uio_t + * is not fully initialized until all iovecs are added using uio_addiov calls. + * a_iovcount is the maximum number of iovecs you may add. + */ +uio_t uio_create( int a_iovcount, /* max number of iovecs */ + off_t a_offset, /* current offset */ + int a_spacetype, /* type of address space */ + int a_iodirection ); /* read or write flag */ + +/* + * uio_reset - reset an uio_t. + * Reset the given uio_t to initial values. The uio_t is not fully initialized + * until all iovecs are added using uio_add_ov calls. + * The a_iovcount value passed in the uio_create is the maximum number of + * iovecs you may add. + */ +void uio_reset( uio_t a_uio, + off_t a_offset, /* current offset */ + int a_spacetype, /* type of address space */ + int a_iodirection ); /* read or write flag */ + +/* + * uio_duplicate - allocate a new uio and make a copy of the given uio_t. + * may return NULL. + */ +uio_t uio_duplicate( uio_t a_uio ); + + +/* + * uio_free - free a uio_t allocated via uio_create. + */ +void uio_free( uio_t a_uio ); + +/* + * uio_addiov - add an iovec to the given uio_t. You may call this up to + * the a_iovcount number that was passed to uio_create. + * returns 0 if add was successful else non zero. + */ +int uio_addiov( uio_t a_uio, user_addr_t a_baseaddr, user_size_t a_length ); + +/* + * uio_getiov - get iovec data associated with the given uio_t. Use + * a_index to iterate over each iovec (0 to (uio_iovcnt(uio_t) - 1)). + * a_baseaddr_p and a_length_p may be NULL. + * returns -1 when a_index is out of range or invalid uio_t. + * returns 0 when data is returned. + */ +int uio_getiov( uio_t a_uio, + int a_index, + user_addr_t * a_baseaddr_p, + user_size_t * a_length_p ); + +/* + * uio_update - update the given uio_t for a_count of completed IO. + * This call adjusts decrements the current iovec length and residual IO, + * and increments the current iovec base address and offset value. + */ +void uio_update( uio_t a_uio, user_size_t a_count ); + +/* + * uio_resid - return the residual IO value for the given uio_t + */ +user_ssize_t uio_resid( uio_t a_uio ); + +/* + * uio_setresid - set the residual IO value for the given uio_t + */ +void uio_setresid( uio_t a_uio, user_ssize_t a_value ); + +/* + * uio_iovcnt - return count of active iovecs for the given uio_t + */ +int uio_iovcnt( uio_t a_uio ); + +/* + * uio_offset - return the current offset value for the given uio_t + */ +off_t uio_offset( uio_t a_uio ); + +/* + * uio_setoffset - set the current offset value for the given uio_t + */ +void uio_setoffset( uio_t a_uio, off_t a_offset ); + +/* + * uio_rw - return the read / write flag for the given uio_t + */ +int uio_rw( uio_t a_uio ); + +/* + * uio_setrw - set the read / write flag for the given uio_t + */ +void uio_setrw( uio_t a_uio, int a_value ); + +/* + * uio_isuserspace - return non zero value if the address space + * flag is for a user address space (could be 32 or 64 bit). + */ +int uio_isuserspace( uio_t a_uio ); + +/* + * uio_curriovbase - return the base address of the current iovec associated + * with the given uio_t. May return 0. + */ +user_addr_t uio_curriovbase( uio_t a_uio ); + +/* + * uio_curriovlen - return the length value of the current iovec associated + * with the given uio_t. + */ +user_size_t uio_curriovlen( uio_t a_uio ); + /* * Limits */ #define UIO_MAXIOV 1024 /* max 1K of iov's */ #define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ -extern int uiomove __P((caddr_t cp, int n, struct uio *uio)); -extern int ureadc __P((int c, struct uio *uio)); -extern int uwritec __P((struct uio *uio)); +extern int uiomove(const char * cp, int n, struct uio *uio); +extern int uiomove64(const __uint64_t cp, int n, struct uio *uio); +__END_DECLS #endif /* KERNEL */ #ifndef KERNEL -#include __BEGIN_DECLS -ssize_t readv __P((int, const struct iovec *, int)); -ssize_t writev __P((int, const struct iovec *, int)); +ssize_t readv(int, const struct iovec *, int) __DARWIN_ALIAS_C(readv); +ssize_t writev(int, const struct iovec *, int) __DARWIN_ALIAS_C(writev); __END_DECLS #endif /* !KERNEL */ + #endif /* !_SYS_UIO_H_ */