Merge pull request #3742 from julek-wolfssl/error-queue-per-thread

Add --enable-error-queue-per-thread
This commit is contained in:
toddouska
2021-02-23 12:02:16 -08:00
committed by GitHub
3 changed files with 87 additions and 4 deletions

View File

@ -938,6 +938,18 @@ then
AM_CFLAGS="-DWOLFSSL_EKU_OID -DWOLFSSL_MULTI_ATTRIB $AM_CFLAGS"
fi
# One Error Queue per Thread
AC_ARG_ENABLE([error-queue-per-thread],
[AS_HELP_STRING([--enable-error-queue-per-thread],[Enable one error queue per thread. Requires thread local storage. (default: disabled)])],
[ ENABLED_ERRORQUEUEPERTHREAD=$enableval ],
[ ENABLED_ERRORQUEUEPERTHREAD=no ]
)
if test "$ENABLED_ERRORQUEUEPERTHREAD" = "yes"
then
AM_CFLAGS="-DERROR_QUEUE_PER_THREAD $AM_CFLAGS"
fi
# High Strength Build
AC_ARG_ENABLE([maxstrength],
[AS_HELP_STRING([--enable-maxstrength],[Enable Max Strength build, allows TLSv1.2-AEAD-PFS ciphers only (default: disabled)])],

View File

@ -30241,6 +30241,57 @@ static void test_wolfSSL_PKCS8_d2i(void)
#endif /* HAVE_FIPS */
}
#if defined(ERROR_QUEUE_PER_THREAD) && !defined(NO_ERROR_QUEUE) && \
defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL)
#define LOGGING_THREADS 5
#define ERROR_COUNT 10
static volatile int loggingThreadsReady;
static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
{
const char* file;
int line;
int err;
int errorCount = 0;
int i;
(void)args;
while (!loggingThreadsReady);
for (i = 0; i < ERROR_COUNT; i++)
ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
while ((err = ERR_get_error_line(&file, &line))) {
AssertIntEQ(err, 990 + errorCount);
errorCount++;
}
AssertIntEQ(errorCount, ERROR_COUNT);
return 0;
}
#endif
static void test_error_queue_per_thread(void)
{
#if defined(ERROR_QUEUE_PER_THREAD) && !defined(NO_ERROR_QUEUE) && \
defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL)
THREAD_TYPE loggingThreads[LOGGING_THREADS];
int i;
printf(testingFmt, "error_queue_per_thread()");
ERR_clear_error(); /* clear out any error nodes */
loggingThreadsReady = 0;
for (i = 0; i < LOGGING_THREADS; i++)
start_thread(test_logging, NULL, &loggingThreads[i]);
loggingThreadsReady = 1;
for (i = 0; i < LOGGING_THREADS; i++)
join_thread(loggingThreads[i]);
printf(resultFmt, passed);
#endif
}
static void test_wolfSSL_ERR_put_error(void)
{
#if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
@ -40470,6 +40521,7 @@ void ApiTest(void)
test_wolfSSL_pseudo_rand();
test_wolfSSL_PKCS8_Compat();
test_wolfSSL_PKCS8_d2i();
test_error_queue_per_thread();
test_wolfSSL_ERR_put_error();
#ifndef NO_BIO
test_wolfSSL_ERR_print_errors();

View File

@ -34,11 +34,19 @@
#endif
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
static wolfSSL_Mutex debug_mutex; /* mutex for access to debug structure */
static
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
wolfSSL_Mutex debug_mutex; /* mutex for access to debug structure */
/* accessing any node from the queue should be wrapped in a lock of
* debug_mutex */
static void* wc_error_heap;
static
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
void* wc_error_heap;
struct wc_error_queue {
void* heap; /* the heap hint used with nodes creation */
struct wc_error_queue* next;
@ -48,9 +56,20 @@ struct wc_error_queue {
int value;
int line;
};
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
volatile struct wc_error_queue* wc_errors;
static struct wc_error_queue* wc_current_node;
static struct wc_error_queue* wc_last_node;
static
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
struct wc_error_queue* wc_current_node;
static
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
struct wc_error_queue* wc_last_node;
/* pointer to last node in queue to make insertion O(1) */
#endif