|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Wire decoding and canonical layout validation for streamed books. More...
Go to the source code of this file.
Functions | |
| ra8_err_t | priv_book_stream_read (const stream_validate_t *ctx, uint64_t off, uint8_t *dst, uint32_t len) |
| Read one exact, bounded source span. | |
| static void | internal_decode_header (const uint8_t *raw, book_header_t *hdr) |
| Decode the fixed header from canonical little-endian wire bytes. | |
| static ra8_err_t | internal_layout_segment (uint32_t off, uint32_t count, uint32_t elem, uint64_t *cursor) |
| Require one segment to begin at the canonical cursor and advance it. | |
| static ra8_err_t | internal_validate_header_fields (const stream_validate_t *ctx) |
| Validate decoded header fields before walking the table layout. | |
| static ra8_err_t | internal_validate_header_layout (const stream_validate_t *ctx) |
| Validate version, flags, exact source length, and canonical layout. | |
| ra8_err_t | priv_book_stream_read_validate_header (stream_validate_t *ctx) |
| Read, decode, and validate the canonical stream header and layout. | |
| ra8_err_t | priv_book_stream_string_ref (const stream_validate_t *ctx, uint32_t off) |
| Require a referenced offset to name an interned-string boundary. | |
| ra8_err_t | priv_book_stream_nonempty_string_ref (const stream_validate_t *ctx, uint32_t off) |
| Require a string reference to name a non-empty interned string. | |
| ra8_err_t | priv_book_stream_validate_string_envelope (const stream_validate_t *ctx) |
| Validate the string pool's leading and trailing NUL sentinels. | |
Wire decoding and canonical layout validation for streamed books.
Owns the exact-read guard, fixed-header decoding, gap-free table geometry, and interned-string boundary checks used by the semantic stream passes. Keeping wire concerns here leaves book_stream.c responsible for coordinating the chapter, DOM, attribute, stylesheet, image, and integrity validators.
Definition in file book_stream_wire.c.
|
static |
Decode the fixed header from canonical little-endian wire bytes.
Copies the byte magic and decodes every scalar field explicitly; no packed-structure alias or host-endian assumption is used.
| [in] | raw | Header wire bytes. |
| [out] | hdr | Decoded host-order header. |
raw holds exactly k_book_sizeof_header bytes. hdr addresses one writable header object disjoint from raw. hdr are not modified. Definition at line 44 of file book_stream_wire.c.
References book_header_t::attr_count, book_header_t::attr_off, book_header_t::author_off, book_header_t::chapter_count, book_header_t::chapter_off, book_header_t::cover_image_index, book_header_t::crc32_val, book_header_t::flags, book_header_t::format_version, book_header_t::identifier_off, book_header_t::image_count, book_header_t::image_off, book_header_t::image_pool_off, book_header_t::image_pool_size, internal_book_stream_le32(), k_stream_hdr_attr_count, k_stream_hdr_attr_off, k_stream_hdr_author, k_stream_hdr_chapter_count, k_stream_hdr_chapter_off, k_stream_hdr_cover, k_stream_hdr_crc, k_stream_hdr_flags, k_stream_hdr_identifier, k_stream_hdr_image_count, k_stream_hdr_image_off, k_stream_hdr_language, k_stream_hdr_node_count, k_stream_hdr_node_off, k_stream_hdr_pool_off, k_stream_hdr_pool_size, k_stream_hdr_string_off, k_stream_hdr_string_size, k_stream_hdr_style_count, k_stream_hdr_style_off, k_stream_hdr_title, k_stream_hdr_total, k_stream_hdr_version, book_header_t::language_off, book_header_t::magic, memcpy(), book_header_t::node_count, book_header_t::node_off, RA8_INTERNAL, book_header_t::string_off, book_header_t::string_size, book_header_t::stylesheet_count, book_header_t::stylesheet_off, book_header_t::title_off, and book_header_t::total_size.
Referenced by priv_book_stream_read_validate_header().
|
static |
Require one segment to begin at the canonical cursor and advance it.
Enforces gap-free table layout and performs the count-by-element product in 64 bits before accepting a 32-bit wire offset.
| [in] | off | Stored segment offset. |
| [in] | count | Number of records or bytes. |
| [in] | elem | Wire bytes per record. |
| [in,out] | cursor | Expected start and resulting end. |
| k_ra8_ok | The segment begins at the cursor and its end is representable. |
| k_ra8_err_invalid_size | The offset differs or the end exceeds UINT32_MAX. |
cursor is non-NULL. cursor contains the validated end of the preceding segment. cursor by count times elem. cursor unchanged unless the start already matched. cursor. Definition at line 92 of file book_stream_wire.c.
References k_ra8_err_invalid_size, and k_ra8_ok.
Referenced by internal_validate_header_layout().
|
static |
Validate decoded header fields before walking the table layout.
Checks magic, supported features, exact source length, and scratch ownership-map capacity without reading any table data.
| [in] | ctx | State containing a decoded header. |
| k_ra8_ok | The decoded header fields are supported and bounded. |
| k_ra8_err_invalid_arg | Magic, version, or feature bits are invalid. |
| k_ra8_err_invalid_size | Source or scratch geometry is invalid. |
ctx is non-NULL and its header is decoded. Definition at line 121 of file book_stream_wire.c.
References book_header_t::flags, book_header_t::format_version, stream_validate_t::hdr, k_book_flag_mask_known, k_book_format_version, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_ok, k_stream_bits_per_byte, k_stream_mark_round, book_header_t::magic, book_header_t::node_count, RA8_INTERNAL, stream_validate_t::scratch_cap, stream_validate_t::source_size, and book_header_t::total_size.
Referenced by internal_validate_header_layout().
|
static |
Validate version, flags, exact source length, and canonical layout.
Validates the decoded fields, then walks every table and pool in canonical wire order.
| [in] | ctx | State containing a decoded header. |
| k_ra8_ok | The header and all segment extents are canonical. |
| k_ra8_err_invalid_arg | Magic, version, or feature bits are invalid. |
| k_ra8_err_invalid_size | Source, scratch, or segment geometry is invalid. |
ctx is non-NULL and its header is decoded. Definition at line 157 of file book_stream_wire.c.
References book_header_t::attr_count, book_header_t::attr_off, book_header_t::chapter_count, book_header_t::chapter_off, stream_validate_t::hdr, book_header_t::image_count, book_header_t::image_off, book_header_t::image_pool_off, book_header_t::image_pool_size, internal_layout_segment(), internal_validate_header_fields(), k_book_sizeof_attr, k_book_sizeof_chapter, k_book_sizeof_header, k_book_sizeof_image, k_book_sizeof_node, k_book_sizeof_stylesheet, k_ra8_err_invalid_size, k_ra8_ok, book_header_t::node_count, book_header_t::node_off, RA8_INTERNAL, book_header_t::string_off, book_header_t::string_size, book_header_t::stylesheet_count, book_header_t::stylesheet_off, and book_header_t::total_size.
Referenced by priv_book_stream_read_validate_header().
| ra8_err_t priv_book_stream_nonempty_string_ref | ( | const stream_validate_t * | ctx, |
| uint32_t | off ) |
Require a string reference to name a non-empty interned string.
Proves the offset is a string boundary and rejects a NUL first byte.
| [in] | ctx | Validation state with canonical string-pool geometry. |
| [in] | off | Offset relative to the string pool. |
| k_ra8_ok | The reference begins with a non-NUL byte. |
| k_ra8_err_invalid_arg | The reference is invalid or names an empty string. |
ctx and its exact-read callback are valid. Definition at line 231 of file book_stream_wire.c.
References stream_validate_t::hdr, k_ra8_err_invalid_arg, k_ra8_ok, priv_book_stream_read(), priv_book_stream_string_ref(), RA8_PRIV, and book_header_t::string_off.
Referenced by internal_validate_attrs(), internal_validate_chapters(), internal_validate_images(), and priv_book_stream_validate_element().
| ra8_err_t priv_book_stream_read | ( | const stream_validate_t * | ctx, |
| uint64_t | off, | ||
| uint8_t * | dst, | ||
| uint32_t | len ) |
Read one exact, bounded source span.
Private test seam for the overflow-safe source-range guard used by every streamed validation pass.
| [in] | ctx | Validation source. |
| [in] | off | Source byte offset. |
| [out] | dst | Destination buffer. |
| [in] | len | Exact byte count. |
| k_ra8_ok | The callback supplied the requested bytes. |
| k_ra8_err_invalid_size | The offset or length exceeds the source. |
dst holds len bytes. len bytes. Definition at line 20 of file book_stream_wire.c.
References k_ra8_err_invalid_size, RA8_PRIV, stream_validate_t::read, stream_validate_t::read_ctx, and stream_validate_t::source_size.
Referenced by internal_validate_attrs(), internal_validate_chapters(), internal_validate_crc(), internal_validate_images(), internal_validate_nodes(), priv_book_stream_nonempty_string_ref(), priv_book_stream_read_validate_header(), priv_book_stream_string_ref(), priv_book_stream_validate_string_envelope(), and priv_book_stream_validate_styles().
| ra8_err_t priv_book_stream_read_validate_header | ( | stream_validate_t * | ctx | ) |
Read, decode, and validate the canonical stream header and layout.
Reads the fixed wire header, decodes every little-endian field, and proves that all following tables and pools form one gap-free span.
| [in,out] | ctx | Validation state whose header receives decoded fields. |
| k_ra8_ok | The header and complete source layout are canonical. |
| k_ra8_err_invalid_arg | A magic, version, or feature invariant fails. |
| k_ra8_err_invalid_size | A source, scratch, table, or pool extent fails. |
ctx and its exact-read callback are valid. Definition at line 203 of file book_stream_wire.c.
References stream_validate_t::hdr, internal_decode_header(), internal_validate_header_layout(), k_book_sizeof_header, k_ra8_ok, priv_book_stream_read(), and RA8_PRIV.
Referenced by internal_validate_body().
| ra8_err_t priv_book_stream_string_ref | ( | const stream_validate_t * | ctx, |
| uint32_t | off ) |
Require a referenced offset to name an interned-string boundary.
Accepts the empty-string sentinel at zero; every other offset must be in range and immediately preceded by a NUL terminator.
| [in] | ctx | Validation state with canonical string-pool geometry. |
| [in] | off | Offset relative to the string pool. |
| k_ra8_ok | off names the sentinel or a valid string boundary. |
| k_ra8_err_invalid_arg | The offset is outside the pool or mid-string. |
ctx and its exact-read callback are valid. Definition at line 214 of file book_stream_wire.c.
References stream_validate_t::hdr, k_ra8_err_invalid_arg, k_ra8_ok, priv_book_stream_read(), RA8_PRIV, book_header_t::string_off, and book_header_t::string_size.
Referenced by internal_validate_attrs(), internal_validate_chapters(), priv_book_stream_nonempty_string_ref(), priv_book_stream_validate_metadata(), priv_book_stream_validate_styles(), and priv_book_stream_validate_text().
| ra8_err_t priv_book_stream_validate_string_envelope | ( | const stream_validate_t * | ctx | ) |
Validate the string pool's leading and trailing NUL sentinels.
Private test seam for the read-status and two boundary-byte conditions used before any string reference is accepted.
| [in] | ctx | Validation state with canonical string-pool geometry. |
| k_ra8_ok | Both sentinel bytes are NUL. |
| k_ra8_err_invalid_size | The pool is empty or unreadable. |
| k_ra8_err_invalid_arg | One sentinel byte is non-NUL. |
ctx and its read callback are valid. Definition at line 244 of file book_stream_wire.c.
References stream_validate_t::hdr, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_ok, priv_book_stream_read(), RA8_PRIV, book_header_t::string_off, and book_header_t::string_size.
Referenced by internal_validate_body().