From e931d0efe592461d0237f5c3f3b4ac5bcb027044 Mon Sep 17 00:00:00 2001 From: irwir Date: Sat, 23 Jun 2018 18:55:14 +0300 Subject: [PATCH 1/4] Replace Windows API threading with CRT functions --- library/timing.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/timing.c b/library/timing.c index 6a30e5125..db186ee29 100644 --- a/library/timing.c +++ b/library/timing.c @@ -51,6 +51,7 @@ #include #include +#include struct _hr_time { @@ -266,18 +267,16 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int /* It's OK to use a global because alarm() is supposed to be global anyway */ static DWORD alarmMs; -static DWORD WINAPI TimerProc( LPVOID TimerContext ) +static void TimerProc( void *TimerContext ) { - ((void) TimerContext); + (void)TimerContext; Sleep( alarmMs ); mbedtls_timing_alarmed = 1; - return( TRUE ); + // Implicit call of _endthread() is better (see MS online docs) } void mbedtls_set_alarm( int seconds ) { - DWORD ThreadId; - if( seconds == 0 ) { /* No need to create a thread for this simple case. @@ -288,7 +287,7 @@ void mbedtls_set_alarm( int seconds ) mbedtls_timing_alarmed = 0; alarmMs = seconds * 1000; - CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) ); + (void)_beginthread( TimerProc, 0, NULL ); } #else /* _WIN32 && !EFIX64 && !EFI32 */ From e1b82ad25f57138eeb291993eec50ab163b97a63 Mon Sep 17 00:00:00 2001 From: irwir Date: Thu, 30 Aug 2018 11:57:09 +0300 Subject: [PATCH 2/4] Added spaces after type casts `(void) TimerContext;` seems more consistent with the current style than ((void) TimerContext); No objections to changing this if necessary. --- library/timing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/timing.c b/library/timing.c index db186ee29..af27088a0 100644 --- a/library/timing.c +++ b/library/timing.c @@ -269,7 +269,7 @@ static DWORD alarmMs; static void TimerProc( void *TimerContext ) { - (void)TimerContext; + (void) TimerContext; Sleep( alarmMs ); mbedtls_timing_alarmed = 1; // Implicit call of _endthread() is better (see MS online docs) @@ -287,7 +287,7 @@ void mbedtls_set_alarm( int seconds ) mbedtls_timing_alarmed = 0; alarmMs = seconds * 1000; - (void)_beginthread( TimerProc, 0, NULL ); + (void) _beginthread( TimerProc, 0, NULL ); } #else /* _WIN32 && !EFIX64 && !EFI32 */ From da642d98c02cd89d6e6f80f9387a389e30d1f64a Mon Sep 17 00:00:00 2001 From: irwir Date: Fri, 31 Aug 2018 15:14:54 +0300 Subject: [PATCH 3/4] Implicit _endthread call: comment changed --- library/timing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/timing.c b/library/timing.c index af27088a0..25cb70d78 100644 --- a/library/timing.c +++ b/library/timing.c @@ -272,7 +272,8 @@ static void TimerProc( void *TimerContext ) (void) TimerContext; Sleep( alarmMs ); mbedtls_timing_alarmed = 1; - // Implicit call of _endthread() is better (see MS online docs) + /* _endthread will be called implicitly on return + * That ensures execution of thread funcition's epilogue */ } void mbedtls_set_alarm( int seconds ) From 404aa65813fccf751047e21b064ad87e055fc71b Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Mon, 1 Oct 2018 14:44:22 +0100 Subject: [PATCH 4/4] Add ChangeLog entry for Windows threading fix --- ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 027a97174..9f463e1c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ mbed TLS ChangeLog (Sorted per branch, date) += mbed TLS x.x.x branch released xxxx-xx-xx + +Changes + * Change the use of Windows threading to use Microsoft Visual C++ runtime + calls, rather than Win32 API calls directly. This is necessary to avoid + conflict with C runtime usage. Found and fixed by irwir. + = mbed TLS 2.11.0 branch released 2018-06-18 Features