Skip to content

Commit f5accf7

Browse files
authored
Php win32 fix (#9)
* Update version to 0.2.1 * Ignore php_win32_ioutil_init for PHP 8.5 * Create cli_static_85.patch * Update cli_static_85.patch * Use empty patch content * Remove duplicate tsrmls cache define for static win build * Create cli_checks_85.patch * Add win32_api patch
2 parents 155b20a + 0522400 commit f5accf7

9 files changed

Lines changed: 292 additions & 8 deletions

patches/Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ vcruntime140 | Windows | 必须 Nessesary | 禁用sfx启动时GetModuleHandle(vc
1313
win32 | Windows | 必须 Nessesary | 修改构建系统以静态构建 Modify build system for build sfx file
1414
zend_stream | Windows | 必须 Nessesary | 修改构建系统以静态构建 Modify build system for build sfx file
1515
comctl32 | Windows | 可选 Optional | 添加comctl32.dll manifest以启用[visual style](https://learn.microsoft.com/en-us/windows/win32/controls/visual-styles-overview) (会让窗口控件好看一些) Add manifest dependency for comctl32 to enable [visual style](https://learn.microsoft.com/en-us/windows/win32/controls/visual-styles-overview) (makes window control looks modern)
16+
win32_api | Windows | 必须 Necessary | 修复一些win32 api的声明 Fix declarations of some win32 apis
1617

1718
## Usage
1819

@@ -85,3 +86,10 @@ This bypasses many hard-coded cli SAPI name checks.
8586
允许Windows的cli静态构建,不是给micro用的
8687

8788
This allows the Windows cli SAPI to be built fully statically. It is not a patch for micro.
89+
90+
### win32_api
91+
92+
修复一些win32 api的声明,避免编译警告。这些修改已经在新版本 PHP (>=8.4)中合并,但保证旧版本也能用,这些补丁仍然需要
93+
94+
This fixes declarations of some win32 apis to avoid compilation warnings. These changes have been merged into newer versions of PHP (>=8.4), but to ensure that older versions can still be used, these patches are still needed.
95+

patches/cli_checks_85.patch

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
2+
index 4c8fc9d1..8284ac2f 100644
3+
--- a/TSRM/tsrm_win32.c
4+
+++ b/TSRM/tsrm_win32.c
5+
@@ -535,7 +535,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
6+
}
7+
8+
dwCreateFlags = NORMAL_PRIORITY_CLASS;
9+
- if (strcmp(sapi_module.name, "cli") != 0) {
10+
+ if (strcmp(sapi_module.name, "cli") != 0 && strcmp(sapi_module.name, "micro") != 0) {
11+
dwCreateFlags |= CREATE_NO_WINDOW;
12+
}
13+
14+
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
15+
index 10fc11f5..eb4d4175 100644
16+
--- a/ext/ffi/ffi.c
17+
+++ b/ext/ffi/ffi.c
18+
@@ -5478,7 +5478,7 @@ ZEND_MINIT_FUNCTION(ffi)
19+
{
20+
REGISTER_INI_ENTRIES();
21+
22+
- FFI_G(is_cli) = strcmp(sapi_module.name, "cli") == 0;
23+
+ FFI_G(is_cli) = strcmp(sapi_module.name, "cli") == 0 || strcmp(sapi_module.name, "micro") == 1;
24+
25+
zend_ffi_exception_ce = register_class_FFI_Exception(zend_ce_error);
26+
27+
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
28+
index f597df36..ec617af7 100644
29+
--- a/ext/opcache/ZendAccelerator.c
30+
+++ b/ext/opcache/ZendAccelerator.c
31+
@@ -2847,6 +2847,7 @@ static void zps_startup_failure(const char *reason, const char *api_reason, int
32+
static inline bool accel_sapi_is_cli(void)
33+
{
34+
return strcmp(sapi_module.name, "cli") == 0
35+
+ || strcmp(sapi_module.name, "micro") == 0
36+
|| strcmp(sapi_module.name, "phpdbg") == 0;
37+
}
38+
39+
@@ -3163,6 +3164,7 @@ static int accel_startup(zend_extension *extension)
40+
#ifdef HAVE_HUGE_CODE_PAGES
41+
if (ZCG(accel_directives).huge_code_pages &&
42+
(strcmp(sapi_module.name, "cli") == 0 ||
43+
+ strcmp(sapi_module.name, "micro") == 0 ||
44+
strcmp(sapi_module.name, "cli-server") == 0 ||
45+
strcmp(sapi_module.name, "cgi-fcgi") == 0 ||
46+
strcmp(sapi_module.name, "fpm-fcgi") == 0)) {
47+
@@ -4958,6 +4960,7 @@ static zend_result accel_finish_startup_preload_subprocess(pid_t *pid)
48+
|| !*ZCG(accel_directives).preload_user) {
49+
50+
bool sapi_requires_preload_user = !(strcmp(sapi_module.name, "cli") == 0
51+
+ || strcmp(sapi_module.name, "micro") == 0
52+
|| strcmp(sapi_module.name, "phpdbg") == 0);
53+
54+
if (!sapi_requires_preload_user) {
55+
diff --git a/ext/pdo_sqlite/pdo_sqlite.c b/ext/pdo_sqlite/pdo_sqlite.c
56+
index 023e35a2..6f00159a 100644
57+
--- a/ext/pdo_sqlite/pdo_sqlite.c
58+
+++ b/ext/pdo_sqlite/pdo_sqlite.c
59+
@@ -94,6 +94,7 @@ PHP_METHOD(Pdo_Sqlite, loadExtension)
60+
#ifdef ZTS
61+
if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
62+
(strcmp(sapi_module.name, "cli") != 0) &&
63+
+ (strcmp(sapi_module.name, "micro") != 0) &&
64+
(strncmp(sapi_module.name, "embed", 5) != 0)
65+
) {
66+
zend_throw_exception_ex(php_pdo_get_exception(), 0, "Not supported in multithreaded Web servers");
67+
diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c
68+
index 31212999..d7705d59 100644
69+
--- a/ext/readline/readline_cli.c
70+
+++ b/ext/readline/readline_cli.c
71+
@@ -730,7 +730,7 @@ typedef cli_shell_callbacks_t *(__cdecl *get_cli_shell_callbacks)(void);
72+
get_cli_shell_callbacks get_callbacks; \
73+
HMODULE hMod = GetModuleHandle("php.exe"); \
74+
(cb) = NULL; \
75+
- if (strlen(sapi_module.name) >= 3 && 0 == strncmp("cli", sapi_module.name, 3)) { \
76+
+ if (strlen(sapi_module.name) >= 3 && 0 == strncmp("cli", sapi_module.name, 3) || 0 == strcmp("micro", sapi_module.name)) { \
77+
get_callbacks = (get_cli_shell_callbacks)GetProcAddress(hMod, "php_cli_get_shell_callbacks"); \
78+
if (get_callbacks) { \
79+
(cb) = get_callbacks(); \
80+
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
81+
index 21b6840a..05a7aa8e 100644
82+
--- a/ext/sqlite3/sqlite3.c
83+
+++ b/ext/sqlite3/sqlite3.c
84+
@@ -413,6 +413,7 @@ PHP_METHOD(SQLite3, loadExtension)
85+
#ifdef ZTS
86+
if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
87+
(strcmp(sapi_module.name, "cli") != 0) &&
88+
+ (strcmp(sapi_module.name, "micro") != 0) &&
89+
(strncmp(sapi_module.name, "embed", 5) != 0)
90+
) { php_sqlite3_error(db_obj, 0, "Not supported in multithreaded Web servers");
91+
RETURN_FALSE;
92+
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
93+
index ea33ba49..083184b8 100644
94+
--- a/ext/standard/php_fopen_wrapper.c
95+
+++ b/ext/standard/php_fopen_wrapper.c
96+
@@ -242,7 +242,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
97+
}
98+
return NULL;
99+
}
100+
- if (!strcmp(sapi_module.name, "cli")) {
101+
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
102+
static int cli_in = 0;
103+
fd = STDIN_FILENO;
104+
if (cli_in) {
105+
@@ -258,7 +258,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
106+
pipe_requested = 1;
107+
#endif
108+
} else if (!strcasecmp(path, "stdout")) {
109+
- if (!strcmp(sapi_module.name, "cli")) {
110+
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
111+
static int cli_out = 0;
112+
fd = STDOUT_FILENO;
113+
if (cli_out++) {
114+
@@ -274,7 +274,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
115+
pipe_requested = 1;
116+
#endif
117+
} else if (!strcasecmp(path, "stderr")) {
118+
- if (!strcmp(sapi_module.name, "cli")) {
119+
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
120+
static int cli_err = 0;
121+
fd = STDERR_FILENO;
122+
if (cli_err++) {
123+
@@ -295,7 +295,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
124+
zend_long fildes_ori;
125+
int dtablesize;
126+
127+
- if (strcmp(sapi_module.name, "cli")) {
128+
+ if (strcmp(sapi_module.name, "cli") || strcmp(sapi_module.name, "micro")) {
129+
if (options & REPORT_ERRORS) {
130+
php_error_docref(NULL, E_WARNING, "Direct access to file descriptors is only available from command-line PHP");
131+
}
132+
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
133+
index 690e23e0..80ab3d32 100644
134+
--- a/ext/standard/proc_open.c
135+
+++ b/ext/standard/proc_open.c
136+
@@ -1333,7 +1333,7 @@ PHP_FUNCTION(proc_open)
137+
}
138+
139+
dwCreateFlags = NORMAL_PRIORITY_CLASS;
140+
- if(strcmp(sapi_module.name, "cli") != 0) {
141+
+ if(strcmp(sapi_module.name, "cli") != 0 && strcmp(sapi_module.name, "micro") != 0) {
142+
dwCreateFlags |= CREATE_NO_WINDOW;
143+
}
144+
if (create_process_group) {
145+
diff --git a/main/main.c b/main/main.c
146+
index 8465b6c0..cf8f9ef0 100644
147+
--- a/main/main.c
148+
+++ b/main/main.c
149+
@@ -580,7 +580,7 @@ static PHP_INI_DISP(display_errors_mode)
150+
mode = php_get_display_errors_mode(temporary_value);
151+
152+
/* Display 'On' for other SAPIs instead of STDOUT or STDERR */
153+
- cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));
154+
+ cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg") || !strcmp(sapi_module.name, "micro"));
155+
156+
switch (mode) {
157+
case PHP_DISPLAY_ERRORS_STDERR:
158+
@@ -1470,7 +1470,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
159+
}
160+
} else {
161+
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */
162+
- if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) &&
163+
+ if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg") || !strcmp(sapi_module.name, "micro")) &&
164+
PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
165+
) {
166+
fprintf(stderr, "%s: ", error_type_str);
167+
diff --git a/win32/console.c b/win32/console.c
168+
index 9b485610..a2b764cd 100644
169+
--- a/win32/console.c
170+
+++ b/win32/console.c
171+
@@ -111,6 +111,6 @@ PHP_WINUTIL_API BOOL php_win32_console_is_own(void)
172+
173+
PHP_WINUTIL_API BOOL php_win32_console_is_cli_sapi(void)
174+
{/*{{{*/
175+
- return strlen(sapi_module.name) >= sizeof("cli") - 1 && !strncmp(sapi_module.name, "cli", sizeof("cli") - 1);
176+
+ return (strlen(sapi_module.name) >= sizeof("cli") - 1 && !strncmp(sapi_module.name, "cli", sizeof("cli") - 1)) || 0 == strcmp(sapi_module.name, "micro");
177+
}/*}}}*/
178+

patches/cli_static_80.patch

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ index 0ad53e813c..a8cc1bee29 100644
33
--- a/sapi/cli/php_cli.c
44
+++ b/sapi/cli/php_cli.c
55
@@ -97,7 +97,7 @@ PHPAPI extern char *php_ini_scanned_files;
6-
6+
77
#if defined(PHP_WIN32)
88
#if defined(ZTS)
99
-ZEND_TSRMLS_CACHE_DEFINE()
1010
+//ZEND_TSRMLS_CACHE_DEFINE()
1111
#endif
1212
static DWORD orig_cp = 0;
1313
#endif
14-
@@ -1160,6 +1160,11 @@ int main(int argc, char *argv[])
14+
@@ -1160,6 +1160,10 @@ int main(int argc, char *argv[])
1515
#endif
1616
{
1717
#if defined(PHP_WIN32)
18-
+ php_win32_init_gettimeofday();
1918
+ if (!php_win32_ioutil_init()) {
2019
+ fprintf(stderr, "ioutil initialization failed");
2120
+ return 1;

patches/cli_static_85.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
2+
index e212a0f7..f16e8ea9 100644
3+
--- a/sapi/cli/php_cli.c
4+
+++ b/sapi/cli/php_cli.c
5+
@@ -98,7 +98,7 @@ PHPAPI extern char *php_ini_scanned_files;
6+
7+
#if defined(PHP_WIN32)
8+
#if defined(ZTS)
9+
-ZEND_TSRMLS_CACHE_DEFINE()
10+
+// ZEND_TSRMLS_CACHE_DEFINE()
11+
#endif
12+
static DWORD orig_cp = 0;
13+
#endif

patches/static_opcache_85.patch

Whitespace-only changes.

patches/win32_api_80.patch

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
diff --git a/win32/dllmain.c b/win32/dllmain.c
2+
index a507f1e1..ab625bf3 100644
3+
--- a/win32/dllmain.c
4+
+++ b/win32/dllmain.c
5+
@@ -38,20 +38,6 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
6+
switch (reason)
7+
{
8+
case DLL_PROCESS_ATTACH:
9+
- /*
10+
- * We do not need to check the return value of php_win32_init_gettimeofday()
11+
- * because the symbol bare minimum symbol we need is always available on our
12+
- * lowest supported platform.
13+
- *
14+
- * On Windows 8 or greater, we use a more precise symbol to obtain the system
15+
- * time, which is dynamically. The fallback allows us to proper support
16+
- * Vista/7/Server 2003 R2/Server 2008/Server 2008 R2.
17+
- *
18+
- * Instead simply initialize the global in win32/time.c for gettimeofday()
19+
- * use later on
20+
- */
21+
- php_win32_init_gettimeofday();
22+
-
23+
ret = ret && php_win32_ioutil_init();
24+
if (!ret) {
25+
fprintf(stderr, "ioutil initialization failed");
26+
diff --git a/win32/time.c b/win32/time.c
27+
index d1fe5145..57db914e 100644
28+
--- a/win32/time.c
29+
+++ b/win32/time.c
30+
@@ -23,42 +23,13 @@
31+
#include <errno.h>
32+
#include "php_win32_globals.h"
33+
34+
-typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
35+
-
36+
-static MyGetSystemTimeAsFileTime timefunc = NULL;
37+
-
38+
-#ifdef PHP_EXPORTS
39+
-static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
40+
-{/*{{{*/
41+
- MyGetSystemTimeAsFileTime timefunc = NULL;
42+
- HMODULE hMod = GetModuleHandle("kernel32.dll");
43+
-
44+
- if (hMod) {
45+
- /* Max possible resolution <1us, win8/server2012 */
46+
- timefunc = (MyGetSystemTimeAsFileTime)GetProcAddress(hMod, "GetSystemTimePreciseAsFileTime");
47+
- }
48+
-
49+
- if(!timefunc) {
50+
- /* 100ns blocks since 01-Jan-1641 */
51+
- timefunc = (MyGetSystemTimeAsFileTime) GetSystemTimeAsFileTime;
52+
- }
53+
-
54+
- return timefunc;
55+
-}/*}}}*/
56+
-
57+
-void php_win32_init_gettimeofday(void)
58+
-{/*{{{*/
59+
- timefunc = get_time_func();
60+
-}/*}}}*/
61+
-#endif
62+
-
63+
static zend_always_inline int getfilesystemtime(struct timeval *tv)
64+
{/*{{{*/
65+
FILETIME ft;
66+
unsigned __int64 ff = 0;
67+
ULARGE_INTEGER fft;
68+
69+
- timefunc(&ft);
70+
+ GetSystemTimePreciseAsFileTime(&ft);
71+
72+
/*
73+
* Do not cast a pointer to a FILETIME structure to either a
74+
diff --git a/win32/time.h b/win32/time.h
75+
index 51090ccf..77d1cbfd 100644
76+
--- a/win32/time.h
77+
+++ b/win32/time.h
78+
@@ -54,10 +54,4 @@ PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp );
79+
80+
PHPAPI int usleep(unsigned int useconds);
81+
82+
-#ifdef PHP_EXPORTS
83+
-/* This symbols are needed only for the DllMain, but should not be exported
84+
- or be available when used with PHP binaries. */
85+
-void php_win32_init_gettimeofday(void);
86+
-#endif
87+
-
88+
#endif

patches/win32_api_84.patch

Whitespace-only changes.

php_micro.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ here's original copyright notice
5151
# include "win32/time.h"
5252
BOOL php_win32_init_random_bytes(void);
5353
BOOL php_win32_shutdown_random_bytes(void);
54+
#if PHP_VERSION_ID < 80500
5455
BOOL php_win32_ioutil_init(void);
55-
#if PHP_VERSION_ID < 80400
56-
void php_win32_init_gettimeofday(void);
5756
#endif
5857
#else
5958
# define php_select(m, r, w, e, t) select(m, r, w, e, t)
@@ -588,9 +587,8 @@ int main(int argc, char *argv[])
588587
int wapiret = 0;
589588
php_win32_init_random_bytes();
590589
// php_win32_signal_ctrl_handler_init();
590+
#if PHP_VERSION_ID < 80500
591591
php_win32_ioutil_init();
592-
#if PHP_VERSION_ID < 80400
593-
php_win32_init_gettimeofday();
594592
#endif
595593

596594
_fmode = _O_BINARY; /* sets default for file streams to binary */

php_micro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525

2626
#define PHP_MICRO_VER_MAJ 0
2727
#define PHP_MICRO_VER_MIN 2
28-
#define PHP_MICRO_VER_PAT 0
28+
#define PHP_MICRO_VER_PAT 2
2929
// #define PHP_MICRO_VER_APP "nope"
3030
#ifdef PHP_MICRO_VER_APP
3131
# define PHP_MICRO_VER_STR \

0 commit comments

Comments
 (0)