29 #ifndef WOLFSSL_MEMORY_H 30 #define WOLFSSL_MEMORY_H 41 #ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST 42 WOLFSSL_API
void wolfSSL_SetMemFailCount(
int memFailCount);
45 #ifdef WOLFSSL_STATIC_MEMORY 46 #ifdef WOLFSSL_DEBUG_MEMORY 47 typedef void *(*wolfSSL_Malloc_cb)(
size_t size,
void* heap,
int type,
const char* func,
unsigned int line);
48 typedef void (*wolfSSL_Free_cb)(
void *ptr,
void* heap,
int type,
const char* func,
unsigned int line);
49 typedef void *(*wolfSSL_Realloc_cb)(
void *ptr,
size_t size,
void* heap,
int type,
const char* func,
unsigned int line);
50 WOLFSSL_API
void*
wolfSSL_Malloc(
size_t size,
void* heap,
int type,
const char* func,
unsigned int line);
51 WOLFSSL_API
void wolfSSL_Free(
void *ptr,
void* heap,
int type,
const char* func,
unsigned int line);
52 WOLFSSL_API
void*
wolfSSL_Realloc(
void *ptr,
size_t size,
void* heap,
int type,
const char* func,
unsigned int line);
54 typedef void *(*wolfSSL_Malloc_cb)(
size_t size,
void* heap,
int type);
55 typedef void (*wolfSSL_Free_cb)(
void *ptr,
void* heap,
int type);
56 typedef void *(*wolfSSL_Realloc_cb)(
void *ptr,
size_t size,
void* heap,
int type);
57 WOLFSSL_API
void*
wolfSSL_Malloc(
size_t size,
void* heap,
int type);
58 WOLFSSL_API
void wolfSSL_Free(
void *ptr,
void* heap,
int type);
59 WOLFSSL_API
void*
wolfSSL_Realloc(
void *ptr,
size_t size,
void* heap,
int type);
62 #ifdef WOLFSSL_DEBUG_MEMORY 63 typedef void *(*wolfSSL_Malloc_cb)(
size_t size,
const char* func,
unsigned int line);
64 typedef void (*wolfSSL_Free_cb)(
void *ptr,
const char* func,
unsigned int line);
65 typedef void *(*wolfSSL_Realloc_cb)(
void *ptr,
size_t size,
const char* func,
unsigned int line);
68 WOLFSSL_API
void*
wolfSSL_Malloc(
size_t size,
const char* func,
unsigned int line);
69 WOLFSSL_API
void wolfSSL_Free(
void *ptr,
const char* func,
unsigned int line);
70 WOLFSSL_API
void*
wolfSSL_Realloc(
void *ptr,
size_t size,
const char* func,
unsigned int line);
72 typedef void *(*wolfSSL_Malloc_cb)(
size_t size);
73 typedef void (*wolfSSL_Free_cb)(
void *ptr);
74 typedef void *(*wolfSSL_Realloc_cb)(
void *ptr,
size_t size);
86 WOLFSSL_API
int wolfSSL_GetAllocators(wolfSSL_Malloc_cb*,
90 #ifdef WOLFSSL_STATIC_MEMORY 91 #define WOLFSSL_STATIC_TIMEOUT 1 92 #ifndef WOLFSSL_STATIC_ALIGN 93 #define WOLFSSL_STATIC_ALIGN 16 95 #ifndef WOLFMEM_MAX_BUCKETS 96 #define WOLFMEM_MAX_BUCKETS 9 98 #define WOLFMEM_DEF_BUCKETS 9 100 #define WOLFMEM_IO_SZ 16992 102 #ifndef WOLFMEM_BUCKETS 103 #ifndef SESSION_CERTS 105 #ifndef LARGEST_MEM_BUCKET 106 #define LARGEST_MEM_BUCKET 16128 108 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\ 110 #elif defined (OPENSSL_EXTRA) 112 #ifndef LARGEST_MEM_BUCKET 113 #define LARGEST_MEM_BUCKET 25600 115 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3360,4480,\ 117 #elif defined (WOLFSSL_CERT_EXT) 119 #ifndef LARGEST_MEM_BUCKET 120 #define LARGEST_MEM_BUCKET 24576 122 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\ 126 #ifndef LARGEST_MEM_BUCKET 127 #define LARGEST_MEM_BUCKET 23440 129 #define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,\ 134 #ifndef WOLFSSL_STATIC_MEMORY_SMALL 135 #define WOLFMEM_DIST 49,10,6,14,5,6,9,1,1 138 #define WOLFMEM_DIST 29, 7,6, 9,4,4,0,0,0 143 #define WOLFMEM_GENERAL 0x01 144 #define WOLFMEM_IO_POOL 0x02 145 #define WOLFMEM_IO_POOL_FIXED 0x04 146 #define WOLFMEM_TRACK_STATS 0x08 148 #ifndef WOLFSSL_MEM_GUARD 149 #define WOLFSSL_MEM_GUARD 171 word32 blockSz[WOLFMEM_MAX_BUCKETS];
172 word32 avaBlock[WOLFMEM_MAX_BUCKETS];
173 word32 usedBlock[WOLFMEM_MAX_BUCKETS];
177 typedef struct wc_Memory wc_Memory;
179 wc_Memory* ava[WOLFMEM_MAX_BUCKETS];
185 word32 sizeList[WOLFMEM_MAX_BUCKETS];
186 word32 distList[WOLFMEM_MAX_BUCKETS];
192 wolfSSL_Mutex memory_mutex;
207 unsigned char* buf,
unsigned int sz,
int flag,
int max);
209 WOLFSSL_LOCAL
int wolfSSL_init_memory_heap(
WOLFSSL_HEAP* heap);
210 WOLFSSL_LOCAL
int wolfSSL_load_static_memory(byte* buffer, word32 sz,
212 WOLFSSL_LOCAL
int wolfSSL_GetMemStats(
WOLFSSL_HEAP* heap,
214 WOLFSSL_LOCAL
int SetFixedIO(
WOLFSSL_HEAP* heap, wc_Memory** io);
215 WOLFSSL_LOCAL
int FreeFixedIO(
WOLFSSL_HEAP* heap, wc_Memory** io);
221 #ifdef WOLFSSL_STACK_LOG 222 WOLFSSL_API
void __attribute__((no_instrument_function))
223 __cyg_profile_func_enter(
void *func,
void *caller);
224 WOLFSSL_API
void __attribute__((no_instrument_function))
225 __cyg_profile_func_exit(
void *func,
void *caller);
WOLFSSL_API void wolfSSL_Free(void *ptr, void *heap, int type, const char *func, unsigned int line)
This function calls a custom free function, if one has been defined, or simply calls the default C fr...
WOLFSSL_API void * wolfSSL_Realloc(void *ptr, size_t size, void *heap, int type, const char *func, unsigned int line)
This function calls a custom realloc function, if one has been defined, or simply calls the default C...
WOLFSSL_API void * wolfSSL_Malloc(size_t size, void *heap, int type, const char *func, unsigned int line)
This function calls the custom malloc function, if one has been defined, or simply calls the default ...
WOLFSSL_API 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.
Definition: memory.c:451
WOLFSSL_API 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.
Definition: memory.c:461
WOLFSSL_API 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 ...
Definition: memory.c:102