Skip to content

GetSystemTimePreciseAsFileTime() is now always available #15400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions win32/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
switch (reason)
{
case DLL_PROCESS_ATTACH:
/*
* We do not need to check the return value of php_win32_init_gettimeofday()
* because the symbol bare minimum symbol we need is always available on our
* lowest supported platform.
*
* On Windows 8 or greater, we use a more precise symbol to obtain the system
* time, which is dynamically. The fallback allows us to proper support
* Vista/7/Server 2003 R2/Server 2008/Server 2008 R2.
*
* Instead simply initialize the global in win32/time.c for gettimeofday()
* use later on
*/
php_win32_init_gettimeofday();

ret = ret && php_win32_ioutil_init();
if (!ret) {
fprintf(stderr, "ioutil initialization failed");
Expand Down
31 changes: 1 addition & 30 deletions win32/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,13 @@
#include <errno.h>
#include "php_win32_globals.h"

typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);

static MyGetSystemTimeAsFileTime timefunc = NULL;

#ifdef PHP_EXPORTS
static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
{/*{{{*/
MyGetSystemTimeAsFileTime timefunc = NULL;
HMODULE hMod = GetModuleHandle("kernel32.dll");

if (hMod) {
/* Max possible resolution <1us, win8/server2012 */
timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime");
}

if(!timefunc) {
/* 100ns blocks since 01-Jan-1641 */
timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime;
}

return timefunc;
}/*}}}*/

void php_win32_init_gettimeofday(void)
{/*{{{*/
timefunc = get_time_func();
}/*}}}*/
#endif

static zend_always_inline int getfilesystemtime(struct timeval *tv)
{/*{{{*/
Comment on lines 26 to 27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible follow-up, this always returns 0 so make it void?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch. See #15413.

FILETIME ft;
unsigned __int64 ff = 0;
ULARGE_INTEGER fft;

timefunc(&ft);
GetSystemTimePreciseAsFileTime(&ft);

/*
* Do not cast a pointer to a FILETIME structure to either a
Expand Down
Loading