]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man9/copy.9
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / man / man9 / copy.9
CommitLineData
b0d623f7
A
1.\"
2.\" Copyright (c) 2008 Apple Inc. All rights reserved.
3.\"
4.\" @APPLE_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. Please obtain a copy of the License at
10.\" http://www.opensource.apple.com/apsl/ and read it before using this
11.\" file.
12.\"
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.
20.\"
21.\" @APPLE_LICENSE_HEADER_END@
22.\"
23.\"
9bccf70c
A
24.\" $NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $
25.\"
26.\" Copyright (c) 1996 Jason R. Thorpe.
27.\" All rights reserved.
28.\"
29.\" This code is derived from software contributed by Kenneth Stailey.
30.\"
31.\" Redistribution and use in source and binary forms, with or without
32.\" modification, are permitted provided that the following conditions
33.\" are met:
34.\" 1. Redistributions of source code must retain the above copyright
35.\" notice, this list of conditions and the following disclaimer.
36.\" 2. Redistributions in binary form must reproduce the above copyright
37.\" notice, this list of conditions and the following disclaimer in the
38.\" documentation and/or other materials provided with the distribution.
39.\" 3. All advertising materials mentioning features or use of this software
40.\" must display the following acknowledgement:
41.\" This product includes software developed for the NetBSD Project
42.\" by Jason R. Thorpe.
43.\" 4. The name of the author may not be used to endorse or promote products
44.\" derived from this software without specific prior written permission.
45.\"
46.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
51.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
53.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56.\" SUCH DAMAGE.
57.\"
58.\" $FreeBSD: src/share/man/man9/copy.9,v 1.6.2.5 2001/12/17 11:30:18 ru Exp $
59.\"
b0d623f7 60.Dd October 2, 2008
9bccf70c
A
61.Dt COPY 9
62.Os
63.Sh NAME
64.Nm copy ,
65.Nm copyin ,
2d21ac55 66.Nm copyinstr ,
9bccf70c 67.Nm copyout ,
2d21ac55 68.Nm copystr
9bccf70c
A
69.Nd kernel copy functions
70.Sh SYNOPSIS
71.In sys/types.h
72.In sys/systm.h
73.Ft int
2d21ac55
A
74.Fo copyin
75.Fa "const void *uaddr"
76.Fa "void *kaddr"
77.Fa "size_t len"
78.Fc
9bccf70c 79.Ft int
2d21ac55
A
80.Fo copyinstr
81.Fa "const void *uaddr"
82.Fa "void *kaddr"
83.Fa "size_t len"
84.Fa "size_t *done"
85.Fc
9bccf70c 86.Ft int
2d21ac55
A
87.Fo copyout
88.Fa "const void *kaddr"
89.Fa "void *uaddr"
90.Fa "size_t len"
91.Fc
9bccf70c 92.\" .Ft int
2d21ac55
A
93.\" .Fn copyoutstr
94.\" .Fa "const void *kaddr"
95.\" .Fa "void *uaddr"
96.\" .Fa "size_t len"
97.\" .Fa "size_t *done"
98.\" .Fc
99.Ft int
100.Fo copystr
101.Fa "const void *kfaddr"
102.Fa "void *kdaddr"
103.Fa "size_t len"
104.Fa "size_t *done"
105.Fc
9bccf70c
A
106.Sh DESCRIPTION
107The
108.Nm
109functions are designed to copy contiguous data from one address
110to another. All but
111.Fn copystr
112copy data from user-space to kernel-space or vice-versa.
113.Pp
114The
115.Nm
116routines provide the following functionality:
117.Bl -tag -width "copyoutstr()"
2d21ac55 118.\" ========
9bccf70c
A
119.It Fn copyin
120Copies
121.Pa len
122bytes of data from the user-space address
123.Pa uaddr
124to the kernel-space address
125.Pa kaddr .
2d21ac55 126.\" ========
9bccf70c
A
127.It Fn copyinstr
128Copies a NUL-terminated string, at most
129.Pa len
130bytes long, from user-space address
131.Pa uaddr
132to kernel-space address
133.Pa kaddr .
134The number of bytes actually copied, including the terminating
135NUL, is returned in
136.Pa *done .
2d21ac55
A
137.\" ========
138.It Fn copyout
139Copies
140.Pa len
141bytes of data from the kernel-space address
142.Pa kaddr
143to the user-space address
144.Pa uaddr .
145.\" ========
9bccf70c
A
146.\" .It Fn copyoutstr
147.\" Copies a NUL-terminated string, at most
148.\" bytes long, from kernel-space address
149.\" .Pa kaddr
150.\" to user-space address
151.\" .Pa uaddr .
152.\" The number of bytes actually copied, including the terminating
153.\" NUL, is returned in
154.\" .Pa *done .
2d21ac55
A
155.\" ========
156.It Fn copystr
157Copies a NUL-terminated string, at most
158.Pa len
159bytes long, from kernel-space address
160.Pa kfaddr
161to kernel-space address
162.Pa kdaddr .
163The number of bytes actually copied, including the terminating
164NUL, is returned in
165.Pa *done .
9bccf70c
A
166.El
167.Sh RETURN VALUES
168The
169.Nm
b0d623f7
A
170functions return 0 on success or the following error on failure:
171.\" ========
172.Bl -tag -width Er
173.It Bq EFAULT
174If a bad address is encountered. When this error is returned, the contents of the destination buffer (
175.Fa *kaddr
176for
177.Fn copyin ,
178.Fn copyinstr ,
9bccf70c 179and
b0d623f7
A
180.Fn copystr ;
181.Fa *uaddr
182for
183.Fn copyout )
184are undefined. For
9bccf70c 185.Fn copyinstr
b0d623f7
A
186and
187.Fn copystr ,
188the contents of the
189.Fa *done
190parameter are also undefined on a return of EFAULT.
191.El
192.Pp
193In addition to EFAULT,
194.\" .Fn copystr ,
9bccf70c
A
195.\" .Fn copyinstr ,
196.\" and
197.\" .Fn copyoutstr
b0d623f7
A
198.Fn copystr
199and
200.Fn copyinstr
201on failure will return:
202.\" ========
203.Bl -tag -width Er
204.It Bq ENAMETOLONG
205When the string is longer than
9bccf70c 206.Pa len
b0d623f7
A
207bytes. On this error return, the destination buffer is not null-terminated, but the
208.Fa *done
209parameter is maintained.
210.EL
9bccf70c
A
211.Sh SEE ALSO
212.Xr fetch 9 ,
213.Xr store 9