wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:f67a6c6013ca 1 /* memory.c
wolfSSL 13:f67a6c6013ca 2 *
wolfSSL 13:f67a6c6013ca 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:f67a6c6013ca 4 *
wolfSSL 13:f67a6c6013ca 5 * This file is part of wolfSSL.
wolfSSL 13:f67a6c6013ca 6 *
wolfSSL 13:f67a6c6013ca 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:f67a6c6013ca 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:f67a6c6013ca 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:f67a6c6013ca 10 * (at your option) any later version.
wolfSSL 13:f67a6c6013ca 11 *
wolfSSL 13:f67a6c6013ca 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:f67a6c6013ca 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:f67a6c6013ca 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:f67a6c6013ca 15 * GNU General Public License for more details.
wolfSSL 13:f67a6c6013ca 16 *
wolfSSL 13:f67a6c6013ca 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:f67a6c6013ca 18 * along with this program; if not, write to the Free Software
wolfSSL 13:f67a6c6013ca 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:f67a6c6013ca 20 */
wolfSSL 13:f67a6c6013ca 21
wolfSSL 13:f67a6c6013ca 22
wolfSSL 13:f67a6c6013ca 23 #ifdef HAVE_CONFIG_H
wolfSSL 13:f67a6c6013ca 24 #include <config.h>
wolfSSL 13:f67a6c6013ca 25 #endif
wolfSSL 13:f67a6c6013ca 26
wolfSSL 13:f67a6c6013ca 27 #include <wolfssl/wolfcrypt/settings.h>
wolfSSL 13:f67a6c6013ca 28
wolfSSL 13:f67a6c6013ca 29 /* check old macros @wc_fips */
wolfSSL 13:f67a6c6013ca 30 #if defined(USE_CYASSL_MEMORY) && !defined(USE_WOLFSSL_MEMORY)
wolfSSL 13:f67a6c6013ca 31 #define USE_WOLFSSL_MEMORY
wolfSSL 13:f67a6c6013ca 32 #endif
wolfSSL 13:f67a6c6013ca 33 #if defined(CYASSL_MALLOC_CHECK) && !defined(WOLFSSL_MALLOC_CHECK)
wolfSSL 13:f67a6c6013ca 34 #define WOLFSSL_MALLOC_CHECK
wolfSSL 13:f67a6c6013ca 35 #endif
wolfSSL 13:f67a6c6013ca 36
wolfSSL 13:f67a6c6013ca 37 #ifdef USE_WOLFSSL_MEMORY
wolfSSL 13:f67a6c6013ca 38
wolfSSL 13:f67a6c6013ca 39 #include <wolfssl/wolfcrypt/memory.h>
wolfSSL 13:f67a6c6013ca 40 #include <wolfssl/wolfcrypt/error-crypt.h>
wolfSSL 13:f67a6c6013ca 41 #include <wolfssl/wolfcrypt/logging.h>
wolfSSL 13:f67a6c6013ca 42
wolfSSL 13:f67a6c6013ca 43 #if defined(WOLFSSL_MALLOC_CHECK) || defined(WOLFSSL_TRACK_MEMORY_FULL)
wolfSSL 13:f67a6c6013ca 44 #include <stdio.h>
wolfSSL 13:f67a6c6013ca 45 #endif
wolfSSL 13:f67a6c6013ca 46
wolfSSL 13:f67a6c6013ca 47
wolfSSL 13:f67a6c6013ca 48 /* Set these to default values initially. */
wolfSSL 13:f67a6c6013ca 49 static wolfSSL_Malloc_cb malloc_function = 0;
wolfSSL 13:f67a6c6013ca 50 static wolfSSL_Free_cb free_function = 0;
wolfSSL 13:f67a6c6013ca 51 static wolfSSL_Realloc_cb realloc_function = 0;
wolfSSL 13:f67a6c6013ca 52
wolfSSL 13:f67a6c6013ca 53 int wolfSSL_SetAllocators(wolfSSL_Malloc_cb mf,
wolfSSL 13:f67a6c6013ca 54 wolfSSL_Free_cb ff,
wolfSSL 13:f67a6c6013ca 55 wolfSSL_Realloc_cb rf)
wolfSSL 13:f67a6c6013ca 56 {
wolfSSL 13:f67a6c6013ca 57 int res = 0;
wolfSSL 13:f67a6c6013ca 58
wolfSSL 13:f67a6c6013ca 59 if (mf)
wolfSSL 13:f67a6c6013ca 60 malloc_function = mf;
wolfSSL 13:f67a6c6013ca 61 else
wolfSSL 13:f67a6c6013ca 62 res = BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 63
wolfSSL 13:f67a6c6013ca 64 if (ff)
wolfSSL 13:f67a6c6013ca 65 free_function = ff;
wolfSSL 13:f67a6c6013ca 66 else
wolfSSL 13:f67a6c6013ca 67 res = BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 68
wolfSSL 13:f67a6c6013ca 69 if (rf)
wolfSSL 13:f67a6c6013ca 70 realloc_function = rf;
wolfSSL 13:f67a6c6013ca 71 else
wolfSSL 13:f67a6c6013ca 72 res = BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 73
wolfSSL 13:f67a6c6013ca 74 return res;
wolfSSL 13:f67a6c6013ca 75 }
wolfSSL 13:f67a6c6013ca 76
wolfSSL 13:f67a6c6013ca 77 int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
wolfSSL 13:f67a6c6013ca 78 wolfSSL_Free_cb* ff,
wolfSSL 13:f67a6c6013ca 79 wolfSSL_Realloc_cb* rf)
wolfSSL 13:f67a6c6013ca 80 {
wolfSSL 13:f67a6c6013ca 81 if (mf) *mf = malloc_function;
wolfSSL 13:f67a6c6013ca 82 if (ff) *ff = free_function;
wolfSSL 13:f67a6c6013ca 83 if (rf) *rf = realloc_function;
wolfSSL 13:f67a6c6013ca 84 return 0;
wolfSSL 13:f67a6c6013ca 85 }
wolfSSL 13:f67a6c6013ca 86
wolfSSL 13:f67a6c6013ca 87 #ifndef WOLFSSL_STATIC_MEMORY
wolfSSL 13:f67a6c6013ca 88 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 89 void* wolfSSL_Malloc(size_t size, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 90 #else
wolfSSL 13:f67a6c6013ca 91 void* wolfSSL_Malloc(size_t size)
wolfSSL 13:f67a6c6013ca 92 #endif
wolfSSL 13:f67a6c6013ca 93 {
wolfSSL 13:f67a6c6013ca 94 void* res = 0;
wolfSSL 13:f67a6c6013ca 95
wolfSSL 13:f67a6c6013ca 96 if (malloc_function) {
wolfSSL 13:f67a6c6013ca 97 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 98 res = malloc_function(size, func, line);
wolfSSL 13:f67a6c6013ca 99 #else
wolfSSL 13:f67a6c6013ca 100 res = malloc_function(size);
wolfSSL 13:f67a6c6013ca 101 #endif
wolfSSL 13:f67a6c6013ca 102 }
wolfSSL 13:f67a6c6013ca 103 else {
wolfSSL 13:f67a6c6013ca 104 res = malloc(size);
wolfSSL 13:f67a6c6013ca 105 }
wolfSSL 13:f67a6c6013ca 106
wolfSSL 13:f67a6c6013ca 107 #ifdef WOLFSSL_MALLOC_CHECK
wolfSSL 13:f67a6c6013ca 108 if (res == NULL)
wolfSSL 13:f67a6c6013ca 109 puts("wolfSSL_malloc failed");
wolfSSL 13:f67a6c6013ca 110 #endif
wolfSSL 13:f67a6c6013ca 111
wolfSSL 13:f67a6c6013ca 112 return res;
wolfSSL 13:f67a6c6013ca 113 }
wolfSSL 13:f67a6c6013ca 114
wolfSSL 13:f67a6c6013ca 115 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 116 void wolfSSL_Free(void *ptr, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 117 #else
wolfSSL 13:f67a6c6013ca 118 void wolfSSL_Free(void *ptr)
wolfSSL 13:f67a6c6013ca 119 #endif
wolfSSL 13:f67a6c6013ca 120 {
wolfSSL 13:f67a6c6013ca 121 if (free_function) {
wolfSSL 13:f67a6c6013ca 122 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 123 free_function(ptr, func, line);
wolfSSL 13:f67a6c6013ca 124 #else
wolfSSL 13:f67a6c6013ca 125 free_function(ptr);
wolfSSL 13:f67a6c6013ca 126 #endif
wolfSSL 13:f67a6c6013ca 127 }
wolfSSL 13:f67a6c6013ca 128 else {
wolfSSL 13:f67a6c6013ca 129 free(ptr);
wolfSSL 13:f67a6c6013ca 130 }
wolfSSL 13:f67a6c6013ca 131 }
wolfSSL 13:f67a6c6013ca 132
wolfSSL 13:f67a6c6013ca 133 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 134 void* wolfSSL_Realloc(void *ptr, size_t size, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 135 #else
wolfSSL 13:f67a6c6013ca 136 void* wolfSSL_Realloc(void *ptr, size_t size)
wolfSSL 13:f67a6c6013ca 137 #endif
wolfSSL 13:f67a6c6013ca 138 {
wolfSSL 13:f67a6c6013ca 139 void* res = 0;
wolfSSL 13:f67a6c6013ca 140
wolfSSL 13:f67a6c6013ca 141 if (realloc_function) {
wolfSSL 13:f67a6c6013ca 142 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 143 res = realloc_function(ptr, size, func, line);
wolfSSL 13:f67a6c6013ca 144 #else
wolfSSL 13:f67a6c6013ca 145 res = realloc_function(ptr, size);
wolfSSL 13:f67a6c6013ca 146 #endif
wolfSSL 13:f67a6c6013ca 147 }
wolfSSL 13:f67a6c6013ca 148 else {
wolfSSL 13:f67a6c6013ca 149 res = realloc(ptr, size);
wolfSSL 13:f67a6c6013ca 150 }
wolfSSL 13:f67a6c6013ca 151
wolfSSL 13:f67a6c6013ca 152 return res;
wolfSSL 13:f67a6c6013ca 153 }
wolfSSL 13:f67a6c6013ca 154 #endif /* WOLFSSL_STATIC_MEMORY */
wolfSSL 13:f67a6c6013ca 155
wolfSSL 13:f67a6c6013ca 156 #ifdef WOLFSSL_STATIC_MEMORY
wolfSSL 13:f67a6c6013ca 157
wolfSSL 13:f67a6c6013ca 158 struct wc_Memory {
wolfSSL 13:f67a6c6013ca 159 byte* buffer;
wolfSSL 13:f67a6c6013ca 160 struct wc_Memory* next;
wolfSSL 13:f67a6c6013ca 161 word32 sz;
wolfSSL 13:f67a6c6013ca 162 };
wolfSSL 13:f67a6c6013ca 163
wolfSSL 13:f67a6c6013ca 164
wolfSSL 13:f67a6c6013ca 165 /* returns amount of memory used on success. On error returns negative value
wolfSSL 13:f67a6c6013ca 166 wc_Memory** list is the list that new buckets are prepended to
wolfSSL 13:f67a6c6013ca 167 */
wolfSSL 13:f67a6c6013ca 168 static int create_memory_buckets(byte* buffer, word32 bufSz,
wolfSSL 13:f67a6c6013ca 169 word32 buckSz, word32 buckNum, wc_Memory** list) {
wolfSSL 13:f67a6c6013ca 170 word32 i;
wolfSSL 13:f67a6c6013ca 171 byte* pt = buffer;
wolfSSL 13:f67a6c6013ca 172 int ret = 0;
wolfSSL 13:f67a6c6013ca 173 word32 memSz = (word32)sizeof(wc_Memory);
wolfSSL 13:f67a6c6013ca 174 word32 padSz = -(int)memSz & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 175
wolfSSL 13:f67a6c6013ca 176 /* if not enough space available for bucket size then do not try */
wolfSSL 13:f67a6c6013ca 177 if (buckSz + memSz + padSz > bufSz) {
wolfSSL 13:f67a6c6013ca 178 return ret;
wolfSSL 13:f67a6c6013ca 179 }
wolfSSL 13:f67a6c6013ca 180
wolfSSL 13:f67a6c6013ca 181 for (i = 0; i < buckNum; i++) {
wolfSSL 13:f67a6c6013ca 182 if ((buckSz + memSz + padSz) <= (bufSz - ret)) {
wolfSSL 13:f67a6c6013ca 183 /* create a new struct and set its values */
wolfSSL 13:f67a6c6013ca 184 wc_Memory* mem = (struct wc_Memory*)(pt);
wolfSSL 13:f67a6c6013ca 185 mem->sz = buckSz;
wolfSSL 13:f67a6c6013ca 186 mem->buffer = (byte*)pt + padSz + memSz;
wolfSSL 13:f67a6c6013ca 187 mem->next = NULL;
wolfSSL 13:f67a6c6013ca 188
wolfSSL 13:f67a6c6013ca 189 /* add the newly created struct to front of list */
wolfSSL 13:f67a6c6013ca 190 if (*list == NULL) {
wolfSSL 13:f67a6c6013ca 191 *list = mem;
wolfSSL 13:f67a6c6013ca 192 } else {
wolfSSL 13:f67a6c6013ca 193 mem->next = *list;
wolfSSL 13:f67a6c6013ca 194 *list = mem;
wolfSSL 13:f67a6c6013ca 195 }
wolfSSL 13:f67a6c6013ca 196
wolfSSL 13:f67a6c6013ca 197 /* advance pointer and keep track of memory used */
wolfSSL 13:f67a6c6013ca 198 ret += buckSz + padSz + memSz;
wolfSSL 13:f67a6c6013ca 199 pt += buckSz + padSz + memSz;
wolfSSL 13:f67a6c6013ca 200 }
wolfSSL 13:f67a6c6013ca 201 else {
wolfSSL 13:f67a6c6013ca 202 break; /* not enough space left for more buckets of this size */
wolfSSL 13:f67a6c6013ca 203 }
wolfSSL 13:f67a6c6013ca 204 }
wolfSSL 13:f67a6c6013ca 205
wolfSSL 13:f67a6c6013ca 206 return ret;
wolfSSL 13:f67a6c6013ca 207 }
wolfSSL 13:f67a6c6013ca 208
wolfSSL 13:f67a6c6013ca 209 int wolfSSL_init_memory_heap(WOLFSSL_HEAP* heap)
wolfSSL 13:f67a6c6013ca 210 {
wolfSSL 13:f67a6c6013ca 211 word32 wc_MemSz[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_BUCKETS };
wolfSSL 13:f67a6c6013ca 212 word32 wc_Dist[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_DIST };
wolfSSL 13:f67a6c6013ca 213
wolfSSL 13:f67a6c6013ca 214 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 215 return BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 216 }
wolfSSL 13:f67a6c6013ca 217
wolfSSL 13:f67a6c6013ca 218 XMEMSET(heap, 0, sizeof(WOLFSSL_HEAP));
wolfSSL 13:f67a6c6013ca 219
wolfSSL 13:f67a6c6013ca 220 XMEMCPY(heap->sizeList, wc_MemSz, sizeof(wc_MemSz));
wolfSSL 13:f67a6c6013ca 221 XMEMCPY(heap->distList, wc_Dist, sizeof(wc_Dist));
wolfSSL 13:f67a6c6013ca 222
wolfSSL 13:f67a6c6013ca 223 if (wc_InitMutex(&(heap->memory_mutex)) != 0) {
wolfSSL 13:f67a6c6013ca 224 WOLFSSL_MSG("Error creating heap memory mutex");
wolfSSL 13:f67a6c6013ca 225 return BAD_MUTEX_E;
wolfSSL 13:f67a6c6013ca 226 }
wolfSSL 13:f67a6c6013ca 227
wolfSSL 13:f67a6c6013ca 228 return 0;
wolfSSL 13:f67a6c6013ca 229 }
wolfSSL 13:f67a6c6013ca 230
wolfSSL 13:f67a6c6013ca 231 int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
wolfSSL 13:f67a6c6013ca 232 unsigned char* buf, unsigned int sz, int flag, int max)
wolfSSL 13:f67a6c6013ca 233 {
wolfSSL 13:f67a6c6013ca 234 int ret;
wolfSSL 13:f67a6c6013ca 235 WOLFSSL_HEAP* heap;
wolfSSL 13:f67a6c6013ca 236 WOLFSSL_HEAP_HINT* hint;
wolfSSL 13:f67a6c6013ca 237 word32 idx = 0;
wolfSSL 13:f67a6c6013ca 238
wolfSSL 13:f67a6c6013ca 239 if (pHint == NULL || buf == NULL) {
wolfSSL 13:f67a6c6013ca 240 return BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 241 }
wolfSSL 13:f67a6c6013ca 242
wolfSSL 13:f67a6c6013ca 243 if ((sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) > sz - idx) {
wolfSSL 13:f67a6c6013ca 244 return BUFFER_E; /* not enough memory for structures */
wolfSSL 13:f67a6c6013ca 245 }
wolfSSL 13:f67a6c6013ca 246
wolfSSL 13:f67a6c6013ca 247 /* check if hint has already been assigned */
wolfSSL 13:f67a6c6013ca 248 if (*pHint == NULL) {
wolfSSL 13:f67a6c6013ca 249 heap = (WOLFSSL_HEAP*)buf;
wolfSSL 13:f67a6c6013ca 250 idx += sizeof(WOLFSSL_HEAP);
wolfSSL 13:f67a6c6013ca 251 hint = (WOLFSSL_HEAP_HINT*)(buf + idx);
wolfSSL 13:f67a6c6013ca 252 idx += sizeof(WOLFSSL_HEAP_HINT);
wolfSSL 13:f67a6c6013ca 253
wolfSSL 13:f67a6c6013ca 254 ret = wolfSSL_init_memory_heap(heap);
wolfSSL 13:f67a6c6013ca 255 if (ret != 0) {
wolfSSL 13:f67a6c6013ca 256 return ret;
wolfSSL 13:f67a6c6013ca 257 }
wolfSSL 13:f67a6c6013ca 258
wolfSSL 13:f67a6c6013ca 259 XMEMSET(hint, 0, sizeof(WOLFSSL_HEAP_HINT));
wolfSSL 13:f67a6c6013ca 260 hint->memory = heap;
wolfSSL 13:f67a6c6013ca 261 }
wolfSSL 13:f67a6c6013ca 262 else {
wolfSSL 13:f67a6c6013ca 263 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 264 /* do not load in memory if test has been set */
wolfSSL 13:f67a6c6013ca 265 if (heap == (void*)WOLFSSL_HEAP_TEST) {
wolfSSL 13:f67a6c6013ca 266 return 0;
wolfSSL 13:f67a6c6013ca 267 }
wolfSSL 13:f67a6c6013ca 268 #endif
wolfSSL 13:f67a6c6013ca 269
wolfSSL 13:f67a6c6013ca 270 hint = (WOLFSSL_HEAP_HINT*)(*pHint);
wolfSSL 13:f67a6c6013ca 271 heap = hint->memory;
wolfSSL 13:f67a6c6013ca 272 }
wolfSSL 13:f67a6c6013ca 273
wolfSSL 13:f67a6c6013ca 274 ret = wolfSSL_load_static_memory(buf + idx, sz - idx, flag, heap);
wolfSSL 13:f67a6c6013ca 275 if (ret != 1) {
wolfSSL 13:f67a6c6013ca 276 WOLFSSL_MSG("Error partitioning memory");
wolfSSL 13:f67a6c6013ca 277 return -1;
wolfSSL 13:f67a6c6013ca 278 }
wolfSSL 13:f67a6c6013ca 279
wolfSSL 13:f67a6c6013ca 280 /* determine what max applies too */
wolfSSL 13:f67a6c6013ca 281 if ((flag & WOLFMEM_IO_POOL) || (flag & WOLFMEM_IO_POOL_FIXED)) {
wolfSSL 13:f67a6c6013ca 282 heap->maxIO = max;
wolfSSL 13:f67a6c6013ca 283 }
wolfSSL 13:f67a6c6013ca 284 else { /* general memory used in handshakes */
wolfSSL 13:f67a6c6013ca 285 heap->maxHa = max;
wolfSSL 13:f67a6c6013ca 286 }
wolfSSL 13:f67a6c6013ca 287
wolfSSL 13:f67a6c6013ca 288 heap->flag |= flag;
wolfSSL 13:f67a6c6013ca 289 *pHint = hint;
wolfSSL 13:f67a6c6013ca 290
wolfSSL 13:f67a6c6013ca 291 (void)max;
wolfSSL 13:f67a6c6013ca 292
wolfSSL 13:f67a6c6013ca 293 return 0;
wolfSSL 13:f67a6c6013ca 294 }
wolfSSL 13:f67a6c6013ca 295
wolfSSL 13:f67a6c6013ca 296 int wolfSSL_load_static_memory(byte* buffer, word32 sz, int flag,
wolfSSL 13:f67a6c6013ca 297 WOLFSSL_HEAP* heap)
wolfSSL 13:f67a6c6013ca 298 {
wolfSSL 13:f67a6c6013ca 299 word32 ava = sz;
wolfSSL 13:f67a6c6013ca 300 byte* pt = buffer;
wolfSSL 13:f67a6c6013ca 301 int ret = 0;
wolfSSL 13:f67a6c6013ca 302 word32 memSz = (word32)sizeof(wc_Memory);
wolfSSL 13:f67a6c6013ca 303 word32 padSz = -(int)memSz & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 304
wolfSSL 13:f67a6c6013ca 305 WOLFSSL_ENTER("wolfSSL_load_static_memory");
wolfSSL 13:f67a6c6013ca 306
wolfSSL 13:f67a6c6013ca 307 if (buffer == NULL) {
wolfSSL 13:f67a6c6013ca 308 return BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 309 }
wolfSSL 13:f67a6c6013ca 310
wolfSSL 13:f67a6c6013ca 311 /* align pt */
wolfSSL 13:f67a6c6013ca 312 while ((wolfssl_word)pt % WOLFSSL_STATIC_ALIGN && pt < (buffer + sz)) {
wolfSSL 13:f67a6c6013ca 313 *pt = 0x00;
wolfSSL 13:f67a6c6013ca 314 pt++;
wolfSSL 13:f67a6c6013ca 315 ava--;
wolfSSL 13:f67a6c6013ca 316 }
wolfSSL 13:f67a6c6013ca 317
wolfSSL 13:f67a6c6013ca 318 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 319 printf("Allocated %d bytes for static memory @ %p\n", ava, pt);
wolfSSL 13:f67a6c6013ca 320 #endif
wolfSSL 13:f67a6c6013ca 321
wolfSSL 13:f67a6c6013ca 322 /* devide into chunks of memory and add them to available list */
wolfSSL 13:f67a6c6013ca 323 while (ava >= (heap->sizeList[0] + padSz + memSz)) {
wolfSSL 13:f67a6c6013ca 324 int i;
wolfSSL 13:f67a6c6013ca 325 /* creating only IO buffers from memory passed in, max TLS is 16k */
wolfSSL 13:f67a6c6013ca 326 if (flag & WOLFMEM_IO_POOL || flag & WOLFMEM_IO_POOL_FIXED) {
wolfSSL 13:f67a6c6013ca 327 if ((ret = create_memory_buckets(pt, ava,
wolfSSL 13:f67a6c6013ca 328 WOLFMEM_IO_SZ, 1, &(heap->io))) < 0) {
wolfSSL 13:f67a6c6013ca 329 WOLFSSL_LEAVE("wolfSSL_load_static_memory", ret);
wolfSSL 13:f67a6c6013ca 330 return ret;
wolfSSL 13:f67a6c6013ca 331 }
wolfSSL 13:f67a6c6013ca 332
wolfSSL 13:f67a6c6013ca 333 /* check if no more room left for creating IO buffers */
wolfSSL 13:f67a6c6013ca 334 if (ret == 0) {
wolfSSL 13:f67a6c6013ca 335 break;
wolfSSL 13:f67a6c6013ca 336 }
wolfSSL 13:f67a6c6013ca 337
wolfSSL 13:f67a6c6013ca 338 /* advance pointer in buffer for next buckets and keep track
wolfSSL 13:f67a6c6013ca 339 of how much memory is left available */
wolfSSL 13:f67a6c6013ca 340 pt += ret;
wolfSSL 13:f67a6c6013ca 341 ava -= ret;
wolfSSL 13:f67a6c6013ca 342 }
wolfSSL 13:f67a6c6013ca 343 else {
wolfSSL 13:f67a6c6013ca 344 /* start at largest and move to smaller buckets */
wolfSSL 13:f67a6c6013ca 345 for (i = (WOLFMEM_MAX_BUCKETS - 1); i >= 0; i--) {
wolfSSL 13:f67a6c6013ca 346 if ((heap->sizeList[i] + padSz + memSz) <= ava) {
wolfSSL 13:f67a6c6013ca 347 if ((ret = create_memory_buckets(pt, ava, heap->sizeList[i],
wolfSSL 13:f67a6c6013ca 348 heap->distList[i], &(heap->ava[i]))) < 0) {
wolfSSL 13:f67a6c6013ca 349 WOLFSSL_LEAVE("wolfSSL_load_static_memory", ret);
wolfSSL 13:f67a6c6013ca 350 return ret;
wolfSSL 13:f67a6c6013ca 351 }
wolfSSL 13:f67a6c6013ca 352
wolfSSL 13:f67a6c6013ca 353 /* advance pointer in buffer for next buckets and keep track
wolfSSL 13:f67a6c6013ca 354 of how much memory is left available */
wolfSSL 13:f67a6c6013ca 355 pt += ret;
wolfSSL 13:f67a6c6013ca 356 ava -= ret;
wolfSSL 13:f67a6c6013ca 357 }
wolfSSL 13:f67a6c6013ca 358 }
wolfSSL 13:f67a6c6013ca 359 }
wolfSSL 13:f67a6c6013ca 360 }
wolfSSL 13:f67a6c6013ca 361
wolfSSL 13:f67a6c6013ca 362 return 1;
wolfSSL 13:f67a6c6013ca 363 }
wolfSSL 13:f67a6c6013ca 364
wolfSSL 13:f67a6c6013ca 365
wolfSSL 13:f67a6c6013ca 366 /* returns the size of management memory needed for each bucket.
wolfSSL 13:f67a6c6013ca 367 * This is memory that is used to keep track of and align memory buckets. */
wolfSSL 13:f67a6c6013ca 368 int wolfSSL_MemoryPaddingSz(void)
wolfSSL 13:f67a6c6013ca 369 {
wolfSSL 13:f67a6c6013ca 370 word32 memSz = (word32)sizeof(wc_Memory);
wolfSSL 13:f67a6c6013ca 371 word32 padSz = -(int)memSz & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 372 return memSz + padSz;
wolfSSL 13:f67a6c6013ca 373 }
wolfSSL 13:f67a6c6013ca 374
wolfSSL 13:f67a6c6013ca 375
wolfSSL 13:f67a6c6013ca 376 /* Used to calculate memory size for optimum use with buckets.
wolfSSL 13:f67a6c6013ca 377 returns the suggested size rounded down to the nearest bucket. */
wolfSSL 13:f67a6c6013ca 378 int wolfSSL_StaticBufferSz(byte* buffer, word32 sz, int flag)
wolfSSL 13:f67a6c6013ca 379 {
wolfSSL 13:f67a6c6013ca 380 word32 bucketSz[WOLFMEM_MAX_BUCKETS] = {WOLFMEM_BUCKETS};
wolfSSL 13:f67a6c6013ca 381 word32 distList[WOLFMEM_MAX_BUCKETS] = {WOLFMEM_DIST};
wolfSSL 13:f67a6c6013ca 382
wolfSSL 13:f67a6c6013ca 383 word32 ava = sz;
wolfSSL 13:f67a6c6013ca 384 byte* pt = buffer;
wolfSSL 13:f67a6c6013ca 385 word32 memSz = (word32)sizeof(wc_Memory);
wolfSSL 13:f67a6c6013ca 386 word32 padSz = -(int)memSz & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 387
wolfSSL 13:f67a6c6013ca 388 WOLFSSL_ENTER("wolfSSL_static_size");
wolfSSL 13:f67a6c6013ca 389
wolfSSL 13:f67a6c6013ca 390 if (buffer == NULL) {
wolfSSL 13:f67a6c6013ca 391 return BAD_FUNC_ARG;
wolfSSL 13:f67a6c6013ca 392 }
wolfSSL 13:f67a6c6013ca 393
wolfSSL 13:f67a6c6013ca 394 /* align pt */
wolfSSL 13:f67a6c6013ca 395 while ((wolfssl_word)pt % WOLFSSL_STATIC_ALIGN && pt < (buffer + sz)) {
wolfSSL 13:f67a6c6013ca 396 pt++;
wolfSSL 13:f67a6c6013ca 397 ava--;
wolfSSL 13:f67a6c6013ca 398 }
wolfSSL 13:f67a6c6013ca 399
wolfSSL 13:f67a6c6013ca 400 /* creating only IO buffers from memory passed in, max TLS is 16k */
wolfSSL 13:f67a6c6013ca 401 if (flag & WOLFMEM_IO_POOL || flag & WOLFMEM_IO_POOL_FIXED) {
wolfSSL 13:f67a6c6013ca 402 if (ava < (memSz + padSz + WOLFMEM_IO_SZ)) {
wolfSSL 13:f67a6c6013ca 403 return 0; /* not enough room for even one bucket */
wolfSSL 13:f67a6c6013ca 404 }
wolfSSL 13:f67a6c6013ca 405
wolfSSL 13:f67a6c6013ca 406 ava = ava % (memSz + padSz + WOLFMEM_IO_SZ);
wolfSSL 13:f67a6c6013ca 407 }
wolfSSL 13:f67a6c6013ca 408 else {
wolfSSL 13:f67a6c6013ca 409 int i, k;
wolfSSL 13:f67a6c6013ca 410
wolfSSL 13:f67a6c6013ca 411 if (ava < (bucketSz[0] + padSz + memSz)) {
wolfSSL 13:f67a6c6013ca 412 return 0; /* not enough room for even one bucket */
wolfSSL 13:f67a6c6013ca 413 }
wolfSSL 13:f67a6c6013ca 414
wolfSSL 13:f67a6c6013ca 415 while ((ava >= (bucketSz[0] + padSz + memSz)) && (ava > 0)) {
wolfSSL 13:f67a6c6013ca 416 /* start at largest and move to smaller buckets */
wolfSSL 13:f67a6c6013ca 417 for (i = (WOLFMEM_MAX_BUCKETS - 1); i >= 0; i--) {
wolfSSL 13:f67a6c6013ca 418 for (k = distList[i]; k > 0; k--) {
wolfSSL 13:f67a6c6013ca 419 if ((bucketSz[i] + padSz + memSz) <= ava) {
wolfSSL 13:f67a6c6013ca 420 ava -= bucketSz[i] + padSz + memSz;
wolfSSL 13:f67a6c6013ca 421 }
wolfSSL 13:f67a6c6013ca 422 }
wolfSSL 13:f67a6c6013ca 423 }
wolfSSL 13:f67a6c6013ca 424 }
wolfSSL 13:f67a6c6013ca 425 }
wolfSSL 13:f67a6c6013ca 426
wolfSSL 13:f67a6c6013ca 427 return sz - ava; /* round down */
wolfSSL 13:f67a6c6013ca 428 }
wolfSSL 13:f67a6c6013ca 429
wolfSSL 13:f67a6c6013ca 430
wolfSSL 13:f67a6c6013ca 431 int FreeFixedIO(WOLFSSL_HEAP* heap, wc_Memory** io)
wolfSSL 13:f67a6c6013ca 432 {
wolfSSL 13:f67a6c6013ca 433 WOLFSSL_MSG("Freeing fixed IO buffer");
wolfSSL 13:f67a6c6013ca 434
wolfSSL 13:f67a6c6013ca 435 /* check if fixed buffer was set */
wolfSSL 13:f67a6c6013ca 436 if (*io == NULL) {
wolfSSL 13:f67a6c6013ca 437 return 1;
wolfSSL 13:f67a6c6013ca 438 }
wolfSSL 13:f67a6c6013ca 439
wolfSSL 13:f67a6c6013ca 440 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 441 WOLFSSL_MSG("No heap to return fixed IO too");
wolfSSL 13:f67a6c6013ca 442 }
wolfSSL 13:f67a6c6013ca 443 else {
wolfSSL 13:f67a6c6013ca 444 /* put IO buffer back into IO pool */
wolfSSL 13:f67a6c6013ca 445 (*io)->next = heap->io;
wolfSSL 13:f67a6c6013ca 446 heap->io = *io;
wolfSSL 13:f67a6c6013ca 447 *io = NULL;
wolfSSL 13:f67a6c6013ca 448 }
wolfSSL 13:f67a6c6013ca 449
wolfSSL 13:f67a6c6013ca 450 return 1;
wolfSSL 13:f67a6c6013ca 451 }
wolfSSL 13:f67a6c6013ca 452
wolfSSL 13:f67a6c6013ca 453
wolfSSL 13:f67a6c6013ca 454 int SetFixedIO(WOLFSSL_HEAP* heap, wc_Memory** io)
wolfSSL 13:f67a6c6013ca 455 {
wolfSSL 13:f67a6c6013ca 456 WOLFSSL_MSG("Setting fixed IO for SSL");
wolfSSL 13:f67a6c6013ca 457 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 458 return MEMORY_E;
wolfSSL 13:f67a6c6013ca 459 }
wolfSSL 13:f67a6c6013ca 460
wolfSSL 13:f67a6c6013ca 461 *io = heap->io;
wolfSSL 13:f67a6c6013ca 462
wolfSSL 13:f67a6c6013ca 463 if (*io != NULL) {
wolfSSL 13:f67a6c6013ca 464 heap->io = (*io)->next;
wolfSSL 13:f67a6c6013ca 465 (*io)->next = NULL;
wolfSSL 13:f67a6c6013ca 466 }
wolfSSL 13:f67a6c6013ca 467 else { /* failed to grab an IO buffer */
wolfSSL 13:f67a6c6013ca 468 return 0;
wolfSSL 13:f67a6c6013ca 469 }
wolfSSL 13:f67a6c6013ca 470
wolfSSL 13:f67a6c6013ca 471 return 1;
wolfSSL 13:f67a6c6013ca 472 }
wolfSSL 13:f67a6c6013ca 473
wolfSSL 13:f67a6c6013ca 474
wolfSSL 13:f67a6c6013ca 475 int wolfSSL_GetMemStats(WOLFSSL_HEAP* heap, WOLFSSL_MEM_STATS* stats)
wolfSSL 13:f67a6c6013ca 476 {
wolfSSL 13:f67a6c6013ca 477 word32 i;
wolfSSL 13:f67a6c6013ca 478 wc_Memory* pt;
wolfSSL 13:f67a6c6013ca 479
wolfSSL 13:f67a6c6013ca 480 XMEMSET(stats, 0, sizeof(WOLFSSL_MEM_STATS));
wolfSSL 13:f67a6c6013ca 481
wolfSSL 13:f67a6c6013ca 482 stats->totalAlloc = heap->alloc;
wolfSSL 13:f67a6c6013ca 483 stats->totalFr = heap->frAlc;
wolfSSL 13:f67a6c6013ca 484 stats->curAlloc = stats->totalAlloc - stats->totalFr;
wolfSSL 13:f67a6c6013ca 485 stats->maxHa = heap->maxHa;
wolfSSL 13:f67a6c6013ca 486 stats->maxIO = heap->maxIO;
wolfSSL 13:f67a6c6013ca 487 for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
wolfSSL 13:f67a6c6013ca 488 stats->blockSz[i] = heap->sizeList[i];
wolfSSL 13:f67a6c6013ca 489 for (pt = heap->ava[i]; pt != NULL; pt = pt->next) {
wolfSSL 13:f67a6c6013ca 490 stats->avaBlock[i] += 1;
wolfSSL 13:f67a6c6013ca 491 }
wolfSSL 13:f67a6c6013ca 492 }
wolfSSL 13:f67a6c6013ca 493
wolfSSL 13:f67a6c6013ca 494 for (pt = heap->io; pt != NULL; pt = pt->next) {
wolfSSL 13:f67a6c6013ca 495 stats->avaIO++;
wolfSSL 13:f67a6c6013ca 496 }
wolfSSL 13:f67a6c6013ca 497
wolfSSL 13:f67a6c6013ca 498 stats->flag = heap->flag; /* flag used */
wolfSSL 13:f67a6c6013ca 499
wolfSSL 13:f67a6c6013ca 500 return 1;
wolfSSL 13:f67a6c6013ca 501 }
wolfSSL 13:f67a6c6013ca 502
wolfSSL 13:f67a6c6013ca 503
wolfSSL 13:f67a6c6013ca 504 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 505 void* wolfSSL_Malloc(size_t size, void* heap, int type, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 506 #else
wolfSSL 13:f67a6c6013ca 507 void* wolfSSL_Malloc(size_t size, void* heap, int type)
wolfSSL 13:f67a6c6013ca 508 #endif
wolfSSL 13:f67a6c6013ca 509 {
wolfSSL 13:f67a6c6013ca 510 void* res = 0;
wolfSSL 13:f67a6c6013ca 511 wc_Memory* pt = NULL;
wolfSSL 13:f67a6c6013ca 512 int i;
wolfSSL 13:f67a6c6013ca 513
wolfSSL 13:f67a6c6013ca 514 /* check for testing heap hint was set */
wolfSSL 13:f67a6c6013ca 515 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 516 if (heap == (void*)WOLFSSL_HEAP_TEST) {
wolfSSL 13:f67a6c6013ca 517 return malloc(size);
wolfSSL 13:f67a6c6013ca 518 }
wolfSSL 13:f67a6c6013ca 519 #endif
wolfSSL 13:f67a6c6013ca 520
wolfSSL 13:f67a6c6013ca 521 /* if no heap hint then use dynamic memory*/
wolfSSL 13:f67a6c6013ca 522 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 523 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 524 /* allow using malloc for creating ctx and method */
wolfSSL 13:f67a6c6013ca 525 if (type == DYNAMIC_TYPE_CTX || type == DYNAMIC_TYPE_METHOD ||
wolfSSL 13:f67a6c6013ca 526 type == DYNAMIC_TYPE_CERT_MANAGER) {
wolfSSL 13:f67a6c6013ca 527 WOLFSSL_MSG("ERROR allowing null heap hint for ctx/method\n");
wolfSSL 13:f67a6c6013ca 528 res = malloc(size);
wolfSSL 13:f67a6c6013ca 529 }
wolfSSL 13:f67a6c6013ca 530 else {
wolfSSL 13:f67a6c6013ca 531 WOLFSSL_MSG("ERROR null heap hint passed into XMALLOC\n");
wolfSSL 13:f67a6c6013ca 532 res = NULL;
wolfSSL 13:f67a6c6013ca 533 }
wolfSSL 13:f67a6c6013ca 534 #else
wolfSSL 13:f67a6c6013ca 535 #ifndef WOLFSSL_NO_MALLOC
wolfSSL 13:f67a6c6013ca 536 res = malloc(size);
wolfSSL 13:f67a6c6013ca 537 #else
wolfSSL 13:f67a6c6013ca 538 WOLFSSL_MSG("No heap hint found to use and no malloc");
wolfSSL 13:f67a6c6013ca 539 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 540 printf("ERROR: at %s:%d\n", func, line);
wolfSSL 13:f67a6c6013ca 541 #endif
wolfSSL 13:f67a6c6013ca 542 #endif /* WOLFSSL_NO_MALLOC */
wolfSSL 13:f67a6c6013ca 543 #endif /* WOLFSSL_HEAP_TEST */
wolfSSL 13:f67a6c6013ca 544 }
wolfSSL 13:f67a6c6013ca 545 else {
wolfSSL 13:f67a6c6013ca 546 WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap;
wolfSSL 13:f67a6c6013ca 547 WOLFSSL_HEAP* mem = hint->memory;
wolfSSL 13:f67a6c6013ca 548
wolfSSL 13:f67a6c6013ca 549 if (wc_LockMutex(&(mem->memory_mutex)) != 0) {
wolfSSL 13:f67a6c6013ca 550 WOLFSSL_MSG("Bad memory_mutex lock");
wolfSSL 13:f67a6c6013ca 551 return NULL;
wolfSSL 13:f67a6c6013ca 552 }
wolfSSL 13:f67a6c6013ca 553
wolfSSL 13:f67a6c6013ca 554 /* case of using fixed IO buffers */
wolfSSL 13:f67a6c6013ca 555 if (mem->flag & WOLFMEM_IO_POOL_FIXED &&
wolfSSL 13:f67a6c6013ca 556 (type == DYNAMIC_TYPE_OUT_BUFFER ||
wolfSSL 13:f67a6c6013ca 557 type == DYNAMIC_TYPE_IN_BUFFER)) {
wolfSSL 13:f67a6c6013ca 558 if (type == DYNAMIC_TYPE_OUT_BUFFER) {
wolfSSL 13:f67a6c6013ca 559 pt = hint->outBuf;
wolfSSL 13:f67a6c6013ca 560 }
wolfSSL 13:f67a6c6013ca 561 if (type == DYNAMIC_TYPE_IN_BUFFER) {
wolfSSL 13:f67a6c6013ca 562 pt = hint->inBuf;
wolfSSL 13:f67a6c6013ca 563 }
wolfSSL 13:f67a6c6013ca 564 }
wolfSSL 13:f67a6c6013ca 565 else {
wolfSSL 13:f67a6c6013ca 566 /* check if using IO pool flag */
wolfSSL 13:f67a6c6013ca 567 if (mem->flag & WOLFMEM_IO_POOL &&
wolfSSL 13:f67a6c6013ca 568 (type == DYNAMIC_TYPE_OUT_BUFFER ||
wolfSSL 13:f67a6c6013ca 569 type == DYNAMIC_TYPE_IN_BUFFER)) {
wolfSSL 13:f67a6c6013ca 570 if (mem->io != NULL) {
wolfSSL 13:f67a6c6013ca 571 pt = mem->io;
wolfSSL 13:f67a6c6013ca 572 mem->io = pt->next;
wolfSSL 13:f67a6c6013ca 573 }
wolfSSL 13:f67a6c6013ca 574 }
wolfSSL 13:f67a6c6013ca 575
wolfSSL 13:f67a6c6013ca 576 /* general static memory */
wolfSSL 13:f67a6c6013ca 577 if (pt == NULL) {
wolfSSL 13:f67a6c6013ca 578 for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
wolfSSL 13:f67a6c6013ca 579 if ((word32)size < mem->sizeList[i]) {
wolfSSL 13:f67a6c6013ca 580 if (mem->ava[i] != NULL) {
wolfSSL 13:f67a6c6013ca 581 pt = mem->ava[i];
wolfSSL 13:f67a6c6013ca 582 mem->ava[i] = pt->next;
wolfSSL 13:f67a6c6013ca 583 break;
wolfSSL 13:f67a6c6013ca 584 }
wolfSSL 13:f67a6c6013ca 585 }
wolfSSL 13:f67a6c6013ca 586 }
wolfSSL 13:f67a6c6013ca 587 }
wolfSSL 13:f67a6c6013ca 588 }
wolfSSL 13:f67a6c6013ca 589
wolfSSL 13:f67a6c6013ca 590 if (pt != NULL) {
wolfSSL 13:f67a6c6013ca 591 mem->inUse += pt->sz;
wolfSSL 13:f67a6c6013ca 592 mem->alloc += 1;
wolfSSL 13:f67a6c6013ca 593 res = pt->buffer;
wolfSSL 13:f67a6c6013ca 594
wolfSSL 13:f67a6c6013ca 595 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 596 printf("Alloc: %p -> %u at %s:%d\n", pt->buffer, pt->sz, func, line);
wolfSSL 13:f67a6c6013ca 597 #endif
wolfSSL 13:f67a6c6013ca 598
wolfSSL 13:f67a6c6013ca 599 /* keep track of connection statistics if flag is set */
wolfSSL 13:f67a6c6013ca 600 if (mem->flag & WOLFMEM_TRACK_STATS) {
wolfSSL 13:f67a6c6013ca 601 WOLFSSL_MEM_CONN_STATS* stats = hint->stats;
wolfSSL 13:f67a6c6013ca 602 if (stats != NULL) {
wolfSSL 13:f67a6c6013ca 603 stats->curMem += pt->sz;
wolfSSL 13:f67a6c6013ca 604 if (stats->peakMem < stats->curMem) {
wolfSSL 13:f67a6c6013ca 605 stats->peakMem = stats->curMem;
wolfSSL 13:f67a6c6013ca 606 }
wolfSSL 13:f67a6c6013ca 607 stats->curAlloc++;
wolfSSL 13:f67a6c6013ca 608 if (stats->peakAlloc < stats->curAlloc) {
wolfSSL 13:f67a6c6013ca 609 stats->peakAlloc = stats->curAlloc;
wolfSSL 13:f67a6c6013ca 610 }
wolfSSL 13:f67a6c6013ca 611 stats->totalAlloc++;
wolfSSL 13:f67a6c6013ca 612 }
wolfSSL 13:f67a6c6013ca 613 }
wolfSSL 13:f67a6c6013ca 614 }
wolfSSL 13:f67a6c6013ca 615 else {
wolfSSL 13:f67a6c6013ca 616 WOLFSSL_MSG("ERROR ran out of static memory");
wolfSSL 13:f67a6c6013ca 617 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 618 printf("Looking for %lu bytes at %s:%d\n", size, func, line);
wolfSSL 13:f67a6c6013ca 619 #endif
wolfSSL 13:f67a6c6013ca 620 }
wolfSSL 13:f67a6c6013ca 621
wolfSSL 13:f67a6c6013ca 622 wc_UnLockMutex(&(mem->memory_mutex));
wolfSSL 13:f67a6c6013ca 623 }
wolfSSL 13:f67a6c6013ca 624
wolfSSL 13:f67a6c6013ca 625 #ifdef WOLFSSL_MALLOC_CHECK
wolfSSL 13:f67a6c6013ca 626 if ((wolfssl_word)res % WOLFSSL_STATIC_ALIGN) {
wolfSSL 13:f67a6c6013ca 627 WOLFSSL_MSG("ERROR memory is not alligned");
wolfSSL 13:f67a6c6013ca 628 res = NULL;
wolfSSL 13:f67a6c6013ca 629 }
wolfSSL 13:f67a6c6013ca 630 #endif
wolfSSL 13:f67a6c6013ca 631
wolfSSL 13:f67a6c6013ca 632
wolfSSL 13:f67a6c6013ca 633 (void)i;
wolfSSL 13:f67a6c6013ca 634 (void)pt;
wolfSSL 13:f67a6c6013ca 635 (void)type;
wolfSSL 13:f67a6c6013ca 636
wolfSSL 13:f67a6c6013ca 637 return res;
wolfSSL 13:f67a6c6013ca 638 }
wolfSSL 13:f67a6c6013ca 639
wolfSSL 13:f67a6c6013ca 640
wolfSSL 13:f67a6c6013ca 641 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 642 void wolfSSL_Free(void *ptr, void* heap, int type, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 643 #else
wolfSSL 13:f67a6c6013ca 644 void wolfSSL_Free(void *ptr, void* heap, int type)
wolfSSL 13:f67a6c6013ca 645 #endif
wolfSSL 13:f67a6c6013ca 646 {
wolfSSL 13:f67a6c6013ca 647 int i;
wolfSSL 13:f67a6c6013ca 648 wc_Memory* pt;
wolfSSL 13:f67a6c6013ca 649
wolfSSL 13:f67a6c6013ca 650 if (ptr) {
wolfSSL 13:f67a6c6013ca 651 /* check for testing heap hint was set */
wolfSSL 13:f67a6c6013ca 652 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 653 if (heap == (void*)WOLFSSL_HEAP_TEST) {
wolfSSL 13:f67a6c6013ca 654 return free(ptr);
wolfSSL 13:f67a6c6013ca 655 }
wolfSSL 13:f67a6c6013ca 656 #endif
wolfSSL 13:f67a6c6013ca 657
wolfSSL 13:f67a6c6013ca 658 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 659 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 660 /* allow using malloc for creating ctx and method */
wolfSSL 13:f67a6c6013ca 661 if (type == DYNAMIC_TYPE_CTX || type == DYNAMIC_TYPE_METHOD ||
wolfSSL 13:f67a6c6013ca 662 type == DYNAMIC_TYPE_CERT_MANAGER) {
wolfSSL 13:f67a6c6013ca 663 WOLFSSL_MSG("ERROR allowing null heap hint for ctx/method\n");
wolfSSL 13:f67a6c6013ca 664 }
wolfSSL 13:f67a6c6013ca 665 else {
wolfSSL 13:f67a6c6013ca 666 WOLFSSL_MSG("ERROR null heap hint passed into XFREE\n");
wolfSSL 13:f67a6c6013ca 667 }
wolfSSL 13:f67a6c6013ca 668 #endif
wolfSSL 13:f67a6c6013ca 669 #ifndef WOLFSSL_NO_MALLOC
wolfSSL 13:f67a6c6013ca 670 free(ptr);
wolfSSL 13:f67a6c6013ca 671 #else
wolfSSL 13:f67a6c6013ca 672 WOLFSSL_MSG("Error trying to call free when turned off");
wolfSSL 13:f67a6c6013ca 673 #endif /* WOLFSSL_NO_MALLOC */
wolfSSL 13:f67a6c6013ca 674 }
wolfSSL 13:f67a6c6013ca 675 else {
wolfSSL 13:f67a6c6013ca 676 WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap;
wolfSSL 13:f67a6c6013ca 677 WOLFSSL_HEAP* mem = hint->memory;
wolfSSL 13:f67a6c6013ca 678 word32 padSz = -(int)sizeof(wc_Memory) & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 679
wolfSSL 13:f67a6c6013ca 680 /* get memory struct and add it to available list */
wolfSSL 13:f67a6c6013ca 681 pt = (wc_Memory*)((byte*)ptr - sizeof(wc_Memory) - padSz);
wolfSSL 13:f67a6c6013ca 682 if (wc_LockMutex(&(mem->memory_mutex)) != 0) {
wolfSSL 13:f67a6c6013ca 683 WOLFSSL_MSG("Bad memory_mutex lock");
wolfSSL 13:f67a6c6013ca 684 return;
wolfSSL 13:f67a6c6013ca 685 }
wolfSSL 13:f67a6c6013ca 686
wolfSSL 13:f67a6c6013ca 687 /* case of using fixed IO buffers */
wolfSSL 13:f67a6c6013ca 688 if (mem->flag & WOLFMEM_IO_POOL_FIXED &&
wolfSSL 13:f67a6c6013ca 689 (type == DYNAMIC_TYPE_OUT_BUFFER ||
wolfSSL 13:f67a6c6013ca 690 type == DYNAMIC_TYPE_IN_BUFFER)) {
wolfSSL 13:f67a6c6013ca 691 /* fixed IO pools are free'd at the end of SSL lifetime
wolfSSL 13:f67a6c6013ca 692 using FreeFixedIO(WOLFSSL_HEAP* heap, wc_Memory** io) */
wolfSSL 13:f67a6c6013ca 693 }
wolfSSL 13:f67a6c6013ca 694 else if (mem->flag & WOLFMEM_IO_POOL && pt->sz == WOLFMEM_IO_SZ &&
wolfSSL 13:f67a6c6013ca 695 (type == DYNAMIC_TYPE_OUT_BUFFER ||
wolfSSL 13:f67a6c6013ca 696 type == DYNAMIC_TYPE_IN_BUFFER)) {
wolfSSL 13:f67a6c6013ca 697 pt->next = mem->io;
wolfSSL 13:f67a6c6013ca 698 mem->io = pt;
wolfSSL 13:f67a6c6013ca 699 }
wolfSSL 13:f67a6c6013ca 700 else { /* general memory free */
wolfSSL 13:f67a6c6013ca 701 for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
wolfSSL 13:f67a6c6013ca 702 if (pt->sz == mem->sizeList[i]) {
wolfSSL 13:f67a6c6013ca 703 pt->next = mem->ava[i];
wolfSSL 13:f67a6c6013ca 704 mem->ava[i] = pt;
wolfSSL 13:f67a6c6013ca 705 break;
wolfSSL 13:f67a6c6013ca 706 }
wolfSSL 13:f67a6c6013ca 707 }
wolfSSL 13:f67a6c6013ca 708 }
wolfSSL 13:f67a6c6013ca 709 mem->inUse -= pt->sz;
wolfSSL 13:f67a6c6013ca 710 mem->frAlc += 1;
wolfSSL 13:f67a6c6013ca 711
wolfSSL 13:f67a6c6013ca 712 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 713 printf("Free: %p -> %u at %s:%d\n", pt->buffer, pt->sz, func, line);
wolfSSL 13:f67a6c6013ca 714 #endif
wolfSSL 13:f67a6c6013ca 715
wolfSSL 13:f67a6c6013ca 716 /* keep track of connection statistics if flag is set */
wolfSSL 13:f67a6c6013ca 717 if (mem->flag & WOLFMEM_TRACK_STATS) {
wolfSSL 13:f67a6c6013ca 718 WOLFSSL_MEM_CONN_STATS* stats = hint->stats;
wolfSSL 13:f67a6c6013ca 719 if (stats != NULL) {
wolfSSL 13:f67a6c6013ca 720 /* avoid under flow */
wolfSSL 13:f67a6c6013ca 721 if (stats->curMem > pt->sz) {
wolfSSL 13:f67a6c6013ca 722 stats->curMem -= pt->sz;
wolfSSL 13:f67a6c6013ca 723 }
wolfSSL 13:f67a6c6013ca 724 else {
wolfSSL 13:f67a6c6013ca 725 stats->curMem = 0;
wolfSSL 13:f67a6c6013ca 726 }
wolfSSL 13:f67a6c6013ca 727
wolfSSL 13:f67a6c6013ca 728 if (stats->curAlloc > 0) {
wolfSSL 13:f67a6c6013ca 729 stats->curAlloc--;
wolfSSL 13:f67a6c6013ca 730 }
wolfSSL 13:f67a6c6013ca 731 stats->totalFr++;
wolfSSL 13:f67a6c6013ca 732 }
wolfSSL 13:f67a6c6013ca 733 }
wolfSSL 13:f67a6c6013ca 734 wc_UnLockMutex(&(mem->memory_mutex));
wolfSSL 13:f67a6c6013ca 735 }
wolfSSL 13:f67a6c6013ca 736 }
wolfSSL 13:f67a6c6013ca 737
wolfSSL 13:f67a6c6013ca 738 (void)i;
wolfSSL 13:f67a6c6013ca 739 (void)pt;
wolfSSL 13:f67a6c6013ca 740 (void)type;
wolfSSL 13:f67a6c6013ca 741 }
wolfSSL 13:f67a6c6013ca 742
wolfSSL 13:f67a6c6013ca 743 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 744 void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type, const char* func, unsigned int line)
wolfSSL 13:f67a6c6013ca 745 #else
wolfSSL 13:f67a6c6013ca 746 void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type)
wolfSSL 13:f67a6c6013ca 747 #endif
wolfSSL 13:f67a6c6013ca 748 {
wolfSSL 13:f67a6c6013ca 749 void* res = 0;
wolfSSL 13:f67a6c6013ca 750 wc_Memory* pt = NULL;
wolfSSL 13:f67a6c6013ca 751 word32 prvSz;
wolfSSL 13:f67a6c6013ca 752 int i;
wolfSSL 13:f67a6c6013ca 753
wolfSSL 13:f67a6c6013ca 754 /* check for testing heap hint was set */
wolfSSL 13:f67a6c6013ca 755 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 756 if (heap == (void*)WOLFSSL_HEAP_TEST) {
wolfSSL 13:f67a6c6013ca 757 return realloc(ptr, size);
wolfSSL 13:f67a6c6013ca 758 }
wolfSSL 13:f67a6c6013ca 759 #endif
wolfSSL 13:f67a6c6013ca 760
wolfSSL 13:f67a6c6013ca 761 if (heap == NULL) {
wolfSSL 13:f67a6c6013ca 762 #ifdef WOLFSSL_HEAP_TEST
wolfSSL 13:f67a6c6013ca 763 WOLFSSL_MSG("ERROR null heap hint passed in to XREALLOC\n");
wolfSSL 13:f67a6c6013ca 764 #endif
wolfSSL 13:f67a6c6013ca 765 #ifndef WOLFSSL_NO_MALLOC
wolfSSL 13:f67a6c6013ca 766 res = realloc(ptr, size);
wolfSSL 13:f67a6c6013ca 767 #else
wolfSSL 13:f67a6c6013ca 768 WOLFSSL_MSG("NO heap found to use for realloc");
wolfSSL 13:f67a6c6013ca 769 #endif /* WOLFSSL_NO_MALLOC */
wolfSSL 13:f67a6c6013ca 770 }
wolfSSL 13:f67a6c6013ca 771 else {
wolfSSL 13:f67a6c6013ca 772 WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap;
wolfSSL 13:f67a6c6013ca 773 WOLFSSL_HEAP* mem = hint->memory;
wolfSSL 13:f67a6c6013ca 774 word32 padSz = -(int)sizeof(wc_Memory) & (WOLFSSL_STATIC_ALIGN - 1);
wolfSSL 13:f67a6c6013ca 775
wolfSSL 13:f67a6c6013ca 776 if (wc_LockMutex(&(mem->memory_mutex)) != 0) {
wolfSSL 13:f67a6c6013ca 777 WOLFSSL_MSG("Bad memory_mutex lock");
wolfSSL 13:f67a6c6013ca 778 return NULL;
wolfSSL 13:f67a6c6013ca 779 }
wolfSSL 13:f67a6c6013ca 780
wolfSSL 13:f67a6c6013ca 781 /* case of using fixed IO buffers or IO pool */
wolfSSL 13:f67a6c6013ca 782 if (((mem->flag & WOLFMEM_IO_POOL)||(mem->flag & WOLFMEM_IO_POOL_FIXED))
wolfSSL 13:f67a6c6013ca 783 && (type == DYNAMIC_TYPE_OUT_BUFFER ||
wolfSSL 13:f67a6c6013ca 784 type == DYNAMIC_TYPE_IN_BUFFER)) {
wolfSSL 13:f67a6c6013ca 785 /* no realloc, is fixed size */
wolfSSL 13:f67a6c6013ca 786 pt = (wc_Memory*)((byte*)ptr - padSz - sizeof(wc_Memory));
wolfSSL 13:f67a6c6013ca 787 if (pt->sz < size) {
wolfSSL 13:f67a6c6013ca 788 WOLFSSL_MSG("Error IO memory was not large enough");
wolfSSL 13:f67a6c6013ca 789 res = NULL; /* return NULL in error case */
wolfSSL 13:f67a6c6013ca 790 }
wolfSSL 13:f67a6c6013ca 791 res = pt->buffer;
wolfSSL 13:f67a6c6013ca 792 }
wolfSSL 13:f67a6c6013ca 793 else {
wolfSSL 13:f67a6c6013ca 794 /* general memory */
wolfSSL 13:f67a6c6013ca 795 for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
wolfSSL 13:f67a6c6013ca 796 if ((word32)size < mem->sizeList[i]) {
wolfSSL 13:f67a6c6013ca 797 if (mem->ava[i] != NULL) {
wolfSSL 13:f67a6c6013ca 798 pt = mem->ava[i];
wolfSSL 13:f67a6c6013ca 799 mem->ava[i] = pt->next;
wolfSSL 13:f67a6c6013ca 800 break;
wolfSSL 13:f67a6c6013ca 801 }
wolfSSL 13:f67a6c6013ca 802 }
wolfSSL 13:f67a6c6013ca 803 }
wolfSSL 13:f67a6c6013ca 804
wolfSSL 13:f67a6c6013ca 805 if (pt != NULL && res == NULL) {
wolfSSL 13:f67a6c6013ca 806 res = pt->buffer;
wolfSSL 13:f67a6c6013ca 807
wolfSSL 13:f67a6c6013ca 808 /* copy over original information and free ptr */
wolfSSL 13:f67a6c6013ca 809 prvSz = ((wc_Memory*)((byte*)ptr - padSz -
wolfSSL 13:f67a6c6013ca 810 sizeof(wc_Memory)))->sz;
wolfSSL 13:f67a6c6013ca 811 prvSz = (prvSz > pt->sz)? pt->sz: prvSz;
wolfSSL 13:f67a6c6013ca 812 XMEMCPY(pt->buffer, ptr, prvSz);
wolfSSL 13:f67a6c6013ca 813 mem->inUse += pt->sz;
wolfSSL 13:f67a6c6013ca 814 mem->alloc += 1;
wolfSSL 13:f67a6c6013ca 815
wolfSSL 13:f67a6c6013ca 816 /* free memory that was previously being used */
wolfSSL 13:f67a6c6013ca 817 wc_UnLockMutex(&(mem->memory_mutex));
wolfSSL 13:f67a6c6013ca 818 wolfSSL_Free(ptr, heap, type
wolfSSL 13:f67a6c6013ca 819 #ifdef WOLFSSL_DEBUG_MEMORY
wolfSSL 13:f67a6c6013ca 820 , func, line
wolfSSL 13:f67a6c6013ca 821 #endif
wolfSSL 13:f67a6c6013ca 822 );
wolfSSL 13:f67a6c6013ca 823 if (wc_LockMutex(&(mem->memory_mutex)) != 0) {
wolfSSL 13:f67a6c6013ca 824 WOLFSSL_MSG("Bad memory_mutex lock");
wolfSSL 13:f67a6c6013ca 825 return NULL;
wolfSSL 13:f67a6c6013ca 826 }
wolfSSL 13:f67a6c6013ca 827 }
wolfSSL 13:f67a6c6013ca 828 }
wolfSSL 13:f67a6c6013ca 829 wc_UnLockMutex(&(mem->memory_mutex));
wolfSSL 13:f67a6c6013ca 830 }
wolfSSL 13:f67a6c6013ca 831
wolfSSL 13:f67a6c6013ca 832 #ifdef WOLFSSL_MALLOC_CHECK
wolfSSL 13:f67a6c6013ca 833 if ((wolfssl_word)res % WOLFSSL_STATIC_ALIGN) {
wolfSSL 13:f67a6c6013ca 834 WOLFSSL_MSG("ERROR memory is not alligned");
wolfSSL 13:f67a6c6013ca 835 res = NULL;
wolfSSL 13:f67a6c6013ca 836 }
wolfSSL 13:f67a6c6013ca 837 #endif
wolfSSL 13:f67a6c6013ca 838
wolfSSL 13:f67a6c6013ca 839 (void)i;
wolfSSL 13:f67a6c6013ca 840 (void)pt;
wolfSSL 13:f67a6c6013ca 841 (void)type;
wolfSSL 13:f67a6c6013ca 842
wolfSSL 13:f67a6c6013ca 843 return res;
wolfSSL 13:f67a6c6013ca 844 }
wolfSSL 13:f67a6c6013ca 845 #endif /* WOLFSSL_STATIC_MEMORY */
wolfSSL 13:f67a6c6013ca 846
wolfSSL 13:f67a6c6013ca 847 #endif /* USE_WOLFSSL_MEMORY */
wolfSSL 13:f67a6c6013ca 848
wolfSSL 13:f67a6c6013ca 849
wolfSSL 13:f67a6c6013ca 850 #ifdef HAVE_IO_POOL
wolfSSL 13:f67a6c6013ca 851
wolfSSL 13:f67a6c6013ca 852 /* Example for user io pool, shared build may need definitions in lib proper */
wolfSSL 13:f67a6c6013ca 853
wolfSSL 13:f67a6c6013ca 854 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 855 #include <stdlib.h>
wolfSSL 13:f67a6c6013ca 856
wolfSSL 13:f67a6c6013ca 857 #ifndef HAVE_THREAD_LS
wolfSSL 13:f67a6c6013ca 858 #error "Oops, simple I/O pool example needs thread local storage"
wolfSSL 13:f67a6c6013ca 859 #endif
wolfSSL 13:f67a6c6013ca 860
wolfSSL 13:f67a6c6013ca 861
wolfSSL 13:f67a6c6013ca 862 /* allow simple per thread in and out pools */
wolfSSL 13:f67a6c6013ca 863 /* use 17k size since max record size is 16k plus overhead */
wolfSSL 13:f67a6c6013ca 864 static THREAD_LS_T byte pool_in[17*1024];
wolfSSL 13:f67a6c6013ca 865 static THREAD_LS_T byte pool_out[17*1024];
wolfSSL 13:f67a6c6013ca 866
wolfSSL 13:f67a6c6013ca 867
wolfSSL 13:f67a6c6013ca 868 void* XMALLOC(size_t n, void* heap, int type)
wolfSSL 13:f67a6c6013ca 869 {
wolfSSL 13:f67a6c6013ca 870 (void)heap;
wolfSSL 13:f67a6c6013ca 871
wolfSSL 13:f67a6c6013ca 872 if (type == DYNAMIC_TYPE_IN_BUFFER) {
wolfSSL 13:f67a6c6013ca 873 if (n < sizeof(pool_in))
wolfSSL 13:f67a6c6013ca 874 return pool_in;
wolfSSL 13:f67a6c6013ca 875 else
wolfSSL 13:f67a6c6013ca 876 return NULL;
wolfSSL 13:f67a6c6013ca 877 }
wolfSSL 13:f67a6c6013ca 878
wolfSSL 13:f67a6c6013ca 879 if (type == DYNAMIC_TYPE_OUT_BUFFER) {
wolfSSL 13:f67a6c6013ca 880 if (n < sizeof(pool_out))
wolfSSL 13:f67a6c6013ca 881 return pool_out;
wolfSSL 13:f67a6c6013ca 882 else
wolfSSL 13:f67a6c6013ca 883 return NULL;
wolfSSL 13:f67a6c6013ca 884 }
wolfSSL 13:f67a6c6013ca 885
wolfSSL 13:f67a6c6013ca 886 return malloc(n);
wolfSSL 13:f67a6c6013ca 887 }
wolfSSL 13:f67a6c6013ca 888
wolfSSL 13:f67a6c6013ca 889 void* XREALLOC(void *p, size_t n, void* heap, int type)
wolfSSL 13:f67a6c6013ca 890 {
wolfSSL 13:f67a6c6013ca 891 (void)heap;
wolfSSL 13:f67a6c6013ca 892
wolfSSL 13:f67a6c6013ca 893 if (type == DYNAMIC_TYPE_IN_BUFFER) {
wolfSSL 13:f67a6c6013ca 894 if (n < sizeof(pool_in))
wolfSSL 13:f67a6c6013ca 895 return pool_in;
wolfSSL 13:f67a6c6013ca 896 else
wolfSSL 13:f67a6c6013ca 897 return NULL;
wolfSSL 13:f67a6c6013ca 898 }
wolfSSL 13:f67a6c6013ca 899
wolfSSL 13:f67a6c6013ca 900 if (type == DYNAMIC_TYPE_OUT_BUFFER) {
wolfSSL 13:f67a6c6013ca 901 if (n < sizeof(pool_out))
wolfSSL 13:f67a6c6013ca 902 return pool_out;
wolfSSL 13:f67a6c6013ca 903 else
wolfSSL 13:f67a6c6013ca 904 return NULL;
wolfSSL 13:f67a6c6013ca 905 }
wolfSSL 13:f67a6c6013ca 906
wolfSSL 13:f67a6c6013ca 907 return realloc(p, n);
wolfSSL 13:f67a6c6013ca 908 }
wolfSSL 13:f67a6c6013ca 909
wolfSSL 13:f67a6c6013ca 910 void XFREE(void *p, void* heap, int type)
wolfSSL 13:f67a6c6013ca 911 {
wolfSSL 13:f67a6c6013ca 912 (void)heap;
wolfSSL 13:f67a6c6013ca 913
wolfSSL 13:f67a6c6013ca 914 if (type == DYNAMIC_TYPE_IN_BUFFER)
wolfSSL 13:f67a6c6013ca 915 return; /* do nothing, static pool */
wolfSSL 13:f67a6c6013ca 916
wolfSSL 13:f67a6c6013ca 917 if (type == DYNAMIC_TYPE_OUT_BUFFER)
wolfSSL 13:f67a6c6013ca 918 return; /* do nothing, static pool */
wolfSSL 13:f67a6c6013ca 919
wolfSSL 13:f67a6c6013ca 920 free(p);
wolfSSL 13:f67a6c6013ca 921 }
wolfSSL 13:f67a6c6013ca 922
wolfSSL 13:f67a6c6013ca 923 #endif /* HAVE_IO_POOL */
wolfSSL 13:f67a6c6013ca 924
wolfSSL 13:f67a6c6013ca 925