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