11bcc5e0c3
- Add static memory pool implementation (se050_mem_pool.c/h) - Replace all malloc/calloc with pool allocations - Replace all free with pool deallocations - Remove strdup usage (use fixed-size buffer instead) - Update I2C HAL to use fixed-size dev_path array - All 24 tests pass with static memory only Suitable for embedded environments (u-boot, ESP32) without heap.
107 lines
2.7 KiB
C
107 lines
2.7 KiB
C
/**
|
|
* @file se050_mem_pool.h
|
|
* @brief Static Memory Pool for Embedded Systems
|
|
*
|
|
* Replaces malloc/calloc with pre-allocated static pools.
|
|
* Suitable for u-boot, ESP32, and other embedded environments.
|
|
*/
|
|
|
|
#ifndef SE050_MEM_POOL_H
|
|
#define SE050_MEM_POOL_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
/* Configuration: Pool sizes */
|
|
#ifndef SE050_POOL_SESSION_COUNT
|
|
#define SE050_POOL_SESSION_COUNT 4
|
|
#endif
|
|
|
|
#ifndef SE050_POOL_SCP03_COUNT
|
|
#define SE050_POOL_SCP03_COUNT 4
|
|
#endif
|
|
|
|
#ifndef SE050_POOL_KEYSTORE_COUNT
|
|
#define SE050_POOL_KEYSTORE_COUNT 2
|
|
#endif
|
|
|
|
#ifndef SE050_POOL_KEYSTORE_MAX_OBJECTS
|
|
#define SE050_POOL_KEYSTORE_MAX_OBJECTS 8
|
|
#endif
|
|
|
|
#ifndef SE050_POOL_RNG_COUNT
|
|
#define SE050_POOL_RNG_COUNT 2
|
|
#endif
|
|
|
|
#ifndef SE050_POOL_I2C_HAL_COUNT
|
|
#define SE050_POOL_I2C_HAL_COUNT 2
|
|
#endif
|
|
|
|
/* Forward declarations */
|
|
struct se050_session_ctx;
|
|
struct se050_scp03_ctx;
|
|
struct se050_keystore_ctx;
|
|
struct se050_rng_ctx;
|
|
struct se050_i2c_hal;
|
|
|
|
/* ============================================================================
|
|
* Memory Pool API
|
|
* ============================================================================ */
|
|
|
|
/**
|
|
* @brief Initialize all memory pools
|
|
*
|
|
* Must be called before any other SE050 functions.
|
|
*
|
|
* @return 0 on success, -1 on error
|
|
*/
|
|
int se050_mem_pool_init(void);
|
|
|
|
/**
|
|
* @brief Cleanup all memory pools
|
|
*
|
|
* Zeroizes all allocated memory before freeing.
|
|
*/
|
|
void se050_mem_pool_cleanup(void);
|
|
|
|
/* Session pool */
|
|
struct se050_session_ctx *se050_session_alloc_pool(void);
|
|
void se050_session_free_pool(struct se050_session_ctx *ctx);
|
|
|
|
/* SCP03 pool */
|
|
struct se050_scp03_ctx *se050_scp03_alloc_pool(void);
|
|
void se050_scp03_free_pool(struct se050_scp03_ctx *ctx);
|
|
|
|
/* Keystore pool */
|
|
struct se050_keystore_ctx *se050_keystore_alloc_pool(void);
|
|
void se050_keystore_free_pool(struct se050_keystore_ctx *ctx);
|
|
|
|
/* RNG pool */
|
|
struct se050_rng_ctx *se050_rng_alloc_pool(void);
|
|
void se050_rng_free_pool(struct se050_rng_ctx *ctx);
|
|
|
|
/* I2C HAL pool */
|
|
struct se050_i2c_hal *se050_i2c_hal_alloc_pool(void);
|
|
void se050_i2c_hal_free_pool(struct se050_i2c_hal *hal);
|
|
|
|
/* ============================================================================
|
|
* Debug/Statistics
|
|
* ============================================================================ */
|
|
|
|
/**
|
|
* @brief Get pool statistics
|
|
*/
|
|
typedef struct {
|
|
int total;
|
|
int used;
|
|
int free;
|
|
} se050_pool_stats_t;
|
|
|
|
void se050_mem_pool_stats(se050_pool_stats_t *session,
|
|
se050_pool_stats_t *scp03,
|
|
se050_pool_stats_t *keystore,
|
|
se050_pool_stats_t *rng,
|
|
se050_pool_stats_t *i2c_hal);
|
|
|
|
#endif /* SE050_MEM_POOL_H */
|