|
| 1 | +From d919783778c6d2310285e657fd0c3612238bf6ac Mon Sep 17 00:00:00 2001 |
| 2 | +From: "Christoph M. Becker" <cmbecker69@gmx.de> |
| 3 | +Date: Wed, 14 Aug 2024 13:02:12 +0200 |
| 4 | +Subject: [PATCH 1/2] GetSystemTimePreciseAsFileTime() is now always available |
| 5 | + |
| 6 | +As of PHP 8.3.0, we require Windows Server 2012 or Windows 8 as bare |
| 7 | +minimum. Since GetSystemTimePreciseAsFileTime() is always available on |
| 8 | +these Windows versions[1], there is no more need for the workaround |
| 9 | +described in dllmain.c; we just can call the function directly. |
| 10 | + |
| 11 | +[1] <https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime> |
| 12 | +--- |
| 13 | + win32/dllmain.c | 14 -------------- |
| 14 | + win32/time.c | 29 +---------------------------- |
| 15 | + 2 files changed, 1 insertion(+), 42 deletions(-) |
| 16 | + |
| 17 | +diff --git a/win32/dllmain.c b/win32/dllmain.c |
| 18 | +index a507f1e169246..ab625bf3e597b 100644 |
| 19 | +--- a/win32/dllmain.c |
| 20 | ++++ b/win32/dllmain.c |
| 21 | +@@ -38,20 +38,6 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy) |
| 22 | + switch (reason) |
| 23 | + { |
| 24 | + case DLL_PROCESS_ATTACH: |
| 25 | +- /* |
| 26 | +- * We do not need to check the return value of php_win32_init_gettimeofday() |
| 27 | +- * because the symbol bare minimum symbol we need is always available on our |
| 28 | +- * lowest supported platform. |
| 29 | +- * |
| 30 | +- * On Windows 8 or greater, we use a more precise symbol to obtain the system |
| 31 | +- * time, which is dynamically. The fallback allows us to proper support |
| 32 | +- * Vista/7/Server 2003 R2/Server 2008/Server 2008 R2. |
| 33 | +- * |
| 34 | +- * Instead simply initialize the global in win32/time.c for gettimeofday() |
| 35 | +- * use later on |
| 36 | +- */ |
| 37 | +- php_win32_init_gettimeofday(); |
| 38 | +- |
| 39 | + ret = ret && php_win32_ioutil_init(); |
| 40 | + if (!ret) { |
| 41 | + fprintf(stderr, "ioutil initialization failed"); |
| 42 | +diff --git a/win32/time.c b/win32/time.c |
| 43 | +index d1fe51458ec57..af02ee96a10e7 100644 |
| 44 | +--- a/win32/time.c |
| 45 | ++++ b/win32/time.c |
| 46 | +@@ -25,40 +25,13 @@ |
| 47 | + |
| 48 | + typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime); |
| 49 | + |
| 50 | +-static MyGetSystemTimeAsFileTime timefunc = NULL; |
| 51 | +- |
| 52 | +-#ifdef PHP_EXPORTS |
| 53 | +-static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void) |
| 54 | +-{/*{{{*/ |
| 55 | +- MyGetSystemTimeAsFileTime timefunc = NULL; |
| 56 | +- HMODULE hMod = GetModuleHandle("kernel32.dll"); |
| 57 | +- |
| 58 | +- if (hMod) { |
| 59 | +- /* Max possible resolution <1us, win8/server2012 */ |
| 60 | +- timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime"); |
| 61 | +- } |
| 62 | +- |
| 63 | +- if(!timefunc) { |
| 64 | +- /* 100ns blocks since 01-Jan-1641 */ |
| 65 | +- timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime; |
| 66 | +- } |
| 67 | +- |
| 68 | +- return timefunc; |
| 69 | +-}/*}}}*/ |
| 70 | +- |
| 71 | +-void php_win32_init_gettimeofday(void) |
| 72 | +-{/*{{{*/ |
| 73 | +- timefunc = get_time_func(); |
| 74 | +-}/*}}}*/ |
| 75 | +-#endif |
| 76 | +- |
| 77 | + static zend_always_inline int getfilesystemtime(struct timeval *tv) |
| 78 | + {/*{{{*/ |
| 79 | + FILETIME ft; |
| 80 | + unsigned __int64 ff = 0; |
| 81 | + ULARGE_INTEGER fft; |
| 82 | + |
| 83 | +- timefunc(&ft); |
| 84 | ++ GetSystemTimePreciseAsFileTime(&ft); |
| 85 | + |
| 86 | + /* |
| 87 | + * Do not cast a pointer to a FILETIME structure to either a |
| 88 | + |
| 89 | +From b357bc794b0dafe9cee3f09972ba596ac4610d01 Mon Sep 17 00:00:00 2001 |
| 90 | +From: "Christoph M. Becker" <cmbecker69@gmx.de> |
| 91 | +Date: Wed, 14 Aug 2024 13:12:24 +0200 |
| 92 | +Subject: [PATCH 2/2] Remove now unused typedef |
| 93 | + |
| 94 | +--- |
| 95 | + win32/time.c | 2 -- |
| 96 | + 1 file changed, 2 deletions(-) |
| 97 | + |
| 98 | +diff --git a/win32/time.c b/win32/time.c |
| 99 | +index af02ee96a10e7..57db914e6a8f6 100644 |
| 100 | +--- a/win32/time.c |
| 101 | ++++ b/win32/time.c |
| 102 | +@@ -23,8 +23,6 @@ |
| 103 | + #include <errno.h> |
| 104 | + #include "php_win32_globals.h" |
| 105 | + |
| 106 | +-typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime); |
| 107 | +- |
| 108 | + static zend_always_inline int getfilesystemtime(struct timeval *tv) |
| 109 | + {/*{{{*/ |
| 110 | + FILETIME ft; |
0 commit comments