Skip to content

Commit

Permalink
fix thread start callback prototype for Open Watcom toolchain
Browse files Browse the repository at this point in the history
fix callback prototype for Windows and pthread, the Windows version does not return any value and the pthread version is a standard thread callback function (THREAD_CB) with a return value

fix callback function calling convention for Open Watcom toolchain
Open Watcom has an implementation of _beginthread for other operating systems as well, and uses a default calling convention that is not cdecl
  • Loading branch information
jmalak committed Nov 11, 2024
1 parent 4996aed commit 91db32b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 4 additions & 4 deletions examples/benchmark/tls_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ static int bench_tls_client(info_t* info)
}

#if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN)
static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
{
int ret;
info_t* info = (info_t*)args;
Expand All @@ -1242,7 +1242,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_server.cond));

WOLFSSL_RETURN_FROM_THREAD(0);
RETURN_FROM_THREAD_NOJOIN(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_CLIENT */
Expand Down Expand Up @@ -1674,7 +1674,7 @@ static int bench_tls_server(info_t* info)
}

#if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN)
static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
{
int ret = 0;
info_t* info = (info_t*)args;
Expand Down Expand Up @@ -1702,7 +1702,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_client.cond));

WOLFSSL_RETURN_FROM_THREAD(0);
RETURN_FROM_THREAD_NOJOIN(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_SERVER */
Expand Down
6 changes: 3 additions & 3 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ static WC_INLINE word64 Entropy_TimeHiRes(void)
* @param [in,out] args Entropy data including: counter and stop flag.
* @return NULL always.
*/
static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN Entropy_IncCounter(void* args)
static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN Entropy_IncCounter(void* args)
{
(void)args;

Expand All @@ -926,8 +926,8 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN Entropy_IncCounter(void* args)
#ifdef WOLFSSL_DEBUG_ENTROPY_MEMUSE
fprintf(stderr, "EXITING ENTROPY COUNTER THREAD\n");
#endif
/* Exit from thread. */
WOLFSSL_RETURN_FROM_THREAD(0);

RETURN_FROM_THREAD_NOJOIN(0);
}

/* Start a thread that increments counter if not one already.
Expand Down
30 changes: 24 additions & 6 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,11 @@ typedef struct w64wrapper {
#define INVALID_THREAD_VAL ((THREAD_TYPE)(INVALID_HANDLE_VALUE))
#define WOLFSSL_THREAD __stdcall
#if !defined(__MINGW32__)
#define WOLFSSL_THREAD_NO_JOIN __cdecl
#if defined(__WATCOMC__)
#define WOLFSSL_THREAD_NO_JOIN
#else
#define WOLFSSL_THREAD_NO_JOIN __cdecl
#endif
#endif
#else
typedef unsigned int THREAD_RETURN;
Expand Down Expand Up @@ -1580,17 +1584,23 @@ typedef struct w64wrapper {
* to check if the value is an invalid thread
* WOLFSSL_THREAD - attribute that should be used to declare thread
* callbacks
* WOLFSSL_THREAD_NO_JOIN - attribute that should be used to declare
* thread callbacks that don't require cleanup
* WOLFSSL_COND - defined if this system supports signaling
* COND_TYPE - type that should be passed into the signaling API
* WOLFSSL_THREAD_VOID_RETURN - defined if the thread callback has a
* void return
* WOLFSSL_RETURN_FROM_THREAD - define used to correctly return from a
* thread callback
* THREAD_CB - thread callback type for regular threading API
* THREAD_CB_NOJOIN - thread callback type for threading API that don't
*
* WOLFSSL_THREAD_NO_JOIN - attribute used to declare thread callbacks
* that do not require cleanup
* THREAD_CB_NOJOIN - thread callback type for thread APIs that do not
* require cleanup
* THREAD_RETURN_NOJOIN - return type used to declare thread callbacks
* that do not require cleanup
* RETURN_FROM_THREAD_NOJOIN - define used to correctly return from
* a thread callback that do not require
* cleanup
*
* Other defines/types are specific for the threading implementation
*/
Expand All @@ -1613,8 +1623,16 @@ typedef struct w64wrapper {
/* Create a thread that will be automatically cleaned up. We can't
* return a handle/pointer to the new thread because there are no
* guarantees for how long it will be valid. */
typedef THREAD_RETURN (WOLFSSL_THREAD_NO_JOIN *THREAD_CB_NOJOIN)
(void* arg);
#if defined(WOLFSSL_PTHREADS)
#define THREAD_CB_NOJOIN THREAD_CB
#define THREAD_RETURN_NOJOIN THREAD_RETURN
#define RETURN_FROM_THREAD_NOJOIN(x) WOLFSSL_RETURN_FROM_THREAD(x)
#else
#define THREAD_RETURN_NOJOIN void
typedef THREAD_RETURN_NOJOIN
(WOLFSSL_THREAD_NO_JOIN *THREAD_CB_NOJOIN)(void* arg);
#define RETURN_FROM_THREAD_NOJOIN(x)
#endif
WOLFSSL_API int wolfSSL_NewThreadNoJoin(THREAD_CB_NOJOIN cb,
void* arg);
#endif
Expand Down

0 comments on commit 91db32b

Please sign in to comment.