xref: /netbsd-src/share/man/man9/copy.9 (revision 08c81a9c2dc8c7300e893321eb65c0925d60871c)
1.\"	$NetBSD: copy.9,v 1.12 2002/07/20 03:58:26 thorpej Exp $
2.\"
3.\" Copyright (c) 1996, 2002 Jason R. Thorpe.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed by Kenneth Stailey.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed for the NetBSD Project
19.\"	by Jason R. Thorpe.
20.\" 4. The name of the author may not be used to endorse or promote products
21.\"    derived from this software without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.Dd July 19, 2002
36.Dt COPY 9
37.Os
38.Sh NAME
39.Nm copy ,
40.Nm copyin ,
41.Nm copyout ,
42.Nm copystr ,
43.Nm copyinstr ,
44.Nm copyoutstr
45.Nd kernel space to/from user space copy functions
46.Sh SYNOPSIS
47.Fd #include \*[Lt]sys/types.h\*[Gt]
48.Fd #include \*[Lt]sys/systm.h\*[Gt]
49.Ft int
50.Fn copyin "const void *uaddr" "void *kaddr" "size_t len"
51.Ft int
52.Fn copyout "const void *kaddr" "void *uaddr" "size_t len"
53.Ft int
54.Fn copystr "const void *kfaddr" "void *kdaddr" "size_t len" "size_t *done"
55.Ft int
56.Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done"
57.Ft int
58.Fn copyoutstr "const void *kaddr" "void *uaddr" "size_t len" "size_t *done"
59.Ft int
60.Fn copyin_proc "struct proc *p" "const void *uaddr" "void *kaddr" "size_t len"
61.Ft int
62.Fn copyout_proc "struct proc *p" "const void *kaddr" "void *uaddr" "size_t len"
63.Sh DESCRIPTION
64The
65.Nm
66functions are designed to copy contiguous data from one address
67to another.  All but
68.Fn copystr
69copy data from user-space to kernel-space or vice-versa.
70.Pp
71The
72.Nm
73routines provide the following functionality:
74.Bl -tag -width "copyout_proc()"
75.It Fn copyin
76Copies
77.Fa len
78bytes of data from the user-space address
79.Fa uaddr
80in the current process to the kernel-space address
81.Fa kaddr .
82.It Fn copyout
83Copies
84.Fa len
85bytes of data from the kernel-space address
86.Fa kaddr
87to the user-space address
88.Fa uaddr
89in the current process.
90.It Fn copystr
91Copies a NUL-terminated string, at most
92.Fa len
93bytes long, from kernel-space address
94.Fa kfaddr
95to kernel-space address
96.Fa kdaddr .
97If the
98.Fa done
99argument is non-NULL,
100the number of bytes actually copied, including the terminating
101NUL, is returned in
102.Fa *done .
103.It Fn copyinstr
104Copies a NUL-terminated string, at most
105.Fa len
106bytes long, from user-space address
107.Fa uaddr
108in the current process to kernel-space address
109.Fa kaddr .
110If the
111.Fa done
112argument is non-NULL,
113the number of bytes actually copied, including the terminating
114NUL, is returned in
115.Fa *done .
116.It Fn copyoutstr
117Copies a NUL-terminated string, at most
118.Fa len
119bytes long, from kernel-space address
120.Fa kaddr
121to user-space address
122.Fa uaddr
123in the current process.  If the
124.Fa done
125argument is non-NULL,
126the number of bytes actually copied, including the terminating
127NUL, is returned in
128.Fa *done .
129.It Fn copyin_proc
130Like
131.Fn copyin ,
132except it operates on the address space of the process
133.Fa p .
134.It Fn copyout_proc
135Like
136.Fn copyout ,
137except it operates on the address space of the process
138.Fa p .
139.El
140.Sh RETURN VALUES
141The
142.Nm
143functions return 0 on success or EFAULT if a bad address is encountered.
144In addition, the
145.Fn copystr ,
146.Fn copyinstr ,
147and
148.Fn copyoutstr
149functions return ENAMETOOLONG if the string is longer than
150.Fa len
151bytes.
152.Sh SEE ALSO
153.Xr fetch 9 ,
154.Xr store 9
155