From 57260c215c025e17b57e0b7d8478edbcddb74407 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Mon, 30 Aug 2021 23:54:44 +0200 Subject: [PATCH 1/3] windows: resync the VM time when the system clock gets changed Bug report on squeak-dev: http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-June/215908.html --- platforms/win32/vm/sqWin32Heartbeat.c | 7 +++++++ platforms/win32/vm/sqWin32Window.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/platforms/win32/vm/sqWin32Heartbeat.c b/platforms/win32/vm/sqWin32Heartbeat.c index 28b9d61527..93038f4a85 100755 --- a/platforms/win32/vm/sqWin32Heartbeat.c +++ b/platforms/win32/vm/sqWin32Heartbeat.c @@ -260,6 +260,13 @@ ioInitTime(void) utcStartMicroseconds = utcMicrosecondClock; } +void resyncSystemTime() { + // By setting these values to maximum, currentUTCMicroseconds() will resync to the system time. + lastTick = (DWORD)-1; + vmThreadLastTick = (DWORD)-1; + ioUpdateVMTimezone(); +} + unsigned long long ioUTCMicroseconds() { return get64(utcMicrosecondClock); } diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 855ae4c532..74eef329e2 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -625,6 +625,10 @@ MainWndProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_KILLFOCUS: fHasFocus = 0; return DefWindowProcW(hwnd,message,wParam,lParam); + + case WM_TIMECHANGE: + resyncSystemTime(); + default: /* Unprocessed messages may be processed outside the current module. If firstMessageHook is non-NULL and returns a non From 26dda2dec16db8746fda140b214d54c06c29459b Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Tue, 31 Aug 2021 00:12:02 +0200 Subject: [PATCH 2/3] only resync system time for relevant windows versions --- platforms/win32/vm/sqWin32Heartbeat.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platforms/win32/vm/sqWin32Heartbeat.c b/platforms/win32/vm/sqWin32Heartbeat.c index 93038f4a85..b6c4a0f709 100755 --- a/platforms/win32/vm/sqWin32Heartbeat.c +++ b/platforms/win32/vm/sqWin32Heartbeat.c @@ -261,9 +261,13 @@ ioInitTime(void) } void resyncSystemTime() { + #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) + // Nothing to be done, time will be resynced upon every heartbeat tick + #else // (_WIN32_WINNT >= _WIN32_WINNT_WIN8) // By setting these values to maximum, currentUTCMicroseconds() will resync to the system time. lastTick = (DWORD)-1; vmThreadLastTick = (DWORD)-1; + #endif ioUpdateVMTimezone(); } From cd8c50d7839e117f9a12c0d8c3e277f700eae624 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Tue, 7 Sep 2021 18:13:20 +0200 Subject: [PATCH 3/3] Resolve fallthrough --- platforms/win32/vm/sqWin32Window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/win32/vm/sqWin32Window.c b/platforms/win32/vm/sqWin32Window.c index 74eef329e2..1cb36fb751 100644 --- a/platforms/win32/vm/sqWin32Window.c +++ b/platforms/win32/vm/sqWin32Window.c @@ -628,6 +628,7 @@ MainWndProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_TIMECHANGE: resyncSystemTime(); + return DefWindowProcW(hwnd,message,wParam,lParam); default: /* Unprocessed messages may be processed outside the current