/** * @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 #include /* 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 */