From 7f244a5e366f6fe9070ac3e9cdf23da897e6d228 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 d9db5d2df..28bef5579 100644 --- a/library/timing.c +++ b/library/timing.c @@ -46,6 +46,7 @@ #include #include +#include struct _hr_time { @@ -261,18 +262,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. @@ -283,7 +282,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 3476de20137e06615bcb300da94de55b17eb9816 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 28bef5579..7832d04d2 100644 --- a/library/timing.c +++ b/library/timing.c @@ -264,7 +264,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) @@ -282,7 +282,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 8f303f9146921e9606fc2d8d4dc47b903e5dca95 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 7832d04d2..4feb79d7f 100644 --- a/library/timing.c +++ b/library/timing.c @@ -267,7 +267,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 973c29e1cf32f9d55c9293176d7afd1b867715c7 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8c82d08d1..09afc1e11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ Changes * Close a test gap in (D)TLS between the client side and the server side: test the handling of large packets and small packets on the client side in the same way as on the server side. + * 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.1.15 branch released 2018-08-31