Skip to content

Commit b59a06f

Browse files
committed
Add backward patches for win32
1 parent bb44e88 commit b59a06f

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

src/SPC/store/SourcePatcher.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static function init(): void
2323
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']);
2424
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']);
2525
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']);
26+
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchWin32Time']);
2627
FileSystem::addSourceExtractHook('sqlsrv', [__CLASS__, 'patchSQLSRVWin32']);
2728
FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVWin32']);
2829
FileSystem::addSourceExtractHook('yaml', [__CLASS__, 'patchYamlWin32']);
@@ -500,6 +501,22 @@ public static function patchFfiCentos7FixO3strncmp(): bool
500501
return true;
501502
}
502503

504+
public static function patchWin32Time(): bool
505+
{
506+
if (PHP_OS_FAMILY !== 'Windows') {
507+
return false;
508+
}
509+
if (!file_exists(SOURCE_PATH . '/php-src/main/php_version.h')) {
510+
return false;
511+
}
512+
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
513+
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0 && intval($match[1]) < 80400) {
514+
self::patchFile('php_win32_time.patch', SOURCE_PATH . '/php-src');
515+
return true;
516+
}
517+
return false;
518+
}
519+
503520
public static function patchPkgConfigForGcc15(): bool
504521
{
505522
self::patchFile('pkg-config_gcc15.patch', SOURCE_PATH . '/pkg-config');
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)