COPY(9)
π COPY(9) β kernel copy functions π
okay bestie so this is COPY(9) from the Kernel Developer's Manual, and it's literally the page that explains how the kernel moves bytes around without touching the wrong memory and having a whole existential crisis. It's giving essential infrastructure. π¦
β¨ NAME β¨
copy, copyin, copyin_nofault, copyout, copyout_nofault, copystr, copyinstr β the kernel copy functions, aka the friend group that carries your data across the user/kernel boundary π«Ά
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <sys/systm.h>
int
copyin(const void *uaddr, void *kaddr, size_t len);
int
copyin_nofault(const void *uaddr, void *kaddr, size_t len);
int
copyout(const void *kaddr, void *uaddr, size_t len);
int
copyout_nofault(const void *kaddr, void *uaddr, size_t len);
int
copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done);
int
copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done);
π DESCRIPTION π
So the copy functions are all about copying contiguous data from one address to another. That's the whole vibe. β¨
And all of them except copystr() move data from user-space to kernel-space, or the other way around. The two worlds, holding hands. π«Ά
copyin()andcopyin_nofault()copylenbytes of data from the user-space addressuaddrto the kernel-space addresskaddr. Bringing it home. πcopyout()andcopyout_nofault()copylenbytes of data from the kernel-space addresskaddrto the user-space addressuaddr. Sending it out into the world. π¦copyin_nofault()andcopyout_nofault()have a strict requirement bestie, no cap: the kernel-space and user-space data must be accessible without incurring a page fault. The source and destination addresses must be physically mapped for read and write access respectively, and neither the source nor the destination addresses may be pageable. So like, they have to be right there, ready, no dramatics. πcopystr()copies a NUL-terminated string, at mostlenbytes long, from the kernel-space addresskfaddrto the kernel-space addresskdaddr. The number of bytes actually copied β including the terminating NUL β gets returned in*done(ifdoneis non-NULL, obviously, don't be handing it a NULL and expecting magic). πcopyinstr()copies a NUL-terminated string, at mostlenbytes long, from the user-space addressuaddrto the kernel-space addresskaddr. Same deal: the number of bytes actually copied, including the terminating NUL, comes back in*done(ifdoneis non-NULL). β
π₯ RETURN VALUES π₯
The copy functions return 0 on success. Iconic. We love a zero. π
All of them except copystr() return EFAULT if a bad address is encountered β like, the address said it was fine and then it was not fine. π
copyin_nofault() and copyout_nofault() return EFAULT if a page fault occurs. Which, reminder, is exactly the thing they cannot handle. π
copystr() and copyinstr() return ENAMETOOLONG if the string is longer than len bytes. Too much string. Excessive. The string ate and there's nothing left. π
π¦ SEE ALSO π¦
okay that's the whole page bestie, you're basically a kernel dev now, mwah π β¨
This one came from the Debian crew, dated June 15, 2017, and honestly? Still serving. COPY(9) out. πππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Jason R. Thorpe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms