|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Private wire geometry for strict RABOOK1 stream validation. More...
Go to the source code of this file.
Data Structures | |
| struct | stream_validate_t |
| Immutable validation state shared by the bounded table passes. More... | |
Functions | |
| static uint16_t | internal_book_stream_le16 (const uint8_t *p) |
| Decode one little-endian 16-bit field from unaligned bytes. | |
| static uint32_t | internal_book_stream_le32 (const uint8_t *p) |
| Decode one little-endian 32-bit field from unaligned bytes. | |
| 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_read (const stream_validate_t *ctx, uint64_t off, uint8_t *dst, uint32_t len) |
| Read one exact, bounded source span. | |
| ra8_err_t | priv_book_stream_validate_string_envelope (const stream_validate_t *ctx) |
| Validate the string pool's leading and trailing NUL sentinels. | |
| ra8_err_t | priv_book_stream_validate_metadata (const stream_validate_t *ctx) |
| Validate metadata string references and the optional cover index. | |
| ra8_err_t | priv_book_stream_validate_element (const stream_validate_t *ctx, const uint8_t *rec, uint32_t *attr_cursor) |
| Validate one element node and its canonical attribute span. | |
| ra8_err_t | priv_book_stream_validate_text (const stream_validate_t *ctx, const uint8_t *rec) |
| Validate one text node's element-only fields and string reference. | |
| ra8_err_t | priv_book_stream_validate_styles (const stream_validate_t *ctx) |
| Validate every stylesheet source and optional chapter scope. | |
Private wire geometry for strict RABOOK1 stream validation.
Centralizes fixed wire offsets, bit geometry, and the bounded caller-owned validation state used only by the stream validator implementation.
Definition in file book_stream_internal.h.
| enum stream_bit_t : uint8_t |
Bit geometry shared by wire decoding and the node ownership map.
| Enumerator | |
|---|---|
| k_stream_bits_per_byte | Bits represented by one byte. |
| k_stream_mark_round | Ceiling-division numerator bias. |
| k_stream_le_shift_3 | Shift of byte three in a uint32. |
Definition at line 71 of file book_stream_internal.h.
| enum stream_header_off_t : uint8_t |
Wire offsets inside the fixed 100-byte RABOOK1 header.
Definition at line 19 of file book_stream_internal.h.
| enum stream_image_off_t : uint8_t |
Wire offsets inside a 24-byte image descriptor.
Definition at line 58 of file book_stream_internal.h.
| enum stream_node_off_t : uint8_t |
Wire offsets inside a 24-byte DOM node record.
Definition at line 46 of file book_stream_internal.h.
|
inlinestatic |
Decode one little-endian 16-bit field from unaligned bytes.
Combines two octets explicitly so behavior is independent of host byte order and does not require an aligned integer load.
| [in] | p | Readable two-byte wire field. |
| UINT16_C(0) | Both wire bytes are zero. |
| UINT16_MAX | Both wire bytes are 0xff. |
p addresses at least two readable bytes. Definition at line 92 of file book_stream_internal.h.
References k_stream_bits_per_byte, and RA8_INTERNAL.
Referenced by internal_validate_images(), internal_validate_raster(), internal_validate_svg(), priv_book_stream_validate_element(), and priv_book_stream_validate_text().
|
inlinestatic |
Decode one little-endian 32-bit field from unaligned bytes.
Combines four octets explicitly so behavior is independent of host byte order and does not require an aligned integer load.
| [in] | p | Readable four-byte wire field. |
| UINT32_C(0) | All four wire bytes are zero. |
| UINT32_MAX | All four wire bytes are 0xff. |
p addresses at least four readable bytes. Definition at line 112 of file book_stream_internal.h.
References k_stream_bits_per_byte, k_stream_le_shift_3, and RA8_INTERNAL.
Referenced by internal_decode_header(), internal_validate_attrs(), internal_validate_chapters(), internal_validate_images(), internal_validate_one_node(), internal_validate_raster(), internal_validate_svg(), priv_book_stream_validate_element(), priv_book_stream_validate_styles(), and priv_book_stream_validate_text().
| 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_element | ( | const stream_validate_t * | ctx, |
| const uint8_t * | rec, | ||
| uint32_t * | attr_cursor ) |
Validate one element node and its canonical attribute span.
Private test seam for first-attribute and remaining-count guards.
| [in] | ctx | Validation state with canonical strings and attributes. |
| [in] | rec | One complete element-node wire record. |
| [in,out] | attr_cursor | Next unowned attribute index. |
| k_ra8_ok | The element and attribute span are canonical. |
| k_ra8_err_invalid_arg | One element invariant is invalid. |
attr_cursor does not exceed the attribute count. attr_cursor. Definition at line 201 of file book_stream.c.
References book_header_t::attr_count, stream_validate_t::hdr, internal_book_stream_le16(), internal_book_stream_le32(), k_book_nil, k_ra8_err_invalid_arg, k_ra8_ok, k_stream_node_attr_count, k_stream_node_first_attr, k_stream_node_name, k_stream_node_text, priv_book_stream_nonempty_string_ref(), and RA8_PRIV.
Referenced by internal_validate_one_node().
| ra8_err_t priv_book_stream_validate_metadata | ( | const stream_validate_t * | ctx | ) |
Validate metadata string references and the optional cover index.
Private test seam for the nil-cover and image-count bounds policy.
| [in] | ctx | Validation state with a checked string envelope. |
| k_ra8_ok | All references are valid. |
| k_ra8_err_invalid_arg | A string or cover reference is invalid. |
Definition at line 38 of file book_stream.c.
References book_header_t::author_off, book_header_t::cover_image_index, stream_validate_t::hdr, book_header_t::identifier_off, book_header_t::image_count, k_book_nil, k_ra8_err_invalid_arg, k_ra8_ok, book_header_t::language_off, priv_book_stream_string_ref(), RA8_PRIV, and book_header_t::title_off.
Referenced by internal_validate_body().
| 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().
| ra8_err_t priv_book_stream_validate_styles | ( | const stream_validate_t * | ctx | ) |
Validate every stylesheet source and optional chapter scope.
Private test seam for read status, nil scope, and chapter bounds.
| [in] | ctx | Validation state with canonical stylesheet geometry. |
| k_ra8_ok | Every source and optional scope is valid. |
| k_ra8_err_invalid_arg | One source or scope is invalid. |
ctx and its callback are valid. Definition at line 398 of file book_stream.c.
References book_header_t::chapter_count, stream_validate_t::hdr, internal_book_stream_le32(), k_book_nil, k_book_sizeof_stylesheet, k_ra8_err_invalid_arg, k_ra8_ok, priv_book_stream_read(), priv_book_stream_string_ref(), RA8_PRIV, book_header_t::stylesheet_count, and book_header_t::stylesheet_off.
Referenced by internal_validate_body().
| ra8_err_t priv_book_stream_validate_text | ( | const stream_validate_t * | ctx, |
| const uint8_t * | rec ) |
Validate one text node's element-only fields and string reference.
Private test seam for the four-condition text-node invariant.
| [in] | ctx | Validation state with a checked string envelope. |
| [in] | rec | One complete text-node wire record. |
| k_ra8_ok | All element-only fields are empty or nil. |
| k_ra8_err_invalid_arg | One field or string reference is invalid. |
rec has the text node kind. Definition at line 242 of file book_stream.c.
References internal_book_stream_le16(), internal_book_stream_le32(), k_book_nil, k_ra8_err_invalid_arg, k_stream_node_attr_count, k_stream_node_first_attr, k_stream_node_first_child, k_stream_node_name, k_stream_node_text, priv_book_stream_string_ref(), and RA8_PRIV.
Referenced by internal_validate_one_node().