Implement ms time with GetSystemTimeAsFile time.
There's a potential race condition with calling time(NULL) after
GetSystemTime().
See
https://learn.microsoft.com/en-us/archive/msdn-magazine/2004/march/implementing-a-high-resolution-time-provider-for-windows
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
diff --git a/library/platform_util.c b/library/platform_util.c
index 1f60404..e885a92 100644
--- a/library/platform_util.c
+++ b/library/platform_util.c
@@ -196,10 +196,13 @@
#include <windows.h>
mbedtls_ms_time_t mbedtls_ms_time(void)
{
- SYSTEMTIME st;
+ FILETIME ct;
+ mbedtls_ms_time_t current_ms;
- GetSystemTime(&st);
- return time(NULL)*1000LL + st.wMilliseconds;
+ GetSystemTimeAsFileTime(&ct);
+ current_ms = ((mbedtls_ms_time_t) ct.dwLowDateTime +
+ ((mbedtls_ms_time_t) (ct.dwHighDateTime) << 32LL))/10;
+ return current_ms;
}
#else
#error "No mbedtls_ms_time available"