From 35415a0c46f142fdb00acc4a8e38c8db832b3e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 4 Jan 2022 10:23:34 +0100 Subject: [PATCH] Add counter access to memory debug API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- include/mbedtls/memory_buffer_alloc.h | 13 +++++++++++++ library/memory_buffer_alloc.c | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/mbedtls/memory_buffer_alloc.h b/include/mbedtls/memory_buffer_alloc.h index d4737f5c4..ee1973cd0 100644 --- a/include/mbedtls/memory_buffer_alloc.h +++ b/include/mbedtls/memory_buffer_alloc.h @@ -90,6 +90,19 @@ void mbedtls_memory_buffer_set_verify( int verify ); */ void mbedtls_memory_buffer_alloc_status( void ); +/** + * \brief Get the number of alloc/free so far. + * + * \param alloc_count Number of allocations. + * \param free_count Number of frees. + */ +void mbedtls_memory_buffer_alloc_count_get( size_t *alloc_count, size_t *free_count ); + +/** + * \brief Reset alloc/free counters. + */ +void mbedtls_memory_buffer_alloc_count_reset( void ); + /** * \brief Get the peak heap usage so far * diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c index 0d5d27d3d..ddb9595fb 100644 --- a/library/memory_buffer_alloc.c +++ b/library/memory_buffer_alloc.c @@ -522,6 +522,18 @@ void mbedtls_memory_buffer_alloc_status( void ) } } +void mbedtls_memory_buffer_alloc_count_get( size_t *alloc_count, size_t *free_count ) +{ + *alloc_count = heap.alloc_count; + *free_count = heap.free_count; +} + +void mbedtls_memory_buffer_alloc_count_reset( void ) +{ + heap.alloc_count = 0; + heap.free_count = 0; +} + void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks ) { *max_used = heap.maximum_used;