1.\" 2.\" This file and its contents are supplied under the terms of the 3.\" Common Development and Distribution License ("CDDL"), version 1.0. 4.\" You may only use this file in accordance with the terms of version 5.\" 1.0 of the CDDL. 6.\" 7.\" A full copy of the text of the CDDL should have accompanied this 8.\" source. A copy of the CDDL is also available via the Internet at 9.\" http://www.illumos.org/license/CDDL. 10.\" 11.\" 12.\" Copyright 2026 Oxide Computer Company 13.\" 14.Dd July 11, 2026 15.Dt KCOPY 9F 16.Os 17.Sh NAME 18.Nm kcopy 19.Nd copy data between kernel addresses, guarding against faults 20.Sh SYNOPSIS 21.In sys/types.h 22.In sys/systm.h 23.Ft int 24.Fo kcopy 25.Fa "const void *from" 26.Fa "void *to" 27.Fa "size_t count" 28.Fc 29.Sh INTERFACE LEVEL 30Architecture independent level 1 (DDI/DKI). 31.Sh PARAMETERS 32.Bl -tag -width Fa 33.It Fa from 34Source kernel address of the copy. 35.It Fa to 36Destination kernel address of the copy. 37.It Fa count 38Number of bytes to copy. 39.El 40.Sh DESCRIPTION 41The 42.Fn kcopy 43function copies 44.Fa count 45bytes from one kernel address to another. 46It performs the same copy as 47.Xr bcopy 9F , 48but guards against faults for the duration of the copy. 49A fault taken while copying is first handled as an ordinary page fault, 50so a copy involving pageable kernel memory succeeds when the fault can 51be resolved. 52A fault which cannot be resolved causes 53.Fn kcopy 54to return an error, where 55.Xr bcopy 9F 56would panic the system. 57.Pp 58Both 59.Fa from 60and 61.Fa to 62must be kernel addresses. 63.Fn kcopy 64must not be used to copy data to or from user address space; use 65.Xr copyin 9F 66and 67.Xr copyout 9F 68for that. 69If the source and destination areas overlap, the behaviour is 70undefined. 71.Sh CONTEXT 72The 73.Fn kcopy 74function can be called from user or kernel context. 75.Sh RETURN VALUES 76Upon successful completion, the 77.Fn kcopy 78function returns 0. 79Otherwise, a fault occurred that could not be resolved, and an error 80number describing the fault, most commonly 81.Er EFAULT , 82is returned. 83Note that this differs from 84.Xr copyin 9F 85and 86.Xr copyout 9F , 87which return -1 on failure. 88.Sh SEE ALSO 89.Xr bcopy 9F , 90.Xr copyin 9F , 91.Xr copyout 9F , 92.Xr ddi_copyin 9F , 93.Xr ddi_copyout 9F , 94.Xr uio_copyin 9F , 95.Xr uio_copyout 9F 96