15406291aSMike Pritchard.\" $NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $ 25406291aSMike Pritchard.\" 35406291aSMike Pritchard.\" Copyright (c) 1996 Jason R. Thorpe. 45406291aSMike Pritchard.\" All rights reserved. 55406291aSMike Pritchard.\" 65406291aSMike Pritchard.\" This code is derived from software contributed by Kenneth Stailey. 75406291aSMike Pritchard.\" 85406291aSMike Pritchard.\" Redistribution and use in source and binary forms, with or without 95406291aSMike Pritchard.\" modification, are permitted provided that the following conditions 105406291aSMike Pritchard.\" are met: 115406291aSMike Pritchard.\" 1. Redistributions of source code must retain the above copyright 125406291aSMike Pritchard.\" notice, this list of conditions and the following disclaimer. 135406291aSMike Pritchard.\" 2. Redistributions in binary form must reproduce the above copyright 145406291aSMike Pritchard.\" notice, this list of conditions and the following disclaimer in the 155406291aSMike Pritchard.\" documentation and/or other materials provided with the distribution. 165406291aSMike Pritchard.\" 3. All advertising materials mentioning features or use of this software 175406291aSMike Pritchard.\" must display the following acknowledgement: 185406291aSMike Pritchard.\" This product includes software developed for the NetBSD Project 195406291aSMike Pritchard.\" by Jason R. Thorpe. 205406291aSMike Pritchard.\" 4. The name of the author may not be used to endorse or promote products 215406291aSMike Pritchard.\" derived from this software without specific prior written permission. 225406291aSMike Pritchard.\" 235406291aSMike Pritchard.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 245406291aSMike Pritchard.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 255406291aSMike Pritchard.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 265406291aSMike Pritchard.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 275406291aSMike Pritchard.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 285406291aSMike Pritchard.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 295406291aSMike Pritchard.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 305406291aSMike Pritchard.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 315406291aSMike Pritchard.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 325406291aSMike Pritchard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 335406291aSMike Pritchard.\" SUCH DAMAGE. 345406291aSMike Pritchard.\" 35*294b75a8SConrad Meyer.Dd May 11, 2020 365406291aSMike Pritchard.Dt COPY 9 373d45e180SRuslan Ermilov.Os 385406291aSMike Pritchard.Sh NAME 395406291aSMike Pritchard.Nm copy , 405406291aSMike Pritchard.Nm copyin , 416847f7cfSKonstantin Belousov.Nm copyin_nofault , 425406291aSMike Pritchard.Nm copyout , 436847f7cfSKonstantin Belousov.Nm copyout_nofault , 445406291aSMike Pritchard.Nm copystr , 455406291aSMike Pritchard.Nm copyinstr 46*294b75a8SConrad Meyer.Nd heterogenous address space copy functions 475406291aSMike Pritchard.Sh SYNOPSIS 4832eef9aeSRuslan Ermilov.In sys/types.h 4932eef9aeSRuslan Ermilov.In sys/systm.h 505406291aSMike Pritchard.Ft int 512e14815bSBruce Evans.Fn copyin "const void *uaddr" "void *kaddr" "size_t len" 525406291aSMike Pritchard.Ft int 536847f7cfSKonstantin Belousov.Fn copyin_nofault "const void *uaddr" "void *kaddr" "size_t len" 546847f7cfSKonstantin Belousov.Ft int 552e14815bSBruce Evans.Fn copyout "const void *kaddr" "void *uaddr" "size_t len" 565406291aSMike Pritchard.Ft int 576847f7cfSKonstantin Belousov.Fn copyout_nofault "const void *kaddr" "void *uaddr" "size_t len" 58*294b75a8SConrad Meyer.Ft int __deprecated 592e14815bSBruce Evans.Fn copystr "const void *kfaddr" "void *kdaddr" "size_t len" "size_t *done" 605406291aSMike Pritchard.Ft int 612e14815bSBruce Evans.Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done" 625406291aSMike Pritchard.Sh DESCRIPTION 635406291aSMike PritchardThe 645406291aSMike Pritchard.Nm 65*294b75a8SConrad Meyerfunctions are designed to copy contiguous data from one address space 663a858f37SHiten Pandyato another. 67*294b75a8SConrad Meyer.Pp 685406291aSMike Pritchard.Fn copystr 69*294b75a8SConrad Meyeris deprecated and should be replaced with 70*294b75a8SConrad Meyer.Xr strlcpy 9 . 71*294b75a8SConrad MeyerIt will be removed from 72*294b75a8SConrad Meyer.Fx 13 . 735406291aSMike Pritchard.Pp 745406291aSMike PritchardThe 756847f7cfSKonstantin Belousov.Fn copyin 766847f7cfSKonstantin Belousovand 776847f7cfSKonstantin Belousov.Fn copyin_nofault 786847f7cfSKonstantin Belousovfunctions copy 79bc216e3cSHiten Pandya.Fa len 805406291aSMike Pritchardbytes of data from the user-space address 81bc216e3cSHiten Pandya.Fa uaddr 825406291aSMike Pritchardto the kernel-space address 83bc216e3cSHiten Pandya.Fa kaddr . 846847f7cfSKonstantin Belousov.Pp 856847f7cfSKonstantin BelousovThe 866847f7cfSKonstantin Belousov.Fn copyout 876847f7cfSKonstantin Belousovand 886847f7cfSKonstantin Belousov.Fn copyout_nofault 896847f7cfSKonstantin Belousovfunctions copy 90bc216e3cSHiten Pandya.Fa len 915406291aSMike Pritchardbytes of data from the kernel-space address 92bc216e3cSHiten Pandya.Fa kaddr 935406291aSMike Pritchardto the user-space address 94bc216e3cSHiten Pandya.Fa uaddr . 956847f7cfSKonstantin Belousov.Pp 966847f7cfSKonstantin BelousovThe 976847f7cfSKonstantin Belousov.Fn copyin_nofault 986847f7cfSKonstantin Belousovand 996847f7cfSKonstantin Belousov.Fn copyout_nofault 1006847f7cfSKonstantin Belousovfunctions require that the kernel-space and user-space data be 1016847f7cfSKonstantin Belousovaccessible without incurring a page fault. 1026847f7cfSKonstantin BelousovThe source and destination addresses must be physically mapped for 1036847f7cfSKonstantin Belousovread and write access, respectively, and neither the source nor 1046847f7cfSKonstantin Belousovdestination addresses may be pageable. 1056847f7cfSKonstantin Belousov.Pp 1066847f7cfSKonstantin BelousovThe 1076847f7cfSKonstantin Belousov.Fn copystr 1086847f7cfSKonstantin Belousovfunction copies a NUL-terminated string, at most 109bc216e3cSHiten Pandya.Fa len 1105406291aSMike Pritchardbytes long, from kernel-space address 111bc216e3cSHiten Pandya.Fa kfaddr 1125406291aSMike Pritchardto kernel-space address 113bc216e3cSHiten Pandya.Fa kdaddr . 1145406291aSMike PritchardThe number of bytes actually copied, including the terminating 115de635b06SWolfram SchneiderNUL, is returned in 116bc216e3cSHiten Pandya.Fa *done 117bf7f20c2SRuslan Ermilov(if 118bc216e3cSHiten Pandya.Fa done 119449dfbbcSPawel Jakub Dawidekis 120bf7f20c2SRuslan Ermilov.No non- Ns Dv NULL ) . 1216847f7cfSKonstantin Belousov.Pp 1226847f7cfSKonstantin BelousovThe 1236847f7cfSKonstantin Belousov.Fn copyinstr 1246847f7cfSKonstantin Belousovfunction copies a NUL-terminated string, at most 125bc216e3cSHiten Pandya.Fa len 1265406291aSMike Pritchardbytes long, from user-space address 127bc216e3cSHiten Pandya.Fa uaddr 1285406291aSMike Pritchardto kernel-space address 129bc216e3cSHiten Pandya.Fa kaddr . 1305406291aSMike PritchardThe number of bytes actually copied, including the terminating 131de635b06SWolfram SchneiderNUL, is returned in 132bc216e3cSHiten Pandya.Fa *done 133bf7f20c2SRuslan Ermilov(if 134bc216e3cSHiten Pandya.Fa done 135449dfbbcSPawel Jakub Dawidekis 136bf7f20c2SRuslan Ermilov.No non- Ns Dv NULL ) . 1375406291aSMike Pritchard.Sh RETURN VALUES 1385406291aSMike PritchardThe 1395406291aSMike Pritchard.Nm 14058771f90SEric van Gyzenfunctions return 0 on success. 14158771f90SEric van GyzenAll but 14258771f90SEric van Gyzen.Fn copystr 14358771f90SEric van Gyzenreturn 144b92a189eSRuslan Ermilov.Er EFAULT 145b92a189eSRuslan Ermilovif a bad address is encountered. 14658771f90SEric van GyzenThe 1476847f7cfSKonstantin Belousov.Fn copyin_nofault 1486847f7cfSKonstantin Belousovand 1496847f7cfSKonstantin Belousov.Fn copyout_nofault 1506847f7cfSKonstantin Belousovfunctions return 1516847f7cfSKonstantin Belousov.Er EFAULT 15258771f90SEric van Gyzenif a page fault occurs. 15358771f90SEric van GyzenThe 1546847f7cfSKonstantin Belousov.Fn copystr 1555406291aSMike Pritchardand 1565406291aSMike Pritchard.Fn copyinstr 157b92a189eSRuslan Ermilovfunctions return 158b92a189eSRuslan Ermilov.Er ENAMETOOLONG 159b92a189eSRuslan Ermilovif the string is longer than 160bc216e3cSHiten Pandya.Fa len 1615406291aSMike Pritchardbytes. 1625406291aSMike Pritchard.Sh SEE ALSO 1635406291aSMike Pritchard.Xr fetch 9 , 1646fe89339SBen Smithurst.Xr store 9 165