30typedef enum : uint8_t {
59 uintptr_t a_begin = 0U;
60 uintptr_t b_begin = 0U;
61 static_assert(
sizeof(a_begin) ==
sizeof(a),
"uintptr_t must preserve pointer representation");
62 static_assert(
sizeof(b_begin) ==
sizeof(b),
"uintptr_t must preserve pointer representation");
63 (void)
memcpy((
void*)&a_begin, (
const void*)&a,
sizeof(a_begin));
64 (void)
memcpy((
void*)&b_begin, (
const void*)&b,
sizeof(b_begin));
66 if (a_len > (uint64_t)UINTPTR_MAX) {
69 if (b_len > (uint64_t)UINTPTR_MAX) {
72 if (a_begin > (UINTPTR_MAX - (uintptr_t)a_len)) {
75 if (b_begin > (UINTPTR_MAX - (uintptr_t)b_len)) {
79 const uintptr_t a_end = a_begin + (uintptr_t)a_len;
80 const uintptr_t b_end = b_begin + (uintptr_t)b_len;
81 if (a_begin >= b_end) {
84 return b_begin < a_end;
114 if (rd->
table ==
nullptr) {
160 const uint64_t expected_count =
163 const uint64_t table_entries = (uint64_t)rd->
chunk_count + 1U;
164 if (expected_count > (uint64_t)UINT32_MAX) {
173 if (rd->
table[0] != 0U) {
240 const uint8_t* chunk,
242 const uint8_t* scratch,
243 uint32_t scratch_cap,
254 if (bases[i] !=
nullptr) {
258 bool invalid =
false;
291 const uint8_t* chunk,
293 const uint8_t* scratch,
294 uint32_t scratch_cap)
296 const uint64_t table_len = ((uint64_t)rd->
chunk_count + 1U) *
sizeof(rd->
table[0]);
305 bool invalid =
false;
339 const uint64_t offset = (uint64_t)idx * (uint64_t)ctx->
rd->
chunk_bytes;
342 if (remain < (uint64_t)span) {
343 span = (uint32_t)remain;
377 uint64_t cursor = offset;
382 uint32_t copied = 0U;
383 while (copied < len) {
384 const uint32_t idx = (uint32_t)(cursor / (uint64_t)ctx->
rd->
chunk_bytes);
389 const uint32_t in_chunk = (uint32_t)(cursor % (uint64_t)ctx->
rd->
chunk_bytes);
391 if (span > (len - copied)) {
394 (void)
memmove(&dst[copied], &ctx->
chunk[in_chunk], span);
405 uint32_t scratch_cap,
408 if (out_header ==
nullptr) {
419 if ((chunk ==
nullptr) || (scratch ==
nullptr)) {
422 if ((chunk_cap == 0U) || (scratch_cap == 0U)) {
429 if (chunk_cap < rd->chunk_bytes) {
451 *out_header = validated;
Demand-paged chunk reader for the "RBKC" .rabook container.
ra8_err_t book_chunked_read(void *ctx, uint64_t offset, uint8_t *buf, uint32_t len)
Serve one chunk-aligned read of the inflated flat blob.
static bool internal_spans_overlap(const void *a, uint64_t a_len, const void *b, uint64_t b_len, bool *invalid)
Decide whether two non-empty caller-memory spans overlap.
ra8_err_t book_chunked_validate_strict(book_chunked_t *rd, uint8_t *chunk, uint32_t chunk_cap, uint8_t *scratch, uint32_t scratch_cap, book_header_t *out_header)
Strictly validate the complete flat blob behind an open RBKC reader.
static ra8_err_t internal_validate_workspaces(const book_chunked_t *rd, const uint8_t *chunk, uint32_t chunk_len, const uint8_t *scratch, uint32_t scratch_cap)
Require strict-validation workspaces to be pairwise disjoint.
static ra8_err_t internal_validate_reader_fields(const book_chunked_t *rd)
Require every reader callback and geometry field to be present.
static ra8_err_t internal_validate_reader(const book_chunked_t *rd)
Revalidate the open-reader invariants needed by strict validation.
static ra8_err_t internal_load_chunk(chunk_validate_t *ctx, uint32_t idx)
Inflate one requested chunk into the caller cache when not resident.
chunk_validate_constant_t
Fixed span count used by strict alias validation.
@ k_chunk_validate_span_count
Reader, chunk, scratch, staging, and table.
static ra8_err_t internal_validate_reader_table(const book_chunked_t *rd)
Revalidate the derived chunk count and the offset table's shape.
static ra8_err_t internal_chunk_flat_read(void *opaque, uint64_t offset, uint8_t *dst, uint32_t len)
Serve an exact arbitrary flat-blob read through the one-chunk cache.
static bool internal_output_is_aliased(const book_chunked_t *rd, const uint8_t *chunk, uint32_t chunk_cap, const uint8_t *scratch, uint32_t scratch_cap, const book_header_t *out_header)
Reject output aliases before the output is zeroed or published.
ra8_err_t book_validate_stream_strict(book_stream_read_fn read, void *read_ctx, uint64_t source_size, uint8_t *scratch, uint32_t scratch_cap, book_header_t *out_header)
Strictly validate one callback-backed RABOOK1 flat blob.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ 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.
void * memmove(void *dst, const void *src, size_t n)
Copy memory area between potentially overlapping regions.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
One open chunked .rabook file: parsed geometry + caller storage.
uint64_t inflated_total
Served flat-blob length.
ra8_vsource_read_fn file_read
Container byte reader.
uint8_t * staging
Compressed-byte staging.
book_inflate_fn inflate_cb
zlib decompressor.
const uint64_t * table
Chunk offsets.
uint32_t chunk_count
Chunk count.
uint32_t table_cap_entries
Table entry capacity.
uint32_t chunk_bytes
Inflated bytes per chunk.
uint64_t payload_off
First stream file offset.
uint32_t staging_cap
Staging byte capacity.
Cached inflated-chunk view used by arbitrary flat-source reads.
uint32_t loaded_idx
Cached chunk index.
bool loaded
Whether the cache contains data.
book_chunked_t * rd
Open compressed reader.
uint8_t * chunk
Caller-owned inflated chunk.
uint32_t loaded_len
Exact cached inflated byte span.