1*8bff8a49Smiod.\" $OpenBSD: copy.9,v 1.18 2023/01/06 19:10:18 miod Exp $ 223005153Sderaadt.\" $NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $ 323005153Sderaadt.\" 423005153Sderaadt.\" Copyright (c) 1996 Jason R. Thorpe. 523005153Sderaadt.\" All rights reserved. 623005153Sderaadt.\" 723005153Sderaadt.\" This code is derived from software contributed by Kenneth Stailey. 823005153Sderaadt.\" 923005153Sderaadt.\" Redistribution and use in source and binary forms, with or without 1023005153Sderaadt.\" modification, are permitted provided that the following conditions 1123005153Sderaadt.\" are met: 1223005153Sderaadt.\" 1. Redistributions of source code must retain the above copyright 1323005153Sderaadt.\" notice, this list of conditions and the following disclaimer. 1423005153Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright 1523005153Sderaadt.\" notice, this list of conditions and the following disclaimer in the 1623005153Sderaadt.\" documentation and/or other materials provided with the distribution. 1723005153Sderaadt.\" 3. All advertising materials mentioning features or use of this software 1823005153Sderaadt.\" must display the following acknowledgement: 1923005153Sderaadt.\" This product includes software developed for the NetBSD Project 2023005153Sderaadt.\" by Jason R. Thorpe. 2123005153Sderaadt.\" 4. The name of the author may not be used to endorse or promote products 2223005153Sderaadt.\" derived from this software without specific prior written permission. 2323005153Sderaadt.\" 2423005153Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2523005153Sderaadt.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2623005153Sderaadt.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2723005153Sderaadt.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2823005153Sderaadt.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2923005153Sderaadt.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 3023005153Sderaadt.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 3123005153Sderaadt.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 3223005153Sderaadt.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3323005153Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3423005153Sderaadt.\" SUCH DAMAGE. 3523005153Sderaadt.\" 36*8bff8a49Smiod.Dd $Mdocdate: January 6 2023 $ 3733378d91Sjmc.Dt COPYIN 9 38fc8533a3Saaron.Os 3923005153Sderaadt.Sh NAME 4033378d91Sjmc.Nm copyin , 4133378d91Sjmc.Nm copyout , 4233378d91Sjmc.Nm copyinstr , 4333378d91Sjmc.Nm copyoutstr , 4433378d91Sjmc.Nm kcopy 4523005153Sderaadt.Nd kernel copy functions 4623005153Sderaadt.Sh SYNOPSIS 47dddd2645Sschwarze.In sys/types.h 48dddd2645Sschwarze.In sys/systm.h 4923005153Sderaadt.Ft int 50e89fa910Skevlo.Fn copyin "const void *uaddr" "void *kaddr" "size_t len" 5123005153Sderaadt.Ft int 52e89fa910Skevlo.Fn copyout "const void *kaddr" "void *uaddr" "size_t len" 5323005153Sderaadt.Ft int 54e89fa910Skevlo.Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done" 5523005153Sderaadt.Ft int 56e89fa910Skevlo.Fn copyoutstr "const void *kaddr" "void *uaddr" "size_t len" "size_t *done" 57d437321aSmatthew.Ft int 58d437321aSmatthew.Fn kcopy "const void *kfaddr" "void *kdaddr" "size_t len" 5923005153Sderaadt.Sh DESCRIPTION 6023005153SderaadtThe 6123005153Sderaadt.Nm 62ab967380Saaronfunctions are designed to copy contiguous data from one address to another. 63ab967380SaaronAll but 64d437321aSmatthew.Fn kcopy 6523005153Sderaadtcopy data from user-space to kernel-space or vice-versa. 6623005153Sderaadt.Pp 6723005153SderaadtThe 6823005153Sderaadt.Nm 6923005153Sderaadtroutines provide the following functionality: 7023005153Sderaadt.Bl -tag -width "copyoutstr()" 7123005153Sderaadt.It Fn copyin 7223005153SderaadtCopies 73657686c6Sespie.Fa len 7423005153Sderaadtbytes of data from the user-space address 75657686c6Sespie.Fa uaddr 7623005153Sderaadtto the kernel-space address 77657686c6Sespie.Fa kaddr . 7823005153Sderaadt.It Fn copyout 7923005153SderaadtCopies 80657686c6Sespie.Fa len 8123005153Sderaadtbytes of data from the kernel-space address 82657686c6Sespie.Fa kaddr 8323005153Sderaadtto the user-space address 84657686c6Sespie.Fa uaddr . 8523005153Sderaadt.It Fn copyinstr 86fae1d0f6SaaronCopies a null-terminated string, at most 87657686c6Sespie.Fa len 8823005153Sderaadtbytes long, from user-space address 89657686c6Sespie.Fa uaddr 9023005153Sderaadtto kernel-space address 91657686c6Sespie.Fa kaddr . 92fae1d0f6SaaronThe number of bytes actually copied, including the terminating null, 93fae1d0f6Saaronis returned in 94c53ab5e5Sjmc.Fa *done , 95c53ab5e5Sjmcif 96c53ab5e5Sjmc.Fa done 97c53ab5e5Sjmcis not 98c53ab5e5Sjmc.Dv NULL . 9923005153Sderaadt.It Fn copyoutstr 100fae1d0f6SaaronCopies a null-terminated string, at most 1019a9836b3Sjj.Fa len 10223005153Sderaadtbytes long, from kernel-space address 103657686c6Sespie.Fa kaddr 10423005153Sderaadtto user-space address 105657686c6Sespie.Fa uaddr . 106fae1d0f6SaaronThe number of bytes actually copied, including the terminating null, 107fae1d0f6Saaronis returned in 108c53ab5e5Sjmc.Fa *done , 109c53ab5e5Sjmcif 110c53ab5e5Sjmc.Fa done 111c53ab5e5Sjmcis not 112c53ab5e5Sjmc.Dv NULL . 113d437321aSmatthew.It Fn kcopy 114d437321aSmatthewCopies 115d437321aSmatthew.Fa len 116d437321aSmatthewbytes of data from the kernel-space address 117d437321aSmatthew.Fa kfaddr 118d437321aSmatthewto the kernel-space address 119d437321aSmatthew.Fa kdaddr . 12023005153Sderaadt.El 12123005153Sderaadt.Sh RETURN VALUES 12223005153SderaadtThe 12323005153Sderaadt.Nm 124fae1d0f6Saaronfunctions return 0 on success or 125fae1d0f6Saaron.Er EFAULT 126fae1d0f6Saaronif a bad address is encountered. 12723005153SderaadtIn addition, the 128*8bff8a49Smiod.Fn copyinstr 12923005153Sderaadtand 13023005153Sderaadt.Fn copyoutstr 131fae1d0f6Saaronfunctions return 132fae1d0f6Saaron.Er ENAMETOOLONG 133fae1d0f6Saaronif the string is longer than 134657686c6Sespie.Fa len 13523005153Sderaadtbytes. 136c0a75849Smiod.\" .Sh SEE ALSO 137