diff --git a/cr_hsm_alloc.c b/cr_hsm_alloc.c index f4bfd0c..5ded3df 100644 --- a/cr_hsm_alloc.c +++ b/cr_hsm_alloc.c @@ -17,6 +17,10 @@ /* --------------------- */ +static int alloc_counter = 0; + +/* --------------------- */ + const NFast_MallocUpcalls my_hsm_malloc_upcalls = { my_hsm_malloc, my_hsm_realloc, my_hsm_free @@ -27,6 +31,7 @@ const NFast_MallocUpcalls my_hsm_malloc_upcalls = void *my_hsm_malloc( size_t nbytes, struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx ) { + alloc_counter++; return malloc( nbytes ); } @@ -44,6 +49,14 @@ void my_hsm_free( void *ptr, struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx ) { free( ptr ); + alloc_counter--; +} + +/* --------------------- */ + +int my_hsm_get_alloc_counter( void ) +{ + return alloc_counter; } #endif // HSM diff --git a/cr_hsm_alloc.h b/cr_hsm_alloc.h index c7c85a6..74e09f9 100644 --- a/cr_hsm_alloc.h +++ b/cr_hsm_alloc.h @@ -22,6 +22,8 @@ void *my_hsm_realloc( void *ptr, size_t nbytes, void my_hsm_free( void *ptr, struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx ); +int my_hsm_get_alloc_counter( void ); + #ifdef __cplusplus } #endif diff --git a/cr_hsm_code.c b/cr_hsm_code.c index a285923..c8070e3 100644 --- a/cr_hsm_code.c +++ b/cr_hsm_code.c @@ -119,6 +119,7 @@ #ifdef USE_HSM #include "cr_hsm_code.h" +#include "cr_hsm_alloc.h" #include "cr_hsm_bignum.h" #include "cr_generate_id.h" #include "cr_generate_id_private.h" @@ -179,7 +180,8 @@ int hsm_initialize( void ) #endif // init HSM - ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL ); + ret_code = NFastApp_Init( &hsmHandle, my_hsm_alloc, my_hsm_realloc, my_hsm_free, NULL ); + //ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL ); if ( ret_code != CR_GENID_SUCCESS ) { SetErrorInfo( __FUNCTION__, __LINE__ );