KCOPY(9F) Kernel Functions for Drivers KCOPY(9F)

NAME


kcopy - copy data between kernel addresses, guarding against faults

SYNOPSIS


#include <sys/types.h>
#include <sys/systm.h>

int
kcopy(const void *from, void *to, size_t count);

INTERFACE LEVEL


Architecture independent level 1 (DDI/DKI).

PARAMETERS


from Source kernel address of the copy.

to Destination kernel address of the copy.

count Number of bytes to copy.

DESCRIPTION


The kcopy() function copies count bytes from one kernel address to
another. It performs the same copy as bcopy(9F), but guards against
faults for the duration of the copy. A fault taken while copying is
first handled as an ordinary page fault, so a copy involving pageable
kernel memory succeeds when the fault can be resolved. A fault which
cannot be resolved causes kcopy() to return an error, where bcopy(9F)
would panic the system.

Both from and to must be kernel addresses. kcopy() must not be used to
copy data to or from user address space; use copyin(9F) and copyout(9F)
for that. If the source and destination areas overlap, the behaviour
is undefined.

CONTEXT


The kcopy() function can be called from user or kernel context.

RETURN VALUES


Upon successful completion, the kcopy() function returns 0. Otherwise,
a fault occurred that could not be resolved, and an error number
describing the fault, most commonly EFAULT, is returned. Note that
this differs from copyin(9F) and copyout(9F), which return -1 on
failure.

SEE ALSO


bcopy(9F), copyin(9F), copyout(9F), ddi_copyin(9F), ddi_copyout(9F),
uio_copyin(9F), uio_copyout(9F)

illumos July 11, 2026 illumos