#include <libkern/copyio.h>

libkern/copyio.h Kernel.framework

includes: kern/debug.h
4 functions · 2 macros

functioncopyin

OS_WARN_RESULT
int copyin(const user_addr_t uaddr, void *__sized_by(len) kaddr, size_t len)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/copyio.c, osfmk/x86_64/copyio.c
Copies len bytes from the user address uaddr in the current thread's address space to the kernel buffer kaddr. The source range is validated against the user map before copying, and faults during the copy are caught rather than panicking. Returns 0 on success or an errno value (EFAULT for an invalid or unmapped user address, ENAMETOOLONG-style errors do not apply here); a zero-length copy succeeds trivially. Must be called from a thread context with a user address space; the result must be checked (OS_WARN_RESULT).

functioncopyout

int copyout(const void *__sized_by(len) kaddr, user_addr_t udaddr, size_t len)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/copyio.c, osfmk/x86_64/copyio.c
Copies len bytes from the kernel buffer kaddr to the user address udaddr in the current thread's address space. The destination range is validated against the user map before copying, and faults during the copy are caught rather than panicking. Returns 0 on success or an errno value (EFAULT for an invalid or unmapped user address); a zero-length copy succeeds trivially. Must be called from a thread context with a user address space.

function__copyin_chk

OS_ALWAYS_INLINE OS_WARN_RESULT static inline int __copyin_chk(
	const user_addr_t uaddr,
	void *__sized_by(len) kaddr,
	size_t len,
	size_t chk_size
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/copyio.h (SDK libkern/copyio.h)
FORTIFY_SOURCE checked wrapper for copyin. Panics if the compiler-determined size of the destination object (chk_size, from __builtin_object_size) is smaller than len, then performs copyin(uaddr, kaddr, len). Installed transparently by the copyin macro when fortification is enabled; not intended to be called directly.

function__copyout_chk

OS_ALWAYS_INLINE static inline int __copyout_chk(
	const void *__sized_by(len) kaddr,
	user_addr_t uaddr,
	size_t len,
	size_t chk_size
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/copyio.h (SDK libkern/copyio.h)
FORTIFY_SOURCE checked wrapper for copyout. Panics if the compiler-determined size of the source object (chk_size, from __builtin_object_size) is smaller than len, then performs copyout(kaddr, uaddr, len). Installed transparently by the copyout macro when fortification is enabled; not intended to be called directly.

macrocopyin

#define copyin(uaddr, kaddr, len) __copyin_chk(uaddr, kaddr, len, __builtin_object_size(kaddr, 0))

macrocopyout

#define copyout(kaddr, uaddr, len) __copyout_chk(kaddr, uaddr, len, __builtin_object_size(kaddr, 0))