diff --git a/configure.ac b/configure.ac index d10f6c9f7..46e52421e 100644 --- a/configure.ac +++ b/configure.ac @@ -101,8 +101,13 @@ OPTIMIZE_FAST_CFLAGS="-O2 -fomit-frame-pointer" OPTIMIZE_HUGE_CFLAGS="-funroll-loops -DTFM_SMALL_SET -DTFM_HUGE_SET" DEBUG_CFLAGS="-g -DDEBUG -DDEBUG_CYASSL" +thread_ls_on=no # Thread local storage -AX_TLS([AM_CFLAGS="$AM_CFLAGS -DHAVE_THREAD_LS"], [:]) +AX_TLS([ + [AM_CFLAGS="$AM_CFLAGS -DHAVE_THREAD_LS"] + [thread_ls_on=yes] + ] , [:]) + # DEBUG AX_DEBUG @@ -1338,6 +1343,24 @@ then fi +# I/O Pool, an example to show user how to override memory handler and use +# a pool for the input/output buffer requests +AC_ARG_ENABLE([iopool], + [ --enable-iopool Enable I/O Pool example (default: disabled)], + [ ENABLED_IOPOOL=$enableval ], + [ ENABLED_IOPOOL=no ] + ) + +if test "$ENABLED_IOPOOL" = "yes" +then + if test "$thread_ls_on" = "no" + then + AC_MSG_ERROR([I/O Pool example requires Thread Local Storage]) + fi + AM_CFLAGS="$AM_CFLAGS -DHAVE_IO_POOL -DXMALLOC_USER" +fi + + # Certificate Service Support AC_ARG_ENABLE([certservice], [ --enable-certservice Enable cert service (default: disabled)], @@ -1690,6 +1713,7 @@ echo " * ECC_ENCRYPT: $ENABLED_ECC_ENCRYPT" echo " * ASN: $ENABLED_ASN" echo " * CODING: $ENABLED_CODING" echo " * MEMORY: $ENABLED_MEMORY" +echo " * I/O POOL: $ENABLED_IOPOOL" echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS" echo " * DTLS: $ENABLED_DTLS" echo " * Old TLS Versions: $ENABLED_OLD_TLS" diff --git a/ctaocrypt/src/memory.c b/ctaocrypt/src/memory.c index 1058e6bc1..5e8f193d9 100644 --- a/ctaocrypt/src/memory.c +++ b/ctaocrypt/src/memory.c @@ -102,3 +102,82 @@ void* CyaSSL_Realloc(void *ptr, size_t size) } #endif /* USE_CYASSL_MEMORY */ + + +#ifdef HAVE_IO_POOL + +/* Example for user io pool, shared build may need definitions in lib proper */ + +#include +#include + +#ifndef HAVE_THREAD_LS + #error "Oops, simple I/O pool example needs thread local storage" +#endif + + +/* allow simple per thread in and out pools */ +/* use 17k size sense max record size is 16k plus overhead */ +static THREAD_LS_T byte pool_in[17*1024]; +static THREAD_LS_T byte pool_out[17*1024]; + + +void* XMALLOC(size_t n, void* heap, int type) +{ + (void)heap; + + if (type == DYNAMIC_TYPE_IN_BUFFER) { + if (n < sizeof(pool_in)) + return pool_in; + else + return NULL; + } + + if (type == DYNAMIC_TYPE_OUT_BUFFER) { + if (n < sizeof(pool_out)) + return pool_out; + else + return NULL; + } + + return malloc(n); +} + +void* XREALLOC(void *p, size_t n, void* heap, int type) +{ + (void)heap; + + if (type == DYNAMIC_TYPE_IN_BUFFER) { + if (n < sizeof(pool_in)) + return pool_in; + else + return NULL; + } + + if (type == DYNAMIC_TYPE_OUT_BUFFER) { + if (n < sizeof(pool_out)) + return pool_out; + else + return NULL; + } + + return realloc(p, n); +} + + +/* unit api calls, let's make sure visisble with CYASSL_API */ +CYASSL_API void XFREE(void *p, void* heap, int type) +{ + (void)heap; + + if (type == DYNAMIC_TYPE_IN_BUFFER) + return; /* do nothing, static pool */ + + if (type == DYNAMIC_TYPE_OUT_BUFFER) + return; /* do nothing, static pool */ + + free(p); +} + +#endif /* HAVE_IO_POOL */ + diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index a21d1b8c8..32765a2cd 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -25,6 +25,10 @@ #include +#ifdef XMALLOC_USER + #include /* we're using malloc / free direct here */ +#endif + #ifndef NO_CRYPT_TEST #ifdef CYASSL_TEST_CERT diff --git a/cyassl/internal.h b/cyassl/internal.h index fa86cd16b..6d5e09fac 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -894,7 +894,7 @@ enum { MTU_EXTRA + MAX_MSG_EXTRA #else /* don't fragment memory from the record header */ - #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + #define STATIC_BUFFER_LEN RECORD_HEADER_SZ #endif typedef struct { diff --git a/cyassl/test.h b/cyassl/test.h index 644cb96a9..77c6a0db8 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -1674,6 +1674,9 @@ static INLINE void SetupPkCallbacks(CYASSL_CTX* ctx, CYASSL* ssl) #endif /* HAVE_PK_CALLBACKS */ + + + #if defined(__hpux__) || defined(__MINGW32__) /* HP/UX doesn't have strsep, needed by test/suites.c */