37static const char*
const s_tag_xz =
"unarch_xz";
54typedef enum : uint16_t {
68typedef enum : uint8_t {
93 return memeq(sig, want,
sizeof(want));
113 xs->
dec = xz_dec_init(XZ_PREALLOC, dict_max);
114 if (xs->
dec ==
nullptr) {
148 if (ret == XZ_MEMLIMIT_ERROR) {
151 if (ret == XZ_FORMAT_ERROR) {
154 if (ret == XZ_OPTIONS_ERROR) {
157 if (ret == XZ_DATA_ERROR) {
160 if (ret == XZ_BUF_ERROR) {
199 const enum xz_ret ret = xz_dec_run(xs->
dec, &b);
201 *out_used = b.out_pos;
202 if (ret == XZ_STREAM_END) {
248 const size_t* out_len)
250 if (read ==
nullptr) {
313 const uint64_t remain = st->
size - st->
in_off;
328 size_t produced = 0U;
337 st->
in_off += (uint64_t)used;
357 uint32_t scratch_len,
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
ra8_err_t ra8_decomp_budget_charge_output(ra8_decomp_budget_t *b, uint64_t in_total, uint64_t out_delta)
Charge decompressed output against the cap and ratio bounds.
ra8_err_t ra8_decomp_budget_charge_iter(ra8_decomp_budget_t *b)
Charge one decode-loop turn against the iteration budget.
ra8_err_t ra8_decomp_budget_init(ra8_decomp_budget_t *b, const ra8_decomp_limits_t *limits)
Bind a budget to a policy (or the default policy) and zero it.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
#define ra8_log_error(tag, message)
RA8 log error.
Running consumption tracker charged by a decoder against its policy.
One decompression policy: the five resource bounds decoders enforce.
One multi-call XZ decode session (opaque decoder + liveness flag).
struct xz_dec * dec
xz-embedded decoder state (pool-allocated).
bool live
Session is begun and not yet ended.
Loop-carried state of one unwrap: cursors, session, and budget.
size_t out_cap
Arena capacity in bytes.
unarch_read_fn read
Byte reader over the stream.
void * ctx
Context for read.
uint64_t size
Stream length in bytes.
ra8_decomp_budget_t budget
Unified decompression budget.
uint8_t chunk[k_xz_chunk]
Input refill window (one pass).
uint8_t * out
Destination arena.
size_t total_out
Output bytes produced so far.
unarch_xz_stream_t xs
Live decode session.
uint64_t in_off
Input bytes consumed so far.
size_t(* unarch_read_fn)(void *ctx, uint64_t offset, void *buf, size_t len)
Seek+read backing over an archive's bytes.
static ra8_err_t internal_xz_map_err(enum xz_ret ret)
Map an xz-embedded return code onto the wrapper's error space.
static ra8_err_t internal_unwrap_pass(xz_unwrap_state_t *st, bool *end)
Run one refill + decode pass of the unwrap loop.
static const char *const s_tag_xz
Log tag for XZ-wrapper diagnostics.
bool unarch_xz_magic(const uint8_t *sig, size_t sig_len)
Whether sig begins with the XZ stream header magic.
static ra8_err_t internal_unwrap_reject_null(unarch_read_fn read, const uint8_t *out, const void *scratch, const size_t *out_len)
Reject any NULL required argument to unarch_xz_unwrap.
ra8_err_t unarch_xz_stream_run(unarch_xz_stream_t *xs, const uint8_t *in, size_t in_len, size_t *in_used, uint8_t *out, size_t out_cap, size_t *out_used, bool *end)
Feed one input chunk through a live session, producing output.
void unarch_xz_stream_end(unarch_xz_stream_t *xs)
End a session: free the decoder and release the allocation pool.
ra8_err_t unarch_xz_unwrap(unarch_read_fn read, void *ctx, uint64_t size, uint8_t *out, size_t out_cap, void *scratch, uint32_t scratch_len, const ra8_decomp_limits_t *limits, size_t *out_len)
Decode one whole XZ stream from a read seam into a caller arena.
xz_magic_t
The six XZ stream header magic bytes (FD 37 7A 58 5A 00).
@ k_xz_magic_b5
NUL terminator of the magic.
@ k_xz_magic_b0
Non-ASCII lead-in byte.
xz_wrap_dims_t
Fixed sizes for the unwrap input loop.
@ k_xz_chunk
Input refill window per decode pass, bytes.
@ k_xz_out_window
Output window per decode pass, bytes; keeps the budget charge granularity (and thus bomb detection) w...
ra8_err_t unarch_xz_stream_begin(unarch_xz_stream_t *xs, void *scratch, uint32_t scratch_len)
Begin a multi-call XZ decode session over a caller scratch.
Bounded, fail-closed XZ/LZMA2 decoding over the vendored xz-embedded.
@ k_unarch_xz_sig_len
XZ stream header magic length.
@ k_unarch_xz_state_reserve
Decoder-state slice of the scratch.
Caller-owned bump arena backing xz-embedded's allocator seam.
void unarch_xz_pool_reset(void)
Release the installed arena (invalidates every pool allocation).
ra8_err_t unarch_xz_pool_install(void *base, uint32_t len)
Install a caller-owned scratch buffer as the XZ allocation arena.
First-party porting header for the vendored xz-embedded decoder.
#define memeq(a, b, size)
Byte-equality shim the SOUP uses for magic/footer comparison.