#include <libkern/libkern.h>
libkern/libkern.h
variablebin2bcd_data
extern u_char const bin2bcd_data[]
macrobcd2bin
#define bcd2bin(bcd) (bcd2bin_data[bcd])
macrobin2bcd
#define bin2bcd(bin) (bin2bcd_data[bin])
variablehex2ascii_data
extern char const hex2ascii_data[]
macrohex2ascii
#define hex2ascii(hex) (hex2ascii_data[hex])
functionimax
static inline int imax(int a, int b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the larger of two signed integers.
functionimin
static inline int imin(int a, int b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the smaller of two signed integers.
functionlmax
static inline long lmax(long a, long b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the larger of two longs.
functionlmin
static inline long lmin(long a, long b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the smaller of two longs.
functionmax
static inline u_int max(u_int a, u_int b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the larger of two unsigned integers.
functionmin
static inline u_int min(u_int a, u_int b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the smaller of two unsigned integers.
functionulmax
static inline u_int32_t ulmax(u_int32_t a, u_int32_t b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the larger of two u_int32_t values.
functionulmin
static inline u_int32_t ulmin(u_int32_t a, u_int32_t b)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Returns the smaller of two u_int32_t values.
functionffsll
extern int ffsll(unsigned long long)
functionfls
extern int fls(unsigned int)
functionflsll
extern int flsll(unsigned long long)
functionscanc
extern size_t scanc(size_t, u_char *, const u_char *, u_char)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/scanc.c
Scans the byte string cp of length size, stopping at the first byte whose entry in the 256-byte lookup table has any of the bits in mask set (table[*cp] & mask != 0). Returns the number of bytes remaining in the string, counting the matching byte; returns 0 if no byte matched. 4.4BSD utility used by tty and expansion code.
functionstrtol
extern long strtol(const char*, char **, int)
functionstrsep
extern char *strsep(char **, const char *)
functionurl_decode
extern void url_decode(char *str)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/url_encode.c
Decodes percent-encoded (%XX) escape sequences in the string, in place. Each escape whose decoded value is a printable character replaces the sequence and the remainder of the string is shifted down; escapes that decode to non-printable characters are left untouched. Does nothing if str is NULL.
functionsnprintf
__printflike(3, 4) int snprintf(char *__counted_by(count), size_t count, const char *, ...)
NOTE: snprintf() returns the full length of the formatted string even if it
couldn't fit in the supplied buffer.
Use scnprintf() if you need the actual number of bytes (minus the \0)
functionscnprintf
__printflike(3, 4) int scnprintf(char *__counted_by(count), size_t count, const char *, ...)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/kern/subr_prf.c
Formats into the buffer like snprintf, but returns the number of characters actually written, excluding the terminating NUL, rather than the length the full formatted string would have had. Returns 0 when count is 0 and count - 1 on truncation, so the result is always safe to use as an offset for appending.
functiontsnprintf
__printflike(3, 4) const char * tsnprintf(char *__counted_by(count) dst, size_t count, const char *fmt, ...)
Like (v)snprintf, but returns a __null_terminated pointer to `dst` (or NULL
if `count` was 0). This can be used to "finalize" editing a char array and
turn it into a NUL-terminated string when -fbounds-safety is enabled.
Care must be taken to avoid aliasing the character data after the string
has been finalized.
functionvtsnprintf
__printflike(3, 0) const char * vtsnprintf( char *__counted_by(count) dst, size_t count, const char *fmt, va_list ap )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/kern/subr_prf.c
functionsprintf
__deprecated __printflike(2, 3)
int sprintf(char *bufp, const char *, ...)deprecated
sprintf() is being deprecated. Please use snprintf() instead.
functionsscanf
__scanflike(2, 3)
int sscanf(const char *, char const *, ...)functionprintf
__printflike(1, 2)
int printf(const char *, ...)▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/printf.c
Kernel printf. Formats the arguments and delivers the result both to the kernel log (visible through os_log/syslog) and to the console. Supports the usual integer, character and string conversions with width and precision, plus the kernel extensions %b (decode a register value against a bit-name string) and %D (hex dump with separator); %e, %f and %g are not implemented. The return value is always 0 and carries no meaning.
functioncrc32
uint32_t crc32(uint32_t crc, const void *bufp, size_t len)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/crc32.c
Computes the CRC-32 checksum (IEEE 802.3 polynomial 0xedb88320, as used by zlib and POSIX cksum) of the len bytes at bufp, using a byte-at-a-time table lookup. The crc argument is the running checksum from a previous call, permitting incremental computation over discontiguous buffers; pass 0 to start. Pre- and post-inversion of the CRC register is handled internally. Returns the updated checksum.
functioncopystr
int copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/dev/arm/stubs.c, bsd/dev/i386/stubs.c
Copies a NUL-terminated string between two kernel addresses, copying at most len bytes. Returns 0 on success, or ENAMETOOLONG if the string did not fit; if done is non-NULL it receives the number of bytes copied, including the terminating NUL. For new code strlcpy is preferred.
functioncopyinstr
OS_WARN_RESULT int copyinstr(const user_addr_t uaddr, void *kaddr, size_t len, size_t *done)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/copyio.c, osfmk/x86_64/copyio.c
Copies a NUL-terminated string from the user address uaddr of the current task into the kernel buffer kaddr, copying at most len bytes. Returns 0 on success, EFAULT if the user address is invalid or faults, and ENAMETOOLONG if len bytes were exhausted before a NUL was found (len of 0 also returns ENAMETOOLONG). *done receives the number of bytes copied, including the terminating NUL. The result must be checked (OS_WARN_RESULT).
functioncopyoutstr
int copyoutstr(const void *kaddr, user_addr_t udaddr, size_t len, size_t *done)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/dev/arm/stubs.c, bsd/dev/i386/stubs.c
Copies the NUL-terminated kernel string kaddr out to the user address udaddr of the current task, copying at most len bytes. Returns 0 on success, EFAULT if the user address faults, or ENAMETOOLONG if the string and its NUL exceed len (the first len bytes are still copied). If done is non-NULL it receives the number of bytes copied.
functionvsnprintf
__printflike(3, 0) extern int vsnprintf(char *, size_t, const char *, va_list)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/kern/subr_prf.c
Scaled-down kernel version of vsnprintf(3). Formats at most size - 1 characters into str and NUL-terminates when size is at least 1. Returns the length the fully formatted string would have had, even if it did not fit; use vscnprintf to obtain the number of bytes actually written.
functionvscnprintf
__printflike(3, 0) extern int vscnprintf(char *, size_t, const char *, va_list)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/kern/subr_prf.c
va_list form of scnprintf. Formats into buf like vsnprintf but returns the number of characters actually written, excluding the terminating NUL: 0 when size is 0, and size - 1 when the output was truncated.
functionvsprintf
__deprecated __printflike(2, 0) extern int vsprintf(char *bufp, const char *, va_list)
deprecated
vsprintf() is being deprecated. Please use vsnprintf() instead.
functioninvalidate_icache
extern void invalidate_icache(vm_offset_t, unsigned, int)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/caches_asm.s, osfmk/x86_64/pmap.c
Invalidates the instruction cache for the given address range so subsequently executed instructions are fetched from memory; call after writing instructions (e.g. code modification). addr is a kernel virtual address, or a physical address if phys is nonzero. A no-op on x86, where instruction caches are coherent with data accesses.
functionflush_dcache
extern void flush_dcache(vm_offset_t, unsigned, int)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm/caches.c, osfmk/x86_64/pmap.c
Cleans and invalidates (writes back to memory and discards) the data cache for the given address range, to the point of coherency. addr is a kernel virtual address, or a physical address if phys is nonzero. Used around DMA on platforms with non-coherent I/O; a no-op on x86 and on ARM systems built with coherent I/O.
functioninvalidate_icache64
extern void invalidate_icache64(addr64_t, unsigned, int)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/caches_asm.s, osfmk/x86_64/loose_ends.c
Variant of invalidate_icache taking a 64-bit addr64_t address. Invalidates the instruction cache for the range; a physical address is indicated by a nonzero phys argument. On arm64 it is an alias of invalidate_icache; a no-op on x86.
functionflush_dcache64
extern void flush_dcache64(addr64_t, unsigned, int)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/caches_asm.s, osfmk/x86_64/loose_ends.c
Variant of flush_dcache taking a 64-bit addr64_t address. Cleans and invalidates the data cache for the range, treating addr as physical if phys is nonzero. On arm64 it is an alias of flush_dcache; on x86 it flushes cache lines with clflush when given a virtual range.
functionclz
static inline int clz(unsigned int num)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/libkern/libkern.h (inline)
Counts the number of leading zero bits in the 32-bit argument. Defined for an input of 0, returning 32: on ARM the builtin already returns the type width, and on Intel, where __builtin_clz(0) is undefined, the zero case is checked explicitly.