Skip to content
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
8 changes: 8 additions & 0 deletions patches/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vcruntime140 | Windows | 必须 Nessesary | 禁用sfx启动时GetModuleHandle(vc
win32 | Windows | 必须 Nessesary | 修改构建系统以静态构建 Modify build system for build sfx file
zend_stream | Windows | 必须 Nessesary | 修改构建系统以静态构建 Modify build system for build sfx file
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)
win32_api | Windows | 必须 Necessary | 修复一些win32 api的声明 Fix declarations of some win32 apis

## Usage

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

This allows the Windows cli SAPI to be built fully statically. It is not a patch for micro.

### win32_api

修复一些win32 api的声明,避免编译警告。这些修改已经在新版本 PHP (>=8.4)中合并,但保证旧版本也能用,这些补丁仍然需要

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.

178 changes: 178 additions & 0 deletions patches/cli_checks_85.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index 4c8fc9d1..8284ac2f 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -535,7 +535,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
}

dwCreateFlags = NORMAL_PRIORITY_CLASS;
- if (strcmp(sapi_module.name, "cli") != 0) {
+ if (strcmp(sapi_module.name, "cli") != 0 && strcmp(sapi_module.name, "micro") != 0) {
dwCreateFlags |= CREATE_NO_WINDOW;
}

diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
index 10fc11f5..eb4d4175 100644
--- a/ext/ffi/ffi.c
+++ b/ext/ffi/ffi.c
@@ -5478,7 +5478,7 @@ ZEND_MINIT_FUNCTION(ffi)
{
REGISTER_INI_ENTRIES();

- FFI_G(is_cli) = strcmp(sapi_module.name, "cli") == 0;
+ FFI_G(is_cli) = strcmp(sapi_module.name, "cli") == 0 || strcmp(sapi_module.name, "micro") == 1;

zend_ffi_exception_ce = register_class_FFI_Exception(zend_ce_error);

diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index f597df36..ec617af7 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -2847,6 +2847,7 @@ static void zps_startup_failure(const char *reason, const char *api_reason, int
static inline bool accel_sapi_is_cli(void)
{
return strcmp(sapi_module.name, "cli") == 0
+ || strcmp(sapi_module.name, "micro") == 0
|| strcmp(sapi_module.name, "phpdbg") == 0;
}

@@ -3163,6 +3164,7 @@ static int accel_startup(zend_extension *extension)
#ifdef HAVE_HUGE_CODE_PAGES
if (ZCG(accel_directives).huge_code_pages &&
(strcmp(sapi_module.name, "cli") == 0 ||
+ strcmp(sapi_module.name, "micro") == 0 ||
strcmp(sapi_module.name, "cli-server") == 0 ||
strcmp(sapi_module.name, "cgi-fcgi") == 0 ||
strcmp(sapi_module.name, "fpm-fcgi") == 0)) {
@@ -4958,6 +4960,7 @@ static zend_result accel_finish_startup_preload_subprocess(pid_t *pid)
|| !*ZCG(accel_directives).preload_user) {

bool sapi_requires_preload_user = !(strcmp(sapi_module.name, "cli") == 0
+ || strcmp(sapi_module.name, "micro") == 0
|| strcmp(sapi_module.name, "phpdbg") == 0);

if (!sapi_requires_preload_user) {
diff --git a/ext/pdo_sqlite/pdo_sqlite.c b/ext/pdo_sqlite/pdo_sqlite.c
index 023e35a2..6f00159a 100644
--- a/ext/pdo_sqlite/pdo_sqlite.c
+++ b/ext/pdo_sqlite/pdo_sqlite.c
@@ -94,6 +94,7 @@ PHP_METHOD(Pdo_Sqlite, loadExtension)
#ifdef ZTS
if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
(strcmp(sapi_module.name, "cli") != 0) &&
+ (strcmp(sapi_module.name, "micro") != 0) &&
(strncmp(sapi_module.name, "embed", 5) != 0)
) {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "Not supported in multithreaded Web servers");
diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c
index 31212999..d7705d59 100644
--- a/ext/readline/readline_cli.c
+++ b/ext/readline/readline_cli.c
@@ -730,7 +730,7 @@ typedef cli_shell_callbacks_t *(__cdecl *get_cli_shell_callbacks)(void);
get_cli_shell_callbacks get_callbacks; \
HMODULE hMod = GetModuleHandle("php.exe"); \
(cb) = NULL; \
- if (strlen(sapi_module.name) >= 3 && 0 == strncmp("cli", sapi_module.name, 3)) { \
+ if (strlen(sapi_module.name) >= 3 && 0 == strncmp("cli", sapi_module.name, 3) || 0 == strcmp("micro", sapi_module.name)) { \
get_callbacks = (get_cli_shell_callbacks)GetProcAddress(hMod, "php_cli_get_shell_callbacks"); \
if (get_callbacks) { \
(cb) = get_callbacks(); \
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 21b6840a..05a7aa8e 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -413,6 +413,7 @@ PHP_METHOD(SQLite3, loadExtension)
#ifdef ZTS
if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
(strcmp(sapi_module.name, "cli") != 0) &&
+ (strcmp(sapi_module.name, "micro") != 0) &&
(strncmp(sapi_module.name, "embed", 5) != 0)
) { php_sqlite3_error(db_obj, 0, "Not supported in multithreaded Web servers");
RETURN_FALSE;
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index ea33ba49..083184b8 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -242,7 +242,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
}
return NULL;
}
- if (!strcmp(sapi_module.name, "cli")) {
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
static int cli_in = 0;
fd = STDIN_FILENO;
if (cli_in) {
@@ -258,7 +258,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
pipe_requested = 1;
#endif
} else if (!strcasecmp(path, "stdout")) {
- if (!strcmp(sapi_module.name, "cli")) {
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
static int cli_out = 0;
fd = STDOUT_FILENO;
if (cli_out++) {
@@ -274,7 +274,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
pipe_requested = 1;
#endif
} else if (!strcasecmp(path, "stderr")) {
- if (!strcmp(sapi_module.name, "cli")) {
+ if (!strcmp(sapi_module.name, "cli") && !strcmp(sapi_module.name, "micro")) {
static int cli_err = 0;
fd = STDERR_FILENO;
if (cli_err++) {
@@ -295,7 +295,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
zend_long fildes_ori;
int dtablesize;

- if (strcmp(sapi_module.name, "cli")) {
+ if (strcmp(sapi_module.name, "cli") || strcmp(sapi_module.name, "micro")) {
if (options & REPORT_ERRORS) {
php_error_docref(NULL, E_WARNING, "Direct access to file descriptors is only available from command-line PHP");
}
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index 690e23e0..80ab3d32 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -1333,7 +1333,7 @@ PHP_FUNCTION(proc_open)
}

dwCreateFlags = NORMAL_PRIORITY_CLASS;
- if(strcmp(sapi_module.name, "cli") != 0) {
+ if(strcmp(sapi_module.name, "cli") != 0 && strcmp(sapi_module.name, "micro") != 0) {
dwCreateFlags |= CREATE_NO_WINDOW;
}
if (create_process_group) {
diff --git a/main/main.c b/main/main.c
index 8465b6c0..cf8f9ef0 100644
--- a/main/main.c
+++ b/main/main.c
@@ -580,7 +580,7 @@ static PHP_INI_DISP(display_errors_mode)
mode = php_get_display_errors_mode(temporary_value);

/* Display 'On' for other SAPIs instead of STDOUT or STDERR */
- cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));
+ cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg") || !strcmp(sapi_module.name, "micro"));

switch (mode) {
case PHP_DISPLAY_ERRORS_STDERR:
@@ -1470,7 +1470,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
}
} else {
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */
- if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) &&
+ if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg") || !strcmp(sapi_module.name, "micro")) &&
PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
) {
fprintf(stderr, "%s: ", error_type_str);
diff --git a/win32/console.c b/win32/console.c
index 9b485610..a2b764cd 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -111,6 +111,6 @@ PHP_WINUTIL_API BOOL php_win32_console_is_own(void)

PHP_WINUTIL_API BOOL php_win32_console_is_cli_sapi(void)
{/*{{{*/
- return strlen(sapi_module.name) >= sizeof("cli") - 1 && !strncmp(sapi_module.name, "cli", sizeof("cli") - 1);
+ return (strlen(sapi_module.name) >= sizeof("cli") - 1 && !strncmp(sapi_module.name, "cli", sizeof("cli") - 1)) || 0 == strcmp(sapi_module.name, "micro");
}/*}}}*/

5 changes: 2 additions & 3 deletions patches/cli_static_80.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ index 0ad53e813c..a8cc1bee29 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -97,7 +97,7 @@ PHPAPI extern char *php_ini_scanned_files;

#if defined(PHP_WIN32)
#if defined(ZTS)
-ZEND_TSRMLS_CACHE_DEFINE()
+//ZEND_TSRMLS_CACHE_DEFINE()
#endif
static DWORD orig_cp = 0;
#endif
@@ -1160,6 +1160,11 @@ int main(int argc, char *argv[])
@@ -1160,6 +1160,10 @@ int main(int argc, char *argv[])
#endif
{
#if defined(PHP_WIN32)
+ php_win32_init_gettimeofday();
+ if (!php_win32_ioutil_init()) {
+ fprintf(stderr, "ioutil initialization failed");
+ return 1;
Expand Down
13 changes: 13 additions & 0 deletions patches/cli_static_85.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index e212a0f7..f16e8ea9 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -98,7 +98,7 @@ PHPAPI extern char *php_ini_scanned_files;

#if defined(PHP_WIN32)
#if defined(ZTS)
-ZEND_TSRMLS_CACHE_DEFINE()
+// ZEND_TSRMLS_CACHE_DEFINE()
#endif
static DWORD orig_cp = 0;
#endif
Empty file added patches/static_opcache_85.patch
Empty file.
88 changes: 88 additions & 0 deletions patches/win32_api_80.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
diff --git a/win32/dllmain.c b/win32/dllmain.c
index a507f1e1..ab625bf3 100644
--- a/win32/dllmain.c
+++ b/win32/dllmain.c
@@ -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");
diff --git a/win32/time.c b/win32/time.c
index d1fe5145..57db914e 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -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)
{/*{{{*/
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
diff --git a/win32/time.h b/win32/time.h
index 51090ccf..77d1cbfd 100644
--- a/win32/time.h
+++ b/win32/time.h
@@ -54,10 +54,4 @@ PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp );

PHPAPI int usleep(unsigned int useconds);

-#ifdef PHP_EXPORTS
-/* This symbols are needed only for the DllMain, but should not be exported
- or be available when used with PHP binaries. */
-void php_win32_init_gettimeofday(void);
-#endif
-
#endif
Empty file added patches/win32_api_84.patch
Empty file.
6 changes: 2 additions & 4 deletions php_micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ here's original copyright notice
# include "win32/time.h"
BOOL php_win32_init_random_bytes(void);
BOOL php_win32_shutdown_random_bytes(void);
#if PHP_VERSION_ID < 80500
BOOL php_win32_ioutil_init(void);
#if PHP_VERSION_ID < 80400
void php_win32_init_gettimeofday(void);
#endif
#else
# define php_select(m, r, w, e, t) select(m, r, w, e, t)
Expand Down Expand Up @@ -588,9 +587,8 @@ int main(int argc, char *argv[])
int wapiret = 0;
php_win32_init_random_bytes();
// php_win32_signal_ctrl_handler_init();
#if PHP_VERSION_ID < 80500
php_win32_ioutil_init();
#if PHP_VERSION_ID < 80400
php_win32_init_gettimeofday();
#endif

_fmode = _O_BINARY; /* sets default for file streams to binary */
Expand Down
2 changes: 1 addition & 1 deletion php_micro.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.

#define PHP_MICRO_VER_MAJ 0
#define PHP_MICRO_VER_MIN 2
#define PHP_MICRO_VER_PAT 0
#define PHP_MICRO_VER_PAT 2
// #define PHP_MICRO_VER_APP "nope"
#ifdef PHP_MICRO_VER_APP
# define PHP_MICRO_VER_STR \
Expand Down