Topic: User implementation of XMALLOC/XFREE


I'm new to wolfSSL and the topic of secure communication.

I'm trying to implement wolfSSL into our product which runs on an ARM Cortex M4 processor based on the uTasker OS.
My goal is to use a TLS v1.2 connection to another embedded device (which FW I don't have any influence on), and to shrink the wolfSSL implementation to an absolute minimum.

I have made my own XMALLOC/XFREE implementation, but the uTasker uMalloc function is not as intelligent as the standard C-library malloc. It doesn't support free for more than the last allocated block...

I came across the option to use static I/O buffers by looking at the type parameter for the XMALLOC function. If I search in the source code, I can see more than 50 different memory allocation types.

- Does anyone have more information on how to use these memory types?
- Can they be used to reduce the use of dynamic memory?
- What purpose does the heap parameter have? Sometimes it is zero and sometimes it refers to an already allocated memory block (but the size is much larger than the old block).

I have already looked in the wolfSSL documentation for the XMALLOC function, but I didn't get the answers I was looking for...

Best regards


Re: User implementation of XMALLOC/XFREE

[This was also answered through the wolfSSL support channel, but copying here for user reference.]

Since wolfSSL allows you to map XMALLOC and XFREE to a custom function, you could have your own memory handling "malloc" and "free" functions that handle memory as you desire. This could be managing memory from a single block or block(s) of static memory or pre-allocated buffers. We don't have a set of example custom memory functions out of the box for this, but provide the abstraction.

The heap hint gives the memory handlers an idea of what kind of memory the pointer is for. In some cases, this allows the memory handlers to reuse or manage memory more efficiently, keeping track of what types of memory they have allocated and freed. We don't currently have documentation about the different kinds of heap hint types, but this has been added to our documentation request list.

Best Regards,