I am trying to incorporate mbedTLS library to segger embOS 3.90. The mbedtls library uses heap allocation for certain operation using function mbedtls_calloc. I tried to use OS_malloc function as below. However,
#define mbedtls_calloc(a,b) OS_malloc(a*b)
But it is always returning NULL. However, if I use the same function anywhere outside mbedtls - par se, am using the function withing thread function, it seesms to be working fine.
Although root cause is unclear, it is inferred that, while utilizing OS_malloc for mbedTLS crypto purpose, it is returning NULL. Support in resolving the issue would be appreciated.
Hi Gopi,
May I know what Mbed TLS version you are using?
Have you tried using MBEDTLS_PLATFORM_CALLOC_MACRO , MBEDTLS_PLATFORM_FREE_MACRO instead?
Do you have MBEDTLS_PLATFORM_MEMORY defined?
If you are using gcc based compiler, have you tried looking at the processed code to verify that your MACRO is interpreted as you expect?
You can do it by replacing the -o xxx.o in your gcc compilation with -E
Hi gopi,
Thank you for your cooperation.
Please note that the definition is MBEDTLS_PLATFORM_CALLOC_MACRO not MBEDTLS_PLATFORM_CALLOC_MACRO(a,b), so perhaps it behaves different with your toolchain.
I am assuming you are working on latest Mbed TLS version, so I would suggest you not define MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_CALLOC_MACRO , but implements your own calloc and free functions, with the following signatures: