Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_safe_ptr.c File Reference

See sapi_safe_ptr.h for behavior. More...

Include dependency graph for sapi_safe_ptr.c:

Go to the source code of this file.

Macros

#define SAPI_SAFE_PTR_CANARY   ((uint32_t)0x5AFE9021U)

Functions

sapi_status_t sapi_safe_ptr_init (sapi_safe_ptr_t *sp, void *ptr, size_t size)
 Initializes sp to wrap [ptr, ptr + size), writing the canary.
bool sapi_safe_ptr_is_valid (const sapi_safe_ptr_t *sp)
 Checks whether sp currently wraps a valid, non-invalidated region.
sapi_status_t sapi_safe_ptr_get (const sapi_safe_ptr_t *sp, void **out_ptr)
 Retrieves the wrapped pointer directly (the whole region, no offset) after validating it.
sapi_status_t sapi_safe_ptr_offset (const sapi_safe_ptr_t *sp, size_t offset, size_t length, void **out_ptr)
 Computes a bounds-checked pointer at offset within sp's region, verifying the caller's intended access of length bytes starting at offset stays within the wrapped region.
void sapi_safe_ptr_invalidate (sapi_safe_ptr_t *sp)
 Invalidates sp: clears the wrapped pointer and the canary, so every subsequent access on sp fails SAPI_STATUS_DATA_CORRUPTION.

Detailed Description

See sapi_safe_ptr.h for behavior.

Definition in file sapi_safe_ptr.c.

Macro Definition Documentation

◆ SAPI_SAFE_PTR_CANARY

#define SAPI_SAFE_PTR_CANARY   ((uint32_t)0x5AFE9021U)

Fixed canary value written by sapi_safe_ptr_init() and checked by every access function - an arbitrary, distinctive bit pattern (not 0x00000000 or 0xFFFFFFFF, which a plain zeroed or all-ones-erased memory region could produce by coincidence).

Definition at line 15 of file sapi_safe_ptr.c.