|
SafeAPI Backend POSIX
POSIX/Linux OAL backend for safeAPIFreamwork
|
POSIX sapi_memory backend: a single fixed-size static byte arena with a per-pool intrusive free list carved out of it at sapi_mem_pool_create() time (ADR-018 section 2.3). More...
#include "safeapi/posix_backend/sapi_posix_backend.h"#include "safeapi/utils/cast/sapi_cast.h"#include <stdint.h>#include "safeapi/oal/memory/sapi_mem_util.h"Go to the source code of this file.
Data Structures | |
| struct | posix_mem_pool_state_t |
Macros | |
| #define | SAPI_POSIX_MEM_ARENA_SIZE (1024U * 1024U) |
Typedefs | |
| typedef char | posix_mem_pool_storage_fits_[(sizeof(posix_mem_pool_state_t)<=sizeof(sapi_mem_pool_storage_t)) ? 1 :-1] |
Functions | |
| static sapi_status_t | backend_create (sapi_mem_pool_storage_t *storage, const sapi_mem_pool_config_t *config, sapi_mem_pool_handle_t *out_handle) |
| static sapi_status_t | backend_acquire (sapi_mem_pool_handle_t handle, void **out_block) |
| static bool | block_belongs_to_pool (const posix_mem_pool_state_t *state, const void *block) |
| static sapi_status_t | backend_release (sapi_mem_pool_handle_t handle, void *block) |
| static sapi_status_t | backend_stats (sapi_mem_pool_handle_t handle, size_t *out_free_blocks, size_t *out_used_blocks) |
| const sapi_mem_pool_backend_t * | sapi_posix_backend_memory (void) |
| The POSIX sapi_memory backend (static arena, no malloc). | |
Variables | |
| static uint8_t | g_arena [SAPI_POSIX_MEM_ARENA_SIZE] |
| static size_t | g_arena_used = 0U |
| static const sapi_mem_pool_backend_t | s_posix_memory_backend |
POSIX sapi_memory backend: a single fixed-size static byte arena with a per-pool intrusive free list carved out of it at sapi_mem_pool_create() time (ADR-018 section 2.3).
This is static partitioning, not malloc()/free(): the arena's total size (SAPI_POSIX_MEM_ARENA_SIZE, default 1 MiB) is a compile-time constant, every pool's claim against it is a one-way bump allocation checked against remaining arena space (SAPI_STATUS_RESOURCE_EXHAUSTED rather than growing anything), and no memory is ever returned to the arena once a pool claims it - only individual blocks are recycled within their own pool's free list. Matches REQ-OAL-MEM-001: pools are expected to be reserved during system initialization.
Known constraint: the free list is intrusive (a free block's first sizeof(void*) bytes store the pointer to the next free block in the same pool), so block_size must be >= sizeof(void*). A pool requesting a smaller block_size is rejected with SAPI_STATUS_INVALID_PARAM rather than silently corrupting adjacent memory.
Known simplification: the global arena cursor (g_arena_used) and each pool's free-list head are not protected by a lock. REQ-OAL-MEM-001 frames pool reservation as an initialization-time activity (a single thread, before concurrent operation begins), so backend_create() being unsynchronized matches that expectation; acquire()/release() on an already-created pool being called concurrently from multiple threads is NOT safe with this backend and is a documented limitation, not an oversight - a production backend needing concurrent acquire/release would need a lock or a lock-free free-list (e.g. compare-and-swap), deliberately left out of this first cut.
Definition in file sapi_posix_backend_memory.c.
| #define SAPI_POSIX_MEM_ARENA_SIZE (1024U * 1024U) |
Local makros
Definition at line 41 of file sapi_posix_backend_memory.c.
| typedef char posix_mem_pool_storage_fits_[(sizeof(posix_mem_pool_state_t)<=sizeof(sapi_mem_pool_storage_t)) ? 1 :-1] |
Definition at line 56 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 137 of file sapi_posix_backend_memory.c.
|
static |
Local function declarations
Definition at line 85 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 174 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 193 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 161 of file sapi_posix_backend_memory.c.
| const sapi_mem_pool_backend_t * sapi_posix_backend_memory | ( | void | ) |
The POSIX sapi_memory backend (static arena, no malloc).
Global variables declarations Global functions
Definition at line 77 of file sapi_posix_backend_memory.c.
|
static |
Local variables declarations
Definition at line 68 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 69 of file sapi_posix_backend_memory.c.
|
static |
Definition at line 70 of file sapi_posix_backend_memory.c.