COPY(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… COPY(9) β€” the kernel developer's manual, bestie edition πŸŽ€

okay so this is COPY(9) from the Kernel Developer's Manual, and it's literally the glow-up guide for moving bytes between address spaces. buckle up πŸ¦‹


✨ NAME ✨

copy, copyin, copyin_nofault, copyout, copyout_nofault, copystr, copyinstr β€” the heterogeneous address space copy functions πŸ’«

(heterogeneous address space = fancy speak for "the two addresses live in different worlds," iykyk)


🌸 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 __deprecated
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);

not me pointing out that __deprecated sitting right there in the signature like a warning label 🫢


πŸ‘‘ DESCRIPTION πŸ‘‘

the copy functions are designed to copy contiguous data from one address space to another. that's the whole vibe. contiguous bytes, two worlds, one function call ✨

πŸ’€ big heads-up: copystr() is deprecated and should be replaced with strlcpy(9). it will be removed from FreeBSD 13. so like… start migrating, bestie. fr fr.

copyin() and copyin_nofault() copy len bytes of data from the user-space address uaddr to the kernel-space address kaddr. userland ➑️ kernel, slay.

copyout() and copyout_nofault() copy len bytes of data from the kernel-space address kaddr to the user-space address uaddr. kernel ➑️ userland, also slay.

copyin_nofault() and copyout_nofault() require that the kernel-space and user-space data be accessible without incurring a page fault. like, no surprises allowed, periodt. the source and destination addresses must be physically mapped for read and write access, respectively, and neither the source nor destination addresses may be pageable. if any of that isn't true… that's not it. πŸ™ˆ

copystr() copies a NUL-terminated string, at most len bytes long, from kernel-space address kfaddr to kernel-space address kdaddr. the number of bytes actually copied β€” including the terminating NUL β€” is returned in *done (if done is non-NULL). πŸ“

copyinstr() copies a NUL-terminated string, at most len bytes long, from user-space address uaddr to kernel-space address kaddr. the number of bytes actually copied β€” including the terminating NUL β€” is returned in *done (if done is non-NULL). yes, same deal, different address space, iconic behavior πŸ’…


⭐ RETURN VALUES ⭐

  • the copy functions return 0 on success. we love a clean zero πŸ₯°
  • all of them except copystr() return EFAULT if a bad address is encountered. bad address = vibe check failed.
  • copyin_nofault() and copyout_nofault() return EFAULT if a page fault occurs. (remember: those two literally can't be doing page faults, so this is the "you were warned" error πŸ’€)
  • copystr() and copyinstr() return ENAMETOOLONG if the string is longer than len bytes. too long, too much, we're not doing that πŸŽ€

🌈 SEE ALSO 🌈

go read those too, bestie, you'll be obsessed πŸ’œ


and that's the page!! no cap, you now know COPY(9) better than most. this little gem came to you from the Debian edition, dated May 11, 2020 β€” so when you cite it in your commit message, cite it with pride 🧚✨ 🫢

πŸ“¦ where this page comes from