|
Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Thin, MISRA-visible wrappers over the three raw memory-block primitives (fill/copy/compare) every other safeAPIFreamwork or downstream-application module needs but has no business calling libc's <string.h> directly for - sapi_mem_set()/sapi_mem_copy()/ sapi_mem_compare() are the ONE sanctioned call site for each underlying libc function, so an audit for "does this codebase call libc string/memory functions directly" has exactly one file to check instead of grepping every translation unit for <string.h>. Deliberately NOT a "safe string library" (no strcpy/strcat/strlen-style variable-length text handling) - this framework and every application built on it work in fixed-size buffers throughout (CLAUDE.md: no malloc/free), so the only primitives actually needed are fixed-length block operations. More...
#include <stddef.h>#include <string.h>Go to the source code of this file.
Functions | |
| static void | sapi_mem_set (void *dest, int value, size_t count) |
Fills count bytes starting at dest with value - the one sanctioned call site for libc memset() in this framework (see this file's own doc). | |
| static void | sapi_mem_copy (void *dest, const void *src, size_t count) |
Copies count bytes from src to dest - the one sanctioned call site for libc memcpy() in this framework (see this file's own doc). | |
| static int | sapi_mem_compare (const void *a, const void *b, size_t count) |
Byte-for-byte compares count bytes of a against b - the one sanctioned call site for libc memcmp() in this framework (see this file's own doc). | |
Thin, MISRA-visible wrappers over the three raw memory-block primitives (fill/copy/compare) every other safeAPIFreamwork or downstream-application module needs but has no business calling libc's <string.h> directly for - sapi_mem_set()/sapi_mem_copy()/ sapi_mem_compare() are the ONE sanctioned call site for each underlying libc function, so an audit for "does this codebase call libc string/memory functions directly" has exactly one file to check instead of grepping every translation unit for <string.h>. Deliberately NOT a "safe string library" (no strcpy/strcat/strlen-style variable-length text handling) - this framework and every application built on it work in fixed-size buffers throughout (CLAUDE.md: no malloc/free), so the only primitives actually needed are fixed-length block operations.
static inline, header-only, no backend/.c file: these are trivial, stateless wrappers with no OS dependency at all (unlike the seven real OAL services - sapi_timer, sapi_nvm, sapi_memory, etc. - see sapi_appmanager.h's own note on that distinction) - same convention as sapi_notify.h's SAFEAPI_DECLARE_CALLBACK_LIST (ADR-030).
Definition in file sapi_mem_util.h.
|
inlinestatic |
Fills count bytes starting at dest with value - the one sanctioned call site for libc memset() in this framework (see this file's own doc).
| dest | Caller-owned storage, at least count bytes. Must not be NULL unless count is 0. |
| value | Byte value to write, same truncation-to-unsigned-char convention as memset() itself. |
| count | Number of bytes to fill; 0 is a no-op. |
Definition at line 39 of file sapi_mem_util.h.
|
inlinestatic |
Copies count bytes from src to dest - the one sanctioned call site for libc memcpy() in this framework (see this file's own doc).
| dest | Destination, caller-owned, at least count bytes. Must not be NULL unless count is 0. |
| src | Source, caller-owned, at least count bytes. Must not overlap dest (same contract as memcpy() itself - use a genuinely overlap-safe primitive instead if that is ever needed; none is provided here since nothing in this codebase currently copies overlapping ranges). Must not be NULL unless count is 0. |
| count | Number of bytes to copy; 0 is a no-op. |
Definition at line 56 of file sapi_mem_util.h.
|
inlinestatic |
Byte-for-byte compares count bytes of a against b - the one sanctioned call site for libc memcmp() in this framework (see this file's own doc).
| a,b | Caller-owned, at least count bytes each. Must not be NULL unless count is 0. |
| count | Number of bytes to compare; 0 always returns 0. |
Definition at line 70 of file sapi_mem_util.h.