Skip to content

Commit 9fdcd2e

Browse files
authored
Merge pull request #9382 from douzzer/20251104-WC_MUTEX_OPS_INLINE
20251104-WC_MUTEX_OPS_INLINE
2 parents 4b93e3e + 54dc060 commit 9fdcd2e

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ WC_RSA_DIRECT
616616
WC_RSA_NONBLOCK
617617
WC_RSA_NONBLOCK_TIME
618618
WC_RSA_NO_FERMAT_CHECK
619+
WC_RWLOCK_OPS_INLINE
619620
WC_SHA384
620621
WC_SHA384_DIGEST_SIZE
621622
WC_SHA512

linuxkm/linuxkm_wc_port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,8 @@
13681368
#endif /* HAVE_FIPS */
13691369

13701370
#ifdef WOLFSSL_LINUXKM_USE_MUTEXES
1371+
#define WC_MUTEX_OPS_INLINE
1372+
13711373
#ifdef LINUXKM_LKCAPI_REGISTER
13721374
/* must use spin locks when registering implementations with the
13731375
* kernel, because mutexes are forbidden when calling with nonzero
@@ -1412,6 +1414,8 @@
14121414
return 0;
14131415
}
14141416
#else
1417+
#define WC_MUTEX_OPS_INLINE
1418+
14151419
/* if BUILDING_WOLFSSL, spinlock.h will have already been included
14161420
* recursively above, with the bevy of warnings suppressed, and the
14171421
* below include will be a redundant no-op.

wolfcrypt/src/wc_port.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,12 @@ int wolfSSL_HwPkMutexUnLock(void)
18801880
return compat_mutex_cb;
18811881
}
18821882
#endif /* defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) */
1883-
#ifdef SINGLE_THREADED
1883+
1884+
#if defined(WC_MUTEX_OPS_INLINE)
1885+
1886+
/* defined in headers */
1887+
1888+
#elif defined(SINGLE_THREADED)
18841889

18851890
int wc_InitMutex(wolfSSL_Mutex* m)
18861891
{
@@ -2423,10 +2428,6 @@ int wolfSSL_HwPkMutexUnLock(void)
24232428
else
24242429
return BAD_MUTEX_E;
24252430
}
2426-
#elif defined(WOLFSSL_LINUXKM)
2427-
2428-
/* defined as inlines in linuxkm/linuxkm_wc_port.h */
2429-
24302431
#elif defined(WOLFSSL_VXWORKS)
24312432

24322433
int wc_InitMutex(wolfSSL_Mutex* m)
@@ -3472,7 +3473,8 @@ int wolfSSL_HwPkMutexUnLock(void)
34723473
#warning No mutex handling defined
34733474

34743475
#endif
3475-
#if !defined(WOLFSSL_USE_RWLOCK) || defined(SINGLE_THREADED)
3476+
#if !defined(WOLFSSL_USE_RWLOCK) || defined(SINGLE_THREADED) || \
3477+
(defined(WC_MUTEX_OPS_INLINE) && !defined(WC_RWLOCK_OPS_INLINE))
34763478
int wc_InitRwLock(wolfSSL_RwLock* m)
34773479
{
34783480
return wc_InitMutex(m);

wolfssl/wolfcrypt/wc_port.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@
472472
#define WOLFSSL_MUTEX_INITIALIZER_CLAUSE(lockname) /* null expansion */
473473
#endif
474474

475-
#if !defined(WOLFSSL_USE_RWLOCK) || defined(SINGLE_THREADED)
475+
#if !defined(WOLFSSL_USE_RWLOCK) || defined(SINGLE_THREADED) || \
476+
(defined(WC_MUTEX_OPS_INLINE) && !defined(WC_RWLOCK_OPS_INLINE))
476477
typedef wolfSSL_Mutex wolfSSL_RwLock;
477478
#endif
478479

@@ -829,17 +830,21 @@ WOLFSSL_LOCAL void wolfSSL_RefWithMutexDec(wolfSSL_RefWithMutex* ref,
829830
#endif /* !defined(NO_PK_MUTEX) && defined(WOLFSSL_ALGO_HW_MUTEX) */
830831

831832
/* Mutex functions */
832-
WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex* m);
833+
#ifndef WC_MUTEX_OPS_INLINE
834+
WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex* m);
835+
WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex* m);
836+
WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex* m);
837+
WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex* m);
838+
#endif
833839
WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void);
834-
WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex* m);
835-
WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex* m);
836-
WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex* m);
837-
/* RwLock functions. Fallback to Mutex when not implemented explicitly. */
838-
WOLFSSL_API int wc_InitRwLock(wolfSSL_RwLock* m);
839-
WOLFSSL_API int wc_FreeRwLock(wolfSSL_RwLock* m);
840-
WOLFSSL_API int wc_LockRwLock_Wr(wolfSSL_RwLock* m);
841-
WOLFSSL_API int wc_LockRwLock_Rd(wolfSSL_RwLock* m);
842-
WOLFSSL_API int wc_UnLockRwLock(wolfSSL_RwLock* m);
840+
#ifndef WC_RWLOCK_OPS_INLINE
841+
/* RwLock functions. Fallback to Mutex when not implemented explicitly. */
842+
WOLFSSL_API int wc_InitRwLock(wolfSSL_RwLock* m);
843+
WOLFSSL_API int wc_FreeRwLock(wolfSSL_RwLock* m);
844+
WOLFSSL_API int wc_LockRwLock_Wr(wolfSSL_RwLock* m);
845+
WOLFSSL_API int wc_LockRwLock_Rd(wolfSSL_RwLock* m);
846+
WOLFSSL_API int wc_UnLockRwLock(wolfSSL_RwLock* m);
847+
#endif
843848
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
844849
/* dynamically set which mutex to use. unlock / lock is controlled by flag */
845850
typedef void (mutex_cb)(int flag, int type, const char* file, int line);

0 commit comments

Comments
 (0)