Skip to content

Commit 25afbdb

Browse files
authored
GetSystemTimePreciseAsFileTime() is now always available (phpGH-15400)
* GetSystemTimePreciseAsFileTime() is now always available As of PHP 8.3.0, we require Windows Server 2012 or Windows 8 as bare minimum. Since GetSystemTimePreciseAsFileTime() is always available on these Windows versions[1], there is no more need for the workaround described in dllmain.c; we just can call the function directly. [1] <https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime>
1 parent 390088b commit 25afbdb

File tree

2 files changed

+1
-44
lines changed

2 files changed

+1
-44
lines changed

win32/dllmain.c

-14
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
3838
switch (reason)
3939
{
4040
case DLL_PROCESS_ATTACH:
41-
/*
42-
* We do not need to check the return value of php_win32_init_gettimeofday()
43-
* because the symbol bare minimum symbol we need is always available on our
44-
* lowest supported platform.
45-
*
46-
* On Windows 8 or greater, we use a more precise symbol to obtain the system
47-
* time, which is dynamically. The fallback allows us to proper support
48-
* Vista/7/Server 2003 R2/Server 2008/Server 2008 R2.
49-
*
50-
* Instead simply initialize the global in win32/time.c for gettimeofday()
51-
* use later on
52-
*/
53-
php_win32_init_gettimeofday();
54-
5541
ret = ret && php_win32_ioutil_init();
5642
if (!ret) {
5743
fprintf(stderr, "ioutil initialization failed");

win32/time.c

+1-30
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,13 @@
2323
#include <errno.h>
2424
#include "php_win32_globals.h"
2525

26-
typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
27-
28-
static MyGetSystemTimeAsFileTime timefunc = NULL;
29-
30-
#ifdef PHP_EXPORTS
31-
static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
32-
{/*{{{*/
33-
MyGetSystemTimeAsFileTime timefunc = NULL;
34-
HMODULE hMod = GetModuleHandle("kernel32.dll");
35-
36-
if (hMod) {
37-
/* Max possible resolution <1us, win8/server2012 */
38-
timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime");
39-
}
40-
41-
if(!timefunc) {
42-
/* 100ns blocks since 01-Jan-1641 */
43-
timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime;
44-
}
45-
46-
return timefunc;
47-
}/*}}}*/
48-
49-
void php_win32_init_gettimeofday(void)
50-
{/*{{{*/
51-
timefunc = get_time_func();
52-
}/*}}}*/
53-
#endif
54-
5526
static zend_always_inline int getfilesystemtime(struct timeval *tv)
5627
{/*{{{*/
5728
FILETIME ft;
5829
unsigned __int64 ff = 0;
5930
ULARGE_INTEGER fft;
6031

61-
timefunc(&ft);
32+
GetSystemTimePreciseAsFileTime(&ft);
6233

6334
/*
6435
* Do not cast a pointer to a FILETIME structure to either a

0 commit comments

Comments
 (0)