|
Safe Data API
CRC-protected (optionally redundant) data containers for Zephyr
|
|
v0.0-dev+gbb519af | |
Integrity-event reporting: fault handler, statistics, self-test. More...
Data Structures | |
| struct | safe_data_fault_info |
| Event descriptor passed to the registered fault handler. More... | |
| struct | safe_data_stats |
| Global fault/recovery statistics (CONFIG_SAFE_DATA_STATS). More... | |
Typedefs | |
| typedef void(* | safe_data_fault_cb_t) (const struct safe_data_fault_info *info) |
| Fault/diagnostic event callback. | |
Enumerations | |
| enum | safe_data_fault_kind { SAFE_DATA_FAULT_KIND_UNRECOVERABLE , SAFE_DATA_FAULT_KIND_RECOVERED_TAG , SAFE_DATA_FAULT_KIND_RECOVERED_PAYLOAD , SAFE_DATA_FAULT_KIND_LOCK_TIMEOUT , SAFE_DATA_FAULT_KIND_OVERWRITTEN , SAFE_DATA_FAULT_KIND_MUTATOR_CLAMPED } |
| Kind of integrity event reported to the fault handler / statistics. More... | |
Functions | |
| int | safe_data_fault_handler_register (safe_data_fault_cb_t cb) |
| Register the fault handler callback. | |
| void | safe_data_fault_handler (const void *payload, size_t len) |
| Legacy user-overridable (weak) fault handler. | |
| int | safe_data_stats_get (struct safe_data_stats *out) |
| Snapshot the global statistics. | |
| void | safe_data_stats_reset (void) |
| Reset all statistics counters to zero. | |
| int | safe_data_selftest (void) |
| Self-test of the integrity mechanism itself. | |
| int | safe_data_selftest_result (void) |
| Result of the boot-time self-test (CONFIG_SAFE_DATA_SELFTEST_BOOT). | |
Integrity-event reporting: fault handler, statistics, self-test.
The observability interface a health monitor hooks into. Every integrity event (recovery, unrecoverable corruption, lock timeout, overwritten contents, clamped mutator return) is reported exactly once per detection.
| typedef void(* safe_data_fault_cb_t) (const struct safe_data_fault_info *info) |
Fault/diagnostic event callback.
May be invoked while the affected container's lock is held: the handler must not block and must not access any safe container (AoU: record the event, set a flag/semaphore for a monitor thread, or drive the safe state).
| info | Event descriptor (kind, affected payload, size). Only valid for the duration of the call; copy what you need. |
Definition at line 149 of file safe_data.h.
| enum safe_data_fault_kind |
Kind of integrity event reported to the fault handler / statistics.
Definition at line 114 of file safe_data.h.
| void safe_data_fault_handler | ( | const void * | payload, |
| size_t | len ) |
Legacy user-overridable (weak) fault handler.
Called for unrecoverable faults when CONFIG_SAFE_DATA_FAULT_HANDLER is selected and no callback is registered via safe_data_fault_handler_register() (the registered callback takes precedence). The default implementation logs and returns. The same execution-context constraints apply as for safe_data_fault_cb_t.
| payload | Pointer to the payload whose integrity check failed. |
| len | Payload size in bytes. |
Definition at line 90 of file safe_data.c.
Referenced by safe_event().
Satisfies requirement SD-REQ-011 (Configurable unrecoverable-fault reaction).
| int safe_data_fault_handler_register | ( | safe_data_fault_cb_t | cb | ) |
Register the fault handler callback.
When registered, the callback receives ALL integrity events (recoveries, timeouts, overwritten-corrupt, clamped returns), independent of the configured CONFIG_SAFE_DATA_FAULT_* reaction - which still governs the control-flow response to an unrecoverable fault (return vs panic).
| cb | Handler, or NULL to unregister. |
Definition at line 97 of file safe_data.c.
References fault_cb.
Satisfies requirement SD-REQ-013 (Fault-handler registration and event reporting).
| int safe_data_selftest | ( | void | ) |
Self-test of the integrity mechanism itself.
Runs a known-answer test of the configured CRC backend and a seal/corrupt/detect(/recover) round trip on a scratch container, without invoking the configured fault reaction and without polluting the statistics.
Definition at line 490 of file safe_data.c.
References event_mute, SAFE_DATA_KAT_EXPECTED, SAFE_DATA_RECOVERED, safe_data_verify_repair(), safe_tag(), and verify_quiet().
Referenced by safe_data_boot_selftest().
Satisfies requirement SD-REQ-017 (Integrity-mechanism self-test).
| int safe_data_selftest_result | ( | void | ) |
Result of the boot-time self-test (CONFIG_SAFE_DATA_SELFTEST_BOOT).
Definition at line 551 of file safe_data.c.
References boot_selftest_result.
| int safe_data_stats_get | ( | struct safe_data_stats * | out | ) |
Snapshot the global statistics.
| out | Destination for the counter snapshot. |
Definition at line 112 of file safe_data.c.
References safe_data_stats::lock_timeouts, safe_data_stats::mutator_clamped, safe_data_stats::overwritten, safe_data_stats::recovered_payload, safe_data_stats::recovered_tag, SAFE_DATA_FAULT_KIND_LOCK_TIMEOUT, SAFE_DATA_FAULT_KIND_MUTATOR_CLAMPED, SAFE_DATA_FAULT_KIND_OVERWRITTEN, SAFE_DATA_FAULT_KIND_RECOVERED_PAYLOAD, SAFE_DATA_FAULT_KIND_RECOVERED_TAG, SAFE_DATA_FAULT_KIND_UNRECOVERABLE, stat_counters, and safe_data_stats::unrecoverable.
Satisfies requirements SD-REQ-002 (Argument validation), and SD-REQ-012 (Integrity-event statistics).
| void safe_data_stats_reset | ( | void | ) |
Reset all statistics counters to zero.
Definition at line 134 of file safe_data.c.
References stat_counters.