Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20241113-WC_THREADSHARED #8184

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/sniffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ BOOL APIENTRY DllMain( HMODULE hModule,
#endif /* _WIN32 */


static WOLFSSL_GLOBAL int TraceOn = 0; /* Trace is off by default */
static WOLFSSL_GLOBAL XFILE TraceFile = 0;
static WC_THREADSHARED int TraceOn = 0; /* Trace is off by default */
static WC_THREADSHARED XFILE TraceFile = 0;


/* windows uses .rc table for this */
Expand Down Expand Up @@ -566,52 +566,52 @@ typedef struct SnifferSession {


/* Sniffer Server List and mutex */
static THREAD_LS_T WOLFSSL_GLOBAL SnifferServer* ServerList = NULL;
static THREAD_LS_T SnifferServer* ServerList = NULL;
#ifndef HAVE_C___ATOMIC
static WOLFSSL_GLOBAL wolfSSL_Mutex ServerListMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(ServerListMutex);
static WC_THREADSHARED wolfSSL_Mutex ServerListMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(ServerListMutex);
#endif

/* Session Hash Table, mutex, and count */
static THREAD_LS_T WOLFSSL_GLOBAL SnifferSession* SessionTable[HASH_SIZE];
static THREAD_LS_T SnifferSession* SessionTable[HASH_SIZE];
#ifndef HAVE_C___ATOMIC
static WOLFSSL_GLOBAL wolfSSL_Mutex SessionMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(SessionMutex);
static WC_THREADSHARED wolfSSL_Mutex SessionMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(SessionMutex);
#endif
static THREAD_LS_T WOLFSSL_GLOBAL int SessionCount = 0;
static THREAD_LS_T int SessionCount = 0;

static WOLFSSL_GLOBAL int RecoveryEnabled = 0; /* global switch */
static WOLFSSL_GLOBAL int MaxRecoveryMemory = -1;
static WC_THREADSHARED int RecoveryEnabled = 0; /* global switch */
static WC_THREADSHARED int MaxRecoveryMemory = -1;
/* per session max recovery memory */
#ifndef WOLFSSL_SNIFFER_NO_RECOVERY
/* Recovery of missed data switches and stats */
static WOLFSSL_GLOBAL wolfSSL_Mutex RecoveryMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(RecoveryMutex); /* for stats */
static WC_THREADSHARED wolfSSL_Mutex RecoveryMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(RecoveryMutex); /* for stats */
/* # of sessions with missed data */
static WOLFSSL_GLOBAL word32 MissedDataSessions = 0;
static WC_THREADSHARED word32 MissedDataSessions = 0;
#endif

/* Connection Info Callback */
static WOLFSSL_GLOBAL SSLConnCb ConnectionCb;
static WOLFSSL_GLOBAL void* ConnectionCbCtx = NULL;
static WC_THREADSHARED SSLConnCb ConnectionCb;
static WC_THREADSHARED void* ConnectionCbCtx = NULL;

#ifdef WOLFSSL_SNIFFER_STATS
/* Sessions Statistics */
static WOLFSSL_GLOBAL SSLStats SnifferStats;
static WOLFSSL_GLOBAL wolfSSL_Mutex StatsMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(StatsMutex);
static WC_THREADSHARED SSLStats SnifferStats;
static WC_THREADSHARED wolfSSL_Mutex StatsMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(StatsMutex);
#endif

#ifdef WOLFSSL_SNIFFER_KEY_CALLBACK
static WOLFSSL_GLOBAL SSLKeyCb KeyCb;
static WOLFSSL_GLOBAL void* KeyCbCtx = NULL;
static WC_THREADSHARED SSLKeyCb KeyCb;
static WC_THREADSHARED void* KeyCbCtx = NULL;
#endif

#ifdef WOLFSSL_SNIFFER_WATCH
/* Watch Key Callback */
static WOLFSSL_GLOBAL SSLWatchCb WatchCb;
static WOLFSSL_GLOBAL void* WatchCbCtx = NULL;
static WC_THREADSHARED SSLWatchCb WatchCb;
static WC_THREADSHARED void* WatchCbCtx = NULL;
#endif

#ifdef WOLFSSL_SNIFFER_STORE_DATA_CB
/* Store Data Callback */
static WOLFSSL_GLOBAL SSLStoreDataCb StoreDataCb;
static WC_THREADSHARED SSLStoreDataCb StoreDataCb;
#endif


Expand Down Expand Up @@ -656,7 +656,7 @@ static void UpdateMissedDataSessions(void)


#if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_ASYNC_CRYPT)
static WOLFSSL_GLOBAL int CryptoDeviceId = INVALID_DEVID;
static WC_THREADSHARED int CryptoDeviceId = INVALID_DEVID;
#endif

#if defined(WOLFSSL_SNIFFER_KEYLOGFILE)
Expand Down Expand Up @@ -7234,11 +7234,11 @@ typedef struct SecretNode {
#define WOLFSSL_SNIFFER_KEYLOGFILE_HASH_TABLE_SIZE HASH_SIZE
#endif

static THREAD_LS_T WOLFSSL_GLOBAL
static THREAD_LS_T
SecretNode*
secretHashTable[WOLFSSL_SNIFFER_KEYLOGFILE_HASH_TABLE_SIZE] = {NULL};
#ifndef HAVE_C___ATOMIC
static WOLFSSL_GLOBAL wolfSSL_Mutex secretListMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(secretListMutex);
static WC_THREADSHARED wolfSSL_Mutex secretListMutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(secretListMutex);
#endif

static unsigned int secretHashFunction(unsigned char* clientRandom);
Expand Down
6 changes: 3 additions & 3 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,12 +1032,12 @@ int GetEchConfigsEx(WOLFSSL_EchConfig* configs, byte* output, word32* outputLen)
#endif

/* prevent multiple mutex initializations */
static volatile WOLFSSL_GLOBAL int initRefCount = 0;
static volatile WC_THREADSHARED int initRefCount = 0;
/* init ref count mutex */
static WOLFSSL_GLOBAL wolfSSL_Mutex inits_count_mutex
static WC_THREADSHARED wolfSSL_Mutex inits_count_mutex
WOLFSSL_MUTEX_INITIALIZER_CLAUSE(inits_count_mutex);
#ifndef WOLFSSL_MUTEX_INITIALIZER
static WOLFSSL_GLOBAL volatile int inits_count_mutex_valid = 0;
static WC_THREADSHARED volatile int inits_count_mutex_valid = 0;
#endif

/* Create a new WOLFSSL_CTX struct and return the pointer to created struct.
Expand Down
14 changes: 7 additions & 7 deletions src/ssl_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@
} SessionRow;
#define SIZEOF_SESSION_ROW (sizeof(WOLFSSL_SESSION) + (sizeof(int) * 2))

static WOLFSSL_GLOBAL SessionRow SessionCache[SESSION_ROWS];
static WC_THREADSHARED SessionRow SessionCache[SESSION_ROWS];

#if defined(WOLFSSL_SESSION_STATS) && defined(WOLFSSL_PEAK_SESSIONS)
static WOLFSSL_GLOBAL word32 PeakSessions;
static WC_THREADSHARED word32 PeakSessions;
#endif

#ifdef ENABLE_SESSION_CACHE_ROW_LOCK
#define SESSION_ROW_RD_LOCK(row) wc_LockRwLock_Rd(&(row)->row_lock)
#define SESSION_ROW_WR_LOCK(row) wc_LockRwLock_Wr(&(row)->row_lock)
#define SESSION_ROW_UNLOCK(row) wc_UnLockRwLock(&(row)->row_lock);
#else
static WOLFSSL_GLOBAL wolfSSL_RwLock session_lock; /* SessionCache lock */
static WOLFSSL_GLOBAL int session_lock_valid = 0;
static WC_THREADSHARED wolfSSL_RwLock session_lock; /* SessionCache lock */
static WC_THREADSHARED int session_lock_valid = 0;
#define SESSION_ROW_RD_LOCK(row) wc_LockRwLock_Rd(&session_lock)
#define SESSION_ROW_WR_LOCK(row) wc_LockRwLock_Wr(&session_lock)
#define SESSION_ROW_UNLOCK(row) wc_UnLockRwLock(&session_lock);
Expand Down Expand Up @@ -176,15 +176,15 @@
ClientSession Clients[CLIENT_SESSIONS_PER_ROW];
} ClientRow;

static WOLFSSL_GLOBAL ClientRow ClientCache[CLIENT_SESSION_ROWS];
static WC_THREADSHARED ClientRow ClientCache[CLIENT_SESSION_ROWS];
/* Client Cache */
/* uses session mutex */

/* ClientCache mutex */
static WOLFSSL_GLOBAL wolfSSL_Mutex clisession_mutex
static WC_THREADSHARED wolfSSL_Mutex clisession_mutex
WOLFSSL_MUTEX_INITIALIZER_CLAUSE(clisession_mutex);
#ifndef WOLFSSL_MUTEX_INITIALIZER
static WOLFSSL_GLOBAL int clisession_mutex_valid = 0;
static WC_THREADSHARED int clisession_mutex_valid = 0;
#endif
#endif /* !NO_CLIENT_CACHE */

Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/cryptocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct CryptoCb {
CryptoDevCallbackFunc cb;
void* ctx;
} CryptoCb;
static WOLFSSL_GLOBAL CryptoCb gCryptoDev[MAX_CRYPTO_DEVID_CALLBACKS];
static WC_THREADSHARED CryptoCb gCryptoDev[MAX_CRYPTO_DEVID_CALLBACKS];

#ifdef WOLF_CRYPTO_CB_FIND
static CryptoDevCallbackFind CryptoCb_FindCb = NULL;
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/port/Renesas/renesas_fspsm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern FSPSM_CONFIG gFSPSM_cfg;
#endif

#if defined(WOLFSSL_RENESAS_FSPSM_ECC)
WOLFSSL_GLOBAL FSPSM_ST_PKC gPKCbInfo;
WC_THREADSHARED FSPSM_ST_PKC gPKCbInfo;
#endif


Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#include <wolfssl/wolfcrypt/settings.h>

#include <wolfssl/wolfcrypt/error-crypt.h>

#ifdef HAVE_STACK_SIZE
THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args);
#else
Expand All @@ -58,6 +60,8 @@ int wolf_test_task(void);
#define WC_TEST_RET_TAG_ERRNO 2L
#define WC_TEST_RET_TAG_I 3L

wc_static_assert(-(long)MIN_CODE_E < 0x7ffL);

#define WC_TEST_RET_ENC(line, i, tag) \
((wc_test_ret_t)(-((wc_test_ret_t)(line) + ((wc_test_ret_t)((word32)(i) & 0x7ffL) * 100000L) + ((wc_test_ret_t)(tag) << 29L))))

Expand Down
4 changes: 2 additions & 2 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -1299,9 +1299,9 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
/* By default, the OCTEON's global variables are all thread local. This
* tag allows them to be shared between threads. */
#include "cvmx-platform.h"
#define WOLFSSL_GLOBAL CVMX_SHARED
#define WC_THREADSHARED CVMX_SHARED
#else
#define WOLFSSL_GLOBAL
#define WC_THREADSHARED
#endif

#ifdef WOLFSSL_DSP
Expand Down
Loading