forked from wolfSSL/wolfssl
add debug log and adjust set global heap hint function
This commit is contained in:
@ -3042,10 +3042,6 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
||||
!= 0) {
|
||||
err_sys("unable to load static memory");
|
||||
}
|
||||
/* for test case (does not handle all memory used on default build)
|
||||
wolfSSL_SetGlobalHeapHint(heap);
|
||||
*/
|
||||
|
||||
|
||||
ctx = wolfSSL_CTX_new_ex(method(heap), heap);
|
||||
if (ctx == NULL)
|
||||
|
@ -2518,10 +2518,6 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
|
||||
!= WOLFSSL_SUCCESS)
|
||||
err_sys_ex(catastrophic, "unable to load static memory and create ctx");
|
||||
|
||||
/* for test case (does not handle all memory used on default build)
|
||||
wolfSSL_SetGlobalHeapHint(wolfSSL_CTX_GetHeap(ctx, NULL));
|
||||
*/
|
||||
|
||||
/* load in a buffer for IO */
|
||||
if (wolfSSL_CTX_load_static_memory(&ctx, NULL, memoryIO, sizeof(memoryIO),
|
||||
WOLFMEM_IO_POOL_FIXED | WOLFMEM_TRACK_STATS, 1)
|
||||
|
@ -904,9 +904,23 @@ int wolfSSL_GetMemStats(WOLFSSL_HEAP* heap, WOLFSSL_MEM_STATS* stats)
|
||||
* NOT thread safe, should be set once before any expected XMALLOC XFREE calls
|
||||
*/
|
||||
static void* globalHeapHint = NULL;
|
||||
void wolfSSL_SetGlobalHeapHint(void* heap)
|
||||
|
||||
|
||||
/* Used to set a new global heap hint. Returns a pointer to the current global
|
||||
* heap hint before being set. */
|
||||
void* wolfSSL_SetGlobalHeapHint(void* heap)
|
||||
{
|
||||
void *oldHint = globalHeapHint;
|
||||
|
||||
globalHeapHint = heap;
|
||||
return oldHint;
|
||||
}
|
||||
|
||||
|
||||
/* returns a pointer to the current global heap hint */
|
||||
void* wolfSSL_GetGlobalHeapHint()
|
||||
{
|
||||
return globalHeapHint;
|
||||
}
|
||||
|
||||
|
||||
@ -967,6 +981,9 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type)
|
||||
|
||||
if (hint == NULL) {
|
||||
hint = (WOLFSSL_HEAP_HINT*)globalHeapHint;
|
||||
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||
fprintf(stderr, "(Using global heap hint %p) ", hint);
|
||||
#endif
|
||||
}
|
||||
mem = hint->memory;
|
||||
|
||||
@ -1119,6 +1136,9 @@ void wolfSSL_Free(void *ptr, void* heap, int type)
|
||||
|
||||
if (hint == NULL) {
|
||||
hint = (WOLFSSL_HEAP_HINT*)globalHeapHint;
|
||||
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||
fprintf(stderr, "(Using global heap hint %p) ", hint);
|
||||
#endif
|
||||
}
|
||||
mem = hint->memory;
|
||||
|
||||
@ -1219,6 +1239,9 @@ void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type)
|
||||
|
||||
if (hint == NULL) {
|
||||
hint = (WOLFSSL_HEAP_HINT*)globalHeapHint;
|
||||
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||
fprintf(stderr, "(Using global heap hint %p) ", hint);
|
||||
#endif
|
||||
}
|
||||
mem = hint->memory;
|
||||
|
||||
|
@ -1059,7 +1059,9 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
|
||||
printf("unable to load static memory.\n");
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
#ifndef OPENSSL_EXTRA
|
||||
wolfSSL_SetGlobalHeapHint(HEAP_HINT);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
|
||||
@ -2014,6 +2016,9 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_EXTRA
|
||||
wolfSSL_SetGlobalHeapHint(NULL);
|
||||
#endif
|
||||
TEST_PASS("Test complete\n");
|
||||
|
||||
EXIT_TEST(ret);
|
||||
|
@ -241,6 +241,8 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
|
||||
} WOLFSSL_HEAP_HINT;
|
||||
|
||||
WOLFSSL_API void wolfSSL_SetGlobalHeapHint(void* heap);
|
||||
WOLFSSL_API void* wolfSSL_SetGlobalHeapHint(void* heap);
|
||||
WOLFSSL_API void* wolfSSL_GetGlobalHeapHint(void);
|
||||
WOLFSSL_API int wc_LoadStaticMemory_ex(WOLFSSL_HEAP_HINT** pHint,
|
||||
unsigned int listSz, const unsigned int *sizeList,
|
||||
const unsigned int *distList, unsigned char* buf, unsigned int sz,
|
||||
|
Reference in New Issue
Block a user