#include <vm/lz4.h>
vm/lz4.h
macrolz4_memcpy
#define lz4_memcpy __builtin_memcpy
typedeflz4_hash_entry_t
typedef struct { uint32_t offset; uint32_t word; } lz4_hash_entry_tvariablelz4_hash_table_size
static const size_t lz4_hash_table_size = LZ4_COMPRESS_HASH_ENTRIES * sizeof(lz4_hash_entry_t)
functionlz4_encode_2gb
extern void lz4_encode_2gb( uint8_t **dst_ptr, size_t dst_size, const uint8_t **src_ptr, const uint8_t *src_begin, size_t src_size, lz4_hash_entry_t hash_table[LZ4_COMPRESS_HASH_ENTRIES], int skip_final_literals )
Worker function for lz4 encode. Underlies both the buffer and stream encode operations.
Performs lz4 encoding of up to 2gb of data, updates dst_ptr and src_ptr to point to the
first byte of output and input that couldn't be completely processed, respectively.
If skip_final_literals is 0, the entire src buffer is encoded, by emitting a final sequence of literals
at the end of the compressed payload.
If skip_final_literals is not 0, this final literal sequence is not emitted, and the src buffer is
partially encoded (the length of this literal sequence varies).
functionlz4_decode
extern int lz4_decode( uint8_t **dst_ptr, uint8_t *dst_begin, uint8_t *dst_end, const uint8_t **src_ptr, const uint8_t *src_end )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h, osfmk/vm/lz4.c
Low-level safe LZ4 block decoder underlying lz4raw_decode_buffer. Decodes LZ4 sequences (literal/match command bytes with extension bytes and 2-byte match offsets) from *src_ptr up to src_end into *dst_ptr, bounded below by dst_begin (match offsets may not reach before it) and above by dst_end, checking every input and output bound. Updates *dst_ptr and *src_ptr to the last fully decoded position. Returns 0 when input is exhausted or the output buffer is full, nonzero on invalid or truncated input (e.g. a match distance reaching before dst_begin).
functionlz4_decode_asm
extern int lz4_decode_asm( uint8_t **dst_ptr, uint8_t *dst_begin, uint8_t *dst_end, const uint8_t **src_ptr, const uint8_t *src_end )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h, osfmk/vm/lz4.c
Hand-optimized assembly variant of lz4_decode, available when LZ4_ENABLE_ASSEMBLY_DECODE is set for the platform. Same interface and return convention as lz4_decode; for speed it is run by lz4raw_decode_buffer only with a safety margin (LZ4_GOFAST_SAFETY_MARGIN) kept back from the end of both buffers, after which the C decoder finishes the tail safely.
variablelz4_encode_scratch_size
static const size_t lz4_encode_scratch_size = lz4_hash_table_size
variablelz4_decode_scratch_size
static const size_t lz4_decode_scratch_size = 0
functionlz4raw_encode_buffer
size_t lz4raw_encode_buffer( uint8_t * __restrict dst_buffer, size_t dst_size, const uint8_t * __restrict src_buffer, size_t src_size, lz4_hash_entry_t hash_table[LZ4_COMPRESS_HASH_ENTRIES] )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h, osfmk/vm/lz4.c
Encodes src_size bytes from src_buffer into dst_buffer as a raw LZ4 block stream (no frame headers), the format used by the VM compressor's LZ4 codec. hash_table is caller-supplied scratch of LZ4_COMPRESS_HASH_ENTRIES entries (lz4_encode_scratch_size bytes), reinitialized per 2 GB block; inputs larger than 2 GB are encoded as independent concatenated blocks via lz4_encode_2gb. Returns the number of bytes written to dst_buffer, or 0 if the data could not be encoded into dst_size bytes (output space exhausted or too many trailing literals).
functionlz4raw_decode_buffer
size_t lz4raw_decode_buffer( uint8_t * __restrict dst_buffer, size_t dst_size, const uint8_t * __restrict src_buffer, size_t src_size, void * __restrict work __attribute__((unused)) )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h, osfmk/vm/lz4.c
Decodes a raw LZ4 block stream of src_size bytes from src_buffer into dst_buffer, stopping when the input is consumed or dst_size bytes have been produced. When platform assembly decode is enabled, runs lz4_decode_asm over the bulk of the buffers with a safety margin held back, then finishes with the bounds-checked C decoder lz4_decode. The work argument is unused (lz4_decode_scratch_size is 0). Returns the number of bytes produced, or 0 on invalid input.
typedefvector_uchar8
typedef __attribute__((__ext_vector_type__(8))) uint8_t vector_uchar8
typedefvector_uchar16
typedef __attribute__((__ext_vector_type__(16))) uint8_t vector_uchar16
typedefvector_uchar32
typedef __attribute__((__ext_vector_type__(32))) uint8_t vector_uchar32
typedefvector_uchar64
typedef __attribute__((__ext_vector_type__(64))) uint8_t vector_uchar64
typedefpacked_uchar16
typedef __attribute__((__ext_vector_type__(16), __aligned__(1))) uint8_t packed_uchar16
typedefpacked_uchar32
typedef __attribute__((__ext_vector_type__(32), __aligned__(1))) uint8_t packed_uchar32
typedefpacked_uchar64
typedef __attribute__((__ext_vector_type__(64), __aligned__(1))) uint8_t packed_uchar64
typedefvector_ushort4
typedef __attribute__((__ext_vector_type__(4))) uint16_t vector_ushort4
typedefpacked_ushort4
typedef __attribute__((__ext_vector_type__(4), __aligned__(2))) uint16_t packed_ushort4
typedefvector_int2
typedef __attribute__((__ext_vector_type__(2))) int32_t vector_int2
typedefvector_int4
typedef __attribute__((__ext_vector_type__(4))) int32_t vector_int4
typedefvector_int8
typedef __attribute__((__ext_vector_type__(8))) int32_t vector_int8
typedefvector_uint4
typedef __attribute__((__ext_vector_type__(4))) uint32_t vector_uint4
macroUTIL_FUNCTION
#define UTIL_FUNCTION static inline __attribute__((__always_inline__)) __attribute__((__overloadable__))
functionload4
UTIL_FUNCTION uint32_t load4(const void * ptr)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: loads 4 bytes from the possibly unaligned location ptr and returns them as a uint32_t, in native byte order (implemented with memcpy, so no alignment is required).
functionload8
UTIL_FUNCTION uint64_t load8(const void * ptr)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: loads 8 bytes from the possibly unaligned location ptr and returns them as a uint64_t, in native byte order (implemented with memcpy, so no alignment is required).
functionload16
UTIL_FUNCTION vector_uchar16 load16(const void * ptr)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: loads 16 bytes from the possibly unaligned location ptr and returns them as a vector_uchar16. Compiled via a packed (byte-aligned) vector type so no alignment is required.
functionload32
UTIL_FUNCTION vector_uchar32 load32(const void * ptr)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: loads 32 bytes from the possibly unaligned location ptr and returns them as a vector_uchar32. Compiled via a packed (byte-aligned) vector type so no alignment is required.
functionload64
UTIL_FUNCTION vector_uchar64 load64(const void * ptr)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: loads 64 bytes from the possibly unaligned location ptr and returns them as a vector_uchar64. Compiled via a packed (byte-aligned) vector type so no alignment is required.
functionstore2
UTIL_FUNCTION void store2(void * ptr, uint16_t data)
Store N bytes to unaligned location PTR
functionstore4
UTIL_FUNCTION void store4(void * ptr, uint32_t data)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: stores the 4-byte value data to the possibly unaligned location ptr. Counterpart of load4; no alignment is required.
functionstore8
UTIL_FUNCTION void store8(void * ptr, uint64_t data)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: stores the 8-byte value data to the possibly unaligned location ptr. Counterpart of load8; no alignment is required.
functionstore16
UTIL_FUNCTION void store16(void * ptr, vector_uchar16 data)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: stores the 16-byte value data to the possibly unaligned location ptr. Counterpart of load16; no alignment is required.
functionstore32
UTIL_FUNCTION void store32(void * ptr, vector_uchar32 data)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: stores the 32-byte value data to the possibly unaligned location ptr. Counterpart of load32; no alignment is required.
functionstore64
UTIL_FUNCTION void store64(void * ptr, vector_uchar64 data)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: stores the 64-byte value data to the possibly unaligned location ptr. Counterpart of load64; no alignment is required.
functioncopy8
UTIL_FUNCTION void copy8(void * dst, const void * src)
Load+Store N bytes from unaligned locations SRC to DST. No overlap allowed.
functioncopy16
UTIL_FUNCTION void copy16(void * dst, const void * src)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: copies 16 bytes from src to dst, both possibly unaligned, as two 8-byte load/store pairs. The copy is not required to be atomic and the ranges must not overlap in a way that a forward copy would corrupt.
functioncopy32
UTIL_FUNCTION void copy32(void * dst, const void * src)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/vm/lz4.h
Inline utility used by the LZ4 codec: copies 32 bytes from src to dst, both possibly unaligned, as four 8-byte load/store pairs. Counterpart of copy16 for 32-byte quantities.