From d6412609875769751b0bc7a170b562701c485484 Mon Sep 17 00:00:00 2001 From: Embedthis Software Date: Thu, 10 Sep 2015 11:45:13 -0700 Subject: [PATCH 1/4] Fix single threaded builds --- include/mbedtls/threading.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/mbedtls/threading.h b/include/mbedtls/threading.h index c39cbf24d7..b416d478a5 100644 --- a/include/mbedtls/threading.h +++ b/include/mbedtls/threading.h @@ -81,6 +81,7 @@ void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * void mbedtls_threading_free_alt( void ); #endif /* MBEDTLS_THREADING_ALT */ +#if defined(MBEDTLS_THREADING_C) /* * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock * @@ -96,6 +97,7 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); */ extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; +#endif #ifdef __cplusplus } From 3d72b5d68865f47608471392586a94e7e3edcdae Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 10 May 2016 16:17:27 +0100 Subject: [PATCH 2/4] Add end guard comment --- include/mbedtls/threading.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/threading.h b/include/mbedtls/threading.h index b416d478a5..b0c34ecc74 100644 --- a/include/mbedtls/threading.h +++ b/include/mbedtls/threading.h @@ -97,7 +97,7 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); */ extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; -#endif +#endif /* MBEDTLS_THREADING_C */ #ifdef __cplusplus } From 0a91973e4b6f6049be3a0777861c48e965050e66 Mon Sep 17 00:00:00 2001 From: Gergely Budai Date: Wed, 23 Aug 2017 14:23:58 +0200 Subject: [PATCH 3/4] Do not define and initialize global mutexes on configurations that do not use them. --- include/mbedtls/threading.h | 4 ++++ library/threading.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/mbedtls/threading.h b/include/mbedtls/threading.h index b0c34ecc74..3218f5cdfd 100644 --- a/include/mbedtls/threading.h +++ b/include/mbedtls/threading.h @@ -95,8 +95,12 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); /* * Global mutexes */ +#if defined(MBEDTLS_FS_IO) extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; +#endif +#if defined(MBEDTLS_HAVE_TIME_DATE) extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; +#endif #endif /* MBEDTLS_THREADING_C */ #ifdef __cplusplus diff --git a/library/threading.c b/library/threading.c index 07586756f2..f1c37245c7 100644 --- a/library/threading.c +++ b/library/threading.c @@ -111,8 +111,12 @@ void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * mbedtls_mutex_lock = mutex_lock; mbedtls_mutex_unlock = mutex_unlock; +#if defined(MBEDTLS_FS_IO) mbedtls_mutex_init( &mbedtls_threading_readdir_mutex ); +#endif +#if defined(MBEDTLS_HAVE_TIME_DATE) mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex ); +#endif } /* @@ -120,8 +124,12 @@ void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * */ void mbedtls_threading_free_alt( void ) { +#if defined(MBEDTLS_FS_IO) mbedtls_mutex_free( &mbedtls_threading_readdir_mutex ); +#endif +#if defined(MBEDTLS_HAVE_TIME_DATE) mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex ); +#endif } #endif /* MBEDTLS_THREADING_ALT */ @@ -131,7 +139,11 @@ void mbedtls_threading_free_alt( void ) #ifndef MUTEX_INIT #define MUTEX_INIT #endif +#if defined(MBEDTLS_FS_IO) mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT; +#endif +#if defined(MBEDTLS_HAVE_TIME_DATE) mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT; +#endif #endif /* MBEDTLS_THREADING_C */ From 2a0aee3163793b16789671dce490fb2a08ffad5c Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Wed, 21 Mar 2018 15:35:01 +0000 Subject: [PATCH 4/4] Add ChangeLog entry for redundant mutex initialization optimizations --- ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0eb0702129..571f5eb651 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ mbed TLS ChangeLog (Sorted per branch, date) += mbed TLS 2.1.x branch released xxxx-xx-xx + +Changes + * Do not define global mutexes around readdir() and gmtime() in + configurations where the feature is disabled. Found and fixed by Gergely + Budai. + = mbed TLS 2.1.11 branch released xxxx-xx-xx Default behavior changes