My Project
Functions
Memory Handling

Functions

void * wolfSSL_Malloc (size_t size, void *heap, int type)
 This function is similar to malloc(), but calls the memory allocation function which wolfSSL has been configured to use. By default, wolfSSL uses malloc(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Malloc is not called directly by wolfSSL, but instead called by macro XMALLOC. For the default build only the size argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included. More...
 
void wolfSSL_Free (void *ptr, void *heap, int type)
 This function is similar to free(), but calls the memory free function which wolfSSL has been configured to use. By default, wolfSSL uses free(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Free is not called directly by wolfSSL, but instead called by macro XFREE. For the default build only the ptr argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included. More...
 
void * wolfSSL_Realloc (void *ptr, size_t size, void *heap, int type)
 This function is similar to realloc(), but calls the memory re-allocation function which wolfSSL has been configured to use. By default, wolfSSL uses realloc(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Realloc is not called directly by wolfSSL, but instead called by macro XREALLOC. For the default build only the size argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included. More...
 
int wolfSSL_SetAllocators (wolfSSL_Malloc_cb, wolfSSL_Free_cb, wolfSSL_Realloc_cb)
 This function registers the allocation functions used by wolfSSL. By default, if the system supports it, malloc/free and realloc are used. Using this function allows the user at runtime to install their own memory handlers. More...
 
int wolfSSL_StaticBufferSz (byte *buffer, word32 sz, int flag)
 This function is available when static memory feature is used (–enable-staticmemory). It gives the optimum buffer size for memory “buckets”. This allows for a way to compute buffer size so that no extra unused memory is left at the end after it has been partitioned. The returned value, if positive, is the computed buffer size to use. More...
 
int wolfSSL_MemoryPaddingSz (void)
 This function is available when static memory feature is used (–enable-staticmemory). It gives the size of padding needed for each partition of memory. This padding size will be the size needed to contain a memory management structure along with any extra for memory alignment. More...
 
int wolfSSL_CTX_load_static_memory (WOLFSSL_CTX **ctx, wolfSSL_method_func method, unsigned char *buf, unsigned int sz, int flag, int max)
 This function is used to set aside static memory for a CTX. Memory set aside is then used for the CTX’s lifetime and for any SSL objects created from the CTX. By passing in a NULL ctx pointer and a wolfSSL_method_func function the creation of the CTX itself will also use static memory. wolfSSL_method_func has the function signature of WOLFSSL_METHOD* (wolfSSL_method_func)(void heap);. Passing in 0 for max makes it behave as if not set and no max concurrent use restrictions is in place. The flag value passed in determines how the memory is used and behavior while operating. Available flags are the following. More...
 
int wolfSSL_CTX_is_static_memory (WOLFSSL_CTX *ctx, WOLFSSL_MEM_STATS *mem_stats)
 This function does not change any of the connections behavior and is used only for gathering information about the static memory usage. More...
 
int wolfSSL_is_static_memory (WOLFSSL *ssl, WOLFSSL_MEM_CONN_STATS *mem_stats)
 wolfSSL_is_static_memory is used to gather information about a SSL’s static memory usage. The return value indicates if static memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent CTX when loading in static memory. More...
 
int wc_LoadStaticMemory (WOLFSSL_HEAP_HINT *hint, unsigned char *buf, unsigned int sz, int flag, int max)
 This function is used to set aside static memory for wolfCrypt use. Memory can be used by passing the created heap hint into functions. An example of this is when calling wc_InitRng_ex. The flag value passed in determines how the memory is used and behavior while operating, in general wolfCrypt operations will use memory from a WOLFMEM_GENERAL pool. Available flags are the following. More...
 
void * XMALLOC (size_t n, void *heap, int type)
 This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n)) More...
 
void * XREALLOC (void *p, size_t n, void *heap, int type)
 This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n)) More...
 
void XFREE (void *p, void *heap, int type)
 This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n)) More...
 

Detailed Description

Function Documentation

◆ wc_LoadStaticMemory()

int wc_LoadStaticMemory ( WOLFSSL_HEAP_HINT *  hint,
unsigned char *  buf,
unsigned int  sz,
int  flag,
int  max 
)

This function is used to set aside static memory for wolfCrypt use. Memory can be used by passing the created heap hint into functions. An example of this is when calling wc_InitRng_ex. The flag value passed in determines how the memory is used and behavior while operating, in general wolfCrypt operations will use memory from a WOLFMEM_GENERAL pool. Available flags are the following.

WOLFMEM_GENERAL - default general memory

WOLFMEM_IO_POOL - used for input/output buffer when sending receiving messages. Overrides general memory, so all memory in buffer passed in is used for IO. WOLFMEM_IO_FIXED - same as WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for their lifetime. WOLFMEM_TRACK_STATS - each SSL keeps track of memory stats while running

Returns
If successful, 0 will be returned.
All unsuccessful return values will be less than 0.
Parameters
hintWOLFSSL_HEAP_HINT structure to use
bufmemory to use for all operations.
szsize of memory buffer being passed in.
flagtype of memory.
maxmax concurrent operations (handshakes, IO).

Example

WOLFSSL_HEAP_HINT hint;
int ret;
unsigned char memory[MAX];
int memorySz = MAX;
int flag = WOLFMEM_GENERAL | WOLFMEM_TRACK_STATS;
...
// load in memory for use
ret = wc_LoadStaticMemory(&hint, memory, memorySz, flag, 0);
if (ret != SSL_SUCCESS) {
// handle error case
}
...
ret = wc_InitRng_ex(&rng, hint, 0);
// check ret value
int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT *hint, unsigned char *buf, unsigned int sz, int flag, int max)
This function is used to set aside static memory for wolfCrypt use. Memory can be used by passing the...
See also
none

◆ wolfSSL_CTX_is_static_memory()

int wolfSSL_CTX_is_static_memory ( WOLFSSL_CTX *  ctx,
WOLFSSL_MEM_STATS *  mem_stats 
)

This function does not change any of the connections behavior and is used only for gathering information about the static memory usage.

Returns
A value of 1 is returned if using static memory for the CTX is true.
0 is returned if not using static memory.
Parameters
ctxa pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
mem_statsstructure to hold information about staic memory usage.

Example

WOLFSSL_CTX* ctx;
int ret;
WOLFSSL_MEM_STATS mem_stats;
...
//get information about static memory with CTX
ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
if (ret == 1) {
// handle case of is using static memory
// print out or inspect elements of mem_stats
}
if (ret == 0) {
//handle case of ctx not using static memory
}
...
int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX *ctx, WOLFSSL_MEM_STATS *mem_stats)
This function does not change any of the connections behavior and is used only for gathering informat...
See also
wolfSSL_CTX_new
wolfSSL_CTX_load_static_memory
wolfSSL_is_static_memory

◆ wolfSSL_CTX_load_static_memory()

int wolfSSL_CTX_load_static_memory ( WOLFSSL_CTX **  ctx,
wolfSSL_method_func  method,
unsigned char *  buf,
unsigned int  sz,
int  flag,
int  max 
)

This function is used to set aside static memory for a CTX. Memory set aside is then used for the CTX’s lifetime and for any SSL objects created from the CTX. By passing in a NULL ctx pointer and a wolfSSL_method_func function the creation of the CTX itself will also use static memory. wolfSSL_method_func has the function signature of WOLFSSL_METHOD* (wolfSSL_method_func)(void heap);. Passing in 0 for max makes it behave as if not set and no max concurrent use restrictions is in place. The flag value passed in determines how the memory is used and behavior while operating. Available flags are the following.

0 - default general memory

WOLFMEM_IO_POOL - used for input/output buffer when sending receiving messages. Overrides general memory, so all memory in buffer passed in is used for IO. WOLFMEM_IO_FIXED - same as WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for their lifetime. WOLFMEM_TRACK_STATS - each SSL keeps track of memory stats while running.

Returns
If successful, SSL_SUCCESS will be returned.
All unsuccessful return values will be less than 0 or equal to SSL_FAILURE.
Parameters
ctxaddress of pointer to a WOLFSSL_CTX structure.
methodfunction to create protocol. (should be NULL if ctx is not also NULL)
bufmemory to use for all operations.
szsize of memory buffer being passed in.
flagtype of memory.
maxmax concurrent operations.

Example

WOLFSSL_CTX* ctx;
WOLFSSL* ssl;
int ret;
unsigned char memory[MAX];
int memorySz = MAX;
unsigned char IO[MAX];
int IOSz = MAX;
int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
...
// create ctx also using static memory, start with general memory to use
ctx = NULL:
ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex, memory, memorySz, 0,
MAX_CONCURRENT_HANDSHAKES);
if (ret != SSL_SUCCESS) {
// handle error case
}
// load in memory for use with IO
ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag, MAX_CONCURRENT_IO);
if (ret != SSL_SUCCESS) {
// handle error case
}
...
int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX **ctx, wolfSSL_method_func method, unsigned char *buf, unsigned int sz, int flag, int max)
This function is used to set aside static memory for a CTX. Memory set aside is then used for the CTX...
See also
wolfSSL_CTX_new
wolfSSL_CTX_is_static_memory
wolfSSL_is_static_memory

◆ wolfSSL_Free()

void wolfSSL_Free ( void *  ptr,
void *  heap,
int  type 
)

This function is similar to free(), but calls the memory free function which wolfSSL has been configured to use. By default, wolfSSL uses free(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Free is not called directly by wolfSSL, but instead called by macro XFREE. For the default build only the ptr argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.

Returns
none No returns.
Parameters
ptrpointer to the memory to be freed.
heapheap hint to use for memory. Can be NULL
typedynamic type (see DYNAMIC_TYPE_ list in types.h)

Example

int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
// process data as desired
...
if(tenInts) {
wolfSSL_Free(tenInts);
}
void * wolfSSL_Malloc(size_t size, void *heap, int type)
This function is similar to malloc(), but calls the memory allocation function which wolfSSL has been...
void wolfSSL_Free(void *ptr, void *heap, int type)
This function is similar to free(), but calls the memory free function which wolfSSL has been configu...
See also
wolfSSL_Alloc
wolfSSL_Realloc
wolfSSL_SetAllocators
XMALLOC
XFREE
XREALLOC

◆ wolfSSL_is_static_memory()

int wolfSSL_is_static_memory ( WOLFSSL *  ssl,
WOLFSSL_MEM_CONN_STATS *  mem_stats 
)

wolfSSL_is_static_memory is used to gather information about a SSL’s static memory usage. The return value indicates if static memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent CTX when loading in static memory.

Returns
A value of 1 is returned if using static memory for the CTX is true.
0 is returned if not using static memory.
Parameters
ssla pointer to a WOLFSSL structure, created using wolfSSL_new().
mem_statsstructure to contain static memory usage

Example

WOLFSSL* ssl;
int ret;
WOLFSSL_MEM_CONN_STATS mem_stats;
...
ret = wolfSSL_is_static_memory(ssl, mem_stats);
if (ret == 1) {
// handle case when is static memory
// investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
}
...
int wolfSSL_is_static_memory(WOLFSSL *ssl, WOLFSSL_MEM_CONN_STATS *mem_stats)
wolfSSL_is_static_memory is used to gather information about a SSL’s static memory usage....
See also
wolfSSL_new
wolfSSL_CTX_is_static_memory

◆ wolfSSL_Malloc()

void* wolfSSL_Malloc ( size_t  size,
void *  heap,
int  type 
)

This function is similar to malloc(), but calls the memory allocation function which wolfSSL has been configured to use. By default, wolfSSL uses malloc(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Malloc is not called directly by wolfSSL, but instead called by macro XMALLOC. For the default build only the size argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.

Returns
pointer If successful, this function returns a pointer to allocated memory.
error If there is an error, NULL will be returned.
Parameters
sizesize, in bytes, of the memory to allocate
heapheap hint to use for memory. Can be NULL
typedynamic type (see DYNAMIC_TYPE_ list in types.h)

Example

int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
See also
wolfSSL_Free
wolfSSL_Realloc
wolfSSL_SetAllocators
XMALLOC
XFREE
XREALLOC

◆ wolfSSL_MemoryPaddingSz()

int wolfSSL_MemoryPaddingSz ( void  )

This function is available when static memory feature is used (–enable-staticmemory). It gives the size of padding needed for each partition of memory. This padding size will be the size needed to contain a memory management structure along with any extra for memory alignment.

Returns
On successfully memory padding calculation the return value will be a positive value
All negative values are considered error cases.
Parameters
noneNo parameters.

Example

int padding;
if (padding < 0) { //handle error case }
printf(“The padding size needed for each \”bucket\” of memory is %d\n”,
padding);
// calculation of buffer for IO POOL size is number of buckets
// times (padding + WOLFMEM_IO_SZ)
...
int wolfSSL_MemoryPaddingSz(void)
This function is available when static memory feature is used (–enable-staticmemory)....
See also
wolfSSL_Malloc
wolfSSL_Free

◆ wolfSSL_Realloc()

void* wolfSSL_Realloc ( void *  ptr,
size_t  size,
void *  heap,
int  type 
)

This function is similar to realloc(), but calls the memory re-allocation function which wolfSSL has been configured to use. By default, wolfSSL uses realloc(). This can be changed using the wolfSSL memory abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Realloc is not called directly by wolfSSL, but instead called by macro XREALLOC. For the default build only the size argument exists. If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.

Returns
pointer If successful, this function returns a pointer to re-allocated memory. This may be the same pointer as ptr, or a new pointer location.
Null If there is an error, NULL will be returned.
Parameters
ptrpointer to the previously-allocated memory, to be reallocated.
sizenumber of bytes to allocate.
heapheap hint to use for memory. Can be NULL
typedynamic type (see DYNAMIC_TYPE_ list in types.h)

Example

int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
int* twentyInts = (int*)wolfSSL_Realloc(tenInts, sizeof(int)*20);
void * wolfSSL_Realloc(void *ptr, size_t size, void *heap, int type)
This function is similar to realloc(), but calls the memory re-allocation function which wolfSSL has ...
See also
wolfSSL_Free
wolfSSL_Malloc
wolfSSL_SetAllocators
XMALLOC
XFREE
XREALLOC

◆ wolfSSL_SetAllocators()

int wolfSSL_SetAllocators ( wolfSSL_Malloc_cb  ,
wolfSSL_Free_cb  ,
wolfSSL_Realloc_cb   
)

This function registers the allocation functions used by wolfSSL. By default, if the system supports it, malloc/free and realloc are used. Using this function allows the user at runtime to install their own memory handlers.

Returns
Success If successful this function will return 0.
BAD_FUNC_ARG is the error that will be returned if a function pointer is not provided.
Parameters
malloc_functionmemory allocation function for wolfSSL to use. Function signature must match wolfSSL_Malloc_cb prototype, above.
free_functionmemory free function for wolfSSL to use. Function signature must match wolfSSL_Free_cb prototype, above.
realloc_functionmemory re-allocation function for wolfSSL to use. Function signature must match wolfSSL_Realloc_cb prototype, above.

Example

static void* MyMalloc(size_t size)
{
// custom malloc function
}
static void MyFree(void* ptr)
{
// custom free function
}
static void* MyRealloc(void* ptr, size_t size)
{
// custom realloc function
}
// Register custom memory functions with wolfSSL
int ret = wolfSSL_SetAllocators(MyMalloc, MyFree, MyRealloc);
if (ret != 0) {
// failed to set memory functions
}
int wolfSSL_SetAllocators(wolfSSL_Malloc_cb, wolfSSL_Free_cb, wolfSSL_Realloc_cb)
This function registers the allocation functions used by wolfSSL. By default, if the system supports ...
See also
none

◆ wolfSSL_StaticBufferSz()

int wolfSSL_StaticBufferSz ( byte *  buffer,
word32  sz,
int  flag 
)

This function is available when static memory feature is used (–enable-staticmemory). It gives the optimum buffer size for memory “buckets”. This allows for a way to compute buffer size so that no extra unused memory is left at the end after it has been partitioned. The returned value, if positive, is the computed buffer size to use.

Returns
Success On successfully completing buffer size calculations a positive value is returned. This returned value is for optimum buffer size.
Failure All negative values are considered to be error cases.
Parameters
bufferpointer to buffer
sizesize of buffer
typedesired type of memory ie WOLFMEM_GENERAL or WOLFMEM_IO_POOL

Example

byte buffer[1000];
word32 size = sizeof(buffer);
int optimum;
optimum = wolfSSL_StaticBufferSz(buffer, size, WOLFMEM_GENERAL);
if (optimum < 0) { //handle error case }
printf(“The optimum buffer size to make use of all memory is %d\n”,
optimum);
...
int wolfSSL_StaticBufferSz(byte *buffer, word32 sz, int flag)
This function is available when static memory feature is used (–enable-staticmemory)....
See also
wolfSSL_Malloc
wolfSSL_Free

◆ XFREE()

void XFREE ( void *  p,
void *  heap,
int  type 
)

This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))

Returns
none No returns.
Parameters
ppointer to the address to free
h(used by custom XFREE function) pointer to the heap to use
tmemory allocation types for user hints. See enum in types.h

Example

int* tenInts = XMALLOC(sizeof(int) * 10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tenInts == NULL) {
// error allocating space
return MEMORY_E;
}
void * XMALLOC(size_t n, void *heap, int type)
This is not actually a function, but rather a preprocessor macro, which allows the user to substitute...
See also
wolfSSL_Malloc
wolfSSL_Realloc
wolfSSL_Free
wolfSSL_SetAllocators

◆ XMALLOC()

void* XMALLOC ( size_t  n,
void *  heap,
int  type 
)

This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))

Returns
pointer Return a pointer to allocated memory on success
NULL on failure
Parameters
ssize of memory to allocate
h(used by custom XMALLOC function) pointer to the heap to use
tmemory allocation types for user hints. See enum in types.h

Example

int* tenInts = XMALLOC(sizeof(int)*10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tenInts == NULL) {
// error allocating space
return MEMORY_E;
}
See also
wolfSSL_Malloc
wolfSSL_Realloc
wolfSSL_Free
wolfSSL_SetAllocators

◆ XREALLOC()

void* XREALLOC ( void *  p,
size_t  n,
void *  heap,
int  type 
)

This is not actually a function, but rather a preprocessor macro, which allows the user to substitute in their own malloc, realloc, and free functions in place of the standard C memory functions. To use external memory functions, define XMALLOC_USER. This will cause the memory functions to be replaced by external functions of the form: extern void XMALLOC(size_t n, void heap, int type); extern void XREALLOC(void *p, size_t n, void heap, int type); extern void XFREE(void p, void heap, int type); To use the basic C memory functions in place of wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free, define NO_WOLFSSL_MEMORY. This will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} #define XREALLOC(p, n, h, t) realloc((p), (n)) If none of these options are selected, the system will default to use the wolfSSL memory functions. A user can set custom memory functions through callback hooks, (see wolfSSL_Malloc, wolfSSL_Realloc, wolfSSL_Free). This option will replace the memory functions with: #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s))) #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));} #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))

Returns
Return a pointer to allocated memory on success
NULL on failure
Parameters
ppointer to the address to reallocate
nsize of memory to allocate
h(used by custom XREALLOC function) pointer to the heap to use
tmemory allocation types for user hints. See enum in types.h

Example

int* tenInts = (int*)XMALLOC(sizeof(int)*10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
int* twentyInts = (int*)XREALLOC(tenInts, sizeof(int)*20, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
void * XREALLOC(void *p, size_t n, void *heap, int type)
This is not actually a function, but rather a preprocessor macro, which allows the user to substitute...
See also
wolfSSL_Malloc
wolfSSL_Realloc
wolfSSL_Free
wolfSSL_SetAllocators